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

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 (136) 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 +7 -2
  5. package/lib/client/Branch.d.ts +1 -1
  6. package/lib/client/ExecutionCanvas.js +5 -10
  7. package/lib/client/WorkflowCanvas.js +11 -40
  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 +21 -25
  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 +38 -13
  25. package/lib/client/locale/en-US.js +39 -14
  26. package/lib/client/locale/index.js +12 -29
  27. package/lib/client/locale/zh-CN.d.ts +47 -20
  28. package/lib/client/locale/zh-CN.js +48 -21
  29. package/lib/client/nodes/calculation.d.ts +40 -6
  30. package/lib/client/nodes/calculation.js +171 -19
  31. package/lib/client/nodes/condition.d.ts +67 -0
  32. package/lib/client/nodes/condition.js +287 -27
  33. package/lib/client/nodes/create.d.ts +8 -6
  34. package/lib/client/nodes/create.js +27 -33
  35. package/lib/client/nodes/delay.d.ts +2 -0
  36. package/lib/client/nodes/delay.js +8 -4
  37. package/lib/client/nodes/destroy.d.ts +2 -2
  38. package/lib/client/nodes/destroy.js +2 -2
  39. package/lib/client/nodes/index.d.ts +10 -2
  40. package/lib/client/nodes/index.js +73 -27
  41. package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
  42. package/lib/client/nodes/manual/AssigneesSelect.js +64 -0
  43. package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
  44. package/lib/client/nodes/manual/ModeConfig.js +160 -0
  45. package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
  46. package/lib/client/nodes/manual/SchemaConfig.js +715 -0
  47. package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
  48. package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
  49. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
  50. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
  51. package/lib/client/nodes/manual/index.d.ts +64 -0
  52. package/lib/client/nodes/manual/index.js +146 -0
  53. package/lib/client/nodes/parallel.d.ts +11 -5
  54. package/lib/client/nodes/parallel.js +22 -34
  55. package/lib/client/nodes/query.d.ts +9 -14
  56. package/lib/client/nodes/query.js +38 -44
  57. package/lib/client/nodes/request.d.ts +75 -33
  58. package/lib/client/nodes/request.js +124 -63
  59. package/lib/client/nodes/update.d.ts +2 -2
  60. package/lib/client/nodes/update.js +2 -2
  61. package/lib/client/schemas/collection.js +1 -1
  62. package/lib/client/schemas/executions.js +1 -1
  63. package/lib/client/schemas/workflows.js +1 -1
  64. package/lib/client/style.js +0 -4
  65. package/lib/client/triggers/collection.d.ts +7 -3
  66. package/lib/client/triggers/collection.js +39 -48
  67. package/lib/client/triggers/index.d.ts +5 -2
  68. package/lib/client/triggers/index.js +34 -12
  69. package/lib/client/triggers/schedule/index.d.ts +7 -5
  70. package/lib/client/triggers/schedule/index.js +38 -79
  71. package/lib/client/utils.d.ts +1 -0
  72. package/lib/client/utils.js +38 -0
  73. package/lib/client/variable.d.ts +21 -0
  74. package/lib/client/variable.js +147 -0
  75. package/lib/server/Plugin.d.ts +3 -3
  76. package/lib/server/Plugin.js +12 -21
  77. package/lib/server/Processor.d.ts +9 -2
  78. package/lib/server/Processor.js +39 -43
  79. package/lib/server/actions/index.js +2 -4
  80. package/lib/server/actions/workflows.d.ts +1 -0
  81. package/lib/server/actions/workflows.js +80 -23
  82. package/lib/server/collections/executions.js +5 -7
  83. package/lib/server/collections/flow_nodes.js +6 -18
  84. package/lib/server/collections/jobs.js +3 -1
  85. package/lib/server/collections/workflows.js +8 -4
  86. package/lib/server/constants.d.ts +9 -3
  87. package/lib/server/constants.js +11 -5
  88. package/lib/server/functions/index.d.ts +4 -0
  89. package/lib/server/functions/index.js +38 -0
  90. package/lib/server/index.d.ts +0 -1
  91. package/lib/server/index.js +0 -14
  92. package/lib/server/instructions/calculation.d.ts +2 -7
  93. package/lib/server/instructions/calculation.js +32 -37
  94. package/lib/server/instructions/condition.d.ts +4 -4
  95. package/lib/server/instructions/condition.js +126 -54
  96. package/lib/server/instructions/index.js +1 -1
  97. package/lib/server/instructions/manual/actions.js +101 -0
  98. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
  99. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
  100. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
  101. package/lib/server/instructions/manual/index.d.ts +25 -0
  102. package/lib/server/instructions/manual/index.js +200 -0
  103. package/lib/server/instructions/parallel.js +11 -7
  104. package/lib/server/instructions/request.d.ts +8 -4
  105. package/lib/server/instructions/request.js +60 -94
  106. package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
  107. package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
  108. package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
  109. package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
  110. package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
  111. package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
  112. package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
  113. package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
  114. package/lib/server/triggers/schedule.js +11 -3
  115. package/package.json +11 -10
  116. package/lib/client/calculators.d.ts +0 -89
  117. package/lib/client/calculators.js +0 -668
  118. package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
  119. package/lib/client/components/CollectionFieldSelect.js +0 -106
  120. package/lib/client/components/EjsTextArea.d.ts +0 -2
  121. package/lib/client/components/EjsTextArea.js +0 -232
  122. package/lib/server/actions/jobs.d.ts +0 -2
  123. package/lib/server/actions/jobs.js +0 -39
  124. package/lib/server/calculators/index.d.ts +0 -40
  125. package/lib/server/calculators/index.js +0 -187
  126. package/lib/server/extensions/assignees/actions.js +0 -75
  127. package/lib/server/extensions/assignees/index.d.ts +0 -2
  128. package/lib/server/extensions/assignees/index.js +0 -273
  129. package/lib/server/extensions/index.d.ts +0 -3
  130. package/lib/server/extensions/index.js +0 -13
  131. package/lib/server/instructions/prompt.d.ts +0 -19
  132. package/lib/server/instructions/prompt.js +0 -131
  133. /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
  134. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
  135. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
  136. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
