@fincity/kirun-js 1.6.17 → 1.8.0

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 (84) hide show
  1. package/__tests__/engine/function/system/array/AddFirstTest.ts +28 -19
  2. package/__tests__/engine/function/system/array/ArrayToArrayOfObjectsTest.ts +0 -2
  3. package/__tests__/engine/function/system/array/ArrayToObjectTest.ts +180 -0
  4. package/__tests__/engine/function/system/array/BinarySearchTest.ts +5 -20
  5. package/__tests__/engine/function/system/array/{AddTest.ts → ConcatenateTest.ts} +22 -24
  6. package/__tests__/engine/function/system/array/CopyTest.ts +1 -1
  7. package/__tests__/engine/function/system/array/DeleteFirstTest.ts +7 -9
  8. package/__tests__/engine/function/system/array/DeleteFromTest.ts +4 -12
  9. package/__tests__/engine/function/system/array/DeleteLastTest.ts +7 -9
  10. package/__tests__/engine/function/system/array/DeleteTest.ts +7 -9
  11. package/__tests__/engine/function/system/array/DisjointTest.ts +3 -3
  12. package/__tests__/engine/function/system/array/FillTest.ts +6 -6
  13. package/__tests__/engine/function/system/array/FrequencyTest.ts +2 -2
  14. package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +6 -24
  15. package/__tests__/engine/function/system/array/IndexOfTest.ts +5 -17
  16. package/__tests__/engine/function/system/array/InsertTest.ts +5 -15
  17. package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +3 -3
  18. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +4 -18
  19. package/__tests__/engine/function/system/array/MaxTest.ts +6 -8
  20. package/__tests__/engine/function/system/array/MinTest.ts +8 -8
  21. package/__tests__/engine/function/system/array/MisMatchTest.ts +3 -12
  22. package/__tests__/engine/function/system/array/RemoveDuplicatesTest.ts +74 -0
  23. package/__tests__/engine/function/system/array/ReverseTest.ts +4 -8
  24. package/__tests__/engine/function/system/array/RotateTest.ts +9 -9
  25. package/__tests__/engine/function/system/array/SortTest.ts +5 -5
  26. package/__tests__/engine/function/system/array/SubArrayTest.ts +4 -13
  27. package/__tests__/engine/function/system/loop/BreakLoopTest.ts +173 -0
  28. package/__tests__/engine/function/system/loop/CountLoopTest.ts +1 -1
  29. package/__tests__/engine/function/system/loop/RangeLoopTest.ts +145 -0
  30. package/__tests__/engine/function/system/string/SplitTest.ts +2 -2
  31. package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +0 -1
  32. package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +47 -0
  33. package/__tests__/engine/runtime/KIRuntimeNoValuesTest.ts +0 -1
  34. package/__tests__/engine/runtime/expression/tokenextractor/ObjectValueSetterExtractorTest.ts +51 -0
  35. package/dist/index.js +1 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/module.js +1 -1
  38. package/dist/module.js.map +1 -1
  39. package/dist/types.d.ts +41 -30
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/engine/function/system/array/AbstractArrayFunction.ts +5 -0
  43. package/src/engine/function/system/array/AddFirst.ts +8 -7
  44. package/src/engine/function/system/array/ArrayFunctionRepository.ts +8 -2
  45. package/src/engine/function/system/array/ArrayToObject.ts +77 -0
  46. package/src/engine/function/system/array/BinarySearch.ts +1 -1
  47. package/src/engine/function/system/array/{Add.ts → Concatenate.ts} +8 -6
  48. package/src/engine/function/system/array/Copy.ts +2 -2
  49. package/src/engine/function/system/array/Delete.ts +11 -7
  50. package/src/engine/function/system/array/DeleteFirst.ts +5 -2
  51. package/src/engine/function/system/array/DeleteFrom.ts +5 -2
  52. package/src/engine/function/system/array/DeleteLast.ts +5 -2
  53. package/src/engine/function/system/array/Disjoint.ts +1 -5
  54. package/src/engine/function/system/array/Fill.ts +6 -2
  55. package/src/engine/function/system/array/Frequency.ts +2 -5
  56. package/src/engine/function/system/array/IndexOf.ts +2 -2
  57. package/src/engine/function/system/array/IndexOfArray.ts +2 -2
  58. package/src/engine/function/system/array/Insert.ts +9 -3
  59. package/src/engine/function/system/array/InsertLast.ts +31 -0
  60. package/src/engine/function/system/array/LastIndexOf.ts +2 -7
  61. package/src/engine/function/system/array/LastIndexOfArray.ts +2 -6
  62. package/src/engine/function/system/array/Max.ts +1 -3
  63. package/src/engine/function/system/array/Min.ts +1 -3
  64. package/src/engine/function/system/array/MisMatch.ts +1 -1
  65. package/src/engine/function/system/array/RemoveDuplicates.ts +64 -0
  66. package/src/engine/function/system/array/Reverse.ts +6 -2
  67. package/src/engine/function/system/array/Rotate.ts +10 -3
  68. package/src/engine/function/system/array/Shuffle.ts +9 -3
  69. package/src/engine/function/system/array/Sort.ts +4 -3
  70. package/src/engine/function/system/array/SubArray.ts +1 -1
  71. package/src/engine/function/system/loop/Break.ts +31 -0
  72. package/src/engine/function/system/loop/CountLoop.ts +8 -2
  73. package/src/engine/function/system/loop/ForEachLoop.ts +70 -0
  74. package/src/engine/function/system/loop/RangeLoop.ts +7 -1
  75. package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -0
  76. package/src/engine/function/system/object/ObjectPutValue.ts +61 -0
  77. package/src/engine/json/schema/validator/SchemaValidator.ts +3 -2
  78. package/src/engine/repository/KIRunFunctionRepository.ts +5 -1
  79. package/src/engine/runtime/FunctionExecutionParameters.ts +10 -1
  80. package/src/engine/runtime/KIRuntime.ts +2 -1
  81. package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +3 -2
  82. package/src/engine/runtime/expression/tokenextractor/ObjectValueSetterExtractor.ts +172 -0
  83. package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +1 -1
  84. package/src/index.ts +1 -0
