@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.
Files changed (95) hide show
  1. package/lib/client/AddButton.js +21 -13
  2. package/lib/client/ExecutionCanvas.js +10 -24
  3. package/lib/client/ExecutionResourceProvider.d.ts +2 -1
  4. package/lib/client/ExecutionResourceProvider.js +4 -3
  5. package/lib/client/FlowContext.js +1 -1
  6. package/lib/client/WorkflowCanvas.js +136 -39
  7. package/lib/client/WorkflowProvider.d.ts +3 -0
  8. package/lib/client/WorkflowProvider.js +71 -16
  9. package/lib/client/WorkflowShortcut.d.ts +0 -1
  10. package/lib/client/WorkflowShortcut.js +4 -47
  11. package/lib/client/calculators.d.ts +27 -37
  12. package/lib/client/calculators.js +168 -150
  13. package/lib/client/components/CollectionFieldset.js +10 -20
  14. package/lib/client/components/Duration.js +3 -14
  15. package/lib/client/components/EjsTextArea.d.ts +2 -0
  16. package/lib/client/components/EjsTextArea.js +232 -0
  17. package/lib/client/components/OpenDrawer.d.ts +6 -0
  18. package/lib/client/components/OpenDrawer.js +93 -0
  19. package/lib/client/constants.js +11 -9
  20. package/lib/client/index.d.ts +1 -0
  21. package/lib/client/index.js +14 -0
  22. package/lib/client/locale/en-US.d.ts +105 -0
  23. package/lib/client/locale/en-US.js +111 -0
  24. package/lib/client/locale/index.d.ts +3 -0
  25. package/lib/client/locale/index.js +69 -0
  26. package/lib/client/locale/ja-JP.d.ts +88 -0
  27. package/lib/client/locale/ja-JP.js +94 -0
  28. package/lib/client/locale/ru-RU.d.ts +88 -0
  29. package/lib/client/locale/ru-RU.js +94 -0
  30. package/lib/client/locale/tr-TR.d.ts +88 -0
  31. package/lib/client/locale/tr-TR.js +94 -0
  32. package/lib/client/locale/zh-CN.d.ts +130 -0
  33. package/lib/client/locale/zh-CN.js +136 -0
  34. package/lib/client/nodes/calculation.d.ts +0 -1
  35. package/lib/client/nodes/calculation.js +9 -17
  36. package/lib/client/nodes/condition.js +16 -22
  37. package/lib/client/nodes/create.d.ts +3 -1
  38. package/lib/client/nodes/create.js +11 -11
  39. package/lib/client/nodes/delay.js +8 -6
  40. package/lib/client/nodes/index.js +46 -14
  41. package/lib/client/nodes/parallel.d.ts +0 -1
  42. package/lib/client/nodes/parallel.js +11 -32
  43. package/lib/client/nodes/query.js +9 -17
  44. package/lib/client/nodes/request.d.ts +138 -0
  45. package/lib/client/nodes/request.js +167 -0
  46. package/lib/client/nodes/update.js +4 -2
  47. package/lib/client/schemas/collection.js +3 -1
  48. package/lib/client/schemas/executions.d.ts +211 -207
  49. package/lib/client/schemas/executions.js +102 -96
  50. package/lib/client/schemas/workflows.js +112 -22
  51. package/lib/client/style.js +7 -7
  52. package/lib/client/triggers/collection.d.ts +2 -1
  53. package/lib/client/triggers/collection.js +49 -34
  54. package/lib/client/triggers/index.d.ts +4 -6
  55. package/lib/client/triggers/index.js +57 -51
  56. package/lib/client/triggers/schedule/EndsByField.js +13 -39
  57. package/lib/client/triggers/schedule/OnField.js +10 -5
  58. package/lib/client/triggers/schedule/RepeatField.js +6 -14
  59. package/lib/client/triggers/schedule/ScheduleConfig.js +25 -20
  60. package/lib/client/triggers/schedule/constants.d.ts +4 -0
  61. package/lib/client/triggers/schedule/constants.js +11 -0
  62. package/lib/client/triggers/schedule/index.d.ts +2 -3
  63. package/lib/client/triggers/schedule/index.js +55 -40
  64. package/lib/server/Plugin.d.ts +15 -5
  65. package/lib/server/Plugin.js +176 -61
  66. package/lib/server/Processor.d.ts +1 -2
  67. package/lib/server/Processor.js +3 -19
  68. package/lib/server/actions/jobs.js +2 -3
  69. package/lib/server/actions/workflows.js +13 -5
  70. package/lib/server/calculators/index.d.ts +4 -2
  71. package/lib/server/calculators/index.js +6 -4
  72. package/lib/server/collections/executions.js +2 -1
  73. package/lib/server/constants.d.ts +1 -0
  74. package/lib/server/constants.js +1 -0
  75. package/lib/server/extensions/assignees/actions.js +2 -3
  76. package/lib/server/extensions/assignees/collections/users_jobs.js +9 -1
  77. package/lib/server/index.d.ts +3 -4
  78. package/lib/server/index.js +21 -44
  79. package/lib/server/instructions/condition.js +1 -1
  80. package/lib/server/instructions/create.js +3 -1
  81. package/lib/server/instructions/delay.js +2 -3
  82. package/lib/server/instructions/destroy.js +3 -1
  83. package/lib/server/instructions/index.d.ts +3 -2
  84. package/lib/server/instructions/index.js +1 -1
  85. package/lib/server/instructions/prompt.js +2 -1
  86. package/lib/server/instructions/query.js +3 -1
  87. package/lib/server/instructions/request.d.ts +14 -0
  88. package/lib/server/instructions/request.js +154 -0
  89. package/lib/server/instructions/update.d.ts +1 -1
  90. package/lib/server/instructions/update.js +3 -1
  91. package/lib/server/migrations/20221129153547-calculation-variables.d.ts +5 -0
  92. package/lib/server/migrations/20221129153547-calculation-variables.js +116 -0
  93. package/lib/server/triggers/collection.js +5 -7
  94. package/lib/server/triggers/schedule.js +17 -6
  95. package/package.json +13 -8
