@fincity/kirun-js 1.9.0 → 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 +60 -7
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +35 -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.map +1 -1
- package/package.json +1 -1
- package/src/engine/json/schema/validator/NullValidator.ts +6 -7
- package/src/engine/model/Statement.ts +13 -3
- package/src/engine/runtime/KIRuntime.ts +11 -6
|
@@ -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
|
+
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
|
|
2
|
-
import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
|
|
3
2
|
import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
|
|
4
3
|
import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
|
|
5
4
|
import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
|
|
6
5
|
import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const oldLog = console.log;
|
|
8
|
+
|
|
9
|
+
test('KIRuntime With ExecuteIfTrue 1', async () => {
|
|
10
|
+
let def = {
|
|
10
11
|
name: 'getAppData',
|
|
11
12
|
namespace: 'UIApp',
|
|
12
13
|
parameters: {
|
|
@@ -47,12 +48,10 @@ test('KIRuntime With Definition 1', async () => {
|
|
|
47
48
|
},
|
|
48
49
|
};
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
const oldLog = console.log;
|
|
52
|
-
|
|
51
|
+
let fd = FunctionDefinition.from(def);
|
|
53
52
|
const mock = jest.spyOn(global.console, 'log').mockImplementation(oldLog);
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
await new KIRuntime(fd, false).execute(
|
|
56
55
|
new FunctionExecutionParameters(
|
|
57
56
|
new KIRunFunctionRepository(),
|
|
58
57
|
new KIRunSchemaRepository(),
|
|
@@ -62,4 +61,58 @@ test('KIRuntime With Definition 1', async () => {
|
|
|
62
61
|
);
|
|
63
62
|
|
|
64
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);
|
|
65
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
|
+
});
|