@ldsg/workflow 0.2.12 → 0.3.0
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 +100 -41
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +40 -14
- package/dist/types/node.d.ts +19 -9
- package/dist/types/node.d.ts.map +1 -1
- package/dist/utils/evaluate-variables.d.ts +11 -0
- package/dist/utils/evaluate-variables.d.ts.map +1 -0
- package/dist/utils/evaluate-variables.js +35 -0
- package/dist/utils/evaluate-variables.test.d.ts +2 -0
- package/dist/utils/evaluate-variables.test.d.ts.map +1 -0
- package/dist/utils/evaluate-variables.test.js +141 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/package.json +9 -5
- package/dist/utils/get-workflow-output-variables.d.ts +0 -10
- package/dist/utils/get-workflow-output-variables.d.ts.map +0 -1
- package/dist/utils/get-workflow-output-variables.js +0 -12
|
@@ -1,53 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const resource_1 = require("../../resource");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const numberIdList = ["1", "2", "3", "4", "5"];
|
|
5
|
+
const nodeIdList = numberIdList.map((id) => `node-${id}`);
|
|
6
|
+
const nodes = nodeIdList.map((nodeId) => {
|
|
7
|
+
const workflowNodeExecute = async (params) => {
|
|
8
|
+
const { variables: workflowNodeInputVariables } = params;
|
|
9
|
+
const workflowNodeOutputVariables = workflowNodeInputVariables;
|
|
7
10
|
const res = {
|
|
8
|
-
variables:
|
|
11
|
+
variables: workflowNodeOutputVariables,
|
|
9
12
|
};
|
|
10
13
|
return res;
|
|
11
14
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
let input;
|
|
16
|
+
let output;
|
|
17
|
+
switch (nodeId) {
|
|
18
|
+
case "node-1": {
|
|
19
|
+
input = {
|
|
20
|
+
hello: "jsonata:hello",
|
|
21
|
+
};
|
|
22
|
+
output = {
|
|
23
|
+
hello: "jsonata:hello",
|
|
24
|
+
};
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case "node-5": {
|
|
28
|
+
input = {
|
|
29
|
+
hello: `jsonata:$."node-1".hello`,
|
|
30
|
+
};
|
|
31
|
+
output = {
|
|
32
|
+
hello: "jsonata:hello",
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
default: {
|
|
37
|
+
input = {
|
|
38
|
+
hello: "other",
|
|
39
|
+
};
|
|
40
|
+
output = {
|
|
41
|
+
hello: "other",
|
|
42
|
+
};
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
16
46
|
const res = {
|
|
17
|
-
id,
|
|
18
|
-
|
|
47
|
+
id: nodeId,
|
|
48
|
+
properties: {
|
|
49
|
+
input,
|
|
50
|
+
output,
|
|
51
|
+
},
|
|
52
|
+
propertiesSchema: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
input: {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
hello: {
|
|
59
|
+
type: "string",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
output: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
hello: {
|
|
67
|
+
type: "string",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
execute: workflowNodeExecute,
|
|
19
74
|
};
|
|
20
75
|
return res;
|
|
21
76
|
});
|
|
77
|
+
const workflowData = {
|
|
78
|
+
edges: [
|
|
79
|
+
{
|
|
80
|
+
sourceWorkflowNodeResourceId: "node-1",
|
|
81
|
+
targetWorkflowNodeResourceId: "node-2",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
sourceWorkflowNodeResourceId: "node-2",
|
|
85
|
+
targetWorkflowNodeResourceId: "node-3",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
sourceWorkflowNodeResourceId: "node-3",
|
|
89
|
+
targetWorkflowNodeResourceId: "node-4",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
sourceWorkflowNodeResourceId: "node-4",
|
|
93
|
+
targetWorkflowNodeResourceId: "node-5",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
nodes,
|
|
97
|
+
};
|
|
98
|
+
const getWorkflowDataRes = {
|
|
99
|
+
workflowData,
|
|
100
|
+
};
|
|
22
101
|
class TestWorkflowResource extends resource_1.WorkflowResource {
|
|
23
102
|
constructor() {
|
|
24
103
|
super(...arguments);
|
|
25
104
|
this.getWorkflowData = () => {
|
|
26
|
-
|
|
27
|
-
edges: [
|
|
28
|
-
{
|
|
29
|
-
sourceWorkflowNodeResourceId: "1",
|
|
30
|
-
targetWorkflowNodeResourceId: "2",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
sourceWorkflowNodeResourceId: "2",
|
|
34
|
-
targetWorkflowNodeResourceId: "3",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
sourceWorkflowNodeResourceId: "3",
|
|
38
|
-
targetWorkflowNodeResourceId: "4",
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
sourceWorkflowNodeResourceId: "4",
|
|
42
|
-
targetWorkflowNodeResourceId: "5",
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
nodes,
|
|
46
|
-
};
|
|
47
|
-
const res = {
|
|
48
|
-
workflowData,
|
|
49
|
-
};
|
|
50
|
-
return res;
|
|
105
|
+
return getWorkflowDataRes;
|
|
51
106
|
};
|
|
52
107
|
}
|
|
53
108
|
}
|
|
@@ -59,14 +114,18 @@ test("WorkflowResource execute", async () => {
|
|
|
59
114
|
settings: {
|
|
60
115
|
title: "",
|
|
61
116
|
description: "",
|
|
62
|
-
startWorkflowNodeResourceId: "1",
|
|
63
|
-
endWorkflowNodeResourceId: "5",
|
|
117
|
+
startWorkflowNodeResourceId: "node-1",
|
|
118
|
+
endWorkflowNodeResourceId: "node-5",
|
|
64
119
|
},
|
|
65
120
|
});
|
|
121
|
+
const workflowInputVariables = {
|
|
122
|
+
hello: "world",
|
|
123
|
+
};
|
|
124
|
+
const workflowOutputVariables = {
|
|
125
|
+
hello: "world",
|
|
126
|
+
};
|
|
66
127
|
const { variables } = await testWorkflowResource.execute({
|
|
67
|
-
variables:
|
|
68
|
-
hello: "world",
|
|
69
|
-
},
|
|
128
|
+
variables: workflowInputVariables,
|
|
70
129
|
});
|
|
71
|
-
expect(variables).
|
|
130
|
+
expect(variables).toMatchObject(workflowOutputVariables);
|
|
72
131
|
});
|
package/dist/resource.d.ts.map
CHANGED
|
@@ -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,
|
|
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,CAgGtB;IAEF,eAAe,EAAE,eAAe,CAY9B;CACH"}
|
package/dist/resource.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.WorkflowResource = void 0;
|
|
|
7
7
|
const resource_1 = require("@ldsg/resource");
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
|
+
const evaluate_variables_1 = require("./utils/evaluate-variables");
|
|
10
11
|
class WorkflowResource extends resource_1.Resource {
|
|
11
12
|
constructor() {
|
|
12
13
|
super(...arguments);
|
|
@@ -71,22 +72,47 @@ class WorkflowResource extends resource_1.Resource {
|
|
|
71
72
|
startNode,
|
|
72
73
|
endNode,
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
const orderedNodeListLength = orderedNodeList.length;
|
|
76
|
+
if (orderedNodeListLength < 2) {
|
|
77
|
+
throw new Error("invalid workflow nodes count");
|
|
78
|
+
}
|
|
79
|
+
let workflowOutputVariables;
|
|
80
|
+
for (let index = 0; index < orderedNodeListLength; index++) {
|
|
81
|
+
const node = orderedNodeList[index];
|
|
82
|
+
const { id, properties, propertiesSchema, execute: nodeExecute } = node;
|
|
83
|
+
const workflowVariables = Object.fromEntries(workflowVariablesMap);
|
|
84
|
+
// 输入变量从工作流变量中使用表达式获取
|
|
85
|
+
const workflowNodeInputJsonataExpression = lodash_1.default.get(properties, "input");
|
|
86
|
+
const { variables: workflowNodeInputVariables } = await (0, evaluate_variables_1.evaluateVariables)({
|
|
87
|
+
expression: workflowNodeInputJsonataExpression,
|
|
88
|
+
/**
|
|
89
|
+
* 对于开始节点,不忽略 input 表达式,但替换工作流内部变量为工作流输入变量。
|
|
90
|
+
*/
|
|
91
|
+
variables: index === 0 ? workflowInputVariables : workflowVariables,
|
|
92
|
+
});
|
|
93
|
+
const { variables: workflowNodeOutputExpressionEvaluateInput } = await nodeExecute({
|
|
94
|
+
variables: workflowNodeInputVariables,
|
|
95
|
+
context: {
|
|
96
|
+
workflowResourceInstance: this,
|
|
97
|
+
},
|
|
82
98
|
});
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
/**
|
|
100
|
+
* 输出变量从结果中使用表达式获取
|
|
101
|
+
* 对于结束节点,不忽略 output 表达式,但表达式固定为取返回变量。
|
|
102
|
+
*/
|
|
103
|
+
const workflowNodeOutputJsonataExpression = lodash_1.default.get(properties, "output");
|
|
104
|
+
const { variables: workflowNodeOutputVariables } = await (0, evaluate_variables_1.evaluateVariables)({
|
|
105
|
+
expression: workflowNodeOutputJsonataExpression,
|
|
106
|
+
variables: workflowNodeOutputExpressionEvaluateInput,
|
|
107
|
+
});
|
|
108
|
+
workflowVariablesMap.set(id, workflowNodeOutputVariables);
|
|
109
|
+
if (index === orderedNodeListLength - 1) {
|
|
110
|
+
workflowOutputVariables = workflowNodeOutputVariables;
|
|
111
|
+
}
|
|
85
112
|
}
|
|
86
|
-
const res =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
113
|
+
const res = {
|
|
114
|
+
variables: workflowOutputVariables,
|
|
115
|
+
};
|
|
90
116
|
return res;
|
|
91
117
|
};
|
|
92
118
|
this.getWorkflowInfo = () => {
|
package/dist/types/node.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JSONSchema7 } from "json-schema";
|
|
2
|
+
import { WorkflowResource } from "../resource";
|
|
2
3
|
export type WorkflowNodeExecuterExecute = () => void | Promise<void>;
|
|
3
4
|
export interface WorkflowNodeExecuteParams {
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* (输入)变量
|
|
7
|
+
* 由工作流向工作流节点内输入
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
workflowVariablesRecord: WorkflowVariablesRecord;
|
|
9
|
+
variables: any;
|
|
10
|
+
context: {
|
|
11
|
+
workflowResourceInstance: WorkflowResource;
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
14
|
export interface WorkflowNodeExecuteRes {
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* (输出)变量
|
|
17
|
+
* 由工作流节点向工作流内输入
|
|
17
18
|
*/
|
|
18
19
|
variables: any;
|
|
19
20
|
}
|
|
@@ -27,6 +28,15 @@ export interface WorkflowNodeInfo {
|
|
|
27
28
|
* ID
|
|
28
29
|
*/
|
|
29
30
|
id: string;
|
|
31
|
+
/**
|
|
32
|
+
* Workflow Node Properties
|
|
33
|
+
*/
|
|
34
|
+
properties: any;
|
|
35
|
+
/**
|
|
36
|
+
* Workflow Node Properties Schema
|
|
37
|
+
* 在运行时,可用于检验数据,默认不开启,仅开启调试模式时开启
|
|
38
|
+
*/
|
|
39
|
+
propertiesSchema: JSONSchema7;
|
|
30
40
|
/**
|
|
31
41
|
* 工作流节点执行方法
|
|
32
42
|
* 工作流节点执行时,实际运行的方法
|
package/dist/types/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/types/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/types/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,2BAA2B,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC;IAEf,OAAO,EAAE;QACP,wBAAwB,EAAE,gBAAgB,CAAC;KAC5C,CAAC;CACH;AAED,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,EAAE,yBAAyB,KAC9B,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAErC,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,GAAG,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,EAAE,WAAW,CAAC;IAE9B;;;OAGG;IACH,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED,MAAM,MAAM,mBAAmB,GAAG,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface EvaluateVariablesParams {
|
|
2
|
+
expression: any;
|
|
3
|
+
variables: any;
|
|
4
|
+
}
|
|
5
|
+
interface EvaluateVariablesRes {
|
|
6
|
+
variables: any;
|
|
7
|
+
}
|
|
8
|
+
type EvaluateVariables = (params: EvaluateVariablesParams) => Promise<EvaluateVariablesRes>;
|
|
9
|
+
export declare const evaluateVariables: EvaluateVariables;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=evaluate-variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-variables.d.ts","sourceRoot":"","sources":["../../src/utils/evaluate-variables.ts"],"names":[],"mappings":"AAIA,UAAU,uBAAuB;IAC/B,UAAU,EAAE,GAAG,CAAC;IAChB,SAAS,EAAE,GAAG,CAAC;CAChB;AAED,UAAU,oBAAoB;IAC5B,SAAS,EAAE,GAAG,CAAC;CAChB;AAED,KAAK,iBAAiB,GAAG,CACvB,MAAM,EAAE,uBAAuB,KAC5B,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnC,eAAO,MAAM,iBAAiB,EAAE,iBAkC/B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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.evaluateVariables = void 0;
|
|
7
|
+
const flat_1 = require("flat");
|
|
8
|
+
const jsonata_1 = __importDefault(require("jsonata"));
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const evaluateVariables = async (params) => {
|
|
11
|
+
const { expression: paramsExpression, variables: input } = params;
|
|
12
|
+
const flattenRes = (0, flat_1.flatten)(paramsExpression);
|
|
13
|
+
const expressionSubstrings = [];
|
|
14
|
+
lodash_1.default.each(flattenRes, (value, key) => {
|
|
15
|
+
if (value.startsWith("jsonata:")) {
|
|
16
|
+
const { pathname } = new URL(value);
|
|
17
|
+
if (pathname) {
|
|
18
|
+
expressionSubstrings.push(`"${key}": ${pathname}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const stringifyRes = JSON.stringify({ [key]: value });
|
|
23
|
+
const pushParams = stringifyRes.slice(1, -1);
|
|
24
|
+
expressionSubstrings.push(pushParams);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const expression = `{${expressionSubstrings.join(",")}}`;
|
|
28
|
+
const evaluateRes = await (0, jsonata_1.default)(expression).evaluate(input);
|
|
29
|
+
const variables = (0, flat_1.unflatten)(evaluateRes);
|
|
30
|
+
const res = {
|
|
31
|
+
variables: JSON.parse(JSON.stringify(variables)),
|
|
32
|
+
};
|
|
33
|
+
return res;
|
|
34
|
+
};
|
|
35
|
+
exports.evaluateVariables = evaluateVariables;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-variables.test.d.ts","sourceRoot":"","sources":["../../src/utils/evaluate-variables.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const evaluate_variables_1 = require("./evaluate-variables");
|
|
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 expression = JSON.parse(JSON.stringify({
|
|
78
|
+
CurrentAccount: "Current Account",
|
|
79
|
+
AccountName: `jsonata:Account."Account Name"`,
|
|
80
|
+
CurrentOrder: `jsonata:"Current Order"`,
|
|
81
|
+
OrderPrice: `jsonata:$sum(Account.Order.Product.(Price * Quantity))`,
|
|
82
|
+
OrderIds: `jsonata:Account.Order.Product.ProductID`,
|
|
83
|
+
nestd: {
|
|
84
|
+
CurrentAccount: "Current Account",
|
|
85
|
+
AccountName: `jsonata:Account."Account Name"`,
|
|
86
|
+
CurrentOrder: `jsonata:"Current Order"`,
|
|
87
|
+
OrderPrice: `jsonata:$sum(Account.Order.Product.(Price * Quantity))`,
|
|
88
|
+
OrderIds: `jsonata:Account.Order.Product.ProductID`,
|
|
89
|
+
nestd: {
|
|
90
|
+
CurrentAccount: "Current Account",
|
|
91
|
+
AccountName: `jsonata:Account."Account Name"`,
|
|
92
|
+
CurrentOrder: `jsonata:"Current Order"`,
|
|
93
|
+
OrderPrice: `jsonata:$sum(Account.Order.Product.(Price * Quantity))`,
|
|
94
|
+
OrderIds: `jsonata:Account.Order.Product.ProductID`,
|
|
95
|
+
nestd: {
|
|
96
|
+
CurrentAccount: "Current Account",
|
|
97
|
+
AccountName: `jsonata:Account."Account Name"`,
|
|
98
|
+
CurrentOrder: `jsonata:"Current Order"`,
|
|
99
|
+
OrderPrice: `jsonata:$sum(Account.Order.Product.(Price * Quantity))`,
|
|
100
|
+
OrderIds: `jsonata:Account.Order.Product.ProductID`,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
}));
|
|
105
|
+
test("evaluate variables", async () => {
|
|
106
|
+
const evaluateVariablesRes = await (0, evaluate_variables_1.evaluateVariables)({
|
|
107
|
+
expression,
|
|
108
|
+
variables: input,
|
|
109
|
+
});
|
|
110
|
+
const expectedObject = {
|
|
111
|
+
variables: {
|
|
112
|
+
CurrentAccount: "Current Account",
|
|
113
|
+
AccountName: "Firefly",
|
|
114
|
+
CurrentOrder: "Current Order",
|
|
115
|
+
OrderPrice: 336.36,
|
|
116
|
+
OrderIds: [858383, 858236, 858383, 345664],
|
|
117
|
+
nestd: {
|
|
118
|
+
CurrentAccount: "Current Account",
|
|
119
|
+
AccountName: "Firefly",
|
|
120
|
+
CurrentOrder: "Current Order",
|
|
121
|
+
OrderPrice: 336.36,
|
|
122
|
+
OrderIds: [858383, 858236, 858383, 345664],
|
|
123
|
+
nestd: {
|
|
124
|
+
CurrentAccount: "Current Account",
|
|
125
|
+
AccountName: "Firefly",
|
|
126
|
+
CurrentOrder: "Current Order",
|
|
127
|
+
OrderPrice: 336.36,
|
|
128
|
+
OrderIds: [858383, 858236, 858383, 345664],
|
|
129
|
+
nestd: {
|
|
130
|
+
CurrentAccount: "Current Account",
|
|
131
|
+
AccountName: "Firefly",
|
|
132
|
+
CurrentOrder: "Current Order",
|
|
133
|
+
OrderPrice: 336.36,
|
|
134
|
+
OrderIds: [858383, 858236, 858383, 345664],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
expect(evaluateVariablesRes).toMatchObject(expectedObject);
|
|
141
|
+
});
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./get-workflow-output-variables"), exports);
|
|
18
17
|
__exportStar(require("./get-ordered-node-list"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/workflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -14,14 +14,18 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"flat": "^5.0.2",
|
|
18
|
+
"json-schema": "0.4.0",
|
|
17
19
|
"lodash": "^4.17.21",
|
|
18
|
-
"@ldsg/handler": "0.
|
|
19
|
-
"@ldsg/resource": "0.
|
|
20
|
-
"@ldsg/resource
|
|
20
|
+
"@ldsg/handler": "0.3.0",
|
|
21
|
+
"@ldsg/resource-definition": "0.3.0",
|
|
22
|
+
"@ldsg/resource": "0.3.0"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
25
|
+
"@types/flat": "^5.0.5",
|
|
26
|
+
"@types/json-schema": "^7.0.15",
|
|
23
27
|
"@types/lodash": "^4.14.202",
|
|
24
|
-
"@ldsg/types": "0.
|
|
28
|
+
"@ldsg/types": "0.3.0"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
27
31
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WorkflowExecuteRes, WorkflowNodeInfo, WorkflowVariablesMap } from "../types";
|
|
2
|
-
export interface GetWorkflowOutputVariablesParams {
|
|
3
|
-
endNode: WorkflowNodeInfo;
|
|
4
|
-
workflowVariablesMap: WorkflowVariablesMap;
|
|
5
|
-
}
|
|
6
|
-
export interface GetWorkflowOutputVariablesRes extends WorkflowExecuteRes {
|
|
7
|
-
}
|
|
8
|
-
export type GetWorkflowOutputVariables = (params: GetWorkflowOutputVariablesParams) => GetWorkflowOutputVariablesRes;
|
|
9
|
-
export declare const getWorkflowOutputVariables: GetWorkflowOutputVariables;
|
|
10
|
-
//# sourceMappingURL=get-workflow-output-variables.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-workflow-output-variables.d.ts","sourceRoot":"","sources":["../../src/utils/get-workflow-output-variables.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,gCAAgC;IAC/C,OAAO,EAAE,gBAAgB,CAAC;IAC1B,oBAAoB,EAAE,oBAAoB,CAAC;CAC5C;AAED,MAAM,WAAW,6BAA8B,SAAQ,kBAAkB;CAAG;AAE5E,MAAM,MAAM,0BAA0B,GAAG,CACvC,MAAM,EAAE,gCAAgC,KACrC,6BAA6B,CAAC;AAEnC,eAAO,MAAM,0BAA0B,EAAE,0BAYxC,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWorkflowOutputVariables = void 0;
|
|
4
|
-
const getWorkflowOutputVariables = (params) => {
|
|
5
|
-
const { endNode, workflowVariablesMap } = params;
|
|
6
|
-
const variables = workflowVariablesMap.get(endNode.id);
|
|
7
|
-
const res = {
|
|
8
|
-
variables,
|
|
9
|
-
};
|
|
10
|
-
return res;
|
|
11
|
-
};
|
|
12
|
-
exports.getWorkflowOutputVariables = getWorkflowOutputVariables;
|