0.6.0 • Published 4 years ago

jsre v0.6.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Build Info

Statements Functions Lines Branches

JSon Rules Engine

There are several JSON rules engines avaialable so why build another one? As usual, the ones out there were not really a good fit. So this package is based on the following focus:

  1. Derived facts should be computed to the document of inspection before the business rules are run
  2. Use the latest ES7 based capabilities in the implementation to eliminate unnecessary boiler plate
  3. Focus on inspecting a single large JSON object that could come back from an API or an object moving through a streaming platform
  4. Allow for the use of YAML, it is just more concise
  5. Lean on AJV for rule specification validation
  6. Lean on lodash for a lot of heavy lifting
  7. Like other rule engines, re-use the rules data structure to put the results of calculation to make it easier to diagnose failures
  8. In the results returned, returned a focused list of errors to simplify diagnosing errors

Example

test('example rule pass', () => {
  const testDocument = {
    prop1 : {
      prop2 : {
        prop3 : 1
      }
    }
  };
  
  const rules = [
    {
      conditions: {
        all: [
          {
            operator: "equal",
            lhs: 1,
            rhs: {
              path: "prop1.prop2.prop3"
            }
          }
        ]
      }
    }
  ];
  
  const engine = new Engine( { rules } );
  const results = engine.run( testDocument );
  expect(results).toHaveProperty('success');
  expect(results.success).toBe(true);
});

Operators

Operators are very easy to add and are kept pluggable in a directory called operator

Requests

Requests for added functionality are welcome and will be implemented without asking for pull requests or $ =)

Docs

Documentation

0.6.0

4 years ago

0.5.0

4 years ago

0.3.0

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago