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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/lib/client/AddButton.js +17 -64
  2. package/lib/client/Branch.js +0 -13
  3. package/lib/client/ExecutionCanvas.js +16 -63
  4. package/lib/client/ExecutionLink.js +3 -21
  5. package/lib/client/ExecutionPage.js +1 -19
  6. package/lib/client/ExecutionResourceProvider.js +6 -23
  7. package/lib/client/FlowContext.js +0 -8
  8. package/lib/client/WorkflowCanvas.js +56 -127
  9. package/lib/client/WorkflowLink.js +3 -21
  10. package/lib/client/WorkflowPage.js +1 -19
  11. package/lib/client/WorkflowProvider.js +24 -47
  12. package/lib/client/WorkflowShortcut.js +0 -16
  13. package/lib/client/components/CollectionBlockInitializer.js +12 -22
  14. package/lib/client/components/CollectionFieldInitializers.js +5 -24
  15. package/lib/client/components/CollectionFieldset.js +31 -79
  16. package/lib/client/components/Duration.js +0 -14
  17. package/lib/client/components/DynamicExpression.d.ts +4 -0
  18. package/lib/client/components/DynamicExpression.js +102 -0
  19. package/lib/client/components/FieldsSelect.d.ts +2 -0
  20. package/lib/client/components/FieldsSelect.js +66 -0
  21. package/lib/client/components/FilterDynamicComponent.js +1 -10
  22. package/lib/client/components/NullRender.js +0 -1
  23. package/lib/client/components/OpenDrawer.js +10 -35
  24. package/lib/client/components/RadioWithTooltip.js +5 -27
  25. package/lib/client/components/renderEngineReference.d.ts +1 -0
  26. package/lib/client/components/renderEngineReference.js +55 -0
  27. package/lib/client/constants.js +0 -9
  28. package/lib/client/index.js +0 -6
  29. package/lib/client/interfaces/expression.d.ts +3 -0
  30. package/lib/client/interfaces/expression.js +37 -0
  31. package/lib/client/locale/index.js +5 -15
  32. package/lib/client/locale/pt-BR.d.ts +130 -0
  33. package/lib/client/locale/pt-BR.js +136 -0
  34. package/lib/client/locale/zh-CN.d.ts +16 -1
  35. package/lib/client/locale/zh-CN.js +17 -2
  36. package/lib/client/nodes/calculation.d.ts +54 -3
  37. package/lib/client/nodes/calculation.js +136 -63
  38. package/lib/client/nodes/condition.d.ts +1 -1
  39. package/lib/client/nodes/condition.js +21 -76
  40. package/lib/client/nodes/create.d.ts +35 -9
  41. package/lib/client/nodes/create.js +13 -19
  42. package/lib/client/nodes/delay.d.ts +1 -3
  43. package/lib/client/nodes/delay.js +3 -10
  44. package/lib/client/nodes/destroy.d.ts +1 -6
  45. package/lib/client/nodes/destroy.js +12 -9
  46. package/lib/client/nodes/index.d.ts +2 -2
  47. package/lib/client/nodes/index.js +45 -147
  48. package/lib/client/nodes/manual/AssigneesSelect.js +6 -17
  49. package/lib/client/nodes/manual/ModeConfig.js +0 -27
  50. package/lib/client/nodes/manual/SchemaConfig.js +87 -449
  51. package/lib/client/nodes/manual/WorkflowTodo.js +99 -163
  52. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +4 -20
  53. package/lib/client/nodes/manual/forms/customForm.d.ts +40 -0
  54. package/lib/client/nodes/manual/forms/customForm.js +411 -0
  55. package/lib/client/nodes/manual/index.d.ts +12 -1
  56. package/lib/client/nodes/manual/index.js +54 -41
  57. package/lib/client/nodes/parallel.js +7 -41
  58. package/lib/client/nodes/query.d.ts +28 -7
  59. package/lib/client/nodes/query.js +15 -22
  60. package/lib/client/nodes/request.d.ts +2 -3
  61. package/lib/client/nodes/request.js +5 -22
  62. package/lib/client/nodes/update.d.ts +1 -6
  63. package/lib/client/nodes/update.js +8 -16
  64. package/lib/client/schemas/collection.d.ts +20 -4
  65. package/lib/client/schemas/collection.js +26 -22
  66. package/lib/client/schemas/executions.js +3 -18
  67. package/lib/client/schemas/workflows.js +10 -33
  68. package/lib/client/style.js +24 -21
  69. package/lib/client/triggers/collection.d.ts +24 -20
  70. package/lib/client/triggers/collection.js +34 -123
  71. package/lib/client/triggers/index.d.ts +2 -5
  72. package/lib/client/triggers/index.js +34 -105
  73. package/lib/client/triggers/schedule/DateFieldsSelect.js +6 -29
  74. package/lib/client/triggers/schedule/EndsByField.js +1 -18
  75. package/lib/client/triggers/schedule/OnField.js +10 -38
  76. package/lib/client/triggers/schedule/RepeatField.js +4 -32
  77. package/lib/client/triggers/schedule/ScheduleConfig.js +10 -51
  78. package/lib/client/triggers/schedule/index.d.ts +21 -0
  79. package/lib/client/triggers/schedule/index.js +21 -22
  80. package/lib/client/triggers/schedule/locale/Cron.zh-CN.js +8 -4
  81. package/lib/client/utils.d.ts +1 -0
  82. package/lib/client/utils.js +31 -10
  83. package/lib/client/variable.d.ts +7 -6
  84. package/lib/client/variable.js +132 -71
  85. package/lib/index.js +0 -2
  86. package/lib/server/Plugin.d.ts +7 -7
  87. package/lib/server/Plugin.js +76 -111
  88. package/lib/server/Processor.d.ts +2 -0
  89. package/lib/server/Processor.js +62 -125
  90. package/lib/server/actions/index.js +3 -10
  91. package/lib/server/actions/nodes.js +34 -87
  92. package/lib/server/actions/workflows.js +46 -96
  93. package/lib/server/collections/executions.js +1 -1
  94. package/lib/server/collections/flow_nodes.js +7 -4
  95. package/lib/server/collections/jobs.js +1 -1
  96. package/lib/server/collections/workflows.js +3 -4
  97. package/lib/server/fields/expression-field.d.ts +8 -0
  98. package/lib/server/fields/expression-field.js +26 -0
  99. package/lib/server/fields/index.d.ts +1 -0
  100. package/lib/server/fields/index.js +12 -0
  101. package/lib/server/functions/index.js +3 -14
  102. package/lib/server/index.js +0 -6
  103. package/lib/server/instructions/calculation.js +22 -17
  104. package/lib/server/instructions/condition.js +8 -52
  105. package/lib/server/instructions/create.js +31 -15
  106. package/lib/server/instructions/delay.js +4 -32
  107. package/lib/server/instructions/destroy.js +6 -12
  108. package/lib/server/instructions/index.js +6 -23
  109. package/lib/server/instructions/manual/actions.js +22 -31
  110. package/lib/server/instructions/manual/collecions/users_jobs.js +1 -1
  111. package/lib/server/instructions/manual/index.d.ts +13 -12
  112. package/lib/server/instructions/manual/index.js +9 -47
  113. package/lib/server/instructions/parallel.js +9 -36
  114. package/lib/server/instructions/query.js +17 -15
  115. package/lib/server/instructions/request.js +7 -30
  116. package/lib/server/instructions/update.js +8 -14
  117. package/lib/server/migrations/20221129153547-calculation-variables.js +3 -27
  118. package/lib/server/migrations/20230221032941-change-request-body-type.js +3 -26
  119. package/lib/server/migrations/20230221071831-calculation-expression.js +1 -33
  120. package/lib/server/migrations/20230221121203-condition-calculation.js +5 -28
  121. package/lib/server/migrations/20230221162902-jsonb-to-json.js +3 -18
  122. package/lib/server/migrations/20230411034722-manual-multi-form.d.ts +4 -0
  123. package/lib/server/migrations/20230411034722-manual-multi-form.js +303 -0
  124. package/lib/server/models/Execution.js +0 -5
  125. package/lib/server/models/FlowNode.js +0 -5
  126. package/lib/server/models/Job.js +0 -5
  127. package/lib/server/models/Workflow.js +0 -5
  128. package/lib/server/triggers/collection.js +39 -61
  129. package/lib/server/triggers/index.js +3 -22
  130. package/lib/server/triggers/schedule.js +72 -194
  131. package/package.json +14 -11