@@ -13,7 +13,7 @@ export class Delete extends AbstractArrayFunction {
13
13
  AbstractArrayFunction.PARAMETER_ARRAY_SOURCE,
14
14
  AbstractArrayFunction.PARAMETER_ANY_VAR_ARGS,
15
15
  ],
16
- AbstractArrayFunction.EVENT_RESULT_EMPTY,
16
+ AbstractArrayFunction.EVENT_RESULT_ARRAY,
17
17
  );
18
18
  }
19
19
 
@@ -37,7 +37,6 @@ export class Delete extends AbstractArrayFunction {
37
37
  );
38
38
 
39
39
  let indexes = new Set<number>();
40
- let duplicateResource: any[] = [];
41
40
 
42
41
  for (let i: number = source.length - 1; i >= 0; i--) {
43
42
  for (let j: number = 0; j < receivedArgs.length; j++) {
@@ -46,10 +45,15 @@ export class Delete extends AbstractArrayFunction {
46
45
  }
47
46
  }
48
47
 
49
- duplicateResource = source.filter((value) => !indexes.has(value));
50
-
51
- source.splice(0, source.length, ...duplicateResource);
52
-
53
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
48
+ return new FunctionOutput([
49
+ EventResult.outputOf(
50
+ new Map([
51
+ [
52
+ AbstractArrayFunction.EVENT_RESULT_NAME,
53
+ source.filter((value) => !indexes.has(value)),
54
+ ],
55
+ ]),
56
+ ),
57
+ ]);
54
58
  }
55
59
  }
@@ -6,7 +6,7 @@ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
6
 
