@fincity/kirun-js 2.1.2 → 2.1.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,161 @@
1
+ import { Insert } from '../../../../../src/engine/function/system/array/Insert';
2
+ import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
3
+ import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
4
+ import { Join } from '../../../../../src/engine/function/system/array/Join';
5
+
6
+ describe('Join Tests', () => {
7
+ test('Join Test 1', async () => {
8
+ let join: Join = new Join();
9
+
10
+ let array: any[] = [
11
+ 'test',
12
+ 'Driven',
13
+ 'developement',
14
+ 'I',
15
+ 'am',
16
+ 'using',
17
+ 'eclipse',
18
+ 'I',
19
+ 'to',
20
+ 'test',
21
+ 'the',
22
+ 'changes',
23
+ 'with',
24
+ 'test',
25
+ 'Driven',
26
+ 'developement',
27
+ ];
28
+
29
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
30
+ new KIRunFunctionRepository(),
31
+ new KIRunSchemaRepository(),
32
+ )
33
+ .setArguments(
34
+ new Map<string, any>([
35
+ ['source', array],
36
+ ['delimiter', ' '],
37
+ ]),
38
+ )
39
+ .setSteps(new Map([]))
40
+ .setContext(new Map([]));
41
+
42
+ let res: string =
43
+ 'test Driven developement I am using eclipse I to test the changes with test Driven developement';
44
+
45
+ expect((await join.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(
46
+ res,
47
+ );
48
+ });
49
+
50
+ test('Join Test without delimiter', async () => {
51
+ let join: Join = new Join();
52
+
53
+ let array: any[] = [
54
+ 'test',
55
+ 'Driven',
56
+ 'developement',
57
+ 'I',
58
+ 'am',
59
+ 'using',
60
+ 'eclipse',
61
+ 'I',
62
+ 'to',
63
+ 'test',
64
+ 'the',
65
+ 'changes',
66
+ 'with',
67
+ 'test',
68
+ 'Driven',
69
+ 'developement',
70
+ ];
71
+
72
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
73
+ new KIRunFunctionRepository(),
74
+ new KIRunSchemaRepository(),
75
+ )
76
+ .setArguments(new Map<string, any>([['source', array]]))
77
+ .setSteps(new Map([]))
78
+ .setContext(new Map([]));
79
+
80
+ let res: string =
81
+ 'testDrivendevelopementIamusingeclipseItotestthechangeswithtestDrivendevelopement';
82
+
83
+ expect((await join.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(
84
+ res,
85
+ );
86
+ });
87
+
88
+ test('Join Test with mixxed data types', async () => {
89
+ let join: Join = new Join();
90
+
91
+ let array: any[] = [
92
+ 'test',
93
+ 'Driven',
94
+ 'developement',
95
+ 'I',
96
+ 'am',
97
+ 'using',
98
+ 'eclipse',
99
+ 'I',
100
+ 'to',
101
+ 'test',
102
+ 'the',
103
+ 'changes',
104
+ 'with',
105
+ 'test',
106
+ 4,
107
+ 5,
108
+ ];
109
+
110
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
111
+ new KIRunFunctionRepository(),
112
+ new KIRunSchemaRepository(),
113
+ )
114
+ .setArguments(new Map<string, any>([['source', array]]))
115
+ .setSteps(new Map([]))
116
+ .setContext(new Map([]));
117
+
118
+ let res: string = 'testDrivendevelopementIamusingeclipseItotestthechangeswithtest45';
119
+
120
+ expect((await join.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(
121
+ res,
122
+ );
123
+ });
124
+
125
+ test('Join Test with undefined', async () => {
126
+ let join: Join = new Join();
127
+
128
+ let array: any[] = [
129
+ 'test',
130
+ 'Driven',
131
+ 'developement',
132
+ 'I',
133
+ 'am',
134
+ 'using',
135
+ 'eclipse',
136
+ 'I',
137
+ 'to',
138
+ 'test',
139
+ 'the',
140
+ undefined,
141
+ 'with',
142
+ 'test',
143
+ 4,
144
+ 5,
145
+ ];
146
+
147
+ let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
148
+ new KIRunFunctionRepository(),
149
+ new KIRunSchemaRepository(),
150
+ )
151
+ .setArguments(new Map<string, any>([['source', array]]))
152
+ .setSteps(new Map([]))
153
+ .setContext(new Map([]));
154
+
155
+ let res: string = 'testDrivendevelopementIamusingeclipseItotestthewithtest45';
156
+
157
+ expect((await join.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(
158
+ res,
159
+ );
160
+ });
161
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fincity/kirun-js",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Javascript Runtime for Kinetic Instructions",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,59 @@
1
+ import { Schema } from '../../../json/schema/Schema';
2
+ import { SchemaType } from '../../../json/schema/type/SchemaType';
3
+ import { Event } from '../../../model/Event';
4
+ import { EventResult } from '../../../model/EventResult';
5
+ import { FunctionOutput } from '../../../model/FunctionOutput';
6
+ import { FunctionSignature } from '../../../model/FunctionSignature';
7
+ import { Parameter } from '../../../model/Parameter';
8
+ import { Namespaces } from '../../../namespaces/Namespaces';
9
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
10
+ import { AbstractFunction } from '../../AbstractFunction';
11
+
12
+ const VALUE = 'source';
13
+ const DELIMITTER = 'delimiter';
14
+ const OUTPUT = 'result';
15
+
16
+ const SIGNATURE = new FunctionSignature('Join')
17
+ .setNamespace(Namespaces.SYSTEM_ARRAY)
18
+ .setParameters(
19
+ new Map([
20
+ [
21
+ VALUE,
22
+ new Parameter(
23
+ VALUE,
24
+ Schema.ofArray(
25
+ VALUE,
26
+ Schema.of(
27
+ 'each',
28
+ SchemaType.STRING,
29
+ SchemaType.INTEGER,
30
+ SchemaType.LONG,
31
+ SchemaType.DOUBLE,
32
+ SchemaType.FLOAT,
33
+ SchemaType.NULL,
34
+ ),
35
+ ),
36
+ ),
37
+ ],
38
+ [
39
+ DELIMITTER,
40
+ new Parameter(DELIMITTER, Schema.ofString(DELIMITTER).setDefaultValue('')),
41
+ ],
42
+ ]),
43
+ )
44
+ .setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT, Schema.ofString(OUTPUT)]]))]));
45
+
46
+ export class Join extends AbstractFunction {
47
+ public getSignature(): FunctionSignature {
48
+ return SIGNATURE;
49
+ }
50
+
51
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
52
+ let source: any[] = context?.getArguments()?.get(VALUE);
53
+ let delimitter: string = context?.getArguments()?.get(DELIMITTER);
54
+
55
+ return new FunctionOutput([
56
+ EventResult.outputOf(new Map([[OUTPUT, source.join(delimitter)]])),
57
+ ]);
58
+ }
59
+ }