@fincity/kirun-js 1.0.0 → 1.0.3

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 (27) 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 +108 -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
  27. package/src/index.ts +11 -0
@@ -25,45 +25,67 @@ export abstract class AbstractStringFunction extends AbstractFunction {
25
25
 
26
26
  public static readonly EVENT_RESULT_NAME: string = 'result';
27
27
 
28
- protected static readonly PARAMETER_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_STRING_NAME));
29
-
30
- protected static readonly PARAMETER_SECOND_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_SECOND_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_SECOND_STRING_NAME));
31
-
32
- protected static readonly PARAMETER_THIRD_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_THIRD_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_THIRD_STRING_NAME));
33
-
34
- protected static readonly PARAMETER_INDEX: Parameter =new Parameter(AbstractStringFunction.PARAMETER_INDEX_NAME,Schema.ofInteger(AbstractStringFunction.PARAMETER_INDEX_NAME));
35
-
36
- protected static readonly PARAMETER_SECOND_INDEX: Parameter =new Parameter(AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME,Schema.ofInteger(AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME));
37
-
38
- protected static readonly PARAMETER_SEARCH_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_STRING_NAME));
39
-
40
- protected static readonly EVENT_STRING: Event =new Event(Event.OUTPUT,
41
- MapUtil.of(
42
- AbstractStringFunction.EVENT_RESULT_NAME,
43
- Schema.ofString(AbstractStringFunction.EVENT_RESULT_NAME),
44
- ),
45
- );
46
-
47
- protected static readonly EVENT_BOOLEAN: Event =new Event(Event.OUTPUT,
48
- MapUtil.of(
49
- AbstractStringFunction.EVENT_RESULT_NAME,
50
- Schema.ofBoolean(AbstractStringFunction.EVENT_RESULT_NAME),
51
- ),
52
- );
53
-
54
- protected static readonly EVENT_INT: Event =new Event(Event.OUTPUT,
55
- MapUtil.of(
56
- AbstractStringFunction.EVENT_RESULT_NAME,
57
- Schema.ofInteger(AbstractStringFunction.EVENT_RESULT_NAME),
58
- ),
59
- );
60
-
61
- protected static readonly EVENT_ARRAY: Event =new Event(Event.OUTPUT,
62
- MapUtil.of(
63
- AbstractStringFunction.EVENT_RESULT_NAME,
64
- Schema.ofArray(AbstractStringFunction.EVENT_RESULT_NAME),
65
- ),
66
- );
28
+ protected static readonly PARAMETER_STRING: Parameter = new Parameter(
29
+ AbstractStringFunction.PARAMETER_STRING_NAME,
30
+ Schema.ofString(AbstractStringFunction.PARAMETER_STRING_NAME),
31
+ );
32
+
33
+ protected static readonly PARAMETER_SECOND_STRING: Parameter = new Parameter(
34
+ AbstractStringFunction.PARAMETER_SECOND_STRING_NAME,
35
+ Schema.ofString(AbstractStringFunction.PARAMETER_SECOND_STRING_NAME),
36
+ );
37
+
38
+ protected static readonly PARAMETER_THIRD_STRING: Parameter = new Parameter(
39
+ AbstractStringFunction.PARAMETER_THIRD_STRING_NAME,
40
+ Schema.ofString(AbstractStringFunction.PARAMETER_THIRD_STRING_NAME),
41
+ );
42
+
43
+ protected static readonly PARAMETER_INDEX: Parameter = new Parameter(
44
+ AbstractStringFunction.PARAMETER_INDEX_NAME,
45
+ Schema.ofInteger(AbstractStringFunction.PARAMETER_INDEX_NAME),
46
+ );
47
+
48
+ protected static readonly PARAMETER_SECOND_INDEX: Parameter = new Parameter(
49
+ AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME,
50
+ Schema.ofInteger(AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME),
51
+ );
52
+
53
+ protected static readonly PARAMETER_SEARCH_STRING: Parameter = new Parameter(
54
+ AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME,
55
+ Schema.ofString(AbstractStringFunction.PARAMETER_STRING_NAME),
56
+ );
57
+
58
+ protected static readonly EVENT_STRING: Event = new Event(
59
+ Event.OUTPUT,
60
+ MapUtil.of(
61
+ AbstractStringFunction.EVENT_RESULT_NAME,
62
+ Schema.ofString(AbstractStringFunction.EVENT_RESULT_NAME),
63
+ ),
64
+ );
65
+
66
+ protected static readonly EVENT_BOOLEAN: Event = new Event(
67
+ Event.OUTPUT,
68
+ MapUtil.of(
69
+ AbstractStringFunction.EVENT_RESULT_NAME,
70
+ Schema.ofBoolean(AbstractStringFunction.EVENT_RESULT_NAME),
71
+ ),
72
+ );
73
+
74
+ protected static readonly EVENT_INT: Event = new Event(
75
+ Event.OUTPUT,
76
+ MapUtil.of(
77
+ AbstractStringFunction.EVENT_RESULT_NAME,
78
+ Schema.ofInteger(AbstractStringFunction.EVENT_RESULT_NAME),
79
+ ),
80
+ );
81
+
82
+ protected static readonly EVENT_ARRAY: Event = new Event(
83
+ Event.OUTPUT,
84
+ MapUtil.of(
85
+ AbstractStringFunction.EVENT_RESULT_NAME,
86
+ Schema.ofArray(AbstractStringFunction.EVENT_RESULT_NAME),
87
+ ),
88
+ );
67
89
 
