@ldsg/workflow 0.3.9 → 0.3.10
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/dist/__tests__/unit/resource.js +62 -61
- package/dist/constants.d.ts +3 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +11 -11
- package/dist/handler.d.ts +5 -7
- package/dist/handler.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/instantiate-resource.d.ts +4 -4
- package/dist/instantiate-resource.js +1 -1
- package/dist/resource.d.ts +2 -2
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +30 -30
- package/dist/types/index.d.ts +6 -6
- package/dist/types/json_schema_with_expression_extension.d.ts +8 -6
- package/dist/types/json_schema_with_expression_extension.d.ts.map +1 -1
- package/dist/types/node.d.ts +11 -11
- package/dist/types/node.d.ts.map +1 -1
- package/dist/types/specific-resource-settings.d.ts +1 -1
- package/dist/types/specific-resource-settings.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +7 -3
- package/dist/types/workflow.d.ts.map +1 -1
- package/dist/utils/evaluate-variables/constants.d.ts.map +1 -1
- package/dist/utils/evaluate-variables/constants.js +17 -17
- package/dist/utils/evaluate-variables/index.d.ts +2 -2
- package/dist/utils/evaluate-variables/index.d.ts.map +1 -1
- package/dist/utils/evaluate-variables/index.debug.d.ts +2 -0
- package/dist/utils/evaluate-variables/index.debug.d.ts.map +1 -0
- package/dist/utils/evaluate-variables/index.debug.js +194 -0
- package/dist/utils/evaluate-variables/index.js +5 -5
- package/dist/utils/evaluate-variables/index.test.js +98 -98
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.d.ts +21 -0
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.d.ts.map +1 -0
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.js +17 -0
- 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
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.d.ts.map +1 -0
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.js +73 -0
- package/dist/utils/evaluate-variables/utils/get-field-path-by-field-type-key.d.ts.map +1 -1
- package/dist/utils/evaluate-variables/utils/get-field-path-by-field-type-key.js +3 -3
- package/dist/utils/get-execution-levels.d.ts +1 -1
- package/dist/utils/get-execution-levels.d.ts.map +1 -1
- package/dist/utils/get-execution-levels.js +5 -5
- package/dist/utils/get-execution-levels.test.js +86 -86
- package/package.json +22 -13
- package/dist/utils/evaluate-variables/utils/resolve-json-schema.d.ts.map +0 -1
- package/dist/utils/evaluate-variables/utils/resolve-json-schema.js +0 -112
package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,mBAAmB,CAAC;AAGtE,UAAU,mCAAmC;IAC3C;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,iCAAiC,CAAC;CAC/C;AAED,UAAU,gCAAgC;IACxC;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED,KAAK,6BAA6B,GAAG,CACnC,MAAM,EAAE,mCAAmC,KACxC,OAAO,CAAC,gCAAgC,CAAC,CAAC;AAE/C,eAAO,MAAM,6BAA6B,EAAE,6BAc3C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDataWithJsonSchemaAndInput = void 0;
|
|
4
|
+
const resolve_json_schema_1 = require("./resolve-json-schema");
|
|
5
|
+
const getDataWithJsonSchemaAndInput = async (params) => {
|
|
6
|
+
const { input, jsonSchema } = params;
|
|
7
|
+
const { data } = await (0, resolve_json_schema_1.resolveJsonSchema)({
|
|
8
|
+
input,
|
|
9
|
+
jsonSchema,
|
|
10
|
+
source: {}
|
|
11
|
+
});
|
|
12
|
+
const res = {
|
|
13
|
+
data
|
|
14
|
+
};
|
|
15
|
+
return res;
|
|
16
|
+
};
|
|
17
|
+
exports.getDataWithJsonSchemaAndInput = getDataWithJsonSchemaAndInput;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JSONSchemaWithExpressionExtension } from '../../../../types';
|
|
2
2
|
interface ResolveJsonSchemaParams {
|
|
3
|
-
jsonSchema: JSONSchema7;
|
|
4
3
|
/**
|
|
5
4
|
* 输入
|
|
6
5
|
*/
|
|
7
6
|
input: any;
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
8
|
+
* json schema
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
jsonSchema: JSONSchemaWithExpressionExtension;
|
|
11
|
+
/**
|
|
12
|
+
* 源数据,即上级数据
|
|
13
|
+
*/
|
|
14
|
+
source?: any;
|
|
12
15
|
}
|
|
13
16
|
interface ResolveJsonSchemaRes {
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 数据
|
|
19
|
+
*/
|
|
15
20
|
data?: any;
|
|
16
|
-
default?: any;
|
|
17
|
-
expression?: any;
|
|
18
21
|
}
|
|
19
22
|
type ResolveJsonSchema = (params: ResolveJsonSchemaParams) => Promise<ResolveJsonSchemaRes>;
|
|
20
23
|
export declare const resolveJsonSchema: ResolveJsonSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-json-schema.d.ts","sourceRoot":"","sources":["../../../../../src/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iCAAiC,EAAE,MAAM,mBAAmB,CAAC;AAEtE,UAAU,uBAAuB;IAC/B;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,iCAAiC,CAAC;IAE9C;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,UAAU,oBAAoB;IAC5B;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED,KAAK,iBAAiB,GAAG,CAAC,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAE5F,eAAO,MAAM,iBAAiB,EAAE,iBAkF/B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
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 } = 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
|
+
throw new Error('unsupported array type');
|
|
55
|
+
}
|
|
56
|
+
case 'boolean':
|
|
57
|
+
case 'integer':
|
|
58
|
+
case 'number':
|
|
59
|
+
case 'string': {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case 'null': {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
default: {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const res = { data };
|
|
71
|
+
return res;
|
|
72
|
+
};
|
|
73
|
+
exports.resolveJsonSchema = resolveJsonSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-field-path-by-field-type-key.d.ts","sourceRoot":"","sources":["../../../../src/utils/evaluate-variables/utils/get-field-path-by-field-type-key.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,GAAI,cAAc,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"get-field-path-by-field-type-key.d.ts","sourceRoot":"","sources":["../../../../src/utils/evaluate-variables/utils/get-field-path-by-field-type-key.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,GAAI,cAAc,MAAM,KAAG,MAejE,CAAC"}
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFieldPathByFieldTypeKey = void 0;
|
|
4
4
|
const getFieldPathByFieldTypeKey = (fieldTypeKey) => {
|
|
5
5
|
// 将字符串按点分割成数组
|
|
6
|
-
const splitRes = fieldTypeKey.split(
|
|
6
|
+
const splitRes = fieldTypeKey.split('.');
|
|
7
7
|
// 过滤数组:除了索引为复数且值为 properties ,其他所有元素均保留
|
|
8
8
|
const filterRes = splitRes.filter((value, index) => {
|
|
9
|
-
const res = !(value ===
|
|
9
|
+
const res = !(value === 'properties' && index % 2 === 0);
|
|
10
10
|
return res;
|
|
11
11
|
});
|
|
12
12
|
// 将过滤后的数组重新用点连接成字符串
|
|
13
|
-
const res = filterRes.join(
|
|
13
|
+
const res = filterRes.join('.');
|
|
14
14
|
return res;
|
|
15
15
|
};
|
|
16
16
|
exports.getFieldPathByFieldTypeKey = getFieldPathByFieldTypeKey;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,GAAI,QAAQ,wBAAwB,KAAG,qBAuJrE,CAAC"}
|
|
@@ -61,7 +61,7 @@ const getExecutionLevels = (params) => {
|
|
|
61
61
|
// 检查所有节点是否存在循环依赖
|
|
62
62
|
for (const nodeId of dependencies.keys()) {
|
|
63
63
|
if (hasCycle(nodeId)) {
|
|
64
|
-
throw new Error(
|
|
64
|
+
throw new Error('Circular dependency detected in workflow');
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
// 复制依赖关系到剩余依赖映射
|
|
@@ -93,7 +93,7 @@ const getExecutionLevels = (params) => {
|
|
|
93
93
|
});
|
|
94
94
|
// 如果没有找到可以执行的节点,说明存在循环依赖
|
|
95
95
|
if (currentLevel.length === 0) {
|
|
96
|
-
throw new Error(
|
|
96
|
+
throw new Error('Circular dependency detected in workflow');
|
|
97
97
|
}
|
|
98
98
|
executionLevels.push(currentLevel);
|
|
99
99
|
// 标记当前层级的节点为已完成
|
|
@@ -113,12 +113,12 @@ const getExecutionLevels = (params) => {
|
|
|
113
113
|
// 确保结束节点在最后一层
|
|
114
114
|
if (executionLevels.length > 0) {
|
|
115
115
|
const lastLevel = executionLevels[executionLevels.length - 1];
|
|
116
|
-
const endNodeInLastLevel = lastLevel.some(node => node.id === endNode.id);
|
|
116
|
+
const endNodeInLastLevel = lastLevel.some((node) => node.id === endNode.id);
|
|
117
117
|
if (!endNodeInLastLevel) {
|
|
118
118
|
// 如果结束节点不在最后一层,需要检查是否已经在某一层中
|
|
119
119
|
let endNodeFound = false;
|
|
120
120
|
for (const level of executionLevels) {
|
|
121
|
-
if (level.some(node => node.id === endNode.id)) {
|
|
121
|
+
if (level.some((node) => node.id === endNode.id)) {
|
|
122
122
|
endNodeFound = true;
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
@@ -130,7 +130,7 @@ const getExecutionLevels = (params) => {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
return {
|
|
133
|
-
executionLevels
|
|
133
|
+
executionLevels
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
exports.getExecutionLevels = getExecutionLevels;
|
|
@@ -5,16 +5,16 @@ const get_execution_levels_1 = require("./get-execution-levels");
|
|
|
5
5
|
const createTestNode = (id) => ({
|
|
6
6
|
id,
|
|
7
7
|
propertiesSchema: {
|
|
8
|
-
type:
|
|
8
|
+
type: 'object',
|
|
9
9
|
properties: {
|
|
10
|
-
input: { type:
|
|
11
|
-
output: { type:
|
|
12
|
-
}
|
|
10
|
+
input: { type: 'object' },
|
|
11
|
+
output: { type: 'object' }
|
|
12
|
+
}
|
|
13
13
|
},
|
|
14
|
-
execute: async () => ({ variables: {} })
|
|
14
|
+
execute: async () => ({ variables: {} })
|
|
15
15
|
});
|
|
16
|
-
describe(
|
|
17
|
-
test(
|
|
16
|
+
describe('getExecutionLevels', () => {
|
|
17
|
+
test('should create correct execution levels for parallel workflow', () => {
|
|
18
18
|
// 测试场景:1-2, 1-3, 2-4, 3-4, 4-5
|
|
19
19
|
// 期望的层级:
|
|
20
20
|
// Level 0: [1]
|
|
@@ -22,86 +22,86 @@ describe("getExecutionLevels", () => {
|
|
|
22
22
|
// Level 2: [4] (需要2,3都完成)
|
|
23
23
|
// Level 3: [5]
|
|
24
24
|
const nodes = [
|
|
25
|
-
createTestNode(
|
|
26
|
-
createTestNode(
|
|
27
|
-
createTestNode(
|
|
28
|
-
createTestNode(
|
|
29
|
-
createTestNode(
|
|
25
|
+
createTestNode('node-1'),
|
|
26
|
+
createTestNode('node-2'),
|
|
27
|
+
createTestNode('node-3'),
|
|
28
|
+
createTestNode('node-4'),
|
|
29
|
+
createTestNode('node-5')
|
|
30
30
|
];
|
|
31
31
|
const workflowData = {
|
|
32
32
|
edges: [
|
|
33
33
|
{
|
|
34
|
-
sourceWorkflowNodeResourceId:
|
|
35
|
-
targetWorkflowNodeResourceId:
|
|
34
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
35
|
+
targetWorkflowNodeResourceId: 'node-2'
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
|
-
sourceWorkflowNodeResourceId:
|
|
39
|
-
targetWorkflowNodeResourceId:
|
|
38
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
39
|
+
targetWorkflowNodeResourceId: 'node-3'
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
|
-
sourceWorkflowNodeResourceId:
|
|
43
|
-
targetWorkflowNodeResourceId:
|
|
42
|
+
sourceWorkflowNodeResourceId: 'node-2',
|
|
43
|
+
targetWorkflowNodeResourceId: 'node-4'
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
|
-
sourceWorkflowNodeResourceId:
|
|
47
|
-
targetWorkflowNodeResourceId:
|
|
46
|
+
sourceWorkflowNodeResourceId: 'node-3',
|
|
47
|
+
targetWorkflowNodeResourceId: 'node-4'
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
|
-
sourceWorkflowNodeResourceId:
|
|
51
|
-
targetWorkflowNodeResourceId:
|
|
52
|
-
}
|
|
50
|
+
sourceWorkflowNodeResourceId: 'node-4',
|
|
51
|
+
targetWorkflowNodeResourceId: 'node-5'
|
|
52
|
+
}
|
|
53
53
|
],
|
|
54
|
-
nodes
|
|
54
|
+
nodes
|
|
55
55
|
};
|
|
56
56
|
const startNode = nodes[0]; // node-1
|
|
57
57
|
const endNode = nodes[4]; // node-5
|
|
58
58
|
const { executionLevels } = (0, get_execution_levels_1.getExecutionLevels)({
|
|
59
59
|
workflowData,
|
|
60
60
|
startNode,
|
|
61
|
-
endNode
|
|
61
|
+
endNode
|
|
62
62
|
});
|
|
63
63
|
// 验证层级数量
|
|
64
64
|
expect(executionLevels.length).toBe(4);
|
|
65
65
|
// 验证第一层(只有node-1)
|
|
66
66
|
expect(executionLevels[0]).toHaveLength(1);
|
|
67
|
-
expect(executionLevels[0][0].id).toBe(
|
|
67
|
+
expect(executionLevels[0][0].id).toBe('node-1');
|
|
68
68
|
// 验证第二层(node-2和node-3,可以并行)
|
|
69
69
|
expect(executionLevels[1]).toHaveLength(2);
|
|
70
70
|
const level2NodeIds = executionLevels[1].map((node) => node.id).sort();
|
|
71
|
-
expect(level2NodeIds).toEqual([
|
|
71
|
+
expect(level2NodeIds).toEqual(['node-2', 'node-3']);
|
|
72
72
|
// 验证第三层(只有node-4,需要2,3都完成)
|
|
73
73
|
expect(executionLevels[2]).toHaveLength(1);
|
|
74
|
-
expect(executionLevels[2][0].id).toBe(
|
|
74
|
+
expect(executionLevels[2][0].id).toBe('node-4');
|
|
75
75
|
// 验证第四层(只有node-5)
|
|
76
76
|
expect(executionLevels[3]).toHaveLength(1);
|
|
77
|
-
expect(executionLevels[3][0].id).toBe(
|
|
77
|
+
expect(executionLevels[3][0].id).toBe('node-5');
|
|
78
78
|
});
|
|
79
|
-
test(
|
|
79
|
+
test('should handle simple sequential workflow', () => {
|
|
80
80
|
// 测试简单的顺序工作流:1-2-3
|
|
81
81
|
const nodes = [
|
|
82
|
-
createTestNode(
|
|
83
|
-
createTestNode(
|
|
84
|
-
createTestNode(
|
|
82
|
+
createTestNode('node-1'),
|
|
83
|
+
createTestNode('node-2'),
|
|
84
|
+
createTestNode('node-3')
|
|
85
85
|
];
|
|
86
86
|
const workflowData = {
|
|
87
87
|
edges: [
|
|
88
88
|
{
|
|
89
|
-
sourceWorkflowNodeResourceId:
|
|
90
|
-
targetWorkflowNodeResourceId:
|
|
89
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
90
|
+
targetWorkflowNodeResourceId: 'node-2'
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
|
-
sourceWorkflowNodeResourceId:
|
|
94
|
-
targetWorkflowNodeResourceId:
|
|
95
|
-
}
|
|
93
|
+
sourceWorkflowNodeResourceId: 'node-2',
|
|
94
|
+
targetWorkflowNodeResourceId: 'node-3'
|
|
95
|
+
}
|
|
96
96
|
],
|
|
97
|
-
nodes
|
|
97
|
+
nodes
|
|
98
98
|
};
|
|
99
99
|
const startNode = nodes[0]; // node-1
|
|
100
100
|
const endNode = nodes[2]; // node-3
|
|
101
101
|
const { executionLevels } = (0, get_execution_levels_1.getExecutionLevels)({
|
|
102
102
|
workflowData,
|
|
103
103
|
startNode,
|
|
104
|
-
endNode
|
|
104
|
+
endNode
|
|
105
105
|
});
|
|
106
106
|
// 验证层级数量
|
|
107
107
|
expect(executionLevels.length).toBe(3);
|
|
@@ -111,7 +111,7 @@ describe("getExecutionLevels", () => {
|
|
|
111
111
|
expect(level[0].id).toBe(`node-${index + 1}`);
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
|
-
test(
|
|
114
|
+
test('should handle complex parallel workflow', () => {
|
|
115
115
|
// 测试更复杂的并行工作流:1-2, 1-3, 1-4, 2-5, 3-5, 4-6, 5-6, 6-7
|
|
116
116
|
// 期望的层级:
|
|
117
117
|
// Level 0: [1]
|
|
@@ -120,100 +120,100 @@ describe("getExecutionLevels", () => {
|
|
|
120
120
|
// Level 3: [6] (需要4,5完成)
|
|
121
121
|
// Level 4: [7]
|
|
122
122
|
const nodes = [
|
|
123
|
-
createTestNode(
|
|
124
|
-
createTestNode(
|
|
125
|
-
createTestNode(
|
|
126
|
-
createTestNode(
|
|
127
|
-
createTestNode(
|
|
128
|
-
createTestNode(
|
|
129
|
-
createTestNode(
|
|
123
|
+
createTestNode('node-1'),
|
|
124
|
+
createTestNode('node-2'),
|
|
125
|
+
createTestNode('node-3'),
|
|
126
|
+
createTestNode('node-4'),
|
|
127
|
+
createTestNode('node-5'),
|
|
128
|
+
createTestNode('node-6'),
|
|
129
|
+
createTestNode('node-7')
|
|
130
130
|
];
|
|
131
131
|
const workflowData = {
|
|
132
132
|
edges: [
|
|
133
133
|
{
|
|
134
|
-
sourceWorkflowNodeResourceId:
|
|
135
|
-
targetWorkflowNodeResourceId:
|
|
134
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
135
|
+
targetWorkflowNodeResourceId: 'node-2'
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
|
-
sourceWorkflowNodeResourceId:
|
|
139
|
-
targetWorkflowNodeResourceId:
|
|
138
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
139
|
+
targetWorkflowNodeResourceId: 'node-3'
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
|
-
sourceWorkflowNodeResourceId:
|
|
143
|
-
targetWorkflowNodeResourceId:
|
|
142
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
143
|
+
targetWorkflowNodeResourceId: 'node-4'
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
|
-
sourceWorkflowNodeResourceId:
|
|
147
|
-
targetWorkflowNodeResourceId:
|
|
146
|
+
sourceWorkflowNodeResourceId: 'node-2',
|
|
147
|
+
targetWorkflowNodeResourceId: 'node-5'
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
|
-
sourceWorkflowNodeResourceId:
|
|
151
|
-
targetWorkflowNodeResourceId:
|
|
150
|
+
sourceWorkflowNodeResourceId: 'node-3',
|
|
151
|
+
targetWorkflowNodeResourceId: 'node-5'
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
|
-
sourceWorkflowNodeResourceId:
|
|
155
|
-
targetWorkflowNodeResourceId:
|
|
154
|
+
sourceWorkflowNodeResourceId: 'node-4',
|
|
155
|
+
targetWorkflowNodeResourceId: 'node-6'
|
|
156
156
|
},
|
|
157
157
|
{
|
|
158
|
-
sourceWorkflowNodeResourceId:
|
|
159
|
-
targetWorkflowNodeResourceId:
|
|
158
|
+
sourceWorkflowNodeResourceId: 'node-5',
|
|
159
|
+
targetWorkflowNodeResourceId: 'node-6'
|
|
160
160
|
},
|
|
161
161
|
{
|
|
162
|
-
sourceWorkflowNodeResourceId:
|
|
163
|
-
targetWorkflowNodeResourceId:
|
|
164
|
-
}
|
|
162
|
+
sourceWorkflowNodeResourceId: 'node-6',
|
|
163
|
+
targetWorkflowNodeResourceId: 'node-7'
|
|
164
|
+
}
|
|
165
165
|
],
|
|
166
|
-
nodes
|
|
166
|
+
nodes
|
|
167
167
|
};
|
|
168
168
|
const startNode = nodes[0]; // node-1
|
|
169
169
|
const endNode = nodes[6]; // node-7
|
|
170
170
|
const { executionLevels } = (0, get_execution_levels_1.getExecutionLevels)({
|
|
171
171
|
workflowData,
|
|
172
172
|
startNode,
|
|
173
|
-
endNode
|
|
173
|
+
endNode
|
|
174
174
|
});
|
|
175
175
|
// 验证层级数量
|
|
176
176
|
expect(executionLevels.length).toBe(5);
|
|
177
177
|
// 验证第一层(只有node-1)
|
|
178
178
|
expect(executionLevels[0]).toHaveLength(1);
|
|
179
|
-
expect(executionLevels[0][0].id).toBe(
|
|
179
|
+
expect(executionLevels[0][0].id).toBe('node-1');
|
|
180
180
|
// 验证第二层(node-2, node-3, node-4,可以并行)
|
|
181
181
|
expect(executionLevels[1]).toHaveLength(3);
|
|
182
182
|
const level2NodeIds = executionLevels[1].map((node) => node.id).sort();
|
|
183
|
-
expect(level2NodeIds).toEqual([
|
|
183
|
+
expect(level2NodeIds).toEqual(['node-2', 'node-3', 'node-4']);
|
|
184
184
|
// 验证第三层(只有node-5,需要2,3完成)
|
|
185
185
|
expect(executionLevels[2]).toHaveLength(1);
|
|
186
|
-
expect(executionLevels[2][0].id).toBe(
|
|
186
|
+
expect(executionLevels[2][0].id).toBe('node-5');
|
|
187
187
|
// 验证第四层(只有node-6,需要4,5完成)
|
|
188
188
|
expect(executionLevels[3]).toHaveLength(1);
|
|
189
|
-
expect(executionLevels[3][0].id).toBe(
|
|
189
|
+
expect(executionLevels[3][0].id).toBe('node-6');
|
|
190
190
|
// 验证第五层(只有node-7)
|
|
191
191
|
expect(executionLevels[4]).toHaveLength(1);
|
|
192
|
-
expect(executionLevels[4][0].id).toBe(
|
|
192
|
+
expect(executionLevels[4][0].id).toBe('node-7');
|
|
193
193
|
});
|
|
194
|
-
test(
|
|
194
|
+
test('should throw error for circular dependency', () => {
|
|
195
195
|
// 测试循环依赖:1-2, 2-3, 3-1
|
|
196
196
|
const nodes = [
|
|
197
|
-
createTestNode(
|
|
198
|
-
createTestNode(
|
|
199
|
-
createTestNode(
|
|
197
|
+
createTestNode('node-1'),
|
|
198
|
+
createTestNode('node-2'),
|
|
199
|
+
createTestNode('node-3')
|
|
200
200
|
];
|
|
201
201
|
const workflowData = {
|
|
202
202
|
edges: [
|
|
203
203
|
{
|
|
204
|
-
sourceWorkflowNodeResourceId:
|
|
205
|
-
targetWorkflowNodeResourceId:
|
|
204
|
+
sourceWorkflowNodeResourceId: 'node-1',
|
|
205
|
+
targetWorkflowNodeResourceId: 'node-2'
|
|
206
206
|
},
|
|
207
207
|
{
|
|
208
|
-
sourceWorkflowNodeResourceId:
|
|
209
|
-
targetWorkflowNodeResourceId:
|
|
208
|
+
sourceWorkflowNodeResourceId: 'node-2',
|
|
209
|
+
targetWorkflowNodeResourceId: 'node-3'
|
|
210
210
|
},
|
|
211
211
|
{
|
|
212
|
-
sourceWorkflowNodeResourceId:
|
|
213
|
-
targetWorkflowNodeResourceId:
|
|
214
|
-
}
|
|
212
|
+
sourceWorkflowNodeResourceId: 'node-3',
|
|
213
|
+
targetWorkflowNodeResourceId: 'node-1'
|
|
214
|
+
}
|
|
215
215
|
],
|
|
216
|
-
nodes
|
|
216
|
+
nodes
|
|
217
217
|
};
|
|
218
218
|
const startNode = nodes[0]; // node-1
|
|
219
219
|
const endNode = nodes[2]; // node-3
|
|
@@ -221,8 +221,8 @@ describe("getExecutionLevels", () => {
|
|
|
221
221
|
(0, get_execution_levels_1.getExecutionLevels)({
|
|
222
222
|
workflowData,
|
|
223
223
|
startNode,
|
|
224
|
-
endNode
|
|
224
|
+
endNode
|
|
225
225
|
});
|
|
226
|
-
}).toThrow(
|
|
226
|
+
}).toThrow('Circular dependency detected in workflow');
|
|
227
227
|
});
|
|
228
228
|
});
|
package/package.json
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/workflow",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
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": {
|
|
17
14
|
"json-schema": "0.4.0",
|
|
18
15
|
"json-schema-default": "^1.0.2",
|
|
16
|
+
"jsonata": "^2.0.6",
|
|
19
17
|
"lodash": "^4.17.21",
|
|
20
|
-
"@ldsg/
|
|
21
|
-
"@ldsg/resource": "0.3.
|
|
22
|
-
"@ldsg/
|
|
18
|
+
"@ldsg/resource": "0.3.10",
|
|
19
|
+
"@ldsg/resource-definition": "0.3.10",
|
|
20
|
+
"@ldsg/constants": "0.3.10",
|
|
21
|
+
"@ldsg/handler": "0.3.10"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
|
-
"@types/
|
|
24
|
+
"@types/fs-extra": "^11.0.4",
|
|
25
|
+
"@types/jest": "^29.5.2",
|
|
26
26
|
"@types/json-schema": "^7.0.15",
|
|
27
27
|
"@types/lodash": "^4.14.202",
|
|
28
|
-
"
|
|
28
|
+
"fs-extra": "^11.3.0",
|
|
29
|
+
"jest": "^29.5.0",
|
|
30
|
+
"supertest": "^6.3.4",
|
|
31
|
+
"ts-jest": "^29.1.5",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "^5.8.3",
|
|
34
|
+
"@ldsg/types": "0.3.10"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
29
38
|
},
|
|
30
39
|
"scripts": {
|
|
31
40
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -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"}
|