@ldsg/workflow 0.3.9 → 0.3.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.
Files changed (58) hide show
  1. package/dist/__tests__/unit/evaluate-variables.prefixItems.test.d.ts +2 -0
  2. package/dist/__tests__/unit/evaluate-variables.prefixItems.test.d.ts.map +1 -0
  3. package/dist/__tests__/unit/evaluate-variables.prefixItems.test.js +391 -0
  4. package/dist/__tests__/unit/resource.js +62 -61
  5. package/dist/__tests__/unit/resource.portId.test.d.ts +2 -0
  6. package/dist/__tests__/unit/resource.portId.test.d.ts.map +1 -0
  7. package/dist/__tests__/unit/resource.portId.test.js +275 -0
  8. package/dist/constants.d.ts +3 -3
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/constants.js +11 -11
  11. package/dist/handler.d.ts +5 -7
  12. package/dist/handler.d.ts.map +1 -1
  13. package/dist/index.d.ts +5 -5
  14. package/dist/instantiate-resource.d.ts +4 -4
  15. package/dist/instantiate-resource.js +1 -1
  16. package/dist/resource.d.ts +2 -2
  17. package/dist/resource.d.ts.map +1 -1
  18. package/dist/resource.js +23 -83
  19. package/dist/types/index.d.ts +6 -6
  20. package/dist/types/json_schema_with_expression_extension.d.ts +9 -6
  21. package/dist/types/json_schema_with_expression_extension.d.ts.map +1 -1
  22. package/dist/types/node.d.ts +15 -11
  23. package/dist/types/node.d.ts.map +1 -1
  24. package/dist/types/specific-resource-settings.d.ts +1 -1
  25. package/dist/types/specific-resource-settings.d.ts.map +1 -1
  26. package/dist/types/workflow.d.ts +12 -3
  27. package/dist/types/workflow.d.ts.map +1 -1
  28. package/dist/utils/evaluate-variables/constants.d.ts.map +1 -1
  29. package/dist/utils/evaluate-variables/constants.js +17 -17
  30. package/dist/utils/evaluate-variables/index.d.ts +2 -2
  31. package/dist/utils/evaluate-variables/index.d.ts.map +1 -1
  32. package/dist/utils/evaluate-variables/index.debug.d.ts +2 -0
  33. package/dist/utils/evaluate-variables/index.debug.d.ts.map +1 -0
  34. package/dist/utils/evaluate-variables/index.debug.js +194 -0
  35. package/dist/utils/evaluate-variables/index.js +5 -5
  36. package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.d.ts +21 -0
  37. package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.d.ts.map +1 -0
  38. package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.js +17 -0
  39. package/dist/utils/evaluate-variables/utils/{resolve-json-schema.d.ts → get-data-with-json-schema-and-input/resolve-json-schema.d.ts} +10 -7
  40. package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.d.ts.map +1 -0
  41. package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.js +96 -0
  42. package/dist/utils/evaluate-variables/utils/get-field-path-by-field-type-key.d.ts.map +1 -1
  43. package/dist/utils/evaluate-variables/utils/get-field-path-by-field-type-key.js +3 -3
  44. package/dist/utils/execute-workflow.d.ts +22 -0
  45. package/dist/utils/execute-workflow.d.ts.map +1 -0
  46. package/dist/utils/execute-workflow.js +212 -0
  47. package/package.json +25 -14
  48. package/dist/utils/evaluate-variables/index.test.d.ts +0 -2
  49. package/dist/utils/evaluate-variables/index.test.d.ts.map +0 -1
  50. package/dist/utils/evaluate-variables/index.test.js +0 -219
  51. package/dist/utils/evaluate-variables/utils/resolve-json-schema.d.ts.map +0 -1
  52. package/dist/utils/evaluate-variables/utils/resolve-json-schema.js +0 -112
  53. package/dist/utils/get-execution-levels.d.ts +0 -17
  54. package/dist/utils/get-execution-levels.d.ts.map +0 -1
  55. package/dist/utils/get-execution-levels.js +0 -136
  56. package/dist/utils/get-execution-levels.test.d.ts +0 -2
  57. package/dist/utils/get-execution-levels.test.d.ts.map +0 -1
  58. package/dist/utils/get-execution-levels.test.js +0 -228
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resource_1 = require("../../resource");
4
+ // 创建测试节点
5
+ const createNode = (nodeId, inputSchema, outputSchema, execute) => ({
6
+ id: nodeId,
7
+ propertiesSchema: {
8
+ type: 'object',
9
+ properties: {
10
+ input: inputSchema,
11
+ output: outputSchema
12
+ }
13
+ },
14
+ execute
15
+ });
16
+ // 测试 portId 功能
17
+ test('WorkflowResource execute with portId', async () => {
18
+ // 创建节点
19
+ const startNode = createNode('start', {
20
+ type: 'object',
21
+ properties: {
22
+ value: {
23
+ type: 'string',
24
+ default: 'start'
25
+ }
26
+ }
27
+ }, {
28
+ type: 'object',
29
+ properties: {
30
+ value: {
31
+ type: 'string',
32
+ 'x-expression': 'value'
33
+ }
34
+ }
35
+ }, async ({ variables }) => ({
36
+ variables: { value: variables.value || 'start' }, // 确保输出有 value 字段
37
+ portId: 'port-success' // 返回成功端口
38
+ }));
39
+ const successNode = createNode('success', {
40
+ type: 'object',
41
+ properties: {
42
+ value: {
43
+ type: 'string',
44
+ 'x-expression': `$."start".value`
45
+ }
46
+ }
47
+ }, {
48
+ type: 'object',
49
+ properties: {
50
+ result: {
51
+ type: 'string',
52
+ 'x-expression': 'result'
53
+ }
54
+ }
55
+ }, async ({ variables }) => ({
56
+ variables: { result: `success: ${variables.value}` }
57
+ }));
58
+ const failureNode = createNode('failure', {
59
+ type: 'object',
60
+ properties: {
61
+ value: {
62
+ type: 'string',
63
+ 'x-expression': `$."start".value`
64
+ }
65
+ }
66
+ }, {
67
+ type: 'object',
68
+ properties: {
69
+ result: {
70
+ type: 'string',
71
+ 'x-expression': 'value'
72
+ }
73
+ }
74
+ }, async ({ variables }) => ({
75
+ variables: { result: `failure: ${variables.value}` }
76
+ }));
77
+ const endNode = createNode('end', {
78
+ type: 'object',
79
+ properties: {
80
+ result: {
81
+ type: 'string',
82
+ 'x-expression': '$."success".result'
83
+ }
84
+ }
85
+ }, {
86
+ type: 'object',
87
+ properties: {
88
+ result: {
89
+ type: 'string',
90
+ 'x-expression': 'result'
91
+ }
92
+ }
93
+ }, async ({ variables }) => ({
94
+ variables // 直接返回评估后的变量
95
+ }));
96
+ // 创建工作流数据
97
+ // start -> success -> end (使用 port-success)
98
+ // start -> failure (使用 port-failure, 不会被执行)
99
+ const workflowData = {
100
+ edges: [
101
+ {
102
+ sourceWorkflowNodeResourceId: 'start',
103
+ sourceWorkflowNodePortId: 'port-success',
104
+ targetWorkflowNodeResourceId: 'success'
105
+ },
106
+ {
107
+ sourceWorkflowNodeResourceId: 'start',
108
+ sourceWorkflowNodePortId: 'port-failure',
109
+ targetWorkflowNodeResourceId: 'failure'
110
+ },
111
+ {
112
+ sourceWorkflowNodeResourceId: 'success',
113
+ targetWorkflowNodeResourceId: 'end'
114
+ }
115
+ ],
116
+ nodes: [startNode, successNode, failureNode, endNode]
117
+ };
118
+ const getWorkflowDataRes = {
119
+ workflowData
120
+ };
121
+ class TestWorkflowResource extends resource_1.WorkflowResource {
122
+ constructor() {
123
+ super(...arguments);
124
+ this.getWorkflowData = () => {
125
+ return getWorkflowDataRes;
126
+ };
127
+ }
128
+ }
129
+ const testWorkflowResource = new TestWorkflowResource({
130
+ id: 'test',
131
+ kind: 'workflow',
132
+ parentId: 'root',
133
+ settings: {
134
+ title: '',
135
+ description: '',
136
+ startWorkflowNodeResourceId: 'start',
137
+ endWorkflowNodeResourceId: 'end'
138
+ }
139
+ });
140
+ const { variables } = await testWorkflowResource.execute({
141
+ context: {},
142
+ variables: {}
143
+ });
144
+ // 验证只有 success 分支被执行
145
+ expect(variables.result).toBe('success: start');
146
+ });
147
+ // 测试默认端口(无 portId)
148
+ test('WorkflowResource execute without portId', async () => {
149
+ const startNode = createNode('start', {
150
+ type: 'object',
151
+ properties: {
152
+ value: {
153
+ type: 'string',
154
+ default: 'default'
155
+ }
156
+ }
157
+ }, {
158
+ type: 'object',
159
+ properties: {
160
+ value: {
161
+ type: 'string',
162
+ 'x-expression': 'value'
163
+ }
164
+ }
165
+ }, async ({ variables }) => ({
166
+ variables: { value: variables.value || 'default' }
167
+ // 不返回 portId,使用默认端口
168
+ }));
169
+ const defaultNode = createNode('default', {
170
+ type: 'object',
171
+ properties: {
172
+ value: {
173
+ type: 'string',
174
+ 'x-expression': `$."start".value`
175
+ }
176
+ }
177
+ }, {
178
+ type: 'object',
179
+ properties: {
180
+ result: {
181
+ type: 'string',
182
+ 'x-expression': 'result'
183
+ }
184
+ }
185
+ }, async ({ variables }) => ({
186
+ variables: { result: `default: ${variables.value}` }
187
+ }));
188
+ const specificNode = createNode('specific', {
189
+ type: 'object',
190
+ properties: {
191
+ value: {
192
+ type: 'string',
193
+ 'x-expression': `$."start".value`
194
+ }
195
+ }
196
+ }, {
197
+ type: 'object',
198
+ properties: {
199
+ result: {
200
+ type: 'string',
201
+ 'x-expression': 'result'
202
+ }
203
+ }
204
+ }, async ({ variables }) => ({
205
+ variables: { result: `specific: ${variables.value}` }
206
+ }));
207
+ const endNode = createNode('end', {
208
+ type: 'object',
209
+ properties: {
210
+ result: {
211
+ type: 'string',
212
+ 'x-expression': '$."default".result'
213
+ }
214
+ }
215
+ }, {
216
+ type: 'object',
217
+ properties: {
218
+ result: {
219
+ type: 'string',
220
+ 'x-expression': 'result'
221
+ }
222
+ }
223
+ }, async ({ variables }) => ({
224
+ variables // 直接返回评估后的变量
225
+ }));
226
+ // start -> default -> end (默认端口,无 portId)
227
+ // start -> specific (使用 port-specific, 不会被执行)
228
+ const workflowData = {
229
+ edges: [
230
+ {
231
+ sourceWorkflowNodeResourceId: 'start',
232
+ // 无 sourceWorkflowNodePortId,表示默认端口
233
+ targetWorkflowNodeResourceId: 'default'
234
+ },
235
+ {
236
+ sourceWorkflowNodeResourceId: 'start',
237
+ sourceWorkflowNodePortId: 'port-specific',
238
+ targetWorkflowNodeResourceId: 'specific'
239
+ },
240
+ {
241
+ sourceWorkflowNodeResourceId: 'default',
242
+ targetWorkflowNodeResourceId: 'end'
243
+ }
244
+ ],
245
+ nodes: [startNode, defaultNode, specificNode, endNode]
246
+ };
247
+ const getWorkflowDataRes = {
248
+ workflowData
249
+ };
250
+ class TestWorkflowResource extends resource_1.WorkflowResource {
251
+ constructor() {
252
+ super(...arguments);
253
+ this.getWorkflowData = () => {
254
+ return getWorkflowDataRes;
255
+ };
256
+ }
257
+ }
258
+ const testWorkflowResource = new TestWorkflowResource({
259
+ id: 'test',
260
+ kind: 'workflow',
261
+ parentId: 'root',
262
+ settings: {
263
+ title: '',
264
+ description: '',
265
+ startWorkflowNodeResourceId: 'start',
266
+ endWorkflowNodeResourceId: 'end'
267
+ }
268
+ });
269
+ const { variables } = await testWorkflowResource.execute({
270
+ context: {},
271
+ variables: {}
272
+ });
273
+ // 验证只有默认分支被执行
274
+ expect(variables.result).toBe('default: default');
275
+ });
@@ -1,6 +1,6 @@
1
- import { HandlerSpecificResourceSettings } from "@ldsg/handler";
2
- import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
3
- import { GeneralResourceSettings } from "@ldsg/types";
1
+ import { HandlerSpecificResourceSettings } from '@ldsg/handler';
2
+ import { ResourceDefinitionSpecificResourceSettings } from '@ldsg/resource-definition';
3
+ import { GeneralResourceSettings } from '@ldsg/types';
4
4
  /**
5
5
  * Instantiate Resource Handler General Resource Settings
6
6
  * 实例化资源处理程序普通资源配置
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAIlE,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBAIzD,CAAC;AAEJ,eAAO,MAAM,8CAA8C,EAAE,0CAI1D,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,iEAAiE;;;CAIlE,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iEAAiE;;;CAGpE,CAAC"}
package/dist/constants.js CHANGED
@@ -7,8 +7,8 @@ const constants_1 = require("@ldsg/constants");
7
7
  * 实例化资源处理程序普通资源配置
8
8
  */
