@nocobase/plugin-workflow 0.11.0-alpha.1 → 0.11.1-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 (133) hide show
  1. package/lib/client/AddButton.js +13 -4
  2. package/lib/client/Branch.js +4 -2
  3. package/lib/client/CanvasContent.js +6 -4
  4. package/lib/client/ExecutionCanvas.js +18 -7
  5. package/lib/client/ExecutionPage.js +4 -2
  6. package/lib/client/WorkflowCanvas.js +16 -6
  7. package/lib/client/WorkflowPage.js +4 -2
  8. package/lib/client/WorkflowProvider.js +2 -2
  9. package/lib/client/components/CollectionBlockInitializer.js +3 -3
  10. package/lib/client/components/CollectionFieldset.js +7 -1
  11. package/lib/client/components/FieldsSelect.js +4 -1
  12. package/lib/client/components/NodeDescription.js +36 -22
  13. package/lib/client/index.js +3 -3
  14. package/lib/client/locale/zh-CN.d.ts +5 -1
  15. package/lib/client/locale/zh-CN.js +6 -2
  16. package/lib/client/nodes/aggregate.d.ts +6 -1
  17. package/lib/client/nodes/aggregate.js +4 -3
  18. package/lib/client/nodes/calculation.d.ts +5 -3
  19. package/lib/client/nodes/calculation.js +6 -5
  20. package/lib/client/nodes/condition.d.ts +1 -7
  21. package/lib/client/nodes/condition.js +12 -23
  22. package/lib/client/nodes/create.d.ts +2 -4
  23. package/lib/client/nodes/create.js +1 -3
  24. package/lib/client/nodes/index.d.ts +1 -2
  25. package/lib/client/nodes/index.js +24 -24
  26. package/lib/client/nodes/loop.js +19 -28
  27. package/lib/client/nodes/manual/FormBlockInitializer.js +6 -5
  28. package/lib/client/nodes/manual/SchemaConfig.d.ts +1 -2
  29. package/lib/client/nodes/manual/SchemaConfig.js +175 -21
  30. package/lib/client/nodes/manual/WorkflowTodo.js +39 -46
  31. package/lib/client/nodes/manual/forms/create.js +8 -1
  32. package/lib/client/nodes/manual/forms/custom.js +11 -4
  33. package/lib/client/nodes/manual/forms/update.js +8 -1
  34. package/lib/client/nodes/manual/index.d.ts +6 -1
  35. package/lib/client/nodes/manual/index.js +5 -4
  36. package/lib/client/nodes/parallel.js +7 -4
  37. package/lib/client/nodes/query.d.ts +2 -5
  38. package/lib/client/nodes/query.js +1 -3
  39. package/lib/client/nodes/sql.d.ts +26 -0
  40. package/lib/client/{triggers/schedule/DateFieldsSelect.js → nodes/sql.js} +37 -46
  41. package/lib/client/schemas/collection.d.ts +2 -3
  42. package/lib/client/schemas/collection.js +8 -7
  43. package/lib/client/style.d.ts +18 -13
  44. package/lib/client/style.js +312 -289
  45. package/lib/client/triggers/collection.d.ts +9 -10
  46. package/lib/client/triggers/collection.js +4 -0
  47. package/lib/client/triggers/index.d.ts +2 -3
  48. package/lib/client/triggers/index.js +10 -5
  49. package/lib/client/triggers/schedule/OnField.js +35 -23
  50. package/lib/client/triggers/schedule/ScheduleConfig.js +7 -7
  51. package/lib/client/triggers/schedule/index.d.ts +0 -1
  52. package/lib/client/triggers/schedule/index.js +31 -19
  53. package/lib/client/variable.d.ts +29 -11
  54. package/lib/client/variable.js +39 -24
  55. package/lib/server/Plugin.d.ts +1 -3
  56. package/lib/server/Plugin.js +10 -6
  57. package/lib/server/Processor.d.ts +1 -1
  58. package/lib/server/Processor.js +2 -2
  59. package/lib/server/instructions/create.d.ts +1 -1
  60. package/lib/server/instructions/create.js +13 -13
  61. package/lib/server/instructions/index.js +1 -1
  62. package/lib/server/instructions/manual/actions.js +19 -7
  63. package/lib/server/instructions/manual/forms/create.js +7 -1
  64. package/lib/server/instructions/manual/forms/update.js +7 -1
  65. package/lib/server/instructions/query.js +8 -1
  66. package/lib/server/instructions/request.d.ts +1 -1
  67. package/lib/server/instructions/request.js +4 -2
  68. package/lib/server/instructions/sql.d.ts +12 -0
  69. package/lib/server/instructions/sql.js +34 -0
  70. package/lib/server/migrations/20230710115902-manual-action-values.d.ts +4 -0
  71. package/lib/server/migrations/20230710115902-manual-action-values.js +97 -0
  72. package/lib/server/triggers/collection.js +13 -11
  73. package/lib/server/utils.d.ts +2 -0
  74. package/lib/server/utils.js +21 -0
  75. package/package.json +12 -11
  76. package/src/client/AddButton.tsx +17 -5
  77. package/src/client/Branch.tsx +4 -2
  78. package/src/client/CanvasContent.tsx +6 -4
  79. package/src/client/ExecutionCanvas.tsx +11 -13
  80. package/src/client/ExecutionPage.tsx +3 -2
  81. package/src/client/WorkflowCanvas.tsx +14 -13
  82. package/src/client/WorkflowPage.tsx +3 -2
  83. package/src/client/WorkflowProvider.tsx +2 -2
  84. package/src/client/components/CollectionBlockInitializer.tsx +3 -3
  85. package/src/client/components/CollectionFieldset.tsx +5 -3
  86. package/src/client/components/FieldsSelect.tsx +5 -1
  87. package/src/client/components/NodeDescription.tsx +30 -23
  88. package/src/client/index.tsx +3 -3
  89. package/src/client/locale/zh-CN.ts +8 -2
  90. package/src/client/nodes/aggregate.tsx +4 -4
  91. package/src/client/nodes/calculation.tsx +4 -5
  92. package/src/client/nodes/condition.tsx +7 -34
  93. package/src/client/nodes/create.tsx +0 -1
  94. package/src/client/nodes/index.tsx +21 -25
  95. package/src/client/nodes/loop.tsx +16 -31
  96. package/src/client/nodes/manual/FormBlockInitializer.tsx +6 -5
  97. package/src/client/nodes/manual/SchemaConfig.tsx +162 -18
  98. package/src/client/nodes/manual/WorkflowTodo.tsx +43 -47
  99. package/src/client/nodes/manual/forms/create.tsx +5 -1
  100. package/src/client/nodes/manual/forms/custom.tsx +7 -3
  101. package/src/client/nodes/manual/forms/update.tsx +5 -1
  102. package/src/client/nodes/manual/index.tsx +5 -5
  103. package/src/client/nodes/parallel.tsx +6 -5
  104. package/src/client/nodes/query.tsx +0 -1
  105. package/src/client/nodes/sql.tsx +37 -0
  106. package/src/client/schemas/collection.ts +6 -6
  107. package/src/client/style.tsx +324 -289
  108. package/src/client/triggers/collection.tsx +4 -0
  109. package/src/client/triggers/index.tsx +14 -10
  110. package/src/client/triggers/schedule/OnField.tsx +29 -15
  111. package/src/client/triggers/schedule/ScheduleConfig.tsx +21 -19
  112. package/src/client/triggers/schedule/index.tsx +25 -19
  113. package/src/client/variable.tsx +48 -26
  114. package/src/server/Plugin.ts +13 -9
  115. package/src/server/Processor.ts +2 -2
  116. package/src/server/__tests__/collections/categories.ts +4 -0
  117. package/src/server/__tests__/instructions/manual.test.ts +391 -72
  118. package/src/server/__tests__/instructions/request.test.ts +30 -0
  119. package/src/server/__tests__/instructions/sql.test.ts +162 -0
  120. package/src/server/__tests__/triggers/collection.test.ts +35 -0
  121. package/src/server/instructions/create.ts +13 -11
  122. package/src/server/instructions/index.ts +1 -0
  123. package/src/server/instructions/manual/actions.ts +16 -4
  124. package/src/server/instructions/manual/forms/create.ts +2 -1
  125. package/src/server/instructions/manual/forms/update.ts +3 -2
  126. package/src/server/instructions/query.ts +12 -1
  127. package/src/server/instructions/request.ts +2 -1
  128. package/src/server/instructions/sql.ts +25 -0
  129. package/src/server/migrations/20230710115902-manual-action-values.ts +78 -0
  130. package/src/server/triggers/collection.ts +15 -11
  131. package/src/server/utils.ts +17 -0
  132. package/lib/client/triggers/schedule/DateFieldsSelect.d.ts +0 -2
  133. package/src/client/triggers/schedule/DateFieldsSelect.tsx +0 -28