@@ -4,58 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
-
8
7
  function _path() {
9
8
  const data = _interopRequireDefault(require("path"));
10
-
11
9
  _path = function _path() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _utils() {
19
15
  const data = require("@nocobase/utils");
20
-
21
16
  _utils = function _utils() {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
22
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
31
-
32
23
  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."); }
33
-
34
24
  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); }
35
-
36
25
  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; }
37
-
38
- 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; }
39
-
26
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
40
27
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
41
-
42
28
  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; }
43
-
44
29
  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; }
45
-
46
- 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; }
47
-
30
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
32
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
48
33
  function _default(plugin, more = {}) {
49
34
  const instructions = plugin.instructions;
50
35
  const natives = ['calculation', 'condition', 'parallel', 'delay', 'manual', 'query', 'create', 'update', 'destroy', 'request'].reduce((result, key) => Object.assign(result, {
51
36
  [key]: (0, _utils().requireModule)(_path().default.isAbsolute(key) ? key : _path().default.join(__dirname, key))
52
37
  }), {});
53
-
54
38
  for (var _i = 0, _Object$entries = Object.entries(_objectSpread(_objectSpread({}, more), natives)); _i < _Object$entries.length; _i++) {
55
39
  const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
56
- name = _Object$entries$_i[0],
57
- instruction = _Object$entries$_i[1];
58
-
40
+ name = _Object$entries$_i[0],
41
+ instruction = _Object$entries$_i[1];
59
42
  instructions.register(name, typeof instruction === 'function' ? new instruction(plugin) : instruction);
60
43
  }
61
44
  }