9
9
  exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
10
- title: "工作流实例化资源处理程序",
11
- description: "",
10
+ title: '工作流实例化资源处理程序',
11
+ description: ''
12
12
  };
13
13
  /**
14
14
  * Instantiate Resource Handler Specific Resource Settings
@@ -19,22 +19,22 @@ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
19
19
  code: `export * from "@ldsg/workflow";`,
20
20
  dependencies: [
21
21
  {
22
- name: "@ldsg/workflow",
23
- },
24
- ],
22
+ name: '@ldsg/workflow'
23
+ }
24
+ ]
25
25
  };
26
26
  exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
27
- title: "工作流资源定义",
28
- description: "",
27
+ title: '工作流资源定义',
28
+ description: ''
29
29
  };
30
30
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
31
- kind: "workflow",
32
- parentKind: constants_1.ROOT_RESOURCE_KIND,
31
+ kind: 'workflow',
32
+ parentKind: constants_1.ROOT_RESOURCE_KIND
33
33
  };
34
34
  /**
35
35
  * Specific Workflow Node Type Id Map
36
36
  */
37
37
  exports.SPECIFIC_WORKFLOW_NODE_TYPE_TO_WORKFLOW_NODE_TYPE_RESOURCE_ID_MAP = {
38
- start: "start-workflow-node-type",
39
- end: "end-workflow-node-type",
38
+ start: 'start-workflow-node-type',
39
+ end: 'end-workflow-node-type'
40
40
  };
