@fincity/kirun-js 1.0.1 → 1.0.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.
Files changed (26) hide show
  1. package/__tests__/engine/function/system/array/BinarySearchTest.ts +51 -42
  2. package/__tests__/engine/function/system/array/IndexOfTest.ts +1 -1
  3. package/__tests__/engine/function/system/context/SetFunctionTest.ts +52 -0
  4. package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +2 -2
  5. package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +10 -0
  6. package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +18 -10
  7. package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +5 -7
  8. package/__tests__/engine/runtime/expression/ExpressionTest.ts +6 -0
  9. package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/module.js +1 -1
  13. package/dist/module.js.map +1 -1
  14. package/dist/types.d.ts +3 -1
  15. package/dist/types.d.ts.map +1 -1
  16. package/package.json +1 -1
  17. package/src/engine/function/system/array/AbstractArrayFunction.ts +12 -0
  18. package/src/engine/function/system/array/BinarySearch.ts +3 -3
  19. package/src/engine/function/system/context/SetFunction.ts +94 -107
  20. package/src/engine/function/system/string/AbstractStringFunction.ts +61 -39
  21. package/src/engine/function/system/string/StringFunctionRepository.ts +2 -2
  22. package/src/engine/json/schema/validator/StringValidator.ts +1 -1
  23. package/src/engine/runtime/expression/Expression.ts +6 -8
  24. package/src/engine/runtime/expression/Operation.ts +26 -4
  25. package/src/engine/util/MapUtil.ts +10 -10
  26. package/src/engine/util/primitive/PrimitiveUtil.ts +2 -1
@@ -6,9 +6,9 @@ export class Operation {
6
6
  public static readonly ADDITION: Operation = new Operation('+');
7
7
  public static readonly SUBTRACTION: Operation = new Operation('-');
8
8
 
9
- public static readonly NOT: Operation = new Operation('not');
10
- public static readonly AND: Operation = new Operation('and');
11
- public static readonly OR: Operation = new Operation('or');
9
+ public static readonly NOT: Operation = new Operation('not', undefined, true);
10
+ public static readonly AND: Operation = new Operation('and', undefined, true);
11
+ public static readonly OR: Operation = new Operation('or', undefined, true);
12
12
  public static readonly LESS_THAN: Operation = new Operation('<');
13
13
  public static readonly LESS_THAN_EQUAL: Operation = new Operation('<=');
14
14
  public static readonly GREATER_THAN: Operation = new Operation('>');
@@ -144,6 +144,18 @@ export class Operation {
144
144
  ].map((e) => e.getOperator()),
145
145
  );
146
146
 
147
+ public static readonly OPERATORS_WITHOUT_SPACE_WRAP: Set<string> = new Set(
148
+ [
149
+ ...Array.from(Operation.ARITHMETIC_OPERATORS),
150
+ ...Array.from(Operation.LOGICAL_OPERATORS),
151
+ ...Array.from(Operation.BITWISE_OPERATORS),
152
+ Operation.ARRAY_OPERATOR,
153
+ Operation.OBJECT_OPERATOR,
154
+ ]
155
+ .filter((e) => !e.shouldBeWrappedInSpace())
156
+ .map((e) => e.getOperator()),
157
+ );
158
+
147
159
  public static readonly OPERATION_VALUE_OF: Map<string, Operation> = new Map(
148
160
  Array.from(Operation.VALUE_OF.entries()).map(([_, o]) => [o.getOperator(), o]),
149
161
  );
@@ -167,9 +179,15 @@ export class Operation {
167
179
 
168
180
  private operator: string;
169
181
  private operatorName: string;
170
- public constructor(operator: string, operatorName?: string) {
182
+ private _shouldBeWrappedInSpace: boolean;
183
+ public constructor(
184
+ operator: string,
185
+ operatorName?: string,
186
+ shouldBeWrappedInSpace: boolean = false,
187
+ ) {
171
188
  this.operator = operator;
172
189
  this.operatorName = operatorName ?? operator;
190
+ this._shouldBeWrappedInSpace = shouldBeWrappedInSpace;
173
191
  }
174
192
 
175
193
  public getOperator(): string {
@@ -180,6 +198,10 @@ export class Operation {
180
198
  return this.operatorName;
181
199
  }
182
200
 
201
+ public shouldBeWrappedInSpace(): boolean {
202
+ return this._shouldBeWrappedInSpace;
203
+ }
204
+
183
205
  public valueOf(str: string): Operation | undefined {
184
206
  return Operation.VALUE_OF.get(str);
185
207
  }
@@ -25,25 +25,25 @@ export class MapUtil {
25
25
  ): Map<K, V> {
26
26
  const map: Map<K, V> = new Map();
27
27
 
28
- if (k1 && v1) map.set(k1, v1);
28
+ if (!isNullValue(k1) && !isNullValue(v1)) map.set(k1!, v1!);
29
29
 
30
- if (k2 && v2) map.set(k2, v2);
30
+ if (!isNullValue(k2) && !isNullValue(v2)) map.set(k2!, v2!);
31
31
 
32
- if (k3 && v3) map.set(k3, v3);
32
+ if (!isNullValue(k3) && !isNullValue(v3)) map.set(k3!, v3!);
33
33
 
34
- if (k4 && v4) map.set(k4, v4);
34
+ if (!isNullValue(k4) && !isNullValue(v4)) map.set(k4!, v4!);
35
35
 
36
- if (k5 && v5) map.set(k5, v5);
36
+ if (!isNullValue(k5) && !isNullValue(v5)) map.set(k5!, v5!);
37
37
 
38
- if (k6 && v6) map.set(k6, v6);
38
+ if (!isNullValue(k6) && !isNullValue(v6)) map.set(k6!, v6!);
39
39
 
40
- if (k7 && v7) map.set(k7, v7);
40
+ if (!isNullValue(k7) && !isNullValue(v7)) map.set(k7!, v7!);
41
41
 
42
- if (k8 && v8) map.set(k8, v8);
42
+ if (!isNullValue(k8) && !isNullValue(v8)) map.set(k8!, v8!);
43
43
 
44
- if (k9 && v9) map.set(k9, v9);
44
+ if (!isNullValue(k9) && !isNullValue(v9)) map.set(k9!, v9!);
45
45
 
46
- if (k10 && v10) map.set(k10, v10);
46
+ if (!isNullValue(k10) && !isNullValue(v10)) map.set(k10!, v10!);
47
47
 
48
48
  return map;
49
49
  }
@@ -83,7 +83,7 @@ export class PrimitiveUtil {
83
83
  if (isNullValue(a) || isNullValue(b)) return isNullValue(a) ? -1 : 1;
84
84
 
85
85
  if (Array.isArray(a) || Array.isArray(b)) {
86
- if (Array.isArray(a) || Array.isArray(b)) {
86
+ if (Array.isArray(a) && Array.isArray(b)) {
87
87
  if (a.length != b.length) return a.length - b.length;
88
88
  for (let i = 0; i < a.length; i++) {
89
89
  let cmp: number = this.compare(a[i], b[i]);
@@ -104,6 +104,7 @@ export class PrimitiveUtil {
104
104
  if (cmp != 0) return cmp;
105
105
  });
106
106
  }
107
+ return typofa === 'object' ? -1 : 1;
107
108
  }
108
109
 
109
110
  return this.comparePrimitive(a, b);