@fincity/kirun-js 2.0.2 → 2.0.4

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.
@@ -53,9 +53,9 @@ test('sort test 2', async () => {
53
53
 
54
54
  let res: any[] = [];
55
55
  res.push(12);
56
- res.push(1);
57
- res.push(15);
58
56
  res.push(98);
57
+ res.push(15);
58
+ res.push(1);
59
59
 
60
60
  expect((await sort.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(res);
61
61
  });
@@ -72,10 +72,10 @@ test('sort test 3', async () => {
72
72
  let res: any[] = [];
73
73
  res.push(12);
74
74
  res.push(15);
75
- res.push('sure');
76
- res.push('c');
77
- res.push(98);
78
75
  res.push(1);
76
+ res.push(98);
77
+ res.push('c');
78
+ res.push('sure');
79
79
 
80
80
  let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
81
81
  new KIRunFunctionRepository(),
@@ -121,7 +121,7 @@ test('sort test 4', async () => {
121
121
  new Map<string, any>([
122
122
  [Sort.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), arr],
123
123
  [Sort.PARAMETER_INT_FIND_FROM.getParameterName(), 2],
124
- [Sort.PARAMETER_BOOLEAN_ASCENDING.getParameterName(), true],
124
+ [Sort.PARAMETER_BOOLEAN_ASCENDING.getParameterName(), false],
125
125
  ]),
126
126
  );
127
127
 
@@ -144,3 +144,100 @@ test('sort test 5', async () => {
144
144
  let res: any[] = ['Banana', 'Apple', 'Mango', 'Orange'];
145
145
  expect((await sort.execute(fep)).allResults()[0].getResult().get('result')).toMatchObject(res);
146
146
  });
147
+
148
+ test('sort test 6', async () => {
149
+ let arr: any[] = [
150
+ { order: 13 },
151
+ { order: 3 },
152
+ { order: 130 },
153
+ { order: 10 },
154
+ { order: 21 },
155
+ { order: 1 },
156
+ ];
157
+
158
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
159
+ new KIRunFunctionRepository(),
160
+ new KIRunSchemaRepository(),
161
+ ).setArguments(
162
+ new Map<string, any>([
163
+ [Sort.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), arr],
164
+ [Sort.PARAMETER_INT_FIND_FROM.getParameterName(), 0],
165
+ [Sort.PARAMETER_INT_LENGTH.getParameterName(), arr.length],
166
+ [Sort.PARAMETER_KEY_PATH.getParameterName(), 'order'],
167
+ ]),
168
+ );
169
+ let res: any[] = [
170
+ { order: 1 },
171
+ { order: 3 },
172
+ { order: 10 },
173
+ { order: 13 },
174
+ { order: 21 },
175
+ { order: 130 },
176
+ ];
177
+ expect((await sort.execute(fep)).allResults()[0].getResult().get('result')).toMatchObject(res);
178
+ });
179
+
180
+ test('sort test 7', async () => {
181
+ let arr: any[] = [
182
+ { order: { order: 13 } },
183
+ { order: { order: 3 } },
184
+ { order: { order: 130 } },
185
+ { order: { order: 10 } },
186
+ { order: { order: 21 } },
187
+ { order: { order: 1 } },
188
+ ];
189
+
190
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
191
+ new KIRunFunctionRepository(),
192
+ new KIRunSchemaRepository(),
193
+ ).setArguments(
194
+ new Map<string, any>([
195
+ [Sort.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), arr],
196
+ [Sort.PARAMETER_INT_FIND_FROM.getParameterName(), 0],
197
+ [Sort.PARAMETER_INT_LENGTH.getParameterName(), arr.length],
198
+ [Sort.PARAMETER_KEY_PATH.getParameterName(), 'order.order'],
199
+ ]),
200
+ );
201
+ let res: any[] = [
202
+ { order: { order: 1 } },
203
+ { order: { order: 3 } },
204
+ { order: { order: 10 } },
205
+ { order: { order: 13 } },
206
+ { order: { order: 21 } },
207
+ { order: { order: 130 } },
208
+ ];
209
+ expect((await sort.execute(fep)).allResults()[0].getResult().get('result')).toMatchObject(res);
210
+ });
211
+
212
+ test('sort test 8', async () => {
213
+ let arr: any[] = [
214
+ { order: { order: 13 } },
215
+ { order: { order: 3 } },
216
+ { order: { order: 130 } },
217
+ { order: { order: 10 } },
218
+ { order: { order: 21 } },
219
+ { order: { order: 1 } },
220
+ ];
221
+
222
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
223
+ new KIRunFunctionRepository(),
224
+ new KIRunSchemaRepository(),
225
+ ).setArguments(
226
+ new Map<string, any>([
227
+ [Sort.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), arr],
228
+ [Sort.PARAMETER_INT_FIND_FROM.getParameterName(), 0],
229
+ [Sort.PARAMETER_INT_LENGTH.getParameterName(), arr.length],
230
+ [Sort.PARAMETER_KEY_PATH.getParameterName(), 'order.order'],
231
+ [Sort.PARAMETER_BOOLEAN_ASCENDING.getParameterName(), false],
232
+ ]),
233
+ );
234
+ let res: any[] = [
235
+ { order: { order: 130 } },
236
+ { order: { order: 21 } },
237
+ { order: { order: 13 } },
238
+ { order: { order: 10 } },
239
+ { order: { order: 3 } },
240
+ { order: { order: 1 } },
241
+ ];
242
+ expect((await sort.execute(fep)).allResults()[0].getResult().get('result')).toMatchObject(res);
243
+ });
@@ -0,0 +1,118 @@
1
+ import {
2
+ FunctionExecutionParameters,
3
+ KIRunFunctionRepository,
4
+ KIRunSchemaRepository,
5
+ } from '../../../../../src';
6
+ import { Matches } from '../../../../../src/engine/function/system/string/Matches';
7
+
8
+ const matchesF = new Matches();
9
+
10
+ test('simple matches test', async () => {
11
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
12
+ new KIRunFunctionRepository(),
13
+ new KIRunSchemaRepository(),
14
+ );
15
+
16
+ fep.setArguments(
17
+ new Map<string, string>([
18
+ ['regex', '(\\d{2}).(\\d{2}).(\\d{4})'],
19
+ ['string', '10.12.1222'],
20
+ ]),
21
+ );
22
+
23
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeTruthy();
24
+
25
+ fep.setArguments(
26
+ new Map<string, string>([
27
+ ['regex', '(\\d{2}).(\\d{2}).(\\d{4})$'],
28
+ ['string', '10.12.1222 '],
29
+ ]),
30
+ );
31
+
32
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeFalsy();
33
+
34
+ fep.setArguments(
35
+ new Map<string, string>([
36
+ ['regex', '(\\d{2}).(\\d{2}).(\\d{4})'],
37
+ ['string', 'fdsgjhg10.12.122 2'],
38
+ ]),
39
+ );
40
+
41
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeFalsy();
42
+ });
43
+
44
+ test('simple name test', async () => {
45
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
46
+ new KIRunFunctionRepository(),
47
+ new KIRunSchemaRepository(),
48
+ );
49
+
50
+ fep.setArguments(
51
+ new Map<string, string>([
52
+ ['regex', '(\\w+),\\s(Mr|Ms|Mrs|Dr)\\.\\s?(\\w+)'],
53
+ ['string', 'smith, Mr.John'],
54
+ ]),
55
+ );
56
+
57
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeTruthy();
58
+
59
+ fep.setArguments(
60
+ new Map<string, string>([
61
+ ['regex', '(\\w+),\\s(Mr|Ms|Mrs|Dr)\\.\\s?(\\w+)'],
62
+ ['string', 'How are you doing smith, Mr.John??'],
63
+ ]),
64
+ );
65
+
66
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeTruthy();
67
+
68
+ fep.setArguments(
69
+ new Map<string, string>([
70
+ ['regex', '$(\\w+),\\s(Mr|Ms|Mrs|Dr)\\.\\s?(\\w+)$'],
71
+ ['string', 'smith, Mr.Johnadf'],
72
+ ]),
73
+ );
74
+
75
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeFalsy();
76
+ });
77
+
78
+ test('simple time test', async () => {
79
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
80
+ new KIRunFunctionRepository(),
81
+ new KIRunSchemaRepository(),
82
+ );
83
+
84
+ fep.setArguments(
85
+ new Map<string, string>([
86
+ ['regex', '^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$'],
87
+ ['string', '03:33:33'],
88
+ ]),
89
+ );
90
+
91
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeTruthy();
92
+
93
+ fep.setArguments(
94
+ new Map<string, string>([
95
+ ['regex', '([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$'],
96
+ ['string', 'How are you d 03:33:33oing smith, Mr.John??'],
97
+ ]),
98
+ );
99
+
100
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeFalsy();
101
+
102
+ fep.setArguments(
103
+ new Map<string, string>([
104
+ ['regex', '([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?'],
105
+ ['string', 'surendhar12:12:12-02:54asd'],
106
+ ]),
107
+ );
108
+
109
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeTruthy();
110
+ fep.setArguments(
111
+ new Map<string, string>([
112
+ ['regex', '^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?'],
113
+ ['string', 'surendhar12:12:12-02:54asd'],
114
+ ]),
115
+ );
116
+
117
+ expect((await matchesF.execute(fep)).allResults()[0].getResult().get('result')).toBeFalsy();
118
+ });
@@ -0,0 +1,306 @@
1
+ import {
2
+ FunctionDefinition,
3
+ FunctionExecutionParameters,
4
+ KIRunFunctionRepository,
5
+ KIRunSchemaRepository,
6
+ KIRuntime,
7
+ } from '../../../src';
8
+
9
+ test('Testing Fib', async () => {
10
+ let def = {
11
+ name: 'fibonaccii',
12
+ namespace: 'TestUI',
13
+ parameters: {
14
+ n: {
15
+ parameterName: 'n',
16
+ schema: {
17
+ type: ['INTEGER'],
18
+ version: 1,
19
+ },
20
+ },
21
+ },
22
+ events: {
23
+ output: {
24
+ name: 'output',
25
+ parameters: {
26
+ result: {
27
+ type: ['ARRAY'],
28
+ version: 1,
29
+ items: {
30
+ type: ['INTEGER'],
31
+ },
32
+ },
33
+ },
34
+ },
35
+ },
36
+ steps: {
37
+ create: {
38
+ statementName: 'create',
39
+ name: 'Create',
40
+ namespace: 'System.Context',
41
+ position: {
42
+ left: -3,
43
+ top: 65.5,
44
+ },
45
+ parameterMap: {
46
+ name: {
47
+ '2JUURU6NHj9voaArLv0pS8': {
48
+ key: '2JUURU6NHj9voaArLv0pS8',
49
+ type: 'VALUE',
50
+ expression: '',
51
+ order: 1,
52
+ value: 'a',
53
+ },
54
+ },
55
+ schema: {
56
+ '2vxDXyOakSmhiUmH4CuDED': {
57
+ key: '2vxDXyOakSmhiUmH4CuDED',
58
+ type: 'VALUE',
59
+ expression: '',
60
+ order: 1,
61
+ value: {
62
+ type: 'ARRAY',
63
+ items: {
64
+ type: 'INTEGER',
65
+ },
66
+ },
67
+ },
68
+ },
69
+ },
70
+ },
71
+ rangeLoop: {
72
+ statementName: 'rangeLoop',
73
+ name: 'RangeLoop',
74
+ namespace: 'System.Loop',
75
+ position: {
76
+ left: 503,
77
+ top: 377.5,
78
+ },
79
+ parameterMap: {
80
+ to: {
81
+ '6RAIEdM1OAek2AKf64ucqM': {
82
+ key: '6RAIEdM1OAek2AKf64ucqM',
83
+ type: 'EXPRESSION',
84
+ expression: 'Arguments.n',
85
+ value: 1,
86
+ },
87
+ },
88
+ },
89
+ dependentStatements: {
90
+ 'Steps.create.output': false,
91
+ 'Steps.set2.output': true,
92
+ },
93
+ },
94
+ if: {
95
+ statementName: 'if',
96
+ name: 'If',
97
+ namespace: 'System',
98
+ position: {
99
+ left: 802,
100
+ top: 248.5,
101
+ },
102
+ parameterMap: {
103
+ condition: {
104
+ C2FB54BobtFXTmLKv4v6s: {
105
+ key: 'C2FB54BobtFXTmLKv4v6s',
106
+ type: 'EXPRESSION',
107
+ expression: 'Steps.rangeLoop.iteration.index < 2',
108
+ order: 1,
109
+ },
110
+ },
111
+ },
112
+ },
113
+ generateEvent: {
114
+ statementName: 'generateEvent',
115
+ name: 'GenerateEvent',
116
+ namespace: 'System',
117
+ position: {
118
+ left: 706,
119
+ top: 739.5,
120
+ },
121
+ parameterMap: {
122
+ results: {
123
+ '8brcu20HciA9rYDPOFeef': {
124
+ key: '8brcu20HciA9rYDPOFeef',
125
+ type: 'VALUE',
126
+ value: {
127
+ name: 'result',
128
+ value: { isExpression: true, value: 'Context.a' },
129
+ },
130
+ order: 1,
131
+ },
132
+ },
133
+ },
134
+ dependentStatements: {
135
+ 'Steps.rangeLoop.output': true,
136
+ },
137
+ },
138
+ trueInsert: {
139
+ statementName: 'trueInsert',
140
+ name: 'InsertLast',
141
+ namespace: 'System.Array',
142
+ position: {
143
+ left: 1304,
144
+ top: 277.77777777777777,
145
+ },
146
+ parameterMap: {
147
+ source: {
148
+ '4DzS3icjwGl7nUPvk7QUST': {
149
+ key: '4DzS3icjwGl7nUPvk7QUST',
150
+ type: 'EXPRESSION',
151
+ expression: 'Context.a',
152
+ order: 1,
153
+ },
154
+ },
155
+ element: {
156
+ '1sWH8NKqkdKevU7vQJk9jn': {
157
+ key: '1sWH8NKqkdKevU7vQJk9jn',
158
+ type: 'EXPRESSION',
159
+ expression: 'Steps.rangeLoop.iteration.index',
160
+ order: 1,
161
+ },
162
+ },
163
+ },
164
+ dependentStatements: {
165
+ 'Steps.if.true': true,
166
+ },
167
+ },
168
+ set: {
169
+ statementName: 'set',
170
+ name: 'Set',
171
+ namespace: 'System.Context',
172
+ position: {
173
+ left: 1617,
174
+ top: 434.5,
175
+ },
176
+ parameterMap: {
177
+ name: {
178
+ UPMhlPSuFHCygh0DYa7Zc: {
179
+ key: 'UPMhlPSuFHCygh0DYa7Zc',
180
+ type: 'VALUE',
181
+ expression: '',
182
+ order: 1,
183
+ value: 'Context.a',
184
+ },
185
+ },
186
+ value: {
187
+ '1B8Bfavmym6BmbdsDesmNX': {
188
+ key: '1B8Bfavmym6BmbdsDesmNX',
189
+ type: 'EXPRESSION',
190
+ expression: 'Steps.trueInsert.output.result',
191
+ order: 1,
192
+ },
193
+ },
194
+ },
195
+ dependentStatements: {
196
+ 'Steps.if.true': false,
197
+ },
198
+ },
199
+ set1: {
200
+ statementName: 'set1',
201
+ name: 'Set',
202
+ namespace: 'System.Context',
203
+ position: {
204
+ left: 1503,
205
+ top: 715.5,
206
+ },
207
+ parameterMap: {
208
+ name: {
209
+ '6dYVAyspJbF82O8qJm3f2O': {
210
+ key: '6dYVAyspJbF82O8qJm3f2O',
211
+ type: 'VALUE',
212
+ expression: '',
213
+ order: 1,
214
+ value: 'Context.a',
215
+ },
216
+ },
217
+ value: {
218
+ fVB75EKlR6It0i7iho3oQ: {
219
+ key: 'fVB75EKlR6It0i7iho3oQ',
220
+ type: 'EXPRESSION',
221
+ expression: 'Steps.falseInsert.output.result',
222
+ order: 1,
223
+ },
224
+ },
225
+ },
226
+ dependentStatements: {
227
+ 'Steps.if.false': false,
228
+ },
229
+ },
230
+ falseInsert: {
231
+ statementName: 'falseInsert',
232
+ name: 'InsertLast',
233
+ namespace: 'System.Array',
234
+ position: {
235
+ left: 1140.3333333333333,
236
+ top: 548.8888888888889,
237
+ },
238
+ parameterMap: {
239
+ source: {
240
+ '1GsJu3FbuponBIcaqI48rF': {
241
+ key: '1GsJu3FbuponBIcaqI48rF',
242
+ type: 'EXPRESSION',
243
+ expression: 'Context.a',
244
+ order: 1,
245
+ },
246
+ },
247
+ element: {
248
+ '53vsp50RjvhS94xdCtWWx0': {
249
+ key: '53vsp50RjvhS94xdCtWWx0',
250
+ type: 'EXPRESSION',
251
+ expression:
252
+ 'Context.a[Steps.rangeLoop.iteration.index - 1] + Context.a[Steps.rangeLoop.iteration.index - 2]',
253
+ order: 1,
254
+ },
255
+ },
256
+ },
257
+ dependentStatements: {
258
+ 'Steps.if.false': true,
259
+ },
260
+ },
261
+ set2: {
262
+ statementName: 'set2',
263
+ name: 'Set',
264
+ namespace: 'System.Context',
265
+ position: {
266
+ left: 257,
267
+ top: 273.5,
268
+ },
269
+ parameterMap: {
270
+ name: {
271
+ '2XVsWDK0VUQhZJ0VnJllrQ': {
272
+ key: '2XVsWDK0VUQhZJ0VnJllrQ',
273
+ type: 'VALUE',
274
+ expression: '',
275
+ order: 1,
276
+ value: 'Context.a',
277
+ },
278
+ },
279
+ value: {
280
+ '1ksRfalqqgGfh4uZcLXDy9': {
281
+ key: '1ksRfalqqgGfh4uZcLXDy9',
282
+ type: 'VALUE',
283
+ expression: '',
284
+ order: 1,
285
+ value: [],
286
+ },
287
+ },
288
+ },
289
+ dependentStatements: {
290
+ 'Steps.create.output': true,
291
+ },
292
+ },
293
+ },
294
+ };
295
+
296
+ let fd = FunctionDefinition.from(def);
297
+
298
+ let out = await new KIRuntime(fd, true).execute(
299
+ new FunctionExecutionParameters(
300
+ new KIRunFunctionRepository(),
301
+ new KIRunSchemaRepository(),
302
+ ).setArguments(new Map([['n', 5]])),
303
+ );
304
+
305
+ console.log(out.next()?.getResult());
306
+ });