@@ -4,45 +4,39 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.submit = submit;
7
-
8
7
  function _actions() {
9
8
  const data = require("@nocobase/actions");
10
-
11
9
  _actions = function _actions() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  var _constants = require("../../constants");
19
-
15
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
+ 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."); }
17
+ 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); }
18
+ 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; }
19
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
20
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
21
  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); } }
21
-
22
22
  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); }); }; }
23
-
24
23
  function submit(_x, _x2) {
25
24
  return _submit.apply(this, arguments);
26
25
  }
27
-
28
26
  function _submit() {
29
27
  _submit = _asyncToGenerator(function* (context, next) {
30
28
  const repository = _actions().utils.getRepositoryFromParams(context);
31
-
32
29
  const _context$action$param = context.action.params,
33
- filterByTk = _context$action$param.filterByTk,
34
- values = _context$action$param.values;
30
+ filterByTk = _context$action$param.filterByTk,
31
+ values = _context$action$param.values;
35
32
  const currentUser = context.state.currentUser;
36
-
37
33
  if (!currentUser) {
38
34
  return context.throw(401);
39
35
  }
40
-
41
36
  const plugin = context.app.pm.get('workflow');
42
37
  const userJob = yield context.db.sequelize.transaction( /*#__PURE__*/function () {
43
38
  var _ref = _asyncToGenerator(function* (transaction) {
44
- var _instance$node$config2;
45
-
39
+ var _values$result, _forms$form, _forms$form$actions, _instance$node$config2;
46
40
  const instance = yield repository.findOne({
47
41
  filterByTk,
48
42
  // filter: {
@@ -52,30 +46,28 @@ function _submit() {
52
46
  context,
53
47
  transaction
54
48
  });
55
-
56
49
  if (!instance) {
57
50
  return context.throw(404);
58
51
  }
59
-
60
- const _instance$node$config = instance.node.config.actions,
61
- actions = _instance$node$config === void 0 ? [] : _instance$node$config; // NOTE: validate status
62
-
63
- if (instance.status !== _constants.JOB_STATUS.PENDING || instance.job.status !== _constants.JOB_STATUS.PENDING || instance.execution.status !== _constants.EXECUTION_STATUS.STARTED || !instance.workflow.enabled || !actions.includes(values.status)) {
52
+ const _instance$node$config = instance.node.config.forms,
53
+ forms = _instance$node$config === void 0 ? {} : _instance$node$config;
54
+ const _Object$keys = Object.keys((_values$result = values.result) !== null && _values$result !== void 0 ? _values$result : {}),
55
+ _Object$keys2 = _slicedToArray(_Object$keys, 1),
56
+ form = _Object$keys2[0];
57
+ // NOTE: validate status
58
+ if (instance.status !== _constants.JOB_STATUS.PENDING || instance.job.status !== _constants.JOB_STATUS.PENDING || instance.execution.status !== _constants.EXECUTION_STATUS.STARTED || !instance.workflow.enabled || !((_forms$form = forms[form]) === null || _forms$form === void 0 ? void 0 : (_forms$form$actions = _forms$form.actions) === null || _forms$form$actions === void 0 ? void 0 : _forms$form$actions.includes(values.status))) {
64
59
  return context.throw(400);
65
60
  }
66
-
67
61
  instance.execution.workflow = instance.workflow;
68
62
  const processor = plugin.createProcessor(instance.execution, {
69
63
  transaction
70
64
  });
71
65
  yield processor.prepare();
72
66
  const assignees = processor.getParsedValue((_instance$node$config2 = instance.node.config.assignees) !== null && _instance$node$config2 !== void 0 ? _instance$node$config2 : []);
73
-
74
67
  if (!assignees.includes(currentUser.id) || instance.userId !== currentUser.id) {
75
68
  return context.throw(403);
76
- } // NOTE: validate assignee
77
-
78
-
69
+ }
70
+ // NOTE: validate assignee
79
71
  yield instance.update({
80
72
  status: values.status,
81
73
  result: values.result
@@ -84,17 +76,16 @@ function _submit() {
84
76
  });
85
77
  return instance;
86
78
  });
87
-
88
79
  return function (_x3) {
89
80
  return _ref.apply(this, arguments);
90
81
  };
91
- }()); // await transaction.commit();
92
-
82
+ }());
83
+ // await transaction.commit();
93
84
  context.body = userJob;
94
85
  context.status = 202;
95
86
  yield next();
96
- userJob.job.latestUserJob = userJob; // NOTE: resume the process and no `await` for quick returning
97
-
87
+ userJob.job.latestUserJob = userJob;
88
+ // NOTE: resume the process and no `await` for quick returning
98
89
  plugin.resume(userJob.job);
99
90
  });
100
91
  return _submit.apply(this, arguments);
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _default = {
8
- namespace: 'workflow',
8
+ namespace: 'workflow.executionLogs',
9
9
  name: 'users_jobs',
10
10
  duplicator: 'optional',
11
11
  fields: [{
@@ -1,20 +1,20 @@
1
1
  import Plugin from '../..';
2
2
  import { Instruction } from '..';
3
+ declare type FormType = {
4
+ type: 'custom' | 'create' | 'update';
5
+ actions: number[];
6
+ options: {
7
+ [key: string]: any;
8
+ };
9
+ };
3
10
  export interface ManualConfig {
4
11
  schema: {
5
- collection: {
6
- name: string;
7
- fields: any[];
8
- };
9
- blocks: {
10
- [key: string]: any;
11
- };
12
- actions: {
13
- [key: string]: any;
14
- };
12
+ [key: string]: any;
15
13
  };
16
- actions: number[];
17
- assignees?: number[];
14
+ forms: {
15
+ [key: string]: FormType;
16
+ };
17
+ assignees?: (number | string)[];
18
18
  mode?: number;
19
19
  }
20
20
  export default class implements Instruction {
@@ -23,3 +23,4 @@ export default class implements Instruction {
23
23
  run(node: any, prevJob: any, processor: any): Promise<any>;
24
24
  resume(node: any, job: any, processor: any): Promise<any>;
25
25
  }
26
+ export {};
@@ -4,39 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _actions() {
9
8
  const data = _interopRequireDefault(require("@nocobase/actions"));
10
-
11
9
  _actions = function _actions() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  var _constants = require("../../constants");
19
-
20
15
  var _jobs = _interopRequireDefault(require("./collecions/jobs"));
21
-
22
16
  var _users = _interopRequireDefault(require("./collecions/users"));
23
-
24
17
  var _users_jobs = _interopRequireDefault(require("./collecions/users_jobs"));
25
-
26
18
  var _actions2 = require("./actions");
27
-
28
19
  const _excluded = ["mode"];
29
-
30
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
21
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
-
34
22
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
-
36
23
  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); } }
37
-
38
24
  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); }); }; }
