@fincity/kirun-js 2.16.0 → 2.16.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/function/system/MakeTest.ts +317 -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/function/system/Make.ts +83 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +2 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionExecutionParameters,
|
|
3
|
+
KIRunFunctionRepository,
|
|
4
|
+
KIRunSchemaRepository,
|
|
5
|
+
} from '../../../../src';
|
|
6
|
+
import { Make } from '../../../../src/engine/function/system/Make';
|
|
7
|
+
|
|
8
|
+
const make: Make = new Make();
|
|
9
|
+
|
|
10
|
+
function createOutputMap(data: Record<string, any>): Map<string, Map<string, Map<string, any>>> {
|
|
11
|
+
return new Map([
|
|
12
|
+
[
|
|
13
|
+
'step1',
|
|
14
|
+
new Map([
|
|
15
|
+
[
|
|
16
|
+
'output',
|
|
17
|
+
new Map(Object.entries(data)),
|
|
18
|
+
],
|
|
19
|
+
]),
|
|
20
|
+
],
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test('test simple object with expression', async () => {
|
|
25
|
+
const source = { name: 'John', age: 30 };
|
|
26
|
+
|
|
27
|
+
const resultShape = {
|
|
28
|
+
fullName: '{{Steps.step1.output.source.name}}',
|
|
29
|
+
userAge: '{{Steps.step1.output.source.age}}',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
33
|
+
new KIRunFunctionRepository(),
|
|
34
|
+
new KIRunSchemaRepository(),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
38
|
+
fep.setContext(new Map());
|
|
39
|
+
fep.setSteps(createOutputMap({ source }));
|
|
40
|
+
|
|
41
|
+
const result = await make.execute(fep);
|
|
42
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
43
|
+
|
|
44
|
+
expect(value).toStrictEqual({
|
|
45
|
+
fullName: 'John',
|
|
46
|
+
userAge: 30,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('test nested object with expressions', async () => {
|
|
51
|
+
const source = {
|
|
52
|
+
user: { firstName: 'John', lastName: 'Doe' },
|
|
53
|
+
address: { city: 'NYC', zip: '10001' },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const resultShape = {
|
|
57
|
+
person: {
|
|
58
|
+
name: '{{Steps.step1.output.source.user.firstName}}',
|
|
59
|
+
surname: '{{Steps.step1.output.source.user.lastName}}',
|
|
60
|
+
},
|
|
61
|
+
location: {
|
|
62
|
+
cityName: '{{Steps.step1.output.source.address.city}}',
|
|
63
|
+
postalCode: '{{Steps.step1.output.source.address.zip}}',
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
68
|
+
new KIRunFunctionRepository(),
|
|
69
|
+
new KIRunSchemaRepository(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
73
|
+
fep.setContext(new Map());
|
|
74
|
+
fep.setSteps(createOutputMap({ source }));
|
|
75
|
+
|
|
76
|
+
const result = await make.execute(fep);
|
|
77
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
78
|
+
|
|
79
|
+
expect(value).toStrictEqual({
|
|
80
|
+
person: {
|
|
81
|
+
name: 'John',
|
|
82
|
+
surname: 'Doe',
|
|
83
|
+
},
|
|
84
|
+
location: {
|
|
85
|
+
cityName: 'NYC',
|
|
86
|
+
postalCode: '10001',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('test array with expressions', async () => {
|
|
92
|
+
const source = {
|
|
93
|
+
items: ['apple', 'banana', 'cherry'],
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const resultShape = {
|
|
97
|
+
fruits: [
|
|
98
|
+
'{{Steps.step1.output.source.items[0]}}',
|
|
99
|
+
'{{Steps.step1.output.source.items[1]}}',
|
|
100
|
+
'{{Steps.step1.output.source.items[2]}}',
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
105
|
+
new KIRunFunctionRepository(),
|
|
106
|
+
new KIRunSchemaRepository(),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
110
|
+
fep.setContext(new Map());
|
|
111
|
+
fep.setSteps(createOutputMap({ source }));
|
|
112
|
+
|
|
113
|
+
const result = await make.execute(fep);
|
|
114
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
115
|
+
|
|
116
|
+
expect(value).toStrictEqual({
|
|
117
|
+
fruits: ['apple', 'banana', 'cherry'],
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('test deeply nested structure with arrays', async () => {
|
|
122
|
+
const source = {
|
|
123
|
+
data: {
|
|
124
|
+
users: [
|
|
125
|
+
{ id: 1, name: 'Alice' },
|
|
126
|
+
{ id: 2, name: 'Bob' },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const resultShape = {
|
|
132
|
+
level1: {
|
|
133
|
+
level2: {
|
|
134
|
+
level3: {
|
|
135
|
+
userList: [
|
|
136
|
+
{
|
|
137
|
+
userId: '{{Steps.step1.output.source.data.users[0].id}}',
|
|
138
|
+
userName: '{{Steps.step1.output.source.data.users[0].name}}',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
userId: '{{Steps.step1.output.source.data.users[1].id}}',
|
|
142
|
+
userName: '{{Steps.step1.output.source.data.users[1].name}}',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
151
|
+
new KIRunFunctionRepository(),
|
|
152
|
+
new KIRunSchemaRepository(),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
156
|
+
fep.setContext(new Map());
|
|
157
|
+
fep.setSteps(createOutputMap({ source }));
|
|
158
|
+
|
|
159
|
+
const result = await make.execute(fep);
|
|
160
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
161
|
+
|
|
162
|
+
expect(value).toStrictEqual({
|
|
163
|
+
level1: {
|
|
164
|
+
level2: {
|
|
165
|
+
level3: {
|
|
166
|
+
userList: [
|
|
167
|
+
{ userId: 1, userName: 'Alice' },
|
|
168
|
+
{ userId: 2, userName: 'Bob' },
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('test mixed static and dynamic values', async () => {
|
|
177
|
+
const source = { dynamicValue: 'from source' };
|
|
178
|
+
|
|
179
|
+
const resultShape = {
|
|
180
|
+
static: 'static string',
|
|
181
|
+
dynamic: '{{Steps.step1.output.source.dynamicValue}}',
|
|
182
|
+
nested: {
|
|
183
|
+
staticNum: 42,
|
|
184
|
+
dynamicNum: '{{Steps.step1.output.source.dynamicValue}}',
|
|
185
|
+
},
|
|
186
|
+
array: ['static', '{{Steps.step1.output.source.dynamicValue}}', 123],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
190
|
+
new KIRunFunctionRepository(),
|
|
191
|
+
new KIRunSchemaRepository(),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
195
|
+
fep.setContext(new Map());
|
|
196
|
+
fep.setSteps(createOutputMap({ source }));
|
|
197
|
+
|
|
198
|
+
const result = await make.execute(fep);
|
|
199
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
200
|
+
|
|
201
|
+
expect(value).toStrictEqual({
|
|
202
|
+
static: 'static string',
|
|
203
|
+
dynamic: 'from source',
|
|
204
|
+
nested: {
|
|
205
|
+
staticNum: 42,
|
|
206
|
+
dynamicNum: 'from source',
|
|
207
|
+
},
|
|
208
|
+
array: ['static', 'from source', 123],
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('test null and undefined handling', async () => {
|
|
213
|
+
const resultShape = {
|
|
214
|
+
nullValue: null,
|
|
215
|
+
nested: {
|
|
216
|
+
inner: null,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
221
|
+
new KIRunFunctionRepository(),
|
|
222
|
+
new KIRunSchemaRepository(),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
226
|
+
fep.setContext(new Map());
|
|
227
|
+
fep.setSteps(new Map());
|
|
228
|
+
|
|
229
|
+
const result = await make.execute(fep);
|
|
230
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
231
|
+
|
|
232
|
+
expect(value).toStrictEqual({
|
|
233
|
+
nullValue: null,
|
|
234
|
+
nested: {
|
|
235
|
+
inner: null,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('test array of arrays', async () => {
|
|
241
|
+
const source = {
|
|
242
|
+
matrix: [
|
|
243
|
+
[1, 2],
|
|
244
|
+
[3, 4],
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const resultShape = {
|
|
249
|
+
grid: [
|
|
250
|
+
['{{Steps.step1.output.source.matrix[0][0]}}', '{{Steps.step1.output.source.matrix[0][1]}}'],
|
|
251
|
+
['{{Steps.step1.output.source.matrix[1][0]}}', '{{Steps.step1.output.source.matrix[1][1]}}'],
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
256
|
+
new KIRunFunctionRepository(),
|
|
257
|
+
new KIRunSchemaRepository(),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
261
|
+
fep.setContext(new Map());
|
|
262
|
+
fep.setSteps(createOutputMap({ source }));
|
|
263
|
+
|
|
264
|
+
const result = await make.execute(fep);
|
|
265
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
266
|
+
|
|
267
|
+
expect(value).toStrictEqual({
|
|
268
|
+
grid: [
|
|
269
|
+
[1, 2],
|
|
270
|
+
[3, 4],
|
|
271
|
+
],
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('test primitive result shape', async () => {
|
|
276
|
+
const source = { value: 'hello' };
|
|
277
|
+
|
|
278
|
+
const resultShape = '{{Steps.step1.output.source.value}}';
|
|
279
|
+
|
|
280
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
281
|
+
new KIRunFunctionRepository(),
|
|
282
|
+
new KIRunSchemaRepository(),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
286
|
+
fep.setContext(new Map());
|
|
287
|
+
fep.setSteps(createOutputMap({ source }));
|
|
288
|
+
|
|
289
|
+
const result = await make.execute(fep);
|
|
290
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
291
|
+
|
|
292
|
+
expect(value).toBe('hello');
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('test array as root result shape', async () => {
|
|
296
|
+
const source = { a: 1, b: 2, c: 3 };
|
|
297
|
+
|
|
298
|
+
const resultShape = [
|
|
299
|
+
'{{Steps.step1.output.source.a}}',
|
|
300
|
+
'{{Steps.step1.output.source.b}}',
|
|
301
|
+
'{{Steps.step1.output.source.c}}',
|
|
302
|
+
];
|
|
303
|
+
|
|
304
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
305
|
+
new KIRunFunctionRepository(),
|
|
306
|
+
new KIRunSchemaRepository(),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
fep.setArguments(new Map<string, any>([['resultShape', resultShape]]));
|
|
310
|
+
fep.setContext(new Map());
|
|
311
|
+
fep.setSteps(createOutputMap({ source }));
|
|
312
|
+
|
|
313
|
+
const result = await make.execute(fep);
|
|
314
|
+
const value = result.allResults()[0]?.getResult()?.get('value');
|
|
315
|
+
|
|
316
|
+
expect(value).toStrictEqual([1, 2, 3]);
|
|
317
|
+
});
|