@ldsg/workflow 0.3.32 → 0.3.33
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,96 @@
|
|
|
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 jsonata_1 = __importDefault(require("jsonata"));
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const resolveJsonSchema = async (params) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const { input, jsonSchema, source } = params;
|
|
12
|
+
const { type: jsonSchemaType, 'x-expression': jsonSchemaExpression, const: jsonSchemaConst, prefixItems: jsonSchemaPrefixItems } = jsonSchema;
|
|
13
|
+
let data;
|
|
14
|
+
/**
|
|
15
|
+
* 若常量值存在,则直接返回
|
|
16
|
+
*/
|
|
17
|
+
if (jsonSchemaConst) {
|
|
18
|
+
data = jsonSchemaConst;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
data = source;
|
|
22
|
+
/**
|
|
23
|
+
* 若表达式存在,则尝试获取表达式值
|
|
24
|
+
*/
|
|
25
|
+
if (jsonSchemaExpression) {
|
|
26
|
+
const expression = (0, jsonata_1.default)(jsonSchemaExpression);
|
|
27
|
+
data = await expression.evaluate(input);
|
|
28
|
+
}
|
|
29
|
+
switch (jsonSchemaType) {
|
|
30
|
+
case 'object': {
|
|
31
|
+
data = data !== null && data !== void 0 ? data : {};
|
|
32
|
+
const jsonSchemaProperties = (_a = jsonSchema.properties) !== null && _a !== void 0 ? _a : {};
|
|
33
|
+
const keys = lodash_1.default.keys(jsonSchemaProperties);
|
|
34
|
+
const keysMapResPromises = keys.map(async (key) => {
|
|
35
|
+
const source = lodash_1.default.get(data, key);
|
|
36
|
+
const resolveJsonSchemaRes = await (0, exports.resolveJsonSchema)({
|
|
37
|
+
jsonSchema: jsonSchemaProperties[key],
|
|
38
|
+
input,
|
|
39
|
+
source
|
|
40
|
+
});
|
|
41
|
+
const res = {
|
|
42
|
+
key,
|
|
43
|
+
resolveJsonSchemaRes
|
|
44
|
+
};
|
|
45
|
+
return res;
|
|
46
|
+
});
|
|
47
|
+
const keysMapRes = await Promise.all(keysMapResPromises);
|
|
48
|
+
lodash_1.default.each(keysMapRes, ({ key, resolveJsonSchemaRes }) => {
|
|
49
|
+
lodash_1.default.set(data, key, resolveJsonSchemaRes.data);
|
|
50
|
+
});
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'array': {
|
|
54
|
+
/**
|
|
55
|
+
* 如果 prefixItems 存在,则转为数组结果
|
|
56
|
+
*/
|
|
57
|
+
if (jsonSchemaPrefixItems) {
|
|
58
|
+
if (jsonSchemaPrefixItems.length > 0) {
|
|
59
|
+
const itemsDataPromises = jsonSchemaPrefixItems.map(async (prefixItem) => {
|
|
60
|
+
const resolveJsonSchemaRes = await (0, exports.resolveJsonSchema)({
|
|
61
|
+
jsonSchema: prefixItem,
|
|
62
|
+
input,
|
|
63
|
+
source
|
|
64
|
+
});
|
|
65
|
+
return resolveJsonSchemaRes.data;
|
|
66
|
+
});
|
|
67
|
+
const itemsData = await Promise.all(itemsDataPromises);
|
|
68
|
+
data = itemsData;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
/**
|
|
72
|
+
* 空数组时,初始化为空数组
|
|
73
|
+
*/
|
|
74
|
+
data = [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'boolean':
|
|
80
|
+
case 'integer':
|
|
81
|
+
case 'number':
|
|
82
|
+
case 'string': {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 'null': {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
default: {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const res = { data };
|
|
94
|
+
return res;
|
|
95
|
+
};
|
|
96
|
+
exports.resolveJsonSchema = resolveJsonSchema;
|
|
@@ -1 +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;
|
|
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;AAyND;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6HhG"}
|
|
@@ -29,6 +29,12 @@ function safeStringify(obj) {
|
|
|
29
29
|
async function executeNode(node, context, workflowVariablesMap, isFirstLevel, workflowInputVariables) {
|
|
30
30
|
const { id, propertiesSchema, execute: nodeExecute } = node;
|
|
31
31
|
const workflowVariables = Object.fromEntries(workflowVariablesMap);
|
|
32
|
+
if (process.env.DEBUG) {
|
|
33
|
+
console.debug("executeNode", node.id, {
|
|
34
|
+
isFirstLevel,
|
|
35
|
+
workflowVariablesKeys: Object.keys(workflowVariables),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
32
38
|
// 输入变量从工作流变量中使用表达式获取
|
|
33
39
|
const workflowNodePropertiesInputSchema = lodash_1.default.get(propertiesSchema, "properties.input");
|
|
34
40
|
const workflowNodePropertiesOutputSchema = lodash_1.default.get(propertiesSchema, "properties.output");
|
|
@@ -46,36 +52,58 @@ async function executeNode(node, context, workflowVariablesMap, isFirstLevel, wo
|
|
|
46
52
|
});
|
|
47
53
|
workflowNodeInputVariables = variables;
|
|
48
54
|
}
|
|
49
|
-
const { variables: workflowNodeOutputExpressionEvaluateInput, portId } = await nodeExecute({
|
|
50
|
-
context,
|
|
51
|
-
variables: workflowNodeInputVariables,
|
|
52
|
-
});
|
|
53
|
-
/**
|
|
54
|
-
* 输出变量从结果中使用表达式获取
|
|
55
|
-
* 对于结束节点,不忽略 output 表达式,但表达式固定为取返回变量。
|
|
56
|
-
*/
|
|
57
|
-
let workflowNodeOutputVariables = {};
|
|
58
|
-
if (workflowNodePropertiesOutputSchema) {
|
|
59
|
-
const { variables } = await (0, evaluate_variables_1.evaluateVariables)({
|
|
60
|
-
jsonSchema: workflowNodePropertiesOutputSchema,
|
|
61
|
-
variables: workflowNodeOutputExpressionEvaluateInput,
|
|
62
|
-
});
|
|
63
|
-
workflowNodeOutputVariables = variables;
|
|
64
|
-
}
|
|
65
55
|
if (process.env.DEBUG) {
|
|
66
|
-
console.
|
|
67
|
-
|
|
68
|
-
portId,
|
|
69
|
-
inputVariables: workflowNodeInputVariables,
|
|
70
|
-
outputVariables: workflowNodeOutputVariables,
|
|
71
|
-
});
|
|
56
|
+
console.log(`[EXEC] node ${id} inputExpressionEvaluateInput keys:`, Object.keys(workflowNodeInputExpressionEvaluateInput || {}));
|
|
57
|
+
console.log(`[EXEC] node ${id} inputVariables:`, safeStringify(workflowNodeInputVariables));
|
|
72
58
|
}
|
|
73
|
-
|
|
59
|
+
let consoleDirInfo = {
|
|
74
60
|
nodeId: id,
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
inputVariables: workflowNodeInputVariables,
|
|
62
|
+
status: "processing",
|
|
77
63
|
};
|
|
78
|
-
|
|
64
|
+
try {
|
|
65
|
+
const { variables: workflowNodeOutputExpressionEvaluateInput, portId } = await nodeExecute({
|
|
66
|
+
context,
|
|
67
|
+
variables: workflowNodeInputVariables,
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* 输出变量从结果中使用表达式获取
|
|
71
|
+
* 对于结束节点,不忽略 output 表达式,但表达式固定为取返回变量。
|
|
72
|
+
*/
|
|
73
|
+
let workflowNodeOutputVariables = {};
|
|
74
|
+
if (workflowNodePropertiesOutputSchema) {
|
|
75
|
+
const { variables } = await (0, evaluate_variables_1.evaluateVariables)({
|
|
76
|
+
jsonSchema: workflowNodePropertiesOutputSchema,
|
|
77
|
+
variables: workflowNodeOutputExpressionEvaluateInput,
|
|
78
|
+
});
|
|
79
|
+
workflowNodeOutputVariables = variables;
|
|
80
|
+
}
|
|
81
|
+
consoleDirInfo = {
|
|
82
|
+
...consoleDirInfo,
|
|
83
|
+
status: "success",
|
|
84
|
+
portId,
|
|
85
|
+
outputVariables: workflowNodeOutputVariables,
|
|
86
|
+
};
|
|
87
|
+
const res = {
|
|
88
|
+
nodeId: id,
|
|
89
|
+
variables: workflowNodeOutputVariables,
|
|
90
|
+
portId,
|
|
91
|
+
};
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
consoleDirInfo = {
|
|
96
|
+
...consoleDirInfo,
|
|
97
|
+
status: "error",
|
|
98
|
+
error,
|
|
99
|
+
};
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
if (process.env.DEBUG) {
|
|
104
|
+
console.dir(consoleDirInfo);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
79
107
|
}
|
|
80
108
|
/**
|
|
81
109
|
* 查找下一个需要执行的节点集合
|
|
@@ -205,6 +233,12 @@ async function executeWorkflow(params) {
|
|
|
205
233
|
workflowVariablesMap.set(result.nodeId, result.variables);
|
|
206
234
|
}
|
|
207
235
|
});
|
|
236
|
+
if (process.env.DEBUG) {
|
|
237
|
+
console.debug("executeWorkflow level done", {
|
|
238
|
+
executedNodes: levelResults.filter(Boolean).map((r) => r.nodeId),
|
|
239
|
+
workflowVariablesKeys: [...workflowVariablesMap.keys()],
|
|
240
|
+
});
|
|
241
|
+
}
|
|
208
242
|
// 根据执行结果和 portId 查找下一个节点集合
|
|
209
243
|
const { nextNodeIds, workflowOutputVariables: tempOutputVariables } = findNextNodeIds(levelResults, edges, visitedNodes, completedNodePredecessors, activatedEdges, endNode.id);
|
|
210
244
|
if (tempOutputVariables !== undefined) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/workflow",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "wanxger",
|
|
8
|
-
"main": "dist/index.js",
|
|
9
|
-
"types": "dist",
|
|
10
8
|
"files": [
|
|
11
9
|
"dist/"
|
|
12
10
|
],
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
13
16
|
"dependencies": {
|
|
14
17
|
"@opentelemetry/api": "~1.9.0",
|
|
15
18
|
"json-schema": "0.4.0",
|
|
@@ -17,10 +20,10 @@
|
|
|
17
20
|
"jsonata": "2.2.2",
|
|
18
21
|
"lodash": "^4.17.21",
|
|
19
22
|
"zod": "^4.1.11",
|
|
20
|
-
"@ldsg/constants": "0.3.
|
|
21
|
-
"@ldsg/resource": "0.3.
|
|
22
|
-
"@ldsg/handler": "0.3.
|
|
23
|
-
"@ldsg/resource
|
|
23
|
+
"@ldsg/constants": "0.3.33",
|
|
24
|
+
"@ldsg/resource-definition": "0.3.33",
|
|
25
|
+
"@ldsg/handler": "0.3.33",
|
|
26
|
+
"@ldsg/resource": "0.3.33"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
29
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -35,10 +38,7 @@
|
|
|
35
38
|
"ts-jest": "^29.1.5",
|
|
36
39
|
"ts-node": "^10.9.2",
|
|
37
40
|
"typescript": "^5.8.3",
|
|
38
|
-
"@ldsg/types": "0.3.
|
|
39
|
-
},
|
|
40
|
-
"publishConfig": {
|
|
41
|
-
"access": "public"
|
|
41
|
+
"@ldsg/types": "0.3.33"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc --project tsconfig.build.json",
|