@fincity/kirun-js 2.0.2 → 2.0.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.
@@ -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
+ });