68
90
  private signature: FunctionSignature;
69
91
 
@@ -9,8 +9,8 @@ export class StringFunctionRepository implements Repository<Function> {
9
9
  AbstractStringFunction.ofEntryString('Trim', (e) => e.trim()),
10
10
  AbstractStringFunction.ofEntryString('LowerCase', (e) => e.toLocaleLowerCase()),
11
11
  AbstractStringFunction.ofEntryString('UpperCase', (e) => e.toUpperCase()),
12
- AbstractStringFunction.ofEntryStringBooleanOutput('Blank', (e) => e.trim() == ''),
13
- AbstractStringFunction.ofEntryStringBooleanOutput('Empty', (e) => e == ''),
12
+ AbstractStringFunction.ofEntryStringBooleanOutput('IsBlank', (e) => e.trim() === ''),
13
+ AbstractStringFunction.ofEntryStringBooleanOutput('IsEmpty', (e) => e === ''),
14
14
 
15
15
  AbstractStringFunction.ofEntryAsStringBooleanOutput(
16
16
  'Contains',
@@ -18,7 +18,7 @@ export class StringValidator {
18
18
  if (isNullValue(element))
19
19
  throw new SchemaValidationException(
20
20
  SchemaValidator.path(parents),
21
- 'Expected a string but found null',
21
+ 'Expected a string but found ' + element,
22
22
  );
23
23
 
24
24
  if (typeof element !== 'string')
@@ -134,7 +134,7 @@ export class Expression extends ExpressionToken {
134
134
 
135
135
  for (let size = start; size > 0; size--) {
136
136
  let op: string = this.expression.substring(i, i + size);
137
- if (Operation.OPERATORS.has(op)) {
137
+ if (Operation.OPERATORS_WITHOUT_SPACE_WRAP.has(op)) {
138
138
  if (!StringUtil.isNullOrBlank(buff)) {
139
139
  this.tokens.push(new ExpressionToken(buff));
140
140
  isPrevOp = false;
@@ -236,14 +236,12 @@ export class Expression extends ExpressionToken {
236
236
  op: Operation | undefined,
237
237
  isPrevOp: boolean,
238
238
  ): void {
239
- if(!op) return;
239
+ if (!op) return;
240
240
  if (isPrevOp || tokens.isEmpty()) {
241
- if (Operation.UNARY_OPERATORS.has(op)){
241
+ if (Operation.UNARY_OPERATORS.has(op)) {
242
242
  const x = Operation.UNARY_MAP.get(op);
243
- if(x)
244
- ops.push(x);
245
- }
246
- else
243
+ if (x) ops.push(x);
244
+ } else
247
245
  throw new ExpressionEvaluationException(
248
246
  this.expression,
249
247
  StringFormatter.format('Extra operator $ found.', op),
@@ -269,7 +267,7 @@ export class Expression extends ExpressionToken {
269
267
  private hasPrecedence(op1: Operation, op2: Operation): boolean {
270
268
  let pre1: number | undefined = Operation.OPERATOR_PRIORITY.get(op1);
271
269
  let pre2: number | undefined = Operation.OPERATOR_PRIORITY.get(op2);
272
- if(!pre1 || !pre2) {
270
+ if (!pre1 || !pre2) {
273
271
  throw new Error('Unknown operators provided');
274
272
  }
275
273
  return pre2 < pre1;
@@ -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);
package/src/index.ts CHANGED
@@ -11,3 +11,14 @@ export * from './engine/function/Function';
11
11
  export * from './engine/function/AbstractFunction';
12
12
  export * from './engine/namespaces/Namespaces';
13
13
  export * from './engine/runtime/KIRuntime';
14
+ export * from './engine/runtime/expression/Expression';
15
+ export * from './engine/runtime/expression/ExpressionEvaluator';
16
+ export * from './engine/runtime/expression/tokenextractor/TokenValueExtractor';
17
+ export * from './engine/runtime/expression/exception/ExpressionEvaluationException';
18
+ export * from './engine/runtime/expression/ExpressionToken';
19
+ export * from './engine/runtime/expression/ExpressionTokenValue';
20
+ export * from './engine/runtime/expression/Operation';
21
+ export * from './engine/util/LinkedList';
22
+ export * from './engine/util/NullCheck';
23
+ export * from './engine/util/string/StringFormatter';
24
+ export * from './engine/util/string/StringUtil';