jsre
v0.6.0
Published
JSON based rules engine
Readme
Build Info
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:
- Derived facts should be computed to the document of inspection before the business rules are run
- Use the latest ES7 based capabilities in the implementation to eliminate unnecessary boiler plate
- Focus on inspecting a single large JSON object that could come back from an API or an object moving through a streaming platform
- Allow for the use of YAML, it is just more concise
- Lean on
AJVfor rule specification validation - Lean on
lodashfor a lot of heavy lifting - Like other rule engines, re-use the
rulesdata structure to put the results of calculation to make it easier to diagnose failures - In the results returned, returned a focused list of
errorsto 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 $ =)
