@nocobase/plugin-workflow 0.7.0-alpha.83 → 0.7.1-alpha.5

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 (47) hide show
  1. package/lib/Plugin.d.ts +18 -0
  2. package/lib/Plugin.js +285 -0
  3. package/lib/Processor.d.ts +40 -0
  4. package/lib/Processor.js +440 -0
  5. package/lib/actions/workflows.d.ts +1 -2
  6. package/lib/actions/workflows.js +13 -87
  7. package/lib/calculators/index.d.ts +2 -2
  8. package/lib/calculators/index.js +4 -4
  9. package/lib/collections/executions.js +7 -15
  10. package/lib/collections/jobs.js +7 -26
  11. package/lib/collections/workflows.d.ts +1 -2
  12. package/lib/collections/workflows.js +67 -67
  13. package/lib/index.d.ts +4 -3
  14. package/lib/index.js +24 -10
  15. package/lib/instructions/calculation.d.ts +1 -1
  16. package/lib/instructions/calculation.js +4 -6
  17. package/lib/instructions/condition.d.ts +2 -2
  18. package/lib/instructions/condition.js +15 -19
  19. package/lib/instructions/create.d.ts +1 -1
  20. package/lib/instructions/create.js +8 -12
  21. package/lib/instructions/delay.d.ts +14 -0
  22. package/lib/instructions/delay.js +138 -0
  23. package/lib/instructions/destroy.d.ts +1 -1
  24. package/lib/instructions/destroy.js +8 -12
  25. package/lib/instructions/index.d.ts +11 -8
  26. package/lib/instructions/index.js +43 -13
  27. package/lib/instructions/parallel.d.ts +3 -3
  28. package/lib/instructions/parallel.js +15 -19
  29. package/lib/instructions/prompt.d.ts +2 -2
  30. package/lib/instructions/prompt.js +2 -2
  31. package/lib/instructions/query.d.ts +2 -1
  32. package/lib/instructions/query.js +9 -13
  33. package/lib/instructions/update.d.ts +2 -2
  34. package/lib/instructions/update.js +10 -14
  35. package/lib/models/Execution.d.ts +2 -33
  36. package/lib/models/Execution.js +2 -397
  37. package/lib/models/Workflow.d.ts +2 -2
  38. package/lib/models/Workflow.js +1 -81
  39. package/lib/triggers/collection.d.ts +2 -6
  40. package/lib/triggers/collection.js +62 -27
  41. package/lib/triggers/index.d.ts +11 -4
  42. package/lib/triggers/index.js +52 -5
  43. package/lib/triggers/schedule.d.ts +4 -7
  44. package/lib/triggers/schedule.js +205 -135
  45. package/package.json +8 -9
  46. package/lib/server.d.ts +0 -10
  47. package/lib/server.js +0 -124