39
-
40
25
  const MULTIPLE_ASSIGNED_MODE = {
41
26
  SINGLE: Symbol('single'),
42
27
  ALL: Symbol('all'),
@@ -50,65 +35,49 @@ const Modes = {
50
35
  const done = distribution.find(item => item.status !== _constants.JOB_STATUS.PENDING && item.count > 0);
51
36
  return done ? done.status : null;
52
37
  }
53
-
54
38
  },
55
39
  [MULTIPLE_ASSIGNED_MODE.ALL]: {
56
40
  getStatus(distribution, assignees) {
57
41
  const resolved = distribution.find(item => item.status === _constants.JOB_STATUS.RESOLVED);
58
-
59
42
  if (resolved && resolved.count === assignees.length) {
60
43
  return _constants.JOB_STATUS.RESOLVED;
61
44
  }
62
-
63
45
  const rejected = distribution.find(item => item.status < _constants.JOB_STATUS.PENDING);
64
-
65
46
  if (rejected && rejected.count) {
66
47
  return rejected.status;
67
48
  }
68
-
69
49
  return null;
70
50
  }
71
-
72
51
  },
73
52
  [MULTIPLE_ASSIGNED_MODE.ANY]: {
74
53
  getStatus(distribution, assignees) {
75
54
  const resolved = distribution.find(item => item.status === _constants.JOB_STATUS.RESOLVED);
76
-
77
55
  if (resolved && resolved.count) {
78
56
  return _constants.JOB_STATUS.RESOLVED;
79
57
  }
80
-
81
- const rejectedCount = distribution.reduce((count, item) => item.status < _constants.JOB_STATUS.PENDING ? count + item.count : count, 0); // NOTE: all failures are considered as rejected for now
82
-
58
+ const rejectedCount = distribution.reduce((count, item) => item.status < _constants.JOB_STATUS.PENDING ? count + item.count : count, 0);
59
+ // NOTE: all failures are considered as rejected for now
83
60
  if (rejectedCount === assignees.length) {
84
61
  return _constants.JOB_STATUS.REJECTED;
85
62
  }
86
-
87
63
  return null;
88
64
  }
89
-
90
65
  }
