json-rules-engine
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -1,2 +0,5 @@ | ||
#### 6.0. / 2020-12-22 | ||
#### 6.0.1 / 2021-03-09 | ||
* Updates Typescript types to include `failureEvents` in EngineResult. | ||
#### 6.0.0 / 2020-12-22 | ||
* BREAKING CHANGES | ||
@@ -3,0 +6,0 @@ * To continue using [selectn](https://github.com/wilmoore/selectn.js) syntax for condition `path`s, use the new `pathResolver` feature. Read more [here](./docs/rules.md#condition-helpers-custom-path-resolver). Add the following to the engine constructor: |
{ | ||
"name": "json-rules-engine", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "Rules Engine expressed in simple json", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,2 +11,15 @@ ![json-rules-engine](http://i.imgur.com/MAzq7l2.png) | ||
* [Synopsis](#synopsis) | ||
* [Features](#features) | ||
* [Installation](#installation) | ||
* [Docs](#docs) | ||
* [Examples](#examples) | ||
* [Basic Example](#basic-example) | ||
* [Advanced Example](#advanced-example) | ||
* [Debugging](#debugging) | ||
* [Node](#node) | ||
* [Browser](#browser) | ||
* [Related Projects](#related-projects) | ||
* [License](#license) | ||
## Synopsis | ||
@@ -23,3 +36,3 @@ | ||
* Isomorphic; runs in node and browser | ||
* Lightweight & extendable; 12kb gzipped w/few dependencies | ||
* Lightweight & extendable; 17kb gzipped w/few dependencies | ||
@@ -32,2 +45,13 @@ ## Installation | ||
## Docs | ||
- [engine](./docs/engine.md) | ||
- [rules](./docs/rules.md) | ||
- [almanac](./docs/almanac.md) | ||
- [facts](./docs/facts.md) | ||
## Examples | ||
See the [Examples](./examples), which demonstrate the major features and capabilities. | ||
## Basic Example | ||
@@ -136,3 +160,3 @@ | ||
value: 'microsoft', | ||
path: '.company' // access the 'company' property of "account-information" | ||
path: '$.company' // access the 'company' property of "account-information" | ||
}, { | ||
@@ -142,3 +166,3 @@ fact: 'account-information', | ||
value: ['active', 'paid-leave'], // 'status' can be active or paid-leave | ||
path: '.status' // access the 'status' property of "account-information" | ||
path: '$.status' // access the 'status' property of "account-information" | ||
}, { | ||
@@ -148,3 +172,3 @@ fact: 'account-information', | ||
value: '2016-12-25', | ||
path: '.ptoDaysTaken' // access the 'ptoDaysTaken' property of "account-information" | ||
path: '$.ptoDaysTaken' // access the 'ptoDaysTaken' property of "account-information" | ||
}] | ||
@@ -193,21 +217,2 @@ }, | ||
## Docs | ||
The examples above provide a simple demonstrations of what `json-rules-engine` can do. To learn more about the advanced features and techniques, | ||
see the [docs](./docs) and read through the [examples](./examples). There is also a [walkthrough](./docs/walkthrough.md) available. | ||
## Persisting Rules | ||
Rules may be easily converted to JSON and persisted to a database, file system, or elsewhere. To convert a rule to JSON, simply call the ```rule.toJSON()``` method. Later, a rule may be restored by feeding the json into the Rule constructor. | ||
```js | ||
// save somewhere... | ||
let jsonString = rule.toJSON() | ||
// ...later: | ||
let rule = new Rule(jsonString) | ||
``` | ||
_Why aren't "fact" methods persistable?_ This is by design, for several reasons. Firstly, facts are by definition business logic bespoke to your application, and therefore lie outside the scope of this library. Secondly, many times this request indicates a design smell; try thinking of other ways to compose the rules and facts to accomplish the same objective. Finally, persisting fact methods would involve serializing javascript code, and restoring it later via ``eval()``. If you have a strong desire for this feature, the [node-rules](https://github.com/mithunsatheesh/node-rules) project supports this (though be aware the capability is enabled via ``eval()``. | ||
## Debugging | ||
@@ -217,3 +222,3 @@ | ||
#### Node | ||
### Node | ||
@@ -224,3 +229,3 @@ ```bash | ||
#### Browser | ||
### Browser | ||
```js | ||
@@ -231,3 +236,10 @@ // set debug flag in local storage & refresh page to see console output | ||
## Related Projects | ||
https://github.com/vinzdeveloper/json-rule-editor - configuration ui for json-rules-engine: | ||
<img width="1680" alt="rule editor 2" src="https://user-images.githubusercontent.com/61467683/82750274-dd3b3b80-9da6-11ea-96eb-434a6a1a9bc1.png"> | ||
## License | ||
[ISC](./LICENSE) |
@@ -8,2 +8,3 @@ export interface EngineOptions { | ||
events: Event[]; | ||
failureEvents: Event[]; | ||
almanac: Almanac; | ||
@@ -10,0 +11,0 @@ results: RuleResult[]; |
1413
236
76571