@nocobase/plugin-workflow 0.9.0-alpha.2 → 0.9.1-alpha.2

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 (138) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +9 -0
  3. package/lib/client/AddButton.d.ts +1 -1
  4. package/lib/client/AddButton.js +43 -27
  5. package/lib/client/Branch.d.ts +1 -1
  6. package/lib/client/ExecutionCanvas.js +5 -10
  7. package/lib/client/WorkflowCanvas.js +12 -42
  8. package/lib/client/WorkflowProvider.js +10 -1
  9. package/lib/client/components/CollectionBlockInitializer.d.ts +7 -0
  10. package/lib/client/components/CollectionBlockInitializer.js +81 -0
  11. package/lib/client/components/CollectionFieldInitializers.d.ts +2 -0
  12. package/lib/client/components/CollectionFieldInitializers.js +89 -0
  13. package/lib/client/components/CollectionFieldset.js +25 -33
  14. package/lib/client/components/FilterDynamicComponent.d.ts +6 -0
  15. package/lib/client/components/FilterDynamicComponent.js +43 -0
  16. package/lib/client/components/NullRender.d.ts +1 -0
  17. package/lib/client/components/NullRender.js +10 -0
  18. package/lib/client/components/RadioWithTooltip.d.ts +7 -0
  19. package/lib/client/components/RadioWithTooltip.js +94 -0
  20. package/lib/client/constants.d.ts +10 -8
  21. package/lib/client/constants.js +52 -14
  22. package/lib/client/index.d.ts +0 -1
  23. package/lib/client/index.js +1 -10
  24. package/lib/client/locale/en-US.d.ts +18 -18
  25. package/lib/client/locale/en-US.js +19 -19
  26. package/lib/client/locale/zh-CN.d.ts +47 -20
  27. package/lib/client/locale/zh-CN.js +48 -21
  28. package/lib/client/nodes/calculation.d.ts +39 -7
  29. package/lib/client/nodes/calculation.js +165 -19
  30. package/lib/client/nodes/condition.d.ts +67 -4
  31. package/lib/client/nodes/condition.js +283 -31
  32. package/lib/client/nodes/create.d.ts +10 -10
  33. package/lib/client/nodes/create.js +28 -42
  34. package/lib/client/nodes/delay.d.ts +4 -4
  35. package/lib/client/nodes/delay.js +10 -8
  36. package/lib/client/nodes/destroy.d.ts +4 -7
  37. package/lib/client/nodes/destroy.js +4 -5
  38. package/lib/client/nodes/index.d.ts +10 -2
  39. package/lib/client/nodes/index.js +217 -110
  40. package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
  41. package/lib/client/nodes/manual/AssigneesSelect.js +65 -0
  42. package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
  43. package/lib/client/nodes/manual/ModeConfig.js +160 -0
  44. package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
  45. package/lib/client/nodes/manual/SchemaConfig.js +715 -0
  46. package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
  47. package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
  48. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
  49. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
  50. package/lib/client/nodes/manual/index.d.ts +62 -0
  51. package/lib/client/nodes/manual/index.js +137 -0
  52. package/lib/client/nodes/parallel.d.ts +12 -7
  53. package/lib/client/nodes/parallel.js +32 -39
  54. package/lib/client/nodes/query.d.ts +11 -19
  55. package/lib/client/nodes/query.js +40 -47
  56. package/lib/client/nodes/request.d.ts +77 -42
  57. package/lib/client/nodes/request.js +123 -69
  58. package/lib/client/nodes/update.d.ts +33 -29
  59. package/lib/client/nodes/update.js +14 -7
  60. package/lib/client/schemas/collection.d.ts +0 -3
  61. package/lib/client/schemas/collection.js +2 -7
  62. package/lib/client/schemas/executions.js +1 -1
  63. package/lib/client/schemas/workflows.js +1 -1
  64. package/lib/client/style.js +51 -9
  65. package/lib/client/triggers/collection.d.ts +44 -15
  66. package/lib/client/triggers/collection.js +104 -82
  67. package/lib/client/triggers/index.d.ts +6 -3
  68. package/lib/client/triggers/index.js +167 -74
  69. package/lib/client/triggers/schedule/DateFieldsSelect.js +1 -3
  70. package/lib/client/triggers/schedule/ScheduleConfig.js +15 -17
  71. package/lib/client/triggers/schedule/index.d.ts +7 -6
  72. package/lib/client/triggers/schedule/index.js +39 -81
  73. package/lib/client/utils.d.ts +1 -0
  74. package/lib/client/utils.js +38 -0
  75. package/lib/client/variable.d.ts +21 -0
  76. package/lib/client/variable.js +147 -0
  77. package/lib/server/Plugin.d.ts +3 -3
  78. package/lib/server/Plugin.js +12 -21
  79. package/lib/server/Processor.d.ts +9 -2
  80. package/lib/server/Processor.js +33 -33
  81. package/lib/server/actions/index.js +2 -4
  82. package/lib/server/actions/workflows.d.ts +1 -0
  83. package/lib/server/actions/workflows.js +80 -23
  84. package/lib/server/collections/executions.js +5 -7
  85. package/lib/server/collections/flow_nodes.js +6 -18
  86. package/lib/server/collections/jobs.js +3 -1
  87. package/lib/server/collections/workflows.js +8 -4
  88. package/lib/server/constants.d.ts +9 -3
  89. package/lib/server/constants.js +11 -5
  90. package/lib/server/functions/index.d.ts +4 -0
  91. package/lib/server/functions/index.js +38 -0
  92. package/lib/server/index.d.ts +0 -1
  93. package/lib/server/index.js +0 -14
  94. package/lib/server/instructions/calculation.d.ts +2 -7
  95. package/lib/server/instructions/calculation.js +32 -37
  96. package/lib/server/instructions/condition.d.ts +4 -4
  97. package/lib/server/instructions/condition.js +126 -54
  98. package/lib/server/instructions/index.js +1 -1
  99. package/lib/server/instructions/manual/actions.js +101 -0
  100. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
  101. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
  102. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
  103. package/lib/server/instructions/manual/index.d.ts +25 -0
  104. package/lib/server/instructions/manual/index.js +200 -0
  105. package/lib/server/instructions/parallel.js +11 -7
  106. package/lib/server/instructions/request.d.ts +5 -4
  107. package/lib/server/instructions/request.js +60 -79
  108. package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
  109. package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
  110. package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
  111. package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
  112. package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
  113. package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
  114. package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
  115. package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
  116. package/lib/server/triggers/schedule.js +11 -3
  117. package/package.json +10 -10
  118. package/lib/client/calculators.d.ts +0 -89
  119. package/lib/client/calculators.js +0 -668
  120. package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
  121. package/lib/client/components/CollectionFieldSelect.js +0 -106
  122. package/lib/client/components/EjsTextArea.d.ts +0 -2
  123. package/lib/client/components/EjsTextArea.js +0 -232
  124. package/lib/server/actions/jobs.d.ts +0 -2
  125. package/lib/server/actions/jobs.js +0 -39
  126. package/lib/server/calculators/index.d.ts +0 -40
  127. package/lib/server/calculators/index.js +0 -187
  128. package/lib/server/extensions/assignees/actions.js +0 -75
  129. package/lib/server/extensions/assignees/index.d.ts +0 -2
  130. package/lib/server/extensions/assignees/index.js +0 -273
  131. package/lib/server/extensions/index.d.ts +0 -3
  132. package/lib/server/extensions/index.js +0 -13
  133. package/lib/server/instructions/prompt.d.ts +0 -19
  134. package/lib/server/instructions/prompt.js +0 -131
  135. /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
  136. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
  137. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
  138. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.linkNodes = linkNodes;
