@fincity/kirun-js 1.6.17 → 1.7.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.
- package/__tests__/engine/function/system/array/AddFirstTest.ts +28 -19
- package/__tests__/engine/function/system/array/ArrayToArrayOfObjectsTest.ts +0 -2
- package/__tests__/engine/function/system/array/BinarySearchTest.ts +5 -20
- package/__tests__/engine/function/system/array/{AddTest.ts → ConcatenateTest.ts} +22 -24
- package/__tests__/engine/function/system/array/CopyTest.ts +1 -1
- package/__tests__/engine/function/system/array/DeleteFirstTest.ts +7 -9
- package/__tests__/engine/function/system/array/DeleteFromTest.ts +4 -12
- package/__tests__/engine/function/system/array/DeleteLastTest.ts +7 -9
- package/__tests__/engine/function/system/array/DeleteTest.ts +7 -9
- package/__tests__/engine/function/system/array/DisjointTest.ts +3 -3
- package/__tests__/engine/function/system/array/FillTest.ts +6 -6
- package/__tests__/engine/function/system/array/FrequencyTest.ts +2 -2
- package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +6 -24
- package/__tests__/engine/function/system/array/IndexOfTest.ts +5 -17
- package/__tests__/engine/function/system/array/InsertTest.ts +5 -15
- package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +3 -3
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +4 -18
- package/__tests__/engine/function/system/array/MaxTest.ts +6 -8
- package/__tests__/engine/function/system/array/MinTest.ts +8 -8
- package/__tests__/engine/function/system/array/MisMatchTest.ts +3 -12
- package/__tests__/engine/function/system/array/ReverseTest.ts +4 -8
- package/__tests__/engine/function/system/array/RotateTest.ts +9 -9
- package/__tests__/engine/function/system/array/SortTest.ts +5 -5
- package/__tests__/engine/function/system/array/SubArrayTest.ts +4 -13
- package/__tests__/engine/function/system/loop/BreakLoopTest.ts +173 -0
- package/__tests__/engine/function/system/loop/RangeLoopTest.ts +145 -0
- package/__tests__/engine/function/system/string/SplitTest.ts +2 -2
- package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +0 -1
- package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +47 -0
- package/__tests__/engine/runtime/KIRuntimeNoValuesTest.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +32 -30
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/array/AddFirst.ts +8 -7
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +4 -2
- package/src/engine/function/system/array/BinarySearch.ts +1 -1
- package/src/engine/function/system/array/{Add.ts → Concatenate.ts} +8 -6
- package/src/engine/function/system/array/Copy.ts +2 -2
- package/src/engine/function/system/array/Delete.ts +11 -7
- package/src/engine/function/system/array/DeleteFirst.ts +5 -2
- package/src/engine/function/system/array/DeleteFrom.ts +5 -2
- package/src/engine/function/system/array/DeleteLast.ts +5 -2
- package/src/engine/function/system/array/Disjoint.ts +1 -5
- package/src/engine/function/system/array/Fill.ts +6 -2
- package/src/engine/function/system/array/Frequency.ts +2 -5
- package/src/engine/function/system/array/IndexOf.ts +2 -2
- package/src/engine/function/system/array/IndexOfArray.ts +2 -2
- package/src/engine/function/system/array/Insert.ts +9 -3
- package/src/engine/function/system/array/InsertLast.ts +31 -0
- package/src/engine/function/system/array/LastIndexOf.ts +2 -7
- package/src/engine/function/system/array/LastIndexOfArray.ts +2 -6
- package/src/engine/function/system/array/Max.ts +1 -3
- package/src/engine/function/system/array/Min.ts +1 -3
- package/src/engine/function/system/array/MisMatch.ts +1 -1
- package/src/engine/function/system/array/Reverse.ts +6 -2
- package/src/engine/function/system/array/Rotate.ts +10 -3
- package/src/engine/function/system/array/Shuffle.ts +9 -3
- package/src/engine/function/system/array/Sort.ts +4 -3
- package/src/engine/function/system/array/SubArray.ts +1 -1
- package/src/engine/function/system/loop/Break.ts +31 -0
- package/src/engine/function/system/loop/CountLoop.ts +8 -2
- package/src/engine/function/system/loop/ForEachLoop.ts +70 -0
- package/src/engine/function/system/loop/RangeLoop.ts +7 -1
- package/src/engine/json/schema/validator/SchemaValidator.ts +3 -2
- package/src/engine/repository/KIRunFunctionRepository.ts +5 -1
- package/src/engine/runtime/FunctionExecutionParameters.ts +10 -1
- package/src/engine/runtime/KIRuntime.ts +2 -1
|
@@ -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 :
|
|
48
|
+
source[i] = isNullValue(element) ? element : duplicate(element);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
return new FunctionOutput([
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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([
|
|
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([
|
|
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.
|
|
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.
|
|
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.
|
|
63
|
+
EventResult.outputOf(new Map([[MisMatch.EVENT_RESULT_NAME, index]])),
|
|
64
64
|
]);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -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.
|
|
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([
|
|
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.
|
|
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)
|
|
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([
|
|
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.
|
|
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)
|
|
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([
|
|
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.
|
|
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([[
|
|
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([[
|
|
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.
|
|
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 (
|
|
41
|
-
|
|
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]]));
|
|
@@ -0,0 +1,70 @@
|
|
|
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 SOURCE = 'source';
|
|
13
|
+
const EACH = 'each';
|
|
14
|
+
const INDEX = 'index';
|
|
15
|
+
const VALUE = 'value';
|
|
16
|
+
|
|
17
|
+
const SIGNATURE = new FunctionSignature('ForEachLoop')
|
|
18
|
+
.setNamespace(Namespaces.SYSTEM_LOOP)
|
|
19
|
+
.setParameters(
|
|
20
|
+
new Map([Parameter.ofEntry(SOURCE, Schema.ofArray(SOURCE, Schema.ofAny(SOURCE)))]),
|
|
21
|
+
)
|
|
22
|
+
.setEvents(
|
|
23
|
+
new Map([
|
|
24
|
+
Event.eventMapEntry(
|
|
25
|
+
Event.ITERATION,
|
|
26
|
+
new Map([
|
|
27
|
+
[INDEX, Schema.of(INDEX, SchemaType.INTEGER)],
|
|
28
|
+
[EACH, Schema.ofAny(EACH)],
|
|
29
|
+
]),
|
|
30
|
+
),
|
|
31
|
+
Event.outputEventMapEntry(new Map([[VALUE, Schema.of(VALUE, SchemaType.INTEGER)]])),
|
|
32
|
+
]),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export class ForEachLoop extends AbstractFunction {
|
|
36
|
+
public getSignature(): FunctionSignature {
|
|
37
|
+
return SIGNATURE;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
41
|
+
let source: any[] = context.getArguments()?.get(SOURCE);
|
|
42
|
+
|
|
43
|
+
let current = 0;
|
|
44
|
+
|
|
45
|
+
let statementName = context.getStatementExecution()?.getStatement()?.getStatementName();
|
|
46
|
+
|
|
47
|
+
return new FunctionOutput({
|
|
48
|
+
next(): EventResult {
|
|
49
|
+
if (
|
|
50
|
+
current >= source.length ||
|
|
51
|
+
(statementName && context.getExecutionContext()?.get(statementName)) //check for breaks;
|
|
52
|
+
) {
|
|
53
|
+
if (statementName) context.getExecutionContext()?.delete(statementName);
|
|
54
|
+
return EventResult.outputOf(new Map([[VALUE, current]]));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const eve = EventResult.of(
|
|
58
|
+
Event.ITERATION,
|
|
59
|
+
new Map([
|
|
60
|
+
[INDEX, current],
|
|
61
|
+
[EACH, source[current]],
|
|
62
|
+
]),
|
|
63
|
+
);
|
|
64
|
+
++current;
|
|
65
|
+
|
|
66
|
+
return eve;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -100,13 +100,19 @@ export class RangeLoop extends AbstractFunction {
|
|
|
100
100
|
const forward = step > 0;
|
|
101
101
|
let current: number = from;
|
|
102
102
|
let done: boolean = false;
|
|
103
|
+
let statementName = context.getStatementExecution()?.getStatement()?.getStatementName();
|
|
103
104
|
|
|
104
105
|
return new FunctionOutput({
|
|
105
106
|
next(): EventResult | undefined {
|
|
106
107
|
if (done) return undefined;
|
|
107
108
|
|
|
108
|
-
if (
|
|
109
|
+
if (
|
|
110
|
+
(forward && current >= to) ||
|
|
111
|
+
(!forward && current <= to) ||
|
|
112
|
+
(statementName && context.getExecutionContext()?.get(statementName)) //Check for break;
|
|
113
|
+
) {
|
|
109
114
|
done = true;
|
|
115
|
+
if (statementName) context.getExecutionContext()?.delete(statementName);
|
|
110
116
|
return EventResult.outputOf(new Map([[VALUE, current]]));
|
|
111
117
|
}
|
|
112
118
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Repository } from '../../../Repository';
|
|
2
|
+
import { deepEqual } from '../../../util/deepEqual';
|
|
2
3
|
import { isNullValue } from '../../../util/NullCheck';
|
|
3
4
|
import { StringUtil } from '../../../util/string/StringUtil';
|
|
4
5
|
import { Schema } from '../Schema';
|
|
@@ -40,7 +41,7 @@ export class SchemaValidator {
|
|
|
40
41
|
return JSON.parse(JSON.stringify(schema.getDefaultValue()));
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
if (schema.getConstant()) {
|
|
44
|
+
if (!isNullValue(schema.getConstant())) {
|
|
44
45
|
return SchemaValidator.constantValidation(parents, schema, element);
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -92,7 +93,7 @@ export class SchemaValidator {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
public static constantValidation(parents: Schema[], schema: Schema, element: any): any {
|
|
95
|
-
if (!schema.getConstant()
|
|
96
|
+
if (!deepEqual(schema.getConstant(), element)) {
|
|
96
97
|
throw new SchemaValidationException(
|
|
97
98
|
SchemaValidator.path(parents),
|
|
98
99
|
'Expecting a constant value : ' + element,
|
|
@@ -5,6 +5,7 @@ import { Get } from '../function/system/context/Get';
|
|
|
5
5
|
import { SetFunction } from '../function/system/context/SetFunction';
|
|
6
6
|
import { GenerateEvent } from '../function/system/GenerateEvent';
|
|
7
7
|
import { If } from '../function/system/If';
|
|
8
|
+
import { Break } from '../function/system/loop/Break';
|
|
8
9
|
import { CountLoop } from '../function/system/loop/CountLoop';
|
|
9
10
|
import { RangeLoop } from '../function/system/loop/RangeLoop';
|
|
10
11
|
import { MathFunctionRepository } from '../function/system/math/MathFunctionRepository';
|
|
@@ -20,7 +21,10 @@ const map: Map<string, Map<string, Function>> = new Map([
|
|
|
20
21
|
Namespaces.SYSTEM_CTX,
|
|
21
22
|
new Map([mapEntry(new Create()), mapEntry(new Get()), mapEntry(new SetFunction())]),
|
|
22
23
|
],
|
|
23
|
-
[
|
|
24
|
+
[
|
|
25
|
+
Namespaces.SYSTEM_LOOP,
|
|
26
|
+
new Map([mapEntry(new RangeLoop()), mapEntry(new CountLoop()), mapEntry(new Break())]),
|
|
27
|
+
],
|
|
24
28
|
[
|
|
25
29
|
Namespaces.SYSTEM,
|
|
26
30
|
new Map([mapEntry(new If()), mapEntry(new GenerateEvent()), mapEntry(new Print())]),
|
|
@@ -5,7 +5,6 @@ import UUID from '../util/UUID';
|
|
|
5
5
|
import { ContextElement } from './ContextElement';
|
|
6
6
|
import { TokenValueExtractor } from './expression/tokenextractor/TokenValueExtractor';
|
|
7
7
|
import { StatementExecution } from './StatementExecution';
|
|
8
|
-
import { ArgumentsTokenValueExtractor } from './tokenextractor/ArgumentsTokenValueExtractor';
|
|
9
8
|
import { ContextTokenValueExtractor } from './tokenextractor/ContextTokenValueExtractor';
|
|
10
9
|
import { OutputMapTokenValueExtractor } from './tokenextractor/OutputMapTokenValueExtractor';
|
|
11
10
|
|
|
@@ -19,6 +18,7 @@ export class FunctionExecutionParameters {
|
|
|
19
18
|
private functionRepository: Repository<Function>;
|
|
20
19
|
private schemaRepository: Repository<Schema>;
|
|
21
20
|
private executionId: string;
|
|
21
|
+
private executionContext: Map<string, any> = new Map();
|
|
22
22
|
|
|
23
23
|
private valueExtractors: Map<string, TokenValueExtractor> = new Map();
|
|
24
24
|
|
|
@@ -121,4 +121,13 @@ export class FunctionExecutionParameters {
|
|
|
121
121
|
|
|
122
122
|
return this;
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
public setExecutionContext(executionContext: Map<string, any>): FunctionExecutionParameters {
|
|
126
|
+
this.executionContext = executionContext;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public getExecutionContext(): Map<string, any> {
|
|
131
|
+
return this.executionContext;
|
|
132
|
+
}
|
|
124
133
|
}
|
|
@@ -359,7 +359,8 @@ export class KIRuntime extends AbstractFunction {
|
|
|
359
359
|
.setEvents(inContext.getEvents()!)
|
|
360
360
|
.setSteps(inContext.getSteps()!)
|
|
361
361
|
.setStatementExecution(vertex.getData())
|
|
362
|
-
.setCount(inContext.getCount())
|
|
362
|
+
.setCount(inContext.getCount())
|
|
363
|
+
.setExecutionContext(inContext.getExecutionContext());
|
|
363
364
|
}
|
|
364
365
|
|
|
365
366
|
let result: FunctionOutput = await fun.execute(fep);
|