@fincity/kirun-js 1.4.10 → 1.4.11
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/KIRuntimeFunctionInFunction.ts +163 -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/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/runtime/FunctionExecutionParameters.ts +1 -2
- package/src/engine/runtime/KIRuntime.ts +37 -14
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Function,
|
|
3
|
+
FunctionDefinition,
|
|
4
|
+
HybridRepository,
|
|
5
|
+
KIRunFunctionRepository,
|
|
6
|
+
Repository,
|
|
7
|
+
KIRuntime,
|
|
8
|
+
FunctionExecutionParameters,
|
|
9
|
+
KIRunSchemaRepository,
|
|
10
|
+
} from '../../../src';
|
|
11
|
+
|
|
12
|
+
test('KIRuntime Function in Function', async () => {
|
|
13
|
+
const first = new KIRuntime(
|
|
14
|
+
FunctionDefinition.from(
|
|
15
|
+
JSON.parse(`{
|
|
16
|
+
"name": "First",
|
|
17
|
+
"namespace": "Internal",
|
|
18
|
+
"events": {
|
|
19
|
+
"output": {
|
|
20
|
+
"name": "output",
|
|
21
|
+
"parameters": { "aresult": { "name": "aresult", "type": "INTEGER" } }
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"steps": {
|
|
25
|
+
"exSecond": {
|
|
26
|
+
"statementName": "exSecond",
|
|
27
|
+
"name": "Second",
|
|
28
|
+
"namespace": "Internal",
|
|
29
|
+
"parameterMap": {
|
|
30
|
+
"value" : { "one" : { "key": "one", "type": "VALUE", "value": 2 } }
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"exThird": {
|
|
34
|
+
"statementName": "exThird",
|
|
35
|
+
"name": "Third",
|
|
36
|
+
"namespace": "Internal",
|
|
37
|
+
"parameterMap": {
|
|
38
|
+
"value" : { "one" : { "key": "one", "type": "VALUE", "value": 3 } }
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"genOutput": {
|
|
42
|
+
"statementName": "genOutput",
|
|
43
|
+
"namespace": "System",
|
|
44
|
+
"name": "GenerateEvent",
|
|
45
|
+
"dependentStatements": {
|
|
46
|
+
"Steps.exSecond.output": true,
|
|
47
|
+
"Steps.exThird.output": true
|
|
48
|
+
},
|
|
49
|
+
"parameterMap": {
|
|
50
|
+
"eventName": { "one": { "key": "one", "type": "VALUE", "value": "output" } },
|
|
51
|
+
"results": {
|
|
52
|
+
"one": {
|
|
53
|
+
"key": "one",
|
|
54
|
+
"type": "VALUE",
|
|
55
|
+
"value": {
|
|
56
|
+
"name": "aresult",
|
|
57
|
+
"value": { "isExpression": true, "value": "Steps.exThird.output.result" }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}`),
|
|
65
|
+
),
|
|
66
|
+
true,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const second = new KIRuntime(
|
|
70
|
+
FunctionDefinition.from(
|
|
71
|
+
JSON.parse(`{
|
|
72
|
+
"name": "Second",
|
|
73
|
+
"namespace": "Internal",
|
|
74
|
+
"parameters": {
|
|
75
|
+
"value": { "parameterName": "value", "schema": { "name": "INTEGER", "type": "INTEGER" } } },
|
|
76
|
+
"events": {
|
|
77
|
+
"output": {
|
|
78
|
+
"name": "output",
|
|
79
|
+
"parameters": { "result": { "name": "result", "type": "INTEGER" } }
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"steps": {
|
|
83
|
+
"genOutput": {
|
|
84
|
+
"statementName": "genOutput",
|
|
85
|
+
"namespace": "System",
|
|
86
|
+
"name": "GenerateEvent",
|
|
87
|
+
"parameterMap": {
|
|
88
|
+
"eventName": { "one": { "key": "one", "type": "VALUE", "value": "output" } },
|
|
89
|
+
"results": {
|
|
90
|
+
"one": {
|
|
91
|
+
"key": "one",
|
|
92
|
+
"type": "VALUE",
|
|
93
|
+
"value": {
|
|
94
|
+
"name": "result",
|
|
95
|
+
"value": { "isExpression": true, "value": "Arguments.value * 2" }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}`),
|
|
103
|
+
),
|
|
104
|
+
true,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const third = new KIRuntime(
|
|
108
|
+
FunctionDefinition.from(
|
|
109
|
+
JSON.parse(`{
|
|
110
|
+
"name": "Third",
|
|
111
|
+
"namespace": "Internal",
|
|
112
|
+
"parameters": {
|
|
113
|
+
"value": { "parameterName": "value", "schema": { "name": "INTEGER", "type": "INTEGER" } } },
|
|
114
|
+
"events": {
|
|
115
|
+
"output": {
|
|
116
|
+
"name": "output",
|
|
117
|
+
"parameters": { "result": { "name": "result", "type": "INTEGER" } }
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"steps": {
|
|
121
|
+
"genOutput": {
|
|
122
|
+
"statementName": "genOutput",
|
|
123
|
+
"namespace": "System",
|
|
124
|
+
"name": "GenerateEvent",
|
|
125
|
+
"parameterMap": {
|
|
126
|
+
"eventName": { "one": { "key": "one", "type": "VALUE", "value": "output" } },
|
|
127
|
+
"results": {
|
|
128
|
+
"one": {
|
|
129
|
+
"key": "one",
|
|
130
|
+
"type": "VALUE",
|
|
131
|
+
"value": {
|
|
132
|
+
"name": "result",
|
|
133
|
+
"value": { "isExpression": true, "value": "Arguments.value * 3" }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}`),
|
|
141
|
+
),
|
|
142
|
+
true,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
class InternalRepository implements Repository<Function> {
|
|
146
|
+
find(namespace: string, name: string): Function | undefined {
|
|
147
|
+
if (namespace !== 'Internal') return;
|
|
148
|
+
|
|
149
|
+
if (name === 'Third') return third;
|
|
150
|
+
if (name === 'Second') return second;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const repo = new HybridRepository(new KIRunFunctionRepository(), new InternalRepository());
|
|
155
|
+
|
|
156
|
+
const results = (
|
|
157
|
+
await first.execute(
|
|
158
|
+
new FunctionExecutionParameters(repo, new KIRunSchemaRepository(), 'Testing'),
|
|
159
|
+
)
|
|
160
|
+
).next();
|
|
161
|
+
|
|
162
|
+
expect(results?.getResult().get('aresult')).toBe(9);
|
|
163
|
+
});
|