package/dist/handler.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { Handler, HandlerExtendedResourceSettings } from "@ldsg/handler";
2
- import { InstantiateResourceParams, InstantiateResourceRes } from "@ldsg/resource";
3
- import { WorkflowResource } from "./resource";
4
- import { WorkflowSpecificResourceSettings } from "./types";
5
- export declare const handler: Handler<[
6
- InstantiateResourceParams<HandlerExtendedResourceSettings<WorkflowSpecificResourceSettings>>
7
- ], InstantiateResourceRes<WorkflowResource>>;
1
+ import { Handler, HandlerExtendedResourceSettings } from '@ldsg/handler';
2
+ import { InstantiateResourceParams, InstantiateResourceRes } from '@ldsg/resource';
3
+ import { WorkflowResource } from './resource';
4
+ import { WorkflowSpecificResourceSettings } from './types';
5
+ export declare const handler: Handler<InstantiateResourceParams<HandlerExtendedResourceSettings<WorkflowSpecificResourceSettings>>, InstantiateResourceRes<WorkflowResource>>;
8
6
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAC;AAE3D,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B;IACE,yBAAyB,CACvB,+BAA+B,CAAC,gCAAgC,CAAC,CAClE;CACF,EACD,sBAAsB,CAAC,gBAAgB,CAAC,CACnB,CAAC"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAC;AAE3D,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B,yBAAyB,CAAC,+BAA+B,CAAC,gCAAgC,CAAC,CAAC,EAC5F,sBAAsB,CAAC,gBAAgB,CAAC,CACnB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./constants";
2
- export * from "./handler";
3
- export * from "./instantiate-resource";
4
- export * from "./resource";
5
- export * from "./types";
1
+ export * from './constants';
2
+ export * from './handler';
3
+ export * from './instantiate-resource';
4
+ export * from './resource';
5
+ export * from './types';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
- import { HandlerExtendedResourceSettings } from "@ldsg/handler";
2
- import { InstantiateResource } from "@ldsg/resource";
3
- import { WorkflowResource } from "./resource";
4
- import { WorkflowSpecificResourceSettings } from "./types";
1
+ import { HandlerExtendedResourceSettings } from '@ldsg/handler';
2
+ import { InstantiateResource } from '@ldsg/resource';
3
+ import { WorkflowResource } from './resource';
4
+ import { WorkflowSpecificResourceSettings } from './types';
5
5
  export declare const instantiateResource: InstantiateResource<HandlerExtendedResourceSettings<WorkflowSpecificResourceSettings>, WorkflowResource>;