7
7
  export class DeleteFirst extends AbstractArrayFunction {
8
8
  public constructor() {
9
- super('DeleteFirst', [DeleteFirst.PARAMETER_ARRAY_SOURCE], DeleteFirst.EVENT_RESULT_EMPTY);
9
+ super('DeleteFirst', [DeleteFirst.PARAMETER_ARRAY_SOURCE], DeleteFirst.EVENT_RESULT_ARRAY);
10
10
  }
11
11
 
12
12
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -16,7 +16,10 @@ export class DeleteFirst extends AbstractArrayFunction {
16
16
 
17
17
  if (source.length == 0) throw new KIRuntimeException('Given source array is empty');
18
18
 
19
+ source = [...source];
19
20
  source.shift();
20
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
21
+ return new FunctionOutput([
22
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
23
+ ]);
21
24
  }
22
25
  }
@@ -13,7 +13,7 @@ export class DeleteFrom extends AbstractArrayFunction {
13
13
  DeleteFrom.PARAMETER_INT_SOURCE_FROM,
14
14
  DeleteFrom.PARAMETER_INT_LENGTH,
15
15
  ],
16
- DeleteFrom.EVENT_RESULT_EMPTY,
16
+ DeleteFrom.EVENT_RESULT_ARRAY,
17
17
  );
18
18
  }
19
19
 
@@ -32,6 +32,7 @@ export class DeleteFrom extends AbstractArrayFunction {
32
32
 
33
33
  if (source.length == 0) throw new KIRuntimeException('There are no elements to be deleted');
34
34
 
35
+ source = [...source];
35
36
  if (start >= source.length || start < 0)
36
37
  throw new KIRuntimeException(
37
38
  'The int source for the array should be in between 0 and length of the array ',
@@ -46,6 +47,8 @@ export class DeleteFrom extends AbstractArrayFunction {
46
47
 
47
48
  source.splice(start, len);
48
49
 
49
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
50
+ return new FunctionOutput([
51
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
52
+ ]);
50
53
  }
51
54
  }
@@ -6,7 +6,7 @@ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
6
 
7
7
  export class DeleteLast extends AbstractArrayFunction {
8
8
  public constructor() {
9
- super('DeleteLast', [DeleteLast.PARAMETER_ARRAY_SOURCE], DeleteLast.EVENT_RESULT_EMPTY);
9
+ super('DeleteLast', [DeleteLast.PARAMETER_ARRAY_SOURCE], DeleteLast.EVENT_RESULT_ARRAY);
10
10
  }
11
11
 
12
12
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -16,8 +16,11 @@ export class DeleteLast extends AbstractArrayFunction {
16
16
 
17
17
  if (source.length == 0) throw new KIRuntimeException('Given source array is empty');
18
18
 
19
+ source = [...source];
19
20
  source.pop();
20
21
 
21
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
22
+ return new FunctionOutput([
23
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
24
+ ]);
22
25
  }
23
26
  }
@@ -74,12 +74,8 @@ export class Disjoint extends AbstractArrayFunction {
74
74
  if (!set1.has(element)) set3.add(element);
75
75
  });
76
76
 
77
- let disjointArray: any[] = [];
78
-
79
- set3.forEach((element) => disjointArray.push(element));
80
-
81
77
  return new FunctionOutput([
82
- EventResult.outputOf(new Map([[Disjoint.EVENT_RESULT_ARRAY.getName(), disjointArray]])),
78
+ EventResult.outputOf(new Map([[Disjoint.EVENT_RESULT_NAME, [...set3]]])),
83
79
  ]);
84
80
  }
85
81
  }
@@ -4,6 +4,7 @@ import { FunctionOutput } from '../../../model/FunctionOutput';
4
4
  import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
5
  import { MapUtil } from '../../../util/MapUtil';
6
6
  import { isNullValue } from '../../../util/NullCheck';
7
+ import { duplicate } from '../../../util/duplicate';
7
8
  import { StringFormatter } from '../../../util/string/StringFormatter';
8
9
  import { AbstractArrayFunction } from './AbstractArrayFunction';
9
10
 