91
66
  };
92
-
93
67
  function getMode(mode) {
94
68
  switch (true) {
95
69
  case mode === 1:
96
70
  return Modes[MULTIPLE_ASSIGNED_MODE.ALL];
97
-
98
71
  case mode === -1:
99
72
  return Modes[MULTIPLE_ASSIGNED_MODE.ANY];
100
-
101
73
  case mode > 0:
102
74
  return Modes[MULTIPLE_ASSIGNED_MODE.ALL_PERCENTAGE];
103
-
104
75
  case mode < 0:
105
76
  return Modes[MULTIPLE_ASSIGNED_MODE.ANY_PERCENTAGE];
106
-
107
77
  default:
108
78
  return Modes[MULTIPLE_ASSIGNED_MODE.SINGLE];
109
79
  }
110
80
  }
111
-
112
81
  class _default {
113
82
  constructor(plugin) {
114
83
  this.plugin = void 0;
@@ -136,23 +105,20 @@ class _default {
136
105
  }
137
106
  });
138
107
  }
139
-
140
108
  run(node, prevJob, processor) {
141
109
  return _asyncToGenerator(function* () {
142
110
  var _prevJob$id;
143
-
144
111
  const _node$config = node.config,
145
- mode = _node$config.mode,
146
- config = _objectWithoutProperties(_node$config, _excluded);
147
-
112
+ mode = _node$config.mode,
113
+ config = _objectWithoutProperties(_node$config, _excluded);
148
114
  const assignees = [...new Set(processor.getParsedValue(config.assignees) || [])];
149
115
  const job = yield processor.saveJob({
150
116
  status: _constants.JOB_STATUS.PENDING,
151
117
  result: mode ? [] : null,
152
118
  nodeId: node.id,
153
119
  upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
154
- }); // NOTE: batch create users jobs
155
-
120
+ });
121
+ // NOTE: batch create users jobs
156
122
  const UserJobModel = processor.options.plugin.db.getModel('users_jobs');
157
123
  yield UserJobModel.bulkCreate(assignees.map(userId => ({
158
124
  userId,
@@ -167,16 +133,14 @@ class _default {
167
133
  return job;
168
134
  })();
169
135
  }
170
-
171
136
  resume(node, job, processor) {
172
137
  return _asyncToGenerator(function* () {
173
138
  var _job$latestUserJob$re, _job$latestUserJob, _getMode$getStatus;
174
-
175
139
  // NOTE: check all users jobs related if all done then continue as parallel
176
140
  const _node$config2 = node.config,
177
- _node$config2$assigne = _node$config2.assignees,
178
- assignees = _node$config2$assigne === void 0 ? [] : _node$config2$assigne,
179
- mode = _node$config2.mode;
141
+ _node$config2$assigne = _node$config2.assignees,
142
+ assignees = _node$config2$assigne === void 0 ? [] : _node$config2$assigne,
143
+ mode = _node$config2.mode;
180
144
  const UserJobModel = processor.options.plugin.db.getModel('users_jobs');
181
145
  const distribution = yield UserJobModel.count({
182
146
  where: {
@@ -193,8 +157,6 @@ class _default {
193
157
  return job;
194
158
  })();
195
159
  }
196
-
197
160
  }
198
-
199
161
  exports.default = _default;
200
162
  ;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.PARALLEL_MODE = void 0;
7
-
8
7
  var _constants = require("../constants");
9
-
10
8
  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); } }
11
-
12
9
  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); }); }; }