6
6
  //# sourceMappingURL=instantiate-resource.d.ts.map
@@ -6,7 +6,7 @@ const instantiateResource = (params) => {
6
6
  const { resourceConstructorParams } = params;
7
7
  const resource = new resource_1.WorkflowResource(resourceConstructorParams);
8
8
  const res = {
9
- resource,
9
+ resource
10
10
  };
11
11
  return res;
12
12
  };
@@ -1,5 +1,5 @@
1
- import { Resource } from "@ldsg/resource";
2
- import { WorkflowData, WorkflowEdgeInfo, WorkflowExecute, WorkflowInfo, WorkflowNodeInfo, WorkflowSpecificResourceSettings } from "./types";
1
+ import { Resource } from '@ldsg/resource';
2
+ import { WorkflowData, WorkflowEdgeInfo, WorkflowExecute, WorkflowInfo, WorkflowNodeInfo, WorkflowSpecificResourceSettings } from './types';
3
3
  export interface GetWorkflowEdgeInfoListRes {
4
4
  workflowEdgeInfoList: WorkflowEdgeInfo[];
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAGL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EAEf,YAAY,EACZ,gBAAgB,EAChB,gCAAgC,EAGjC,MAAM,SAAS,CAAC;AAIjB,MAAM,WAAW,0BAA0B;IACzC,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;CAC1C;AAED,MAAM,MAAM,uBAAuB,GAAG,MAAM,0BAA0B,CAAC;AAEvE,MAAM,WAAW,0BAA0B;IACzC,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;CAC1C;AAED,MAAM,MAAM,uBAAuB,GAAG,MAAM,0BAA0B,CAAC;AAEvE,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC;AAEvD,qBAAa,gBAAiB,SAAQ,QAAQ,CAAC,gCAAgC,CAAC;IAC9E,uBAAuB,EAAE,uBAAuB,CA4B9C;IAEF,uBAAuB,EAAE,uBAAuB,CAsB9C;IAEF,eAAe,EAAE,eAAe,CAiB9B;IAEF,OAAO,EAAE,eAAe,CAiItB;IAEF,eAAe,EAAE,eAAe,CAY9B;CACH"}
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAGL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,gCAAgC,EACjC,MAAM,SAAS,CAAC;AAGjB,MAAM,WAAW,0BAA0B;IACzC,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;CAC1C;AAED,MAAM,MAAM,uBAAuB,GAAG,MAAM,0BAA0B,CAAC;AAEvE,MAAM,WAAW,0BAA0B;IACzC,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;CAC1C;AAED,MAAM,MAAM,uBAAuB,GAAG,MAAM,0BAA0B,CAAC;AAEvE,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC;AAEvD,qBAAa,gBAAiB,SAAQ,QAAQ,CAAC,gCAAgC,CAAC;IAC9E,uBAAuB,EAAE,uBAAuB,CAsB9C;IAEF,uBAAuB,EAAE,uBAAuB,CAsB9C;IAEF,eAAe,EAAE,eAAe,CAiB9B;IAEF,OAAO,EAAE,eAAe,CAuBtB;IAEF,eAAe,EAAE,eAAe,CAY9B;CACH"}
package/dist/resource.js CHANGED
@@ -6,40 +6,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WorkflowResource = void 0;
7
7
  const resource_1 = require("@ldsg/resource");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
- const evaluate_variables_1 = require("./utils/evaluate-variables");
10
- const get_execution_levels_1 = require("./utils/get-execution-levels");
9
+ const execute_workflow_1 = require("./utils/execute-workflow");
11
10
  class WorkflowResource extends resource_1.Resource {
12
11
  constructor() {
13
12
  super(...arguments);
14
13
  this.getWorkflowEdgeInfoList = () => {
15
14
  const { id, getFilteredResources } = this;
16
15
  const { resources } = getFilteredResources({
17
- parentId: id,
16
+ parentId: id
18
17
  });
19
18
  const mapRes = resources.map((resource) => {
20
19
  var _a;
21
20
  return (_a = resource.getWorkflowEdgeInfo) === null || _a === void 0 ? void 0 : _a.call(resource);
22
21
  });
23
22
  const getWorkflowEdgeInfoResList = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
24
- const workflowEdgeInfoList = lodash_1.default.map(getWorkflowEdgeInfoResList, "workflowEdgeInfo");
23
+ const workflowEdgeInfoList = lodash_1.default.map(getWorkflowEdgeInfoResList, 'workflowEdgeInfo');
25
24
  const res = {
26
- workflowEdgeInfoList,
25
+ workflowEdgeInfoList
27
26
  };
28
27
  return res;
29
28
  };
30
29
  this.getWorkflowNodeInfoList = () => {
31
30
  const { id, getFilteredResources } = this;
32
31
  const { resources } = getFilteredResources({
33
- parentId: id,
32
+ parentId: id
34
33
  });
35
34
  const mapRes = resources.map((resource) => {
36
35
  var _a;
37
36
  return (_a = resource.getWorkflowNodeInfo) === null || _a === void 0 ? void 0 : _a.call(resource);
38
37
  });
39
38
  const filterRes = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
40
- const workflowNodeInfoList = lodash_1.default.map(filterRes, "workflowNodeInfo");
39
+ const workflowNodeInfoList = lodash_1.default.map(filterRes, 'workflowNodeInfo');
41
40
  const res = {
42
- workflowNodeInfoList,
41
+ workflowNodeInfoList
43
42
  };
44
43
  return res;
45
44
  };
@@ -49,96 +48,37 @@ class WorkflowResource extends resource_1.Resource {
49
48
  const { workflowNodeInfoList } = getWorkflowNodeInfoList();
50
49
  const workflowData = {
51
50
  edges: workflowEdgeInfoList,
52
- nodes: workflowNodeInfoList,
51
+ nodes: workflowNodeInfoList
53
52
  };
54
53
  const res = {
55
- workflowData,
54
+ workflowData
56
55
  };
57
56
  return res;
58
57
  };
59
58
  this.execute = async (params) => {
60
- const { presetWorkflowVariables = {}, variables: workflowInputVariables } = params;
61
- const { getWorkflowData, settings: { startWorkflowNodeResourceId, endWorkflowNodeResourceId }, } = this;
62
- const workflowVariablesMap = new Map(Object.entries(presetWorkflowVariables));
59
+ const { context, presetWorkflowVariables, variables, traceContext } = params;
60
+ const { getWorkflowData, settings: { startWorkflowNodeResourceId, endWorkflowNodeResourceId } } = this;
63
61
  const { workflowData } = getWorkflowData();
64
- const { nodes } = workflowData;
65
- const startNode = nodes.find((value) => value.id === startWorkflowNodeResourceId);
66
- const endNode = nodes.find((value) => value.id === endWorkflowNodeResourceId);
67
- if (!startNode || !endNode) {
68
- throw new Error("invalid workflow nodes");
69
- }
70
- const { executionLevels } = (0, get_execution_levels_1.getExecutionLevels)({
62
+ const { nodes, edges } = workflowData;
63
+ return (0, execute_workflow_1.executeWorkflow)({
64
+ context,
65
+ endWorkflowNodeResourceId,
66
+ nodes,
67
+ edges,
68
+ presetWorkflowVariables,
69
+ startWorkflowNodeResourceId,
70
+ variables,
71
71
  workflowData,
72
- startNode,
73
- endNode,
72
+ traceContext
74
73
  });
75
- if (executionLevels.length < 1) {
76
- throw new Error("invalid workflow execution levels");
77
- }
78
- let workflowOutputVariables;
79
- // 按层级执行,同一层级的节点可以并行执行
80
- for (let levelIndex = 0; levelIndex < executionLevels.length; levelIndex++) {
81
- const currentLevel = executionLevels[levelIndex];
82
- // 并行执行当前层级的所有节点
83
- const levelPromises = currentLevel.map(async (node) => {
84
- const { id, propertiesSchema, execute: nodeExecute } = node;
85
- const workflowVariables = Object.fromEntries(workflowVariablesMap);
86
- // 输入变量从工作流变量中使用表达式获取
87
- const workflowNodePropertiesInputSchema = lodash_1.default.get(propertiesSchema, "properties.input");
88
- const workflowNodePropertiesOutputSchema = lodash_1.default.get(propertiesSchema, "properties.output");
89
- if (!lodash_1.default.isObject(workflowNodePropertiesInputSchema) ||
90
- !lodash_1.default.isObject(workflowNodePropertiesOutputSchema)) {
91
- throw new Error("invalid workflow node properties schema");
92
- }
93
- const { variables: workflowNodeInputVariables } = await (0, evaluate_variables_1.evaluateVariables)({
94
- jsonSchema: workflowNodePropertiesInputSchema,
95
- /**
96
- * 对于开始节点,不忽略 input 表达式,但替换工作流内部变量为工作流输入变量。
97
- */
98
- variables: levelIndex === 0 ? workflowInputVariables : workflowVariables,
99
- });
100
- const { variables: workflowNodeOutputExpressionEvaluateInput } = await nodeExecute({
101
- variables: workflowNodeInputVariables,
102
- context: {
103
- workflowResourceInstance: this,
104
- },
105
- });
106
- /**
107
- * 输出变量从结果中使用表达式获取
108
- * 对于结束节点,不忽略 output 表达式,但表达式固定为取返回变量。
109
- */
110
- const { variables: workflowNodeOutputVariables } = await (0, evaluate_variables_1.evaluateVariables)({
111
- jsonSchema: workflowNodePropertiesOutputSchema,
112
- variables: workflowNodeOutputExpressionEvaluateInput,
113
- });
114
- return {
115
- nodeId: id,
116
- variables: workflowNodeOutputVariables,
117
- };
118
- });
119
- // 等待当前层级的所有节点执行完成
120
- const levelResults = await Promise.all(levelPromises);
121
- // 将当前层级的结果更新到工作流变量映射中
122
- levelResults.forEach((result) => {
123
- workflowVariablesMap.set(result.nodeId, result.variables);
124
- // 如果是结束节点,保存输出变量
125
- if (result.nodeId === endNode.id) {
126
- workflowOutputVariables = result.variables;
127
- }
128
- });
129
- }
130
- const res = {
131
- variables: workflowOutputVariables,
132
- };
133
- return res;
134
74
  };
135
75
  this.getWorkflowInfo = () => {
136
76
  const { execute } = this;
137
77
  const workflowInfo = {
138
- execute,
78
+ execute
139
79
  };
140
80
  const res = {
141
- workflowInfo,
81
+ workflowInfo
142
82
  };
143
83
  return res;
144
84
  };
@@ -1,7 +1,7 @@
1
- export * from "./edge";
2
- export * from "./json_schema_with_expression_extension";
3
- export * from "./node";
4
- export * from "./specific-resource-settings";
5
- export * from "./variables";
6
- export * from "./workflow";
1
+ export * from './edge';
2
+ export * from './json_schema_with_expression_extension';
3
+ export * from './node';
4
+ export * from './specific-resource-settings';
5
+ export * from './variables';
6
+ export * from './workflow';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,14 +1,17 @@
1
- import { JSONSchema7 } from "json-schema";
1
+ import { JSONSchema7, JSONSchema7TypeName } from 'json-schema';
2
+ export type JSONSchemaWithExpressionExtensionType = JSONSchema7TypeName | 'any';
2
3
  /**
3
4
  * JSON Schema with Expression Extension
4
5
  */
5
- export interface JSONSchemaWithExpressionExtension extends JSONSchema7 {
6
- "x-expression"?: string;
7
- "x-expression-const"?: string;
8
- "x-expression-default"?: string;
6
+ export interface JSONSchemaWithExpressionExtension extends Omit<JSONSchema7, 'type' | 'items' | 'properties'> {
7
+ type?: JSONSchemaWithExpressionExtensionType;
9
8
  properties?: {
10
9
  [key: string]: JSONSchemaWithExpressionExtension;
11
10
  };
12
- items?: JSONSchemaWithExpressionExtension | JSONSchemaWithExpressionExtension[];
11
+ items?: JSONSchemaWithExpressionExtension;
12
+ prefixItems?: JSONSchemaWithExpressionExtension[];
13
+ 'x-expression'?: string;
14
+ 'x-expression-const'?: string;
15
+ 'x-expression-default'?: string;
13
16
  }
14
17
  //# sourceMappingURL=json_schema_with_expression_extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema_with_expression_extension.d.ts","sourceRoot":"","sources":["../../src/types/json_schema_with_expression_extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,iCAAkC,SAAQ,WAAW;IACpE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC,UAAU,CAAC,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,iCAAiC,CAAC;KAClD,CAAC;IAEF,KAAK,CAAC,EACF,iCAAiC,GACjC,iCAAiC,EAAE,CAAC;CACzC"}
1
+ {"version":3,"file":"json_schema_with_expression_extension.d.ts","sourceRoot":"","sources":["../../src/types/json_schema_with_expression_extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,MAAM,qCAAqC,GAAG,mBAAmB,GAAG,KAAK,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,iCACf,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,CAAC;IAC1D,IAAI,CAAC,EAAE,qCAAqC,CAAC;IAE7C,UAAU,CAAC,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,iCAAiC,CAAC;KAClD,CAAC;IAEF,KAAK,CAAC,EAAE,iCAAiC,CAAC;IAE1C,WAAW,CAAC,EAAE,iCAAiC,EAAE,CAAC;IAElD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC"}