@nocobase/plugin-workflow 0.7.0-alpha.9 → 0.7.1-alpha.6

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 (159) hide show
  1. package/lib/Plugin.d.ts +18 -0
  2. package/lib/Plugin.js +285 -0
  3. package/lib/Processor.d.ts +40 -0
  4. package/lib/Processor.js +440 -0
  5. package/lib/actions/index.d.ts +3 -1
  6. package/lib/actions/index.js +33 -26
  7. package/{esm/actions/flow_nodes.d.ts → lib/actions/nodes.d.ts} +1 -0
  8. package/lib/actions/nodes.js +321 -0
  9. package/lib/actions/workflows.d.ts +2 -0
  10. package/lib/actions/workflows.js +197 -0
  11. package/lib/calculators/index.d.ts +2 -2
  12. package/lib/calculators/index.js +144 -92
  13. package/lib/collections/executions.js +32 -38
  14. package/lib/collections/flow_nodes.js +60 -72
  15. package/lib/collections/jobs.js +26 -47
  16. package/lib/collections/workflows.d.ts +1 -2
  17. package/lib/collections/workflows.js +70 -63
  18. package/lib/constants.js +22 -17
  19. package/lib/index.d.ts +4 -3
  20. package/lib/index.js +85 -22
  21. package/lib/instructions/calculation.d.ts +1 -1
  22. package/lib/instructions/calculation.js +32 -29
  23. package/lib/instructions/condition.d.ts +2 -2
  24. package/lib/instructions/condition.js +91 -88
  25. package/lib/instructions/create.d.ts +2 -2
  26. package/lib/instructions/create.js +39 -25
  27. package/lib/instructions/delay.d.ts +14 -0
  28. package/lib/instructions/delay.js +138 -0
  29. package/lib/instructions/destroy.d.ts +1 -1
  30. package/lib/instructions/destroy.js +38 -25
  31. package/lib/instructions/index.d.ts +11 -8
  32. package/lib/instructions/index.js +76 -25
  33. package/lib/instructions/parallel.d.ts +3 -3
  34. package/lib/instructions/parallel.js +95 -84
  35. package/lib/instructions/prompt.d.ts +2 -2
  36. package/lib/instructions/prompt.js +21 -13
  37. package/lib/instructions/query.d.ts +2 -1
  38. package/lib/instructions/query.js +42 -25
  39. package/lib/instructions/update.d.ts +2 -1
  40. package/lib/instructions/update.js +40 -25
  41. package/lib/models/Execution.d.ts +3 -33
  42. package/lib/models/Execution.js +18 -254
  43. package/lib/models/FlowNode.js +18 -5
  44. package/lib/models/Job.js +18 -5
  45. package/lib/models/Workflow.d.ts +5 -6
  46. package/lib/models/Workflow.js +18 -76
  47. package/lib/triggers/collection.d.ts +12 -0
  48. package/lib/triggers/collection.js +184 -0
  49. package/lib/triggers/index.d.ts +11 -7
  50. package/lib/triggers/index.js +64 -11
  51. package/lib/triggers/schedule.d.ts +38 -0
  52. package/lib/triggers/schedule.js +672 -0
  53. package/package.json +8 -12
  54. package/esm/actions/flow_nodes.js +0 -139
  55. package/esm/actions/flow_nodes.js.map +0 -1
  56. package/esm/actions/index.d.ts +0 -1
  57. package/esm/actions/index.js +0 -8
  58. package/esm/actions/index.js.map +0 -1
  59. package/esm/calculators/index.d.ts +0 -38
  60. package/esm/calculators/index.js +0 -128
  61. package/esm/calculators/index.js.map +0 -1
  62. package/esm/collections/executions.d.ts +0 -3
  63. package/esm/collections/executions.js +0 -38
  64. package/esm/collections/executions.js.map +0 -1
  65. package/esm/collections/flow_nodes.d.ts +0 -3
  66. package/esm/collections/flow_nodes.js +0 -72
  67. package/esm/collections/flow_nodes.js.map +0 -1
  68. package/esm/collections/jobs.d.ts +0 -3
  69. package/esm/collections/jobs.js +0 -47
  70. package/esm/collections/jobs.js.map +0 -1
  71. package/esm/collections/workflows.d.ts +0 -3
  72. package/esm/collections/workflows.js +0 -63
  73. package/esm/collections/workflows.js.map +0 -1
  74. package/esm/constants.d.ts +0 -17
  75. package/esm/constants.js +0 -18
  76. package/esm/constants.js.map +0 -1
  77. package/esm/index.d.ts +0 -5
  78. package/esm/index.js +0 -6
  79. package/esm/index.js.map +0 -1
  80. package/esm/instructions/calculation.d.ts +0 -8
  81. package/esm/instructions/calculation.js +0 -55
  82. package/esm/instructions/calculation.js.map +0 -1
  83. package/esm/instructions/condition.d.ts +0 -5
  84. package/esm/instructions/condition.js +0 -99
  85. package/esm/instructions/condition.js.map +0 -1
  86. package/esm/instructions/create.d.ts +0 -8
  87. package/esm/instructions/create.js +0 -25
  88. package/esm/instructions/create.js.map +0 -1
  89. package/esm/instructions/destroy.d.ts +0 -8
  90. package/esm/instructions/destroy.js +0 -25
  91. package/esm/instructions/destroy.js.map +0 -1
  92. package/esm/instructions/index.d.ts +0 -15
  93. package/esm/instructions/index.js +0 -20
  94. package/esm/instructions/index.js.map +0 -1
  95. package/esm/instructions/parallel.d.ts +0 -13
  96. package/esm/instructions/parallel.js +0 -88
  97. package/esm/instructions/parallel.js.map +0 -1
  98. package/esm/instructions/prompt.d.ts +0 -7
  99. package/esm/instructions/prompt.js +0 -13
  100. package/esm/instructions/prompt.js.map +0 -1
  101. package/esm/instructions/query.d.ts +0 -8
  102. package/esm/instructions/query.js +0 -25
  103. package/esm/instructions/query.js.map +0 -1
  104. package/esm/instructions/update.d.ts +0 -8
  105. package/esm/instructions/update.js +0 -25
  106. package/esm/instructions/update.js.map +0 -1
  107. package/esm/models/Execution.d.ts +0 -50
  108. package/esm/models/Execution.js +0 -250
  109. package/esm/models/Execution.js.map +0 -1
  110. package/esm/models/FlowNode.d.ts +0 -17
  111. package/esm/models/FlowNode.js +0 -4
  112. package/esm/models/FlowNode.js.map +0 -1
  113. package/esm/models/Job.d.ts +0 -15
  114. package/esm/models/Job.js +0 -4
  115. package/esm/models/Job.js.map +0 -1
  116. package/esm/models/Workflow.d.ts +0 -27
  117. package/esm/models/Workflow.js +0 -72
  118. package/esm/models/Workflow.js.map +0 -1
  119. package/esm/server.d.ts +0 -5
  120. package/esm/server.js +0 -62
  121. package/esm/server.js.map +0 -1
  122. package/esm/triggers/index.d.ts +0 -9
  123. package/esm/triggers/index.js +0 -6
  124. package/esm/triggers/index.js.map +0 -1
  125. package/esm/triggers/model.d.ts +0 -12
  126. package/esm/triggers/model.js +0 -47
  127. package/esm/triggers/model.js.map +0 -1
  128. package/lib/actions/flow_nodes.d.ts +0 -3
  129. package/lib/actions/flow_nodes.js +0 -163
  130. package/lib/actions/flow_nodes.js.map +0 -1
  131. package/lib/actions/index.js.map +0 -1
  132. package/lib/calculators/index.js.map +0 -1
  133. package/lib/collections/executions.js.map +0 -1
  134. package/lib/collections/flow_nodes.js.map +0 -1
  135. package/lib/collections/jobs.js.map +0 -1
  136. package/lib/collections/workflows.js.map +0 -1
  137. package/lib/constants.js.map +0 -1
  138. package/lib/index.js.map +0 -1
  139. package/lib/instructions/calculation.js.map +0 -1
  140. package/lib/instructions/condition.js.map +0 -1
  141. package/lib/instructions/create.js.map +0 -1
  142. package/lib/instructions/destroy.js.map +0 -1
  143. package/lib/instructions/index.js.map +0 -1
  144. package/lib/instructions/parallel.js.map +0 -1
  145. package/lib/instructions/prompt.js.map +0 -1
  146. package/lib/instructions/query.js.map +0 -1
  147. package/lib/instructions/update.js.map +0 -1
  148. package/lib/models/Execution.js.map +0 -1
  149. package/lib/models/FlowNode.js.map +0 -1
  150. package/lib/models/Job.js.map +0 -1
  151. package/lib/models/Workflow.js.map +0 -1
  152. package/lib/server.d.ts +0 -5
  153. package/lib/server.js +0 -68
  154. package/lib/server.js.map +0 -1
  155. package/lib/triggers/index.js.map +0 -1
  156. package/lib/triggers/model.d.ts +0 -12
  157. package/lib/triggers/model.js +0 -49
  158. package/lib/triggers/model.js.map +0 -1
  159. package/tsconfig.build.json +0 -9