7
+
8
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
+
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+
14
+ function linkNodes(nodes) {
15
+ const nodesMap = new Map();
16
+ nodes.forEach(item => nodesMap.set(item.id, item));
17
+
18
+ var _iterator = _createForOfIteratorHelper(nodesMap.values()),
19
+ _step;
20
+
21
+ try {
22
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
23
+ let node = _step.value;
24
+
25
+ if (node.upstreamId) {
26
+ node.upstream = nodesMap.get(node.upstreamId);
27
+ }
28
+
29
+ if (node.downstreamId) {
30
+ node.downstream = nodesMap.get(node.downstreamId);
31
+ }
32
+ }
33
+ } catch (err) {
34
+ _iterator.e(err);
35
+ } finally {
36
+ _iterator.f();
37
+ }
38
+ }
@@ -0,0 +1,21 @@
1
+ export declare type VariableOption = {
2
+ key: string;
3
+ value: string;
4
+ label: string;
5
+ children?: VariableOption[];
6
+ };
7
+ export declare const TypeSets: {
8
+ boolean: Set<string>;
9
+ number: Set<string>;
10
+ string: Set<string>;
11
+ date: Set<string>;
12
+ };
13
+ export declare function filterTypedFields(fields: any, types: any): any;
14
+ export declare function useWorkflowVariableOptions(): {
15
+ label: any;
16
+ value: any;
17
+ key: any;
18
+ children: any;
19
+ disabled: boolean;
20
+ }[];
21
+ export declare function useCollectionFieldOptions(props: any): any;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TypeSets = void 0;
7
+ exports.filterTypedFields = filterTypedFields;
8
+ exports.useCollectionFieldOptions = useCollectionFieldOptions;
9
+ exports.useWorkflowVariableOptions = useWorkflowVariableOptions;
10
+
11
+ function _client() {
12
+ const data = require("@nocobase/client");
13
+
14
+ _client = function _client() {
15
+ return data;
16
+ };
17
+
18
+ return data;
19
+ }
20
+
21
+ var _nodes = require("./nodes");
22
+
23
+ var _FlowContext = require("./FlowContext");
24
+
25
+ var _triggers = require("./triggers");
26
+
27
+ var _locale = require("./locale");
28
+
29
+ const VariableTypes = [{
30
+ title: `{{t("Node result", { ns: "${_locale.NAMESPACE}" })}}`,
31
+ value: '$jobsMapByNodeId',
32
+
33
+ options(types) {
34
+ const current = (0, _nodes.useNodeContext)();
35
+ const upstreams = (0, _nodes.useAvailableUpstreams)(current);
36
+ const options = [];
37
+ upstreams.forEach(node => {
38
+ var _instruction$getOptio;
39
+
40
+ const instruction = _nodes.instructions.get(node.type);
41
+
42
+ const subOptions = (_instruction$getOptio = instruction.getOptions) === null || _instruction$getOptio === void 0 ? void 0 : _instruction$getOptio.call(instruction, node.config, types);
43
+
44
+ if (subOptions) {
45
+ var _node$title;
46
+
47
+ options.push({
48
+ key: node.id.toString(),
49
+ value: node.id.toString(),
50
+ label: (_node$title = node.title) !== null && _node$title !== void 0 ? _node$title : `#${node.id}`,
51
+ children: subOptions
52
+ });
53
+ }
54
+ });
55
+ return options;
56
+ }
57
+
58
+ }, {
59
+ title: `{{t("Trigger variables", { ns: "${_locale.NAMESPACE}" })}}`,
60
+ value: '$context',
61
+
62
+ options(types) {
63
+ var _trigger$getOptions, _trigger$getOptions2;
64
+
65
+ const _useFlowContext = (0, _FlowContext.useFlowContext)(),
66
+ workflow = _useFlowContext.workflow;
67
+
68
+ const trigger = _triggers.triggers.get(workflow.type);
69
+
70
+ return (_trigger$getOptions = trigger === null || trigger === void 0 ? void 0 : (_trigger$getOptions2 = trigger.getOptions) === null || _trigger$getOptions2 === void 0 ? void 0 : _trigger$getOptions2.call(trigger, workflow.config, types)) !== null && _trigger$getOptions !== void 0 ? _trigger$getOptions : null;
71
+ }
72
+
73
+ }, {
74
+ title: `{{t("System variables", { ns: "${_locale.NAMESPACE}" })}}`,
75
+ value: '$system',
76
+ options: [{
77
+ key: 'now',
78
+ value: 'now',
79
+ label: `{{t("Current time", { ns: "${_locale.NAMESPACE}" })}}`
80
+ }]
81
+ }];
82
+ const TypeSets = {
83
+ boolean: new Set(['boolean']),
84
+ number: new Set(['integer', 'bigInt', 'float', 'double', 'real', 'decimal']),
85
+ string: new Set(['string', 'text', 'password']),
86
+ date: new Set(['date', 'time'])
87
+ };
88
+ exports.TypeSets = TypeSets;
89
+
90
+ function matchFieldType(field, type) {
91
+ if (typeof type === 'string') {
92
+ var _TypeSets$type;
93
+
94
+ return Boolean((_TypeSets$type = TypeSets[type]) === null || _TypeSets$type === void 0 ? void 0 : _TypeSets$type.has(field.type));
95
+ }
96
+
97
+ if (typeof type === 'object' && type.type === 'reference') {
98
+ var _type$options, _type$options2;
99
+
100
+ return field.collectionName === ((_type$options = type.options) === null || _type$options === void 0 ? void 0 : _type$options.collection) && field.name === 'id' || field.type === 'belongsTo' && field.target === ((_type$options2 = type.options) === null || _type$options2 === void 0 ? void 0 : _type$options2.collection);
101
+ }
102
+
103
+ return false;
104
+ }
105
+
106
+ function filterTypedFields(fields, types) {
107
+ return types ? fields.filter(field => types.some(type => matchFieldType(field, type))) : fields;
108
+ }
109
+
110
+ function useWorkflowVariableOptions() {
111
+ const compile = (0, _client().useCompile)();
112
+ const options = VariableTypes.map(item => {
113
+ const options = typeof item.options === 'function' ? item.options().filter(Boolean) : item.options;
114
+ return {
115
+ label: compile(item.title),
116
+ value: item.value,
117
+ key: item.value,
118
+ children: compile(options),
119
+ disabled: options && !options.length
120
+ };
121
+ });
122
+ return options;
123
+ }
124
+
125
+ function useCollectionFieldOptions(props) {
126
+ const fields = props.fields,
127
+ collection = props.collection,
128
+ types = props.types;
129
+ const compile = (0, _client().useCompile)();
130
+
131
+ const _useCollectionManager = (0, _client().useCollectionManager)(),
132
+ getCollectionFields = _useCollectionManager.getCollectionFields;
133
+
134
+ return filterTypedFields(fields !== null && fields !== void 0 ? fields : getCollectionFields(collection), types).filter(field => field.interface && (!field.target || field.type === 'belongsTo')).map(field => {
135
+ var _field$uiSchema, _field$uiSchema2;
136
+
137
+ return field.type === 'belongsTo' ? {
138
+ label: `${compile(((_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.title) || field.name)} ID`,
139
+ key: field.foreignKey,
140
+ value: field.foreignKey
141
+ } : {
142
+ label: compile(((_field$uiSchema2 = field.uiSchema) === null || _field$uiSchema2 === void 0 ? void 0 : _field$uiSchema2.title) || field.name),
143
+ key: field.name,
144
+ value: field.name
145
+ };
146
+ });
147
+ }
@@ -4,13 +4,13 @@ import { Instruction } from './instructions';
4
4
  import ExecutionModel from './models/Execution';
