@legalplace/conditions-runner 2.3.3 → 2.3.4-staging.1
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/dist/ConditionsRunner.d.ts +1 -1
- package/dist/ConditionsRunner.js +9 -6
- package/dist/ConditionsRunner.test.js +23 -13
- package/dist/DataPopulator.d.ts +2 -1
- package/dist/DataPopulator.js +5 -3
- package/package.json +6 -7
- package/src/ConditionsRunner.test.ts +28 -13
- package/src/ConditionsRunner.ts +24 -5
- package/src/DataPopulator.ts +14 -3
|
@@ -14,7 +14,7 @@ declare class ConditionsRunner {
|
|
|
14
14
|
executeCondition(condition: {
|
|
15
15
|
dataMap: ConditionDataMap;
|
|
16
16
|
conditions: ConditionV3;
|
|
17
|
-
}, id: number, index: number, conditionType: "options" | "optionValidator" | "variables" | "prefillers" | "variableValidator" | "sections" | "documents"): any;
|
|
17
|
+
}, id: number, index: number, conditionType: "options" | "optionValidator" | "variables" | "prefillers" | "variableValidator" | "sections" | "documents" | "multiples", documentSlug?: string): any;
|
|
18
18
|
private buildComparatorResolverContext;
|
|
19
19
|
}
|
|
20
20
|
export default ConditionsRunner;
|
package/dist/ConditionsRunner.js
CHANGED
|
@@ -11,7 +11,7 @@ const ComparatorResolver_1 = require("./ComparatorResolver");
|
|
|
11
11
|
class ConditionsRunner {
|
|
12
12
|
constructor(references, ovc) {
|
|
13
13
|
this.executeConditionMemo = {};
|
|
14
|
-
this.buildMemoizeKey = (condition, id, index, conditionType) => `${JSON.stringify(condition)}-${id}-${index}-${conditionType}`;
|
|
14
|
+
this.buildMemoizeKey = (condition, id, index, conditionType, documentSlug) => `${JSON.stringify(condition)}-${id}-${index}-${conditionType}-${documentSlug}`;
|
|
15
15
|
this.references = references;
|
|
16
16
|
this.ovc = ovc;
|
|
17
17
|
}
|
|
@@ -62,23 +62,26 @@ class ConditionsRunner {
|
|
|
62
62
|
}
|
|
63
63
|
return false;
|
|
64
64
|
}
|
|
65
|
-
executeCondition(condition, id, index, conditionType) {
|
|
66
|
-
const memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType);
|
|
65
|
+
executeCondition(condition, id, index, conditionType, documentSlug = "main") {
|
|
66
|
+
const memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType, documentSlug);
|
|
67
67
|
if (this.executeConditionMemo[memoizedKey] !== undefined) {
|
|
68
68
|
return this.executeConditionMemo[memoizedKey];
|
|
69
69
|
}
|
|
70
70
|
let currentData;
|
|
71
71
|
if (conditionType === "options" || conditionType === "optionValidator") {
|
|
72
|
-
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
|
|
72
|
+
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index, documentSlug).getData();
|
|
73
73
|
}
|
|
74
74
|
else if (conditionType === "variables" ||
|
|
75
75
|
conditionType === "prefillers" ||
|
|
76
76
|
conditionType === "variableValidator") {
|
|
77
77
|
const dataId = this.references.relations.variables[id].parents[0];
|
|
78
|
-
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, dataId, index).getData();
|
|
78
|
+
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, dataId, index, documentSlug).getData();
|
|
79
79
|
}
|
|
80
80
|
else if (conditionType === "sections" || conditionType === "documents") {
|
|
81
|
-
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
|
|
81
|
+
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index, documentSlug).getData();
|
|
82
|
+
}
|
|
83
|
+
else if (conditionType === "multiples") {
|
|
84
|
+
currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap).getData();
|
|
82
85
|
}
|
|
83
86
|
const resolverContext = this.buildComparatorResolverContext(id, index, conditionType);
|
|
84
87
|
const deps = { references: this.references, ovc: this.ovc };
|
|
@@ -164,7 +164,7 @@ describe("ConditionsRunner class", () => {
|
|
|
164
164
|
it("should not raise error when instanciating class", () => {
|
|
165
165
|
expect(new ConditionsRunner_1.default(references_json_1.default, inputs_type_json_1.default)).toBeDefined();
|
|
166
166
|
});
|
|
167
|
-
it("
|
|
167
|
+
it("should slice the condition to the current occurrence when the scope is related on a document", () => {
|
|
168
168
|
const runner = new ConditionsRunner_1.default(buildRelatedDocumentReferences(), relatedOvc);
|
|
169
169
|
const condition = mappedCondition({
|
|
170
170
|
selected: [{ var: "o.3" }],
|
|
@@ -173,7 +173,17 @@ describe("ConditionsRunner class", () => {
|
|
|
173
173
|
expect(runner.executeCondition(condition, 2, 0, "documents")).toBe(true);
|
|
174
174
|
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(false);
|
|
175
175
|
});
|
|
176
|
-
it("
|
|
176
|
+
it("should evaluate the condition unsliced when the target type is multiples", () => {
|
|
177
|
+
const runner = new ConditionsRunner_1.default(buildRelatedDocumentReferences(), relatedOvc);
|
|
178
|
+
const condition = mappedCondition({
|
|
179
|
+
selected: [{ var: "o.3" }],
|
|
180
|
+
scope: "any",
|
|
181
|
+
});
|
|
182
|
+
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(false);
|
|
183
|
+
expect(runner.executeCondition(condition, 2, 1, "multiples")).toBe(true);
|
|
184
|
+
expect(runner.executeCondition(condition, 2, 0, "multiples")).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
it("should evaluate against the first occurrence when the scope is first", () => {
|
|
177
187
|
const runner = new ConditionsRunner_1.default(buildRelatedDocumentReferences(), relatedOvc);
|
|
178
188
|
const condition = mappedCondition({
|
|
179
189
|
selected: [{ var: "o.3" }],
|
|
@@ -181,7 +191,7 @@ describe("ConditionsRunner class", () => {
|
|
|
181
191
|
});
|
|
182
192
|
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(true);
|
|
183
193
|
});
|
|
184
|
-
it("
|
|
194
|
+
it("should bind a sibling [var:N] to the current occurrence when the scope is related", () => {
|
|
185
195
|
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), siblingOvc);
|
|
186
196
|
const condition = mappedCondition({
|
|
187
197
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
@@ -191,7 +201,7 @@ describe("ConditionsRunner class", () => {
|
|
|
191
201
|
expect(runner.executeCondition(condition, 3, 1, "variables")).toBe(false);
|
|
192
202
|
expect(runner.executeCondition(condition, 3, 2, "variables")).toBe(true);
|
|
193
203
|
});
|
|
194
|
-
it("
|
|
204
|
+
it("should bind a sibling [var:N] to occurrence 0 when the scope is first", () => {
|
|
195
205
|
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), siblingOvc);
|
|
196
206
|
const condition = mappedCondition({
|
|
197
207
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
@@ -199,7 +209,7 @@ describe("ConditionsRunner class", () => {
|
|
|
199
209
|
});
|
|
200
210
|
expect(runner.executeCondition(condition, 3, 2, "variables")).toBe(true);
|
|
201
211
|
});
|
|
202
|
-
it("
|
|
212
|
+
it("should return true when the scope is all and every pairwise row matches", () => {
|
|
203
213
|
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), {
|
|
204
214
|
options: { 10: [true, true], 20: [true] },
|
|
205
215
|
variables: {
|
|
@@ -214,7 +224,7 @@ describe("ConditionsRunner class", () => {
|
|
|
214
224
|
});
|
|
215
225
|
expect(runner.executeCondition(condition, 3, 0, "options")).toBe(true);
|
|
216
226
|
});
|
|
217
|
-
it("
|
|
227
|
+
it("should return false when the scope is all and a pairwise row fails", () => {
|
|
218
228
|
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), {
|
|
219
229
|
options: { 10: [true, true], 20: [true] },
|
|
220
230
|
variables: {
|
|
@@ -229,7 +239,7 @@ describe("ConditionsRunner class", () => {
|
|
|
229
239
|
});
|
|
230
240
|
expect(runner.executeCondition(condition, 3, 0, "options")).toBe(false);
|
|
231
241
|
});
|
|
232
|
-
it("
|
|
242
|
+
it("should return true when the scope is any and a later pairwise row matches", () => {
|
|
233
243
|
const runner = new ConditionsRunner_1.default(buildSiblingVariableReferences(), {
|
|
234
244
|
options: { 10: [true, true], 20: [true] },
|
|
235
245
|
variables: {
|
|
@@ -244,7 +254,7 @@ describe("ConditionsRunner class", () => {
|
|
|
244
254
|
});
|
|
245
255
|
expect(runner.executeCondition(condition, 5, 0, "options")).toBe(true);
|
|
246
256
|
});
|
|
247
|
-
it("
|
|
257
|
+
it("should join every value when the [var:N] reference is not a sibling of the multiple", () => {
|
|
248
258
|
const references = buildSiblingVariableReferences();
|
|
249
259
|
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
250
260
|
"=": [{ var: "v.3" }, "[var:5]"],
|
|
@@ -258,7 +268,7 @@ describe("ConditionsRunner class", () => {
|
|
|
258
268
|
describe("resolveConditionComparators", () => {
|
|
259
269
|
const references = buildSiblingVariableReferences();
|
|
260
270
|
const deps = { references, ovc: siblingOvc };
|
|
261
|
-
it("
|
|
271
|
+
it("should resolve a sibling [var:N] to the current occurrence when the leaf scope is related", () => {
|
|
262
272
|
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
263
273
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
264
274
|
scope: "related",
|
|
@@ -267,7 +277,7 @@ describe("resolveConditionComparators", () => {
|
|
|
267
277
|
"=": [{ var: "v.3" }, "c"],
|
|
268
278
|
});
|
|
269
279
|
});
|
|
270
|
-
it("
|
|
280
|
+
it("should resolve a sibling [var:N] to occurrence 0 when the leaf scope is first", () => {
|
|
271
281
|
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
272
282
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
273
283
|
scope: "first",
|
|
@@ -276,7 +286,7 @@ describe("resolveConditionComparators", () => {
|
|
|
276
286
|
"=-first": [{ var: "v.3" }, "same"],
|
|
277
287
|
});
|
|
278
288
|
});
|
|
279
|
-
it("
|
|
289
|
+
it("should resolve to the empty sentinel when the sibling value is missing", () => {
|
|
280
290
|
const resolved = (0, ComparatorResolver_1.resolveConditionComparators)((0, referencesparser_1.lowerScope)({
|
|
281
291
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
282
292
|
scope: "related",
|
|
@@ -293,7 +303,7 @@ describe("resolveConditionComparators", () => {
|
|
|
293
303
|
});
|
|
294
304
|
});
|
|
295
305
|
describe("includes / does-not-include operators", () => {
|
|
296
|
-
it("
|
|
306
|
+
it("should lower the operator to includes-any when the scope is any", () => {
|
|
297
307
|
expect((0, referencesparser_1.lowerScope)({
|
|
298
308
|
includes: [{ var: "v.1" }, "SARL"],
|
|
299
309
|
scope: "any",
|
|
@@ -301,7 +311,7 @@ describe("includes / does-not-include operators", () => {
|
|
|
301
311
|
"includes-any": [{ var: "v.1" }, "SARL"],
|
|
302
312
|
});
|
|
303
313
|
});
|
|
304
|
-
it("
|
|
314
|
+
it("should lower the operator to does-not-include-first when the scope is first", () => {
|
|
305
315
|
expect((0, referencesparser_1.lowerScope)({
|
|
306
316
|
"does-not-include": [{ var: "v.1" }, "SARL"],
|
|
307
317
|
scope: "first",
|
package/dist/DataPopulator.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ declare class DataPopulator {
|
|
|
9
9
|
private id?;
|
|
10
10
|
private index?;
|
|
11
11
|
private dataMap;
|
|
12
|
+
private documentSlug;
|
|
12
13
|
private data;
|
|
13
|
-
constructor(conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: InputsType, dataMap: ConditionDataMap, id?: number, index?: number);
|
|
14
|
+
constructor(conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: InputsType, dataMap: ConditionDataMap, id?: number, index?: number, documentSlug?: string);
|
|
14
15
|
getData(): Readonly<ConditionData>;
|
|
15
16
|
private populateConditions;
|
|
16
17
|
private getOptionConditions;
|
package/dist/DataPopulator.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class DataPopulator {
|
|
4
|
-
constructor(conditionsRunner, references, ovc, dataMap, id, index) {
|
|
4
|
+
constructor(conditionsRunner, references, ovc, dataMap, id, index, documentSlug = "main") {
|
|
5
5
|
this.data = {
|
|
6
6
|
o: {},
|
|
7
7
|
v: {},
|
|
@@ -11,6 +11,7 @@ class DataPopulator {
|
|
|
11
11
|
v: {},
|
|
12
12
|
},
|
|
13
13
|
};
|
|
14
|
+
this.documentSlug = documentSlug;
|
|
14
15
|
this.id = id;
|
|
15
16
|
this.ovc = ovc;
|
|
16
17
|
this.index = index;
|
|
@@ -156,10 +157,11 @@ class DataPopulator {
|
|
|
156
157
|
return result;
|
|
157
158
|
}
|
|
158
159
|
sectionConditionValue(sectionId) {
|
|
159
|
-
|
|
160
|
+
var _a;
|
|
161
|
+
const conditions = (_a = this.references.conditions.sections[this.documentSlug]) === null || _a === void 0 ? void 0 : _a[sectionId];
|
|
160
162
|
if (conditions === undefined)
|
|
161
163
|
return undefined;
|
|
162
|
-
return this.conditionsRunner.executeCondition(conditions, 0, 0, "sections");
|
|
164
|
+
return this.conditionsRunner.executeCondition(conditions, 0, 0, "sections", this.documentSlug);
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
167
|
exports.default = DataPopulator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/conditions-runner",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4-staging.1",
|
|
4
4
|
"description": "Package containing method to execute conditions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/ConditionsRunner.js",
|
|
@@ -22,13 +22,12 @@
|
|
|
22
22
|
"prettier": "@legalplace/prettier-config",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@legalplace/lplogic": "2.4.1",
|
|
25
|
-
"@legalplace/models-v3-types": "
|
|
26
|
-
"@legalplace/referencesparser": "
|
|
25
|
+
"@legalplace/models-v3-types": "5.18.3-staging.0",
|
|
26
|
+
"@legalplace/referencesparser": "3.3.5-staging.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@legalplace/prettier-config": "
|
|
30
|
-
"@legalplace/types": "
|
|
29
|
+
"@legalplace/prettier-config": "2.1.4-staging.0",
|
|
30
|
+
"@legalplace/types": "2.22.15-staging.0",
|
|
31
31
|
"ts-node": "^10.8.1"
|
|
32
|
-
}
|
|
33
|
-
"gitHead": "051ddec22eba44657f3a7fbab9356209e8ab476a"
|
|
32
|
+
}
|
|
34
33
|
}
|
|
@@ -191,7 +191,7 @@ describe("ConditionsRunner class", () => {
|
|
|
191
191
|
).toBeDefined();
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
it("
|
|
194
|
+
it("should slice the condition to the current occurrence when the scope is related on a document", () => {
|
|
195
195
|
const runner = new ConditionsRunner(
|
|
196
196
|
buildRelatedDocumentReferences(),
|
|
197
197
|
relatedOvc
|
|
@@ -205,7 +205,22 @@ describe("ConditionsRunner class", () => {
|
|
|
205
205
|
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(false);
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
-
it("
|
|
208
|
+
it("should evaluate the condition unsliced when the target type is multiples", () => {
|
|
209
|
+
const runner = new ConditionsRunner(
|
|
210
|
+
buildRelatedDocumentReferences(),
|
|
211
|
+
relatedOvc
|
|
212
|
+
);
|
|
213
|
+
const condition = mappedCondition({
|
|
214
|
+
selected: [{ var: "o.3" }],
|
|
215
|
+
scope: "any",
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(false);
|
|
219
|
+
expect(runner.executeCondition(condition, 2, 1, "multiples")).toBe(true);
|
|
220
|
+
expect(runner.executeCondition(condition, 2, 0, "multiples")).toBe(true);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("should evaluate against the first occurrence when the scope is first", () => {
|
|
209
224
|
const runner = new ConditionsRunner(
|
|
210
225
|
buildRelatedDocumentReferences(),
|
|
211
226
|
relatedOvc
|
|
@@ -218,7 +233,7 @@ describe("ConditionsRunner class", () => {
|
|
|
218
233
|
expect(runner.executeCondition(condition, 2, 1, "documents")).toBe(true);
|
|
219
234
|
});
|
|
220
235
|
|
|
221
|
-
it("
|
|
236
|
+
it("should bind a sibling [var:N] to the current occurrence when the scope is related", () => {
|
|
222
237
|
const runner = new ConditionsRunner(
|
|
223
238
|
buildSiblingVariableReferences(),
|
|
224
239
|
siblingOvc
|
|
@@ -236,7 +251,7 @@ describe("ConditionsRunner class", () => {
|
|
|
236
251
|
expect(runner.executeCondition(condition, 3, 2, "variables")).toBe(true);
|
|
237
252
|
});
|
|
238
253
|
|
|
239
|
-
it("
|
|
254
|
+
it("should bind a sibling [var:N] to occurrence 0 when the scope is first", () => {
|
|
240
255
|
const runner = new ConditionsRunner(
|
|
241
256
|
buildSiblingVariableReferences(),
|
|
242
257
|
siblingOvc
|
|
@@ -250,7 +265,7 @@ describe("ConditionsRunner class", () => {
|
|
|
250
265
|
expect(runner.executeCondition(condition, 3, 2, "variables")).toBe(true);
|
|
251
266
|
});
|
|
252
267
|
|
|
253
|
-
it("
|
|
268
|
+
it("should return true when the scope is all and every pairwise row matches", () => {
|
|
254
269
|
const runner = new ConditionsRunner(buildSiblingVariableReferences(), {
|
|
255
270
|
options: { 10: [true, true], 20: [true] },
|
|
256
271
|
variables: {
|
|
@@ -267,7 +282,7 @@ describe("ConditionsRunner class", () => {
|
|
|
267
282
|
expect(runner.executeCondition(condition, 3, 0, "options")).toBe(true);
|
|
268
283
|
});
|
|
269
284
|
|
|
270
|
-
it("
|
|
285
|
+
it("should return false when the scope is all and a pairwise row fails", () => {
|
|
271
286
|
const runner = new ConditionsRunner(buildSiblingVariableReferences(), {
|
|
272
287
|
options: { 10: [true, true], 20: [true] },
|
|
273
288
|
variables: {
|
|
@@ -284,7 +299,7 @@ describe("ConditionsRunner class", () => {
|
|
|
284
299
|
expect(runner.executeCondition(condition, 3, 0, "options")).toBe(false);
|
|
285
300
|
});
|
|
286
301
|
|
|
287
|
-
it("
|
|
302
|
+
it("should return true when the scope is any and a later pairwise row matches", () => {
|
|
288
303
|
const runner = new ConditionsRunner(buildSiblingVariableReferences(), {
|
|
289
304
|
options: { 10: [true, true], 20: [true] },
|
|
290
305
|
variables: {
|
|
@@ -301,7 +316,7 @@ describe("ConditionsRunner class", () => {
|
|
|
301
316
|
expect(runner.executeCondition(condition, 5, 0, "options")).toBe(true);
|
|
302
317
|
});
|
|
303
318
|
|
|
304
|
-
it("
|
|
319
|
+
it("should join every value when the [var:N] reference is not a sibling of the multiple", () => {
|
|
305
320
|
const references = buildSiblingVariableReferences();
|
|
306
321
|
const resolved = resolveConditionComparators(
|
|
307
322
|
lowerScope({
|
|
@@ -322,7 +337,7 @@ describe("resolveConditionComparators", () => {
|
|
|
322
337
|
const references = buildSiblingVariableReferences();
|
|
323
338
|
const deps = { references, ovc: siblingOvc };
|
|
324
339
|
|
|
325
|
-
it("
|
|
340
|
+
it("should resolve a sibling [var:N] to the current occurrence when the leaf scope is related", () => {
|
|
326
341
|
const resolved = resolveConditionComparators(
|
|
327
342
|
lowerScope({
|
|
328
343
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
@@ -337,7 +352,7 @@ describe("resolveConditionComparators", () => {
|
|
|
337
352
|
});
|
|
338
353
|
});
|
|
339
354
|
|
|
340
|
-
it("
|
|
355
|
+
it("should resolve a sibling [var:N] to occurrence 0 when the leaf scope is first", () => {
|
|
341
356
|
const resolved = resolveConditionComparators(
|
|
342
357
|
lowerScope({
|
|
343
358
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
@@ -352,7 +367,7 @@ describe("resolveConditionComparators", () => {
|
|
|
352
367
|
});
|
|
353
368
|
});
|
|
354
369
|
|
|
355
|
-
it("
|
|
370
|
+
it("should resolve to the empty sentinel when the sibling value is missing", () => {
|
|
356
371
|
const resolved = resolveConditionComparators(
|
|
357
372
|
lowerScope({
|
|
358
373
|
"=": [{ var: "v.3" }, "[var:4]"],
|
|
@@ -375,7 +390,7 @@ describe("resolveConditionComparators", () => {
|
|
|
375
390
|
});
|
|
376
391
|
|
|
377
392
|
describe("includes / does-not-include operators", () => {
|
|
378
|
-
it("
|
|
393
|
+
it("should lower the operator to includes-any when the scope is any", () => {
|
|
379
394
|
expect(
|
|
380
395
|
lowerScope({
|
|
381
396
|
includes: [{ var: "v.1" }, "SARL"],
|
|
@@ -386,7 +401,7 @@ describe("includes / does-not-include operators", () => {
|
|
|
386
401
|
});
|
|
387
402
|
});
|
|
388
403
|
|
|
389
|
-
it("
|
|
404
|
+
it("should lower the operator to does-not-include-first when the scope is first", () => {
|
|
390
405
|
expect(
|
|
391
406
|
lowerScope({
|
|
392
407
|
"does-not-include": [{ var: "v.1" }, "SARL"],
|
package/src/ConditionsRunner.ts
CHANGED
|
@@ -114,7 +114,12 @@ class ConditionsRunner {
|
|
|
114
114
|
| "variableValidator"
|
|
115
115
|
| "sections"
|
|
116
116
|
| "documents"
|
|
117
|
-
|
|
117
|
+
| "multiples",
|
|
118
|
+
documentSlug: string
|
|
119
|
+
) =>
|
|
120
|
+
`${JSON.stringify(
|
|
121
|
+
condition
|
|
122
|
+
)}-${id}-${index}-${conditionType}-${documentSlug}`;
|
|
118
123
|
|
|
119
124
|
executeCondition(
|
|
120
125
|
condition: {
|
|
@@ -131,12 +136,15 @@ class ConditionsRunner {
|
|
|
131
136
|
| "variableValidator"
|
|
132
137
|
| "sections"
|
|
133
138
|
| "documents"
|
|
139
|
+
| "multiples",
|
|
140
|
+
documentSlug = "main"
|
|
134
141
|
): any {
|
|
135
142
|
const memoizedKey = this.buildMemoizeKey(
|
|
136
143
|
condition,
|
|
137
144
|
id,
|
|
138
145
|
index,
|
|
139
|
-
conditionType
|
|
146
|
+
conditionType,
|
|
147
|
+
documentSlug
|
|
140
148
|
);
|
|
141
149
|
if (this.executeConditionMemo[memoizedKey] !== undefined) {
|
|
142
150
|
return this.executeConditionMemo[memoizedKey];
|
|
@@ -151,7 +159,8 @@ class ConditionsRunner {
|
|
|
151
159
|
this.ovc,
|
|
152
160
|
condition.dataMap,
|
|
153
161
|
id,
|
|
154
|
-
index
|
|
162
|
+
index,
|
|
163
|
+
documentSlug
|
|
155
164
|
).getData();
|
|
156
165
|
} else if (
|
|
157
166
|
conditionType === "variables" ||
|
|
@@ -165,7 +174,8 @@ class ConditionsRunner {
|
|
|
165
174
|
this.ovc,
|
|
166
175
|
condition.dataMap,
|
|
167
176
|
dataId,
|
|
168
|
-
index
|
|
177
|
+
index,
|
|
178
|
+
documentSlug
|
|
169
179
|
).getData();
|
|
170
180
|
} else if (conditionType === "sections" || conditionType === "documents") {
|
|
171
181
|
currentData = new DataPopulator(
|
|
@@ -174,7 +184,16 @@ class ConditionsRunner {
|
|
|
174
184
|
this.ovc,
|
|
175
185
|
condition.dataMap,
|
|
176
186
|
id,
|
|
177
|
-
index
|
|
187
|
+
index,
|
|
188
|
+
documentSlug
|
|
189
|
+
).getData();
|
|
190
|
+
} else if (conditionType === "multiples") {
|
|
191
|
+
// Multiple CTA conditions are evaluated once for the whole group
|
|
192
|
+
currentData = new DataPopulator(
|
|
193
|
+
this,
|
|
194
|
+
this.references,
|
|
195
|
+
this.ovc,
|
|
196
|
+
condition.dataMap
|
|
178
197
|
).getData();
|
|
179
198
|
}
|
|
180
199
|
|
package/src/DataPopulator.ts
CHANGED
|
@@ -16,6 +16,8 @@ class DataPopulator {
|
|
|
16
16
|
|
|
17
17
|
private dataMap: ConditionDataMap;
|
|
18
18
|
|
|
19
|
+
private documentSlug: string;
|
|
20
|
+
|
|
19
21
|
private data: ConditionData = {
|
|
20
22
|
o: {},
|
|
21
23
|
v: {},
|
|
@@ -32,8 +34,10 @@ class DataPopulator {
|
|
|
32
34
|
ovc: InputsType,
|
|
33
35
|
dataMap: ConditionDataMap,
|
|
34
36
|
id?: number,
|
|
35
|
-
index?: number
|
|
37
|
+
index?: number,
|
|
38
|
+
documentSlug = "main"
|
|
36
39
|
) {
|
|
40
|
+
this.documentSlug = documentSlug;
|
|
37
41
|
this.id = id;
|
|
38
42
|
this.ovc = ovc;
|
|
39
43
|
this.index = index;
|
|
@@ -306,10 +310,17 @@ class DataPopulator {
|
|
|
306
310
|
*/
|
|
307
311
|
private sectionConditionValue(sectionId: number) {
|
|
308
312
|
// Getting section conditions
|
|
309
|
-
const conditions =
|
|
313
|
+
const conditions =
|
|
314
|
+
this.references.conditions.sections[this.documentSlug]?.[sectionId];
|
|
310
315
|
if (conditions === undefined) return undefined;
|
|
311
316
|
|
|
312
|
-
return this.conditionsRunner.executeCondition(
|
|
317
|
+
return this.conditionsRunner.executeCondition(
|
|
318
|
+
conditions,
|
|
319
|
+
0,
|
|
320
|
+
0,
|
|
321
|
+
"sections",
|
|
322
|
+
this.documentSlug
|
|
323
|
+
);
|
|
313
324
|
}
|
|
314
325
|
}
|
|
315
326
|
|