@@ -25,7 +25,7 @@ function submit(_x, _x2) {
25
25
  }
26
26
  function _submit() {
27
27
  _submit = _asyncToGenerator(function* (context, next) {
28
- var _values$result, _forms$formKey, _forms$formKey$action, _userJob$node$config$2, _userJob$result;
28
+ var _values$result, _values$result2, _forms$formKey, _forms$formKey$action, _userJob$node$config$2, _actionItem$values, _userJob$result;
29
29
  const repository = _actions().utils.getRepositoryFromParams(context);
30
30
  const _context$action$param = context.action.params,
31
31
  filterByTk = _context$action$param.filterByTk,
@@ -49,11 +49,13 @@ function _submit() {
49
49
  }
50
50
  const _userJob$node$config$ = userJob.node.config.forms,
51
51
  forms = _userJob$node$config$ === void 0 ? {} : _userJob$node$config$;
52
- const _Object$keys = Object.keys((_values$result = values.result) !== null && _values$result !== void 0 ? _values$result : {}),
53
- _Object$keys2 = _slicedToArray(_Object$keys, 1),
54
- formKey = _Object$keys2[0];
52
+ const _Object$keys$filter = Object.keys((_values$result = values.result) !== null && _values$result !== void 0 ? _values$result : {}).filter(key => key !== '_'),
53
+ _Object$keys$filter2 = _slicedToArray(_Object$keys$filter, 1),
54
+ formKey = _Object$keys$filter2[0];
55
+ const actionKey = (_values$result2 = values.result) === null || _values$result2 === void 0 ? void 0 : _values$result2._;
56
+ const actionItem = (_forms$formKey = forms[formKey]) === null || _forms$formKey === void 0 ? void 0 : (_forms$formKey$action = _forms$formKey.actions) === null || _forms$formKey$action === void 0 ? void 0 : _forms$formKey$action.find(item => item.key === actionKey);
55
57
  // NOTE: validate status
56
- if (userJob.status !== _constants.JOB_STATUS.PENDING || userJob.job.status !== _constants.JOB_STATUS.PENDING || userJob.execution.status !== _constants.EXECUTION_STATUS.STARTED || !userJob.workflow.enabled || !((_forms$formKey = forms[formKey]) !== null && _forms$formKey !== void 0 && (_forms$formKey$action = _forms$formKey.actions) !== null && _forms$formKey$action !== void 0 && _forms$formKey$action.includes(values.status))) {
58
+ if (userJob.status !== _constants.JOB_STATUS.PENDING || userJob.job.status !== _constants.JOB_STATUS.PENDING || userJob.execution.status !== _constants.EXECUTION_STATUS.STARTED || !userJob.workflow.enabled || !actionKey || (actionItem === null || actionItem === void 0 ? void 0 : actionItem.status) == null) {
57
59
  return context.throw(400);
58
60
  }
59
61
  userJob.execution.workflow = userJob.workflow;
@@ -64,9 +66,17 @@ function _submit() {
64
66
  if (!assignees.includes(currentUser.id) || userJob.userId !== currentUser.id) {
65
67
  return context.throw(403);
66
68
  }
69
+ const presetValues = processor.getParsedValue((_actionItem$values = actionItem.values) !== null && _actionItem$values !== void 0 ? _actionItem$values : {}, null, {
70
+ currentUser: currentUser.toJSON(),
71
+ currentRecord: values.result[formKey],
72
+ currentTime: new Date()
73
+ });
67
74
  userJob.set({
68
- status: values.status,
69
- result: values.status ? values.result : Object.assign((_userJob$result = userJob.result) !== null && _userJob$result !== void 0 ? _userJob$result : {}, values.result)
75
+ status: actionItem.status,
76
+ result: actionItem.status > _constants.JOB_STATUS.PENDING ? {
77
+ [formKey]: Object.assign(values.result[formKey], presetValues),
78
+ _: actionKey
79
+ } : Object.assign((_userJob$result = userJob.result) !== null && _userJob$result !== void 0 ? _userJob$result : {}, values.result)
70
80
  });
71
81
  const handler = instruction.formTypes.get(forms[formKey].type);
72
82
  if (handler && userJob.status) {
@@ -79,8 +89,10 @@ function _submit() {
79
89
  context.body = userJob;
80
90
  context.status = 202;
81
91
  yield next();
92
+ userJob.job.execution = userJob.execution;
82
93
  userJob.job.latestUserJob = userJob;
83
94
  // NOTE: resume the process and no `await` for quick returning
95
+ processor.logger.info(`manual node (${userJob.nodeId}) action trigger execution (${userJob.execution.id}) to resume`);
84
96
  plugin.resume(userJob.job);
85
97
  });
86
98
  return _submit.apply(this, arguments);
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
+ const _excluded = ["_"];
7
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; }
8
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; }
9
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; }
@@ -15,6 +16,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
15
16
  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; }
16
17
  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; } }
