@fincity/kirun-js 2.1.4 → 2.1.5
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/KIRuntimeVariableArgDefaultNullTest.ts +294 -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/package.json +1 -1
- package/src/engine/model/Parameter.ts +1 -1
- package/src/engine/runtime/KIRuntime.ts +3 -3
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractFunction,
|
|
3
|
+
EventResult,
|
|
4
|
+
Function,
|
|
5
|
+
FunctionOutput,
|
|
6
|
+
FunctionSignature,
|
|
7
|
+
HybridRepository,
|
|
8
|
+
Parameter,
|
|
9
|
+
Schema,
|
|
10
|
+
SchemaType,
|
|
11
|
+
} from '../../../src';
|
|
12
|
+
import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
|
|
13
|
+
import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
|
|
14
|
+
import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
|
|
15
|
+
import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
|
|
16
|
+
import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
|
|
17
|
+
import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
|
|
18
|
+
|
|
19
|
+
test('KIRuntime Print function with no arguments', async () => {
|
|
20
|
+
var def = {
|
|
21
|
+
name: 'varArgWithNothing',
|
|
22
|
+
namespace: 'Test',
|
|
23
|
+
steps: {
|
|
24
|
+
testFunction: {
|
|
25
|
+
statementName: 'testFunction',
|
|
26
|
+
namespace: 'LocalFunction',
|
|
27
|
+
name: 'Other',
|
|
28
|
+
parameterMap: {
|
|
29
|
+
storageName: {
|
|
30
|
+
one: {
|
|
31
|
+
type: 'VALUE',
|
|
32
|
+
value: 'Test',
|
|
33
|
+
key: 'one',
|
|
34
|
+
order: 1,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var OtherFunction = new KIRuntime(
|
|
43
|
+
FunctionDefinition.from({
|
|
44
|
+
namespace: 'LocalFunction',
|
|
45
|
+
name: 'Other',
|
|
46
|
+
steps: {
|
|
47
|
+
print: {
|
|
48
|
+
statementName: 'print',
|
|
49
|
+
namespace: Namespaces.SYSTEM,
|
|
50
|
+
name: 'Print',
|
|
51
|
+
parameterMap: {
|
|
52
|
+
values: {
|
|
53
|
+
one: {
|
|
54
|
+
type: 'EXPRESSION',
|
|
55
|
+
expression: '"Storage : " + Arguments.storageName + "\n"',
|
|
56
|
+
key: 'one',
|
|
57
|
+
order: 1,
|
|
58
|
+
},
|
|
59
|
+
two: {
|
|
60
|
+
type: 'EXPRESSION',
|
|
61
|
+
expression: '"Page : " + Arguments.page + "\n"',
|
|
62
|
+
key: 'two',
|
|
63
|
+
order: 2,
|
|
64
|
+
},
|
|
65
|
+
three: {
|
|
66
|
+
type: 'EXPRESSION',
|
|
67
|
+
expression: '"Size : " + Arguments.size + "\n"',
|
|
68
|
+
key: 'three',
|
|
69
|
+
order: 3,
|
|
70
|
+
},
|
|
71
|
+
five: {
|
|
72
|
+
type: 'EXPRESSION',
|
|
73
|
+
expression: '"Count : " + Arguments.count + "\n"',
|
|
74
|
+
key: 'five',
|
|
75
|
+
order: 5,
|
|
76
|
+
},
|
|
77
|
+
six: {
|
|
78
|
+
type: 'EXPRESSION',
|
|
79
|
+
expression: '"Client Code : " + Arguments.clientCode + "\n"',
|
|
80
|
+
key: 'six',
|
|
81
|
+
order: 6,
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
eight: {
|
|
85
|
+
type: 'EXPRESSION',
|
|
86
|
+
expression: '"Eager : " + Arguments.eager + "\n"',
|
|
87
|
+
key: 'eight',
|
|
88
|
+
order: 8,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
parameters: {
|
|
95
|
+
appCode: {
|
|
96
|
+
schema: {
|
|
97
|
+
namespace: '_',
|
|
98
|
+
name: 'appCode',
|
|
99
|
+
version: 1,
|
|
100
|
+
type: {
|
|
101
|
+
type: 'STRING',
|
|
102
|
+
},
|
|
103
|
+
defaultValue: '',
|
|
104
|
+
},
|
|
105
|
+
parameterName: 'appCode',
|
|
106
|
+
variableArgument: false,
|
|
107
|
+
type: 'EXPRESSION',
|
|
108
|
+
},
|
|
109
|
+
page: {
|
|
110
|
+
schema: {
|
|
111
|
+
namespace: '_',
|
|
112
|
+
name: 'page',
|
|
113
|
+
version: 1,
|
|
114
|
+
type: {
|
|
115
|
+
type: 'INTEGER',
|
|
116
|
+
},
|
|
117
|
+
defaultValue: 0,
|
|
118
|
+
},
|
|
119
|
+
parameterName: 'page',
|
|
120
|
+
variableArgument: false,
|
|
121
|
+
type: 'EXPRESSION',
|
|
122
|
+
},
|
|
123
|
+
storageName: {
|
|
124
|
+
schema: {
|
|
125
|
+
namespace: '_',
|
|
126
|
+
name: 'storageName',
|
|
127
|
+
version: 1,
|
|
128
|
+
type: {
|
|
129
|
+
type: 'STRING',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
parameterName: 'storageName',
|
|
133
|
+
variableArgument: false,
|
|
134
|
+
type: 'EXPRESSION',
|
|
135
|
+
},
|
|
136
|
+
size: {
|
|
137
|
+
schema: {
|
|
138
|
+
namespace: '_',
|
|
139
|
+
name: 'size',
|
|
140
|
+
version: 1,
|
|
141
|
+
type: {
|
|
142
|
+
type: 'INTEGER',
|
|
143
|
+
},
|
|
144
|
+
defaultValue: 20,
|
|
145
|
+
},
|
|
146
|
+
parameterName: 'size',
|
|
147
|
+
variableArgument: false,
|
|
148
|
+
type: 'EXPRESSION',
|
|
149
|
+
},
|
|
150
|
+
count: {
|
|
151
|
+
schema: {
|
|
152
|
+
namespace: '_',
|
|
153
|
+
name: 'count',
|
|
154
|
+
version: 1,
|
|
155
|
+
type: {
|
|
156
|
+
type: 'BOOLEAN',
|
|
157
|
+
},
|
|
158
|
+
defaultValue: true,
|
|
159
|
+
},
|
|
160
|
+
parameterName: 'count',
|
|
161
|
+
variableArgument: false,
|
|
162
|
+
type: 'EXPRESSION',
|
|
163
|
+
},
|
|
164
|
+
clientCode: {
|
|
165
|
+
schema: {
|
|
166
|
+
namespace: '_',
|
|
167
|
+
name: 'clientCode',
|
|
168
|
+
version: 1,
|
|
169
|
+
type: {
|
|
170
|
+
type: 'STRING',
|
|
171
|
+
},
|
|
172
|
+
defaultValue: '',
|
|
173
|
+
},
|
|
174
|
+
parameterName: 'clientCode',
|
|
175
|
+
variableArgument: false,
|
|
176
|
+
type: 'EXPRESSION',
|
|
177
|
+
},
|
|
178
|
+
eagerFields: {
|
|
179
|
+
schema: {
|
|
180
|
+
namespace: '_',
|
|
181
|
+
name: 'eagerFields',
|
|
182
|
+
version: 1,
|
|
183
|
+
type: {
|
|
184
|
+
type: 'STRING',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
parameterName: 'eagerFields',
|
|
188
|
+
variableArgument: true,
|
|
189
|
+
type: 'EXPRESSION',
|
|
190
|
+
},
|
|
191
|
+
filter: {
|
|
192
|
+
schema: {
|
|
193
|
+
namespace: '_',
|
|
194
|
+
name: 'filter',
|
|
195
|
+
version: 1,
|
|
196
|
+
type: {
|
|
197
|
+
type: 'OBJECT',
|
|
198
|
+
},
|
|
199
|
+
defaultValue: {},
|
|
200
|
+
},
|
|
201
|
+
parameterName: 'filter',
|
|
202
|
+
variableArgument: false,
|
|
203
|
+
type: 'EXPRESSION',
|
|
204
|
+
},
|
|
205
|
+
eager: {
|
|
206
|
+
schema: {
|
|
207
|
+
namespace: '_',
|
|
208
|
+
name: 'eager',
|
|
209
|
+
version: 1,
|
|
210
|
+
type: {
|
|
211
|
+
type: 'BOOLEAN',
|
|
212
|
+
},
|
|
213
|
+
defaultValue: false,
|
|
214
|
+
},
|
|
215
|
+
parameterName: 'eager',
|
|
216
|
+
variableArgument: false,
|
|
217
|
+
type: 'EXPRESSION',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
}),
|
|
221
|
+
false,
|
|
222
|
+
);
|
|
223
|
+
const fd = FunctionDefinition.from(def);
|
|
224
|
+
const oldConsole = console.log;
|
|
225
|
+
const test = (console.log = jest.fn().mockImplementation(() => {}));
|
|
226
|
+
|
|
227
|
+
let result = await new KIRuntime(fd, false).execute(
|
|
228
|
+
new FunctionExecutionParameters(
|
|
229
|
+
new HybridRepository<Function>(new KIRunFunctionRepository(), {
|
|
230
|
+
find: async (namespace: string, name: string): Promise<Function | undefined> => {
|
|
231
|
+
if (namespace === 'LocalFunction' && name === 'Other') return OtherFunction;
|
|
232
|
+
return undefined;
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
filter: async (name: string): Promise<string[]> => {
|
|
236
|
+
return ['LocalFunction.Other'];
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
new KIRunSchemaRepository(),
|
|
240
|
+
),
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
console.log = oldConsole;
|
|
244
|
+
|
|
245
|
+
expect(test.mock.calls[0]).toMatchObject([
|
|
246
|
+
'Storage : Test\n',
|
|
247
|
+
'Page : 0\n',
|
|
248
|
+
'Size : 20\n',
|
|
249
|
+
'Count : true\n',
|
|
250
|
+
'Client Code : \n',
|
|
251
|
+
'Eager : false\n',
|
|
252
|
+
]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("KIRuntime Print function with 'null' argument", async () => {
|
|
256
|
+
class TestPrint extends AbstractFunction {
|
|
257
|
+
private static readonly VALUES: string = 'values';
|
|
258
|
+
|
|
259
|
+
private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Print')
|
|
260
|
+
.setNamespace(Namespaces.SYSTEM)
|
|
261
|
+
.setParameters(
|
|
262
|
+
new Map([
|
|
263
|
+
Parameter.ofEntry(
|
|
264
|
+
TestPrint.VALUES,
|
|
265
|
+
Schema.of(
|
|
266
|
+
TestPrint.VALUES,
|
|
267
|
+
SchemaType.STRING,
|
|
268
|
+
SchemaType.NULL,
|
|
269
|
+
).setDefaultValue(null),
|
|
270
|
+
false,
|
|
271
|
+
),
|
|
272
|
+
]),
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
public getSignature(): FunctionSignature {
|
|
276
|
+
return TestPrint.SIGNATURE;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
protected async internalExecute(
|
|
280
|
+
context: FunctionExecutionParameters,
|
|
281
|
+
): Promise<FunctionOutput> {
|
|
282
|
+
var values = context.getArguments()?.get(TestPrint.VALUES);
|
|
283
|
+
|
|
284
|
+
console?.log(values);
|
|
285
|
+
|
|
286
|
+
return new FunctionOutput([EventResult.outputOf(new Map())]);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var fun = new TestPrint();
|
|
291
|
+
fun.execute(
|
|
292
|
+
new FunctionExecutionParameters(new KIRunFunctionRepository(), new KIRunSchemaRepository()),
|
|
293
|
+
);
|
|
294
|
+
});
|