@@ -0,0 +1,440 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _jsonTemplates() {
9
+ const data = _interopRequireDefault(require("json-templates"));
10
+
11
+ _jsonTemplates = function _jsonTemplates() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _database() {
19
+ const data = require("@nocobase/database");
20
+
21
+ _database = function _database() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ var _calculators = _interopRequireDefault(require("./calculators"));
29
+
30
+ var _constants = require("./constants");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ 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
+
36
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
37
+
38
+ 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."); }
39
+
40
+ 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); }
41
+
42
+ 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; }
43
+
44
+ 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; }
45
+
46
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
47
+
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
+ 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
+
56
+ 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); }); }; }
57
+
58
+ class Processor {
59
+ constructor(execution, options) {
60
+ this.execution = void 0;
61
+ this.options = void 0;
62
+ this.transaction = void 0;
63
+ this.nodes = [];
64
+ this.nodesMap = new Map();
65
+ this.jobsMap = new Map();
66
+ this.jobsMapByNodeId = {};
67
+ this.execution = execution;
68
+ this.options = options;
69
+ } // make dual linked nodes list then cache
70
+
71
+
72
+ makeNodes(nodes = []) {
73
+ this.nodes = nodes;
74
+ nodes.forEach(node => {
75
+ this.nodesMap.set(node.id, node);
76
+ });
77
+ nodes.forEach(node => {
78
+ if (node.upstreamId) {
79
+ node.upstream = this.nodesMap.get(node.upstreamId);
80
+ }
81
+
82
+ if (node.downstreamId) {
83
+ node.downstream = this.nodesMap.get(node.downstreamId);
84
+ }
85
+ });
86
+ }
87
+
88
+ makeJobs(jobs) {
89
+ jobs.forEach(job => {
90
+ this.jobsMap.set(job.id, job); // TODO: should consider cycle, and from previous job
91
+
92
+ this.jobsMapByNodeId[job.nodeId] = job.result;
93
+ });
94
+ }
95
+
96
+ getTransaction() {
97
+ var _this = this;
98
+
99
+ return _asyncToGenerator(function* () {
100
+ if (!_this.execution.useTransaction) {
101
+ return;
102
+ }
103
+
104
+ const options = _this.options;
105
+ const sequelize = _this.execution.constructor.database.sequelize; // @ts-ignore
106
+
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;
119
+ })();
120
+ }
121
+
122
+ prepare(commit) {
123
+ var _this2 = this;
124
+
125
+ return _asyncToGenerator(function* () {
126
+ const transaction = yield _this2.getTransaction();
127
+ _this2.transaction = transaction;
128
+ const execution = _this2.execution;
129
+
130
+ if (!execution.workflow) {
131
+ execution.workflow = yield execution.getWorkflow({
132
+ transaction
133
+ });
134
+ }
135
+
136
+ const nodes = yield execution.workflow.getNodes({
137
+ transaction
138
+ });
139
+
140
+ _this2.makeNodes(nodes);
141
+
142
+ const jobs = yield execution.getJobs({
143
+ order: [['id', 'ASC']],
144
+ transaction
145
+ });
146
+
147
+ _this2.makeJobs(jobs);
148
+
149
+ if (commit) {
150
+ yield _this2.commit();
151
+ }
152
+ })();
153
+ }
154
+
155
+ start() {
156
+ var _this3 = this;
157
+
158
+ return _asyncToGenerator(function* () {
159
+ const execution = _this3.execution;
160
+
161
+ if (execution.status !== _constants.EXECUTION_STATUS.STARTED) {
162
+ throw new Error(`execution was ended with status ${execution.status}`);
163
+ }
164
+
165
+ yield _this3.prepare();
166
+
167
+ if (_this3.nodes.length) {
168
+ const head = _this3.nodes.find(item => !item.upstream);
169
+
170
+ yield _this3.run(head, {
171
+ result: execution.context
172
+ });
173
+ } else {
174
+ yield _this3.exit(null);
175
+ }
176
+
177
+ yield _this3.commit();
178
+ })();
179
+ }
180
+
181
+ resume(job) {
182
+ var _this4 = this;
183
+
184
+ return _asyncToGenerator(function* () {
185
+ const execution = _this4.execution;
186
+
187
+ if (execution.status !== _constants.EXECUTION_STATUS.STARTED) {
188
+ throw new Error(`execution was ended with status ${execution.status}`);
189
+ }
190
+
191
+ yield _this4.prepare();
192
+
193
+ const node = _this4.nodesMap.get(job.nodeId);
194
+
195
+ yield _this4.recall(node, job);
196
+ yield _this4.commit();
197
+ })();
198
+ }
199
+
200
+ commit() {
201
+ var _this5 = this;
202
+
203
+ return _asyncToGenerator(function* () {
204
+ // @ts-ignore
205
+ if (_this5.transaction && (!_this5.options.transaction || _this5.options.transaction.finished)) {
206
+ yield _this5.transaction.commit();
207
+ }
208
+ })();
209
+ }
210
+
211
+ exec(instruction, node, prevJob) {
212
+ var _this6 = this;
213
+
214
+ return _asyncToGenerator(function* () {
215
+ let job;
216
+
217
+ try {
218
+ // call instruction to get result and status
219
+ job = yield instruction(node, prevJob, _this6);
220
+
221
+ if (!job) {
222
+ return null;
223
+ }
224
+ } catch (err) {
225
+ // for uncaught error, set to rejected
226
+ job = {
227
+ result: err instanceof Error ? {
228
+ message: err.message,
229
+ stack: process.env.NODE_ENV === 'production' ? [] : err.stack
230
+ } : err,
231
+ status: _constants.JOB_STATUS.REJECTED
232
+ }; // if previous job is from resuming
233
+
234
+ if (prevJob && prevJob.nodeId === node.id) {
235
+ prevJob.set(job);
236
+ job = prevJob;
237
+ }
238
+ }
239
+
240
+ let savedJob; // TODO(optimize): many checking of resuming or new could be improved
241
+ // could be implemented separately in exec() / resume()
242
+
243
+ if (job instanceof _database().Model) {
244
+ savedJob = yield job.save({
245
+ transaction: _this6.transaction
246
+ });
247
+ } else {
248
+ const upstreamId = prevJob instanceof _database().Model ? prevJob.get('id') : null;
249
+ savedJob = yield _this6.saveJob(_objectSpread({
250
+ nodeId: node.id,
251
+ upstreamId
252
+ }, job));
253
+ }
254
+
255
+ if (savedJob.status === _constants.JOB_STATUS.RESOLVED && node.downstream) {
256
+ // run next node
257
+ return _this6.run(node.downstream, savedJob);
258
+ } // all nodes in scope have been executed
259
+
260
+
261
+ return _this6.end(node, savedJob);
262
+ })();
263
+ }
264
+
265
+ run(node, input) {
266
+ var _this7 = this;
267
+
268
+ return _asyncToGenerator(function* () {
269
+ const instructions = _this7.options.plugin.instructions;
270
+
271
+ const _instructions$get = instructions.get(node.type),
272
+ run = _instructions$get.run;
273
+
274
+ if (typeof run !== 'function') {
275
+ return Promise.reject(new Error('`run` should be implemented for customized execution of the node'));
276
+ }
277
+
278
+ return _this7.exec(run, node, input);
279
+ })();
280
+ } // parent node should take over the control
281
+
282
+
283
+ end(node, job) {
284
+ const parentNode = this.findBranchParentNode(node); // no parent, means on main flow
285
+
286
+ if (parentNode) {
287
+ return this.recall(parentNode, job);
288
+ } // really done for all nodes
289
+ // * should mark execution as done with last job status
290
+
291
+
292
+ return this.exit(job);
293
+ }
294
+
295
+ recall(node, job) {
296
+ var _this8 = this;
297
+
298
+ return _asyncToGenerator(function* () {
299
+ const instructions = _this8.options.plugin.instructions;
300
+
301
+ const _instructions$get2 = instructions.get(node.type),
302
+ resume = _instructions$get2.resume;
303
+
304
+ if (typeof resume !== 'function') {
305
+ return Promise.reject(new Error('`resume` should be implemented'));
306
+ }
307
+
308
+ return _this8.exec(resume, node, job);
309
+ })();
310
+ }
311
+
312
+ exit(job) {
313
+ var _this9 = this;
314
+
315
+ return _asyncToGenerator(function* () {
316
+ const status = job ? _this9.constructor.StatusMap[job.status] : _constants.EXECUTION_STATUS.RESOLVED;
317
+ yield _this9.execution.update({
318
+ status
319
+ }, {
320
+ transaction: _this9.transaction
321
+ });
322
+ return null;
323
+ })();
324
+ } // TODO(optimize)
325
+
326
+
327
+ saveJob(payload) {
328
+ var _this10 = this;
329
+
330
+ return _asyncToGenerator(function* () {
331
+ const database = _this10.execution.constructor.database;
332
+
333
+ const _database$getCollecti = database.getCollection('jobs'),
334
+ model = _database$getCollecti.model;
335
+
336
+ let job;
337
+
338
+ if (payload instanceof model) {
339
+ job = yield payload.save({
340
+ transaction: _this10.transaction
341
+ });
342
+ } else if (payload.id) {
343
+ var _yield$model$update = yield model.update(payload, {
344
+ where: {
345
+ id: payload.id
346
+ },
347
+ returning: true,
348
+ transaction: _this10.transaction
349
+ });
350
+
351
+ var _yield$model$update2 = _slicedToArray(_yield$model$update, 1);
352
+
353
+ job = _yield$model$update2[0];
354
+ } else {
355
+ job = yield model.create(_objectSpread(_objectSpread({}, payload), {}, {
356
+ executionId: _this10.execution.id
357
+ }), {
358
+ transaction: _this10.transaction
359
+ });
360
+ }
361
+
362
+ _this10.jobsMap.set(job.id, job);
363
+
364
+ _this10.jobsMapByNodeId[job.nodeId] = job.result;
365
+ return job;
366
+ })();
367
+ } // find the first node in current branch
368
+
369
+
370
+ findBranchStartNode(node) {
371
+ for (let n = node; n; n = n.upstream) {
372
+ if (n.branchIndex !== null) {
373
+ return n;
374
+ }
375
+ }
376
+
377
+ return null;
378
+ } // find the node start current branch
379
+
380
+
381
+ findBranchParentNode(node) {
382
+ for (let n = node; n; n = n.upstream) {
383
+ if (n.branchIndex !== null) {
384
+ return n.upstream;
385
+ }
386
+ }
387
+
388
+ return null;
389
+ }
390
+
391
+ findBranchParentJob(job, node) {
392
+ for (let j = job; j; j = this.jobsMap.get(j.upstreamId)) {
393
+ if (j.nodeId === node.id) {
394
+ return j;
395
+ }
396
+ }
397
+
398
+ return null;
399
+ }
400
+
401
+ getParsedValue(value, node) {
402
+ const injectedFns = {};
403
+ const scope = {
404
+ execution: this.execution,
405
+ node
406
+ };
407
+
408
+ var _iterator = _createForOfIteratorHelper(_calculators.default.getEntities()),
409
+ _step;
410
+
411
+ try {
412
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
413
+ let _step$value = _slicedToArray(_step.value, 2),
414
+ name = _step$value[0],
415
+ fn = _step$value[1];
416
+
417
+ injectedFns[name] = fn.bind(scope);
418
+ }
419
+ } catch (err) {
420
+ _iterator.e(err);
421
+ } finally {
422
+ _iterator.f();
423
+ }
424
+
425
+ return (0, _jsonTemplates().default)(value)({
426
+ $context: this.execution.context,
427
+ $jobsMapByNodeId: this.jobsMapByNodeId,
428
+ $fn: injectedFns
429
+ });
430
+ }
431
+
432
+ }
433
+
434
+ exports.default = Processor;
435
+ Processor.StatusMap = {
436
+ [_constants.JOB_STATUS.PENDING]: _constants.EXECUTION_STATUS.STARTED,
437
+ [_constants.JOB_STATUS.RESOLVED]: _constants.EXECUTION_STATUS.RESOLVED,
438
+ [_constants.JOB_STATUS.REJECTED]: _constants.EXECUTION_STATUS.REJECTED,
439
+ [_constants.JOB_STATUS.CANCELLED]: _constants.EXECUTION_STATUS.CANCELLED
440
+ };
@@ -1,3 +1,2 @@
1
1
  import { Context } from '@nocobase/actions';
