@fincity/kirun-js 1.8.1 → 1.9.1
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/json/schema/validator/NullValidatorTest.ts +13 -0
- package/__tests__/engine/runtime/KIRuntimeDependencyTest.ts +118 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +35 -0
- package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +2 -0
- 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 +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/json/schema/validator/NullValidator.ts +6 -7
- package/src/engine/model/Statement.ts +26 -3
- package/src/engine/repository/KIRunFunctionRepository.ts +7 -1
- package/src/engine/runtime/KIRuntime.ts +18 -0
- package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schema, SchemaValidator } from '../../../../../src';
|
|
2
|
+
|
|
3
|
+
test('Check for valid Null value', () => {
|
|
4
|
+
let schema = Schema.from({
|
|
5
|
+
type: 'NULL',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
expect(() => SchemaValidator.validate([], schema!, undefined, 23)).toThrowError();
|
|
9
|
+
expect(() => SchemaValidator.validate([], schema!, undefined, 0)).toThrowError();
|
|
10
|
+
expect(() => SchemaValidator.validate([], schema!, undefined, '')).toThrowError();
|
|
11
|
+
expect(SchemaValidator.validate([], schema!, undefined, null)).toBeNull();
|
|
12
|
+
expect(SchemaValidator.validate([], schema!, undefined, undefined)).toBeUndefined();
|
|
13
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
|
|
2
|
+
import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
|
|
3
|
+
import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
|
|
5
|
+
import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
|
|
6
|
+
|
|
7
|
+
const oldLog = console.log;
|
|
8
|
+
|
|
9
|
+
test('KIRuntime With ExecuteIfTrue 1', async () => {
|
|
10
|
+
let def = {
|
|
11
|
+
name: 'getAppData',
|
|
12
|
+
namespace: 'UIApp',
|
|
13
|
+
parameters: {
|
|
14
|
+
a: {
|
|
15
|
+
parameterName: 'a',
|
|
16
|
+
schema: { name: 'INTEGER', type: ['ARRAY'], items: { type: ['OBJECT', 'NULL'] } },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
steps: {
|
|
21
|
+
forEach: {
|
|
22
|
+
statementName: 'forEach',
|
|
23
|
+
namespace: 'System.Loop',
|
|
24
|
+
name: 'ForEachLoop',
|
|
25
|
+
parameterMap: {
|
|
26
|
+
source: {
|
|
27
|
+
one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
print: {
|
|
32
|
+
statementName: 'print',
|
|
33
|
+
namespace: 'System',
|
|
34
|
+
name: 'Print',
|
|
35
|
+
parameterMap: {
|
|
36
|
+
values: {
|
|
37
|
+
one: {
|
|
38
|
+
key: 'one',
|
|
39
|
+
type: 'EXPRESSION',
|
|
40
|
+
expression: 'Steps.forEach.iteration.each.name',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
executeIftrue: {
|
|
45
|
+
'Steps.forEach.iteration.each.name': true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let fd = FunctionDefinition.from(def);
|
|
52
|
+
const mock = jest.spyOn(global.console, 'log').mockImplementation(oldLog);
|
|
53
|
+
|
|
54
|
+
await new KIRuntime(fd, false).execute(
|
|
55
|
+
new FunctionExecutionParameters(
|
|
56
|
+
new KIRunFunctionRepository(),
|
|
57
|
+
new KIRunSchemaRepository(),
|
|
58
|
+
).setArguments(
|
|
59
|
+
new Map([['a', [{ name: 'Kiran', age: 40 }, null, { name: 'Kumar', age: 39 }]]]),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(mock).toBeCalledTimes(2);
|
|
64
|
+
|
|
65
|
+
let newDef = {
|
|
66
|
+
name: 'getAppData',
|
|
67
|
+
namespace: 'UIApp',
|
|
68
|
+
parameters: {
|
|
69
|
+
a: {
|
|
70
|
+
parameterName: 'a',
|
|
71
|
+
schema: { name: 'INTEGER', type: ['ARRAY'], items: { type: ['OBJECT', 'NULL'] } },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
steps: {
|
|
76
|
+
forEach: {
|
|
77
|
+
statementName: 'forEach',
|
|
78
|
+
namespace: 'System.Loop',
|
|
79
|
+
name: 'ForEachLoop',
|
|
80
|
+
parameterMap: {
|
|
81
|
+
source: {
|
|
82
|
+
one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
print: {
|
|
87
|
+
statementName: 'print',
|
|
88
|
+
namespace: 'System',
|
|
89
|
+
name: 'Print',
|
|
90
|
+
parameterMap: {
|
|
91
|
+
values: {
|
|
92
|
+
one: {
|
|
93
|
+
key: 'one',
|
|
94
|
+
type: 'EXPRESSION',
|
|
95
|
+
expression: 'Steps.forEach.iteration.each.name',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
executeIftrue: {
|
|
100
|
+
'(Steps.forEach.iteration.each.age ?? 1) % 2 = 0': true,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
fd = FunctionDefinition.from(newDef);
|
|
107
|
+
|
|
108
|
+
let result = await new KIRuntime(fd, false).execute(
|
|
109
|
+
new FunctionExecutionParameters(
|
|
110
|
+
new KIRunFunctionRepository(),
|
|
111
|
+
new KIRunSchemaRepository(),
|
|
112
|
+
).setArguments(
|
|
113
|
+
new Map([['a', [{ name: 'Kiran', age: 40 }, null, { name: 'Kumar', age: 39 }]]]),
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(mock).toBeCalledTimes(3);
|
|
118
|
+
});
|
|
@@ -243,3 +243,38 @@ test('Partial path evaluation', () => {
|
|
|
243
243
|
console.log(ev.getExpression().toString());
|
|
244
244
|
expect(ev.evaluate(valuesMap)).toBe(2);
|
|
245
245
|
});
|
|
246
|
+
|
|
247
|
+
test('Expression with consecutive negative operators', () => {
|
|
248
|
+
let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
|
|
249
|
+
new Map<string, any>([
|
|
250
|
+
['a', 'kirun '],
|
|
251
|
+
['b', 1],
|
|
252
|
+
['b1', 4],
|
|
253
|
+
['b2', 4],
|
|
254
|
+
]),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
let valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
|
|
258
|
+
|
|
259
|
+
let ev = new ExpressionEvaluator('Arguments.b - Arguments.b1 - Arguments.b2');
|
|
260
|
+
expect(ev.evaluate(valuesMap)).toBe(-7);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('Expression with multiple coalesce operator', () => {
|
|
264
|
+
let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
|
|
265
|
+
new Map<string, any>([
|
|
266
|
+
['a', 'kirun '],
|
|
267
|
+
['b', 1],
|
|
268
|
+
['b1', 4],
|
|
269
|
+
['b2', 4],
|
|
270
|
+
]),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
let valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
|
|
274
|
+
|
|
275
|
+
let ev = new ExpressionEvaluator('Arguments.b3 ?? (Arguments.b - 3) ?? Arguments.b5 ?? 4');
|
|
276
|
+
expect(ev.evaluate(valuesMap)).toBe(-2);
|
|
277
|
+
|
|
278
|
+
ev = new ExpressionEvaluator('Arguments.b3 ?? Arguments.b - 3 ?? Arguments.b5 ?? 4');
|
|
279
|
+
expect(ev.evaluate(valuesMap)).toBe(-2);
|
|
280
|
+
});
|
package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts
CHANGED
|
@@ -46,9 +46,11 @@ test('OutputMapTokenValueExtractor Test', () => {
|
|
|
46
46
|
test('OutputMapTokenValueExtractor Test 2', () => {
|
|
47
47
|
let output: Map<string, Map<string, Map<string, any>>> = new Map([
|
|
48
48
|
['step1', new Map([['output', new Map([['arr', ['a', 'b', 'c']]])]])],
|
|
49
|
+
['step2', new Map([['output', new Map()]])],
|
|
49
50
|
]);
|
|
50
51
|
|
|
51
52
|
var omtv = new OutputMapTokenValueExtractor(output);
|
|
52
53
|
expect(omtv.getValue('Steps.step1.output.arr[1]')).toBe('b');
|
|
53
54
|
expect(omtv.getValue('Steps.step1.output.arr1[1]')).toBeUndefined();
|
|
55
|
+
expect(omtv.getValue('Steps.step2.output')).toBeDefined();
|
|
54
56
|
});
|