@@ -1,65 +1,72 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ function _default() {
9
+ return {
4
10
  name: 'workflows',
5
- model: 'WorkflowModel',
6
- title: '自动化',
7
- fields: [
8
- {
9
- interface: 'string',
10
- type: 'string',
11
- name: 'title',
12
- title: '自动化名称',
13
- required: true
14
- },
15
- {
16
- interface: 'boolean',
17
- type: 'boolean',
18
- name: 'enabled',
19
- title: '启用'
20
- },
21
- {
22
- interface: 'textarea',
23
- type: 'text',
24
- name: 'description',
25
- title: '描述'
26
- },
27
- {
28
- interface: 'select',
29
- type: 'string',
30
- title: '触发方式',
31
- name: 'type',
32
- required: true
33
- },
34
- {
35
- interface: 'json',
36
- type: 'jsonb',
37
- title: '触发配置',
38
- name: 'config',
39
- required: true,
40
- defaultValue: {}
41
- },
42
- {
43
- interface: 'boolean',
44
- type: 'boolean',
45
- title: '使用事务',
46
- name: 'useTransaction',
47
- defaultValue: true
48
- },
49
- {
50
- interface: 'linkTo',
51
- type: 'hasMany',
52
- name: 'nodes',
53
- target: 'flow_nodes',
54
- title: '流程节点'
55
- },
56
- {
57
- interface: 'linkTo',
58
- type: 'hasMany',
59
- name: 'executions',
60
- target: 'executions',
61
- title: '触发执行'
62
- }
63
- ]
64
- };
65
- //# sourceMappingURL=workflows.js.map
11
+ fields: [{
12
+ name: 'key',
13
+ type: 'uid'
14
+ }, {
15
+ type: 'string',
16
+ name: 'title',
17
+ required: true
18
+ }, {
19
+ type: 'boolean',
20
+ name: 'enabled',
21
+ defaultValue: false
22
+ }, {
23
+ type: 'text',
24
+ name: 'description'
25
+ }, {
26
+ type: 'string',
27
+ name: 'type',
28
+ required: true
29
+ }, {
30
+ type: 'jsonb',
31
+ name: 'config',
32
+ required: true,
33
+ defaultValue: {}
34
+ }, {
35
+ type: 'boolean',
36
+ name: 'useTransaction',
37
+ defaultValue: true
38
+ }, {
39
+ type: 'hasMany',
40
+ name: 'nodes',
41
+ target: 'flow_nodes'
42
+ }, {
43
+ type: 'hasMany',
44
+ name: 'executions'
45
+ }, {
46
+ type: 'integer',
47
+ name: 'executed',
48
+ defaultValue: 0
49
+ }, {
50
+ type: 'integer',
51
+ name: 'allExecuted',
52
+ defaultValue: 0
53
+ }, {
54
+ type: 'boolean',
55
+ name: 'current',
56
+ defaultValue: null
57
+ }, {
58
+ type: 'hasMany',
59
+ name: 'revisions',
60
+ target: 'workflows',
61
+ foreignKey: 'key',
62
+ sourceKey: 'key',
63
+ // NOTE: no constraints needed here because tricky self-referencing
64
+ constraints: false
65
+ }],
66
+ // NOTE: use unique index for avoiding deadlock in mysql when setCurrent
67
+ indexes: [{
68
+ unique: true,
69
+ fields: ['key', 'current']
70
+ }]
71
+ };
72
+ }
package/lib/constants.js CHANGED
@@ -1,21 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BRANCH_INDEX = exports.JOB_STATUS = exports.EXECUTION_STATUS = void 0;
4
- exports.EXECUTION_STATUS = {
5
- STARTED: 0,
6
- RESOLVED: 1,
7
- REJECTED: -1,
8
- CANCELLED: -2
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JOB_STATUS = exports.EXECUTION_STATUS = exports.BRANCH_INDEX = void 0;
7
+ const EXECUTION_STATUS = {
8
+ STARTED: 0,
9
+ RESOLVED: 1,
10
+ REJECTED: -1,
11
+ CANCELLED: -2
9
12
  };
10
- exports.JOB_STATUS = {
11
- PENDING: 0,
12
- RESOLVED: 1,
13
- REJECTED: -1,
14
- CANCELLED: -2
13
+ exports.EXECUTION_STATUS = EXECUTION_STATUS;
14
+ const JOB_STATUS = {
15
+ PENDING: 0,
16
+ RESOLVED: 1,
17
+ REJECTED: -1,
18
+ CANCELLED: -2
15
19
  };
16
- exports.BRANCH_INDEX = {
17
- DEFAULT: null,
18
- ON_TRUE: 1,
19
- ON_FALSE: 0
20
+ exports.JOB_STATUS = JOB_STATUS;
21
+ const BRANCH_INDEX = {
22
+ DEFAULT: null,
23
+ ON_TRUE: 1,
24
+ ON_FALSE: 0
20
25
  };
21
- //# sourceMappingURL=constants.js.map
26
+ exports.BRANCH_INDEX = BRANCH_INDEX;
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * from './constants';
2
1
  export * from './calculators';
3
- export * from './triggers';
2
+ export * from './constants';
4
3
  export * from './instructions';
5
- export { default } from './server';
4
+ export * from './triggers';
5
+ export * from './Processor';
6
+ export { default } from './Plugin';
package/lib/index.js CHANGED
@@ -1,23 +1,86 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.default = void 0;
17
- __exportStar(require("./constants"), exports);
18
- __exportStar(require("./calculators"), exports);
19
- __exportStar(require("./triggers"), exports);
20
- __exportStar(require("./instructions"), exports);
21
- var server_1 = require("./server");
22
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(server_1).default; } });
23
- //# sourceMappingURL=index.js.map
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {};
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _Plugin.default;
11
+ }
12
+ });
13
+
14
+ var _calculators = require("./calculators");
15
+
16
+ Object.keys(_calculators).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
+ if (key in exports && exports[key] === _calculators[key]) return;
20
+ Object.defineProperty(exports, key, {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _calculators[key];
24
+ }
25
+ });
26
+ });
27
+
28
+ var _constants = require("./constants");
29
+
30
+ Object.keys(_constants).forEach(function (key) {
31
+ if (key === "default" || key === "__esModule") return;
32
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
33
+ if (key in exports && exports[key] === _constants[key]) return;
34
+ Object.defineProperty(exports, key, {
35
+ enumerable: true,
36
+ get: function get() {
37
+ return _constants[key];
38
+ }
39
+ });
40
+ });
41
+
42
+ var _instructions = require("./instructions");
43
+
44
+ Object.keys(_instructions).forEach(function (key) {
45
+ if (key === "default" || key === "__esModule") return;
46
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
47
+ if (key in exports && exports[key] === _instructions[key]) return;
48
+ Object.defineProperty(exports, key, {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _instructions[key];
52
+ }
53
+ });
54
+ });
55
+
56
+ var _triggers = require("./triggers");
57
+
58
+ Object.keys(_triggers).forEach(function (key) {
59
+ if (key === "default" || key === "__esModule") return;
60
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
61
+ if (key in exports && exports[key] === _triggers[key]) return;
62
+ Object.defineProperty(exports, key, {
63
+ enumerable: true,
64
+ get: function get() {
65
+ return _triggers[key];
66
+ }
67
+ });
68
+ });
69
+
70
+ var _Processor = require("./Processor");
71
+
72
+ Object.keys(_Processor).forEach(function (key) {
73
+ if (key === "default" || key === "__esModule") return;
74
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
75
+ if (key in exports && exports[key] === _Processor[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return _Processor[key];
80
+ }
81
+ });
82
+ });
83
+
84
+ var _Plugin = _interopRequireDefault(require("./Plugin"));
85
+
86
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1,6 +1,6 @@
1
1
  import FlowNodeModel from "../models/FlowNode";