@@ -38,14 +39,17 @@ export class Fill extends AbstractArrayFunction {
38
39
 
39
40
  let add = srcfrom + length - source.length;
40
41
 
42
+ source = [...source];
41
43
  if (add > 0) {
42
44
  for (let i = 0; i < add; i++) source.push();
43
45
  }
44
46
 
45
47
  for (let i = srcfrom; i < srcfrom + length; i++) {
46
- source[i] = isNullValue(element) ? element : JSON.parse(JSON.stringify(element));
48
+ source[i] = isNullValue(element) ? element : duplicate(element);
47
49
  }
48
50
 
49
- return new FunctionOutput([EventResult.outputOf(MapUtil.of())]);
51
+ return new FunctionOutput([
52
+ EventResult.outputOf(MapUtil.of(AbstractArrayFunction.EVENT_RESULT_NAME, source)),
53
+ ]);
50
54
  }
51
55
  }
@@ -39,15 +39,12 @@ export class Frequency extends AbstractArrayFunction {
39
39
 
40
40
  if (source.length == 0)
41
41
  return new FunctionOutput([
42
- EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_INTEGER.getName(), 0]])),
42
+ EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_NAME, 0]])),
43
43
  ]);
44
44
 
45
45
  if (start > source.length)
46
46
  throw new KIRuntimeException('Given start point is more than the size of source');
47
47
 
48
- if (isNullValue(find))
49
- throw new KIRuntimeException('Given find was null. Hence cannot be found in the array');
50
-
51
48
  let end: number = start + length;
52
49
 
53
50
  if (length == -1) end = source.length - start;
@@ -62,7 +59,7 @@ export class Frequency extends AbstractArrayFunction {
62
59
  }
63
60
 
64
61
  return new FunctionOutput([
65
- EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_INTEGER.getName(), frequency]])),
62
+ EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_NAME, frequency]])),
66
63
  ]);
67
64
  }
68
65
  }
@@ -32,7 +32,7 @@ export class IndexOf extends AbstractArrayFunction {
32
32
 
33
33
  if (source.length == 0)
34
34
  return new FunctionOutput([
35
- EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_INTEGER.getName(), -1]])),
35
+ EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_NAME, -1]])),
36
36
  ]);
37
37
 
38
38
  if (len < 0 || len > source.length)
@@ -50,7 +50,7 @@ export class IndexOf extends AbstractArrayFunction {
50
50
  }
51
51
 
52
52
  return new FunctionOutput([
53
- EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_INTEGER.getName(), index]])),
53
+ EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_NAME, index]])),
54
54
  ]);
55
55
  }
56
56
  }
@@ -33,7 +33,7 @@ export class IndexOfArray extends AbstractArrayFunction {
33
33
 
34
34
  if (source.length == 0 || secondSource.length == 0)
35
35
  return new FunctionOutput([
36
- EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_INTEGER.getName(), -1]])),
36
+ EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_NAME, -1]])),
37
37
  ]);
38
38
 
39
39
  if (from < 0 || from > source.length || source.length < secondSource.length)
@@ -61,7 +61,7 @@ export class IndexOfArray extends AbstractArrayFunction {
61
61
  }
62
62
 
63
63
  return new FunctionOutput([
64
- EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_INTEGER.getName(), index]])),
64
+ EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_NAME, index]])),
65
65
  ]);
66
66
  }
67
67
  }
@@ -10,7 +10,7 @@ export class Insert extends AbstractArrayFunction {
10
10
  super(
11
11
  'Insert',
12
12
  [Insert.PARAMETER_ARRAY_SOURCE, Insert.PARAMETER_INT_OFFSET, Insert.PARAMETER_ANY],
13
- Insert.EVENT_RESULT_EMPTY,
13
+ Insert.EVENT_RESULT_ARRAY,
14
14
  );
15
15
  }
16
16
 
@@ -28,9 +28,13 @@ export class Insert extends AbstractArrayFunction {
28
28
  if (isNullValue(output) || isNullValue(offset) || offset > source.length)
29
29
  throw new KIRuntimeException('Please valid resouces to insert at the correct location');
30
30
 
31
+ source = [...source];
32
+
31
33
  if (source.length == 0) {
32
34
  if (offset == 0) source.push(output);
33
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
35
+ return new FunctionOutput([
36
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
37
+ ]);
34
38
  }
35
39
 
36
40
  source.push(output);
@@ -43,6 +47,8 @@ export class Insert extends AbstractArrayFunction {
43
47
  source[len--] = temp;
44
48
  }
45
49
 
46
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
50
+ return new FunctionOutput([
51
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
52
+ ]);
47
53
  }