17
18
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+ 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; }
20
+ 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; }
18
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); } }
19
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); }); }; }
20
23
  function _default(_x, _x2, _x3) {
@@ -28,7 +31,10 @@ function _ref() {
28
31
  if (!repo) {
29
32
  throw new Error(`collection ${collection} for create data on manual node not found`);
30
33
  }
31
- const _Object$values = Object.values(instance.result),
34
+ const _instance$result = instance.result,
35
+ _ = _instance$result._,
36
+ form = _objectWithoutProperties(_instance$result, _excluded);
37
+ const _Object$values = Object.values(form),
32
38
  _Object$values2 = _slicedToArray(_Object$values, 1),
33
39
  values = _Object$values2[0];
34
40
  yield repo.create({
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
+ const _excluded = ["_"];
7
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; }
8
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; }
9
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; }
@@ -15,6 +16,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
15
16
  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; }
16
17
  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; } }
17
18
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+ 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; }
20
+ 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; }
18
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); } }
19
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); }); }; }
20
23
  function _default(_x, _x2, _x3) {
@@ -29,7 +32,10 @@ function _ref() {
29
32
  if (!repo) {
30
33
  throw new Error(`collection ${collection} for update data on manual node not found`);
31
34
  }
32
- const _Object$values = Object.values(instance.result),
35
+ const _instance$result = instance.result,
36
+ _ = _instance$result._,
37
+ form = _objectWithoutProperties(_instance$result, _excluded);
38
+ const _Object$values = Object.values(form),
33
39
  _Object$values2 = _slicedToArray(_Object$values, 1),
34
40
  values = _Object$values2[0];
35
41
  yield repo.update({
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _constants = require("../constants");
8
+ var _utils = require("../utils");
8
9
  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; }
9
10
  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; }
10
11
  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; }
@@ -24,7 +25,13 @@ var _default = {
24
25
  failOnEmpty = _node$config$failOnEm === void 0 ? false : _node$config$failOnEm;
25
26
  const repo = node.constructor.database.getRepository(collection);
26
27
  const options = processor.getParsedValue(params, node);
28
+ const appends = options.appends ? Array.from(options.appends.reduce((set, field) => {
29
+ set.add(field.split('.')[0]);
30
+ set.add(field);
31
+ return set;
32
+ }, new Set())) : options.appends;
27
33
  const result = yield (multiple ? repo.find : repo.findOne).call(repo, _objectSpread(_objectSpread({}, options), {}, {
34
+ appends: appends,
28
35
  transaction: processor.transaction
29
36
  }));
30
37
  if (failOnEmpty && (multiple ? !result.length : !result)) {
@@ -37,7 +44,7 @@ var _default = {
37
44
  // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
38
45
  // so the properties can not be get by json-templates(object-path)
39
46
  return {
40
- result: multiple ? result.map(item => item.toJSON()) : result === null || result === void 0 ? void 0 : result.toJSON(),
47
+ result: (0, _utils.toJSON)(result),
41
48
  status: _constants.JOB_STATUS.RESOLVED
42
49
  };
43
50
  })();
@@ -13,6 +13,6 @@ export type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'params'
13
13
  export default class implements Instruction {
14
14
  plugin: any;
15
15
  constructor(plugin: any);
16
- run(node: FlowNodeModel, input: any, processor: Processor): Promise<any>;
16
+ run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<any>;
17
17
  resume(node: FlowNodeModel, job: any, processor: Processor): Promise<any>;
18
18
  }
@@ -57,12 +57,14 @@ class _default {
57
57
  this.plugin = void 0;
58
58
  this.plugin = plugin;
59
59
  }
60
- run(node, input, processor) {
60
+ run(node, prevJob, processor) {
61
61
  var _this = this;
62
62
  return _asyncToGenerator(function* () {
63
+ var _prevJob$id;
63
64
  const job = yield processor.saveJob({
64
65
  status: _constants.JOB_STATUS.PENDING,
65
- nodeId: node.id
66
+ nodeId: node.id,
67
+ upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
66
68
  });
67
69
  const config = processor.getParsedValue(node.config, node);
68
70
  // eslint-disable-next-line promise/catch-or-return
@@ -0,0 +1,12 @@
1
+ import { Processor } from '..';
2
+ import type { FlowNodeModel } from '../types';
3
+ declare const _default: {
4
+ run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
5
+ status: number;
6
+ result?: undefined;
7
+ } | {
8
+ result: [unknown[], unknown];
9
+ status: number;
10
+ }>;
11
+ };
12
+ export default _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _ = require("..");
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); } }
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); }); }; }
10
+ var _default = {
11
+ run(node, input, processor) {
12
+ return _asyncToGenerator(function* () {
13
+ var _node$config$sql;
14
+ const sequelize = node.constructor.database.sequelize;
15
+ const sql = processor.getParsedValue((_node$config$sql = node.config.sql) !== null && _node$config$sql !== void 0 ? _node$config$sql : '', node).trim();
16
+ if (!sql) {
17
+ return {
18
+ status: _.JOB_STATUS.RESOLVED
19
+ };
20
+ }
21
+ const result = yield sequelize.query(sql, {
22
+ transaction: processor.transaction
23
+ // plain: true,
24
+ // model: db.getCollection(node.config.collection).model
25
+ });
26
+
27
+ return {
28
+ result,
29
+ status: _.JOB_STATUS.RESOLVED
30
+ };
31
+ })();
32
+ }
33
+ };
34
+ exports.default = _default;
@@ -0,0 +1,4 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class extends Migration {
3
+ up(): Promise<void>;
4
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _server() {
8
+ const data = require("@nocobase/server");
9
+ _server = function _server() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ 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; }
15
+ 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; }
16
+ 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; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
+ 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); }
19
+ 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); } }
20
+ 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); }); }; }
21
+ function findSchema(root, filter, onlyLeaf = false) {
22
+ const result = [];
23
+ if (!root) {
24
+ return result;
25
+ }
26
+ if (filter(root) && (!onlyLeaf || !root.properties)) {
27
+ result.push(root);
28
+ return result;
29
+ }
30
+ if (root.properties) {
31
+ Object.keys(root.properties).forEach(key => {
32
+ result.push(...findSchema(root.properties[key], filter));
33
+ });
34
+ }
35
+ return result;
36
+ }
37
+ function migrateConfig(config) {
38
+ const _config$forms = config.forms,
39
+ forms = _config$forms === void 0 ? {} : _config$forms,
40
+ _config$schema = config.schema,
41
+ schema = _config$schema === void 0 ? {} : _config$schema;
42
+ const root = {
43
+ properties: schema
44
+ };
45
+ Object.keys(forms).forEach(key => {
46
+ const form = forms[key];
47
+ const formSchema = findSchema(root, item => item.name === key);
48
+ const actions = findSchema(formSchema[0], item => item['x-component'] === 'Action');
49
+ form.actions = actions.map(action => {
50
+ action['x-designer'] = 'ManualActionDesigner';
51
+ action['x-action-settings'] = {};
52
+ delete action['x-action'];
53
+ return {
54
+ status: action['x-decorator-props'].value,
55
+ values: {},
56
+ key: action.name
57
+ };
58
+ });
59
+ });
60
+ return config;
61
+ }
62
+ class _default extends _server().Migration {
63
+ up() {
64
+ var _this = this;
65
+ return _asyncToGenerator(function* () {
66
+ const match = yield _this.app.version.satisfies('<0.11.0-alpha.2');
67
+ if (!match) {
68
+ return;
69
+ }
70
+ const db = _this.context.db;
71
+ const NodeRepo = db.getRepository('flow_nodes');
72
+ yield db.sequelize.transaction( /*#__PURE__*/function () {
73
+ var _ref = _asyncToGenerator(function* (transaction) {
74
+ const nodes = yield NodeRepo.find({
75
+ filter: {
76
+ type: 'manual'
77
+ },
78
+ transaction
79
+ });
80
+ console.log('%d nodes need to be migrated.', nodes.length);
81
+ yield nodes.reduce((promise, node) => promise.then(() => {
82
+ node.set('config', _objectSpread({}, migrateConfig(node.config)));
83
+ node.changed('config', true);
84
+ return node.save({
85
+ silent: true,
86
+ transaction
87
+ });
88
+ }), Promise.resolve());
89
+ });
90
+ return function (_x) {
91
+ return _ref.apply(this, arguments);
92
+ };
93
+ }());
94
+ })();
95
+ }
96
+ }
97
+ exports.default = _default;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _ = require("..");
8
+ var _utils = require("../utils");
8
9
  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."); }