@@ -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);
@@ -250,15 +241,13 @@ class Processor {
250
241
 
251
242
  return _asyncToGenerator(function* () {
252
243
  const instructions = _this7.options.plugin.instructions;
244
+ const instruction = instructions.get(node.type);
253
245
 
254
- const _instructions$get = instructions.get(node.type),
255
- run = _instructions$get.run;
256
-
257
- if (typeof run !== 'function') {
246
+ if (typeof instruction.run !== 'function') {
258
247
  return Promise.reject(new Error('`run` should be implemented for customized execution of the node'));
259
248
  }
260
249
 
261
- return _this7.exec(run, node, input);
250
+ return _this7.exec(instruction.run.bind(instruction), node, input);
262
251
  })();
263
252
  } // parent node should take over the control
264
253
 
@@ -286,15 +275,13 @@ class Processor {
286
275
 
287
276
  return _asyncToGenerator(function* () {
288
277
  const instructions = _this9.options.plugin.instructions;
278
+ const instruction = instructions.get(node.type);
289
279
 
290
- const _instructions$get2 = instructions.get(node.type),
291
- resume = _instructions$get2.resume;
292
-
293
- if (typeof resume !== 'function') {
280
+ if (typeof instruction.resume !== 'function') {
294
281
  return Promise.reject(new Error('`resume` should be implemented'));
295
282
  }
296
283
 
297
- return _this9.exec(resume, node, job);
284
+ return _this9.exec(instruction.resume.bind(instruction), node, job);
298
285
  })();
299
286
  }
300
287
 
@@ -302,7 +289,9 @@ class Processor {
302
289
  var _this10 = this;
303
290
 
304
291
  return _asyncToGenerator(function* () {
305
- 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;
306
295
  yield _this10.execution.update({
307
296
  status
308
297
  }, {
@@ -356,7 +345,7 @@ class Processor {
356
345
  }
357
346
 
358
347
  getBranches(node) {
359
- 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));
360
349
  } // find the first node in current branch
361
350
 
362
351
 
@@ -397,14 +386,14 @@ class Processor {
397
386
  return null;
398
387
  }
399
388
 
400
- getParsedValue(value, node) {
401
- const injectedFns = {};
389
+ getScope(node) {
390
+ const systemFns = {};
402
391
  const scope = {
403
392
  execution: this.execution,
404
393
  node
405
394
  };
406
395
 
407
- var _iterator = _createForOfIteratorHelper(_calculators.default.getEntities()),
396
+ var _iterator = _createForOfIteratorHelper(this.options.plugin.functions.getEntities()),
408
397
  _step;
409
398
 
410
399
  try {
@@ -413,7 +402,7 @@ class Processor {
413
402
  name = _step$value[0],
414
403
  fn = _step$value[1];
415
404
 
416
- injectedFns[name] = fn.bind(scope);
405
+ systemFns[name] = fn.bind(scope);
417
406
  }
418
407
  } catch (err) {
419
408
  _iterator.e(err);
@@ -421,11 +410,15 @@ class Processor {
421
410
  _iterator.f();
422
411
  }
423
412
 
424
- return (0, _jsonTemplates().default)(value)({
413
+ return {
425
414
  $context: this.execution.context,
426
415
  $jobsMapByNodeId: this.jobsMapByNodeId,
427
- $fn: injectedFns
428
- });
416
+ $system: systemFns
417
+ };
418
+ }
419
+
420
+ getParsedValue(value, node) {
421
+ return (0, _jsonTemplates().default)(value)(this.getScope(node));
429
422
  }
430
423
 
431
424
  }
@@ -434,6 +427,9 @@ exports.default = Processor;
434
427
  Processor.StatusMap = {
435
428
  [_constants.JOB_STATUS.PENDING]: _constants.EXECUTION_STATUS.STARTED,
436
429
  [_constants.JOB_STATUS.RESOLVED]: _constants.EXECUTION_STATUS.RESOLVED,
437
- [_constants.JOB_STATUS.REJECTED]: _constants.EXECUTION_STATUS.REJECTED,
438
- [_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
439
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>;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.destroy = destroy;
6
7
  exports.revision = revision;
7
8
  exports.update = update;
8
9
 
@@ -16,6 +17,16 @@ function _actions() {
16
17
  return data;
17
18
  }
18
19
 
20
+ function _database() {
21
+ const data = require("@nocobase/database");
22
+
23
+ _database = function _database() {
24
+ return data;
25
+ };
26
+
27
+ return data;
28
+ }
29
+
19
30
  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); }
20
31
 
21
32
  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; }
@@ -56,13 +67,16 @@ function _update() {
56
67
 
57
68
  const _context$action$param = context.action.params,
58
69
  filterByTk = _context$action$param.filterByTk,
59
- values = _context$action$param.values; // only enable/disable
70
+ values = _context$action$param.values;
71
+ context.action.mergeParams({
72
+ whitelist: ['title', 'description', 'enabled', 'config']
73
+ }); // only enable/disable
60
74
 
61
- if (Object.keys(values).sort().join() !== 'enabled,key') {
75
+ if (Object.keys(values).includes('config')) {
62
76
  const workflow = yield repository.findById(filterByTk);
63
77
 
64
78
  if (workflow.get('executed')) {
65
- return context.throw(400, 'executed workflow can not be updated');
79
+ return context.throw(400, 'config of executed workflow can not be updated');
66
80
  }
67
81
  }
68
82
 
@@ -71,6 +85,54 @@ function _update() {
71
85
  return _update.apply(this, arguments);
72
86
  }
73
87
 
88
+ function destroy(_x3, _x4) {
89
+ return _destroy.apply(this, arguments);
90
+ }
91
+
92
+ function _destroy() {
93
+ _destroy = _asyncToGenerator(function* (context, next) {
94
+ const repository = _actions().utils.getRepositoryFromParams(context);
95
+
96
+ const _context$action$param2 = context.action.params,
97
+ filterByTk = _context$action$param2.filterByTk,
98
+ filter = _context$action$param2.filter;
99
+ yield context.db.sequelize.transaction( /*#__PURE__*/function () {
100
+ var _ref = _asyncToGenerator(function* (transaction) {
101
+ const items = yield repository.find({
102
+ filterByTk,
103
+ filter,
104
+ fields: ['id', 'key', 'current'],
105
+ transaction
106
+ });
107
+ const ids = new Set(items.map(item => item.id));
108
+ const keysSet = new Set(items.filter(item => item.current).map(item => item.key));
109
+ const revisions = yield repository.find({
110
+ filter: {
111
+ key: Array.from(keysSet),
112
+ current: {
113
+ [_database().Op.not]: true
114
+ }
115
+ },
116
+ fields: ['id'],
117
+ transaction
118
+ });
119
+ revisions.forEach(item => ids.add(item.id));
120
+ context.body = yield repository.destroy({
121
+ filterByTk: Array.from(ids),
122
+ individualHooks: true,
123
+ transaction
124
+ });
125
+ });
126
+
127
+ return function (_x7) {
128
+ return _ref.apply(this, arguments);
129
+ };
130
+ }());
131
+ next();
132
+ });
133
+ return _destroy.apply(this, arguments);
134
+ }
135
+
74
136
  function typeOf(value) {
75
137
  if (Array.isArray(value)) {
76
138
  return 'array';
@@ -105,20 +167,15 @@ function migrateConfig(config, oldToNew) {
105
167
  return value.map(item => migrate(item));
106
168
 
107
169
  case 'string':
108
- const matcher = value.match(/(\{\{\$jobsMapByNodeId\.)([\w-]+)/);
170
+ return value.replace(/(\{\{\$jobsMapByNodeId\.)([\w-]+)/g, (_, jobVar, oldNodeId) => {
171
+ const newNode = oldToNew.get(Number.parseInt(oldNodeId, 10));
109
172
 
110
- if (!matcher) {
111
- return value;
112
- }
113
-
114
- const oldNodeId = Number.parseInt(matcher[2], 10);
115
- const newNode = oldToNew.get(oldNodeId);
116
-
117
- if (!newNode) {
118
- throw new Error('node configurated for result is not existed');
119
- }
173
+ if (!newNode) {
174
+ throw new Error('node configurated for result is not existed');
175
+ }
120
176
 
121
- return value.replace(matcher[0], `{{$jobsMapByNodeId.${newNode.id}`);
177
+ return `{{$jobsMapByNodeId.${newNode.id}`;
178
+ });
122
179
 
123
180
  default:
124
181
  return value;
@@ -128,7 +185,7 @@ function migrateConfig(config, oldToNew) {
128
185
  return migrate(config);
129
186
  }
130
187
 
131
- function revision(_x3, _x4) {
188
+ function revision(_x5, _x6) {
132
189
  return _revision.apply(this, arguments);
133
190
  }
134
191
 
@@ -138,12 +195,12 @@ function _revision() {
138
195
 
139
196
  const repository = _actions().utils.getRepositoryFromParams(context);
140
197
 
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;
198
+ const _context$action$param3 = context.action.params,
199
+ filterByTk = _context$action$param3.filterByTk,
200
+ _context$action$param4 = _context$action$param3.filter,
201
+ filter = _context$action$param4 === void 0 ? {} : _context$action$param4;
145
202
  context.body = yield db.sequelize.transaction( /*#__PURE__*/function () {
146
- var _ref = _asyncToGenerator(function* (transaction) {
203
+ var _ref2 = _asyncToGenerator(function* (transaction) {
147
204
  const origin = yield repository.findOne({
148
205
  filterByTk,
149
206
  filter,
@@ -256,8 +313,8 @@ function _revision() {
256
313
  return instance;
257
314
  });
258
315
 
259
- return function (_x5) {
260
- return _ref.apply(this, arguments);
316
+ return function (_x8) {
317
+ return _ref2.apply(this, arguments);
261
318
  };
262
319
  }());
263
320
  yield next();
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _default = {
8
+ namespace: 'workflow',
9
+ duplicator: 'optional',
8
10
  name: 'executions',
9
11
  fields: [{
10
12
  type: 'belongsTo',
@@ -16,16 +18,12 @@ var _default = {
16
18
  type: 'boolean',
17
19
  name: 'useTransaction',
18
20
  defaultValue: false
19
- }, // @deprecated
20
- {
21
- type: 'uuid',
22
- name: 'transaction',
23
- defaultValue: null
24
21
  }, {
25
22
  type: 'hasMany',
26
- name: 'jobs'
23
+ name: 'jobs',
24
+ onDelete: 'CASCADE'
27
25
  }, {
28
- type: 'jsonb',
26
+ type: 'json',
29
27
  name: 'context'
30
28
  }, {
31
29
  type: 'integer',
@@ -5,26 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _default = {
8
+ namespace: 'workflow',
9
+ duplicator: 'required',
8
10
  name: 'flow_nodes',
9
- // model: 'FlowNodeModel',
10
- title: 'Workflow Nodes',
11
11
  fields: [{
12
- interface: 'string',
13
12
  type: 'string',
14
- name: 'title',
15
- title: '名称'
13
+ name: 'title'
16
14
  }, // which workflow belongs to
17
15
  {
18
- interface: 'linkTo',
19
16
  name: 'workflow',
20
17
  type: 'belongsTo'
21
18
  }, {
22
- interface: 'linkTo',
23
19
  name: 'upstream',
24
20
  type: 'belongsTo',
25
21
  target: 'flow_nodes'
26
22
  }, {
27
- interface: 'linkTo',
28
23
  name: 'branches',
29
24
  type: 'hasMany',
30
25
  target: 'flow_nodes',
@@ -34,28 +29,21 @@ var _default = {
34
29
  // put here because the design of flow-links model is not really necessary for now.
35
30
  // or it should be put into flow-links model.
36
31
  {
37
- interface: 'select',
38
32
  name: 'branchIndex',
39
- type: 'integer',
40
- title: 'branch index'
33
+ type: 'integer'
41
34
  }, // Note: for reasons:
42
35
  // 1. redirect type node to solve cycle flow.
43
36
  // 2. recognize as real next node after branches.
44
37
  {
45
- interface: 'linkTo',
46
38
  name: 'downstream',
47
39
  type: 'belongsTo',
48
40
  target: 'flow_nodes'
49
41
  }, {
50
- interface: 'select',
51
42
  type: 'string',
52
- name: 'type',
53
- title: '类型'
43
+ name: 'type'
54
44
  }, {
55
- interface: 'json',
56
- type: 'jsonb',
45
+ type: 'json',
57
46
  name: 'config',
58
- title: '配置',
59
47
  defaultValue: {}
60
48
  }]
61
49
  };
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _default = {
8
+ namespace: 'workflow',
9
+ duplicator: 'optional',
8
10
  name: 'jobs',
9
11
  fields: [{
10
12
  type: 'belongsTo',
@@ -21,7 +23,7 @@ var _default = {
21
23
  type: 'integer',
22
24
  name: 'status'
23
25
  }, {
24
- type: 'jsonb',
26
+ type: 'json',
25
27
  name: 'result'
26
28
  }]
27
29
  };
@@ -7,6 +7,8 @@ exports.default = _default;
7
7
 
8
8
  function _default() {
9
9
  return {
10
+ namespace: 'workflow',
11
+ duplicator: 'required',
10
12
  name: 'workflows',
11
13
  fields: [{
12
14
  name: 'key',
@@ -27,7 +29,7 @@ function _default() {
27
29
  name: 'type',
28
30
  required: true
29
31
  }, {
30
- type: 'jsonb',
32
+ type: 'json',
31
33
  name: 'config',
32
34
  required: true,
33
35
  defaultValue: {}
@@ -38,10 +40,12 @@ function _default() {
38
40
  }, {
39
41
  type: 'hasMany',
40
42
  name: 'nodes',
41
- target: 'flow_nodes'
43
+ target: 'flow_nodes',
44
+ onDelete: 'CASCADE'
42
45
  }, {
43
46
  type: 'hasMany',
44
- name: 'executions'
47
+ name: 'executions',
48
+ onDelete: 'CASCADE'
45
49
  }, {
46
50
  type: 'integer',
47
51
  name: 'executed',
@@ -53,7 +57,7 @@ function _default() {
53
57
  }, {
54
58
  type: 'boolean',
55
59
  name: 'current',
56
- defaultValue: null
60
+ defaultValue: false
57
61
  }, {
58
62
  type: 'hasMany',
59
63
  name: 'revisions',
@@ -1,15 +1,21 @@
1
1
  export declare const EXECUTION_STATUS: {
2
- CREATED: any;
2
+ QUEUEING: any;
3
3
  STARTED: number;
4
4
  RESOLVED: number;
5
- REJECTED: number;
5
+ FAILED: number;
6
+ ERROR: number;
7
+ ABORTED: number;
6
8
  CANCELED: number;
9
+ REJECTED: number;
7
10
  };
8
11
  export declare const JOB_STATUS: {
9
12
  PENDING: number;
10
13
  RESOLVED: number;
11
- REJECTED: number;
14
+ FAILED: number;
15
+ ERROR: number;
16
+ ABORTED: number;
12
17
  CANCELED: number;
18
+ REJECTED: number;
13
19
  };
14
20
  export declare const BRANCH_INDEX: {
15
21
  DEFAULT: any;
@@ -5,18 +5,24 @@ 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
+ QUEUEING: null,
9
9
  STARTED: 0,
10
10
  RESOLVED: 1,
11
- REJECTED: -1,
12
- CANCELED: -2
11
+ FAILED: -1,
12
+ ERROR: -2,
13
+ ABORTED: -3,
14
+ CANCELED: -4,
15
+ REJECTED: -5
13
16
  };
14
17
  exports.EXECUTION_STATUS = EXECUTION_STATUS;
15
18
  const JOB_STATUS = {
16
19
  PENDING: 0,
17
20
  RESOLVED: 1,
18
- REJECTED: -1,
19
- CANCELED: -2
21
+ FAILED: -1,
22
+ ERROR: -2,
23
+ ABORTED: -3,
24
+ CANCELED: -4,
25
+ REJECTED: -5
20
26
  };
21
27
  exports.JOB_STATUS = JOB_STATUS;
22
28
  const BRANCH_INDEX = {
@@ -0,0 +1,4 @@
1
+ import Plugin from "..";
2
+ export default function ({ functions }: Plugin, more?: {
3
+ [key: string]: Function;
4
+ }): void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+
10
+ 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."); }
11
+
12
+ 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); }
13
+
14
+ 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; }
15
+
16
+ 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; }
17
+
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+
20
+ function now() {
21
+ return new Date();
22
+ }
23
+
24
+ function _default({
25
+ functions
26
+ }, more = {}) {
27
+ functions.register('now', now);
28
+
29
+ for (var _i = 0, _Object$entries = Object.entries(more); _i < _Object$entries.length; _i++) {
30
+ const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
31
+ name = _Object$entries$_i[0],
32
+ fn = _Object$entries$_i[1];
33
+
34
+ functions.register(name, fn);
35
+ }
36
+ }
37
+
38
+ ;
@@ -1,5 +1,4 @@
1
1
  export * from './constants';
2
- export * from './calculators';
3
2
  export { Trigger } from './triggers';
4
3
  export { default as Processor } from './Processor';
5
4
  export { default } from './Plugin';
@@ -40,20 +40,6 @@ Object.keys(_constants).forEach(function (key) {
40
40
  });
41
41
  });
42
42
 
43
- var _calculators = require("./calculators");
44
-
45
- Object.keys(_calculators).forEach(function (key) {
46
- if (key === "default" || key === "__esModule") return;
47
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
48
- if (key in exports && exports[key] === _calculators[key]) return;
49
- Object.defineProperty(exports, key, {
50
- enumerable: true,
51
- get: function get() {
52
- return _calculators[key];
53
- }
54
- });
55
- });
56
-
57
43
  var _triggers = require("./triggers");
58
44
 
59
45
  var _Processor = _interopRequireDefault(require("./Processor"));