@fincity/kirun-js 1.7.0 → 1.8.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/ArrayToObjectTest.ts +180 -0
- package/__tests__/engine/function/system/array/RemoveDuplicatesTest.ts +74 -0
- package/__tests__/engine/function/system/loop/CountLoopTest.ts +1 -1
- package/__tests__/engine/runtime/expression/tokenextractor/ObjectValueSetterExtractorTest.ts +51 -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 +9 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/array/AbstractArrayFunction.ts +5 -0
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +4 -0
- package/src/engine/function/system/array/ArrayToObject.ts +77 -0
- package/src/engine/function/system/array/RemoveDuplicates.ts +64 -0
- package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -0
- package/src/engine/function/system/object/ObjectPutValue.ts +61 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +3 -2
- package/src/engine/runtime/expression/tokenextractor/ObjectValueSetterExtractor.ts +172 -0
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +1 -1
- package/src/index.ts +1 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionExecutionParameters,
|
|
3
|
+
KIRunFunctionRepository,
|
|
4
|
+
KIRunSchemaRepository,
|
|
5
|
+
} from '../../../../../src';
|
|
6
|
+
import { ArrayToObject } from '../../../../../src/engine/function/system/array/ArrayToObject';
|
|
7
|
+
|
|
8
|
+
test('Array To Object Test', async () => {
|
|
9
|
+
const atoo = new ArrayToObject();
|
|
10
|
+
|
|
11
|
+
let source = [
|
|
12
|
+
{ name: 'A', num: 1 },
|
|
13
|
+
{ name: 'B', num: 2 },
|
|
14
|
+
null,
|
|
15
|
+
{ name: 'C', num: 3 },
|
|
16
|
+
{ name: 'D', num: 4 },
|
|
17
|
+
{ name: 'E', num: 4 },
|
|
18
|
+
undefined,
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const funRepo = new KIRunFunctionRepository();
|
|
22
|
+
const schemaRepo = new KIRunSchemaRepository();
|
|
23
|
+
|
|
24
|
+
let result = (
|
|
25
|
+
await atoo.execute(
|
|
26
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
27
|
+
new Map<string, any>([
|
|
28
|
+
['source', source],
|
|
29
|
+
['keyPath', 'name'],
|
|
30
|
+
['valuePath', 'num'],
|
|
31
|
+
]),
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
.allResults()[0]
|
|
36
|
+
.getResult()
|
|
37
|
+
.get('result');
|
|
38
|
+
|
|
39
|
+
expect(result).toMatchObject({ A: 1, B: 2, C: 3, D: 4, E: 4 });
|
|
40
|
+
|
|
41
|
+
result = (
|
|
42
|
+
await atoo.execute(
|
|
43
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
44
|
+
new Map<string, any>([
|
|
45
|
+
['source', source],
|
|
46
|
+
['keyPath', 'num'],
|
|
47
|
+
['valuePath', 'name'],
|
|
48
|
+
]),
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
.allResults()[0]
|
|
53
|
+
.getResult()
|
|
54
|
+
.get('result');
|
|
55
|
+
|
|
56
|
+
expect(result).toMatchObject({ 1: 'A', 2: 'B', 3: 'C', 4: 'E' });
|
|
57
|
+
|
|
58
|
+
result = (
|
|
59
|
+
await atoo.execute(
|
|
60
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
61
|
+
new Map<string, any>([
|
|
62
|
+
['source', source],
|
|
63
|
+
['keyPath', 'num'],
|
|
64
|
+
['valuePath', 'name'],
|
|
65
|
+
['ignoreDuplicateKeys', true],
|
|
66
|
+
]),
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
.allResults()[0]
|
|
71
|
+
.getResult()
|
|
72
|
+
.get('result');
|
|
73
|
+
|
|
74
|
+
expect(result).toMatchObject({ 1: 'A', 2: 'B', 3: 'C', 4: 'D' });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('Array To Object Test - Invalid Key Path', async () => {
|
|
78
|
+
const atoo = new ArrayToObject();
|
|
79
|
+
|
|
80
|
+
let source = [
|
|
81
|
+
{ name: 'A', num: 1 },
|
|
82
|
+
{ name: 'B', num: 2 },
|
|
83
|
+
{ name: 'C', num: 3 },
|
|
84
|
+
{ name: 'D', num: 4 },
|
|
85
|
+
{ name: 'E', num: 4 },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const funRepo = new KIRunFunctionRepository();
|
|
89
|
+
const schemaRepo = new KIRunSchemaRepository();
|
|
90
|
+
|
|
91
|
+
let result = (
|
|
92
|
+
await atoo.execute(
|
|
93
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
94
|
+
new Map<string, any>([
|
|
95
|
+
['source', source],
|
|
96
|
+
['keyPath', 'name1'],
|
|
97
|
+
['valuePath', 'num'],
|
|
98
|
+
]),
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
.allResults()[0]
|
|
103
|
+
.getResult()
|
|
104
|
+
.get('result');
|
|
105
|
+
|
|
106
|
+
expect(result).toMatchObject({});
|
|
107
|
+
|
|
108
|
+
result = (
|
|
109
|
+
await atoo.execute(
|
|
110
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
111
|
+
new Map<string, any>([
|
|
112
|
+
['source', source],
|
|
113
|
+
['keyPath', 'name'],
|
|
114
|
+
['valuePath', 'num1'],
|
|
115
|
+
]),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
.allResults()[0]
|
|
120
|
+
.getResult()
|
|
121
|
+
.get('result');
|
|
122
|
+
|
|
123
|
+
expect(result).toMatchObject({
|
|
124
|
+
A: undefined,
|
|
125
|
+
B: undefined,
|
|
126
|
+
C: undefined,
|
|
127
|
+
D: undefined,
|
|
128
|
+
E: undefined,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
result = (
|
|
132
|
+
await atoo.execute(
|
|
133
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
134
|
+
new Map<string, any>([
|
|
135
|
+
['source', source],
|
|
136
|
+
['keyPath', 'name'],
|
|
137
|
+
['valuePath', 'num1'],
|
|
138
|
+
['ignoreNullValues', true],
|
|
139
|
+
]),
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
.allResults()[0]
|
|
144
|
+
.getResult()
|
|
145
|
+
.get('result');
|
|
146
|
+
|
|
147
|
+
expect(result).toMatchObject({});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('Array To Object Test - Deep Path', async () => {
|
|
151
|
+
const atoo = new ArrayToObject();
|
|
152
|
+
|
|
153
|
+
let source = [
|
|
154
|
+
{ name: 'A', num: 1, info: { age: 10 } },
|
|
155
|
+
{ name: 'B', num: 2, info: { age: 20 } },
|
|
156
|
+
{ name: 'C', num: 3, info: { age: 30 } },
|
|
157
|
+
{ name: 'D', num: 4, info: { age: 40 } },
|
|
158
|
+
{ name: 'E', num: 4, info: { age: 50 } },
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
const funRepo = new KIRunFunctionRepository();
|
|
162
|
+
const schemaRepo = new KIRunSchemaRepository();
|
|
163
|
+
|
|
164
|
+
let result = (
|
|
165
|
+
await atoo.execute(
|
|
166
|
+
new FunctionExecutionParameters(funRepo, schemaRepo).setArguments(
|
|
167
|
+
new Map<string, any>([
|
|
168
|
+
['source', source],
|
|
169
|
+
['keyPath', 'info.age'],
|
|
170
|
+
['valuePath', 'name'],
|
|
171
|
+
]),
|
|
172
|
+
),
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
.allResults()[0]
|
|
176
|
+
.getResult()
|
|
177
|
+
.get('result');
|
|
178
|
+
|
|
179
|
+
expect(result).toMatchObject({ 10: 'A', 20: 'B', 30: 'C', 40: 'D', 50: 'E' });
|
|
180
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AbstractArrayFunction } from '../../../../../src/engine/function/system/array/AbstractArrayFunction';
|
|
2
|
+
import { FunctionOutput } from '../../../../../src/engine/model/FunctionOutput';
|
|
3
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
4
|
+
|
|
5
|
+
import { MapUtil } from '../../../../../src/engine/util/MapUtil';
|
|
6
|
+
|
|
7
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
8
|
+
import { RemoveDuplicates } from '../../../../../src/engine/function/system/array/RemoveDuplicates';
|
|
9
|
+
|
|
10
|
+
test('RemoveDuplicates Test', async () => {
|
|
11
|
+
let removeDuplicates: RemoveDuplicates = new RemoveDuplicates();
|
|
12
|
+
|
|
13
|
+
let source: any[] = [2, 2, 2, 2, 2];
|
|
14
|
+
|
|
15
|
+
let fep1: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
16
|
+
new KIRunFunctionRepository(),
|
|
17
|
+
new KIRunSchemaRepository(),
|
|
18
|
+
).setArguments(
|
|
19
|
+
MapUtil.of(
|
|
20
|
+
AbstractArrayFunction.PARAMETER_ARRAY_SOURCE.getParameterName(),
|
|
21
|
+
source as any,
|
|
22
|
+
AbstractArrayFunction.PARAMETER_INT_SOURCE_FROM.getParameterName(),
|
|
23
|
+
2,
|
|
24
|
+
AbstractArrayFunction.PARAMETER_INT_LENGTH.getParameterName(),
|
|
25
|
+
4,
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
await expect(removeDuplicates.execute(fep1)).rejects.toThrow();
|
|
30
|
+
|
|
31
|
+
source.push(6);
|
|
32
|
+
|
|
33
|
+
let result: any[] = [2, 2, 2, 6];
|
|
34
|
+
|
|
35
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
36
|
+
new KIRunFunctionRepository(),
|
|
37
|
+
new KIRunSchemaRepository(),
|
|
38
|
+
).setArguments(
|
|
39
|
+
MapUtil.of(
|
|
40
|
+
RemoveDuplicates.PARAMETER_ARRAY_SOURCE.getParameterName(),
|
|
41
|
+
source as any,
|
|
42
|
+
RemoveDuplicates.PARAMETER_INT_SOURCE_FROM.getParameterName(),
|
|
43
|
+
2,
|
|
44
|
+
RemoveDuplicates.PARAMETER_INT_LENGTH.getParameterName(),
|
|
45
|
+
4,
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
let fo: FunctionOutput = await removeDuplicates.execute(fep);
|
|
50
|
+
expect(fo.allResults()[0].getResult().get(RemoveDuplicates.EVENT_RESULT_NAME)).toStrictEqual(
|
|
51
|
+
result,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
source = new Array();
|
|
55
|
+
source.push({ name: 'Kiran' });
|
|
56
|
+
source.push({ name: 'Kiran' });
|
|
57
|
+
source.push({ name: 'Kiran' });
|
|
58
|
+
source.push({ name: 'Kumar' });
|
|
59
|
+
|
|
60
|
+
result = new Array();
|
|
61
|
+
result.push({ name: 'Kiran' });
|
|
62
|
+
result.push({ name: 'Kumar' });
|
|
63
|
+
|
|
64
|
+
fep = new FunctionExecutionParameters(
|
|
65
|
+
new KIRunFunctionRepository(),
|
|
66
|
+
new KIRunSchemaRepository(),
|
|
67
|
+
).setArguments(MapUtil.of(RemoveDuplicates.PARAMETER_ARRAY_SOURCE.getParameterName(), source));
|
|
68
|
+
|
|
69
|
+
fo = await removeDuplicates.execute(fep);
|
|
70
|
+
|
|
71
|
+
expect(fo.allResults()[0].getResult().get(RemoveDuplicates.EVENT_RESULT_NAME)).toMatchObject(
|
|
72
|
+
result,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
@@ -43,7 +43,7 @@ test('Count Loop2', async () => {
|
|
|
43
43
|
|
|
44
44
|
expect(iterations).toMatchObject([]);
|
|
45
45
|
expect(er?.getName()).toBe('output');
|
|
46
|
-
expect(er?.getResult().get('value')).toBe(
|
|
46
|
+
expect(er?.getResult().get('value')).toBe(0);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('Count Loop3', async () => {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ObjectValueSetterExtractor } from '../../../../../src';
|
|
2
|
+
|
|
3
|
+
test('ObjectValueSetterExtractor Test', async () => {
|
|
4
|
+
let store = {
|
|
5
|
+
name: 'Kiran',
|
|
6
|
+
addresses: [
|
|
7
|
+
{
|
|
8
|
+
city: 'Bangalore',
|
|
9
|
+
state: 'Karnataka',
|
|
10
|
+
country: 'India',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
city: 'Kakinada',
|
|
14
|
+
state: 'Andhra Pradesh',
|
|
15
|
+
country: 'India',
|
|
16
|
+
},
|
|
17
|
+
{ city: 'Beaverton', state: 'Oregon' },
|
|
18
|
+
],
|
|
19
|
+
phone: {
|
|
20
|
+
home: '080-23456789',
|
|
21
|
+
office: '080-23456789',
|
|
22
|
+
mobile: '080-23456789',
|
|
23
|
+
mobile2: '503-23456789',
|
|
24
|
+
},
|
|
25
|
+
plain: [1, 2, 3, 4],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let extractor: ObjectValueSetterExtractor = new ObjectValueSetterExtractor(store, 'Store');
|
|
29
|
+
|
|
30
|
+
expect(extractor.getValue('Store.name')).toStrictEqual('Kiran');
|
|
31
|
+
|
|
32
|
+
extractor.setValue('Store.name', 'Kiran Kumar');
|
|
33
|
+
store = extractor.getStore();
|
|
34
|
+
|
|
35
|
+
expect(store.name).toStrictEqual('Kiran Kumar');
|
|
36
|
+
|
|
37
|
+
extractor.setValue('Store.addresses[0].city', 'Bengaluru');
|
|
38
|
+
expect(extractor.getValue('Store.addresses[0].city')).toStrictEqual('Bengaluru');
|
|
39
|
+
|
|
40
|
+
extractor.setValue('Store.plain[0]', '123');
|
|
41
|
+
expect(extractor.getValue('Store.plain')).toMatchObject(['123', 2, 3, 4]);
|
|
42
|
+
|
|
43
|
+
extractor.setValue('Store.plain[0]', 1, false);
|
|
44
|
+
expect(extractor.getValue('Store.plain')).toMatchObject(['123', 2, 3, 4]);
|
|
45
|
+
|
|
46
|
+
extractor.setValue('Store.plain', undefined, true, true);
|
|
47
|
+
expect(Object.keys(extractor.getValue('Store'))).toMatchObject(['name', 'addresses', 'phone']);
|
|
48
|
+
|
|
49
|
+
extractor.setValue('Store.plain', 'plainString', false, false);
|
|
50
|
+
expect(extractor.getValue('Store.plain')).toStrictEqual('plainString');
|
|
51
|
+
});
|