2
2
  declare const _default: {
3
- run(this: FlowNodeModel, prevJob: any, execution: any): Promise<{
3
+ run(node: FlowNodeModel, prevJob: any, processor: any): Promise<{
4
4
  result: any;
5
5
  status: number;
6
6
  }>;
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const constants_1 = require("../constants");
13
- const calculators_1 = require("../calculators");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _constants = require("../constants");
9
+
10
+ var _calculators = require("../calculators");
11
+
12
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
+
14
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
15
+
14
16
  // @calculation: {
15
17
  // calculator: 'concat',
16
18
  // operands: [
@@ -37,21 +39,22 @@ const calculators_1 = require("../calculators");
37
39
  // }
38
40
  // ]
39
41
  // }
40
- exports.default = {
41
- run(prevJob, execution) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const { calculation } = this.config || {};
44
- const result = calculation
45
- ? (0, calculators_1.calculate)({
46
- type: '$calculation',
47
- options: execution.getParsedValue(calculation)
48
- }, prevJob, execution)
49
- : null;
50
- return {
51
- result,
52
- status: constants_1.JOB_STATUS.RESOLVED
53
- };
54
- });
55
- }
42
+ var _default = {
43
+ run(node, prevJob, processor) {
44
+ return _asyncToGenerator(function* () {
45
+ const _ref = node.config || {},
46
+ calculation = _ref.calculation;
47
+
48
+ const result = calculation ? (0, _calculators.calculate)({
49
+ type: '$calculation',
50
+ options: processor.getParsedValue(calculation)
51
+ }, prevJob, processor) : null;
52
+ return {
53
+ result,
54
+ status: _constants.JOB_STATUS.RESOLVED
55
+ };
56
+ })();
57
+ }
58
+
56
59
  };
