@legalplace/lplogic 2.3.2-staging.0 → 2.3.2

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/.gitlab-automator CHANGED
@@ -1,7 +1,7 @@
1
- GITLAB_PRIVATE_TOKEN=glpat-BOv5W1i6MoAAvHjzkmc5nW86MQp1OjkH.01.0w119catf
1
+ GITLAB_PRIVATE_TOKEN=glpat-2LLXVHzUViBmoVAUPBzy
2
2
  GITLAB_BASE_URL=https://git.legalplace.eu
3
3
  GITLAB_API_PROJECT_ID=28
4
4
  GITLAB_USER_ID=9
5
5
  CURRENT_PROJECT_ID=39
6
6
  SLACK_USER_ID=U0B3SNBV3
7
- CLICKUP_PRIVATE_TOKEN=pk_32519579_K5W4L4KEVXY03A3D2WFA46D07HVGTL5L
7
+ CLICKUP_PRIVATE_TOKEN=pk_32519579_FSGO0KOHXZ93NPCODYRPIWHWG12Y4G3A
package/dist/LpLogic.js CHANGED
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var json_logic_js_1 = __importDefault(require("@legalplace/json-logic-js"));
7
7
  var reduceParents = function (parents, length) {
8
8
  var reducedParents = [];
9
- var safeParents = parents.filter(function (entry) { return Array.isArray(entry); });
10
- safeParents.sort(function (a, b) { return b.length - a.length; });
9
+ parents.sort(function (a, b) { return b.length - a.length; });
11
10
  var _loop_1 = function (index) {
12
- var currentIndexResult = safeParents.reduce(function (previousValue, currentValue) {
11
+ var currentIndexResult = parents.reduce(function (previousValue, currentValue) {
13
12
  if (currentValue.length === 1)
14
13
  return previousValue && currentValue[0];
15
14
  if (currentValue[index] === undefined)
@@ -24,7 +23,7 @@ var reduceParents = function (parents, length) {
24
23
  return reducedParents;
25
24
  };
26
25
  var reduceValues = function (values, parents, compareFunction) {
27
- if (!Array.isArray(parents) || parents.length === 0) {
26
+ if (parents === undefined || parents.length === 0) {
28
27
  return values.map(function (currentValue) {
29
28
  return compareFunction(currentValue, true);
30
29
  });
@@ -271,108 +270,5 @@ var regexMatch = function (values, comparator, parents) {
271
270
  return reducedValues.length === filter.length;
272
271
  };
273
272
  json_logic_js_1.default.add_operation("regex-match", regexMatch);
274
- var aggregateAny = function (reducedValues) {
275
- return reducedValues.includes(true);
276
- };
277
- var aggregateFirst = function (reducedValues) {
278
- return reducedValues[0] === true;
279
- };
280
- var cleanString = function (value) {
281
- return (typeof value === "number" ? value.toString() : value.trim()).toLowerCase();
282
- };
283
- var registerScopedBooleanOp = function (baseName, compareFn) {
284
- json_logic_js_1.default.add_operation("".concat(baseName, "-first"), function (values, _comparator, parents) {
285
- var reducedValue = reduceValues(values, parents, compareFn);
286
- return aggregateFirst(reducedValue);
287
- });
288
- json_logic_js_1.default.add_operation("".concat(baseName, "-any"), function (values, _comparator, parents) {
289
- var reducedValue = reduceValues(values, parents, compareFn);
290
- return aggregateAny(reducedValue);
291
- });
292
- };
293
- registerScopedBooleanOp("selected", function (value, parent) { return value && parent; });
294
- registerScopedBooleanOp("not-selected", function (value, parent) { return !value && parent; });
295
- var conditionMet = function (value, parent) {
296
- return value === true && parent;
297
- };
298
- var conditionNotMet = function (value, parent) {
299
- return value !== true && parent;
300
- };
301
- json_logic_js_1.default.add_operation("conditions-met", function (values, comparator, parents) {
302
- return reduceValues(values, parents, conditionMet).every(function (value) { return value === true; });
303
- });
304
- json_logic_js_1.default.add_operation("conditions-not-met", function (values, comparator, parents) {
305
- return reduceValues(values, parents, conditionNotMet).every(function (value) { return value === true; });
306
- });
307
- registerScopedBooleanOp("conditions-met", conditionMet);
308
- registerScopedBooleanOp("conditions-not-met", conditionNotMet);
309
- var registerScopedComparisonOp = function (baseName, compareFn) {
310
- json_logic_js_1.default.add_operation("".concat(baseName, "-any"), function (values, comparator, parents) {
311
- var reducedValues = reduceValues(values, parents, function (value, parent) {
312
- return compareFn(value, comparator, parent);
313
- });
314
- return aggregateAny(reducedValues);
315
- });
316
- json_logic_js_1.default.add_operation("".concat(baseName, "-first"), function (values, comparator, parents) {
317
- var reducedValues = reduceValues(values, parents, function (value, parent) {
318
- return compareFn(value, comparator, parent);
319
- });
320
- return aggregateFirst(reducedValues);
321
- });
322
- };
323
- registerScopedComparisonOp("=", function (value, comparator, parent) {
324
- return safeEqual(value, comparator) && parent;
325
- });
326
- registerScopedComparisonOp("<>", function (value, comparator, parent) {
327
- return !safeEqual(value, comparator) && parent;
328
- });
329
- registerScopedComparisonOp("==", function (value, comparator, parent) {
330
- return parseNumber(value) === parseNumber(comparator) && parent;
331
- });
332
- registerScopedComparisonOp(">=", function (value, comparator, parent) {
333
- return parseNumber(value) >= parseNumber(comparator) && parent;
334
- });
335
- registerScopedComparisonOp("<=", function (value, comparator, parent) {
336
- return parseNumber(value) <= parseNumber(comparator) && parent;
337
- });
338
- registerScopedComparisonOp(">", function (value, comparator, parent) {
339
- return parseNumber(value) > parseNumber(comparator) && parent;
340
- });
341
- registerScopedComparisonOp("<", function (value, comparator, parent) {
342
- return parseNumber(value) < parseNumber(comparator) && parent;
343
- });
344
- registerScopedComparisonOp("is", function (value, comparator, parent) {
345
- return cleanString(value) === cleanString(comparator) && parent;
346
- });
347
- registerScopedComparisonOp("not", function (value, comparator, parent) {
348
- return cleanString(value) !== cleanString(comparator) && parent;
349
- });
350
- registerScopedComparisonOp("contains", function (value, comparator, parent) {
351
- return cleanString(value).includes(cleanString(comparator)) && parent;
352
- });
353
- registerScopedComparisonOp("does-not-contain", function (value, comparator, parent) {
354
- return !cleanString(value).includes(cleanString(comparator)) && parent;
355
- });
356
- registerScopedComparisonOp("like", function (value, comparator, parent) {
357
- return new RegExp("( |^)".concat(cleanString(comparator), "( |$)"), "i").test(cleanString(value)) && parent;
358
- });
359
- registerScopedComparisonOp("not-like", function (value, comparator, parent) {
360
- return !new RegExp("( |^)".concat(cleanString(comparator), "( |$)"), "i").test(cleanString(value)) && parent;
361
- });
362
- registerScopedComparisonOp("regex-match", function (value, comparator, parent) {
363
- if (typeof comparator !== "string")
364
- return false;
365
- var regex;
366
- try {
367
- regex = new RegExp(comparator);
368
- }
369
- catch (error) {
370
- return false;
371
- }
372
- var stringValue = typeof value === "number" ? value.toString() : value;
373
- return regex.test(stringValue) && parent;
374
- });
375
- registerScopedComparisonOp("empty", function (value, _comparator, parent) { return cleanString(value).length === 0 && parent; });
376
- registerScopedComparisonOp("not-empty", function (value, _comparator, parent) { return cleanString(value).length > 0 && parent; });
377
273
  var LpLogic = json_logic_js_1.default.apply;
378
274
  exports.default = LpLogic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/lplogic",
3
- "version": "2.3.2-staging.0",
3
+ "version": "2.3.2",
4
4
  "description": "LegalPlace LpLogic",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -129,129 +129,3 @@ test('Testing "not-like" Bye on a value `Hello world`', async () => {
129
129
  test('Testing "not-like" World on a value `Hello world`', async () => {
130
130
  expect( LpLogic({"not-like":[{"var":"v.1"}, "World"]}, {"v":{"1":["Hello world"]}}) ).toBe(false)
131
131
  })
132
-
133
- test('Testing "selected-first" on first occurrence only', async () => {
134
- expect(LpLogic({"selected-first":[{"var":"o.1"}]}, {"o":{"1":[true, false]}})).toBe(true)
135
- expect(LpLogic({"selected-first":[{"var":"o.1"}]}, {"o":{"1":[false, true]}})).toBe(false)
136
- })
137
-
138
- test('Testing "=-any" on multiple values', async () => {
139
- expect(LpLogic({"=-any":[{"var":"v.1"}, "a"]}, {"v":{"1":["a", "b"]}})).toBe(true)
140
- expect(LpLogic({"=-any":[{"var":"v.1"}, "a"]}, {"v":{"1":["b", "c"]}})).toBe(false)
141
- })
142
-
143
- /**
144
- * empty-any / not-empty-any cover occurrence scope "at least one" for emptiness checks.
145
- */
146
- test('Testing "empty-any" on multiple values', async () => {
147
- expect(LpLogic({"empty-any":[{"var":"v.1"}]}, {"v":{"1":["", "x"]}})).toBe(true)
148
- expect(LpLogic({"empty-any":[{"var":"v.1"}]}, {"v":{"1":["x", "y"]}})).toBe(false)
149
- })
150
-
151
- test('Testing "empty-first" on multiple values', async () => {
152
- expect(LpLogic({"empty-first":[{"var":"v.1"}]}, {"v":{"1":["", "x"]}})).toBe(true)
153
- expect(LpLogic({"empty-first":[{"var":"v.1"}]}, {"v":{"1":["x", ""]}})).toBe(false)
154
- })
155
-
156
- test('Testing "not-empty-any" on multiple values', async () => {
157
- expect(LpLogic({"not-empty-any":[{"var":"v.1"}]}, {"v":{"1":["", "x"]}})).toBe(true)
158
- expect(LpLogic({"not-empty-any":[{"var":"v.1"}]}, {"v":{"1":["", ""]}})).toBe(false)
159
- })
160
-
161
- test('Testing "=-first" on multiple values', async () => {
162
- expect(LpLogic({"=-first":[{"var":"v.1"}, "a"]}, {"v":{"1":["a", "b"]}})).toBe(true)
163
- expect(LpLogic({"=-first":[{"var":"v.1"}, "a"]}, {"v":{"1":["b", "a"]}})).toBe(false)
164
- })
165
-
166
- test('Testing "conditions-met" without parents', async () => {
167
- expect(
168
- LpLogic({"conditions-met":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[true, true]}}})
169
- ).toBe(true)
170
- expect(
171
- LpLogic({"conditions-met":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[true, false]}}})
172
- ).toBe(false)
173
- })
174
-
175
- test('Testing "conditions-met" with parents', async () => {
176
- expect(
177
- LpLogic(
178
- {"conditions-met":[{"var":"c.o.2"}, undefined, [{"var":"o.1"}]]},
179
- {"c":{"o":{"2":[true, true]}}, "o":{"1":[true, true]}}
180
- )
181
- ).toBe(true)
182
- expect(
183
- LpLogic(
184
- {"conditions-met":[{"var":"c.o.2"}, undefined, [{"var":"o.1"}]]},
185
- {"c":{"o":{"2":[true, true]}}, "o":{"1":[true, false]}}
186
- )
187
- ).toBe(false)
188
- })
189
-
190
- test('Testing "conditions-met-first" on first occurrence only', async () => {
191
- expect(
192
- LpLogic({"conditions-met-first":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[true, false]}}})
193
- ).toBe(true)
194
- expect(
195
- LpLogic({"conditions-met-first":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[false, true]}}})
196
- ).toBe(false)
197
- })
198
-
199
- test('Testing "conditions-met-any" on multiple values', async () => {
200
- expect(
201
- LpLogic({"conditions-met-any":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[false, true]}}})
202
- ).toBe(true)
203
- expect(
204
- LpLogic({"conditions-met-any":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[false, false]}}})
205
- ).toBe(false)
206
- })
207
-
208
- test('Testing "conditions-not-met"', async () => {
209
- expect(
210
- LpLogic({"conditions-not-met":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[false, false]}}})
211
- ).toBe(true)
212
- expect(
213
- LpLogic({"conditions-not-met":[{"var":"c.o.1"}]}, {"c":{"o":{"1":[true, false]}}})
214
- ).toBe(false)
215
- })
216
-
217
- /**
218
- * Regression: when a condition tree containing `undefined` parents is passed
219
- * through any JSON serialization (e.g. Redux DevTools), `undefined` becomes
220
- * `null` (`JSON.stringify([a, undefined])` → `'[a,null]'`). LpLogic must
221
- * treat a `null` parents arg as "no parents" instead of throwing on
222
- * `null.length`.
223
- */
224
- test('Testing "conditions-met" with null parents (JSON round-trip safety)', async () => {
225
- expect(
226
- LpLogic(
227
- { "conditions-met": [{ var: "c.o.1" }, null, null] },
228
- { "c": { "o": { "1": [true, true] } } }
229
- )
230
- ).toBe(true)
231
- expect(
232
- LpLogic(
233
- { "conditions-met-first": [{ var: "c.o.1" }, null, null] },
234
- { "c": { "o": { "1": [true, false] } } }
235
- )
236
- ).toBe(true)
237
- })
238
-
239
- test('Testing "selected" with null parents (JSON round-trip safety)', async () => {
240
- expect(
241
- LpLogic(
242
- { "selected": [{ var: "o.1" }, null, null] },
243
- { "o": { "1": [true, true] } }
244
- )
245
- ).toBe(true)
246
- })
247
-
248
- test('Testing "conditions-met" with parents containing missing refs (null entries)', async () => {
249
- // `{ var: "o.999" }` resolves to `null` because `o.999` is absent from data.
250
- // Parents array is `[null]`; LpLogic must not throw.
251
- expect(
252
- LpLogic(
253
- { "conditions-met": [{ var: "c.o.1" }, undefined, [{ var: "o.999" }]] },
254
- { "c": { "o": { "1": [true] } } }
255
- )
256
- ).toBe(true)
257
- })