@ldsg/workflow 0.3.8 → 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 +64 -51
- 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.d.ts +2 -0
- package/dist/utils/evaluate-variables/index.test.d.ts.map +1 -0
- package/dist/utils/evaluate-variables/index.test.js +219 -0
- 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 +17 -0
- package/dist/utils/get-execution-levels.d.ts.map +1 -0
- package/dist/utils/get-execution-levels.js +136 -0
- package/dist/utils/get-execution-levels.test.d.ts +2 -0
- package/dist/utils/get-execution-levels.test.d.ts.map +1 -0
- package/dist/utils/get-execution-levels.test.js +228 -0
- 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.test.d.ts +0 -2
- package/dist/utils/evaluate-variables.test.d.ts.map +0 -1
- package/dist/utils/evaluate-variables.test.js +0 -219
- package/dist/utils/get-ordered-node-list.d.ts +0 -19
- package/dist/utils/get-ordered-node-list.d.ts.map +0 -1
- package/dist/utils/get-ordered-node-list.js +0 -41
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,gCAAiC,SAAQ,wBAAwB;IAChF;;OAEG;IACH,2BAA2B,EAAE,MAAM,CAAC;IAEpC;;OAEG;IACH,yBAAyB,EAAE,MAAM,CAAC;CACnC"}
|
package/dist/types/workflow.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { WorkflowEdgeInfo } from
|
|
2
|
-
import { WorkflowNodeInfo } from
|
|
3
|
-
import { WorkflowVariables } from
|
|
1
|
+
import { WorkflowEdgeInfo } from './edge';
|
|
2
|
+
import { WorkflowNodeInfo } from './node';
|
|
3
|
+
import { WorkflowVariables } from './variables';
|
|
4
4
|
export interface WorkflowData {
|
|
5
5
|
edges: WorkflowEdgeInfo[];
|
|
6
6
|
nodes: WorkflowNodeInfo[];
|
|
7
7
|
}
|
|
8
8
|
export interface WorkflowExecuteParams {
|
|
9
|
+
/**
|
|
10
|
+
* 上下文
|
|
11
|
+
*/
|
|
12
|
+
context: any;
|
|
9
13
|
/**
|
|
10
14
|
* 工作流输入变量
|
|
11
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/types/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,SAAS,EAAE,iBAAiB,CAAC;IAE7B;;OAEG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/types/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC;IAEb;;OAEG;IACH,SAAS,EAAE,iBAAiB,CAAC;IAE7B;;OAEG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAE7F,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,eAAe,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/constants.ts"],"names":[],"mappings":"AAEA,UAAU,qCAAqC;IAC7C;;OAEG;IACH,oBAAoB,EAAE,GAAG,CAAC;IAE1B;;;OAGG;IACH,KAAK,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAG3B;AAED,MAAM,WAAW,kCAAkC;IACjD,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,KAAK,+BAA+B,GAAG,CACrC,MAAM,EAAE,qCAAqC,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/constants.ts"],"names":[],"mappings":"AAEA,UAAU,qCAAqC;IAC7C;;OAEG;IACH,oBAAoB,EAAE,GAAG,CAAC;IAE1B;;;OAGG;IACH,KAAK,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAG3B;AAED,MAAM,WAAW,kCAAkC;IACjD,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,KAAK,+BAA+B,GAAG,CACrC,MAAM,EAAE,qCAAqC,KAC1C,OAAO,CAAC,kCAAkC,CAAC,GAAG,kCAAkC,CAAC;AAEtF;;GAEG;AACH,UAAU,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,+BAA+B,CAAC;CACzC;AAqCD;;GAEG;AACH,eAAO,MAAM,6BAA6B,EAAE,yBAAyB,EAuCpE,CAAC"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.FIELD_VALUE_RETRIEVAL_METHODS = void 0;
|
|
7
7
|
const jsonata_1 = __importDefault(require("jsonata"));
|
|
8
8
|
const expressionHandle = async (params) => {
|
|
9
|
-
const { input, retrievalMethodValue, returnExpressionAsData, objectExpression
|
|
9
|
+
const { input, retrievalMethodValue, returnExpressionAsData, objectExpression
|
|
10
10
|
// expressionMayContainObject
|
|
11
11
|
} = params;
|
|
12
12
|
/**
|
|
@@ -14,17 +14,17 @@ const expressionHandle = async (params) => {
|
|
|
14
14
|
*/
|
|
15
15
|
if (returnExpressionAsData) {
|
|
16
16
|
return {
|
|
17
|
-
expression: retrievalMethodValue
|
|
17
|
+
expression: retrievalMethodValue
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
let jsonataStr = retrievalMethodValue;
|
|
21
21
|
if (objectExpression) {
|
|
22
|
-
jsonataStr = retrievalMethodValue.replace(
|
|
22
|
+
jsonataStr = retrievalMethodValue.replace('{}', objectExpression);
|
|
23
23
|
}
|
|
24
24
|
const expression = (0, jsonata_1.default)(jsonataStr);
|
|
25
25
|
const data = await expression.evaluate(input);
|
|
26
26
|
const res = {
|
|
27
|
-
data
|
|
27
|
+
data
|
|
28
28
|
};
|
|
29
29
|
return res;
|
|
30
30
|
};
|
|
@@ -33,37 +33,37 @@ const expressionHandle = async (params) => {
|
|
|
33
33
|
*/
|
|
34
34
|
exports.FIELD_VALUE_RETRIEVAL_METHODS = [
|
|
35
35
|
{
|
|
36
|
-
name:
|
|
36
|
+
name: 'const',
|
|
37
37
|
handle: (params) => {
|
|
38
38
|
const { retrievalMethodValue } = params;
|
|
39
39
|
const res = {
|
|
40
40
|
const: retrievalMethodValue,
|
|
41
|
-
data: retrievalMethodValue
|
|
41
|
+
data: retrievalMethodValue
|
|
42
42
|
};
|
|
43
43
|
return res;
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
|
-
name:
|
|
48
|
-
handle: expressionHandle
|
|
47
|
+
name: 'x-expression-const',
|
|
48
|
+
handle: expressionHandle
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
|
-
name:
|
|
52
|
-
handle: expressionHandle
|
|
51
|
+
name: 'x-expression',
|
|
52
|
+
handle: expressionHandle
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
name:
|
|
56
|
-
handle: expressionHandle
|
|
55
|
+
name: 'x-expression-default',
|
|
56
|
+
handle: expressionHandle
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
|
-
name:
|
|
59
|
+
name: 'default',
|
|
60
60
|
handle: (params) => {
|
|
61
61
|
const { retrievalMethodValue } = params;
|
|
62
62
|
const res = {
|
|
63
63
|
default: retrievalMethodValue,
|
|
64
|
-
data: retrievalMethodValue
|
|
64
|
+
data: retrievalMethodValue
|
|
65
65
|
};
|
|
66
66
|
return res;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
69
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JSONSchemaWithExpressionExtension } from '../../types';
|
|
2
2
|
interface EvaluateVariablesParams {
|
|
3
|
-
jsonSchema:
|
|
3
|
+
jsonSchema: JSONSchemaWithExpressionExtension;
|
|
4
4
|
variables: any;
|
|
5
5
|
}
|
|
6
6
|
interface EvaluateVariablesRes {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAGhE,UAAU,uBAAuB;IAC/B,UAAU,EAAE,iCAAiC,CAAC;IAC9C,SAAS,EAAE,GAAG,CAAC;CAChB;AAED,UAAU,oBAAoB;IAC5B,SAAS,EAAE,GAAG,CAAC;CAChB;AAED,KAAK,iBAAiB,GAAG,CAAC,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAE5F,eAAO,MAAM,iBAAiB,EAAE,iBAe/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.debug.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/index.debug.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,194 @@
|
|
|
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
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const _1 = require(".");
|
|
9
|
+
const input = {
|
|
10
|
+
Account: {
|
|
11
|
+
'Account Name': 'Firefly',
|
|
12
|
+
Order: [
|
|
13
|
+
{
|
|
14
|
+
OrderID: 'order103',
|
|
15
|
+
Product: [
|
|
16
|
+
{
|
|
17
|
+
'Product Name': 'Bowler Hat',
|
|
18
|
+
ProductID: 858383,
|
|
19
|
+
SKU: '0406654608',
|
|
20
|
+
Description: {
|
|
21
|
+
Colour: 'Purple',
|
|
22
|
+
Width: 300,
|
|
23
|
+
Height: 200,
|
|
24
|
+
Depth: 210,
|
|
25
|
+
Weight: 0.75
|
|
26
|
+
},
|
|
27
|
+
Price: 34.45,
|
|
28
|
+
Quantity: 2
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
'Product Name': 'Trilby hat',
|
|
32
|
+
ProductID: 858236,
|
|
33
|
+
SKU: '0406634348',
|
|
34
|
+
Description: {
|
|
35
|
+
Colour: 'Orange',
|
|
36
|
+
Width: 300,
|
|
37
|
+
Height: 200,
|
|
38
|
+
Depth: 210,
|
|
39
|
+
Weight: 0.6
|
|
40
|
+
},
|
|
41
|
+
Price: 21.67,
|
|
42
|
+
Quantity: 1
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
OrderID: 'order104',
|
|
48
|
+
Product: [
|
|
49
|
+
{
|
|
50
|
+
'Product Name': 'Bowler Hat',
|
|
51
|
+
ProductID: 858383,
|
|
52
|
+
SKU: '040657863',
|
|
53
|
+
Description: {
|
|
54
|
+
Colour: 'Purple',
|
|
55
|
+
Width: 300,
|
|
56
|
+
Height: 200,
|
|
57
|
+
Depth: 210,
|
|
58
|
+
Weight: 0.75
|
|
59
|
+
},
|
|
60
|
+
Price: 34.45,
|
|
61
|
+
Quantity: 4
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
ProductID: 345664,
|
|
65
|
+
SKU: '0406654603',
|
|
66
|
+
'Product Name': 'Cloak',
|
|
67
|
+
Description: {
|
|
68
|
+
Colour: 'Black',
|
|
69
|
+
Width: 30,
|
|
70
|
+
Height: 20,
|
|
71
|
+
Depth: 210,
|
|
72
|
+
Weight: 2
|
|
73
|
+
},
|
|
74
|
+
Price: 107.99,
|
|
75
|
+
Quantity: 1
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const subJsonSchema = {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
CurrentAccount: {
|
|
86
|
+
type: 'string',
|
|
87
|
+
/**
|
|
88
|
+
* 从默认值内取值
|
|
89
|
+
*/
|
|
90
|
+
default: 'Current Account',
|
|
91
|
+
const: 'Current Account'
|
|
92
|
+
},
|
|
93
|
+
type: {
|
|
94
|
+
type: 'string',
|
|
95
|
+
default: 'order',
|
|
96
|
+
const: 'order'
|
|
97
|
+
},
|
|
98
|
+
AccountName: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
/**
|
|
101
|
+
* 根据 jsonata 取值
|
|
102
|
+
*/
|
|
103
|
+
'x-expression': `Account."Account Name"`
|
|
104
|
+
},
|
|
105
|
+
CurrentOrder: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
/**
|
|
108
|
+
* 根据 jsonata 取值
|
|
109
|
+
*/
|
|
110
|
+
'x-expression': `"Current Order"`
|
|
111
|
+
},
|
|
112
|
+
OrderPrice: {
|
|
113
|
+
type: 'number',
|
|
114
|
+
'x-expression': '$sum(Account.Order.Product.(Price * Quantity))'
|
|
115
|
+
},
|
|
116
|
+
ProductIds: {
|
|
117
|
+
type: 'array',
|
|
118
|
+
items: {
|
|
119
|
+
type: 'number'
|
|
120
|
+
},
|
|
121
|
+
'x-expression': 'Account.Order.Product.ProductID'
|
|
122
|
+
},
|
|
123
|
+
ordersWithProductIds: {
|
|
124
|
+
type: 'array',
|
|
125
|
+
title: '具有产品 ID 的订单列表',
|
|
126
|
+
items: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
CurrentOrdersWithProductIdsTitle: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
/**
|
|
132
|
+
* 从默认值内取值
|
|
133
|
+
*/
|
|
134
|
+
default: 'CurrentOrdersWithProductIdsTitle',
|
|
135
|
+
const: 'CurrentOrdersWithProductIdsTitle'
|
|
136
|
+
},
|
|
137
|
+
productIds: {
|
|
138
|
+
type: 'array',
|
|
139
|
+
items: {
|
|
140
|
+
type: 'number'
|
|
141
|
+
},
|
|
142
|
+
'x-expression': '$v.Product.ProductID'
|
|
143
|
+
},
|
|
144
|
+
AccountName: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
/**
|
|
147
|
+
* 根据 jsonata 取值
|
|
148
|
+
*/
|
|
149
|
+
'x-expression': `Account."Account Name"`
|
|
150
|
+
},
|
|
151
|
+
orderId: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
'x-expression': '$v.OrderID'
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
'x-expression': '$map($.Account.Order, function($v, $i, $a) {{}})'
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const jsonSchema = {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
...subJsonSchema.properties,
|
|
165
|
+
nestd: {
|
|
166
|
+
type: 'object',
|
|
167
|
+
properties: {
|
|
168
|
+
...subJsonSchema.properties,
|
|
169
|
+
nestd: {
|
|
170
|
+
type: 'object',
|
|
171
|
+
properties: {
|
|
172
|
+
...subJsonSchema.properties,
|
|
173
|
+
nestd: {
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties: {
|
|
176
|
+
...subJsonSchema.properties
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const main = async () => {
|
|
186
|
+
const evaluateVariablesRes = await (0, _1.evaluateVariables)({
|
|
187
|
+
jsonSchema,
|
|
188
|
+
variables: input
|
|
189
|
+
});
|
|
190
|
+
await fs_extra_1.default.writeJson(path_1.default.resolve(__dirname, 'evaluate-variables-res.json'), evaluateVariablesRes, {
|
|
191
|
+
spaces: 2
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
main();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.evaluateVariables = void 0;
|
|
4
|
-
const
|
|
4
|
+
const get_data_with_json_schema_and_input_1 = require("./utils/get-data-with-json-schema-and-input");
|
|
5
5
|
const evaluateVariables = async (params) => {
|
|
6
6
|
const { jsonSchema, variables: paramsVariables } = params;
|
|
7
|
-
const
|
|
7
|
+
const getDataWithJsonSchemaAndInputRes = await (0, get_data_with_json_schema_and_input_1.getDataWithJsonSchemaAndInput)({
|
|
8
8
|
jsonSchema,
|
|
9
|
-
input: paramsVariables
|
|
9
|
+
input: paramsVariables
|
|
10
10
|
});
|
|
11
|
-
const variables =
|
|
11
|
+
const variables = getDataWithJsonSchemaAndInputRes.data;
|
|
12
12
|
const res = {
|
|
13
|
-
variables
|
|
13
|
+
variables
|
|
14
14
|
};
|
|
15
15
|
return res;
|
|
16
16
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/utils/evaluate-variables/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JSONSchemaWithExpressionExtension } from '../../../../types';
|
|
2
|
+
interface GetDataWithJsonSchemaAndInputParams {
|
|
3
|
+
/**
|
|
4
|
+
* 输入
|
|
5
|
+
*/
|
|
6
|
+
input: any;
|
|
7
|
+
/**
|
|
8
|
+
* json schema
|
|
9
|
+
*/
|
|
10
|
+
jsonSchema: JSONSchemaWithExpressionExtension;
|
|
11
|
+
}
|
|
12
|
+
interface GetDataWithJsonSchemaAndInputRes {
|
|
13
|
+
/**
|
|
14
|
+
* 数据
|
|
15
|
+
*/
|
|
16
|
+
data?: any;
|
|
17
|
+
}
|
|
18
|
+
type GetDataWithJsonSchemaAndInput = (params: GetDataWithJsonSchemaAndInputParams) => Promise<GetDataWithJsonSchemaAndInputRes>;
|
|
19
|
+
export declare const getDataWithJsonSchemaAndInput: GetDataWithJsonSchemaAndInput;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
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"}
|