@ruleflow-ts/dsl-core 0.1.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/LICENSE +21 -0
- package/README.md +290 -0
- package/dist/debug.d.ts +11 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +30 -0
- package/dist/debug.js.map +1 -0
- package/dist/errors/PropertyNotFoundError.d.ts +5 -0
- package/dist/errors/PropertyNotFoundError.d.ts.map +1 -0
- package/dist/errors/PropertyNotFoundError.js +17 -0
- package/dist/errors/PropertyNotFoundError.js.map +1 -0
- package/dist/evaluator/AggregationEvaluator.d.ts +9 -0
- package/dist/evaluator/AggregationEvaluator.d.ts.map +1 -0
- package/dist/evaluator/AggregationEvaluator.js +74 -0
- package/dist/evaluator/AggregationEvaluator.js.map +1 -0
- package/dist/evaluator/BinaryAndEvaluator.d.ts +6 -0
- package/dist/evaluator/BinaryAndEvaluator.d.ts.map +1 -0
- package/dist/evaluator/BinaryAndEvaluator.js +14 -0
- package/dist/evaluator/BinaryAndEvaluator.js.map +1 -0
- package/dist/evaluator/BinaryOrEvaluator.d.ts +6 -0
- package/dist/evaluator/BinaryOrEvaluator.d.ts.map +1 -0
- package/dist/evaluator/BinaryOrEvaluator.js +14 -0
- package/dist/evaluator/BinaryOrEvaluator.js.map +1 -0
- package/dist/evaluator/ComparatorEvaluator.d.ts +9 -0
- package/dist/evaluator/ComparatorEvaluator.d.ts.map +1 -0
- package/dist/evaluator/ComparatorEvaluator.js +95 -0
- package/dist/evaluator/ComparatorEvaluator.js.map +1 -0
- package/dist/evaluator/ListEvaluator.d.ts +10 -0
- package/dist/evaluator/ListEvaluator.d.ts.map +1 -0
- package/dist/evaluator/ListEvaluator.js +71 -0
- package/dist/evaluator/ListEvaluator.js.map +1 -0
- package/dist/evaluator/MathAddEvaluator.d.ts +5 -0
- package/dist/evaluator/MathAddEvaluator.d.ts.map +1 -0
- package/dist/evaluator/MathAddEvaluator.js +20 -0
- package/dist/evaluator/MathAddEvaluator.js.map +1 -0
- package/dist/evaluator/MathMulEvaluator.d.ts +5 -0
- package/dist/evaluator/MathMulEvaluator.d.ts.map +1 -0
- package/dist/evaluator/MathMulEvaluator.js +23 -0
- package/dist/evaluator/MathMulEvaluator.js.map +1 -0
- package/dist/evaluator/ParenthesisEvaluator.d.ts +5 -0
- package/dist/evaluator/ParenthesisEvaluator.d.ts.map +1 -0
- package/dist/evaluator/ParenthesisEvaluator.js +10 -0
- package/dist/evaluator/ParenthesisEvaluator.js.map +1 -0
- package/dist/evaluator/RegexlikeEvaluator.d.ts +6 -0
- package/dist/evaluator/RegexlikeEvaluator.d.ts.map +1 -0
- package/dist/evaluator/RegexlikeEvaluator.js +23 -0
- package/dist/evaluator/RegexlikeEvaluator.js.map +1 -0
- package/dist/evaluator/TupleListEvaluator.d.ts +11 -0
- package/dist/evaluator/TupleListEvaluator.d.ts.map +1 -0
- package/dist/evaluator/TupleListEvaluator.js +121 -0
- package/dist/evaluator/TupleListEvaluator.js.map +1 -0
- package/dist/evaluator/UnaryEvaluator.d.ts +6 -0
- package/dist/evaluator/UnaryEvaluator.d.ts.map +1 -0
- package/dist/evaluator/UnaryEvaluator.js +12 -0
- package/dist/evaluator/UnaryEvaluator.js.map +1 -0
- package/dist/evaluator/ValidPropertyEvaluator.d.ts +6 -0
- package/dist/evaluator/ValidPropertyEvaluator.d.ts.map +1 -0
- package/dist/evaluator/ValidPropertyEvaluator.js +32 -0
- package/dist/evaluator/ValidPropertyEvaluator.js.map +1 -0
- package/dist/evaluator/ValueEvaluator.d.ts +8 -0
- package/dist/evaluator/ValueEvaluator.d.ts.map +1 -0
- package/dist/evaluator/ValueEvaluator.js +43 -0
- package/dist/evaluator/ValueEvaluator.js.map +1 -0
- package/dist/evaluator/date/DateAddEvaluator.d.ts +7 -0
- package/dist/evaluator/date/DateAddEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DateAddEvaluator.js +36 -0
- package/dist/evaluator/date/DateAddEvaluator.js.map +1 -0
- package/dist/evaluator/date/DateDiffEvaluator.d.ts +7 -0
- package/dist/evaluator/date/DateDiffEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DateDiffEvaluator.js +31 -0
- package/dist/evaluator/date/DateDiffEvaluator.js.map +1 -0
- package/dist/evaluator/date/DateOperationEvaluator.d.ts +6 -0
- package/dist/evaluator/date/DateOperationEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DateOperationEvaluator.js +13 -0
- package/dist/evaluator/date/DateOperationEvaluator.js.map +1 -0
- package/dist/evaluator/date/DateParseExprEvaluator.d.ts +7 -0
- package/dist/evaluator/date/DateParseExprEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DateParseExprEvaluator.js +44 -0
- package/dist/evaluator/date/DateParseExprEvaluator.js.map +1 -0
- package/dist/evaluator/date/DateSubtractEvaluator.d.ts +7 -0
- package/dist/evaluator/date/DateSubtractEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DateSubtractEvaluator.js +36 -0
- package/dist/evaluator/date/DateSubtractEvaluator.js.map +1 -0
- package/dist/evaluator/date/DateValueEvaluator.d.ts +7 -0
- package/dist/evaluator/date/DateValueEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DateValueEvaluator.js +44 -0
- package/dist/evaluator/date/DateValueEvaluator.js.map +1 -0
- package/dist/evaluator/date/DayOfWeekEvaluator.d.ts +7 -0
- package/dist/evaluator/date/DayOfWeekEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/DayOfWeekEvaluator.js +21 -0
- package/dist/evaluator/date/DayOfWeekEvaluator.js.map +1 -0
- package/dist/evaluator/date/NowEvaluator.d.ts +6 -0
- package/dist/evaluator/date/NowEvaluator.d.ts.map +1 -0
- package/dist/evaluator/date/NowEvaluator.js +10 -0
- package/dist/evaluator/date/NowEvaluator.js.map +1 -0
- package/dist/evaluator/geo/DistanceEvaluator.d.ts +6 -0
- package/dist/evaluator/geo/DistanceEvaluator.d.ts.map +1 -0
- package/dist/evaluator/geo/DistanceEvaluator.js +15 -0
- package/dist/evaluator/geo/DistanceEvaluator.js.map +1 -0
- package/dist/evaluator/geo/DistanceGeohashEvaluator.d.ts +6 -0
- package/dist/evaluator/geo/DistanceGeohashEvaluator.d.ts.map +1 -0
- package/dist/evaluator/geo/DistanceGeohashEvaluator.js +15 -0
- package/dist/evaluator/geo/DistanceGeohashEvaluator.js.map +1 -0
- package/dist/evaluator/geo/GeoOperationEvaluator.d.ts +6 -0
- package/dist/evaluator/geo/GeoOperationEvaluator.d.ts.map +1 -0
- package/dist/evaluator/geo/GeoOperationEvaluator.js +11 -0
- package/dist/evaluator/geo/GeoOperationEvaluator.js.map +1 -0
- package/dist/evaluator/geo/GeohashDecodeEvaluator.d.ts +6 -0
- package/dist/evaluator/geo/GeohashDecodeEvaluator.d.ts.map +1 -0
- package/dist/evaluator/geo/GeohashDecodeEvaluator.js +12 -0
- package/dist/evaluator/geo/GeohashDecodeEvaluator.js.map +1 -0
- package/dist/evaluator/geo/GeohashEncodeEvaluator.d.ts +6 -0
- package/dist/evaluator/geo/GeohashEncodeEvaluator.d.ts.map +1 -0
- package/dist/evaluator/geo/GeohashEncodeEvaluator.js +15 -0
- package/dist/evaluator/geo/GeohashEncodeEvaluator.js.map +1 -0
- package/dist/evaluator/geo/WithinRadiusEvaluator.d.ts +6 -0
- package/dist/evaluator/geo/WithinRadiusEvaluator.d.ts.map +1 -0
- package/dist/evaluator/geo/WithinRadiusEvaluator.js +17 -0
- package/dist/evaluator/geo/WithinRadiusEvaluator.js.map +1 -0
- package/dist/evaluator/geo/geohash.d.ts +4 -0
- package/dist/evaluator/geo/geohash.d.ts.map +1 -0
- package/dist/evaluator/geo/geohash.js +91 -0
- package/dist/evaluator/geo/geohash.js.map +1 -0
- package/dist/evaluator/string/PartialRatioEvaluator.d.ts +6 -0
- package/dist/evaluator/string/PartialRatioEvaluator.d.ts.map +1 -0
- package/dist/evaluator/string/PartialRatioEvaluator.js +13 -0
- package/dist/evaluator/string/PartialRatioEvaluator.js.map +1 -0
- package/dist/evaluator/string/StringDistanceEvaluator.d.ts +6 -0
- package/dist/evaluator/string/StringDistanceEvaluator.d.ts.map +1 -0
- package/dist/evaluator/string/StringDistanceEvaluator.js +13 -0
- package/dist/evaluator/string/StringDistanceEvaluator.js.map +1 -0
- package/dist/evaluator/string/StringSimilarityScoreEvaluator.d.ts +6 -0
- package/dist/evaluator/string/StringSimilarityScoreEvaluator.d.ts.map +1 -0
- package/dist/evaluator/string/StringSimilarityScoreEvaluator.js +13 -0
- package/dist/evaluator/string/StringSimilarityScoreEvaluator.js.map +1 -0
- package/dist/evaluator/string/TokenSetRatioEvaluator.d.ts +6 -0
- package/dist/evaluator/string/TokenSetRatioEvaluator.d.ts.map +1 -0
- package/dist/evaluator/string/TokenSetRatioEvaluator.js +15 -0
- package/dist/evaluator/string/TokenSetRatioEvaluator.js.map +1 -0
- package/dist/evaluator/string/TokenSortRatioEvaluator.d.ts +6 -0
- package/dist/evaluator/string/TokenSortRatioEvaluator.d.ts.map +1 -0
- package/dist/evaluator/string/TokenSortRatioEvaluator.js +15 -0
- package/dist/evaluator/string/TokenSortRatioEvaluator.js.map +1 -0
- package/dist/evaluator/string/levenshtein.d.ts +7 -0
- package/dist/evaluator/string/levenshtein.d.ts.map +1 -0
- package/dist/evaluator/string/levenshtein.js +81 -0
- package/dist/evaluator/string/levenshtein.js.map +1 -0
- package/dist/generated/RuleFlowLanguageLexer.d.ts +4 -0
- package/dist/generated/RuleFlowLanguageLexer.d.ts.map +1 -0
- package/dist/generated/RuleFlowLanguageLexer.js +9 -0
- package/dist/generated/RuleFlowLanguageLexer.js.map +1 -0
- package/dist/generated/RuleFlowLanguageParser.d.ts +8 -0
- package/dist/generated/RuleFlowLanguageParser.d.ts.map +1 -0
- package/dist/generated/RuleFlowLanguageParser.js +13 -0
- package/dist/generated/RuleFlowLanguageParser.js.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageLexer.d.ts +106 -0
- package/dist/generated/src/grammar/RuleFlowLanguageLexer.d.ts.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageLexer.js +1128 -0
- package/dist/generated/src/grammar/RuleFlowLanguageLexer.js.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageListener.d.ts +752 -0
- package/dist/generated/src/grammar/RuleFlowLanguageListener.d.ts.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageListener.js +4 -0
- package/dist/generated/src/grammar/RuleFlowLanguageListener.js.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageParser.d.ts +936 -0
- package/dist/generated/src/grammar/RuleFlowLanguageParser.d.ts.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageParser.js +6080 -0
- package/dist/generated/src/grammar/RuleFlowLanguageParser.js.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageVisitor.d.ts +476 -0
- package/dist/generated/src/grammar/RuleFlowLanguageVisitor.d.ts.map +1 -0
- package/dist/generated/src/grammar/RuleFlowLanguageVisitor.js +4 -0
- package/dist/generated/src/grammar/RuleFlowLanguageVisitor.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/listeners/ErrorListener.d.ts +5 -0
- package/dist/listeners/ErrorListener.d.ts.map +1 -0
- package/dist/listeners/ErrorListener.js +10 -0
- package/dist/listeners/ErrorListener.js.map +1 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/visitors/ActionsVisitor.d.ts +12 -0
- package/dist/visitors/ActionsVisitor.d.ts.map +1 -0
- package/dist/visitors/ActionsVisitor.js +82 -0
- package/dist/visitors/ActionsVisitor.js.map +1 -0
- package/dist/visitors/RulesetVisitor.d.ts +18 -0
- package/dist/visitors/RulesetVisitor.d.ts.map +1 -0
- package/dist/visitors/RulesetVisitor.js +190 -0
- package/dist/visitors/RulesetVisitor.js.map +1 -0
- package/dist/visitors/Visitor.d.ts +13 -0
- package/dist/visitors/Visitor.d.ts.map +1 -0
- package/dist/visitors/Visitor.js +169 -0
- package/dist/visitors/Visitor.js.map +1 -0
- package/dist/workflow.d.ts +9 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +56 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Rodolfo Rivas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# @ruleflow-ts/dsl-core
|
|
2
|
+
|
|
3
|
+
TypeScript interpreter for the Ruleflow DSL. It runs in isomorphic environments (Node, SSR, and potentially Edge) and exposes a simple API to parse and evaluate rule workflows defined in a DSL.
|
|
4
|
+
|
|
5
|
+
- Node >= 18
|
|
6
|
+
- Based on ANTLR4TS for the grammar
|
|
7
|
+
- CommonJS output + type definitions (`.d.ts`)
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Arithmetic and comparison expressions: `+ - * / %`, `< <= > >= == <> =` (case-insensitive)
|
|
12
|
+
- Logical operators: `and`, `or`, `not`
|
|
13
|
+
- Lists: `contains`, `in`, `starts_with` with literal lists, stored lists `list('key')`, or properties
|
|
14
|
+
- Aggregations: `count()`, `average()`, `any{...}`, `all{...}`, `none{...}`, `distinct()`
|
|
15
|
+
- Dates: `dateDiff`, `day_of_week`, `now()`, `date_add`, `date_subtract`, `date(...)`, `datetime(...)`
|
|
16
|
+
- Regex utility: `regex_strip(prop, 're')`
|
|
17
|
+
- Unary: `abs(expr)`
|
|
18
|
+
- Geo: `geohash_encode`, `geohash_decode`, `distance`, `within_radius`
|
|
19
|
+
- Actions: `action('name', { 'k': 'v' })` with params using properties (`{'id': user.id}`)
|
|
20
|
+
- Evaluation mode: `evaluation_mode multi_match` (or default `single_match`)
|
|
21
|
+
|
|
22
|
+
## Install & Build
|
|
23
|
+
|
|
24
|
+
This package is part of the `ts-ruleflow` workspace.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# from ts-ruleflow/
|
|
28
|
+
npm install
|
|
29
|
+
npm run typecheck
|
|
30
|
+
npm run build
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Available scripts in `packages/dsl-core/package.json`:
|
|
34
|
+
|
|
35
|
+
- `generate`: generates the parser with antlr4ts from `src/grammar/RuleFlowLanguage.g4`
|
|
36
|
+
- `typecheck`: TypeScript type-check without emitting files
|
|
37
|
+
- `build`: compiles into `dist/`
|
|
38
|
+
- `clean`: removes `dist/` and `src/generated/`
|
|
39
|
+
|
|
40
|
+
> Note: the ANTLR generated code is included in the repo for easier builds. If you change the grammar, run `npm run generate` before building.
|
|
41
|
+
|
|
42
|
+
## Basic Usage
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Workflow } from '@ruleflow-ts/dsl-core';
|
|
46
|
+
|
|
47
|
+
const dsl = `workflow 'w'
|
|
48
|
+
ruleset 'eligibility'
|
|
49
|
+
'adult_us' user.age > 17 and country = 'US' return 'allow' action('notify', {'id': user.id})
|
|
50
|
+
default 'deny'
|
|
51
|
+
end`;
|
|
52
|
+
|
|
53
|
+
const data = { user: { id: '42', age: 20 }, country: 'US' };
|
|
54
|
+
const lists = {}; // optional
|
|
55
|
+
|
|
56
|
+
const wf = new Workflow(dsl);
|
|
57
|
+
const result = wf.evaluate(data, lists);
|
|
58
|
+
|
|
59
|
+
console.log(result);
|
|
60
|
+
// {
|
|
61
|
+
// workflow: 'w',
|
|
62
|
+
// ruleSet: 'eligibility',
|
|
63
|
+
// rule: 'adult_us',
|
|
64
|
+
// result: 'allow',
|
|
65
|
+
// actions: [{ name: 'notify', params: { id: '42' } }],
|
|
66
|
+
// warnings: [],
|
|
67
|
+
// error: false
|
|
68
|
+
// }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Main API
|
|
72
|
+
|
|
73
|
+
- `new Workflow(dsl: string)`
|
|
74
|
+
- `evaluate(request: InputMap, lists?: ListsMap): WorkflowResult`
|
|
75
|
+
- `validateAndGetWorkflowName(): string`
|
|
76
|
+
|
|
77
|
+
Relevant types (see `src/types.ts`):
|
|
78
|
+
|
|
79
|
+
- `InputMap = Record<string, unknown>`
|
|
80
|
+
- `ListsMap = Record<string, unknown[]>`
|
|
81
|
+
- `WorkflowResult` includes `workflow`, `ruleSet`, `rule`, `result`, `actions`, `warnings`, `matchedRules?`, `error?`
|
|
82
|
+
|
|
83
|
+
## DSL Examples
|
|
84
|
+
|
|
85
|
+
- Aggregations:
|
|
86
|
+
|
|
87
|
+
```sql
|
|
88
|
+
items.count() = 3
|
|
89
|
+
items.any{ type = 'a' } = true
|
|
90
|
+
items.none{ 'blocked' } = true
|
|
91
|
+
items.distinct()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- Dates:
|
|
95
|
+
|
|
96
|
+
```sql
|
|
97
|
+
dateDiff('2025-01-01T00:00:00Z', '2025-01-02T00:00:00Z', day) = 1
|
|
98
|
+
day_of_week('2025-09-14T05:00:00Z') = 'SUNDAY'
|
|
99
|
+
date_add('2025-01-01T00:00:00Z', 1, day) > '2025-01-01T00:00:00Z'
|
|
100
|
+
date_subtract('2025-01-01T12:00:00Z', 1, hour) < '2025-01-01T12:00:00Z'
|
|
101
|
+
datetime(now()) > '2000-01-01T00:00:00Z'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- Geo:
|
|
105
|
+
|
|
106
|
+
```sql
|
|
107
|
+
distance(37.7749, -122.4194, 34.0522, -118.2437) > 500
|
|
108
|
+
within_radius(37.7749, -122.4194, 37.7750, -122.4195, 1) = true
|
|
109
|
+
# with geohash
|
|
110
|
+
distance(geohash_encode(37.7749, -122.4194, 7), geohash_encode(37.7750, -122.4195, 7)) < 0.5
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- Multi-match mode:
|
|
114
|
+
|
|
115
|
+
```sql
|
|
116
|
+
workflow 'w'
|
|
117
|
+
evaluation_mode multi_match
|
|
118
|
+
ruleset 'rs'
|
|
119
|
+
'r1' 1 = 1 return 'A'
|
|
120
|
+
'r2' 2 = 2 return 'B'
|
|
121
|
+
default 'ko'
|
|
122
|
+
end
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
In this case `evaluate()` returns `matchedRules` with all matching rules, and `result` is the value of the first match.
|
|
126
|
+
|
|
127
|
+
## Next.js Integration (App Router) and Serverless
|
|
128
|
+
|
|
129
|
+
Recommended patterns for using `@ruleflow-ts/dsl-core` directly from Next.js pages, without an API Route, plus considerations for Serverless and Edge environments.
|
|
130
|
+
|
|
131
|
+
> Requirements: Next.js 14+ (App Router) and Node.js 18+. If your deployment requires Edge Runtime, review the "Edge Runtime" section below.
|
|
132
|
+
|
|
133
|
+
### 1) Server Actions (recommended)
|
|
134
|
+
|
|
135
|
+
Use a Server Action to evaluate the DSL on the server, invoked from a client component. It avoids exposing the DSL over the network and keeps the client bundle light.
|
|
136
|
+
|
|
137
|
+
`app/actions/evaluate.ts`:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
'use server';
|
|
141
|
+
|
|
142
|
+
import { Workflow } from '@ruleflow-ts/dsl-core';
|
|
143
|
+
|
|
144
|
+
export async function evaluateDsl(input: { dsl: string; data?: any; lists?: any }) {
|
|
145
|
+
const { dsl, data = {}, lists = {} } = input || {};
|
|
146
|
+
const wf = new Workflow(dsl);
|
|
147
|
+
return wf.evaluate(data, lists);
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`app/page.tsx` (client):
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
'use client';
|
|
155
|
+
import { useState } from 'react';
|
|
156
|
+
import { evaluateDsl } from './actions/evaluate';
|
|
157
|
+
|
|
158
|
+
export const runtime = 'nodejs'; // ensure Node.js runtime if your package is CJS
|
|
159
|
+
|
|
160
|
+
export default function Page() {
|
|
161
|
+
const [dsl, setDsl] = useState("workflow 'w'\n ruleset 'rs'\n 'r1' 1 = 1 return 'ok'\n default 'ko'\nend");
|
|
162
|
+
const [dataStr, setDataStr] = useState('{}');
|
|
163
|
+
const [listsStr, setListsStr] = useState('{}');
|
|
164
|
+
const [out, setOut] = useState('');
|
|
165
|
+
|
|
166
|
+
async function onSend() {
|
|
167
|
+
const data = dataStr ? JSON.parse(dataStr) : {};
|
|
168
|
+
const lists = listsStr ? JSON.parse(listsStr) : {};
|
|
169
|
+
const res = await evaluateDsl({ dsl, data, lists });
|
|
170
|
+
setOut(JSON.stringify(res, null, 2));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<div>
|
|
175
|
+
{/* textareas for dsl/data/lists */}
|
|
176
|
+
<button onClick={onSend}>Send</button>
|
|
177
|
+
<pre>{out}</pre>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Notes:
|
|
184
|
+
- If you use CommonJS in the core, set `export const runtime = 'nodejs'` in the current segment to avoid Edge runtime.
|
|
185
|
+
- For user-provided inputs, avoid caching with `export const dynamic = 'force-dynamic'` or `unstable_noStore()`.
|
|
186
|
+
|
|
187
|
+
### 2) Server Component (SSR during render)
|
|
188
|
+
|
|
189
|
+
Evaluate during server render without a Server Action. Useful if input comes from `searchParams` or server data.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import { Workflow } from '@ruleflow-ts/dsl-core';
|
|
193
|
+
import { unstable_noStore as noStore } from 'next/cache';
|
|
194
|
+
|
|
195
|
+
export const runtime = 'nodejs';
|
|
196
|
+
export const dynamic = 'force-dynamic';
|
|
197
|
+
|
|
198
|
+
export default async function Page({ searchParams }: { searchParams: { dsl?: string } }) {
|
|
199
|
+
noStore();
|
|
200
|
+
const dsl = searchParams.dsl ?? "workflow 'w'\n ruleset 'rs'\n 'r1' 1 = 1 return 'ok'\n default 'ko'\nend";
|
|
201
|
+
const wf = new Workflow(dsl);
|
|
202
|
+
const result = wf.evaluate({}, {});
|
|
203
|
+
return <pre>{JSON.stringify(result, null, 2)}</pre>;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### 3) Client Component (evaluate in the browser)
|
|
208
|
+
|
|
209
|
+
Import the core in the client and evaluate locally. Good for offline demos; consider bundle size.
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
'use client';
|
|
213
|
+
import { useState } from 'react';
|
|
214
|
+
|
|
215
|
+
export default function Page() {
|
|
216
|
+
const [dsl, setDsl] = useState("workflow 'w'\n ruleset 'rs'\n 'r1' 1 = 1 return 'ok'\n default 'ko'\nend");
|
|
217
|
+
const [out, setOut] = useState('');
|
|
218
|
+
|
|
219
|
+
async function onSend() {
|
|
220
|
+
// Deferred loading to reduce TTI
|
|
221
|
+
const { Workflow } = await import('@ruleflow-ts/dsl-core');
|
|
222
|
+
const wf = new Workflow(dsl);
|
|
223
|
+
const res = wf.evaluate({}, {});
|
|
224
|
+
setOut(JSON.stringify(res, null, 2));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return <button onClick={onSend}>Send</button>;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Considerations:
|
|
232
|
+
- The bundle will include the parser; if size matters, prefer Server Actions.
|
|
233
|
+
|
|
234
|
+
### 4) Alternative with API Route (if you prefer an endpoint)
|
|
235
|
+
|
|
236
|
+
Expose a `POST /api/evaluate` endpoint and consume it from the UI:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
// app/api/evaluate/route.ts
|
|
240
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
241
|
+
import { Workflow } from '@ruleflow-ts/dsl-core';
|
|
242
|
+
|
|
243
|
+
export const runtime = 'nodejs';
|
|
244
|
+
|
|
245
|
+
export async function POST(req: NextRequest) {
|
|
246
|
+
const { dsl, data = {}, lists = {} } = await req.json();
|
|
247
|
+
if (typeof dsl !== 'string' || !dsl.trim()) {
|
|
248
|
+
return NextResponse.json({ message: 'Field dsl is required' }, { status: 400 });
|
|
249
|
+
}
|
|
250
|
+
const wf = new Workflow(dsl);
|
|
251
|
+
const result = wf.evaluate(data, lists);
|
|
252
|
+
return NextResponse.json(result, { status: 200 });
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Serverless and Edge Runtime
|
|
257
|
+
|
|
258
|
+
- Node.js Serverless (Vercel/Netlify): works out-of-the-box with `runtime = 'nodejs'`.
|
|
259
|
+
- Edge Runtime: requires ESM-only dependencies. If your build is CommonJS, use `runtime = 'nodejs'` or publish a dual package (ESM + CJS). Edge example (if the core is ESM-compatible):
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
export const runtime = 'edge';
|
|
263
|
+
import { Workflow } from '@ruleflow-ts/dsl-core';
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Recommendations:
|
|
267
|
+
- Security: validate DSL and limit input size/time if accepting user-provided DSL.
|
|
268
|
+
- Caching: for dynamic inputs use `noStore()`/`dynamic = 'force-dynamic'`.
|
|
269
|
+
- Sizes: in the client use dynamic `import()` to reduce initial cost.
|
|
270
|
+
|
|
271
|
+
## Types and Result
|
|
272
|
+
|
|
273
|
+
- `new Workflow(dsl)`
|
|
274
|
+
- `evaluate(data?: InputMap, lists?: ListsMap): WorkflowResult`
|
|
275
|
+
- `WorkflowResult` may include `result`, `warnings`, `actions`, and `matchedRules` (in `evaluation_mode multi_match`).
|
|
276
|
+
|
|
277
|
+
## Development
|
|
278
|
+
|
|
279
|
+
- Grammar changed: `npm run generate`
|
|
280
|
+
- Typecheck: `npm run typecheck`
|
|
281
|
+
- Build: `npm run build`
|
|
282
|
+
- Quick smoke test:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
node scripts/smoke.js
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT
|
package/dist/debug.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function lex(input: string): {
|
|
2
|
+
type: number;
|
|
3
|
+
name: string | undefined;
|
|
4
|
+
lit: string | undefined;
|
|
5
|
+
text: string | undefined;
|
|
6
|
+
}[];
|
|
7
|
+
export declare function parse(input: string): {
|
|
8
|
+
treeType: any;
|
|
9
|
+
ctxRuleIndex: any;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAIA,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM;;;;;IAYhC;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM;;;EAQlC"}
|
package/dist/debug.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lex = lex;
|
|
4
|
+
exports.parse = parse;
|
|
5
|
+
const antlr4ts_1 = require("antlr4ts");
|
|
6
|
+
const RuleFlowLanguageLexer_1 = require("./generated/src/grammar/RuleFlowLanguageLexer");
|
|
7
|
+
const RuleFlowLanguageParser_1 = require("./generated/src/grammar/RuleFlowLanguageParser");
|
|
8
|
+
function lex(input) {
|
|
9
|
+
const cs = antlr4ts_1.CharStreams.fromString(input);
|
|
10
|
+
const lexer = new RuleFlowLanguageLexer_1.RuleFlowLanguageLexer(cs);
|
|
11
|
+
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
|
|
12
|
+
tokens.fill();
|
|
13
|
+
const vocab = RuleFlowLanguageParser_1.RuleFlowLanguageParser.VOCABULARY;
|
|
14
|
+
return tokens.getTokens().map((t) => ({
|
|
15
|
+
type: t.type,
|
|
16
|
+
name: vocab.getSymbolicName(t.type),
|
|
17
|
+
lit: vocab.getLiteralName(t.type),
|
|
18
|
+
text: t.text,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
function parse(input) {
|
|
22
|
+
const cs = antlr4ts_1.CharStreams.fromString(input);
|
|
23
|
+
const lexer = new RuleFlowLanguageLexer_1.RuleFlowLanguageLexer(cs);
|
|
24
|
+
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
|
|
25
|
+
const parser = new RuleFlowLanguageParser_1.RuleFlowLanguageParser(tokens);
|
|
26
|
+
parser.buildParseTree = true;
|
|
27
|
+
const tree = parser.parse();
|
|
28
|
+
return { treeType: tree?.constructor?.name, ctxRuleIndex: tree?.ruleIndex };
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=debug.js.map
|
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AAW,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropertyNotFoundError.d.ts","sourceRoot":"","sources":["../../src/errors/PropertyNotFoundError.ts"],"names":[],"mappings":"AAAA,qBAAa,qBAAsB,SAAQ,KAAK;aAClB,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM;CAI7C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertyNotFoundError = void 0;
|
|
4
|
+
class PropertyNotFoundError extends Error {
|
|
5
|
+
constructor(property) {
|
|
6
|
+
super(`${property} field cannot be found`);
|
|
7
|
+
Object.defineProperty(this, "property", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: property
|
|
12
|
+
});
|
|
13
|
+
this.name = 'PropertyNotFoundError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.PropertyNotFoundError = PropertyNotFoundError;
|
|
17
|
+
//# sourceMappingURL=PropertyNotFoundError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropertyNotFoundError.js","sourceRoot":"","sources":["../../src/errors/PropertyNotFoundError.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAA4B,QAAgB;QAC1C,KAAK,CAAC,GAAG,QAAQ,wBAAwB,CAAC,CAAC;QADjC;;;;mBAAgB,QAAQ;WAAQ;QAE1C,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Visitor } from '../visitors/Visitor';
|
|
2
|
+
import { AggregationContext } from '../generated/src/grammar/RuleFlowLanguageParser';
|
|
3
|
+
export declare class AggregationEvaluator {
|
|
4
|
+
evaluate(ctx: AggregationContext, visitor: Visitor): any;
|
|
5
|
+
private evalPredicate;
|
|
6
|
+
private compareValues;
|
|
7
|
+
private identity;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=AggregationEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AggregationEvaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/AggregationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAA0B,kBAAkB,EAAgB,MAAM,iDAAiD,CAAC;AAE3H,qBAAa,oBAAoB;IAC7B,QAAQ,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,GAAG;IAyCxD,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,QAAQ;CAKnB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregationEvaluator = void 0;
|
|
4
|
+
const RuleFlowLanguageParser_1 = require("../generated/src/grammar/RuleFlowLanguageParser");
|
|
5
|
+
class AggregationEvaluator {
|
|
6
|
+
evaluate(ctx, visitor) {
|
|
7
|
+
const valueExpr = ctx._value ?? ctx.expr(0);
|
|
8
|
+
const listVal = visitor.visit(valueExpr);
|
|
9
|
+
if (!Array.isArray(listVal)) {
|
|
10
|
+
throw new Error(`${ctx._value?.text ?? valueExpr?.text ?? 'value'} is not a Collection`);
|
|
11
|
+
}
|
|
12
|
+
const op = ctx._op?.type;
|
|
13
|
+
const pred = ctx._predicate ?? (ctx.expr().length > 1 ? ctx.expr(1) : undefined);
|
|
14
|
+
switch (op) {
|
|
15
|
+
case RuleFlowLanguageParser_1.RuleFlowLanguageParser.K_ALL:
|
|
16
|
+
return listVal.every((item) => Boolean(this.evalPredicate(item, visitor, pred)));
|
|
17
|
+
case RuleFlowLanguageParser_1.RuleFlowLanguageParser.K_ANY:
|
|
18
|
+
return listVal.some((item) => Boolean(this.evalPredicate(item, visitor, pred)));
|
|
19
|
+
case RuleFlowLanguageParser_1.RuleFlowLanguageParser.K_NONE:
|
|
20
|
+
return !listVal.some((item) => Boolean(this.evalPredicate(item, visitor, pred)));
|
|
21
|
+
case RuleFlowLanguageParser_1.RuleFlowLanguageParser.K_COUNT: {
|
|
22
|
+
if (!pred)
|
|
23
|
+
return listVal.length;
|
|
24
|
+
const count = listVal.filter((item) => Boolean(this.evalPredicate(item, visitor, pred))).length;
|
|
25
|
+
return count;
|
|
26
|
+
}
|
|
27
|
+
case RuleFlowLanguageParser_1.RuleFlowLanguageParser.K_AVERAGE: {
|
|
28
|
+
const total = listVal.length || 1;
|
|
29
|
+
const count = pred ? listVal.filter((item) => Boolean(this.evalPredicate(item, visitor, pred))).length : total;
|
|
30
|
+
const ratio = count / total;
|
|
31
|
+
return Math.floor(ratio * 1000) / 1000;
|
|
32
|
+
}
|
|
33
|
+
case RuleFlowLanguageParser_1.RuleFlowLanguageParser.K_DISTINCT: {
|
|
34
|
+
if (!pred)
|
|
35
|
+
return Array.from(new Set(listVal.map((x) => this.identity(x))));
|
|
36
|
+
if (pred instanceof RuleFlowLanguageParser_1.ValueContext) {
|
|
37
|
+
return Array.from(new Set(listVal.map((x) => this.identity(x))));
|
|
38
|
+
}
|
|
39
|
+
const mapped = listVal.map((item) => this.evalPredicate(item, visitor, pred));
|
|
40
|
+
return Array.from(new Set(mapped.map((x) => this.identity(x))));
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Operation not supported: ${ctx._op?.text}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
evalPredicate(item, visitor, pred) {
|
|
47
|
+
if (!pred)
|
|
48
|
+
return true;
|
|
49
|
+
if (pred instanceof RuleFlowLanguageParser_1.ValueContext) {
|
|
50
|
+
const predicateValue = new visitor.constructor(visitor.getRoot(), visitor.getLists(), visitor.getRoot()).visit(pred);
|
|
51
|
+
return this.compareValues(item, predicateValue);
|
|
52
|
+
}
|
|
53
|
+
const data = (item && typeof item === 'object') ? item : { value: item };
|
|
54
|
+
return new visitor.constructor(data, visitor.getLists(), visitor.getRoot()).visit(pred);
|
|
55
|
+
}
|
|
56
|
+
compareValues(a, b) {
|
|
57
|
+
if (a == null && b == null)
|
|
58
|
+
return true;
|
|
59
|
+
if (a == null || b == null)
|
|
60
|
+
return false;
|
|
61
|
+
if (typeof a === 'number' && typeof b === 'number')
|
|
62
|
+
return a === b;
|
|
63
|
+
return String(a) === String(b);
|
|
64
|
+
}
|
|
65
|
+
identity(x) {
|
|
66
|
+
if (x == null)
|
|
67
|
+
return x;
|
|
68
|
+
if (typeof x === 'object')
|
|
69
|
+
return JSON.stringify(x);
|
|
70
|
+
return x;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.AggregationEvaluator = AggregationEvaluator;
|
|
74
|
+
//# sourceMappingURL=AggregationEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AggregationEvaluator.js","sourceRoot":"","sources":["../../src/evaluator/AggregationEvaluator.ts"],"names":[],"mappings":";;;AACA,4FAA2H;AAE3H,MAAa,oBAAoB;IAC7B,QAAQ,CAAC,GAAuB,EAAE,OAAgB;QAC9C,MAAM,SAAS,GAAI,GAAW,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,GAAI,GAAW,CAAC,MAAM,EAAE,IAAI,IAAK,SAAiB,EAAE,IAAI,IAAI,OAAO,sBAAsB,CA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AAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAEO,QAAQ,CAAC,CAAM;QACnB,IAAI,CAAC,IAAI,IAAI;YAAE,OAAO,CAAC,CAAC;QACxB,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpD,OAAO,CAAC,CAAC;IACb,CAAC;CACJ;AAlED,oDAkEC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Visitor } from '../visitors/Visitor';
|
|
2
|
+
import type { BinaryAndContext } from '../generated/src/grammar/RuleFlowLanguageParser';
|
|
3
|
+
export declare class BinaryAndEvaluator {
|
|
4
|
+
evaluate(ctx: BinaryAndContext, visitor: Visitor): boolean;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=BinaryAndEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryAndEvaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/BinaryAndEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iDAAiD,CAAC;AAExF,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;CAM3D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinaryAndEvaluator = void 0;
|
|
4
|
+
class BinaryAndEvaluator {
|
|
5
|
+
evaluate(ctx, visitor) {
|
|
6
|
+
const left = Boolean(visitor.visit(ctx.expr(0)));
|
|
7
|
+
if (!left)
|
|
8
|
+
return false; // short-circuit
|
|
9
|
+
const right = Boolean(visitor.visit(ctx.expr(1)));
|
|
10
|
+
return left && right;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BinaryAndEvaluator = BinaryAndEvaluator;
|
|
14
|
+
//# sourceMappingURL=BinaryAndEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryAndEvaluator.js","sourceRoot":"","sources":["../../src/evaluator/BinaryAndEvaluator.ts"],"names":[],"mappings":";;;AAGA,MAAa,kBAAkB;IAC7B,QAAQ,CAAC,GAAqB,EAAE,OAAgB;QAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC,CAAC,gBAAgB;QACzC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,OAAO,IAAI,IAAI,KAAK,CAAC;IACvB,CAAC;CACF;AAPD,gDAOC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Visitor } from '../visitors/Visitor';
|
|
2
|
+
import type { BinaryOrContext } from '../generated/src/grammar/RuleFlowLanguageParser';
|
|
3
|
+
export declare class BinaryOrEvaluator {
|
|
4
|
+
evaluate(ctx: BinaryOrContext, visitor: Visitor): boolean;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=BinaryOrEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryOrEvaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/BinaryOrEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAEvF,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;CAM1D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinaryOrEvaluator = void 0;
|
|
4
|
+
class BinaryOrEvaluator {
|
|
5
|
+
evaluate(ctx, visitor) {
|
|
6
|
+
const left = Boolean(visitor.visit(ctx.expr(0)));
|
|
7
|
+
if (left)
|
|
8
|
+
return true; // short-circuit
|
|
9
|
+
const right = Boolean(visitor.visit(ctx.expr(1)));
|
|
10
|
+
return left || right;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BinaryOrEvaluator = BinaryOrEvaluator;
|
|
14
|
+
//# sourceMappingURL=BinaryOrEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryOrEvaluator.js","sourceRoot":"","sources":["../../src/evaluator/BinaryOrEvaluator.ts"],"names":[],"mappings":";;;AAGA,MAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAoB,EAAE,OAAgB;QAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC,CAAC,gBAAgB;QACvC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,OAAO,IAAI,IAAI,KAAK,CAAC;IACvB,CAAC;CACF;AAPD,8CAOC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Visitor } from '../visitors/Visitor';
|
|
2
|
+
export declare class ComparatorEvaluator {
|
|
3
|
+
evaluate(ctx: any, visitor: Visitor): boolean;
|
|
4
|
+
private compareNull;
|
|
5
|
+
private compareNumber;
|
|
6
|
+
private compareString;
|
|
7
|
+
private coerceToDate;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ComparatorEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComparatorEvaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/ComparatorEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IA+B7C,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,YAAY;CAQrB"}
|