@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
@@ -1,28 +1,32 @@
1
- import { JSONSchema7 } from "json-schema";
2
- import { WorkflowResource } from "../resource";
1
+ import { JSONSchemaWithExpressionExtension } from './json_schema_with_expression_extension';
3
2
  export type WorkflowNodeExecuterExecute = () => void | Promise<void>;
4
- export interface WorkflowNodeExecuteParams {
3
+ export interface WorkflowNodeExecuteParams<Variables = any, Context = any> {
4
+ /**
5
+ * 上下文
6
+ */
7
+ context: Context;
5
8
  /**
6
9
  * (输入)变量
7
10
  * 由工作流向工作流节点内输入
8
11
  */
9
- variables: any;
10
- context: {
11
- workflowResourceInstance: WorkflowResource;
12
- };
12
+ variables: Variables;
13
13
  }
14
- export interface WorkflowNodeExecuteRes {
14
+ export interface WorkflowNodeExecuteRes<Variables = any> {
15
15
  /**
16
16
  * (输出)变量
17
17
  * 由工作流节点向工作流内输入
18
18
  */
19
- variables: any;
19
+ variables: Variables;
20
+ /**
21
+ * (输出)端口 ID
22
+ */
23
+ portId?: string;
20
24
  }
21
25
  /**
22
26
  * 工作流执行方法
23
27
  * 工作执行时,实际运行的方法
24
28
  */
25
- export type WorkflowNodeExecute = (params: WorkflowNodeExecuteParams) => Promise<WorkflowNodeExecuteRes>;
29
+ export type WorkflowNodeExecute<Variables = any, Context = any> = (params: WorkflowNodeExecuteParams<Variables, Context>) => Promise<WorkflowNodeExecuteRes<Variables>>;
26
30
  export interface WorkflowNodeInfo {
27
31
  /**
28
32
  * ID
@@ -32,7 +36,7 @@ export interface WorkflowNodeInfo {
32
36
  * Workflow Node Properties Schema
33
37
  * 在运行时,可用于检验数据,默认不开启,仅开启调试模式时开启
34
38
  */
35
- propertiesSchema: JSONSchema7;
39
+ propertiesSchema: JSONSchemaWithExpressionExtension;
36
40
  /**
37
41
  * 工作流节点执行方法
38
42
  * 工作流节点执行时,实际运行的方法
@@ -1 +1 @@
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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CAAC,SAAS,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,CAChE,MAAM,EAAE,yBAAyB,CAAC,SAAS,EAAE,OAAO,CAAC,KAClD,OAAO,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,gBAAgB,EAAE,iCAAiC,CAAC;IAEpD;;;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"}
@@ -1,4 +1,4 @@
1
- import { SpecificResourceSettings } from "@ldsg/types";
1
+ import { SpecificResourceSettings } from '@ldsg/types';
2
2
  export interface WorkflowSpecificResourceSettings extends SpecificResourceSettings {
3
3
  /**
4
4
  * Start Workflow Node Resource ID
@@ -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,gCACf,SAAQ,wBAAwB;IAChC;;OAEG;IACH,2BAA2B,EAAE,MAAM,CAAC;IAEpC;;OAEG;IACH,yBAAyB,EAAE,MAAM,CAAC;CACnC"}
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"}
@@ -1,11 +1,15 @@
1
- import { WorkflowEdgeInfo } from "./edge";
2
- import { WorkflowNodeInfo } from "./node";
3
- import { WorkflowVariables } from "./variables";
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
  */
@@ -14,6 +18,11 @@ export interface WorkflowExecuteParams {
14
18
  * 预设工作流变量
15
19
  */
16
20
  presetWorkflowVariables?: Record<string, WorkflowVariables>;
21
+ /**
22
+ * OpenTelemetry 追踪上下文
23
+ * 用于将工作流执行与请求 trace 关联
24
+ */
25
+ traceContext?: any;
17
26
  }
18
27
  export interface WorkflowExecuteRes {
19
28
  /**
@@ -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,CAC5B,MAAM,EAAE,qBAAqB,KAC1B,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,eAAe,CAAC;CAC1B"}
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;IAE5D;;;OAGG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;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,g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yB,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("{}", objectExpression);
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: "const",
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: "x-expression-const",
48
- handle: expressionHandle,
47
+ name: 'x-expression-const',
48
+ handle: expressionHandle
49
49
  },
50
50
  {
51
- name: "x-expression",
52
- handle: expressionHandle,
51
+ name: 'x-expression',
52
+ handle: expressionHandle
53
53
  },
54
54
  {
55
- name: "x-expression-default",
56
- handle: expressionHandle,
55
+ name: 'x-expression-default',
56
+ handle: expressionHandle
57
57
  },
58
58
  {
59
- name: "default",
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 { JSONSchema7 } from "json-schema";
1
+ import { JSONSchemaWithExpressionExtension } from '../../types';
2
2
  interface EvaluateVariablesParams {
3
- jsonSchema: JSONSchema7;
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,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,UAAU,uBAAuB;IAC/B,UAAU,EAAE,WAAW,CAAC;IACxB,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,iBAe/B,CAAC"}
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.debug.d.ts.map
@@ -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 resolve_json_schema_1 = require("./utils/resolve-json-schema");
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 resolveJsonSchemaRes = await (0, resolve_json_schema_1.resolveJsonSchema)({
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 = JSON.parse(JSON.stringify(resolveJsonSchemaRes.data));
11
+ const variables = getDataWithJsonSchemaAndInputRes.data;
12
12
  const res = {
13
- variables,
13
+ variables
14
14
  };
15
15
  return res;
16
16
  };
@@ -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
@@ -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 { JSONSchema7 } from "json-schema";
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
- returnExpressionAsData?: boolean;
10
+ jsonSchema: JSONSchemaWithExpressionExtension;
11
+ /**
12
+ * 源数据,即上级数据
13
+ */
14
+ source?: any;
12
15
  }
13
16
  interface ResolveJsonSchemaRes {
14
- const?: any;
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,iBAiH/B,CAAC"}
@@ -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":"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,MAiBjE,CAAC"}
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 === "properties" && index % 2 === 0);
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;
@@ -0,0 +1,22 @@
1
+ import { WorkflowData, WorkflowExecuteRes, WorkflowNodeInfo, WorkflowVariables } from '../types';
2
+ export interface ExecuteWorkflowParams {
3
+ context: any;
4
+ endWorkflowNodeResourceId: string;
5
+ nodes: WorkflowNodeInfo[];
6
+ edges: WorkflowData['edges'];
7
+ presetWorkflowVariables?: Record<string, WorkflowVariables>;
8
+ startWorkflowNodeResourceId: string;
9
+ variables: any;
10
+ workflowData: WorkflowData;
11
+ traceContext?: any;
12
+ }
13
+ export interface NodeExecutionResult {
14
+ nodeId: string;
15
+ variables: any;
16
+ portId?: string;
17
+ }
18
+ /**
19
+ * 执行工作流
20
+ */
21
+ export declare function executeWorkflow(params: ExecuteWorkflowParams): Promise<WorkflowExecuteRes>;
22
+ //# sourceMappingURL=execute-workflow.d.ts.map