10
11
  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; } }
@@ -72,22 +73,23 @@ function _handler() {
72
73
  return;
73
74
  }
74
75
  }
76
+ let result = data;
75
77
  if (appends !== null && appends !== void 0 && appends.length && !(mode & MODE_BITMAP.DESTROY)) {
76
- const includeFields = appends.filter(field => !data.get(field) || !data[field]);
77
- const included = yield model.findByPk(data[model.primaryKeyAttribute], {
78
- attributes: [model.primaryKeyAttribute],
79
- include: includeFields,
78
+ const includeFields = appends.reduce((set, field) => {
79
+ set.add(field.split('.')[0]);
80
+ set.add(field);
81
+ return set;
82
+ }, new Set());
83
+ result = yield repository.findOne({
84
+ filterByTk: data[model.primaryKeyAttribute],
85
+ appends: Array.from(includeFields),
80
86
  transaction
81
87
  });
82
- includeFields.forEach(field => {
83
- const value = included.get(field);
84
- data.set(field, Array.isArray(value) ? value.map(item => item.toJSON()) : value ? value.toJSON() : null, {
85
- raw: true
86
- });
87
- });
88
88
  }
89
+ // TODO: `result.toJSON()` throws error
90
+ const json = (0, _utils.toJSON)(result);
89
91
  this.plugin.trigger(workflow, {
90
- data: data.toJSON()
92
+ data: json
91
93
  }, {
92
94
  context
93
95
  });
@@ -0,0 +1,2 @@
1
+ import { Model } from '@nocobase/database';
2
+ export declare function toJSON(data: Model | Model[]): object;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toJSON = toJSON;
7
+ function toJSON(data) {
8
+ if (typeof data !== 'object' || !data) {
9
+ return data;
10
+ }
11
+ if (Array.isArray(data)) {
12
+ return data.map(toJSON);
13
+ }
14
+ const result = data.get();
15
+ Object.keys(data.constructor.associations).forEach(key => {
16
+ if (result[key] != null) {
17
+ result[key] = toJSON(result[key]);
18
+ }
19
+ });
20
+ return result;
21
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流",
5
5
  "description": "A powerful workflow plugin designed to support business process management and automation.",
6
6
  "description.zh-CN": "工作流插件,为业务流程管理和自动化提供支持。",
7
- "version": "0.11.0-alpha.1",
7
+ "version": "0.11.1-alpha.2",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./lib/server/index.js",
10
10
  "files": [
@@ -23,11 +23,9 @@
23
23
  "classnames": "^2.3.1",
24
24
  "cron-parser": "4.4.0",
25
25
  "lru-cache": "8.0.5",
26
- "react-js-cron": "^3.1.0",
27
- "sequelize": "^6.26.0",
28
- "winston": "^3.8.2"
26
+ "react-js-cron": "^3.1.0"
29
27
  },
30
- "devDependencies": {
28
+ "peerDependencies": {
31
29
  "@ant-design/icons": "^5.1.4",
32
30
  "@formily/antd-v5": "1.1.0-beta.4",
33
31
  "@formily/core": "2.2.26",
@@ -37,18 +35,21 @@
37
35
  "@nocobase/database": "0.11.0-alpha.1",
38
36
  "@nocobase/evaluators": "0.11.0-alpha.1",
39
37
  "@nocobase/logger": "0.11.0-alpha.1",
40
- "@nocobase/plugin-formula-field": "0.11.0-alpha.1",
41
38
  "@nocobase/plugin-users": "0.11.0-alpha.1",
42
39
  "@nocobase/resourcer": "0.11.0-alpha.1",
43
40
  "@nocobase/server": "0.11.0-alpha.1",
44
- "@nocobase/test": "0.11.0-alpha.1",
45
41
  "@nocobase/utils": "0.11.0-alpha.1",
46
- "@types/ejs": "^3.1.1",
47
- "antd": "5.6.3",
42
+ "antd": "^5.6.4",
48
43
  "dayjs": "^1.11.8",
49
44
  "react": "18.x",
50
45
  "react-i18next": "^11.15.1",
51
- "react-router-dom": "^6.11.2"
46
+ "react-router-dom": "^6.11.2",
47
+ "sequelize": "^6.26.0",
48
+ "winston": "^3.8.2"
49
+ },
50
+ "devDependencies": {
51
+ "@nocobase/test": "0.11.1-alpha.2",
52
+ "@types/ejs": "^3.1.1"
52
53
  },
53
- "gitHead": "7581b6d3a3a54f09f06a9effb7e3e65328281b2b"
54
+ "gitHead": "8482aa720ea1c3abbbb9fe1208e73778bd63f1cf"
54
55
  }
@@ -1,11 +1,11 @@
1
1
  import { PlusOutlined } from '@ant-design/icons';
2
- import { cx, useAPIClient, useCompile } from '@nocobase/client';
2
+ import { cx, css, useAPIClient, useCompile } from '@nocobase/client';
3
3
  import { Button, Dropdown, MenuProps } from 'antd';
4
4
  import React, { useCallback, useMemo } from 'react';
5
5
  import { useFlowContext } from './FlowContext';
6
6
  import { NAMESPACE } from './locale';
7
7
  import { Instruction, instructions } from './nodes';
8
- import { addButtonClass } from './style';
8
+ import useStyles from './style';
9
9
 
10
10
  interface AddButtonProps {
11
11
  upstream;
@@ -17,6 +17,8 @@ export function AddButton({ upstream, branchIndex = null }: AddButtonProps) {
17
17
  const api = useAPIClient();
18
18
  const { workflow, refresh } = useFlowContext() ?? {};
19
19
  const instructionList = Array.from(instructions.getValues()) as Instruction[];
20
+ const { styles } = useStyles();
21
+
20
22
  const groups = useMemo(() => {
21
23
  return [
22
24
  { key: 'control', label: `{{t("Control", { ns: "${NAMESPACE}" })}}` },
@@ -80,7 +82,7 @@ export function AddButton({ upstream, branchIndex = null }: AddButtonProps) {
80
82
 
81
83
  const menu = useMemo<MenuProps>(() => {
82
84
  return {
83
- onClick: (ev) => onCreate(ev),
85
+ onClick: onCreate,
84
86
  items: compile(groups),
85
87
  };
86
88
  }, [groups, onCreate]);
@@ -90,8 +92,18 @@ export function AddButton({ upstream, branchIndex = null }: AddButtonProps) {
90
92
  }
91
93
 
92
94
  return (
93
- <div className={cx(addButtonClass)}>
94
- <Dropdown trigger={['click']} menu={menu} disabled={workflow.executed}>
95
+ <div className={styles.addButtonClass}>
96
+ <Dropdown
97
+ trigger={['click']}
98
+ menu={menu}
99
+ disabled={workflow.executed}
100
+ overlayClassName={css`
101
+ .ant-dropdown-menu-root{
102
+ max-height: 30em;
103
+ overflow-y: auto;
104
+ }
105
+ `}
106
+ >
95
107
  <Button shape="circle" icon={<PlusOutlined />} />
96
108
  </Dropdown>
97
109
  </div>
@@ -2,7 +2,7 @@ import { cx } from '@nocobase/client';
2
2
  import React from 'react';
3
3
  import { AddButton } from './AddButton';
4
4
  import { Node } from './nodes';
5
- import { branchClass } from './style';
5
+ import useStyles from './style';
6
6
 
7
7
  export function Branch({
8
8
  from = null,
@@ -15,13 +15,15 @@ export function Branch({
15
15
  branchIndex?: number | null;
16
16
  controller?: any;
17
17
  }) {
18
+ const { styles } = useStyles();
19
+
18
20
  const list: any[] = [];
19
21
  for (let node = entry; node; node = node.downstream) {
20
22
  list.push(node);
21
23
  }
22
24
 
23
25
  return (
24
- <div className={cx(branchClass)}>
26
+ <div className={cx(styles.branchClass)}>
25
27
  <div className="workflow-branch-lines" />
26
28
  {controller}
27
29
  <AddButton upstream={from} branchIndex={branchIndex} />
@@ -3,18 +3,20 @@ import { Tag } from 'antd';
3
3
  import React from 'react';
4
4
  import { Branch } from './Branch';
5
5
  import { lang } from './locale';
6
- import { branchBlockClass, nodeCardClass, nodeMetaClass } from './style';
6
+ import useStyles from './style';
7
7
  import { TriggerConfig } from './triggers';
8
8
 
9
9
  export function CanvasContent({ entry }) {
10
+ const { styles } = useStyles();
11
+
10
12
  return (
11
13
  <div className="workflow-canvas">
12
14
  <TriggerConfig />
13
- <div className={branchBlockClass}>
15
+ <div className={styles.branchBlockClass}>
14
16
  <Branch entry={entry} />
15
17
  </div>
16
- <div className={cx('end', nodeCardClass)}>
17
- <div className={cx(nodeMetaClass)}>
18
+ <div className={cx('end', styles.nodeCardClass)}>
19
+ <div className={cx(styles.nodeMetaClass)}>
18
20
  <Tag color="#333">{lang('End')}</Tag>
19
21
  </div>
20
22
  </div>
@@ -15,7 +15,7 @@ import { ExecutionStatusOptionsMap, JobStatusOptions } from './constants';
15
15
  import { FlowContext, useFlowContext } from './FlowContext';
16
16
  import { lang, NAMESPACE } from './locale';
17
17
  import { instructions } from './nodes';
18
- import { nodeTitleClass } from './style';
18
+ import useStyles from './style';
19
19
  import { linkNodes } from './utils';
20
20
 
21
21
  function attachJobs(nodes, jobs: any[] = []): void {
@@ -41,6 +41,8 @@ function attachJobs(nodes, jobs: any[] = []): void {
41
41
  function JobModal() {
42
42
  const compile = useCompile();
43
43
  const { viewJob: job, setViewJob } = useFlowContext();
44
+ const { styles } = useStyles();
45
+
44
46
  const { node = {} } = job ?? {};
45
47
  const instruction = instructions.get(node.type);
46
48
 
@@ -58,7 +60,7 @@ function JobModal() {
58
60
  },
59
61
  'x-component': 'Action.Modal',
60
62
  title: (
61
- <div className={nodeTitleClass}>
63
+ <div className={styles.nodeTitleClass}>
62
64
  <Tag>{compile(instruction?.title)}</Tag>
63
65
  <strong>{node.title}</strong>
64
66
  <span className="workflow-node-id">#{node.id}</span>
@@ -144,17 +146,13 @@ export function ExecutionCanvas() {
144
146
  >
145
147
  <div className="workflow-toolbar">
146
148
  <header>
147
- <Breadcrumb>
148
- <Breadcrumb.Item>
149
- <Link to={`/admin/settings/workflow/workflows`}>{lang('Workflow')}</Link>
150
- </Breadcrumb.Item>
151
- <Breadcrumb.Item>
152
- <Link to={`/admin/settings/workflow/workflows/${workflow.id}`}>{workflow.title}</Link>
153
- </Breadcrumb.Item>
154
- <Breadcrumb.Item>
155
- <strong>{`#${execution.id}`}</strong>
156
- </Breadcrumb.Item>
157
- </Breadcrumb>
149
+ <Breadcrumb
150
+ items={[
151
+ { title: <Link to={`/admin/settings/workflow/workflows`}>{lang('Workflow')}</Link> },
152
+ { title: <Link to={`/admin/settings/workflow/workflows/${workflow.id}`}>{workflow.title}</Link> },
153
+ { title: <strong>{`#${execution.id}`}</strong> },
154
+ ]}
155
+ />
158
156
  </header>
159
157
  <aside>
160
158
  <Tag color={statusOption.color}>{compile(statusOption.label)}</Tag>
@@ -2,13 +2,14 @@ import { cx, SchemaComponent } from '@nocobase/client';
2
2
  import React from 'react';
3
3
  import { useParams } from 'react-router-dom';
4
4
  import { ExecutionCanvas } from './ExecutionCanvas';
5
- import { workflowPageClass } from './style';
5
+ import useStyles from './style';
6
6
 
7
7
  export const ExecutionPage = () => {
8
8
  const params = useParams<any>();
9
+ const { styles } = useStyles();
9
10
 
10
11
  return (
11
- <div className={cx(workflowPageClass)}>
12
+ <div className={cx(styles.workflowPageClass)}>
12
13
  <SchemaComponent
13
14
  schema={{
14
15
  type: 'void',