@fincity/kirun-js 1.4.1 → 1.4.3
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 +4 -4
- package/__tests__/engine/runtime/KIRuntimeWithDefinitionTest.ts +39 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +32 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluatorStringLiteralTest.ts +3 -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 +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/engine/function/AbstractFunction.ts +72 -45
- package/src/engine/runtime/expression/Expression.ts +1 -1
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +20 -1
- package/src/engine/runtime/expression/tokenextractor/ExpressionInternalValueExtractor.ts +29 -0
- package/src/engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor.ts +1 -7
- package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +9 -1
|
@@ -35,7 +35,7 @@ test('KIRuntime Test 1', async () => {
|
|
|
35
35
|
array.push(array[i - 2] + array[i - 1]);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
console.log('Normal Logic : ' + (new Date().getTime() - start));
|
|
38
|
+
//console.log('Normal Logic : ' + (new Date().getTime() - start));
|
|
39
39
|
|
|
40
40
|
var create = new Create().getSignature();
|
|
41
41
|
var integerSchema = { name: 'EachElement', type: 'INTEGER' };
|
|
@@ -170,7 +170,7 @@ test('KIRuntime Test 1', async () => {
|
|
|
170
170
|
).setArguments(new Map([['Count', num]])),
|
|
171
171
|
)
|
|
172
172
|
).allResults();
|
|
173
|
-
console.log('KIRunt Logic : ' + (new Date().getTime() - start));
|
|
173
|
+
//console.log('KIRunt Logic : ' + (new Date().getTime() - start));
|
|
174
174
|
expect(out[0].getResult().get('result')).toStrictEqual(array);
|
|
175
175
|
});
|
|
176
176
|
|
|
@@ -306,7 +306,7 @@ test('KIRuntime Test 4', async () => {
|
|
|
306
306
|
array[i] = array[i - 2] + array[i - 1];
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
console.log('Normal Logic : ' + (new Date().getTime() - start));
|
|
309
|
+
//console.log('Normal Logic : ' + (new Date().getTime() - start));
|
|
310
310
|
|
|
311
311
|
var fibFunctionSignature = new FunctionSignature('FibFunction')
|
|
312
312
|
.setNamespace('FibSpace')
|
|
@@ -399,6 +399,6 @@ test('KIRuntime Test 4', async () => {
|
|
|
399
399
|
),
|
|
400
400
|
)
|
|
401
401
|
).allResults();
|
|
402
|
-
console.log('KIRun Logic : ' + (new Date().getTime() - start));
|
|
402
|
+
//console.log('KIRun Logic : ' + (new Date().getTime() - start));
|
|
403
403
|
expect(out[0].getResult().get('result')).toStrictEqual(array);
|
|
404
404
|
});
|
|
@@ -124,3 +124,42 @@ test('KIRuntime With Definition 2', async () => {
|
|
|
124
124
|
|
|
125
125
|
expect(result.allResults()[0].getResult()).toMatchObject({});
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
test('KIRuntime With Definition 3', async () => {
|
|
129
|
+
var def = {
|
|
130
|
+
name: 'Make an error',
|
|
131
|
+
namespace: 'UIApp',
|
|
132
|
+
steps: {
|
|
133
|
+
add: {
|
|
134
|
+
statementName: 'add',
|
|
135
|
+
namespace: Namespaces.MATH,
|
|
136
|
+
name: 'Add',
|
|
137
|
+
parameterMap: {
|
|
138
|
+
value: {
|
|
139
|
+
one: { key: 'one', type: 'VALUE', value: 'X' },
|
|
140
|
+
two: { key: 'two', type: 'VALUE', value: 5 },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
genOutput: {
|
|
145
|
+
statementName: 'genOutput',
|
|
146
|
+
namespace: Namespaces.SYSTEM,
|
|
147
|
+
name: 'GenerateEvent',
|
|
148
|
+
dependentStatements: { 'Steps.add.output': true },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const fd = FunctionDefinition.from(def);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await new KIRuntime(fd).execute(
|
|
157
|
+
new FunctionExecutionParameters(
|
|
158
|
+
new KIRunFunctionRepository(),
|
|
159
|
+
new KIRunSchemaRepository(),
|
|
160
|
+
).setArguments(new Map()),
|
|
161
|
+
);
|
|
162
|
+
} catch (e: any) {
|
|
163
|
+
expect(e.message).toMatch('error');
|
|
164
|
+
}
|
|
165
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArgumentsTokenValueExtractor,
|
|
3
|
+
Expression,
|
|
3
4
|
KIRunFunctionRepository,
|
|
4
5
|
KIRunSchemaRepository,
|
|
5
6
|
MapUtil,
|
|
@@ -211,3 +212,34 @@ test('Expression Evaluation nesting expression', () => {
|
|
|
211
212
|
'There are 4 boys in the class room...There are 4 boys in the class room...',
|
|
212
213
|
);
|
|
213
214
|
});
|
|
215
|
+
|
|
216
|
+
test('Partial path evaluation', () => {
|
|
217
|
+
let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
|
|
218
|
+
new Map<string, any>([
|
|
219
|
+
['a', 'kirun '],
|
|
220
|
+
['b', 1],
|
|
221
|
+
['b1', 4],
|
|
222
|
+
['b2', 4],
|
|
223
|
+
[
|
|
224
|
+
'c',
|
|
225
|
+
{ a: 0, b: [true, false], c: { x: 'Arguments.b2' }, keys: ['a', 'e', { val: 5 }] },
|
|
226
|
+
],
|
|
227
|
+
['d', 'c'],
|
|
228
|
+
[
|
|
229
|
+
'e',
|
|
230
|
+
[
|
|
231
|
+
{ name: 'Kiran', num: 1 },
|
|
232
|
+
{ name: 'Good', num: 2 },
|
|
233
|
+
],
|
|
234
|
+
],
|
|
235
|
+
]),
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
let valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
|
|
239
|
+
|
|
240
|
+
let ev = new ExpressionEvaluator('Arguments.c.keys[2].val + 3');
|
|
241
|
+
expect(ev.evaluate(valuesMap)).toBe(8);
|
|
242
|
+
ev = new ExpressionEvaluator('(Arguments.f ?? Arguments.e)[1+1-1].num');
|
|
243
|
+
console.log(ev.getExpression().toString());
|
|
244
|
+
expect(ev.evaluate(valuesMap)).toBe(2);
|
|
245
|
+
});
|