@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 @@
1
+ {"version":3,"file":"execute-workflow.d.ts","sourceRoot":"","sources":["../../src/utils/execute-workflow.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAqBlB,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,GAAG,CAAC;IACb,yBAAyB,EAAE,MAAM,CAAC;IAClC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC5D,2BAA2B,EAAE,MAAM,CAAC;IACpC,SAAS,EAAE,GAAG,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAgKD;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsHhG"}
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.executeWorkflow = executeWorkflow;
7
+ const api_1 = __importDefault(require("@opentelemetry/api"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const evaluate_variables_1 = require("./evaluate-variables");
10
+ const tracer = api_1.default.trace.getTracer('workspace');
11
+ /**
12
+ * 安全的 JSON 序列化,处理循环引用
13
+ */
14
+ function safeStringify(obj) {
15
+ const seen = new WeakSet();
16
+ return JSON.stringify(obj, (key, value) => {
17
+ if (typeof value === 'object' && value !== null) {
18
+ if (seen.has(value)) {
19
+ return '[Circular Reference]';
20
+ }
21
+ seen.add(value);
22
+ }
23
+ return value;
24
+ });
25
+ }
26
+ /**
27
+ * 执行单个工作流节点
28
+ */
29
+ async function executeNode(node, context, workflowVariablesMap, isFirstLevel, workflowInputVariables) {
30
+ const { id, propertiesSchema, execute: nodeExecute } = node;
31
+ const workflowVariables = Object.fromEntries(workflowVariablesMap);
32
+ // 输入变量从工作流变量中使用表达式获取
33
+ const workflowNodePropertiesInputSchema = lodash_1.default.get(propertiesSchema, 'properties.input');
34
+ const workflowNodePropertiesOutputSchema = lodash_1.default.get(propertiesSchema, 'properties.output');
35
+ /**
36
+ * 对于开始节点,不忽略 input 表达式,但替换工作流内部变量为工作流输入变量。
37
+ */
38
+ const workflowNodeInputExpressionEvaluateInput = isFirstLevel ? workflowInputVariables : workflowVariables;
39
+ let workflowNodeInputVariables = {};
40
+ if (workflowNodePropertiesInputSchema) {
41
+ const { variables } = await (0, evaluate_variables_1.evaluateVariables)({
42
+ jsonSchema: workflowNodePropertiesInputSchema,
43
+ variables: workflowNodeInputExpressionEvaluateInput
44
+ });
45
+ workflowNodeInputVariables = variables;
46
+ }
47
+ const { variables: workflowNodeOutputExpressionEvaluateInput, portId } = await nodeExecute({
48
+ context,
49
+ variables: workflowNodeInputVariables
50
+ });
51
+ /**
52
+ * 输出变量从结果中使用表达式获取
53
+ * 对于结束节点,不忽略 output 表达式,但表达式固定为取返回变量。
54
+ */
55
+ let workflowNodeOutputVariables = {};
56
+ if (workflowNodePropertiesOutputSchema) {
57
+ const { variables } = await (0, evaluate_variables_1.evaluateVariables)({
58
+ jsonSchema: workflowNodePropertiesOutputSchema,
59
+ variables: workflowNodeOutputExpressionEvaluateInput
60
+ });
61
+ workflowNodeOutputVariables = variables;
62
+ }
63
+ return {
64
+ nodeId: id,
65
+ variables: workflowNodeOutputVariables,
66
+ portId
67
+ };
68
+ }
69
+ /**
70
+ * 查找下一个需要执行的节点集合
71
+ */
72
+ function findNextNodeIds(levelResults, edges, visitedNodes, completedNodePredecessors, activatedEdges, endNodeId) {
73
+ const nextNodeIds = [];
74
+ const nextLevelNodesSet = new Set();
75
+ let workflowOutputVariables;
76
+ levelResults.forEach((result) => {
77
+ if (!result) {
78
+ return;
79
+ }
80
+ const { nodeId, variables, portId } = result;
81
+ // 标记节点为已访问
82
+ visitedNodes.add(nodeId);
83
+ // 保存变量
84
+ // workflowVariablesMap.set(nodeId, variables);
85
+ // 如果是结束节点,保存输出变量
86
+ if (nodeId === endNodeId) {
87
+ workflowOutputVariables = variables;
88
+ }
89
+ // 查找从当前节点出发的连线
90
+ const outgoingEdges = edges.filter((edge) => edge.sourceWorkflowNodeResourceId === nodeId);
91
+ // 根据 portId 过滤连线
92
+ const matchedEdges = portId
93
+ ? outgoingEdges.filter((edge) => edge.sourceWorkflowNodePortId === portId)
94
+ : outgoingEdges.filter((edge) => !edge.sourceWorkflowNodePortId);
95
+ // 处理匹配的连线的目标节点
96
+ matchedEdges.forEach((edge) => {
97
+ const targetNodeId = edge.targetWorkflowNodeResourceId;
98
+ // 如果目标节点已访问,跳过
99
+ if (visitedNodes.has(targetNodeId)) {
100
+ return;
101
+ }
102
+ // 记录该目标节点已完成的前驱节点
103
+ if (!completedNodePredecessors.has(targetNodeId)) {
104
+ completedNodePredecessors.set(targetNodeId, new Set());
105
+ }
106
+ completedNodePredecessors.get(targetNodeId).add(nodeId);
107
+ // 记录激活的边(源节点 -> 目标节点)
108
+ if (!activatedEdges.has(targetNodeId)) {
109
+ activatedEdges.set(targetNodeId, new Set());
110
+ }
111
+ activatedEdges.get(targetNodeId).add(nodeId);
112
+ // 查找目标节点的所有可能的入边(用于计算需要等待多少个前驱节点)
113
+ const incomingEdges = edges.filter((edge) => edge.targetWorkflowNodeResourceId === targetNodeId);
114
+ // 计算实际需要等待的前驱节点数量
115
+ // 对于每个前驱节点,检查是否有至少一条激活的入边
116
+ const allPredecessorIds = new Set(incomingEdges.map((edge) => edge.sourceWorkflowNodeResourceId));
117
+ let requiredPredecessorCount = 0;
118
+ allPredecessorIds.forEach((predecessorId) => {
119
+ // 检查该前驱节点是否有激活的入边指向当前节点
120
+ const hasActivatedEdge = incomingEdges.some((e) => {
121
+ var _a;
122
+ return e.sourceWorkflowNodeResourceId === predecessorId &&
123
+ ((_a = activatedEdges.get(targetNodeId)) === null || _a === void 0 ? void 0 : _a.has(predecessorId));
124
+ });
125
+ if (hasActivatedEdge) {
126
+ requiredPredecessorCount++;
127
+ }
128
+ });
129
+ // 只有当所有需要等待的前驱节点都完成时,才加入下一轮执行
130
+ const completedPredecessors = completedNodePredecessors.get(targetNodeId);
131
+ if (completedPredecessors.size === requiredPredecessorCount) {
132
+ // 避免重复添加同一个节点到下一层
133
+ if (!nextLevelNodesSet.has(targetNodeId)) {
134
+ nextLevelNodesSet.add(targetNodeId);
135
+ nextNodeIds.push(targetNodeId);
136
+ }
137
+ }
138
+ });
139
+ });
140
+ return { nextNodeIds, workflowOutputVariables };
141
+ }
142
+ /**
143
+ * 执行工作流
144
+ */
145
+ async function executeWorkflow(params) {
146
+ const { context, endWorkflowNodeResourceId, nodes, edges, presetWorkflowVariables = {}, startWorkflowNodeResourceId, variables: workflowInputVariables, traceContext } = params;
147
+ // 使用传入的 traceContext 或当前活跃的 context 来创建 span
148
+ const parentContext = traceContext || api_1.default.context.active();
149
+ const executeWorkflowSpan = tracer.startSpan('execute-workflow', undefined, parentContext);
150
+ const workflowVariablesMap = new Map(Object.entries(presetWorkflowVariables));
151
+ const startNode = nodes.find((value) => value.id === startWorkflowNodeResourceId);
152
+ const endNode = nodes.find((value) => value.id === endWorkflowNodeResourceId);
153
+ if (!startNode || !endNode) {
154
+ throw new Error('invalid workflow nodes');
155
+ }
156
+ let workflowOutputVariables;
157
+ // 使用动态执行,根据 portId 决定下一步执行哪些节点
158
+ let currentNodeIds = [startNode.id];
159
+ const visitedNodes = new Set();
160
+ const completedNodePredecessors = new Map();
161
+ // 记录每个节点被激活的入边(源节点ID -> 目标节点ID的集合)
162
+ const activatedEdges = new Map();
163
+ let isFirstLevel = true;
164
+ while (currentNodeIds.length > 0) {
165
+ // 去重当前节点集合(避免重复执行)
166
+ const uniqueNodeIds = [...new Set(currentNodeIds)];
167
+ // 并行执行当前节点集合
168
+ const levelPromises = uniqueNodeIds.map(async (nodeId) => {
169
+ // 跳过已访问的节点(避免循环执行)
170
+ if (visitedNodes.has(nodeId)) {
171
+ return null;
172
+ }
173
+ const ctx = api_1.default.trace.setSpan(parentContext, executeWorkflowSpan);
174
+ const span = tracer.startSpan(nodeId, undefined, ctx);
175
+ const node = nodes.find((value) => value.id === nodeId);
176
+ if (!node) {
177
+ throw new Error(`node not found: ${nodeId}`);
178
+ }
179
+ span.addEvent('execution workflow node');
180
+ const res = await executeNode(node, context, workflowVariablesMap, isFirstLevel, workflowInputVariables);
181
+ const { portId: outputPortId } = res;
182
+ span.setAttributes({
183
+ currentNodeId: nodeId,
184
+ outputPortId
185
+ });
186
+ span.end();
187
+ return res;
188
+ });
189
+ // 等待当前节点集合执行完成,如果任何节点失败则抛出异常
190
+ const levelResults = await Promise.all(levelPromises);
191
+ // 保存执行结果中的变量到 workflowVariablesMap
192
+ levelResults.forEach((result) => {
193
+ if (result) {
194
+ workflowVariablesMap.set(result.nodeId, result.variables);
195
+ }
196
+ });
197
+ // 根据执行结果和 portId 查找下一个节点集合
198
+ const { nextNodeIds, workflowOutputVariables: tempOutputVariables } = findNextNodeIds(levelResults, edges, visitedNodes, completedNodePredecessors, activatedEdges, endNode.id);
199
+ if (tempOutputVariables !== undefined) {
200
+ workflowOutputVariables = tempOutputVariables;
201
+ }
202
+ // 更新当前节点集合
203
+ currentNodeIds = nextNodeIds;
204
+ // 标记已过第一轮执行
205
+ isFirstLevel = false;
206
+ }
207
+ const res = {
208
+ variables: workflowOutputVariables
209
+ };
210
+ executeWorkflowSpan.end();
211
+ return res;
212
+ }
package/package.json CHANGED
@@ -1,34 +1,45 @@
1
1
  {
2
2
  "name": "@ldsg/workflow",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "author": "wanxger",
5
8
  "main": "dist/index.js",
9
+ "types": "dist",
6
10
  "files": [
7
11
  "dist/"
8
12
  ],
9
- "types": "dist",
10
- "keywords": [],
11
- "author": "wanxger",
12
- "license": "MIT",
13
- "publishConfig": {
14
- "access": "public"
15
- },
16
13
  "dependencies": {
14
+ "@opentelemetry/api": "~1.9.0",
17
15
  "json-schema": "0.4.0",
18
16
  "json-schema-default": "^1.0.2",
17
+ "jsonata": "^2.0.6",
19
18
  "lodash": "^4.17.21",
20
- "@ldsg/handler": "0.3.9",
21
- "@ldsg/resource": "0.3.9",
22
- "@ldsg/resource-definition": "0.3.9"
19
+ "@ldsg/constants": "0.3.10",
20
+ "@ldsg/handler": "0.3.10",
21
+ "@ldsg/resource": "0.3.10",
22
+ "@ldsg/resource-definition": "0.3.10"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/flat": "^5.0.5",
25
+ "@types/fs-extra": "^11.0.4",
26
+ "@types/jest": "^29.5.2",
26
27
  "@types/json-schema": "^7.0.15",
27
28
  "@types/lodash": "^4.14.202",
28
- "@ldsg/types": "0.3.9"
29
+ "fs-extra": "^11.3.0",
30
+ "jest": "^29.5.0",
31
+ "supertest": "^6.3.4",
32
+ "ts-jest": "^29.1.5",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.8.3",
35
+ "@ldsg/types": "0.3.10"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
29
39
  },
30
40
  "scripts": {
31
41
  "build": "tsc --project tsconfig.build.json",
32
- "clean": "rm -rf dist"
42
+ "clean": "rm -rf dist",
43
+ "test": "jest"
33
44
  }
34
45
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/index.test.ts"],"names":[],"mappings":""}
@@ -1,219 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- const input = {
5
- Account: {
6
- "Account Name": "Firefly",
7
- Order: [
8
- {
9
- OrderID: "order103",
10
- Product: [
11
- {
12
- "Product Name": "Bowler Hat",
13
- ProductID: 858383,
14
- SKU: "0406654608",
15
- Description: {
16
- Colour: "Purple",
17
- Width: 300,
18
- Height: 200,
19
- Depth: 210,
20
- Weight: 0.75,
21
- },
22
- Price: 34.45,
23
- Quantity: 2,
24
- },
25
- {
26
- "Product Name": "Trilby hat",
27
- ProductID: 858236,
28
- SKU: "0406634348",
29
- Description: {
30
- Colour: "Orange",
31
- Width: 300,
32
- Height: 200,
33
- Depth: 210,
34
- Weight: 0.6,
35
- },
36
- Price: 21.67,
37
- Quantity: 1,
38
- },
39
- ],
40
- },
41
- {
42
- OrderID: "order104",
43
- Product: [
44
- {
45
- "Product Name": "Bowler Hat",
46
- ProductID: 858383,
47
- SKU: "040657863",
48
- Description: {
49
- Colour: "Purple",
50
- Width: 300,
51
- Height: 200,
52
- Depth: 210,
53
- Weight: 0.75,
54
- },
55
- Price: 34.45,
56
- Quantity: 4,
57
- },
58
- {
59
- ProductID: 345664,
60
- SKU: "0406654603",
61
- "Product Name": "Cloak",
62
- Description: {
63
- Colour: "Black",
64
- Width: 30,
65
- Height: 20,
66
- Depth: 210,
67
- Weight: 2,
68
- },
69
- Price: 107.99,
70
- Quantity: 1,
71
- },
72
- ],
73
- },
74
- ],
75
- },
76
- };
77
- const subJsonSchema = {
78
- type: "object",
79
- properties: {
80
- CurrentAccount: {
81
- type: "string",
82
- /**
83
- * 从默认值内取值
84
- */
85
- default: "Current Account",
86
- const: "Current Account",
87
- },
88
- type: {
89
- type: "string",
90
- default: "order",
91
- },
92
- AccountName: {
93
- type: "string",
94
- /**
95
- * 根据 jsonata 取值
96
- */
97
- "x-expression": `Account."Account Name"`,
98
- },
99
- CurrentOrder: {
100
- type: "string",
101
- /**
102
- * 根据 jsonata 取值
103
- */
104
- "x-expression": `"Current Order"`,
105
- },
106
- OrderPrice: {
107
- type: "number",
108
- "x-expression": "$sum(Account.Order.Product.(Price * Quantity))",
109
- },
110
- ProductIds: {
111
- type: "array",
112
- items: {
113
- type: "number",
114
- },
115
- "x-expression": "Account.Order.Product.ProductID",
116
- },
117
- ordersWithProductIds: {
118
- type: "array",
119
- title: "具有产品 ID 的订单列表",
120
- items: {
121
- type: "object",
122
- properties: {
123
- CurrentOrdersWithProductIdsTitle: {
124
- type: "string",
125
- /**
126
- * 从默认值内取值
127
- */
128
- default: "CurrentOrdersWithProductIdsTitle",
129
- const: "CurrentOrdersWithProductIdsTitle",
130
- },
131
- productIds: {
132
- type: "array",
133
- items: {
134
- type: "number",
135
- },
136
- "x-expression": "$v.Product.ProductID",
137
- },
138
- AccountName: {
139
- type: "string",
140
- /**
141
- * 根据 jsonata 取值
142
- */
143
- "x-expression": `Account."Account Name"`,
144
- },
145
- orderId: {
146
- type: "string",
147
- "x-expression": "$v.OrderID",
148
- },
149
- },
150
- },
151
- "x-expression": "$map($.Account.Order, function($v, $i, $a) {{}})",
152
- },
153
- },
154
- };
155
- const jsonSchema = {
156
- type: "object",
157
- properties: {
158
- ...subJsonSchema.properties,
159
- nestd: {
160
- type: "object",
161
- properties: {
162
- ...subJsonSchema.properties,
163
- nestd: {
164
- type: "object",
165
- properties: {
166
- ...subJsonSchema.properties,
167
- nestd: {
168
- type: "object",
169
- properties: {
170
- ...subJsonSchema.properties,
171
- },
172
- },
173
- },
174
- },
175
- },
176
- },
177
- },
178
- };
179
- test("evaluate variables", async () => {
180
- const evaluateVariablesRes = await (0, _1.evaluateVariables)({
181
- jsonSchema,
182
- variables: input,
183
- });
184
- const expectedObject = {
185
- variables: {
186
- CurrentAccount: "Current Account",
187
- type: "order",
188
- AccountName: "Firefly",
189
- CurrentOrder: "Current Order",
190
- OrderPrice: 336.36,
191
- ProductIds: [858383, 858236, 858383, 345664],
192
- nestd: {
193
- CurrentAccount: "Current Account",
194
- type: "order",
195
- AccountName: "Firefly",
196
- CurrentOrder: "Current Order",
197
- OrderPrice: 336.36,
198
- ProductIds: [858383, 858236, 858383, 345664],
199
- nestd: {
200
- CurrentAccount: "Current Account",
201
- type: "order",
202
- AccountName: "Firefly",
203
- CurrentOrder: "Current Order",
204
- OrderPrice: 336.36,
205
- ProductIds: [858383, 858236, 858383, 345664],
206
- nestd: {
207
- CurrentAccount: "Current Account",
208
- type: "order",
209
- AccountName: "Firefly",
210
- CurrentOrder: "Current Order",
211
- OrderPrice: 336.36,
212
- ProductIds: [858383, 858236, 858383, 345664],
213
- },
214
- },
215
- },
216
- },
217
- };
218
- expect(evaluateVariablesRes).toMatchObject(expectedObject);
219
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-json-schema.d.ts","sourceRoot":"","sources":["../../../../src/utils/evaluate-variables/utils/resolve-json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAC;AAO/D,UAAU,uBAAuB;IAC/B,UAAU,EAAE,WAAW,CAAC;IAExB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,UAAU,oBAAoB;IAC5B,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ,IAAI,CAAC,EAAE,GAAG,CAAC;IAEX,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB;AAED,KAAK,iBAAiB,GAAG,CACvB,MAAM,EAAE,uBAAuB,KAC5B,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnC,eAAO,MAAM,iBAAiB,EAAE,iBAkK/B,CAAC"}
@@ -1,112 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveJsonSchema = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const constants_1 = require("../constants");
9
- const resolveJsonSchema = async (params) => {
10
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11
- const { input, jsonSchema, returnExpressionAsData } = params;
12
- const { type } = jsonSchema;
13
- const res = {};
14
- switch (type) {
15
- case "object": {
16
- const properties = lodash_1.default.get(jsonSchema, "properties");
17
- const promises = lodash_1.default.keys(properties).map(async (propertyKey) => {
18
- const propertyValue = lodash_1.default.get(properties, propertyKey);
19
- if (!lodash_1.default.isObject(propertyValue)) {
20
- return;
21
- }
22
- const resolveJsonSchemaRes = await (0, exports.resolveJsonSchema)({
23
- jsonSchema: propertyValue,
24
- input,
25
- returnExpressionAsData,
26
- });
27
- lodash_1.default.set(res, `data.${propertyKey}`, resolveJsonSchemaRes.data);
28
- lodash_1.default.set(res, `const.${propertyKey}`, resolveJsonSchemaRes.const);
29
- lodash_1.default.set(res, `default.${propertyKey}`, resolveJsonSchemaRes.default);
30
- lodash_1.default.set(res, `expression.${propertyKey}`, resolveJsonSchemaRes.expression);
31
- });
32
- await Promise.all(promises);
33
- break;
34
- }
35
- case "array": {
36
- const itemsType = (_a = jsonSchema.items) === null || _a === void 0 ? void 0 : _a.type;
37
- let objectExpression;
38
- if (itemsType === "object") {
39
- const resolveJsonSchemaRes = await (0, exports.resolveJsonSchema)({
40
- jsonSchema: jsonSchema.items,
41
- input,
42
- returnExpressionAsData: true,
43
- });
44
- const expressionSubstrings = [];
45
- lodash_1.default.each(resolveJsonSchemaRes.expression, (value, key) => {
46
- if (value) {
47
- expressionSubstrings.push(`"${key}": ${value}`);
48
- }
49
- });
50
- objectExpression = `{${expressionSubstrings.join(",")}}`;
51
- }
52
- const promises = constants_1.FIELD_VALUE_RETRIEVAL_METHODS.map(async (fieldValueRetrievalMethod) => {
53
- const { name, handle } = fieldValueRetrievalMethod;
54
- /**
55
- * 字段的真实 path 是 key 去除类型
56
- */
57
- const value = lodash_1.default.get(jsonSchema, name);
58
- let res;
59
- if (!lodash_1.default.isNil(value)) {
60
- res = await handle({
61
- input,
62
- retrievalMethodValue: value,
63
- objectExpression,
64
- returnExpressionAsData,
65
- });
66
- }
67
- return res;
68
- });
69
- const fieldValues = await Promise.all(promises);
70
- res.const = (_b = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.const))) === null || _b === void 0 ? void 0 : _b.const;
71
- res.data = (_c = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.data))) === null || _c === void 0 ? void 0 : _c.data;
72
- res.default = (_d = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.default))) === null || _d === void 0 ? void 0 : _d.default;
73
- res.expression = (_e = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.expression))) === null || _e === void 0 ? void 0 : _e.expression;
74
- break;
75
- }
76
- case "boolean":
77
- case "integer":
78
- case "number":
79
- case "string": {
80
- const promises = constants_1.FIELD_VALUE_RETRIEVAL_METHODS.map(async (fieldValueRetrievalMethod) => {
81
- const { name, handle } = fieldValueRetrievalMethod;
82
- /**
83
- * 字段的真实 path 是 key 去除类型
84
- */
85
- const value = lodash_1.default.get(jsonSchema, name);
86
- let res;
87
- if (!lodash_1.default.isNil(value)) {
88
- res = await handle({
89
- input,
90
- retrievalMethodValue: value,
91
- returnExpressionAsData,
92
- });
93
- }
94
- return res;
95
- });
96
- const fieldValues = await Promise.all(promises);
97
- res.const = (_f = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.const))) === null || _f === void 0 ? void 0 : _f.const;
98
- res.data = (_g = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.data))) === null || _g === void 0 ? void 0 : _g.data;
99
- res.default = (_h = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.default))) === null || _h === void 0 ? void 0 : _h.default;
100
- res.expression = (_j = fieldValues.find((value) => !lodash_1.default.isNil(value === null || value === void 0 ? void 0 : value.expression))) === null || _j === void 0 ? void 0 : _j.expression;
101
- break;
102
- }
103
- case "null": {
104
- break;
105
- }
106
- default: {
107
- throw new Error("invalid field type");
108
- }
109
- }
110
- return res;
111
- };
112
- exports.resolveJsonSchema = resolveJsonSchema;
@@ -1,17 +0,0 @@
1
- import { WorkflowData, WorkflowNodeInfo } from "../types";
2
- interface GetExecutionLevelsParams {
3
- workflowData: WorkflowData;
4
- startNode: WorkflowNodeInfo;
5
- endNode: WorkflowNodeInfo;
6
- }
7
- interface GetExecutionLevelsRes {
8
- executionLevels: WorkflowNodeInfo[][];
9
- }
10
- /**
11
- * 获取执行层级列表,用于并行执行
12
- * 根据节点依赖关系构建执行层级,同一层级的节点可以并行执行
13
- * 例如:连线如 1-2、1-3、2-4、3-4、4-5 时,需要 2、3 均执行完成后才执行 4
14
- */
15
- export declare const getExecutionLevels: (params: GetExecutionLevelsParams) => GetExecutionLevelsRes;
16
- export {};
17
- //# sourceMappingURL=get-execution-levels.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-execution-levels.d.ts","sourceRoot":"","sources":["../../src/utils/get-execution-levels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE1D,UAAU,wBAAwB;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,UAAU,qBAAqB;IAC7B,eAAe,EAAE,gBAAgB,EAAE,EAAE,CAAC;CACvC;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,wBAAwB,KAC/B,qBAuJF,CAAC"}