48
54
  }
@@ -0,0 +1,31 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { isNullValue } from '../../../util/NullCheck';
6
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
7
+
8
+ export class InsertLast extends AbstractArrayFunction {
9
+ public constructor() {
10
+ super(
11
+ 'InsertLast',
12
+ [InsertLast.PARAMETER_ARRAY_SOURCE, InsertLast.PARAMETER_ANY],
13
+ InsertLast.EVENT_RESULT_ARRAY,
14
+ );
15
+ }
16
+
17
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
18
+ let source: any[] = context
19
+ ?.getArguments()
20
+ ?.get(InsertLast.PARAMETER_ARRAY_SOURCE.getParameterName());
21
+
22
+ var output = context?.getArguments()?.get(InsertLast.PARAMETER_ANY.getParameterName());
23
+
24
+ source = [...source];
25
+
26
+ source.push(output);
27
+ return new FunctionOutput([
28
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
29
+ ]);
30
+ }
31
+ }
@@ -33,7 +33,7 @@ export class LastIndexOf extends AbstractArrayFunction {
33
33
 
34
34
  if (source.length == 0)
35
35
  return new FunctionOutput([
36
- EventResult.outputOf(new Map([[LastIndexOf.EVENT_RESULT_INTEGER.getName(), -1]])),
36
+ EventResult.outputOf(new Map([[LastIndexOf.EVENT_RESULT_NAME, -1]])),
37
37
  ]);
38
38
 
39
39
  if (len < 0 || len > source.length)
@@ -43,11 +43,6 @@ export class LastIndexOf extends AbstractArrayFunction {
43
43
 
44
44
  let index: number = -1;
45
45
 
46
- if (typeof find == null || typeof find == undefined)
47
- throw new KIRuntimeException(
48
- 'Please provide the valid find object or primitive in order to verify',
49
- );
50
-
51
46
  for (let i: number = source.length - 1; i >= len; i--) {
52
47
  if (PrimitiveUtil.compare(source[i], find) == 0) {
53
48
  index = i;
@@ -56,7 +51,7 @@ export class LastIndexOf extends AbstractArrayFunction {
56
51
  }
57
52
 
58
53
  return new FunctionOutput([
59
- EventResult.outputOf(new Map([[LastIndexOf.EVENT_RESULT_INTEGER.getName(), index]])),
54
+ EventResult.outputOf(new Map([[LastIndexOf.EVENT_RESULT_NAME, index]])),
60
55
  ]);
61
56
  }
62
57
  }
@@ -33,9 +33,7 @@ export class LastIndexOfArray extends AbstractArrayFunction {
33
33
 
34
34
  if (source.length == 0)
35
35
  return new FunctionOutput([
36
- EventResult.outputOf(
37
- new Map([[LastIndexOfArray.EVENT_RESULT_ARRAY.getName(), -1]]),
38
- ),
36
+ EventResult.outputOf(new Map([[LastIndexOfArray.EVENT_RESULT_NAME, -1]])),
39
37
  ]);
40
38
 
41
39
  if (from < 0 || from > source.length || secondSource.length > source.length)
@@ -62,9 +60,7 @@ export class LastIndexOfArray extends AbstractArrayFunction {
62
60
  }
63
61
 
64
62
  return new FunctionOutput([
65
- EventResult.outputOf(
66
- new Map([[LastIndexOfArray.EVENT_RESULT_INTEGER.getName(), index]]),
67
- ),
63
+ EventResult.outputOf(new Map([[LastIndexOfArray.EVENT_RESULT_NAME, index]])),
68
64
  ]);
69
65
  }
70
66
  }
@@ -24,8 +24,6 @@ export class Max extends AbstractArrayFunction {
24
24
  max = y;
25
25
  }
26
26
 
27
- return new FunctionOutput([
28
- EventResult.outputOf(new Map([[Max.EVENT_RESULT_ANY.getName(), max]])),
29
- ]);
27
+ return new FunctionOutput([EventResult.outputOf(new Map([[Max.EVENT_RESULT_NAME, max]]))]);
30
28
  }
