@fincity/kirun-js 1.6.5 → 1.6.7

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,50 @@
1
+ import {
2
+ Namespaces,
3
+ FunctionDefinition,
4
+ KIRuntime,
5
+ FunctionExecutionParameters,
6
+ KIRunFunctionRepository,
7
+ KIRunSchemaRepository,
8
+ Repository,
9
+ Function,
10
+ HybridRepository,
11
+ } from '../../../src';
12
+ import { Print } from '../../../src/engine/function/system/Print';
13
+
14
+ test('KIRuntime Without any parameter map passed in definition', async () => {
15
+ var def = {
16
+ name: 'Make an error',
17
+ namespace: 'UIApp',
18
+ steps: {
19
+ print: {
20
+ statementName: 'print',
21
+ namespace: 'function',
22
+ name: 'test',
23
+ },
24
+ },
25
+ };
26
+
27
+ const fd = FunctionDefinition.from(def);
28
+
29
+ const tstPrint = new Print();
30
+
31
+ class TestRepository implements Repository<Function> {
32
+ public find(namespace: string, name: string): Function | undefined {
33
+ return tstPrint;
34
+ }
35
+ filter(name: string): string[] {
36
+ throw new Error('Method not implemented.');
37
+ }
38
+ }
39
+
40
+ try {
41
+ await new KIRuntime(fd).execute(
42
+ new FunctionExecutionParameters(
43
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
44
+ new KIRunSchemaRepository(),
45
+ ).setArguments(new Map()),
46
+ );
47
+ } catch (e: any) {
48
+ console.error(e);
49
+ }
50
+ });
@@ -0,0 +1,53 @@
1
+ import {
2
+ Namespaces,
3
+ FunctionDefinition,
4
+ KIRuntime,
5
+ FunctionExecutionParameters,
6
+ KIRunFunctionRepository,
7
+ KIRunSchemaRepository,
8
+ Repository,
9
+ Function,
10
+ HybridRepository,
11
+ FunctionOutput,
12
+ } from '../../../src';
13
+ import { Print } from '../../../src/engine/function/system/Print';
14
+
15
+ test('KIRuntime With Definition without values object inside parameter Map', async () => {
16
+ var def = {
17
+ name: 'Make an error',
18
+ namespace: 'UIApp',
19
+ steps: {
20
+ print: {
21
+ statementName: 'print',
22
+ namespace: 'function',
23
+ name: 'test',
24
+ parameterMap: {},
25
+ },
26
+ },
27
+ };
28
+
29
+ const fd = FunctionDefinition.from(def);
30
+
31
+ const tstPrint = new Print();
32
+
33
+ class TestRepository implements Repository<Function> {
34
+ public find(namespace: string, name: string): Function | undefined {
35
+ return tstPrint;
36
+ }
37
+ filter(name: string): string[] {
38
+ throw new Error('Method not implemented.');
39
+ }
40
+ }
41
+
42
+ try {
43
+ const fo: FunctionOutput = await new KIRuntime(fd).execute(
44
+ new FunctionExecutionParameters(
45
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
46
+ new KIRunSchemaRepository(),
47
+ ).setArguments(new Map()),
48
+ );
49
+ console.log(fo);
50
+ } catch (e: any) {
51
+ console.error(e);
52
+ }
53
+ });
@@ -0,0 +1,137 @@
1
+ import {
2
+ Namespaces,
3
+ FunctionDefinition,
4
+ KIRuntime,
5
+ FunctionExecutionParameters,
6
+ KIRunFunctionRepository,
7
+ KIRunSchemaRepository,
8
+ Repository,
9
+ Function,
10
+ HybridRepository,
11
+ FunctionOutput,
12
+ Parameter,
13
+ Schema,
14
+ FunctionSignature,
15
+ EventResult,
16
+ AbstractFunction,
17
+ } from '../../../src';
18
+
19
+ class Print extends AbstractFunction {
20
+ private static readonly VALUES: string = 'values';
21
+ private static readonly VALUE: string = 'value';
22
+
23
+ private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Print')
24
+ .setNamespace(Namespaces.SYSTEM)
25
+ .setParameters(
26
+ new Map([
27
+ Parameter.ofEntry(Print.VALUES, Schema.ofAny(Print.VALUES), true),
28
+ Parameter.ofEntry(Print.VALUE, Schema.ofAny(Print.VALUE)),
29
+ ]),
30
+ );
31
+
32
+ public getSignature(): FunctionSignature {
33
+ return Print.SIGNATURE;
34
+ }
35
+
36
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
37
+ let values = context.getArguments()?.get(Print.VALUES);
38
+ let value = context.getArguments()?.get(Print.VALUE);
39
+
40
+ console?.log('Values', ...values);
41
+ console?.log('Value', value);
42
+
43
+ return new FunctionOutput([EventResult.outputOf(new Map())]);
44
+ }
45
+ }
46
+
47
+ test('KIRuntime Undefined and null param type with varargs', async () => {
48
+ var def = {
49
+ name: 'Make an error',
50
+ namespace: 'UIApp',
51
+ steps: {
52
+ print: {
53
+ statementName: 'print',
54
+ namespace: 'function',
55
+ name: 'test',
56
+ parameterMap: {
57
+ values: {
58
+ one: { key: 'one', type: 'VALUE', value: null },
59
+ two: { key: 'two', type: 'VALUE', value: undefined },
60
+ three: { key: 'three', type: 'EXPRESSION', expression: 'null' },
61
+ four: { key: 'four', type: 'VALUE', value: 12 },
62
+ },
63
+ value: {},
64
+ },
65
+ },
66
+ },
67
+ };
68
+
69
+ const fd = FunctionDefinition.from(def);
70
+
71
+ const tstPrint = new Print();
72
+
73
+ class TestRepository implements Repository<Function> {
74
+ public find(namespace: string, name: string): Function | undefined {
75
+ return tstPrint;
76
+ }
77
+ filter(name: string): string[] {
78
+ throw new Error('Method not implemented.');
79
+ }
80
+ }
81
+
82
+ try {
83
+ var fo: FunctionOutput = await new KIRuntime(fd).execute(
84
+ new FunctionExecutionParameters(
85
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
86
+ new KIRunSchemaRepository(),
87
+ ).setArguments(new Map()),
88
+ );
89
+ expect(fo.allResults()).toStrictEqual([]);
90
+ } catch (e: any) {
91
+ console.error(e);
92
+ }
93
+ });
94
+
95
+ test('KIRuntime Undefined and null param type without varargs', async () => {
96
+ var def = {
97
+ name: 'Make an error',
98
+ namespace: 'UIApp',
99
+ steps: {
100
+ print: {
101
+ statementName: 'print',
102
+ namespace: 'function',
103
+ name: 'test',
104
+ parameterMap: {
105
+ value: {
106
+ two: { key: 'two', type: 'VALUE', value: undefined },
107
+ },
108
+ },
109
+ },
110
+ },
111
+ };
112
+
113
+ const fd = FunctionDefinition.from(def);
114
+
115
+ const tstPrint = new Print();
116
+
117
+ class TestRepository implements Repository<Function> {
118
+ public find(namespace: string, name: string): Function | undefined {
119
+ return tstPrint;
120
+ }
121
+ filter(name: string): string[] {
122
+ throw new Error('Method not implemented.');
123
+ }
124
+ }
125
+
126
+ try {
127
+ var fo: FunctionOutput = await new KIRuntime(fd).execute(
128
+ new FunctionExecutionParameters(
129
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
130
+ new KIRunSchemaRepository(),
131
+ ).setArguments(new Map()),
132
+ );
133
+ expect(fo.allResults()).toStrictEqual([]);
134
+ } catch (e: any) {
135
+ console.error(e);
136
+ }
137
+ });
@@ -0,0 +1,172 @@
1
+ import {
2
+ Namespaces,
3
+ FunctionDefinition,
4
+ KIRuntime,
5
+ FunctionExecutionParameters,
6
+ KIRunFunctionRepository,
7
+ KIRunSchemaRepository,
8
+ Repository,
9
+ Function,
10
+ HybridRepository,
11
+ FunctionOutput,
12
+ Parameter,
13
+ AbstractFunction,
14
+ EventResult,
15
+ FunctionSignature,
16
+ Schema,
17
+ } from '../../../src';
18
+
19
+ class Print extends AbstractFunction {
20
+ private static readonly VALUES: string = 'values';
21
+ private static readonly VALUE: string = 'value';
22
+
23
+ private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Print')
24
+ .setNamespace(Namespaces.SYSTEM)
25
+ .setParameters(
26
+ new Map([
27
+ Parameter.ofEntry(Print.VALUES, Schema.ofAny(Print.VALUES), true),
28
+ Parameter.ofEntry(Print.VALUE, Schema.ofAny(Print.VALUE)),
29
+ ]),
30
+ );
31
+
32
+ public getSignature(): FunctionSignature {
33
+ return Print.SIGNATURE;
34
+ }
35
+
36
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
37
+ let values = context.getArguments()?.get(Print.VALUES);
38
+ let value = context.getArguments()?.get(Print.VALUE);
39
+
40
+ console?.log('Values', ...values);
41
+ console?.log('Value', value);
42
+
43
+ return new FunctionOutput([EventResult.outputOf(new Map())]);
44
+ }
45
+ }
46
+
47
+ test('KIRuntime With Definition no values passed ', async () => {
48
+ var def = {
49
+ name: 'Make an error',
50
+ namespace: 'UIApp',
51
+ steps: {
52
+ print: {
53
+ statementName: 'print',
54
+ namespace: 'function',
55
+ name: 'test',
56
+ parameterMap: {
57
+ values: {},
58
+ },
59
+ },
60
+ },
61
+ };
62
+
63
+ const fd = FunctionDefinition.from(def);
64
+
65
+ const tstPrint = new Print();
66
+
67
+ class TestRepository implements Repository<Function> {
68
+ public find(namespace: string, name: string): Function | undefined {
69
+ return tstPrint;
70
+ }
71
+ filter(name: string): string[] {
72
+ throw new Error('Method not implemented.');
73
+ }
74
+ }
75
+
76
+ try {
77
+ const fo: FunctionOutput = await new KIRuntime(fd).execute(
78
+ new FunctionExecutionParameters(
79
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
80
+ new KIRunSchemaRepository(),
81
+ ).setArguments(new Map()),
82
+ );
83
+ console.log(fo);
84
+ } catch (e: any) {
85
+ console.error(e);
86
+ }
87
+ });
88
+
89
+ test('KIRuntime With Definition with no value passed', async () => {
90
+ var def = {
91
+ name: 'Make an error',
92
+ namespace: 'UIApp',
93
+ steps: {
94
+ print: {
95
+ statementName: 'print',
96
+ namespace: 'function',
97
+ name: 'test',
98
+ parameterMap: {
99
+ value: {},
100
+ },
101
+ },
102
+ },
103
+ };
104
+
105
+ const fd = FunctionDefinition.from(def);
106
+
107
+ const tstPrint = new Print();
108
+
109
+ class TestRepository implements Repository<Function> {
110
+ public find(namespace: string, name: string): Function | undefined {
111
+ return tstPrint;
112
+ }
113
+ filter(name: string): string[] {
114
+ throw new Error('Method not implemented.');
115
+ }
116
+ }
117
+
118
+ try {
119
+ const fo: FunctionOutput = await new KIRuntime(fd).execute(
120
+ new FunctionExecutionParameters(
121
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
122
+ new KIRunSchemaRepository(),
123
+ ).setArguments(new Map()),
124
+ );
125
+ console.log(fo);
126
+ } catch (e: any) {
127
+ console.error(e);
128
+ }
129
+ });
130
+
131
+ test('KIRuntime With Definition with no value and values passed', async () => {
132
+ var def = {
133
+ name: 'Make an error',
134
+ namespace: 'UIApp',
135
+ steps: {
136
+ print: {
137
+ statementName: 'print',
138
+ namespace: 'function',
139
+ name: 'test',
140
+ parameterMap: {
141
+ value: {},
142
+ values: {},
143
+ },
144
+ },
145
+ },
146
+ };
147
+
148
+ const fd = FunctionDefinition.from(def);
149
+
150
+ const tstPrint = new Print();
151
+
152
+ class TestRepository implements Repository<Function> {
153
+ public find(namespace: string, name: string): Function | undefined {
154
+ return tstPrint;
155
+ }
156
+ filter(name: string): string[] {
157
+ throw new Error('Method not implemented.');
158
+ }
159
+ }
160
+
161
+ try {
162
+ const fo: FunctionOutput = await new KIRuntime(fd).execute(
163
+ new FunctionExecutionParameters(
164
+ new HybridRepository(new KIRunFunctionRepository(), new TestRepository()),
165
+ new KIRunSchemaRepository(),
166
+ ).setArguments(new Map()),
167
+ );
168
+ console.log(fo);
169
+ } catch (e: any) {
170
+ console.error(e);
171
+ }
172
+ });
@@ -84,7 +84,6 @@ test('KIRuntime With Definition 1', async () => {
84
84
  ]),
85
85
  ),
86
86
  );
87
-
88
87
  expect(result.allResults()[0].getResult().get('additionResult')).toBe(31);
89
88
  });
90
89