13
-
14
10
  const PARALLEL_MODE = {
15
11
  ALL: 'all',
16
12
  ANY: 'any',
@@ -22,127 +18,104 @@ const Modes = {
22
18
  next(previous) {
23
19
  return previous.status >= _constants.JOB_STATUS.PENDING;
24
20
  },
25
-
26
21
  getStatus(result) {
27
22
  const failedStatus = result.find(status => status != null && status < _constants.JOB_STATUS.PENDING);
28
-
29
23
  if (typeof failedStatus !== 'undefined') {
30
24
  return failedStatus;
31
25
  }
32
-
33
26
  if (result.every(status => status != null && status === _constants.JOB_STATUS.RESOLVED)) {
34
27
  return _constants.JOB_STATUS.RESOLVED;
35
28
  }
36
-
37
29
  return _constants.JOB_STATUS.PENDING;
38
30
  }
39
-
40
31
  },
41
32
  [PARALLEL_MODE.ANY]: {
42
33
  next(previous) {
43
34
  return previous.status <= _constants.JOB_STATUS.PENDING;
44
35
  },
45
-
46
36
  getStatus(result) {
47
37
  if (result.some(status => status != null && status === _constants.JOB_STATUS.RESOLVED)) {
48
38
  return _constants.JOB_STATUS.RESOLVED;
49
39
  }
50
-
51
40
  if (result.some(status => status != null ? status === _constants.JOB_STATUS.PENDING : true)) {
52
41
  return _constants.JOB_STATUS.PENDING;
53
42
  }
54
-
55
43
  return _constants.JOB_STATUS.FAILED;
56
44
  }
57
-
58
45
  },
59
46
  [PARALLEL_MODE.RACE]: {
60
47
  next(previous) {
61
48
  return previous.status === _constants.JOB_STATUS.PENDING;
62
49
  },
63
-
64
50
  getStatus(result) {
65
51
  if (result.some(status => status != null && status === _constants.JOB_STATUS.RESOLVED)) {
66
52
  return _constants.JOB_STATUS.RESOLVED;
67
53
  }
68
-
69
54
  const failedStatus = result.find(status => status != null && status < _constants.JOB_STATUS.PENDING);
70
-
71
55
  if (typeof failedStatus !== 'undefined') {
72
56
  return failedStatus;
73
57
  }
74
-
75
58
  return _constants.JOB_STATUS.PENDING;
76
59
  }
77
-
78
60
  }
79
61
  };
80
62
  var _default = {
81
63
  run(node, prevJob, processor) {
82
64
  return _asyncToGenerator(function* () {
83
65
  var _prevJob$id;
84
-
85
66
  const branches = processor.getBranches(node);
86
67
  const job = yield processor.saveJob({
87
68
  status: _constants.JOB_STATUS.PENDING,
88
69
  result: Array(branches.length).fill(null),
89
70
  nodeId: node.id,
90
71
  upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
91
- }); // NOTE:
72
+ });
73
+ // NOTE:
92
74
  // use `reduce` but not `Promise.all` here to avoid racing manupulating db.
93
75
  // for users, this is almost equivalent to `Promise.all`,
94
76
  // because of the delay is not significant sensible.
95
77
  // another benifit of this is, it could handle sequenced branches in future.
96
-
97
78
  const _node$config$mode = node.config.mode,
98
- mode = _node$config$mode === void 0 ? PARALLEL_MODE.ALL : _node$config$mode;
79
+ mode = _node$config$mode === void 0 ? PARALLEL_MODE.ALL : _node$config$mode;
99
80
  yield branches.reduce((promise, branch, i) => promise.then(previous => {
100
81
  if (i && !Modes[mode].next(previous)) {
101
82
  return Promise.resolve(previous);
102
83
  }
103
-
104
84
  return processor.run(branch, job);
105
85
  }), Promise.resolve());
106
86
  return processor.end(node, job);
107
87
  })();
