@legalplace/conditions-runner 2.2.20-staging.0 → 2.2.20
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/CHANGELOG.md +8 -0
- package/dist/ConditionsRunner.d.ts +0 -1
- package/dist/ConditionsRunner.js +1 -23
- package/dist/ConditionsRunner.test.js +0 -281
- package/package.json +7 -6
- package/src/ConditionsRunner.test.ts +1 -361
- package/src/ConditionsRunner.ts +1 -62
- package/dist/ComparatorResolver.d.ts +0 -22
- package/dist/ComparatorResolver.js +0 -180
- package/dist/ScopedLeafEvaluator.d.ts +0 -3
- package/dist/ScopedLeafEvaluator.js +0 -106
- package/src/ComparatorResolver.ts +0 -338
- package/src/ScopedLeafEvaluator.ts +0 -236
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.2.20](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/conditions-runner@2.2.19...@legalplace/conditions-runner@2.2.20) (2026-08-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @legalplace/conditions-runner
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [2.2.19](https://git.legalplace.eu/legalplace/monorepo/compare/@legalplace/conditions-runner@2.2.18...@legalplace/conditions-runner@2.2.19) (2026-08-26)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @legalplace/conditions-runner
|
|
@@ -15,6 +15,5 @@ declare class ConditionsRunner {
|
|
|
15
15
|
dataMap: ConditionDataMap;
|
|
16
16
|
conditions: ConditionV3;
|
|
17
17
|
}, id: number, index: number, conditionType: "options" | "optionValidator" | "variables" | "prefillers" | "variableValidator" | "sections" | "documents"): any;
|
|
18
|
-
private buildComparatorResolverContext;
|
|
19
18
|
}
|
|
20
19
|
export default ConditionsRunner;
|
package/dist/ConditionsRunner.js
CHANGED
|
@@ -4,10 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const lplogic_1 = __importDefault(require("@legalplace/lplogic"));
|
|
7
|
-
const referencesparser_1 = require("@legalplace/referencesparser");
|
|
8
7
|
const DataPopulator_1 = __importDefault(require("./DataPopulator"));
|
|
9
|
-
const ScopedLeafEvaluator_1 = require("./ScopedLeafEvaluator");
|
|
10
|
-
const ComparatorResolver_1 = require("./ComparatorResolver");
|
|
11
8
|
class ConditionsRunner {
|
|
12
9
|
constructor(references, ovc) {
|
|
13
10
|
this.executeConditionMemo = {};
|
|
@@ -80,28 +77,9 @@ class ConditionsRunner {
|
|
|
80
77
|
else if (conditionType === "sections" || conditionType === "documents") {
|
|
81
78
|
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
|
|
82
79
|
}
|
|
83
|
-
const
|
|
84
|
-
const deps = { references: this.references, ovc: this.ovc };
|
|
85
|
-
const aggregatedConditions = (0, ScopedLeafEvaluator_1.aggregateScopedLeaves)((0, referencesparser_1.lowerScope)(condition.conditions), new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap).getData(), resolverContext, deps);
|
|
86
|
-
const resolvedConditions = (0, ComparatorResolver_1.resolveConditionComparators)(aggregatedConditions, resolverContext, deps);
|
|
87
|
-
const result = (0, lplogic_1.default)(resolvedConditions, currentData);
|
|
80
|
+
const result = (0, lplogic_1.default)(condition.conditions, currentData);
|
|
88
81
|
this.executeConditionMemo[memoizedKey] = result;
|
|
89
82
|
return result;
|
|
90
83
|
}
|
|
91
|
-
buildComparatorResolverContext(id, index, conditionType) {
|
|
92
|
-
if (conditionType === "options" || conditionType === "optionValidator") {
|
|
93
|
-
return { optionId: id, index, conditionOptionId: id };
|
|
94
|
-
}
|
|
95
|
-
if (conditionType === "variables" ||
|
|
96
|
-
conditionType === "prefillers" ||
|
|
97
|
-
conditionType === "variableValidator") {
|
|
98
|
-
return {
|
|
99
|
-
optionId: (0, ComparatorResolver_1.getConditionVariableOptionId)(this.references, id),
|
|
100
|
-
index,
|
|
101
|
-
conditionVariableId: id,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return { optionId: id, index };
|
|
105
|
-
}
|
|
106
84
|
}
|
|
107
85
|
exports.default = ConditionsRunner;
|
|
@@ -3,292 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const referencesparser_1 = require("@legalplace/referencesparser");
|
|
7
6
|
const ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
|
|
8
|
-
const ComparatorResolver_1 = require("./ComparatorResolver");
|
|
9
7
|
const inputs_type_json_1 = __importDefault(require("./fixtures/inputs-type.json"));
|
|
10
8
|
const references_json_1 = __importDefault(require("./fixtures/references.json"));
|
|
11
|
-
const emptyOptionRelations = {
|
|
12
|
-
options: [],
|
|
13
|
-
variables: [],
|
|
14
|
-
sections: {},
|
|
15
|
-
documents: [],
|
|
16
|
-
prefillers: [],
|
|
17
|
-
validators: { options: [], variables: [] },
|
|
18
|
-
parents: [],
|
|
19
|
-
children: { options: [], variables: [] },
|
|
20
|
-
dependants: [],
|
|
21
|
-
};
|
|
22
|
-
const buildRelatedDocumentReferences = () => ({
|
|
23
|
-
options: {
|
|
24
|
-
2: {
|
|
25
|
-
meta: {
|
|
26
|
-
id: 2,
|
|
27
|
-
type: "static",
|
|
28
|
-
label: "Partner",
|
|
29
|
-
step: "*",
|
|
30
|
-
multiple: { enabled: true },
|
|
31
|
-
},
|
|
32
|
-
options: [3, 4],
|
|
33
|
-
variables: [],
|
|
34
|
-
},
|
|
35
|
-
3: {
|
|
36
|
-
meta: { id: 3, type: "radio", label: "Yes", step: "*" },
|
|
37
|
-
options: [],
|
|
38
|
-
variables: [],
|
|
39
|
-
},
|
|
40
|
-
4: {
|
|
41
|
-
meta: { id: 4, type: "radio", label: "No", step: "*" },
|
|
42
|
-
options: [],
|
|
43
|
-
variables: [],
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
variables: {},
|
|
47
|
-
outputs: {},
|
|
48
|
-
boxes: {},
|
|
49
|
-
documents: {
|
|
50
|
-
annex: {
|
|
51
|
-
name: "Annex",
|
|
52
|
-
params: { multiple: { enabled: true, repeatOption: 2 } },
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
sections: {},
|
|
56
|
-
relations: {
|
|
57
|
-
options: {
|
|
58
|
-
2: {
|
|
59
|
-
...emptyOptionRelations,
|
|
60
|
-
children: { options: [3, 4], variables: [] },
|
|
61
|
-
},
|
|
62
|
-
3: { ...emptyOptionRelations, parents: [2] },
|
|
63
|
-
4: { ...emptyOptionRelations, parents: [2] },
|
|
64
|
-
},
|
|
65
|
-
variables: {},
|
|
66
|
-
sections: {},
|
|
67
|
-
},
|
|
68
|
-
conditions: {
|
|
69
|
-
options: {},
|
|
70
|
-
variables: {},
|
|
71
|
-
documents: {},
|
|
72
|
-
sections: { main: {} },
|
|
73
|
-
prefillers: {},
|
|
74
|
-
validators: { options: {}, variables: {} },
|
|
75
|
-
},
|
|
76
|
-
defaults: {},
|
|
77
|
-
evaluations: {},
|
|
78
|
-
optionTags: {},
|
|
79
|
-
variableTags: {},
|
|
80
|
-
});
|
|
81
|
-
const buildSiblingVariableReferences = () => ({
|
|
82
|
-
options: {
|
|
83
|
-
10: {
|
|
84
|
-
meta: {
|
|
85
|
-
id: 10,
|
|
86
|
-
type: "static",
|
|
87
|
-
label: "Repeat",
|
|
88
|
-
step: "*",
|
|
89
|
-
multiple: { enabled: true },
|
|
90
|
-
},
|
|
91
|
-
options: [],
|
|
92
|
-
variables: [3, 4],
|
|
93
|
-
},
|
|
94
|
-
20: {
|
|
95
|
-
meta: { id: 20, type: "static", label: "Other", step: "*" },
|
|
96
|
-
options: [],
|
|
97
|
-
variables: [5],
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
variables: {
|
|
101
|
-
3: { meta: { id: 3, type: "string", label: "Left" }, options: [] },
|
|
102
|
-
4: { meta: { id: 4, type: "string", label: "Right" }, options: [] },
|
|
103
|
-
5: { meta: { id: 5, type: "string", label: "Elsewhere" }, options: [] },
|
|
104
|
-
},
|
|
105
|
-
outputs: {},
|
|
106
|
-
boxes: {},
|
|
107
|
-
documents: {},
|
|
108
|
-
sections: {},
|
|
109
|
-
relations: {
|
|
110
|
-
options: {
|
|
111
|
-
10: {
|
|
112
|
-
...emptyOptionRelations,
|
|
113
|
-
children: { options: [], variables: [3, 4] },
|
|
114
|
-
},
|
|
115
|
-
20: {
|
|
116
|
-
...emptyOptionRelations,
|
|
117
|
-
children: { options: [], variables: [5] },
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
variables: {
|
|
121
|
-
3: { ...emptyOptionRelations, parents: [10] },
|
|
122
|
-
4: { ...emptyOptionRelations, parents: [10] },
|
|
123
|
-
5: { ...emptyOptionRelations, parents: [20] },
|
|
124
|
-
},
|
|
125
|
-
sections: {},
|
|
126
|
-
},
|
|
127
|
-
conditions: {
|
|
128
|
-
options: {},
|
|
129
|
-
variables: {},
|
|
130
|
-
documents: {},
|
|
131
|
-
sections: { main: {} },
|
|
132
|
-
prefillers: {},
|
|
133
|
-
validators: { options: {}, variables: {} },
|
|
134
|
-
},
|
|
135
|
-
defaults: {},
|
|
136
|
-
evaluations: {},
|
|
137
|
-
optionTags: {},
|
|
138
|
-
variableTags: {},
|
|
139
|
-
});
|
|
140
|
-
const relatedOvc = {
|
|
141
|
-
options: {
|
|
142
|
-
2: [true, true],
|
|
143
|
-
3: [true, false],
|
|
144
|
-
4: [false, true],
|
|
145
|
-
},
|
|
146
|
-
variables: {},
|
|
147
|
-
};
|
|
148
|
-
const siblingOvc = {
|
|
149
|
-
options: {
|
|
150
|
-
10: [true, true, true],
|
|
151
|
-
20: [true],
|
|
152
|
-
},
|
|
153
|
-
variables: {
|
|
154
|
-
3: ["same", "b", "c"],
|
|
155
|
-
4: ["same", "y", "c"],
|
|
156
|
-
5: ["solo-a", "solo-b"],
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
const mappedCondition = (conditions) => ({
|
|
160
|
-
dataMap: (0, referencesparser_1.extractConditionDataMap)(conditions),
|
|
161
|
-
conditions,
|
|
162
|
-
});
|
|
163
9
|
describe("ConditionsRunner class", () => {
|
|
164
10
|
it("should not raise error when instanciating class", () => {
|
|
165
11
|
expect(new ConditionsRunner_1.default(references_json_1.default, inputs_type_json_1.default)).toBeDefined();
|
|
166
12
|
});
|
|
167
|
-
it("slices related document conditions to the current occurrence", () => {
|
|
168
|
-
const runner = new ConditionsRunner_1.default(buildRelatedDocumentReferences(), relatedOvc);
|
|
169
|
-
const condition = mappedCondition({
|
|
170
|
-
selected: [{ var: "o.3" }],
|
|
171
|
-
scope: "related",
|
|
172
|
-
});
|
|
173
|
-
expect(runner.executeCondition(condition, 2, 0, "documents")).toBe(true);
|
|
174
|
-
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
it("evaluates selected + first against the first row after id/index slicing", () => {
|
|
177
|
-
const runner = new ConditionsRunner_1.default(buildRelatedDocumentReferences(), relatedOvc);
|
|
178
|
-
const condition = mappedCondition({
|
|
179
|
-
selected: [{ var: "o.3" }],
|
|
180
|
-
scope: "first",
|
|
181
|
-
});
|
|
182
|
-
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(true);
|
|
183
|
-
});
|
|
184
|
-
it("related sibling [var:N] uses the current occurrence index", () => {
|
|
185
|
-
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), siblingOvc);
|
|
186
|
-
const condition = mappedCondition({
|
|
187
|
-
"=": [{ var: "v.3" }, "[var:4]"],
|
|
188
|
-
scope: "related",
|
|
189
|
-
});
|
|
190
|
-
expect(runner.executeCondition(condition, 3, 0, "variables")).toBe(true);
|
|
191
|
-
expect(runner.executeCondition(condition, 3, 1, "variables")).toBe(false);
|
|
192
|
-
expect(runner.executeCondition(condition, 3, 2, "variables")).toBe(true);
|
|
193
|
-
});
|
|
194
|
-
it("first-scoped sibling [var:N] uses occurrence 0", () => {
|
|
195
|
-
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), siblingOvc);
|
|
196
|
-
const condition = mappedCondition({
|
|
197
|
-
"=": [{ var: "v.3" }, "[var:4]"],
|
|
198
|
-
scope: "first",
|
|
199
|
-
});
|
|
200
|
-
expect(runner.executeCondition(condition, 3, 2, "variables")).toBe(true);
|
|
201
|
-
});
|
|
202
|
-
it("all-scope sibling [var:N] is pairwise true when every row matches", () => {
|
|
203
|
-
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), {
|
|
204
|
-
options: { 10: [true, true], 20: [true] },
|
|
205
|
-
variables: {
|
|
206
|
-
3: [1, 2],
|
|
207
|
-
4: [2, 3],
|
|
208
|
-
5: ["solo-a"],
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
const condition = mappedCondition({
|
|
212
|
-
"<": [{ var: "v.3" }, "[var:4]"],
|
|
213
|
-
scope: "all",
|
|
214
|
-
});
|
|
215
|
-
expect(runner.executeCondition(condition, 3, 0, "options")).toBe(true);
|
|
216
|
-
});
|
|
217
|
-
it("all-scope sibling [var:N] is pairwise false when a row fails", () => {
|
|
218
|
-
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), {
|
|
219
|
-
options: { 10: [true, true], 20: [true] },
|
|
220
|
-
variables: {
|
|
221
|
-
3: [1, 5],
|
|
222
|
-
4: [2, 3],
|
|
223
|
-
5: ["solo-a"],
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
const condition = mappedCondition({
|
|
227
|
-
"<": [{ var: "v.3" }, "[var:4]"],
|
|
228
|
-
scope: "all",
|
|
229
|
-
});
|
|
230
|
-
expect(runner.executeCondition(condition, 3, 0, "options")).toBe(false);
|
|
231
|
-
});
|
|
232
|
-
it("any-scope sibling [var:N] succeeds on a later pairwise row", () => {
|
|
233
|
-
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), {
|
|
234
|
-
options: { 10: [true, true], 20: [true] },
|
|
235
|
-
variables: {
|
|
236
|
-
3: [5, 1],
|
|
237
|
-
4: [2, 10],
|
|
238
|
-
5: ["solo-a"],
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
const condition = mappedCondition({
|
|
242
|
-
"<": [{ var: "v.3" }, "[var:4]"],
|
|
243
|
-
scope: "any",
|
|
244
|
-
});
|
|
245
|
-
expect(runner.executeCondition(condition, 5, 0, "options")).toBe(true);
|
|
246
|
-
});
|
|
247
|
-
it("joins non-sibling [var:N] values instead of slicing by row", () => {
|
|
248
|
-
const references = buildSiblingVariableReferences();
|
|
249
|
-
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
250
|
-
"=": [{ var: "v.3" }, "[var:5]"],
|
|
251
|
-
scope: "related",
|
|
252
|
-
}), { optionId: 10, index: 2, conditionVariableId: 3 }, { references, ovc: siblingOvc });
|
|
253
|
-
expect(resolved).toEqual({
|
|
254
|
-
"=": [{ var: "v.3" }, "solo-a, solo-b"],
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
describe("resolveConditionComparators", () => {
|
|
259
|
-
const references = buildSiblingVariableReferences();
|
|
260
|
-
const deps = { references, ovc: siblingOvc };
|
|
261
|
-
it("related leaf: sibling [var:N] uses the current occurrence index", () => {
|
|
262
|
-
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
263
|
-
"=": [{ var: "v.3" }, "[var:4]"],
|
|
264
|
-
scope: "related",
|
|
265
|
-
}), { optionId: 10, index: 2, conditionVariableId: 3 }, deps);
|
|
266
|
-
expect(resolved).toEqual({
|
|
267
|
-
"=": [{ var: "v.3" }, "c"],
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
it("first-scoped leaf: sibling [var:N] uses occurrence 0", () => {
|
|
271
|
-
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
272
|
-
"=": [{ var: "v.3" }, "[var:4]"],
|
|
273
|
-
scope: "first",
|
|
274
|
-
}), { optionId: 10, index: 2, conditionVariableId: 3 }, deps);
|
|
275
|
-
expect(resolved).toEqual({
|
|
276
|
-
"=-first": [{ var: "v.3" }, "same"],
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
it("uses empty sentinel for missing sibling values", () => {
|
|
280
|
-
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
281
|
-
"=": [{ var: "v.3" }, "[var:4]"],
|
|
282
|
-
scope: "related",
|
|
283
|
-
}), { optionId: 10, index: 5, conditionVariableId: 3 }, {
|
|
284
|
-
references,
|
|
285
|
-
ovc: {
|
|
286
|
-
options: siblingOvc.options,
|
|
287
|
-
variables: { 3: ["a"], 4: ["b"], 5: [] },
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
expect(resolved).toEqual({
|
|
291
|
-
"=": [{ var: "v.3" }, ComparatorResolver_1.CONDITION_COMPARATOR_EMPTY_SENTINEL],
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
13
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/conditions-runner",
|
|
3
|
-
"version": "2.2.20
|
|
3
|
+
"version": "2.2.20",
|
|
4
4
|
"description": "Package containing method to execute conditions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/ConditionsRunner.js",
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"prettier": "@legalplace/prettier-config",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@legalplace/lplogic": "2.3.
|
|
25
|
-
"@legalplace/models-v3-types": "^5.17.
|
|
26
|
-
"@legalplace/referencesparser": "^3.2.
|
|
24
|
+
"@legalplace/lplogic": "2.3.1",
|
|
25
|
+
"@legalplace/models-v3-types": "^5.17.22",
|
|
26
|
+
"@legalplace/referencesparser": "^3.2.42"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@legalplace/prettier-config": "^2.1.3",
|
|
30
|
-
"@legalplace/types": "^2.22.
|
|
30
|
+
"@legalplace/types": "^2.22.12",
|
|
31
31
|
"ts-node": "^10.8.1"
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "717a08baa101e1dcdead28714410c726f6cf9166"
|
|
33
34
|
}
|