31
29
  }
@@ -25,8 +25,6 @@ export class Min extends AbstractArrayFunction {
25
25
  min = source[i];
26
26
  }
27
27
 
28
- return new FunctionOutput([
29
- EventResult.outputOf(new Map([[Min.EVENT_RESULT_ANY.getName(), min]])),
30
- ]);
28
+ return new FunctionOutput([EventResult.outputOf(new Map([[Min.EVENT_RESULT_NAME, min]]))]);
31
29
  }
32
30
  }
@@ -60,7 +60,7 @@ export class MisMatch extends AbstractArrayFunction {
60
60
  }
61
61
 
62
62
  return new FunctionOutput([
63
- EventResult.outputOf(new Map([[MisMatch.EVENT_RESULT_INTEGER.getName(), index]])),
63
+ EventResult.outputOf(new Map([[MisMatch.EVENT_RESULT_NAME, index]])),
64
64
  ]);
65
65
  }
66
66
  }
@@ -0,0 +1,64 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { MapUtil } from '../../../util/MapUtil';
6
+ import { isNullValue } from '../../../util/NullCheck';
7
+ import { deepEqual } from '../../../util/deepEqual';
8
+ import { duplicate } from '../../../util/duplicate';
9
+ import { StringFormatter } from '../../../util/string/StringFormatter';
10
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
11
+
12
+ export class RemoveDuplicates extends AbstractArrayFunction {
13
+ public constructor() {
14
+ super(
15
+ 'RemoveDuplicates',
16
+ [
17
+ RemoveDuplicates.PARAMETER_ARRAY_SOURCE,
18
+ RemoveDuplicates.PARAMETER_INT_SOURCE_FROM,
19
+ RemoveDuplicates.PARAMETER_INT_LENGTH,
20
+ ],
21
+ RemoveDuplicates.EVENT_RESULT_ARRAY,
22
+ );
23
+ }
24
+
25
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
26
+ var source = context
27
+ ?.getArguments()
28
+ ?.get(RemoveDuplicates.PARAMETER_ARRAY_SOURCE.getParameterName());
29
+ var srcfrom = context
30
+ ?.getArguments()
31
+ ?.get(RemoveDuplicates.PARAMETER_INT_SOURCE_FROM.getParameterName());
32
+ var length = context
33
+ ?.getArguments()
34
+ ?.get(RemoveDuplicates.PARAMETER_INT_LENGTH.getParameterName());
35
+
36
+ if (length == -1) length = source.length - srcfrom;
37
+
38
+ if (srcfrom + length > source.length)
39
+ throw new KIRuntimeException(
40
+ StringFormatter.format(
41
+ 'Array has no elements from $ to $ as the array size is $',
42
+ srcfrom,
43
+ srcfrom + length,
44
+ source.length,
45
+ ),
46
+ );
47
+
48
+ const ja: any[] = [...source];
49
+ const to = srcfrom + length;
50
+
51
+ for (let i = to - 1; i >= srcfrom; i--) {
52
+ for (let j = i - 1; j >= srcfrom; j--) {
53
+ if (deepEqual(ja[i], ja[j])) {
54
+ ja.splice(i, 1);
55
+ break;
56
+ }
57
+ }
58
+ }
59
+
60
+ return new FunctionOutput([
61
+ EventResult.outputOf(MapUtil.of(RemoveDuplicates.EVENT_RESULT_NAME, ja)),
62
+ ]);
63
+ }
64
+ }
@@ -13,7 +13,7 @@ export class Reverse extends AbstractArrayFunction {
13
13
  Reverse.PARAMETER_INT_SOURCE_FROM,
14
14
  Reverse.PARAMETER_INT_LENGTH,
15
15
  ],
16
- Reverse.EVENT_RESULT_EMPTY,
16
+ Reverse.EVENT_RESULT_ARRAY,
17
17
  );