57
- //# sourceMappingURL=calculation.js.map
60
+ exports.default = _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- run(this: any, prevJob: any, execution: any): Promise<any>;
3
- resume(this: any, branchJob: any, execution: any): Promise<any>;
2
+ run(node: any, prevJob: any, processor: any): Promise<any>;
3
+ resume(node: any, branchJob: any, processor: any): Promise<any>;
4
4
  };
5
5
  export default _default;
@@ -1,35 +1,22 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
13
5
  });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- const calculators_1 = __importStar(require("../calculators"));
32
- const constants_1 = require("../constants");
6
+ exports.default = void 0;
7
+
8
+ var _calculators = _interopRequireWildcard(require("../calculators"));
9
+
10
+ var _constants = require("../constants");
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
+
18
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
+
33
20
  // @calculation: {
34
21
  // not: false,
35
22
  // group: {
@@ -57,64 +44,80 @@ const constants_1 = require("../constants");
57
44
  // ]
58
45
  // }
59
46
  // }
60
- function logicCalculate(calculation, input, execution) {
61
- if (!calculation) {
62
- return true;
63
- }
64
- const { not, group } = calculation;
65
- let result;
66
- if (group) {
67
- const method = group.type === 'and' ? 'every' : 'some';
68
- result = group.calculations[method](item => logicCalculate(item, input, execution));
47
+ function logicCalculate(calculation, input, processor) {
48
+ if (!calculation) {
49
+ return true;
50
+ }
51
+
52
+ const not = calculation.not,
53
+ group = calculation.group;
54
+ let result;
55
+
56
+ if (group) {
57
+ const method = group.type === 'and' ? 'every' : 'some';
58
+ result = group.calculations[method](item => logicCalculate(item, input, processor));
59
+ } else {
60
+ const args = calculation.operands.map(operand => (0, _calculators.calculate)(operand, input, processor));
61
+
62
+ const fn = _calculators.default.get(calculation.calculator);
63
+
64
+ if (!fn) {
65
+ throw new Error(`no calculator function registered for "${calculation.calculator}"`);
69
66
  }
70
- else {
71
- const args = calculation.operands.map(operand => (0, calculators_1.calculate)(operand, input, execution));
72
- const fn = calculators_1.default.get(calculation.calculator);
73
- if (!fn) {
74
- throw new Error(`no calculator function registered for "${calculation.calculator}"`);
75
- }
76
- result = fn(...args);
77
- }
78
- return not ? !result : result;
67
+
68
+ result = fn(...args);
69
+ }
70
+
71
+ return not ? !result : result;
79
72
  }
80
- exports.default = {
81
- run(prevJob, execution) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- // TODO(optimize): loading of jobs could be reduced and turned into incrementally in execution
84
- // const jobs = await execution.getJobs();
85
- const { calculation, rejectOnFalse } = this.config || {};
86
- const result = logicCalculate(calculation, prevJob, execution);
87
- if (!result && rejectOnFalse) {
88
- return {
89
- status: constants_1.JOB_STATUS.REJECTED,
90
- result
91
- };
92
- }
93
- const job = {
94
- status: constants_1.JOB_STATUS.RESOLVED,
95
- result,
96
- // TODO(optimize): try unify the building of job
97
- nodeId: this.id,
98
- upstreamId: prevJob && prevJob.id || null
99
- };
100
- const branchNode = execution.nodes
101
- .find(item => item.upstream === this && Boolean(item.branchIndex) === result);
102
- if (!branchNode) {
103
- return job;
104
- }
105
- const savedJob = yield execution.saveJob(job);
106
- return execution.run(branchNode, savedJob);
107
- });
108
- },
109
- resume(branchJob, execution) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- if (branchJob.status === constants_1.JOB_STATUS.RESOLVED) {
112
- // return to continue this.downstream
113
- return branchJob;
114
- }
115
- // pass control to upper scope by ending current scope
116
- return execution.end(this, branchJob);
117
- });
118
- }
73
+
74
+ var _default = {
75
+ run(node, prevJob, processor) {
76
+ return _asyncToGenerator(function* () {
77
+ // TODO(optimize): loading of jobs could be reduced and turned into incrementally in processor
78
+ // const jobs = await processor.getJobs();
79
+ const _ref = node.config || {},
80
+ calculation = _ref.calculation,
81
+ rejectOnFalse = _ref.rejectOnFalse;
82
+
83
+ const result = logicCalculate(calculation, prevJob, processor);
84
+
85
+ if (!result && rejectOnFalse) {
86
+ return {
87
+ status: _constants.JOB_STATUS.REJECTED,
88
+ result
89
+ };
90
+ }
91
+
92
+ const job = {
93
+ status: _constants.JOB_STATUS.RESOLVED,
94
+ result,
95
+ // TODO(optimize): try unify the building of job
96
+ nodeId: node.id,
97
+ upstreamId: prevJob && prevJob.id || null
98
+ };
99
+ const branchNode = processor.nodes.find(item => item.upstream === node && Boolean(item.branchIndex) === result);
100
+
101
+ if (!branchNode) {
102
+ return job;
103
+ }
104
+
105
+ const savedJob = yield processor.saveJob(job);
106
+ return processor.run(branchNode, savedJob);
107
+ })();
108
+ },
109
+
110
+ resume(node, branchJob, processor) {
111
+ return _asyncToGenerator(function* () {
112
+ if (branchJob.status === _constants.JOB_STATUS.RESOLVED) {
113
+ // return to continue node.downstream
114
+ return branchJob;
115
+ } // pass control to upper scope by ending current scope
116
+
117
+
118
+ return processor.end(node, branchJob);
119
+ })();
120
+ }
121
+
119
122
  };
120
- //# sourceMappingURL=condition.js.map
123
+ exports.default = _default;
@@ -1,7 +1,7 @@
1
1
  import FlowNodeModel from "../models/FlowNode";
2
2
  declare const _default: {
3
- run(this: FlowNodeModel, input: any, execution: any): Promise<{
4
- result: import("@nocobase/database").Model<any, any>;
3
+ run(node: FlowNodeModel, input: any, processor: any): Promise<{
4
+ result: any;
5
5
  status: number;
6
6
  }>;
7
7
  };