5
5
  import JobModel from './models/Job';
6
6
  import WorkflowModel from './models/Workflow';
7
+ import Processor from './Processor';
7
8
  import { Trigger } from './triggers';
8
9
  declare type Pending = [ExecutionModel, JobModel?];
9
10
  export default class WorkflowPlugin extends Plugin {
10
11
  instructions: Registry<Instruction>;
11
12
  triggers: Registry<Trigger>;
12
- calculators: Registry<Function>;
13
- extensions: typeof import("./extensions/assignees").default[];
13
+ functions: Registry<Function>;
14
14
  executing: ExecutionModel | null;
15
15
  pending: Pending[];
16
16
  events: [WorkflowModel, any, {
@@ -26,6 +26,6 @@ export default class WorkflowPlugin extends Plugin {
26
26
  resume(job: any): Promise<void>;
27
27
  private dispatch;
28
28
  private process;
29
- private createProcessor;
29
+ createProcessor(execution: ExecutionModel, options?: {}): Processor;
30
30
  }
31
31
  export {};
@@ -47,18 +47,16 @@ function _utils() {
47
47
 
48
48
  var _actions = _interopRequireDefault(require("./actions"));
49
49
 
50
- var _calculators = _interopRequireDefault(require("./calculators"));
51
-
52
50
  var _constants = require("./constants");
53
51
 
54
- var _extensions = _interopRequireDefault(require("./extensions"));
55
-
56
52
  var _instructions = _interopRequireDefault(require("./instructions"));
57
53
 
58
54
  var _Processor = _interopRequireDefault(require("./Processor"));
59
55
 
60
56
  var _triggers = _interopRequireDefault(require("./triggers"));
61
57
 
58
+ var _functions = _interopRequireDefault(require("./functions"));
59
+
62
60
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
61
 
64
62
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -91,8 +89,7 @@ class WorkflowPlugin extends _server().Plugin {
91
89
  _this = this;
92
90
  this.instructions = new (_utils().Registry)();
93
91
  this.triggers = new (_utils().Registry)();
94
- this.calculators = _calculators.default;
95
- this.extensions = _extensions.default;
92
+ this.functions = new (_utils().Registry)();
96
93
  this.executing = null;
97
94
  this.pending = [];
98
95
  this.events = [];
@@ -187,7 +184,7 @@ class WorkflowPlugin extends _server().Plugin {
187
184
  const execution = yield workflow.createExecution({
188
185
  context,
189
186
  key: workflow.key,
190
- status: _constants.EXECUTION_STATUS.CREATED,
187
+ status: _constants.EXECUTION_STATUS.QUEUEING,
191
188
  useTransaction: workflow.useTransaction
192
189
  }, {
193
190
  transaction
@@ -248,6 +245,10 @@ class WorkflowPlugin extends _server().Plugin {
248
245
  return _asyncToGenerator(function* () {
249
246
  const db = _this2.db,
250
247
  options = _this2.options;
248
+ (0, _actions.default)(_this2);
249
+ (0, _triggers.default)(_this2, options.triggers);
250
+ (0, _instructions.default)(_this2, options.instructions);
251
+ (0, _functions.default)(_this2, options.functions);
251
252
 
252
253
  _this2.app.acl.registerSnippet({
253
254
  name: `pm.${_this2.name}.workflows`,
@@ -268,21 +269,13 @@ class WorkflowPlugin extends _server().Plugin {
268
269
  }
269
270
  });
270
271
 
271
- (0, _actions.default)(_this2);
272
- (0, _triggers.default)(_this2, options.triggers);
273
- (0, _instructions.default)(_this2, options.instructions);
274
272
  db.on('workflows.beforeSave', _this2.onBeforeSave);
275
273
  db.on('workflows.afterSave', model => _this2.toggle(model));
276
- db.on('workflows.afterDestroy', model => _this2.toggle(model, false));
277
-
278
- _this2.app.on('afterLoad', /*#__PURE__*/_asyncToGenerator(function* () {
279
- _this2.extensions.reduce((promise, extend) => promise.then(() => extend(_this2)), Promise.resolve());
280
- })); // [Life Cycle]:
274
+ db.on('workflows.afterDestroy', model => _this2.toggle(model, false)); // [Life Cycle]:
281
275
  // * load all workflows in db
282
276
  // * add all hooks for enabled workflows
283
277
  // * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
284
278
 
285
-
286
279
  _this2.app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
287
280
  const collection = db.getCollection('workflows');
288
281
  const workflows = yield collection.repository.find({
@@ -375,7 +368,7 @@ class WorkflowPlugin extends _server().Plugin {
375
368
  } else {
376
369
  const execution = yield _this4.db.getRepository('executions').findOne({
377
370
  filter: {
378
- status: _constants.EXECUTION_STATUS.CREATED
371
+ status: _constants.EXECUTION_STATUS.QUEUEING
379
372
  },
380
373
  sort: 'createdAt'
381
374
  });
@@ -385,8 +378,6 @@ class WorkflowPlugin extends _server().Plugin {
385
378
  }
386
379
  }
387
380
 
388
- ;
389
-
390
381
  if (next) {
391
382
  _this4.process(...next);
392
383
  }
@@ -399,7 +390,7 @@ class WorkflowPlugin extends _server().Plugin {
399
390
  return _asyncToGenerator(function* () {
400
391
  _this5.executing = execution;
401
392
 
402
- if (execution.status === _constants.EXECUTION_STATUS.CREATED) {
393
+ if (execution.status === _constants.EXECUTION_STATUS.QUEUEING) {
403
394
  yield execution.update({
404
395
  status: _constants.EXECUTION_STATUS.STARTED
405
396
  });
@@ -407,7 +398,7 @@ class WorkflowPlugin extends _server().Plugin {
407
398
 
408
399
  const processor = _this5.createProcessor(execution);
409
400
 
410
- _this5.app.logger.info(`[Workflow] execution ${execution.id} ${job ? 'resuming' : 'starting'} ...`);
401
+ _this5.app.logger.info(`[Workflow] execution ${execution.id} ${job ? 'resuming' : 'starting'}...`);
411
402
 
412
403
  try {
413
404
  yield job ? processor.resume(job) : processor.start();
@@ -12,7 +12,7 @@ export default class Processor {
12
12
  static StatusMap: {
13
13
  [x: number]: number;
14
14
  };
15
- transaction: Transaction;
15
+ transaction?: Transaction;
16
16
  nodes: FlowNodeModel[];
17
17
  nodesMap: Map<number, FlowNodeModel>;
18
18
  jobsMap: Map<number, JobModel>;
@@ -23,7 +23,7 @@ export default class Processor {
23
23
  private makeNodes;
24
24
  private makeJobs;
25
25
  private getTransaction;
26
- private prepare;
26
+ prepare(): Promise<void>;
27
27
  start(): Promise<void>;
28
28
  resume(job: JobModel): Promise<void>;
29
29
  private commit;
@@ -37,5 +37,12 @@ export default class Processor {
37
37
  findBranchStartNode(node: FlowNodeModel, parent?: FlowNodeModel): FlowNodeModel | null;
38
38
  findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null;
39
39
  findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null;
40
+ getScope(node?: any): {
41
+ $context: any;
42
+ $jobsMapByNodeId: {
43
+ [key: number]: any;
44
+ };
45
+ $system: {};
46
+ };
40
47
  getParsedValue(value: any, node?: any): any;
41
48
  }
@@ -25,14 +25,18 @@ function _database() {
25
25
  return data;
26
26
  }
27
27
 
28
- var _calculators = _interopRequireDefault(require("./calculators"));
29
-
30
28
  var _constants = require("./constants");
31
29
 
32
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
31
 
34
32
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
35
33
 
34
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
+
36
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
37
+
38
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
39
+
36
40
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
37
41
 
38
42
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -45,12 +49,6 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
45
49
 
46
50
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
47
51
 
48
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
49
-
50
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
-
52
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
53
-
54
52
  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); } }
55
53
 
56
54
  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); }); }; }
@@ -206,13 +204,13 @@ class Processor {
206
204
  return null;
207
205
  }
208
206
  } catch (err) {
209
- // for uncaught error, set to rejected
207
+ // for uncaught error, set to error
210
208
  job = {
211
209
  result: err instanceof Error ? {
212
210
  message: err.message,
213
211
  stack: process.env.NODE_ENV === 'production' ? [] : err.stack
214
212
  } : err,
215
- status: _constants.JOB_STATUS.REJECTED
213
+ status: _constants.JOB_STATUS.ERROR
216
214
  }; // if previous job is from resuming
217
215
 
218
216
  if (prevJob && prevJob.nodeId === node.id) {
@@ -221,20 +219,13 @@ class Processor {
221
219
  }
222
220
  }
223
221
 
224
- let savedJob;
225
-
226
- if (job instanceof _database().Model) {
227
- savedJob = yield job.save({
228
- transaction: _this6.transaction
229
- });
230
- } else {
231
- const upstreamId = prevJob instanceof _database().Model ? prevJob.get('id') : null;
232
- savedJob = yield _this6.saveJob(_objectSpread({
233
- nodeId: node.id,
234
- upstreamId
235
- }, job));
222
+ if (!(job instanceof _database().Model)) {
223
+ job.upstreamId = prevJob instanceof _database().Model ? prevJob.get('id') : null;
224
+ job.nodeId = node.id;
236
225
  }
237
226
 
227
+ const savedJob = yield _this6.saveJob(job);
228
+
238
229
  if (savedJob.status === _constants.JOB_STATUS.RESOLVED && node.downstream) {
239
230
  // run next node
240
231
  return _this6.run(node.downstream, savedJob);
@@ -298,7 +289,9 @@ class Processor {
298
289
  var _this10 = this;
299
290
 
300
291
  return _asyncToGenerator(function* () {
301
- const status = job ? _this10.constructor.StatusMap[job.status] : _constants.EXECUTION_STATUS.RESOLVED;
292
+ var _this10$constructor$S;
293
+
294
+ const status = job ? (_this10$constructor$S = _this10.constructor.StatusMap[job.status]) !== null && _this10$constructor$S !== void 0 ? _this10$constructor$S : Math.sign(job.status) : _constants.EXECUTION_STATUS.RESOLVED;
302
295
  yield _this10.execution.update({
303
296
  status
304
297
  }, {
@@ -352,7 +345,7 @@ class Processor {
352
345
  }
353
346
 
354
347
  getBranches(node) {
355
- return this.nodes.filter(item => item.upstream === node && item.branchIndex !== null).sort((a, b) => a.branchIndex - b.branchIndex);
348
+ return this.nodes.filter(item => item.upstream === node && item.branchIndex !== null).sort((a, b) => Number(a.branchIndex) - Number(b.branchIndex));
356
349
  } // find the first node in current branch
357
350
 
358
351
 
@@ -393,14 +386,14 @@ class Processor {
393
386
  return null;
394
387
  }
395
388
 
396
- getParsedValue(value, node) {
397
- const injectedFns = {};
389
+ getScope(node) {
390
+ const systemFns = {};
398
391
  const scope = {
399
392
  execution: this.execution,
400
393
  node
401
394
  };
402
395
 
403
- var _iterator = _createForOfIteratorHelper(_calculators.default.getEntities()),
396
+ var _iterator = _createForOfIteratorHelper(this.options.plugin.functions.getEntities()),
404
397
  _step;
405
398
 
406
399
  try {
@@ -409,7 +402,7 @@ class Processor {
409
402
  name = _step$value[0],
410
403
  fn = _step$value[1];
411
404
 
412
- injectedFns[name] = fn.bind(scope);
405
+ systemFns[name] = fn.bind(scope);
413
406
  }
414
407
  } catch (err) {
415
408
  _iterator.e(err);
@@ -417,11 +410,15 @@ class Processor {
417
410
  _iterator.f();
418
411
  }
419
412
 
420
- return (0, _jsonTemplates().default)(value)({
413
+ return {
421
414
  $context: this.execution.context,
422
415
  $jobsMapByNodeId: this.jobsMapByNodeId,
423
- $fn: injectedFns
424
- });
416
+ $system: systemFns
417
+ };
418
+ }
419
+
420
+ getParsedValue(value, node) {
421
+ return (0, _jsonTemplates().default)(value)(this.getScope(node));
425
422
  }
426
423
 
427
424
  }
@@ -430,6 +427,9 @@ exports.default = Processor;
430
427
  Processor.StatusMap = {
431
428
  [_constants.JOB_STATUS.PENDING]: _constants.EXECUTION_STATUS.STARTED,
432
429
  [_constants.JOB_STATUS.RESOLVED]: _constants.EXECUTION_STATUS.RESOLVED,
433
- [_constants.JOB_STATUS.REJECTED]: _constants.EXECUTION_STATUS.REJECTED,
434
- [_constants.JOB_STATUS.CANCELED]: _constants.EXECUTION_STATUS.CANCELED
430
+ [_constants.JOB_STATUS.FAILED]: _constants.EXECUTION_STATUS.FAILED,
431
+ [_constants.JOB_STATUS.ERROR]: _constants.EXECUTION_STATUS.ERROR,
432
+ [_constants.JOB_STATUS.ABORTED]: _constants.EXECUTION_STATUS.ABORTED,
433
+ [_constants.JOB_STATUS.CANCELED]: _constants.EXECUTION_STATUS.CANCELED,
434
+ [_constants.JOB_STATUS.REJECTED]: _constants.EXECUTION_STATUS.REJECTED
435
435
  };
@@ -9,8 +9,6 @@ var workflows = _interopRequireWildcard(require("./workflows"));
9
9
 
10
10
  var nodes = _interopRequireWildcard(require("./nodes"));
11
11
 
12
- var jobs = _interopRequireWildcard(require("./jobs"));
13
-
14
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); }
15
13
 
16
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; }
@@ -30,10 +28,10 @@ function make(name, mod) {
30
28
  function _default({
31
29
  app
32
30
  }) {
33
- app.actions(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, make('workflows', workflows)), make('workflows.nodes', {
31
+ app.actions(_objectSpread(_objectSpread(_objectSpread({}, make('workflows', workflows)), make('workflows.nodes', {
34
32
  create: nodes.create,
35
33
  destroy: nodes.destroy
36
34
  })), make('flow_nodes', {
37
35
  update: nodes.update
38
- })), make('jobs', jobs)));
36
+ })));
39
37
  }
@@ -1,3 +1,4 @@
1
1
  import { Context } from '@nocobase/actions';
2
2
  export declare function update(context: Context, next: any): Promise<void>;
3
+ export declare function destroy(context: Context, next: any): Promise<void>;
3
4
  export declare function revision(context: Context, next: any): Promise<void>;