2
- export declare function update(context: Context, next: any): Promise<void>;
3
- export declare function duplicate(context: Context, next: any): Promise<void>;
2
+ export declare function revision(context: Context, next: any): Promise<void>;
@@ -3,8 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.duplicate = duplicate;
7
- exports.update = update;
6
+ exports.revision = revision;
8
7
 
9
8
  function _actions() {
10
9
  const data = require("@nocobase/actions");
@@ -16,16 +15,6 @@ function _actions() {
16
15
  return data;
17
16
  }
18
17
 
19
- function _database() {
20
- const data = require("@nocobase/database");
21
-
22
- _database = function _database() {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
18
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
30
19
 
31
20
  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."); }
@@ -38,83 +27,20 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
38
27
 
39
28
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
40
29
 
30
+ 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); } }
31
+
32
+ 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); }); }; }
33
+
41
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; }
42
35
 
43
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; }
44
37
 
45
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; }
46
39
 
47
- 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); } }
48
-
49
- 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); }); }; }
50
-
51
40
  function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
52
41
 
53
42
  function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function _throw(value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
54
43
 
55
- function update(_x, _x2) {
56
- return _update.apply(this, arguments);
57
- }
58
-
59
- function _update() {
60
- _update = _asyncToGenerator(function* (context, next) {
61
- const db = context.db;
62
-
63
- const repository = _actions().utils.getRepositoryFromParams(context);
64
-
65
- const _context$action$param = context.action.params,
66
- filterByTk = _context$action$param.filterByTk,
67
- values = _context$action$param.values,
68
- whitelist = _context$action$param.whitelist,
69
- blacklist = _context$action$param.blacklist,
70
- filter = _context$action$param.filter,
71
- updateAssociationValues = _context$action$param.updateAssociationValues;
72
- context.body = yield db.sequelize.transaction( /*#__PURE__*/function () {
73
- var _ref = _asyncToGenerator(function* (transaction) {
74
- const others = {};
75
-
76
- if (values.enabled) {
77
- values.current = true;
78
- others.enabled = false;
79
- }
80
-
81
- if (values.current) {
82
- others.current = false;
83
- yield repository.update({
84
- filter: {
85
- key: values.key,
86
- id: {
87
- [_database().Op.ne]: filterByTk
88
- }
89
- },
90
- values: others,
91
- context,
92
- transaction
93
- });
94
- }
95
-
96
- const instance = yield repository.update({
97
- filterByTk,
98
- values,
99
- whitelist,
100
- blacklist,
101
- filter,
102
- updateAssociationValues,
103
- context,
104
- transaction
105
- });
106
- return instance;
107
- });
108
-
109
- return function (_x5) {
110
- return _ref.apply(this, arguments);
111
- };
112
- }());
113
- yield next();
114
- });
115
- return _update.apply(this, arguments);
116
- }
117
-
118
44
  function typeOf(value) {
119
45
  if (Array.isArray(value)) {
120
46
  return 'array';
@@ -149,19 +75,19 @@ function migrateConfig(config, oldToNew) {
149
75
  return migrate(config);
150
76
  }
151
77
 
152
- function duplicate(_x3, _x4) {
153
- return _duplicate.apply(this, arguments);
78
+ function revision(_x, _x2) {
79
+ return _revision.apply(this, arguments);
154
80
  }
155
81
 
156
- function _duplicate() {
157
- _duplicate = _asyncToGenerator(function* (context, next) {
82
+ function _revision() {
83
+ _revision = _asyncToGenerator(function* (context, next) {
158
84
  const db = context.db;
159
85
 
160
86
  const repository = _actions().utils.getRepositoryFromParams(context);
161
87
 
162
88
  const filterByTk = context.action.params.filterByTk;
163
89
  context.body = yield db.sequelize.transaction( /*#__PURE__*/function () {
164
- var _ref2 = _asyncToGenerator(function* (transaction) {
90
+ var _ref = _asyncToGenerator(function* (transaction) {
165
91
  const origin = yield repository.findOne({
166
92
  filterByTk,
167
93
  appends: ['nodes'],
@@ -261,11 +187,11 @@ function _duplicate() {
261
187
  return instance;
262
188
  });
263
189
 
264
- return function (_x6) {
265
- return _ref2.apply(this, arguments);
190
+ return function (_x3) {
191
+ return _ref.apply(this, arguments);
266
192
  };
267
193
  }());
268
194
  yield next();
269
195
  });
270
- return _duplicate.apply(this, arguments);
196
+ return _revision.apply(this, arguments);
271
197
  }
@@ -1,6 +1,6 @@
1
1
  import { Registry } from "@nocobase/utils";
2
- import ExecutionModel from '../models/Execution';
3
2
  import JobModel from '../models/Job';
3
+ import Processor from '../Processor';
4
4
  export declare const calculators: Registry<Function>;
5
5
  export default calculators;
6
6
  export declare type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';
@@ -35,4 +35,4 @@ export declare type Calculation = {
35
35
  options: CalculationOptions;
36
36
  };
37
37
  export declare type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;
38
- export declare function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel): any;
38
+ export declare function calculate(operand: Operand, lastJob: JobModel, processor: Processor): any;
@@ -43,12 +43,12 @@ function get(object, path) {
43
43
  // or the execution should be prepared first.
44
44
 
45
45
 
46
- function calculate(operand, lastJob, execution) {
46
+ function calculate(operand, lastJob, processor) {
47
47
  switch (operand.type) {
48
48
  // @Deprecated
49
49
  // from execution context
50
50
  case '$context':
51
- return get(execution.context, operand.options.path);
51
+ return get(processor.execution.context, operand.options.path);
52
52
  // @Deprecated
53
53
  // from last job (or input job)
54
54
 
@@ -59,7 +59,7 @@ function calculate(operand, lastJob, execution) {
59
59
 
60
60
  case '$jobsMapByNodeId':
61
61
  // assume jobs have been fetched from execution before
62
- const job = execution.jobsMapByNodeId[operand.options.nodeId];
62
+ const job = processor.jobsMapByNodeId[operand.options.nodeId];
63
63
  return job && get(job, operand.options.path);
64
64
 
65
65
  case '$calculation':
@@ -69,7 +69,7 @@ function calculate(operand, lastJob, execution) {
69
69
  throw new Error(`no calculator function registered for "${operand.options.calculator}"`);
70
70
  }
71
71
 
72
- return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));
72
+ return fn(...operand.options.operands.map(item => calculate(item, lastJob, processor)));
73
73
  // constant
74
74
 
75
75
  default:
@@ -6,37 +6,29 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _default = {
8
8
  name: 'executions',
9
- model: 'ExecutionModel',
10
- title: '执行流程',
11
9
  fields: [{
12
- interface: 'linkTo',
13
10
  type: 'belongsTo',
14
- name: 'workflow',
15
- title: '所属工作流'
11
+ name: 'workflow'
12
+ }, {
13
+ type: 'uid',
14
+ name: 'key'
16
15
  }, {
17
16
  type: 'boolean',
18
17
  name: 'useTransaction',
19
- title: '使用事务',
20
18
  defaultValue: false
21
19
  }, {
22
20
  type: 'uuid',
23
21
  name: 'transaction',
24
22
  defaultValue: null
25
23
  }, {
26
- interface: 'linkTo',
27
24
  type: 'hasMany',
28
- name: 'jobs',
29
- title: '流程记录'
25
+ name: 'jobs'
30
26
  }, {
31
- interface: 'json',
32
27
  type: 'jsonb',
33
- name: 'context',
34
- title: '上下文数据'
28
+ name: 'context'
35
29
  }, {
36
- interface: 'select',
37
30
  type: 'integer',
38
- name: 'status',
39
- title: '状态'
31
+ name: 'status'
40
32
  }]
41
33
  };
42
34
  exports.default = _default;