@fincity/kirun-js 2.15.1 → 2.16.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/runtime/KIRuntimeTest.ts +2 -1
- package/__tests__/engine/runtime/KIRuntimeVarArgsTest.ts +101 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +66 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluatorStringLiteralTest.ts +1 -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 +6 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/runtime/KIRuntime.ts +189 -98
- package/src/engine/runtime/expression/Expression.ts +37 -5
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +360 -55
- package/src/engine/runtime/expression/tokenextractor/ExpressionInternalValueExtractor.ts +2 -1
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +100 -18
- package/src/engine/runtime/graph/ExecutionGraph.ts +9 -0
- package/src/engine/runtime/graph/GraphVertex.ts +9 -0
- package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +2 -1
- package/src/engine/runtime/tokenextractor/ContextTokenValueExtractor.ts +2 -1
- package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +1 -1
|
@@ -170,7 +170,8 @@ test('KIRuntime Test 1', async () => {
|
|
|
170
170
|
).setArguments(new Map([['Count', num]])),
|
|
171
171
|
)
|
|
172
172
|
).allResults();
|
|
173
|
-
|
|
173
|
+
console.log('KIRuntime Logic : ' + (new Date().getTime() - start) + 'ms');
|
|
174
|
+
|
|
174
175
|
expect(out[0].getResult().get('result')).toStrictEqual(array);
|
|
175
176
|
});
|
|
176
177
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Function, HybridRepository, ObjectValueSetterExtractor } from '../../../src';
|
|
2
|
+
import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
|
|
3
|
+
import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
|
|
4
|
+
import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
|
|
5
|
+
import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
|
|
6
|
+
import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
|
|
7
|
+
import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
|
|
8
|
+
|
|
9
|
+
test('KIRuntime Print function with variable arguments', async () => {
|
|
10
|
+
var def = {
|
|
11
|
+
name: 'varArgWithNothing',
|
|
12
|
+
namespace: 'Test',
|
|
13
|
+
steps: {
|
|
14
|
+
testFunction: {
|
|
15
|
+
statementName: 'testFunction',
|
|
16
|
+
namespace: 'LocalFunction',
|
|
17
|
+
name: 'Other',
|
|
18
|
+
parameterMap: {
|
|
19
|
+
eagerFields: {
|
|
20
|
+
one: {
|
|
21
|
+
type: 'EXPRESSION',
|
|
22
|
+
expression: 'Store.names',
|
|
23
|
+
key: 'one',
|
|
24
|
+
order: 1,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var OtherFunction = new KIRuntime(
|
|
33
|
+
FunctionDefinition.from({
|
|
34
|
+
namespace: 'LocalFunction',
|
|
35
|
+
name: 'Other',
|
|
36
|
+
steps: {
|
|
37
|
+
print: {
|
|
38
|
+
statementName: 'print',
|
|
39
|
+
namespace: Namespaces.SYSTEM,
|
|
40
|
+
name: 'Print',
|
|
41
|
+
parameterMap: {
|
|
42
|
+
values: {
|
|
43
|
+
one: {
|
|
44
|
+
type: 'EXPRESSION',
|
|
45
|
+
expression: 'Arguments.eagerFields',
|
|
46
|
+
value: 'Test',
|
|
47
|
+
key: 'one',
|
|
48
|
+
order: 1,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
parameters: {
|
|
55
|
+
eagerFields: {
|
|
56
|
+
schema: {
|
|
57
|
+
namespace: '_',
|
|
58
|
+
name: 'eagerFields',
|
|
59
|
+
version: 1,
|
|
60
|
+
type: 'STRING',
|
|
61
|
+
},
|
|
62
|
+
parameterName: 'eagerFields',
|
|
63
|
+
variableArgument: true,
|
|
64
|
+
type: 'EXPRESSION',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
false,
|
|
69
|
+
);
|
|
70
|
+
const fd = FunctionDefinition.from(def);
|
|
71
|
+
|
|
72
|
+
const store = new ObjectValueSetterExtractor(
|
|
73
|
+
{ names: ['kiran', 'kumar', 'grandhi'] },
|
|
74
|
+
'Store.',
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// console.log(store.getValue('Store.names'));
|
|
78
|
+
|
|
79
|
+
const oldConsole = console.log;
|
|
80
|
+
const test = (console.log = jest.fn().mockImplementation(() => {}));
|
|
81
|
+
|
|
82
|
+
let result = await new KIRuntime(fd, false).execute(
|
|
83
|
+
new FunctionExecutionParameters(
|
|
84
|
+
new HybridRepository<Function>(new KIRunFunctionRepository(), {
|
|
85
|
+
find: async (namespace: string, name: string): Promise<Function | undefined> => {
|
|
86
|
+
if (namespace === 'LocalFunction' && name === 'Other') return OtherFunction;
|
|
87
|
+
return undefined;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
filter: async (name: string): Promise<string[]> => {
|
|
91
|
+
return ['LocalFunction.Other'];
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
new KIRunSchemaRepository(),
|
|
95
|
+
).setValuesMap(new Map([[store.getPrefix(), store]])),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
console.log = oldConsole;
|
|
99
|
+
|
|
100
|
+
expect(test.mock.calls[0]).toMatchObject(['kiran', 'kumar', 'grandhi']);
|
|
101
|
+
});
|
|
@@ -558,3 +558,69 @@ test('backslash escape', () => {
|
|
|
558
558
|
let ev = new ExpressionEvaluator("'\\maza'");
|
|
559
559
|
expect(ev.evaluate(new Map())).toBe('\\maza');
|
|
560
560
|
});
|
|
561
|
+
|
|
562
|
+
test('ternary expression with displayValue equality check', () => {
|
|
563
|
+
// Test when displayValue = "0" -> should return "1"
|
|
564
|
+
let ttv = new TestTokenValueExtractor({ displayValue: '0' });
|
|
565
|
+
let ev = new ExpressionEvaluator("(Test.displayValue = '0') ? '1' : (Test.displayValue + '1')");
|
|
566
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('1');
|
|
567
|
+
|
|
568
|
+
// Test when displayValue = "1" -> should return "11"
|
|
569
|
+
ttv = new TestTokenValueExtractor({ displayValue: '1' });
|
|
570
|
+
ev = new ExpressionEvaluator("(Test.displayValue = '0') ? '1' : (Test.displayValue + '1')");
|
|
571
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('11');
|
|
572
|
+
|
|
573
|
+
// Test when displayValue = "5" -> should return "51"
|
|
574
|
+
ttv = new TestTokenValueExtractor({ displayValue: '5' });
|
|
575
|
+
ev = new ExpressionEvaluator("(Test.displayValue = '0') ? '1' : (Test.displayValue + '1')");
|
|
576
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('51');
|
|
577
|
+
|
|
578
|
+
// Test when displayValue = "10" -> should return "101"
|
|
579
|
+
ttv = new TestTokenValueExtractor({ displayValue: '10' });
|
|
580
|
+
ev = new ExpressionEvaluator("(Test.displayValue = '0') ? '1' : (Test.displayValue + '1')");
|
|
581
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('101');
|
|
582
|
+
|
|
583
|
+
// Test ((Test.displayValue = '0') ? '1' : (Test.displayValue + '1'))
|
|
584
|
+
ttv = new TestTokenValueExtractor({ displayValue: '1' });
|
|
585
|
+
ev = new ExpressionEvaluator("((Test.displayValue = '0') ? '1' : (Test.displayValue + '1'))");
|
|
586
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('11');
|
|
587
|
+
|
|
588
|
+
// Test (((Test.displayValue = '0') ? '1' : (Test.displayValue + '1')))
|
|
589
|
+
ttv = new TestTokenValueExtractor({ displayValue: '1' });
|
|
590
|
+
ev = new ExpressionEvaluator("(((Test.displayValue = '0') ? '1' : (Test.displayValue + '1')))");
|
|
591
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('11');
|
|
592
|
+
|
|
593
|
+
// Test (((Test.displayValue = '0')) ? '1' : (((Test.displayValue) + '1')))
|
|
594
|
+
ttv = new TestTokenValueExtractor({ displayValue: '1' });
|
|
595
|
+
ev = new ExpressionEvaluator("(((Test.displayValue = '0')) ? '1' : (((Test.displayValue) + '1')))");
|
|
596
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe('11');
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
test('unary minus operator', () => {
|
|
600
|
+
// Simple negative number
|
|
601
|
+
let ev = new ExpressionEvaluator('-5');
|
|
602
|
+
expect(ev.evaluate(new Map())).toBe(-5);
|
|
603
|
+
|
|
604
|
+
// Negative variable using subtraction from zero
|
|
605
|
+
let ttv = new TestTokenValueExtractor({ value: 10 });
|
|
606
|
+
ev = new ExpressionEvaluator('0 - Test.value');
|
|
607
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe(-10);
|
|
608
|
+
|
|
609
|
+
// Negative in expression: (a + (0 - b)) = 5 + (-3) = 2
|
|
610
|
+
ttv = new TestTokenValueExtractor({ a: 5, b: 3 });
|
|
611
|
+
ev = new ExpressionEvaluator('Test.a + (0 - Test.b)');
|
|
612
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe(2);
|
|
613
|
+
|
|
614
|
+
// Multiplication with negative: a * -1
|
|
615
|
+
ttv = new TestTokenValueExtractor({ a: 5 });
|
|
616
|
+
ev = new ExpressionEvaluator('Test.a * -1');
|
|
617
|
+
expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBe(-5);
|
|
618
|
+
|
|
619
|
+
// Parenthesized negative number
|
|
620
|
+
ev = new ExpressionEvaluator('(-5)');
|
|
621
|
+
expect(ev.evaluate(new Map())).toBe(-5);
|
|
622
|
+
|
|
623
|
+
// Negative number in complex expression
|
|
624
|
+
ev = new ExpressionEvaluator('10 + (-5) * 2');
|
|
625
|
+
expect(ev.evaluate(new Map())).toBe(0);
|
|
626
|
+
});
|
|
@@ -96,7 +96,7 @@ test('Expression with String Literal - 2 ', () => {
|
|
|
96
96
|
expect(ev.evaluate(valuesMap)).toBe('');
|
|
97
97
|
|
|
98
98
|
ev = new ExpressionEvaluator('2.val');
|
|
99
|
-
expect(ev.evaluate(valuesMap)).toBe(
|
|
99
|
+
expect(ev.evaluate(valuesMap)).toBe(undefined);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
test('Testing for string length with object', () => {
|