@nocobase/plugin-workflow 0.8.0-alpha.8 → 0.8.1-alpha.3
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/lib/client/AddButton.js +21 -13
- package/lib/client/ExecutionCanvas.js +10 -24
- package/lib/client/ExecutionResourceProvider.d.ts +2 -1
- package/lib/client/ExecutionResourceProvider.js +4 -3
- package/lib/client/FlowContext.js +1 -1
- package/lib/client/WorkflowCanvas.js +136 -39
- package/lib/client/WorkflowProvider.d.ts +3 -0
- package/lib/client/WorkflowProvider.js +71 -16
- package/lib/client/WorkflowShortcut.d.ts +0 -1
- package/lib/client/WorkflowShortcut.js +4 -47
- package/lib/client/calculators.d.ts +27 -37
- package/lib/client/calculators.js +168 -150
- package/lib/client/components/CollectionFieldset.js +10 -20
- package/lib/client/components/Duration.js +3 -14
- package/lib/client/components/EjsTextArea.d.ts +2 -0
- package/lib/client/components/EjsTextArea.js +232 -0
- package/lib/client/components/OpenDrawer.d.ts +6 -0
- package/lib/client/components/OpenDrawer.js +93 -0
- package/lib/client/constants.js +11 -9
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +14 -0
- package/lib/client/locale/en-US.d.ts +105 -0
- package/lib/client/locale/en-US.js +111 -0
- package/lib/client/locale/index.d.ts +3 -0
- package/lib/client/locale/index.js +69 -0
- package/lib/client/locale/ja-JP.d.ts +88 -0
- package/lib/client/locale/ja-JP.js +94 -0
- package/lib/client/locale/ru-RU.d.ts +88 -0
- package/lib/client/locale/ru-RU.js +94 -0
- package/lib/client/locale/tr-TR.d.ts +88 -0
- package/lib/client/locale/tr-TR.js +94 -0
- package/lib/client/locale/zh-CN.d.ts +130 -0
- package/lib/client/locale/zh-CN.js +136 -0
- package/lib/client/nodes/calculation.d.ts +0 -1
- package/lib/client/nodes/calculation.js +9 -17
- package/lib/client/nodes/condition.js +16 -22
- package/lib/client/nodes/create.d.ts +3 -1
- package/lib/client/nodes/create.js +11 -11
- package/lib/client/nodes/delay.js +8 -6
- package/lib/client/nodes/index.js +46 -14
- package/lib/client/nodes/parallel.d.ts +0 -1
- package/lib/client/nodes/parallel.js +11 -32
- package/lib/client/nodes/query.js +9 -17
- package/lib/client/nodes/request.d.ts +138 -0
- package/lib/client/nodes/request.js +167 -0
- package/lib/client/nodes/update.js +4 -2
- package/lib/client/schemas/collection.js +3 -1
- package/lib/client/schemas/executions.d.ts +211 -207
- package/lib/client/schemas/executions.js +102 -96
- package/lib/client/schemas/workflows.js +112 -22
- package/lib/client/style.js +7 -7
- package/lib/client/triggers/collection.d.ts +2 -1
- package/lib/client/triggers/collection.js +49 -34
- package/lib/client/triggers/index.d.ts +4 -6
- package/lib/client/triggers/index.js +57 -51
- package/lib/client/triggers/schedule/EndsByField.js +13 -39
- package/lib/client/triggers/schedule/OnField.js +10 -5
- package/lib/client/triggers/schedule/RepeatField.js +6 -14
- package/lib/client/triggers/schedule/ScheduleConfig.js +25 -20
- package/lib/client/triggers/schedule/constants.d.ts +4 -0
- package/lib/client/triggers/schedule/constants.js +11 -0
- package/lib/client/triggers/schedule/index.d.ts +2 -3
- package/lib/client/triggers/schedule/index.js +55 -40
- package/lib/server/Plugin.d.ts +15 -5
- package/lib/server/Plugin.js +176 -61
- package/lib/server/Processor.d.ts +1 -2
- package/lib/server/Processor.js +3 -19
- package/lib/server/actions/jobs.js +2 -3
- package/lib/server/actions/workflows.js +13 -5
- package/lib/server/calculators/index.d.ts +4 -2
- package/lib/server/calculators/index.js +6 -4
- package/lib/server/collections/executions.js +2 -1
- package/lib/server/constants.d.ts +1 -0
- package/lib/server/constants.js +1 -0
- package/lib/server/extensions/assignees/actions.js +2 -3
- package/lib/server/extensions/assignees/collections/users_jobs.js +9 -1
- package/lib/server/index.d.ts +3 -4
- package/lib/server/index.js +21 -44
- package/lib/server/instructions/condition.js +1 -1
- package/lib/server/instructions/create.js +3 -1
- package/lib/server/instructions/delay.js +2 -3
- package/lib/server/instructions/destroy.js +3 -1
- package/lib/server/instructions/index.d.ts +3 -2
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/prompt.js +2 -1
- package/lib/server/instructions/query.js +3 -1
- package/lib/server/instructions/request.d.ts +14 -0
- package/lib/server/instructions/request.js +154 -0
- package/lib/server/instructions/update.d.ts +1 -1
- package/lib/server/instructions/update.js +3 -1
- package/lib/server/migrations/20221129153547-calculation-variables.d.ts +5 -0
- package/lib/server/migrations/20221129153547-calculation-variables.js +116 -0
- package/lib/server/triggers/collection.js +5 -7
- package/lib/server/triggers/schedule.js +17 -6
- package/package.json +13 -8
package/lib/server/Plugin.d.ts
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import { Transactionable } from '@nocobase/database';
|
|
2
1
|
import { Plugin } from '@nocobase/server';
|
|
3
2
|
import { Registry } from '@nocobase/utils';
|
|
4
3
|
import { Instruction } from './instructions';
|
|
5
4
|
import ExecutionModel from './models/Execution';
|
|
6
5
|
import WorkflowModel from './models/Workflow';
|
|
7
|
-
import Processor from './Processor';
|
|
8
6
|
import { Trigger } from './triggers';
|
|
7
|
+
import JobModel from './models/Job';
|
|
8
|
+
declare type Pending = [ExecutionModel, JobModel?];
|
|
9
9
|
export default class WorkflowPlugin extends Plugin {
|
|
10
10
|
instructions: Registry<Instruction>;
|
|
11
11
|
triggers: Registry<Trigger>;
|
|
12
12
|
calculators: Registry<Function>;
|
|
13
13
|
extensions: typeof import("./extensions/assignees").default[];
|
|
14
|
+
executing: ExecutionModel | null;
|
|
15
|
+
pending: Pending[];
|
|
16
|
+
events: [WorkflowModel, any, {
|
|
17
|
+
context?: any;
|
|
18
|
+
}][];
|
|
14
19
|
onBeforeSave: (instance: WorkflowModel, options: any) => Promise<void>;
|
|
15
20
|
load(): Promise<void>;
|
|
16
21
|
toggle(workflow: WorkflowModel, enable?: boolean): void;
|
|
17
|
-
trigger(workflow: WorkflowModel, context: Object, options?:
|
|
22
|
+
trigger(workflow: WorkflowModel, context: Object, options?: {
|
|
18
23
|
context?: any;
|
|
19
|
-
}):
|
|
20
|
-
|
|
24
|
+
}): void;
|
|
25
|
+
private prepare;
|
|
26
|
+
resume(job: any): Promise<void>;
|
|
27
|
+
private dispatch;
|
|
28
|
+
private process;
|
|
29
|
+
private createProcessor;
|
|
21
30
|
}
|
|
31
|
+
export {};
|
package/lib/server/Plugin.js
CHANGED
|
@@ -67,6 +67,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
67
67
|
|
|
68
68
|
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; }
|
|
69
69
|
|
|
70
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
71
|
+
|
|
72
|
+
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."); }
|
|
73
|
+
|
|
74
|
+
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); }
|
|
75
|
+
|
|
76
|
+
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; }
|
|
77
|
+
|
|
78
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
79
|
+
|
|
80
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
81
|
+
|
|
70
82
|
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); } }
|
|
71
83
|
|
|
72
84
|
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); }); }; }
|
|
@@ -81,6 +93,9 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
81
93
|
this.triggers = new (_utils().Registry)();
|
|
82
94
|
this.calculators = _calculators.default;
|
|
83
95
|
this.extensions = _extensions.default;
|
|
96
|
+
this.executing = null;
|
|
97
|
+
this.pending = [];
|
|
98
|
+
this.events = [];
|
|
84
99
|
|
|
85
100
|
this.onBeforeSave = /*#__PURE__*/function () {
|
|
86
101
|
var _ref = _asyncToGenerator(function* (instance, options) {
|
|
@@ -134,6 +149,89 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
134
149
|
return _ref.apply(this, arguments);
|
|
135
150
|
};
|
|
136
151
|
}();
|
|
152
|
+
|
|
153
|
+
this.prepare = /*#__PURE__*/_asyncToGenerator(function* () {
|
|
154
|
+
var _options$context;
|
|
155
|
+
|
|
156
|
+
const event = _this.events.shift();
|
|
157
|
+
|
|
158
|
+
if (!event) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const _event = _slicedToArray(event, 3),
|
|
163
|
+
workflow = _event[0],
|
|
164
|
+
context = _event[1],
|
|
165
|
+
options = _event[2];
|
|
166
|
+
|
|
167
|
+
if ((_options$context = options.context) === null || _options$context === void 0 ? void 0 : _options$context.executionId) {
|
|
168
|
+
// NOTE: no transaction here for read-uncommitted execution
|
|
169
|
+
const existed = yield workflow.countExecutions({
|
|
170
|
+
where: {
|
|
171
|
+
id: options.context.executionId
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (existed) {
|
|
176
|
+
console.warn(`workflow ${workflow.id} has already been triggered in same execution (${options.context.executionId}), and newly triggering will be skipped.`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const execution = yield _this.db.sequelize.transaction( /*#__PURE__*/function () {
|
|
182
|
+
var _ref3 = _asyncToGenerator(function* (transaction) {
|
|
183
|
+
const execution = yield workflow.createExecution({
|
|
184
|
+
context,
|
|
185
|
+
key: workflow.key,
|
|
186
|
+
status: _constants.EXECUTION_STATUS.CREATED,
|
|
187
|
+
useTransaction: workflow.useTransaction
|
|
188
|
+
}, {
|
|
189
|
+
transaction
|
|
190
|
+
});
|
|
191
|
+
const executed = yield workflow.countExecutions({
|
|
192
|
+
transaction
|
|
193
|
+
}); // NOTE: not to trigger afterUpdate hook here
|
|
194
|
+
|
|
195
|
+
yield workflow.update({
|
|
196
|
+
executed
|
|
197
|
+
}, {
|
|
198
|
+
transaction,
|
|
199
|
+
hooks: false
|
|
200
|
+
});
|
|
201
|
+
const allExecuted = yield execution.constructor.count({
|
|
202
|
+
where: {
|
|
203
|
+
key: workflow.key
|
|
204
|
+
},
|
|
205
|
+
transaction
|
|
206
|
+
});
|
|
207
|
+
yield workflow.constructor.update({
|
|
208
|
+
allExecuted
|
|
209
|
+
}, {
|
|
210
|
+
where: {
|
|
211
|
+
key: workflow.key
|
|
212
|
+
},
|
|
213
|
+
individualHooks: true,
|
|
214
|
+
transaction
|
|
215
|
+
});
|
|
216
|
+
execution.workflow = workflow;
|
|
217
|
+
return execution;
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
return function (_x3) {
|
|
221
|
+
return _ref3.apply(this, arguments);
|
|
222
|
+
};
|
|
223
|
+
}()); // NOTE: cache first execution for most cases
|
|
224
|
+
|
|
225
|
+
if (!_this.executing && !_this.pending.length) {
|
|
226
|
+
_this.pending.push([execution]);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (_this.events.length) {
|
|
230
|
+
yield _this.prepare();
|
|
231
|
+
} else {
|
|
232
|
+
_this.dispatch();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
137
235
|
}
|
|
138
236
|
|
|
139
237
|
load() {
|
|
@@ -145,6 +243,15 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
145
243
|
yield db.import({
|
|
146
244
|
directory: _path().default.resolve(__dirname, 'collections')
|
|
147
245
|
});
|
|
246
|
+
|
|
247
|
+
_this2.db.addMigrations({
|
|
248
|
+
namespace: 'workflow',
|
|
249
|
+
directory: _path().default.resolve(__dirname, 'migrations'),
|
|
250
|
+
context: {
|
|
251
|
+
plugin: _this2
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
148
255
|
(0, _actions.default)(_this2);
|
|
149
256
|
(0, _triggers.default)(_this2, options.triggers);
|
|
150
257
|
(0, _instructions.default)(_this2, options.instructions);
|
|
@@ -152,8 +259,8 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
152
259
|
db.on('workflows.afterSave', model => _this2.toggle(model));
|
|
153
260
|
db.on('workflows.afterDestroy', model => _this2.toggle(model, false));
|
|
154
261
|
|
|
155
|
-
_this2.app.on('
|
|
156
|
-
|
|
262
|
+
_this2.app.on('afterLoad', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
263
|
+
_this2.extensions.reduce((promise, extend) => promise.then(() => extend(_this2)), Promise.resolve());
|
|
157
264
|
})); // [Life Cycle]:
|
|
158
265
|
// * load all workflows in db
|
|
159
266
|
// * add all hooks for enabled workflows
|
|
@@ -169,7 +276,9 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
169
276
|
});
|
|
170
277
|
workflows.forEach(workflow => {
|
|
171
278
|
_this2.toggle(workflow);
|
|
172
|
-
});
|
|
279
|
+
}); // check for not started executions
|
|
280
|
+
|
|
281
|
+
_this2.dispatch();
|
|
173
282
|
}));
|
|
174
283
|
|
|
175
284
|
_this2.app.on('beforeStop', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
@@ -205,81 +314,87 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
205
314
|
}
|
|
206
315
|
|
|
207
316
|
trigger(workflow, context, options = {}) {
|
|
317
|
+
// `null` means not to trigger
|
|
318
|
+
if (context == null) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
this.events.push([workflow, context, options]);
|
|
323
|
+
|
|
324
|
+
if (this.events.length > 1) {
|
|
325
|
+
return;
|
|
326
|
+
} // NOTE: no await for quick return
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
setTimeout(this.prepare);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
resume(job) {
|
|
208
333
|
var _this3 = this;
|
|
209
334
|
|
|
210
335
|
return _asyncToGenerator(function* () {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return null;
|
|
336
|
+
if (!job.execution) {
|
|
337
|
+
job.execution = yield job.getExecution();
|
|
214
338
|
}
|
|
215
339
|
|
|
216
|
-
|
|
340
|
+
_this3.pending.push([job.execution, job]);
|
|
217
341
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
342
|
+
_this3.dispatch();
|
|
343
|
+
})();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
dispatch() {
|
|
347
|
+
var _this4 = this;
|
|
348
|
+
|
|
349
|
+
return _asyncToGenerator(function* () {
|
|
350
|
+
if (_this4.executing) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
let next = null; // resuming has high priority
|
|
355
|
+
|
|
356
|
+
if (_this4.pending.length) {
|
|
357
|
+
next = _this4.pending.shift();
|
|
358
|
+
} else {
|
|
359
|
+
const execution = yield _this4.db.getRepository('executions').findOne({
|
|
360
|
+
filter: {
|
|
361
|
+
status: _constants.EXECUTION_STATUS.CREATED
|
|
224
362
|
},
|
|
225
|
-
|
|
363
|
+
sort: 'createdAt'
|
|
226
364
|
});
|
|
227
365
|
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
return null;
|
|
366
|
+
if (execution) {
|
|
367
|
+
next = [execution];
|
|
231
368
|
}
|
|
232
369
|
}
|
|
233
370
|
|
|
234
|
-
|
|
235
|
-
context,
|
|
236
|
-
key: workflow.key,
|
|
237
|
-
status: _constants.EXECUTION_STATUS.STARTED,
|
|
238
|
-
useTransaction: workflow.useTransaction,
|
|
239
|
-
transaction: transaction.id
|
|
240
|
-
}, {
|
|
241
|
-
transaction
|
|
242
|
-
});
|
|
243
|
-
console.log('workflow triggered:', new Date(), workflow.id, execution.id);
|
|
244
|
-
const executed = yield workflow.countExecutions({
|
|
245
|
-
transaction
|
|
246
|
-
}); // NOTE: not to trigger afterUpdate hook here
|
|
247
|
-
|
|
248
|
-
yield workflow.update({
|
|
249
|
-
executed
|
|
250
|
-
}, {
|
|
251
|
-
transaction,
|
|
252
|
-
hooks: false
|
|
253
|
-
});
|
|
254
|
-
const allExecuted = yield execution.constructor.count({
|
|
255
|
-
where: {
|
|
256
|
-
key: workflow.key
|
|
257
|
-
},
|
|
258
|
-
transaction
|
|
259
|
-
});
|
|
260
|
-
yield workflow.constructor.update({
|
|
261
|
-
allExecuted
|
|
262
|
-
}, {
|
|
263
|
-
where: {
|
|
264
|
-
key: workflow.key
|
|
265
|
-
},
|
|
266
|
-
individualHooks: true,
|
|
267
|
-
transaction
|
|
268
|
-
});
|
|
269
|
-
execution.workflow = workflow;
|
|
371
|
+
;
|
|
270
372
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
373
|
+
if (next) {
|
|
374
|
+
_this4.process(...next);
|
|
375
|
+
}
|
|
376
|
+
})();
|
|
377
|
+
}
|
|
275
378
|
|
|
276
|
-
|
|
379
|
+
process(execution, job) {
|
|
380
|
+
var _this5 = this;
|
|
277
381
|
|
|
278
|
-
|
|
279
|
-
|
|
382
|
+
return _asyncToGenerator(function* () {
|
|
383
|
+
_this5.executing = execution;
|
|
384
|
+
|
|
385
|
+
if (execution.status === _constants.EXECUTION_STATUS.CREATED) {
|
|
386
|
+
yield execution.update({
|
|
387
|
+
status: _constants.EXECUTION_STATUS.STARTED
|
|
388
|
+
});
|
|
280
389
|
}
|
|
281
390
|
|
|
282
|
-
|
|
391
|
+
const processor = _this5.createProcessor(execution);
|
|
392
|
+
|
|
393
|
+
console.log('workflow processing:', new Date(), execution.workflowId, execution.id);
|
|
394
|
+
yield job ? processor.resume(job) : processor.start();
|
|
395
|
+
_this5.executing = null;
|
|
396
|
+
|
|
397
|
+
_this5.dispatch();
|
|
283
398
|
})();
|
|
284
399
|
}
|
|
285
400
|
|
|
@@ -4,7 +4,6 @@ import ExecutionModel from './models/Execution';
|
|
|
4
4
|
import JobModel from './models/Job';
|
|
5
5
|
import FlowNodeModel from './models/FlowNode';
|
|
6
6
|
export interface ProcessorOptions extends Transactionable {
|
|
7
|
-
_context?: any;
|
|
8
7
|
plugin: Plugin;
|
|
9
8
|
}
|
|
10
9
|
export default class Processor {
|
|
@@ -24,7 +23,7 @@ export default class Processor {
|
|
|
24
23
|
private makeNodes;
|
|
25
24
|
private makeJobs;
|
|
26
25
|
private getTransaction;
|
|
27
|
-
prepare
|
|
26
|
+
private prepare;
|
|
28
27
|
start(): Promise<void>;
|
|
29
28
|
resume(job: JobModel): Promise<void>;
|
|
30
29
|
private commit;
|
package/lib/server/Processor.js
CHANGED
|
@@ -101,25 +101,13 @@ class Processor {
|
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const options = _this.options;
|
|
105
|
-
const sequelize = _this.execution.constructor.database.sequelize; // @ts-ignore
|
|
104
|
+
const options = _this.options; // @ts-ignore
|
|
106
105
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (_this.execution.transaction !== transaction.id) {
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
yield _this.execution.update({
|
|
112
|
-
transaction: transaction.id
|
|
113
|
-
}, {
|
|
114
|
-
transaction
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return transaction;
|
|
106
|
+
return options.transaction && !options.transaction.finished ? options.transaction : yield options.plugin.db.sequelize.transaction();
|
|
119
107
|
})();
|
|
120
108
|
}
|
|
121
109
|
|
|
122
|
-
prepare(
|
|
110
|
+
prepare() {
|
|
123
111
|
var _this2 = this;
|
|
124
112
|
|
|
125
113
|
return _asyncToGenerator(function* () {
|
|
@@ -145,10 +133,6 @@ class Processor {
|
|
|
145
133
|
});
|
|
146
134
|
|
|
147
135
|
_this2.makeJobs(jobs);
|
|
148
|
-
|
|
149
|
-
if (commit) {
|
|
150
|
-
yield _this2.commit();
|
|
151
|
-
}
|
|
152
136
|
})();
|
|
153
137
|
}
|
|
154
138
|
|
|
@@ -31,10 +31,9 @@ function _submit() {
|
|
|
31
31
|
});
|
|
32
32
|
context.status = 202;
|
|
33
33
|
yield next();
|
|
34
|
-
const plugin = context.app.pm.get('workflow');
|
|
35
|
-
const processor = plugin.createProcessor(instance.execution); // NOTE: resume the process and no `await` for quick returning
|
|
34
|
+
const plugin = context.app.pm.get('workflow'); // NOTE: resume the process and no `await` for quick returning
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
plugin.resume(instance);
|
|
38
37
|
});
|
|
39
38
|
return _submit.apply(this, arguments);
|
|
40
39
|
}
|
|
@@ -138,23 +138,31 @@ function _revision() {
|
|
|
138
138
|
|
|
139
139
|
const repository = _actions().utils.getRepositoryFromParams(context);
|
|
140
140
|
|
|
141
|
-
const
|
|
141
|
+
const _context$action$param2 = context.action.params,
|
|
142
|
+
filterByTk = _context$action$param2.filterByTk,
|
|
143
|
+
_context$action$param3 = _context$action$param2.filter,
|
|
144
|
+
filter = _context$action$param3 === void 0 ? {} : _context$action$param3;
|
|
142
145
|
context.body = yield db.sequelize.transaction( /*#__PURE__*/function () {
|
|
143
146
|
var _ref = _asyncToGenerator(function* (transaction) {
|
|
144
147
|
const origin = yield repository.findOne({
|
|
145
148
|
filterByTk,
|
|
149
|
+
filter,
|
|
146
150
|
appends: ['nodes'],
|
|
147
151
|
context,
|
|
148
152
|
transaction
|
|
149
153
|
});
|
|
154
|
+
const revisionData = filter.key ? {
|
|
155
|
+
key: filter.key,
|
|
156
|
+
title: origin.title,
|
|
157
|
+
allExecuted: origin.allExecuted
|
|
158
|
+
} : {};
|
|
150
159
|
const instance = yield repository.create({
|
|
151
|
-
values: {
|
|
152
|
-
|
|
153
|
-
title: origin.title,
|
|
160
|
+
values: _objectSpread({
|
|
161
|
+
title: `${origin.title} copy`,
|
|
154
162
|
description: origin.description,
|
|
155
163
|
type: origin.type,
|
|
156
164
|
config: origin.config
|
|
157
|
-
},
|
|
165
|
+
}, revisionData),
|
|
158
166
|
transaction
|
|
159
167
|
});
|
|
160
168
|
const originalNodesMap = new Map();
|
|
@@ -5,6 +5,7 @@ export declare const calculators: Registry<Function>;
|
|
|
5
5
|
export default calculators;
|
|
6
6
|
export declare type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';
|
|
7
7
|
export declare type ObjectGetterOptions = {
|
|
8
|
+
type?: string;
|
|
8
9
|
path?: string;
|
|
9
10
|
};
|
|
10
11
|
export declare type JobGetterOptions = ObjectGetterOptions & {
|
|
@@ -14,6 +15,7 @@ export declare type CalculationOptions = {
|
|
|
14
15
|
calculator: string;
|
|
15
16
|
operands: Operand[];
|
|
16
17
|
};
|
|
18
|
+
export declare type ValueOperand = string | number | boolean | null | Date;
|
|
17
19
|
export declare type ConstantOperand = {
|
|
18
20
|
type?: 'constant';
|
|
19
21
|
value: any;
|
|
@@ -34,5 +36,5 @@ export declare type Calculation = {
|
|
|
34
36
|
type: '$calculation';
|
|
35
37
|
options: CalculationOptions;
|
|
36
38
|
};
|
|
37
|
-
export declare type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;
|
|
38
|
-
export declare function calculate(operand:
|
|
39
|
+
export declare type Operand = ValueOperand | ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;
|
|
40
|
+
export declare function calculate(operand: any, lastJob: JobModel, processor: Processor): any;
|
|
@@ -44,17 +44,19 @@ function get(object, path) {
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
function calculate(operand, lastJob, processor) {
|
|
47
|
+
if (typeof operand !== 'object' || operand == null) {
|
|
48
|
+
return operand;
|
|
49
|
+
} // @Deprecated
|
|
50
|
+
|
|
51
|
+
|
|
47
52
|
switch (operand.type) {
|
|
48
|
-
// @Deprecated
|
|
49
53
|
// from execution context
|
|
50
54
|
case '$context':
|
|
51
|
-
return get(processor.execution.context, operand.options.path);
|
|
52
|
-
// @Deprecated
|
|
55
|
+
return get(processor.execution.context, [operand.options.type, operand.options.path].filter(Boolean).join('.'));
|
|
53
56
|
// from last job (or input job)
|
|
54
57
|
|
|
55
58
|
case '$input':
|
|
56
59
|
return lastJob !== null && lastJob !== void 0 ? lastJob : get(lastJob.result, operand.options.path);
|
|
57
|
-
// @Deprecated
|
|
58
60
|
// from job in execution
|
|
59
61
|
|
|
60
62
|
case '$jobsMapByNodeId':
|
package/lib/server/constants.js
CHANGED
|
@@ -67,10 +67,9 @@ function _submit() {
|
|
|
67
67
|
context.status = 202;
|
|
68
68
|
yield next();
|
|
69
69
|
instance.job.latestUserJob = instance;
|
|
70
|
-
const plugin = context.app.pm.get('workflow');
|
|
71
|
-
const processor = plugin.createProcessor(instance.execution); // NOTE: resume the process and no `await` for quick returning
|
|
70
|
+
const plugin = context.app.pm.get('workflow'); // NOTE: resume the process and no `await` for quick returning
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
plugin.resume(instance.job);
|
|
74
73
|
});
|
|
75
74
|
return _submit.apply(this, arguments);
|
|
76
75
|
}
|
|
@@ -7,10 +7,18 @@ exports.default = void 0;
|
|
|
7
7
|
var _default = {
|
|
8
8
|
name: 'users_jobs',
|
|
9
9
|
fields: [{
|
|
10
|
-
type: '
|
|
10
|
+
type: 'bigInt',
|
|
11
11
|
name: 'id',
|
|
12
12
|
primaryKey: true,
|
|
13
13
|
autoIncrement: true
|
|
14
|
+
}, {
|
|
15
|
+
type: 'bigInt',
|
|
16
|
+
name: 'userId',
|
|
17
|
+
primaryKey: false
|
|
18
|
+
}, {
|
|
19
|
+
type: 'bigInt',
|
|
20
|
+
name: 'jobId',
|
|
21
|
+
primaryKey: false
|
|
14
22
|
}, {
|
|
15
23
|
type: 'belongsTo',
|
|
16
24
|
name: 'job'
|
package/lib/server/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './calculators';
|
|
2
1
|
export * from './constants';
|
|
3
|
-
export * from './
|
|
4
|
-
export
|
|
5
|
-
export
|
|
2
|
+
export * from './calculators';
|
|
3
|
+
export { Trigger } from './triggers';
|
|
4
|
+
export { default as Processor } from './Processor';
|
|
6
5
|
export { default } from './Plugin';
|
package/lib/server/index.js
CHANGED
|
@@ -3,7 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
Trigger: true,
|
|
8
|
+
Processor: true
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "Processor", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _Processor.default;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "Trigger", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function get() {
|
|
19
|
+
return _triggers.Trigger;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
7
22
|
Object.defineProperty(exports, "default", {
|
|
8
23
|
enumerable: true,
|
|
9
24
|
get: function get() {
|
|
@@ -11,20 +26,6 @@ Object.defineProperty(exports, "default", {
|
|
|
11
26
|
}
|
|
12
27
|
});
|
|
13
28
|
|
|
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
29
|
var _constants = require("./constants");
|
|
29
30
|
|
|
30
31
|
Object.keys(_constants).forEach(function (key) {
|
|
@@ -39,47 +40,23 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
var
|
|
43
|
+
var _calculators = require("./calculators");
|
|
43
44
|
|
|
44
|
-
Object.keys(
|
|
45
|
+
Object.keys(_calculators).forEach(function (key) {
|
|
45
46
|
if (key === "default" || key === "__esModule") return;
|
|
46
47
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
47
|
-
if (key in exports && exports[key] ===
|
|
48
|
+
if (key in exports && exports[key] === _calculators[key]) return;
|
|
48
49
|
Object.defineProperty(exports, key, {
|
|
49
50
|
enumerable: true,
|
|
50
51
|
get: function get() {
|
|
51
|
-
return
|
|
52
|
+
return _calculators[key];
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
var _triggers = require("./triggers");
|
|
57
58
|
|
|
58
|
-
|
|
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
|
-
});
|
|
59
|
+
var _Processor = _interopRequireDefault(require("./Processor"));
|
|
83
60
|
|
|
84
61
|
var _Plugin = _interopRequireDefault(require("./Plugin"));
|
|
85
62
|
|
|
@@ -80,7 +80,7 @@ var _default = {
|
|
|
80
80
|
calculation = _ref.calculation,
|
|
81
81
|
rejectOnFalse = _ref.rejectOnFalse;
|
|
82
82
|
|
|
83
|
-
const result = logicCalculate(calculation, prevJob, processor);
|
|
83
|
+
const result = logicCalculate(processor.getParsedValue(calculation), prevJob, processor);
|
|
84
84
|
|
|
85
85
|
if (!result && rejectOnFalse) {
|
|
86
86
|
return {
|