@@ -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?: Transactionable & {
22
+ trigger(workflow: WorkflowModel, context: Object, options?: {
18
23
  context?: any;
19
- }): Promise<ExecutionModel | null>;
20
- createProcessor(execution: ExecutionModel, options?: {}): Processor;
24
+ }): void;
25
+ private prepare;
26
+ resume(job: any): Promise<void>;
27
+ private dispatch;
28
+ private process;
29
+ private createProcessor;
21
30
  }
31
+ export {};
@@ -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('afterLoadAll', /*#__PURE__*/_asyncToGenerator(function* () {
156
- return _this2.extensions.reduce((promise, extend) => promise.then(() => extend(_this2)), Promise.resolve());
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
- // `null` means not to trigger
212
- if (context === null) {
213
- return null;
336
+ if (!job.execution) {
337
+ job.execution = yield job.getExecution();
214
338
  }
215
339
 
216
- let transaction = null;
340
+ _this3.pending.push([job.execution, job]);
217
341
 
218
- if (workflow.useTransaction) {
219
- // @ts-ignore
220
- transaction = options.transaction && !options.transaction.finished ? options.transaction : yield workflow.constructor.database.sequelize.transaction();
221
- const existed = yield workflow.countExecutions({
222
- where: {
223
- transaction: transaction.id
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
- transaction
363
+ sort: 'createdAt'
226
364
  });
227
365
 
228
- if (existed) {
229
- console.warn(`workflow ${workflow.id} has already been triggered in same execution (${transaction.id}), and newly triggering will be skipped.`);
230
- return null;
366
+ if (execution) {
367
+ next = [execution];
231
368
  }
232
369
  }
233
370
 
234
- const execution = yield workflow.createExecution({
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
- const processor = _this3.createProcessor(execution, {
272
- transaction,
273
- _context: options.context
274
- });
373
+ if (next) {
374
+ _this4.process(...next);
375
+ }
376
+ })();
377
+ }
275
378
 
276
- yield processor.start(); // @ts-ignore
379
+ process(execution, job) {
380
+ var _this5 = this;
277
381
 
278
- if (transaction && (!options.transaction || options.transaction.finished)) {
279
- yield transaction.commit();
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
- return execution;
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(commit?: boolean): Promise<void>;
26
+ private prepare;
28
27
  start(): Promise<void>;
29
28
  resume(job: JobModel): Promise<void>;
30
29
  private commit;
@@ -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
- const transaction = options.transaction && !options.transaction.finished ? options.transaction : yield sequelize.transaction(); // @ts-ignore
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(commit) {
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
- processor.resume(instance);
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 filterByTk = context.action.params.filterByTk;
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
- key: origin.key,
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: Operand, lastJob: JobModel, processor: Processor): any;
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':
@@ -16,7 +16,8 @@ var _default = {
16
16
  type: 'boolean',
17
17
  name: 'useTransaction',
18
18
  defaultValue: false
19
- }, {
19
+ }, // @deprecated
20
+ {
20
21
  type: 'uuid',
21
22
  name: 'transaction',
22
23
  defaultValue: null
@@ -1,4 +1,5 @@
1
1
  export declare const EXECUTION_STATUS: {
2
+ CREATED: any;
2
3
  STARTED: number;
3
4
  RESOLVED: number;
4
5
  REJECTED: number;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.JOB_STATUS = exports.EXECUTION_STATUS = exports.BRANCH_INDEX = void 0;
7
7
  const EXECUTION_STATUS = {
8
+ CREATED: null,
8
9
  STARTED: 0,
9
10
  RESOLVED: 1,
10
11
  REJECTED: -1,
@@ -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
- processor.resume(instance.job);
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: 'integer',
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'
@@ -1,6 +1,5 @@
1
- export * from './calculators';
2
1
  export * from './constants';
3
- export * from './instructions';
4
- export * from './triggers';
5
- export * from './Processor';
2
+ export * from './calculators';
3
+ export { Trigger } from './triggers';
4
+ export { default as Processor } from './Processor';
6
5
  export { default } from './Plugin';
@@ -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 _instructions = require("./instructions");
43
+ var _calculators = require("./calculators");
43
44
 
44
- Object.keys(_instructions).forEach(function (key) {
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] === _instructions[key]) return;
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 _instructions[key];
52
+ return _calculators[key];
52
53
  }
53
54
  });
54
55
  });
55
56
 
56
57
  var _triggers = require("./triggers");
57
58
 
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
- });
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 {