@briza/illogical 1.4.3 → 1.5.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/changelog.md +13 -0
- package/lib/illogical.esm.js +82 -176
- package/lib/illogical.js +82 -175
- package/package.json +23 -23
- package/readme.md +21 -7
- package/types/common/evaluable.d.ts +57 -57
- package/types/common/type-check.d.ts +28 -32
- package/types/common/util.d.ts +11 -11
- package/types/expression/comparison/eq.d.ts +18 -22
- package/types/expression/comparison/ge.d.ts +18 -22
- package/types/expression/comparison/gt.d.ts +18 -22
- package/types/expression/comparison/in.d.ts +23 -27
- package/types/expression/comparison/index.d.ts +45 -49
- package/types/expression/comparison/le.d.ts +18 -22
- package/types/expression/comparison/lt.d.ts +18 -22
- package/types/expression/comparison/ne.d.ts +18 -22
- package/types/expression/comparison/not-in.d.ts +23 -27
- package/types/expression/comparison/overlap.d.ts +23 -27
- package/types/expression/comparison/prefix.d.ts +23 -27
- package/types/expression/comparison/present.d.ts +25 -29
- package/types/expression/comparison/suffix.d.ts +23 -27
- package/types/expression/comparison/undefined.d.ts +28 -32
- package/types/expression/logical/and.d.ts +23 -27
- package/types/expression/logical/index.d.ts +32 -36
- package/types/expression/logical/nor.d.ts +23 -27
- package/types/expression/logical/not.d.ts +23 -27
- package/types/expression/logical/or.d.ts +23 -27
- package/types/expression/logical/xor.d.ts +23 -27
- package/types/index.d.ts +73 -71
- package/types/operand/collection.d.ts +36 -40
- package/types/operand/index.d.ts +25 -29
- package/types/operand/reference.d.ts +44 -48
- package/types/operand/value.d.ts +31 -35
- package/types/parser/index.d.ts +39 -43
- package/types/parser/options.d.ts +61 -65
package/lib/illogical.js
CHANGED
|
@@ -2,26 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function _defineProperty(obj, key, value) {
|
|
6
|
-
if (key in obj) {
|
|
7
|
-
Object.defineProperty(obj, key, {
|
|
8
|
-
value: value,
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true
|
|
12
|
-
});
|
|
13
|
-
} else {
|
|
14
|
-
obj[key] = value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return obj;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Common module.
|
|
22
|
-
* @module illogical/common
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
5
|
/**
|
|
26
6
|
* Is number predicate.
|
|
27
7
|
* @param value Tested value.
|
|
@@ -72,10 +52,20 @@ function isEvaluable(value) {
|
|
|
72
52
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
73
53
|
}
|
|
74
54
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
function _defineProperty(obj, key, value) {
|
|
56
|
+
if (key in obj) {
|
|
57
|
+
Object.defineProperty(obj, key, {
|
|
58
|
+
value: value,
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
obj[key] = value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
79
69
|
|
|
80
70
|
/**
|
|
81
71
|
* Valid types for context members
|
|
@@ -111,12 +101,12 @@ class Comparison {
|
|
|
111
101
|
* @param {Operand} right Right operand.
|
|
112
102
|
*/
|
|
113
103
|
constructor(operator, operatorSymbol, left, right) {
|
|
104
|
+
_defineProperty(this, "type", EvaluableType.Expression);
|
|
105
|
+
|
|
114
106
|
this.operator = operator;
|
|
115
107
|
this.operatorSymbol = operatorSymbol;
|
|
116
108
|
this.left = left;
|
|
117
109
|
this.right = right;
|
|
118
|
-
|
|
119
|
-
_defineProperty(this, "type", EvaluableType.Expression);
|
|
120
110
|
}
|
|
121
111
|
/**
|
|
122
112
|
* {@link Evaluable.evaluate}
|
|
@@ -146,9 +136,9 @@ class Comparison {
|
|
|
146
136
|
/**
|
|
147
137
|
* {@link Evaluable.simplify}
|
|
148
138
|
*/
|
|
149
|
-
simplify(
|
|
150
|
-
const left = this.left.simplify(...
|
|
151
|
-
const right = this.right.simplify(...
|
|
139
|
+
simplify() {
|
|
140
|
+
const left = this.left.simplify(...arguments);
|
|
141
|
+
const right = this.right.simplify(...arguments);
|
|
152
142
|
|
|
153
143
|
if (!isEvaluable(left) && !isEvaluable(right)) {
|
|
154
144
|
return this.comparison(left, right);
|
|
@@ -176,11 +166,6 @@ class Comparison {
|
|
|
176
166
|
|
|
177
167
|
}
|
|
178
168
|
|
|
179
|
-
/**
|
|
180
|
-
* Comparison expression module.
|
|
181
|
-
* @module illogical/expression/comparison
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
169
|
const OPERATOR$h = Symbol('EQ');
|
|
185
170
|
/**
|
|
186
171
|
* Equal comparison expression
|
|
@@ -210,11 +195,6 @@ class Equal extends Comparison {
|
|
|
210
195
|
|
|
211
196
|
}
|
|
212
197
|
|
|
213
|
-
/**
|
|
214
|
-
* Comparison expression module.
|
|
215
|
-
* @module illogical/expression/comparison
|
|
216
|
-
*/
|
|
217
|
-
|
|
218
198
|
const OPERATOR$g = Symbol('GE');
|
|
219
199
|
/**
|
|
220
200
|
* Greater than or equal comparison expression
|
|
@@ -248,11 +228,6 @@ class GreaterThanOrEqual extends Comparison {
|
|
|
248
228
|
|
|
249
229
|
}
|
|
250
230
|
|
|
251
|
-
/**
|
|
252
|
-
* Comparison expression module.
|
|
253
|
-
* @module illogical/expression/comparison
|
|
254
|
-
*/
|
|
255
|
-
|
|
256
231
|
const OPERATOR$f = Symbol('GT');
|
|
257
232
|
/**
|
|
258
233
|
* Greater than comparison expression
|
|
@@ -286,11 +261,6 @@ class GreaterThan extends Comparison {
|
|
|
286
261
|
|
|
287
262
|
}
|
|
288
263
|
|
|
289
|
-
/**
|
|
290
|
-
* Comparison expression module.
|
|
291
|
-
* @module illogical/expression/comparison
|
|
292
|
-
*/
|
|
293
|
-
|
|
294
264
|
const OPERATOR$e = Symbol('IN');
|
|
295
265
|
/**
|
|
296
266
|
* In comparison expression
|
|
@@ -355,11 +325,6 @@ class In extends Comparison {
|
|
|
355
325
|
|
|
356
326
|
}
|
|
357
327
|
|
|
358
|
-
/**
|
|
359
|
-
* Comparison expression module.
|
|
360
|
-
* @module illogical/expression/comparison
|
|
361
|
-
*/
|
|
362
|
-
|
|
363
328
|
const OPERATOR$d = Symbol('LE');
|
|
364
329
|
/**
|
|
365
330
|
* Less than or equal comparison expression
|
|
@@ -393,11 +358,6 @@ class LessThanOrEqual extends Comparison {
|
|
|
393
358
|
|
|
394
359
|
}
|
|
395
360
|
|
|
396
|
-
/**
|
|
397
|
-
* Comparison expression module.
|
|
398
|
-
* @module illogical/expression/comparison
|
|
399
|
-
*/
|
|
400
|
-
|
|
401
361
|
const OPERATOR$c = Symbol('LT');
|
|
402
362
|
/**
|
|
403
363
|
* Less than comparison expression
|
|
@@ -431,11 +391,6 @@ class LessThan extends Comparison {
|
|
|
431
391
|
|
|
432
392
|
}
|
|
433
393
|
|
|
434
|
-
/**
|
|
435
|
-
* Comparison expression module.
|
|
436
|
-
* @module illogical/expression/comparison
|
|
437
|
-
*/
|
|
438
|
-
|
|
439
394
|
const OPERATOR$b = Symbol('NE');
|
|
440
395
|
/**
|
|
441
396
|
* Not equal comparison expression
|
|
@@ -465,11 +420,6 @@ class NotEqual extends Comparison {
|
|
|
465
420
|
|
|
466
421
|
}
|
|
467
422
|
|
|
468
|
-
/**
|
|
469
|
-
* Comparison expression module.
|
|
470
|
-
* @module illogical/expression/comparison
|
|
471
|
-
*/
|
|
472
|
-
|
|
473
423
|
const OPERATOR$a = Symbol('NOT IN');
|
|
474
424
|
/**
|
|
475
425
|
* Not in comparison expression
|
|
@@ -534,11 +484,6 @@ class NotIn extends Comparison {
|
|
|
534
484
|
|
|
535
485
|
}
|
|
536
486
|
|
|
537
|
-
/**
|
|
538
|
-
* Comparison expression module.
|
|
539
|
-
* @module illogical/expression/comparison
|
|
540
|
-
*/
|
|
541
|
-
|
|
542
487
|
const OPERATOR$9 = Symbol('OVERLAP');
|
|
543
488
|
/**
|
|
544
489
|
* Overlap comparison expression
|
|
@@ -589,11 +534,6 @@ class Overlap extends Comparison {
|
|
|
589
534
|
|
|
590
535
|
}
|
|
591
536
|
|
|
592
|
-
/**
|
|
593
|
-
* Prefix expression module.
|
|
594
|
-
* @module illogical/expression/prefix
|
|
595
|
-
*/
|
|
596
|
-
|
|
597
537
|
const OPERATOR$8 = Symbol('PREFIX');
|
|
598
538
|
/**
|
|
599
539
|
* Prefix comparison expression
|
|
@@ -684,9 +624,6 @@ class Value extends Operand {
|
|
|
684
624
|
}
|
|
685
625
|
|
|
686
626
|
super();
|
|
687
|
-
|
|
688
|
-
_defineProperty(this, "value", void 0);
|
|
689
|
-
|
|
690
627
|
this.value = value;
|
|
691
628
|
}
|
|
692
629
|
/**
|
|
@@ -725,11 +662,6 @@ class Value extends Operand {
|
|
|
725
662
|
|
|
726
663
|
}
|
|
727
664
|
|
|
728
|
-
/**
|
|
729
|
-
* Present expression module.
|
|
730
|
-
* @module illogical/expression/comparison
|
|
731
|
-
*/
|
|
732
|
-
|
|
733
665
|
const OPERATOR$7 = Symbol('PRESENT');
|
|
734
666
|
/**
|
|
735
667
|
* Present comparison expression
|
|
@@ -780,11 +712,6 @@ class Present extends Comparison {
|
|
|
780
712
|
|
|
781
713
|
}
|
|
782
714
|
|
|
783
|
-
/**
|
|
784
|
-
* Suffix expression module.
|
|
785
|
-
* @module illogical/expression/suffix
|
|
786
|
-
*/
|
|
787
|
-
|
|
788
715
|
const OPERATOR$6 = Symbol('PREFIX');
|
|
789
716
|
/**
|
|
790
717
|
* Suffix comparison expression
|
|
@@ -829,11 +756,6 @@ class Suffix extends Comparison {
|
|
|
829
756
|
|
|
830
757
|
}
|
|
831
758
|
|
|
832
|
-
/**
|
|
833
|
-
* Undefined expression module.
|
|
834
|
-
* @module illogical/expression/comparison
|
|
835
|
-
*/
|
|
836
|
-
|
|
837
759
|
const OPERATOR$5 = Symbol('UNDEFINED');
|
|
838
760
|
/**
|
|
839
761
|
* Undefined comparison expression
|
|
@@ -898,11 +820,11 @@ class Logical {
|
|
|
898
820
|
* @param {Evaluable[]} operands Collection of operands.
|
|
899
821
|
*/
|
|
900
822
|
constructor(operator, operatorSymbol, operands) {
|
|
823
|
+
_defineProperty(this, "type", EvaluableType.Expression);
|
|
824
|
+
|
|
901
825
|
this.operator = operator;
|
|
902
826
|
this.operatorSymbol = operatorSymbol;
|
|
903
827
|
this.operands = operands;
|
|
904
|
-
|
|
905
|
-
_defineProperty(this, "type", EvaluableType.Expression);
|
|
906
828
|
}
|
|
907
829
|
/**
|
|
908
830
|
* {@link Evaluable.evaluate}
|
|
@@ -932,11 +854,6 @@ class Logical {
|
|
|
932
854
|
|
|
933
855
|
}
|
|
934
856
|
|
|
935
|
-
/**
|
|
936
|
-
* Logical expression module.
|
|
937
|
-
* @module illogical/expression/logical
|
|
938
|
-
*/
|
|
939
|
-
|
|
940
857
|
const OPERATOR$4 = Symbol('AND');
|
|
941
858
|
/**
|
|
942
859
|
* And logical expression
|
|
@@ -975,17 +892,21 @@ class And extends Logical {
|
|
|
975
892
|
*/
|
|
976
893
|
|
|
977
894
|
|
|
978
|
-
simplify(
|
|
895
|
+
simplify() {
|
|
896
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
897
|
+
args[_key] = arguments[_key];
|
|
898
|
+
}
|
|
899
|
+
|
|
979
900
|
const simplified = this.operands.reduce((result, child) => {
|
|
980
901
|
if (result !== false) {
|
|
981
902
|
const childResult = child.simplify(...args);
|
|
982
903
|
|
|
983
|
-
if (
|
|
904
|
+
if (isEvaluable(childResult)) {
|
|
984
905
|
if (isBoolean(result)) {
|
|
985
|
-
return [
|
|
906
|
+
return [childResult];
|
|
986
907
|
}
|
|
987
908
|
|
|
988
|
-
return [...result,
|
|
909
|
+
return [...result, childResult];
|
|
989
910
|
}
|
|
990
911
|
|
|
991
912
|
if (!childResult) {
|
|
@@ -1009,11 +930,6 @@ class And extends Logical {
|
|
|
1009
930
|
|
|
1010
931
|
}
|
|
1011
932
|
|
|
1012
|
-
/**
|
|
1013
|
-
* Logical expression module.
|
|
1014
|
-
* @module illogical/expression/logical
|
|
1015
|
-
*/
|
|
1016
|
-
|
|
1017
933
|
const OPERATOR$3 = Symbol('NOT');
|
|
1018
934
|
/**
|
|
1019
935
|
* Not logical expression
|
|
@@ -1052,8 +968,8 @@ class Not extends Logical {
|
|
|
1052
968
|
*/
|
|
1053
969
|
|
|
1054
970
|
|
|
1055
|
-
simplify(
|
|
1056
|
-
const simplified = this.operands[0].simplify(...
|
|
971
|
+
simplify() {
|
|
972
|
+
const simplified = this.operands[0].simplify(...arguments);
|
|
1057
973
|
|
|
1058
974
|
if (isBoolean(simplified)) {
|
|
1059
975
|
return !simplified;
|
|
@@ -1068,11 +984,6 @@ class Not extends Logical {
|
|
|
1068
984
|
|
|
1069
985
|
}
|
|
1070
986
|
|
|
1071
|
-
/**
|
|
1072
|
-
* Logical expression module.
|
|
1073
|
-
* @module illogical/expression/logical
|
|
1074
|
-
*/
|
|
1075
|
-
|
|
1076
987
|
const OPERATOR$2 = Symbol('NOR');
|
|
1077
988
|
/**
|
|
1078
989
|
* Nor logical expression
|
|
@@ -1111,17 +1022,21 @@ class Nor extends Logical {
|
|
|
1111
1022
|
*/
|
|
1112
1023
|
|
|
1113
1024
|
|
|
1114
|
-
simplify(
|
|
1025
|
+
simplify() {
|
|
1026
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1027
|
+
args[_key] = arguments[_key];
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1115
1030
|
const simplified = this.operands.reduce((result, child) => {
|
|
1116
1031
|
if (result !== false) {
|
|
1117
1032
|
const childResult = child.simplify(...args);
|
|
1118
1033
|
|
|
1119
1034
|
if (isEvaluable(childResult)) {
|
|
1120
1035
|
if (isBoolean(result)) {
|
|
1121
|
-
return [
|
|
1036
|
+
return [childResult];
|
|
1122
1037
|
}
|
|
1123
1038
|
|
|
1124
|
-
return [...result,
|
|
1039
|
+
return [...result, childResult];
|
|
1125
1040
|
}
|
|
1126
1041
|
|
|
1127
1042
|
if (childResult) {
|
|
@@ -1145,11 +1060,6 @@ class Nor extends Logical {
|
|
|
1145
1060
|
|
|
1146
1061
|
}
|
|
1147
1062
|
|
|
1148
|
-
/**
|
|
1149
|
-
* Logical expression module.
|
|
1150
|
-
* @module illogical/expression/logical
|
|
1151
|
-
*/
|
|
1152
|
-
|
|
1153
1063
|
const OPERATOR$1 = Symbol('OR');
|
|
1154
1064
|
/**
|
|
1155
1065
|
* Or logical expression
|
|
@@ -1188,17 +1098,21 @@ class Or extends Logical {
|
|
|
1188
1098
|
*/
|
|
1189
1099
|
|
|
1190
1100
|
|
|
1191
|
-
simplify(
|
|
1101
|
+
simplify() {
|
|
1102
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1103
|
+
args[_key] = arguments[_key];
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1192
1106
|
const simplified = this.operands.reduce((result, child) => {
|
|
1193
1107
|
if (result !== true) {
|
|
1194
1108
|
const childResult = child.simplify(...args);
|
|
1195
1109
|
|
|
1196
|
-
if (
|
|
1110
|
+
if (isEvaluable(childResult)) {
|
|
1197
1111
|
if (isBoolean(result)) {
|
|
1198
|
-
return [
|
|
1112
|
+
return [childResult];
|
|
1199
1113
|
}
|
|
1200
1114
|
|
|
1201
|
-
return [...result,
|
|
1115
|
+
return [...result, childResult];
|
|
1202
1116
|
}
|
|
1203
1117
|
|
|
1204
1118
|
if (childResult) {
|
|
@@ -1222,11 +1136,6 @@ class Or extends Logical {
|
|
|
1222
1136
|
|
|
1223
1137
|
}
|
|
1224
1138
|
|
|
1225
|
-
/**
|
|
1226
|
-
* Logical expression module.
|
|
1227
|
-
* @module illogical/expression/logical
|
|
1228
|
-
*/
|
|
1229
|
-
|
|
1230
1139
|
const OPERATOR = Symbol('XOR');
|
|
1231
1140
|
/**
|
|
1232
1141
|
* Logical xor
|
|
@@ -1280,16 +1189,22 @@ class Xor extends Logical {
|
|
|
1280
1189
|
*/
|
|
1281
1190
|
|
|
1282
1191
|
|
|
1283
|
-
simplify(
|
|
1284
|
-
|
|
1192
|
+
simplify() {
|
|
1193
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1194
|
+
args[_key] = arguments[_key];
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
const [evaluablesLeft, trueCount] = this.operands.reduce((_ref, child) => {
|
|
1198
|
+
let [notSimplifiedConditions, trueCount] = _ref;
|
|
1199
|
+
|
|
1285
1200
|
if (trueCount > 1) {
|
|
1286
1201
|
return [notSimplifiedConditions, trueCount];
|
|
1287
1202
|
}
|
|
1288
1203
|
|
|
1289
1204
|
const childResult = child.simplify(...args);
|
|
1290
1205
|
|
|
1291
|
-
if (
|
|
1292
|
-
return [[...notSimplifiedConditions,
|
|
1206
|
+
if (isEvaluable(childResult)) {
|
|
1207
|
+
return [[...notSimplifiedConditions, childResult], trueCount];
|
|
1293
1208
|
}
|
|
1294
1209
|
|
|
1295
1210
|
if (childResult) {
|
|
@@ -1334,9 +1249,6 @@ class Collection extends Operand {
|
|
|
1334
1249
|
*/
|
|
1335
1250
|
constructor(items) {
|
|
1336
1251
|
super();
|
|
1337
|
-
|
|
1338
|
-
_defineProperty(this, "items", void 0);
|
|
1339
|
-
|
|
1340
1252
|
this.items = items;
|
|
1341
1253
|
}
|
|
1342
1254
|
/**
|
|
@@ -1354,11 +1266,11 @@ class Collection extends Operand {
|
|
|
1354
1266
|
*/
|
|
1355
1267
|
|
|
1356
1268
|
|
|
1357
|
-
simplify(
|
|
1269
|
+
simplify() {
|
|
1358
1270
|
const values = [];
|
|
1359
1271
|
|
|
1360
1272
|
for (const item of this.items) {
|
|
1361
|
-
const simplifiedItem = item.simplify(...
|
|
1273
|
+
const simplifiedItem = item.simplify(...arguments);
|
|
1362
1274
|
|
|
1363
1275
|
if (isEvaluable(simplifiedItem)) {
|
|
1364
1276
|
return this;
|
|
@@ -1519,11 +1431,6 @@ class Reference extends Operand {
|
|
|
1519
1431
|
}
|
|
1520
1432
|
|
|
1521
1433
|
super();
|
|
1522
|
-
|
|
1523
|
-
_defineProperty(this, "key", void 0);
|
|
1524
|
-
|
|
1525
|
-
_defineProperty(this, "dataType", void 0);
|
|
1526
|
-
|
|
1527
1434
|
this.key = key;
|
|
1528
1435
|
const dataTypeMatch = dataTypeRegex.exec(this.key);
|
|
1529
1436
|
|
|
@@ -1550,7 +1457,7 @@ class Reference extends Operand {
|
|
|
1550
1457
|
*/
|
|
1551
1458
|
|
|
1552
1459
|
|
|
1553
|
-
simplify(ctx,
|
|
1460
|
+
simplify(ctx, strictKeys, optionalKeys) {
|
|
1554
1461
|
const keys = extractKeys(ctx, this.key);
|
|
1555
1462
|
|
|
1556
1463
|
if (!keys) {
|
|
@@ -1559,20 +1466,21 @@ class Reference extends Operand {
|
|
|
1559
1466
|
|
|
1560
1467
|
const key = keys[0].replace(/\[.+$/, '');
|
|
1561
1468
|
|
|
1562
|
-
if (ctx[key] !== undefined
|
|
1469
|
+
if (ctx[key] !== undefined) {
|
|
1563
1470
|
return this.evaluate(ctx);
|
|
1564
1471
|
}
|
|
1565
1472
|
|
|
1566
|
-
return this;
|
|
1473
|
+
return strictKeys && strictKeys.includes(key) || optionalKeys && !optionalKeys.includes(key) ? undefined : this;
|
|
1567
1474
|
}
|
|
1568
1475
|
/**
|
|
1569
1476
|
* {@link Evaluable.serialize}
|
|
1570
1477
|
*/
|
|
1571
1478
|
|
|
1572
1479
|
|
|
1573
|
-
serialize({
|
|
1574
|
-
|
|
1575
|
-
|
|
1480
|
+
serialize(_ref) {
|
|
1481
|
+
let {
|
|
1482
|
+
referenceSerialization
|
|
1483
|
+
} = _ref;
|
|
1576
1484
|
const key = this.dataType ? `${this.key}.(${this.dataType})` : this.key;
|
|
1577
1485
|
return referenceSerialization(key);
|
|
1578
1486
|
}
|
|
@@ -1614,11 +1522,6 @@ class Reference extends Operand {
|
|
|
1614
1522
|
|
|
1615
1523
|
}
|
|
1616
1524
|
|
|
1617
|
-
/**
|
|
1618
|
-
* Parser module.
|
|
1619
|
-
* @module illogical/parser
|
|
1620
|
-
*/
|
|
1621
|
-
|
|
1622
1525
|
/**
|
|
1623
1526
|
* Default reference predicate.
|
|
1624
1527
|
* The "$" symbol at the begging of the operand is used
|
|
@@ -1668,10 +1571,6 @@ class Parser {
|
|
|
1668
1571
|
* @param {Options?} options Parser options.
|
|
1669
1572
|
*/
|
|
1670
1573
|
constructor(options) {
|
|
1671
|
-
_defineProperty(this, "opts", void 0);
|
|
1672
|
-
|
|
1673
|
-
_defineProperty(this, "expectedOperators", void 0);
|
|
1674
|
-
|
|
1675
1574
|
this.opts = { ...defaultOptions
|
|
1676
1575
|
}; // Apply exclusive options overrides
|
|
1677
1576
|
|
|
@@ -1720,6 +1619,8 @@ class Parser {
|
|
|
1720
1619
|
|
|
1721
1620
|
|
|
1722
1621
|
parseRawExp(raw) {
|
|
1622
|
+
var _this = this;
|
|
1623
|
+
|
|
1723
1624
|
// Value / Reference
|
|
1724
1625
|
if (!Array.isArray(raw)) {
|
|
1725
1626
|
return this.getOperand(raw);
|
|
@@ -1741,9 +1642,11 @@ class Parser {
|
|
|
1741
1642
|
* @param collapsible
|
|
1742
1643
|
*/
|
|
1743
1644
|
|
|
1744
|
-
const logicalExpressionReducer = (operands
|
|
1645
|
+
const logicalExpressionReducer = function (operands) {
|
|
1646
|
+
let collapsible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1647
|
+
|
|
1745
1648
|
if (operands.length === 0 || operands.filter(operand => operand.type === EvaluableType.Expression).length === 0) {
|
|
1746
|
-
return
|
|
1649
|
+
return _this.getOperand(raw);
|
|
1747
1650
|
}
|
|
1748
1651
|
|
|
1749
1652
|
return collapsible && operands.length === 1 ? operands[0] : undefined;
|
|
@@ -1877,6 +1780,10 @@ class Parser {
|
|
|
1877
1780
|
|
|
1878
1781
|
}
|
|
1879
1782
|
|
|
1783
|
+
/**
|
|
1784
|
+
* Main module.
|
|
1785
|
+
* @module illogical
|
|
1786
|
+
*/
|
|
1880
1787
|
/**
|
|
1881
1788
|
* Condition engine
|
|
1882
1789
|
*/
|
|
@@ -1887,8 +1794,6 @@ class Engine {
|
|
|
1887
1794
|
* @param {Options?} options Parser options.
|
|
1888
1795
|
*/
|
|
1889
1796
|
constructor(options) {
|
|
1890
|
-
_defineProperty(this, "parser", void 0);
|
|
1891
|
-
|
|
1892
1797
|
this.parser = new Parser(options);
|
|
1893
1798
|
}
|
|
1894
1799
|
/**
|
|
@@ -1931,14 +1836,16 @@ class Engine {
|
|
|
1931
1836
|
*
|
|
1932
1837
|
* @param {ExpressionInput} exp Raw expression.
|
|
1933
1838
|
* @param {Context} context Evaluation data context.
|
|
1934
|
-
* @param {string[]}
|
|
1935
|
-
*
|
|
1839
|
+
* @param {string[]} strictKeys keys to be considered present even if they are not present in the context
|
|
1840
|
+
* @param {string[]} optionalKeys keys to be considered not present unless they are in the context or in
|
|
1841
|
+
* `strictKeys`; when `strictKeys` is `undefined` and `optionalKeys` is an array, every key that is not in
|
|
1842
|
+
* `optionalKeys` is considered to be present and thus will be evaluated
|
|
1936
1843
|
* @returns {Inpunt | boolean}
|
|
1937
1844
|
*/
|
|
1938
1845
|
|
|
1939
1846
|
|
|
1940
|
-
simplify(exp, context,
|
|
1941
|
-
const result = this.parse(exp).simplify(context,
|
|
1847
|
+
simplify(exp, context, strictKeys, optionalKeys) {
|
|
1848
|
+
const result = this.parse(exp).simplify(context, strictKeys, optionalKeys);
|
|
1942
1849
|
|
|
1943
1850
|
if (isEvaluable(result)) {
|
|
1944
1851
|
return result.serialize(this.parser.options);
|
|
@@ -1971,4 +1878,4 @@ exports.OPERATOR_PRESENT = OPERATOR$7;
|
|
|
1971
1878
|
exports.OPERATOR_SUFFIX = OPERATOR$6;
|
|
1972
1879
|
exports.OPERATOR_UNDEFINED = OPERATOR$5;
|
|
1973
1880
|
exports.OPERATOR_XOR = OPERATOR;
|
|
1974
|
-
exports
|
|
1881
|
+
exports["default"] = Engine;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@briza/illogical",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.",
|
|
5
5
|
"main": "lib/illogical.js",
|
|
6
6
|
"module": "lib/illogical.esm.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint": "eslint --max-warnings 0 \"src/**/*.{ts,js}\"",
|
|
26
26
|
"lint:fix": "eslint --max-warnings 0 \"src/**/*.{ts,js}\" --fix",
|
|
27
27
|
"prepublishOnly": "npm run test && npm run build",
|
|
28
|
-
"check-licenses": "license-checker --summary --excludePrivatePackages --onlyAllow \"MIT;MIT OR X11;Apache-2.0;ISC;BSD-3-Clause;BSD-2-Clause;CC-BY-4.0;Public Domain;BSD;CC-BY-3.0;CC0-1.0;Unlicense\""
|
|
28
|
+
"check-licenses": "license-checker --summary --excludePrivatePackages --onlyAllow \"MIT;MIT OR X11;Apache-2.0;ISC;BSD-3-Clause;BSD-2-Clause;CC-BY-4.0;Public Domain;BSD;CC-BY-3.0;CC0-1.0;Python-2.0;Unlicense\""
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -42,31 +42,31 @@
|
|
|
42
42
|
"rules"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/core": "^7.
|
|
46
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
47
|
-
"@babel/preset-env": "^7.
|
|
48
|
-
"@babel/preset-typescript": "^7.
|
|
45
|
+
"@babel/core": "^7.16.12",
|
|
46
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
47
|
+
"@babel/preset-env": "^7.16.11",
|
|
48
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
49
49
|
"@rollup/plugin-babel": "^5.2.3",
|
|
50
|
-
"@rollup/plugin-commonjs": "^
|
|
51
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
52
|
-
"@types/jest": "^
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
55
|
-
"eslint": "^
|
|
50
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
51
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
52
|
+
"@types/jest": "^27.4.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
54
|
+
"@typescript-eslint/parser": "^5.10.2",
|
|
55
|
+
"eslint": "^8.8.0",
|
|
56
56
|
"eslint-config-prettier": "^8.3.0",
|
|
57
|
-
"eslint-import-resolver-typescript": "^2.
|
|
58
|
-
"eslint-plugin-import": "^2.
|
|
57
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
58
|
+
"eslint-plugin-import": "^2.25.4",
|
|
59
59
|
"eslint-plugin-node": "^11.1.0",
|
|
60
|
-
"eslint-plugin-prettier": "^3.4.
|
|
61
|
-
"eslint-plugin-promise": "^
|
|
60
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
61
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
62
62
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
63
|
-
"jest": "^
|
|
63
|
+
"jest": "^27.4.7",
|
|
64
64
|
"license-checker": "^25.0.1",
|
|
65
|
-
"prettier": "^2.
|
|
66
|
-
"rollup": "^2.
|
|
65
|
+
"prettier": "^2.5.1",
|
|
66
|
+
"rollup": "^2.66.1",
|
|
67
67
|
"rollup-plugin-eslint": "^7.0.0",
|
|
68
|
-
"ts-jest": "^
|
|
69
|
-
"typedoc": "^0.
|
|
70
|
-
"typescript": "^4.
|
|
68
|
+
"ts-jest": "^27.1.3",
|
|
69
|
+
"typedoc": "^0.22.11",
|
|
70
|
+
"typescript": "^4.5.5"
|
|
71
71
|
}
|
|
72
|
-
}
|
|
72
|
+
}
|