108
88
  },
109
-
110
89
  resume(node, branchJob, processor) {
111
90
  return _asyncToGenerator(function* () {
112
91
  const job = processor.findBranchParentJob(branchJob, node);
113
92
  const result = job.result,
114
- status = job.status; // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.
115
-
93
+ status = job.status;
94
+ // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.
116
95
  if (status !== _constants.JOB_STATUS.PENDING) {
117
96
  return null;
118
- } // find the index of the node which start the branch
119
-
120
-
97
+ }
98
+ // find the index of the node which start the branch
121
99
  const jobNode = processor.nodesMap.get(branchJob.nodeId);
122
100
  const branchStartNode = processor.findBranchStartNode(jobNode, node);
123
101
  const branches = processor.getBranches(node);
124
102
  const branchIndex = branches.indexOf(branchStartNode);
125
-
126
103
  const _ref = node.config || {},
127
- _ref$mode = _ref.mode,
128
- mode = _ref$mode === void 0 ? PARALLEL_MODE.ALL : _ref$mode;
129
-
104
+ _ref$mode = _ref.mode,
105
+ mode = _ref$mode === void 0 ? PARALLEL_MODE.ALL : _ref$mode;
130
106
  const newResult = [...result.slice(0, branchIndex), branchJob.status, ...result.slice(branchIndex + 1)];
131
107
  job.set({
132
108
  result: newResult,
133
109
  status: Modes[mode].getStatus(newResult)
134
110
  });
135
-
136
111
  if (job.status === _constants.JOB_STATUS.PENDING) {
137
112
  yield job.save({
138
113
  transaction: processor.transaction
139
114
  });
140
115
  return processor.end(node, job);
141
116
  }
142
-
143
117
  return job;
144
118
  })();
145
119
  }
146
-
147
120
  };
148
121
  exports.default = _default;
@@ -4,27 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _constants = require("../constants");
9
-
10
8
  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; }
11
-
12
9
  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; }
13
-
14
- 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; }
15
-
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
12
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
16
13
  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); } }
17
-
18
14
  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); }); }; }
19
-
20
15
  var _default = {
21
16
  run(node, input, processor) {
22
17
  return _asyncToGenerator(function* () {
23
18
  const _node$config = node.config,
24
- collection = _node$config.collection,
25
- multiple = _node$config.multiple,
26
- _node$config$params = _node$config.params,
27
- params = _node$config$params === void 0 ? {} : _node$config$params;
19
+ collection = _node$config.collection,
20
+ multiple = _node$config.multiple,
21
+ _node$config$params = _node$config.params,
22
+ params = _node$config$params === void 0 ? {} : _node$config$params,
23
+ _node$config$failOnEm = _node$config.failOnEmpty,
24
+ failOnEmpty = _node$config$failOnEm === void 0 ? false : _node$config$failOnEm;
28
25
  const repo = node.constructor.database.getRepository(collection);
29
26
  const options = processor.getParsedValue(params);
30
27
  const result = yield (multiple ? repo.find : repo.findOne).call(repo, _objectSpread(_objectSpread({}, options), {}, {
@@ -32,16 +29,21 @@ var _default = {
32
29
  executionId: processor.execution.id
33
30
  },
34
31
  transaction: processor.transaction
35
- })); // NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
32
+ }));
33
+ if (failOnEmpty && (multiple ? !result.length : !result)) {
34
+ return {
35
+ result,
36
+ status: _constants.JOB_STATUS.FAILED
37
+ };
38
+ }
39
+ // NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
36
40
  // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
37
41
  // so the properties can not be get by json-templates(object-path)
38
-
39
42
  return {
40
43
  result: multiple ? result.map(item => item.toJSON()) : result === null || result === void 0 ? void 0 : result.toJSON(),
41
44
  status: _constants.JOB_STATUS.RESOLVED
42
45
  };
43
46
  })();
44
47
  }
45
-
46
48
  };
47
49
  exports.default = _default;