18
18
  }
19
19
 
@@ -37,6 +37,8 @@ export class Reverse extends AbstractArrayFunction {
37
37
  'Please provide start point between the start and end indexes or provide the length which was less than the source size ',
38
38
  );
39
39
 
40
+ source = [...source];
41
+
40
42
  let endpoint: number = st + len - 1;
41
43
  while (st <= endpoint) {
42
44
  let first: any = source[st];
@@ -45,6 +47,8 @@ export class Reverse extends AbstractArrayFunction {
45
47
  source[endpoint--] = first;
46
48
  }
47
49
 
48
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
50
+ return new FunctionOutput([
51
+ EventResult.outputOf(new Map([[Reverse.EVENT_RESULT_NAME, source]])),
52
+ ]);
49
53
  }
50
54
  }
@@ -8,7 +8,7 @@ export class Rotate extends AbstractArrayFunction {
8
8
  super(
9
9
  'Rotate',
10
10
  [Rotate.PARAMETER_ARRAY_SOURCE, Rotate.PARAMETER_ROTATE_LENGTH],
11
- Rotate.EVENT_RESULT_EMPTY,
11
+ Rotate.EVENT_RESULT_ANY,
12
12
  );
13
13
  }
14
14
 
@@ -21,7 +21,12 @@ export class Rotate extends AbstractArrayFunction {
21
21
  ?.getArguments()
22
22
  ?.get(Rotate.PARAMETER_ROTATE_LENGTH.getParameterName());
23
23
 
24
- if (source.length == 0) return new FunctionOutput([EventResult.outputOf(new Map([]))]);
24
+ if (source.length == 0)
25
+ return new FunctionOutput([
26
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
27
+ ]);
28
+
29
+ source = [...source];
25
30
 
26
31
  let size: number = source.length;
27
32
  rotLen = rotLen % size;
@@ -30,7 +35,9 @@ export class Rotate extends AbstractArrayFunction {
30
35
  this.rotate(source, rotLen, size - 1);
31
36
  this.rotate(source, 0, size - 1);
32
37
 
33
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
38
+ return new FunctionOutput([
39
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
40
+ ]);
34
41
  }
35
42
 
36
43
  private rotate(elements: any[], start: number, end: number): void {
@@ -5,7 +5,7 @@ import { AbstractArrayFunction } from './AbstractArrayFunction';
5
5
 
6
6
  export class Shuffle extends AbstractArrayFunction {
7
7
  public constructor() {
8
- super('Shuffle', [Shuffle.PARAMETER_ARRAY_SOURCE], Shuffle.EVENT_RESULT_EMPTY);
8
+ super('Shuffle', [Shuffle.PARAMETER_ARRAY_SOURCE], Shuffle.EVENT_RESULT_ANY);
9
9
  }
10
10
 
11
11
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -13,8 +13,12 @@ export class Shuffle extends AbstractArrayFunction {
13
13
  ?.getArguments()
14
14
  ?.get(Shuffle.PARAMETER_ARRAY_SOURCE.getParameterName());
15
15
 
16
- if (source.length <= 1) return new FunctionOutput([EventResult.outputOf(new Map([]))]);
16
+ if (source.length <= 1)
17
+ return new FunctionOutput([
18
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
19
+ ]);
17
20
 
21
+ source = [...source];
18
22
  let x: number = 0;
19
23
  let size: number = source.length;
20
24
 
@@ -26,6 +30,8 @@ export class Shuffle extends AbstractArrayFunction {
26
30
  x = y;
27
31
  }
28
32
 
29
- return new FunctionOutput([EventResult.outputOf(new Map([]))]);
33
+ return new FunctionOutput([
34
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
35
+ ]);
30
36
  }
31
37
  }
@@ -15,7 +15,7 @@ export class Sort extends AbstractArrayFunction {
15
15
  Sort.PARAMETER_INT_LENGTH,
16
16
  Sort.PARAMETER_BOOLEAN_ASCENDING,
17
17
  ],
18
- Sort.EVENT_RESULT_EMPTY,
18
+ Sort.EVENT_RESULT_ANY,
19
19
  );
20
20
  }
