@gorules/zen-engine 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -30
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
ZEN Engine is business friendly Open-Source Business Rules Engine (BRE) to execute decision models according to the [GoRules JSON Decision Model (JDM)](https://gorules.io/docs/rules-engine/json-decision-model) standard. It is written in **Rust** and provides native bindings for **NodeJS** and **Python**. ZEN Engine allows to load and execute JSON Decision Model (JDM) from JSON files.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
|
+
|
|
8
9
|
ZEN Engine is built as embeddable BRE for your **Rust**, **NodeJS** or **Python** applications.
|
|
9
10
|
It parses JDM from JSON content. It is up to you to obtain the JSON content, e.g. from file system, database or service call.
|
|
10
11
|
|
|
11
12
|
If you are looking for a **Decision-as-a-Service** (DaaS) over REST, take a look at [GoRules Cloud](https://gorules.io).
|
|
12
13
|
|
|
13
14
|
### Installation
|
|
15
|
+
|
|
14
16
|
```bash
|
|
15
17
|
npm i @gorules/zen-engine
|
|
16
18
|
```
|
|
@@ -22,10 +24,11 @@ yarn add @gorules/zen-engine
|
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
### Simple Example
|
|
27
|
+
|
|
25
28
|
To execute a simple decision you can use the code below.
|
|
26
29
|
|
|
27
30
|
```typescript
|
|
28
|
-
import { ZenEngine } from
|
|
31
|
+
import { ZenEngine } from '@gorules/zen-engine';
|
|
29
32
|
import fs from 'fs/promises';
|
|
30
33
|
|
|
31
34
|
(async () => {
|
|
@@ -34,7 +37,7 @@ import fs from 'fs/promises';
|
|
|
34
37
|
const engine = new ZenEngine();
|
|
35
38
|
|
|
36
39
|
const decision = engine.createDecision(content);
|
|
37
|
-
const result = await decision.evaluate({input: 15});
|
|
40
|
+
const result = await decision.evaluate({ input: 15 });
|
|
38
41
|
})();
|
|
39
42
|
```
|
|
40
43
|
|
|
@@ -43,28 +46,24 @@ import fs from 'fs/promises';
|
|
|
43
46
|
For more advanced use cases where you want to load multiple decisions and utilise graphs you can build loaders.
|
|
44
47
|
|
|
45
48
|
```typescript
|
|
46
|
-
import { ZenEngine } from
|
|
49
|
+
import { ZenEngine } from '../index';
|
|
47
50
|
import fs from 'fs/promises';
|
|
48
51
|
import path from 'path';
|
|
49
52
|
|
|
50
53
|
const dataRoot = path.join(__dirname, 'jdm_directory');
|
|
51
54
|
|
|
52
|
-
const loader = async (key: string) => fs.readFile(path.join(testDataRoot, key))
|
|
55
|
+
const loader = async (key: string) => fs.readFile(path.join(testDataRoot, key))(async () => {
|
|
56
|
+
const engine = new ZenEngine({ loader });
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
const engine = new ZenEngine({
|
|
56
|
-
loader
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const result = await engine.evaluate('jdm_graph1.json', {input: 5});
|
|
58
|
+
const result = await engine.evaluate('jdm_graph1.json', { input: 5 });
|
|
60
59
|
})();
|
|
61
60
|
```
|
|
61
|
+
|
|
62
62
|
When engine.evaluate is invoked it will call loader and pass a key expecting a content of the JDM decision graph.
|
|
63
63
|
In the case above we will assume file `jdm_directory/jdm_graph1.json` exists.
|
|
64
64
|
|
|
65
65
|
Similar to this example you can also utilise loader to load from different places, for example from REST API, from S3, Database, etc.
|
|
66
66
|
|
|
67
|
-
|
|
68
67
|
## JSON Decision Model (JDM)
|
|
69
68
|
|
|
70
69
|
JDM is a modeling standard for business decisions and business rules and is stored in a JSON format. Decision models are represented by graphs. Graphs are built using nodes and edges. Edges are used to pass the data from one node to another (left-side to right-side).
|
|
@@ -78,6 +77,7 @@ You can try [Free Online Editor](https://editor.gorules.io) with built in Simula
|
|
|
78
77
|
Input node contains all data sent in the context, and Output node returns the data from the decision. Data flows from the Input Node towards Output Node evaluating all the Nodes in between and passing the data where nodes are connected.
|
|
79
78
|
|
|
80
79
|
### Decision Tables
|
|
80
|
+
|
|
81
81
|
Decision table is a node which allows business users to easily modify and add new rules in an intuitive way using spreadsheet like interface. The structure of decision table is defined by its schema. Schema consists of inputs and outputs.
|
|
82
82
|
|
|
83
83
|
Decision tables are evaluated row by row from top to bottom, and depending on the hit policy a result is calculated.
|
|
@@ -105,20 +105,20 @@ Inputs are using business-friendly ZEN Expression Language. The language is desi
|
|
|
105
105
|
|
|
106
106
|
List shows basic example of the unary tests in the Input Fields:
|
|
107
107
|
|
|
108
|
-
| Input entry | Input Expression
|
|
109
|
-
|
|
|
110
|
-
| "A"
|
|
111
|
-
| "A", "B"
|
|
112
|
-
| 36
|
|
113
|
-
| < 36
|
|
114
|
-
| > 36
|
|
115
|
-
| [20..39]
|
|
116
|
-
| 20,39
|
|
117
|
-
| <20, >39
|
|
118
|
-
| true
|
|
119
|
-
| false
|
|
120
|
-
|
|
|
121
|
-
| null
|
|
108
|
+
| Input entry | Input Expression |
|
|
109
|
+
| ----------- | ---------------------------------------------- |
|
|
110
|
+
| "A" | the field equals "A" |
|
|
111
|
+
| "A", "B" | the field is either "A" or "B" |
|
|
112
|
+
| 36 | the numeric value equals 36 |
|
|
113
|
+
| < 36 | a value less than 36 |
|
|
114
|
+
| > 36 | a value greater than 36 |
|
|
115
|
+
| [20..39] | a value between 20 and 39 (inclusive) |
|
|
116
|
+
| 20,39 | a value either 20 or 39 |
|
|
117
|
+
| <20, >39 | a value either less than 20 or greater than 39 |
|
|
118
|
+
| true | the boolean value true |
|
|
119
|
+
| false | the boolean value false |
|
|
120
|
+
| | any value, even null/undefined |
|
|
121
|
+
| null | the value null or undefined |
|
|
122
122
|
|
|
123
123
|
Note: For the full list please visit [ZEN Expression Language](https://gorules.io/docs/rules-engine/expression-language/).
|
|
124
124
|
|
|
@@ -149,21 +149,23 @@ And the result would be:
|
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
### Functions
|
|
152
|
+
|
|
152
153
|
Function nodes are JavaScript lambdas that allow for quick and easy parsing, re-mapping or otherwise modifying the data. Inputs of the node are provided as function's arguments. Functions are executed on top of Google's V8 Engine that is built in into the ZEN Engine.
|
|
153
154
|
|
|
154
155
|
```js
|
|
155
156
|
const handler = (input) => {
|
|
156
157
|
return input;
|
|
157
|
-
}
|
|
158
|
+
};
|
|
158
159
|
```
|
|
159
160
|
|
|
160
161
|
### Decision
|
|
162
|
+
|
|
161
163
|
Decision is a special node whose purpose is for decision model to have an ability to call other/re-usable decision models during an execution.
|
|
162
164
|
|
|
163
165
|
## Support matrix
|
|
164
166
|
|
|
165
|
-
linux-x64-gnu
|
|
166
|
-
:------------
|
|
167
|
-
yes
|
|
167
|
+
| linux-x64-gnu | linux-arm64-gnu | darwin-x64 | darwin-arm64 | win32-x64-msvc |
|
|
168
|
+
| :------------ | :-------------- | :--------- | :----------- | :------------- |
|
|
169
|
+
| yes | yes | yes | yes | yes |
|
|
168
170
|
|
|
169
|
-
We do not support linux-musl for now as we are relying on the GoogleV8 engine to run function blocks as isolates.
|
|
171
|
+
We do not support linux-musl for now as we are relying on the GoogleV8 engine to run function blocks as isolates.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gorules/zen-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,17 +73,18 @@
|
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "napi build --platform --release --js index.js --dts index.d.ts",
|
|
75
75
|
"build:debug": "napi build --platform --js index.js --dts index.d.ts",
|
|
76
|
+
"watch": "cargo watch --ignore '{index.js,index.d.ts}' -- npm run build:debug",
|
|
76
77
|
"test": "jest",
|
|
77
78
|
"artifacts": "napi artifacts -d ../../artifacts",
|
|
78
79
|
"prepublishOnly": "napi prepublish",
|
|
79
80
|
"version": "napi version"
|
|
80
81
|
},
|
|
81
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "d47bca68870423cad21dada17407036b5fe2921e",
|
|
82
83
|
"optionalDependencies": {
|
|
83
|
-
"@gorules/zen-engine-darwin-x64": "0.
|
|
84
|
-
"@gorules/zen-engine-linux-x64-gnu": "0.
|
|
85
|
-
"@gorules/zen-engine-win32-x64-msvc": "0.
|
|
86
|
-
"@gorules/zen-engine-linux-arm64-gnu": "0.
|
|
87
|
-
"@gorules/zen-engine-darwin-arm64": "0.
|
|
84
|
+
"@gorules/zen-engine-darwin-x64": "0.7.0",
|
|
85
|
+
"@gorules/zen-engine-linux-x64-gnu": "0.7.0",
|
|
86
|
+
"@gorules/zen-engine-win32-x64-msvc": "0.7.0",
|
|
87
|
+
"@gorules/zen-engine-linux-arm64-gnu": "0.7.0",
|
|
88
|
+
"@gorules/zen-engine-darwin-arm64": "0.7.0"
|
|
88
89
|
}
|
|
89
90
|
}
|