21
21
 
@@ -38,9 +38,10 @@ export class Sort extends AbstractArrayFunction {
38
38
 
39
39
  if (source.length == 0)
40
40
  return new FunctionOutput([
41
- EventResult.outputOf(new Map([[Sort.EVENT_RESULT_EMPTY.getName(), source]])),
41
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
42
42
  ]);
43
43
 
44
+ source = [...source];
44
45
  if (len == -1) len = source.length - start;
45
46
 
46
47
  if (start < 0 || start >= source.length || start + len > source.length)
@@ -55,7 +56,7 @@ export class Sort extends AbstractArrayFunction {
55
56
  source.splice(start, len, ...slicedArray);
56
57
 
57
58
  return new FunctionOutput([
58
- EventResult.outputOf(new Map([[Sort.EVENT_RESULT_EMPTY.getName(), source]])),
59
+ EventResult.outputOf(new Map([[AbstractArrayFunction.EVENT_RESULT_NAME, source]])),
59
60
  ]);
60
61
  }
61
62
  }
@@ -42,7 +42,7 @@ export class SubArray extends AbstractArrayFunction {
42
42
  let slicedArray: any[] = source.slice(start, start + len);
43
43
 
44
44
  return new FunctionOutput([
45
- EventResult.outputOf(new Map([[SubArray.EVENT_RESULT_ARRAY.getName(), slicedArray]])),
45
+ EventResult.outputOf(new Map([[SubArray.EVENT_RESULT_NAME, slicedArray]])),
46
46
  ]);
47
47
  }
48
48
  }
@@ -0,0 +1,31 @@
1
+ import { Schema } from '../../../json/schema/Schema';
2
+ import { SchemaType } from '../../../json/schema/type/SchemaType';
3
+ import { Event } from '../../../model/Event';
4
+ import { EventResult } from '../../../model/EventResult';
5
+ import { FunctionOutput } from '../../../model/FunctionOutput';
6
+ import { FunctionSignature } from '../../../model/FunctionSignature';
7
+ import { Parameter } from '../../../model/Parameter';
8
+ import { Namespaces } from '../../../namespaces/Namespaces';
9
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
10
+ import { AbstractFunction } from '../../AbstractFunction';
11
+
12
+ const STEP_NAME = 'stepName';
13
+
14
+ const SIGNATURE = new FunctionSignature('Break')
15
+ .setNamespace(Namespaces.SYSTEM_LOOP)
16
+ .setParameters(new Map([Parameter.ofEntry(STEP_NAME, Schema.of(STEP_NAME, SchemaType.STRING))]))
17
+ .setEvents(new Map([Event.outputEventMapEntry(new Map([]))]));
18
+
19
+ export class Break extends AbstractFunction {
20
+ public getSignature(): FunctionSignature {
21
+ return SIGNATURE;
22
+ }
23
+
24
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
25
+ let stepName: string = context.getArguments()?.get(STEP_NAME);
26
+
27
+ context.getExecutionContext().set(stepName, true);
28
+
29
+ return new FunctionOutput([EventResult.outputOf(new Map())]);
30
+ }
31
+ }
@@ -34,11 +34,17 @@ export class CountLoop extends AbstractFunction {
34
34
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
35
35
  let count: number = context.getArguments()?.get(COUNT);
36
36
  let current = 0;
37
+ let statementName = context.getStatementExecution()?.getStatement()?.getStatementName();
37
38
 
38
39
  return new FunctionOutput({
39
40
  next(): EventResult {
40
- if (current >= count) {
41
- return EventResult.outputOf(new Map([[VALUE, count]]));
41
+ if (
42
+ current >= count ||
43
+ (statementName && context.getExecutionContext()?.get(statementName))
44
+ ) {
45
+ // check for break;
46
+ if (statementName) context.getExecutionContext()?.delete(statementName);
47
+ return EventResult.outputOf(new Map([[VALUE, current]]));
42
48
  }
43
49
 
44
50
  const eve = EventResult.of(Event.ITERATION, new Map([[INDEX, current]]));