@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
@@ -56,7 +56,7 @@ function _react2() {
56
56
  }
57
57
  var _FlowContext = require("../FlowContext");
58
58
  var _locale = require("../locale");
59
- var _style = require("../style");
59
+ var _style = _interopRequireDefault(require("../style"));
60
60
  var _collection = _interopRequireDefault(require("./collection"));
61
61
  var _schedule = _interopRequireDefault(require("./schedule/"));
62
62
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -114,6 +114,8 @@ function TriggerExecution() {
114
114
  const _useFlowContext2 = (0, _FlowContext.useFlowContext)(),
115
115
  workflow = _useFlowContext2.workflow,
116
116
  execution = _useFlowContext2.execution;
117
+ const _useStyles = (0, _style.default)(),
118
+ styles = _useStyles.styles;
117
119
  if (!execution) {
118
120
  return null;
119
121
  }
@@ -126,7 +128,8 @@ function TriggerExecution() {
126
128
  'x-component-props': {
127
129
  title: _react2().default.createElement(_icons().InfoOutlined, null),
128
130
  shape: 'circle',
129
- className: _style.nodeJobButtonClass,
131
+ size: 'small',
132
+ className: styles.nodeJobButtonClass,
130
133
  type: 'primary'
131
134
  },
132
135
  properties: {
@@ -138,7 +141,7 @@ function TriggerExecution() {
138
141
  },
139
142
  'x-component': 'Action.Modal',
140
143
  title: _react2().default.createElement("div", {
141
- className: (0, _client().cx)(_style.nodeTitleClass)
144
+ className: (0, _client().cx)(styles.nodeTitleClass)
142
145
  }, _react2().default.createElement(_antd().Tag, null, compile(trigger.title)), _react2().default.createElement("strong", null, workflow.title), _react2().default.createElement("span", {
143
146
  className: "workflow-node-id"
144
147
  }, "#", execution.id)),
@@ -186,6 +189,8 @@ const TriggerConfig = () => {
186
189
  _useState4 = _slicedToArray(_useState3, 2),
187
190
  editingConfig = _useState4[0],
188
191
  setEditingConfig = _useState4[1];
192
+ const _useStyles2 = (0, _style.default)(),
193
+ styles = _useStyles2.styles;
189
194
  let typeTitle = '';
190
195
  (0, _react2().useEffect)(() => {
191
196
  if (workflow) {
@@ -248,10 +253,10 @@ const TriggerConfig = () => {
248
253
  }
249
254
  }
250
255
  return _react2().default.createElement("div", {
251
- className: (0, _client().cx)(_style.nodeCardClass),
256
+ className: (0, _client().cx)(styles.nodeCardClass),
252
257
  onClick: onOpenDrawer
253
258
  }, _react2().default.createElement("div", {
254
- className: (0, _client().cx)(_style.nodeMetaClass, 'workflow-node-meta')
259
+ className: (0, _client().cx)(styles.nodeMetaClass, 'workflow-node-meta')
255
260
  }, _react2().default.createElement(_antd().Tag, {
256
261
  color: "gold"
257
262
  }, titleText)), _react2().default.createElement("div", null, _react2().default.createElement(_antd().Input.TextArea, {
@@ -32,8 +32,8 @@ function _reactI18next() {
32
32
  };
33
33
  return data;
34
34
  }
35
+ var _FieldsSelect = require("../../components/FieldsSelect");
35
36
  var _locale = require("../../locale");
36
- var _DateFieldsSelect = require("./DateFieldsSelect");
37
37
  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); }
38
38
  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; }
39
39
  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; }
@@ -47,14 +47,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
47
47
  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; }
48
48
  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; } }
49
49
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
50
+ function dateFieldFilter(field) {
51
+ return !field.hidden && (field.uiSchema ? field.type === 'date' : false);
52
+ }
50
53
  function OnField({
51
54
  value,
52
55
  onChange: _onChange
53
56
  }) {
54
57
  const _useTranslation = (0, _reactI18next().useTranslation)(),
55
58
  t = _useTranslation.t;
56
- const _useWorkflowTranslati = (0, _locale.useWorkflowTranslation)(),
57
- localT = _useWorkflowTranslati.t;
58
59
  const _useState = (0, _react().useState)(value.offset ? value.offset / Math.abs(value.offset) : 0),
59
60
  _useState2 = _slicedToArray(_useState, 2),
60
61
  dir = _useState2[0],
@@ -64,11 +65,13 @@ function OnField({
64
65
  display: flex;
65
66
  gap: 0.5em;
66
67
  `
67
- }, _react().default.createElement(_DateFieldsSelect.DateFieldsSelect, {
68
+ }, _react().default.createElement(_FieldsSelect.FieldsSelect, {
68
69
  value: value.field,
69
70
  onChange: field => _onChange(_objectSpread(_objectSpread({}, value), {}, {
70
71
  field
71
- }))
72
+ })),
73
+ filter: dateFieldFilter,
74
+ placeholder: t('Select field')
72
75
  }), value.field ? _react().default.createElement(_antd().Select, {
73
76
  value: dir,
74
77
  onChange: v => {
@@ -76,14 +79,18 @@ function OnField({
76
79
  _onChange(_objectSpread(_objectSpread({}, value), {}, {
77
80
  offset: Math.abs(value.offset) * v
78
81
  }));
79
- }
80
- }, _react().default.createElement(_antd().Select.Option, {
81
- value: 0
82
- }, localT('Exactly at')), _react().default.createElement(_antd().Select.Option, {
83
- value: -1
84
- }, t('Before')), _react().default.createElement(_antd().Select.Option, {
85
- value: 1
86
- }, t('After'))) : null, dir ? _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().InputNumber, {
82
+ },
83
+ options: [{
84
+ value: 0,
85
+ label: (0, _locale.lang)('Exactly at')
86
+ }, {
87
+ value: -1,
88
+ label: t('Before')
89
+ }, {
90
+ value: 1,
91
+ label: t('After')
92
+ }]
93
+ }) : null, dir ? _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().InputNumber, {
87
94
  value: Math.abs(value.offset),
88
95
  onChange: v => _onChange(_objectSpread(_objectSpread({}, value), {}, {
89
96
  offset: (v !== null && v !== void 0 ? v : 0) * dir
@@ -92,14 +99,19 @@ function OnField({
92
99
  value: value.unit || 86400000,
93
100
  onChange: unit => _onChange(_objectSpread(_objectSpread({}, value), {}, {
94
101
  unit
95
- }))
96
- }, _react().default.createElement(_antd().Select.Option, {
97
- value: 86400000
98
- }, localT('Days')), _react().default.createElement(_antd().Select.Option, {
99
- value: 3600000
100
- }, localT('Hours')), _react().default.createElement(_antd().Select.Option, {
101
- value: 60000
102
- }, localT('Minutes')), _react().default.createElement(_antd().Select.Option, {
103
- value: 1000
104
- }, localT('Seconds')))) : null);
102
+ })),
103
+ options: [{
104
+ value: 86400000,
105
+ label: (0, _locale.lang)('Days')
106
+ }, {
107
+ value: 3600000,
108
+ label: (0, _locale.lang)('Hours')
109
+ }, {
110
+ value: 60000,
111
+ label: (0, _locale.lang)('Minutes')
112
+ }, {
113
+ value: 1000,
114
+ label: (0, _locale.lang)('Seconds')
115
+ }]
116
+ })) : null);
105
117
  }
@@ -228,14 +228,14 @@ const ScheduleConfig = () => {
228
228
  'x-component': 'fieldset',
229
229
  'x-component-props': {
230
230
  className: (0, _client().css)`
231
- .ant-input-number {
232
- width: 4em;
233
- }
231
+ .ant-input-number {
232
+ width: 4em;
233
+ }
234
234
 
235
- .ant-picker {
236
- width: auto;
237
- }
238
- `
235
+ .ant-picker {
236
+ width: auto;
237
+ }
238
+ `
239
239
  },
240
240
  properties: ModeFieldsets[mode]
241
241
  }
@@ -15,7 +15,6 @@ declare const _default: {
15
15
  };
16
16
  components: {
17
17
  ScheduleConfig: () => import("react").JSX.Element;
18
- FieldsSelect: import("react").MemoExoticComponent<import("@formily/reactive-react").ReactFC<Omit<any, "ref">>>;
19
18
  };
20
19
  useVariables(config: any, opts: any): any[];
21
20
  useInitializers(config: any): SchemaInitializerItemOptions | null;
@@ -16,12 +16,17 @@ var _constants = require("./constants");
16
16
  var _locale = require("../../locale");
17
17
  var _CollectionBlockInitializer = require("../../components/CollectionBlockInitializer");
18
18
  var _variable = require("../../variable");
19
- var _FieldsSelect = require("../../components/FieldsSelect");
20
19
  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; }
21
20
  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; }
22
21
  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; }
23
22
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
24
23
  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); }
24
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
25
+ 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."); }
26
+ 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); }
27
+ 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; }
28
+ 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; } }
29
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
30
  var _default = {
26
31
  title: `{{t("Schedule event", { ns: "${_locale.NAMESPACE}" })}}`,
27
32
  type: 'schedule',
@@ -36,14 +41,14 @@ var _default = {
36
41
  useCollectionDataSource: _client().useCollectionDataSource
37
42
  },
38
43
  components: {
39
- ScheduleConfig: _ScheduleConfig.ScheduleConfig,
40
- FieldsSelect: _FieldsSelect.FieldsSelect
44
+ ScheduleConfig: _ScheduleConfig.ScheduleConfig
41
45
  },
42
46
  useVariables(config, opts) {
43
- var _config$appends;
44
47
  const compile = (0, _client().useCompile)();
45
48
  const _useCollectionManager = (0, _client().useCollectionManager)(),
46
49
  getCollectionFields = _useCollectionManager.getCollectionFields;
50
+ const _opts$fieldNames = opts.fieldNames,
51
+ fieldNames = _opts$fieldNames === void 0 ? _variable.defaultFieldNames : _opts$fieldNames;
47
52
  const options = [];
48
53
  if (!(opts !== null && opts !== void 0 && opts.types) || opts.types.includes('date')) {
49
54
  options.push({
@@ -52,22 +57,29 @@ var _default = {
52
57
  label: (0, _locale.lang)('Trigger time')
53
58
  });
54
59
  }
55
- const depth = (_config$appends = config.appends) !== null && _config$appends !== void 0 && _config$appends.length ? config.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1) + 1 : 1;
56
- const fieldOptions = (0, _variable.getCollectionFieldOptions)(_objectSpread(_objectSpread({
57
- depth
58
- }, opts), {}, {
59
- collection: config.collection,
60
- compile,
61
- getCollectionFields
62
- }));
60
+ // const depth = config.appends?.length
61
+ // ? config.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1) + 1
62
+ // : 1;
63
63
  if (config.mode === _constants.SCHEDULE_MODE.COLLECTION_FIELD) {
64
- if (fieldOptions.length) {
65
- options.push({
66
- key: 'data',
67
- value: 'data',
68
- label: (0, _locale.lang)('Trigger data'),
69
- children: fieldOptions
70
- });
64
+ var _config$appends;
65
+ const _getCollectionFieldOp = (0, _variable.getCollectionFieldOptions)(_objectSpread(_objectSpread({}, opts), {}, {
66
+ fields: [{
67
+ collectionName: config.collection,
68
+ name: 'data',
69
+ type: 'hasOne',
70
+ target: config.collection,
71
+ uiSchema: {
72
+ title: (0, _locale.lang)('Trigger data')
73
+ }
74
+ }],
75
+ appends: ['data', ...(((_config$appends = config.appends) === null || _config$appends === void 0 ? void 0 : _config$appends.map(item => `data.${item}`)) || [])],
76
+ compile,
77
+ getCollectionFields
78
+ })),
79
+ _getCollectionFieldOp2 = _slicedToArray(_getCollectionFieldOp, 1),
80
+ fieldOption = _getCollectionFieldOp2[0];
81
+ if (fieldOption) {
82
+ options.push(fieldOption);
71
83
  }
72
84
  }
73
85
  return options;
@@ -1,34 +1,52 @@
1
1
  export type VariableOption = {
2
2
  key?: string;
3
- value: string;
4
- label: string;
3
+ value?: string;
4
+ label?: string;
5
5
  children?: VariableOptions;
6
+ [key: string]: any;
6
7
  };
7
8
  export type VariableOptions = VariableOption[] | null;
9
+ export type VariableDataType = string | {
10
+ type: string;
11
+ options?: {
12
+ entity?: boolean;
13
+ collection?: string;
14
+ };
15
+ } | ((field: any, appends?: string[]) => boolean);
16
+ export type OptionsOfUseVariableOptions = {
17
+ types?: VariableDataType[];
18
+ fieldNames?: {
19
+ label?: string;
20
+ value?: string;
21
+ children?: string;
22
+ };
23
+ };
24
+ export declare const defaultFieldNames: {
25
+ readonly label: "label";
26
+ readonly value: "value";
27
+ readonly children: "children";
28
+ };
8
29
  export declare const nodesOptions: {
9
30
  label: string;
10
31
  value: string;
11
- useOptions(options: any): VariableOption[];
32
+ useOptions(options: OptionsOfUseVariableOptions): VariableOption[];
12
33
  };
13
34
  export declare const triggerOptions: {
14
35
  label: string;
15
36
  value: string;
16
- useOptions(options: any): VariableOption[];
37
+ useOptions(options: OptionsOfUseVariableOptions): any;
17
38
  };
18
39
  export declare const scopeOptions: {
19
40
  label: string;
20
41
  value: string;
21
- useOptions(options: any): VariableOption[];
42
+ useOptions(options: OptionsOfUseVariableOptions): VariableOption[];
22
43
  };
23
44
  export declare const systemOptions: {
24
45
  label: string;
25
46
  value: string;
26
- useOptions({ types }: {
27
- types: any;
28
- }): {
47
+ useOptions({ types, fieldNames }: OptionsOfUseVariableOptions): {
48
+ [x: string]: string;
29
49
  key: string;
30
- value: string;
31
- label: string;
32
50
  }[];
33
51
  };
34
52
  export declare const BaseTypeSets: {
@@ -37,7 +55,7 @@ export declare const BaseTypeSets: {
37
55
  string: Set<string>;
38
56
  date: Set<string>;
39
57
  };
40
- export declare function useWorkflowVariableOptions(options?: {}): {
58
+ export declare function useWorkflowVariableOptions(options?: OptionsOfUseVariableOptions): {
41
59
  label: any;
42
60
  value: any;
43
61
  key: any;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BaseTypeSets = void 0;
6
+ exports.defaultFieldNames = exports.BaseTypeSets = void 0;
7
7
  exports.getCollectionFieldOptions = getCollectionFieldOptions;
8
8
  exports.triggerOptions = exports.systemOptions = exports.scopeOptions = exports.nodesOptions = void 0;
9
9
  exports.useWorkflowVariableOptions = useWorkflowVariableOptions;
@@ -25,6 +25,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
25
25
  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; }
26
26
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
27
27
  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); }
28
+ const defaultFieldNames = {
29
+ label: 'label',
30
+ value: 'value',
31
+ children: 'children'
32
+ };
33
+ exports.defaultFieldNames = defaultFieldNames;
28
34
  const nodesOptions = {
29
35
  label: `{{t("Node result", { ns: "${_locale.NAMESPACE}" })}}`,
30
36
  value: '$jobsMapByNodeId',
@@ -60,6 +66,8 @@ const scopeOptions = {
60
66
  label: `{{t("Scope variables", { ns: "${_locale.NAMESPACE}" })}}`,
61
67
  value: '$scopes',
62
68
  useOptions(options) {
69
+ const _options$fieldNames = options.fieldNames,
70
+ fieldNames = _options$fieldNames === void 0 ? defaultFieldNames : _options$fieldNames;
63
71
  const current = (0, _nodes.useNodeContext)();
64
72
  const scopes = (0, _nodes.useUpstreamScopes)(current);
65
73
  const result = [];
@@ -71,9 +79,9 @@ const scopeOptions = {
71
79
  var _node$title;
72
80
  result.push({
73
81
  key: node.id.toString(),
74
- value: node.id.toString(),
75
- label: (_node$title = node.title) !== null && _node$title !== void 0 ? _node$title : `#${node.id}`,
76
- children: subOptions
82
+ [fieldNames.value]: node.id.toString(),
83
+ [fieldNames.label]: (_node$title = node.title) !== null && _node$title !== void 0 ? _node$title : `#${node.id}`,
84
+ [fieldNames.children]: subOptions
77
85
  });
78
86
  }
79
87
  });
@@ -85,12 +93,13 @@ const systemOptions = {
85
93
  label: `{{t("System variables", { ns: "${_locale.NAMESPACE}" })}}`,
86
94
  value: '$system',
87
95
  useOptions({
88
- types
96
+ types,
97
+ fieldNames = defaultFieldNames
89
98
  }) {
90
99
  return [...(!types || types.includes('date') ? [{
91
100
  key: 'now',
92
- value: 'now',
93
- label: (0, _locale.lang)('System time')
101
+ [fieldNames.label]: (0, _locale.lang)('System time'),
102
+ [fieldNames.value]: 'now'
94
103
  }] : [])];
95
104
  }
96
105
  };
@@ -167,15 +176,20 @@ function filterTypedFields({
167
176
  });
168
177
  }
169
178
  function useWorkflowVariableOptions(options = {}) {
179
+ var _options$fieldNames2;
180
+ const fieldNames = Object.assign({}, defaultFieldNames, (_options$fieldNames2 = options.fieldNames) !== null && _options$fieldNames2 !== void 0 ? _options$fieldNames2 : {});
181
+ const opts = Object.assign(options, {
182
+ fieldNames
183
+ });
170
184
  const compile = (0, _client().useCompile)();
171
185
  const result = [scopeOptions, nodesOptions, triggerOptions, systemOptions].map(item => {
172
- const opts = item.useOptions(options).filter(Boolean);
186
+ const children = item.useOptions(opts).filter(Boolean);
173
187
  return {
174
- label: compile(item.label),
175
- value: item.value,
176
- key: item.value,
177
- children: opts,
178
- disabled: opts && !opts.length
188
+ [fieldNames.label]: compile(item.label),
189
+ [fieldNames.value]: item.value,
190
+ key: item[fieldNames.value],
191
+ [fieldNames.children]: children,
192
+ disabled: children && !children.length
179
193
  };
180
194
  });
181
195
  return result;
@@ -236,20 +250,17 @@ function loadChildren(_x) {
236
250
  }
237
251
  function _loadChildren() {
238
252
  _loadChildren = _asyncToGenerator(function* (option) {
239
- const result = getCollectionFieldOptions({
253
+ const result = getCollectionFieldOptions(_objectSpread({
240
254
  collection: option.field.target,
241
255
  types: option.types,
242
- appends: getNextAppends(option.field, option.appends),
243
- sourceKey: option.field.key,
244
- compile: this.compile,
245
- getCollectionFields: this.getCollectionFields
246
- });
256
+ appends: getNextAppends(option.field, option.appends)
257
+ }, this));
258
+ option.loadChildren = null;
247
259
  if (result.length) {
248
260
  option.children = result;
249
261
  } else {
250
262
  var _option$types;
251
263
  option.isLeaf = true;
252
- option.loadChildren = null;
253
264
  const matchingType = (_option$types = option.types) === null || _option$types === void 0 ? void 0 : _option$types.some(type => matchFieldType(option.field, type, 0));
254
265
  if (!matchingType) {
255
266
  option.disabled = true;
@@ -265,7 +276,9 @@ function getCollectionFieldOptions(options) {
265
276
  _options$appends = options.appends,
266
277
  appends = _options$appends === void 0 ? [] : _options$appends,
267
278
  compile = options.compile,
268
- getCollectionFields = options.getCollectionFields;
279
+ getCollectionFields = options.getCollectionFields,
280
+ _options$fieldNames3 = options.fieldNames,
281
+ fieldNames = _options$fieldNames3 === void 0 ? defaultFieldNames : _options$fieldNames3;
269
282
  const normalizedFields = getNormalizedFields(collection, {
270
283
  compile,
271
284
  getCollectionFields
@@ -273,7 +286,8 @@ function getCollectionFieldOptions(options) {
273
286
  const computedFields = fields !== null && fields !== void 0 ? fields : normalizedFields;
274
287
  const boundLoadChildren = loadChildren.bind({
275
288
  compile,
276
- getCollectionFields
289
+ getCollectionFields,
290
+ fieldNames
277
291
  });
278
292
  const result = filterTypedFields({
279
293
  fields: computedFields,
@@ -285,13 +299,14 @@ function getCollectionFieldOptions(options) {
285
299
  }).map(field => {
286
300
  var _field$uiSchema5;
287
301
  const label = compile(((_field$uiSchema5 = field.uiSchema) === null || _field$uiSchema5 === void 0 ? void 0 : _field$uiSchema5.title) || field.name);
302
+ // console.log('===', label, field);
288
303
  const nextAppends = getNextAppends(field, appends);
289
304
  // TODO: no matching fields in next appends should consider isLeaf as true
290
305
  const isLeaf = !isAssociationField(field) || !nextAppends.length && !appends.includes(field.name);
291
306
  return {
292
- label,
307
+ [fieldNames.label]: label,
293
308
  key: field.name,
294
- value: field.name,
309
+ [fieldNames.value]: field.name,
295
310
  isLeaf,
296
311
  loadChildren: isLeaf ? null : boundLoadChildren,
297
312
  field,
@@ -19,9 +19,7 @@ export default class WorkflowPlugin extends Plugin {
19
19
  onBeforeSave: (instance: WorkflowModel, options: any) => Promise<void>;
20
20
  load(): Promise<void>;
21
21
  toggle(workflow: WorkflowModel, enable?: boolean): void;
22
- trigger(workflow: WorkflowModel, context: {
23
- [key: string]: any;
24
- }, options?: {
22
+ trigger(workflow: WorkflowModel, context: object, options?: {
25
23
  context?: any;
26
24
  }): void;
27
25
  private prepare;
@@ -133,7 +133,8 @@ class WorkflowPlugin extends _server().Plugin {
133
133
  }();
134
134
  this.prepare = /*#__PURE__*/_asyncToGenerator(function* () {
135
135
  var _options$context;
136
- const event = _this.events.shift();
136
+ const _this$events = _slicedToArray(_this.events, 1),
137
+ event = _this$events[0];
137
138
  if (!event) {
138
139
  return;
139
140
  }
@@ -189,6 +190,7 @@ class WorkflowPlugin extends _server().Plugin {
189
190
  _this.pending.push([execution]);
190
191
  }
191
192
  }
193
+ _this.events.shift();
192
194
  if (_this.events.length) {
193
195
  yield _this.prepare();
194
196
  } else {
@@ -330,6 +332,7 @@ class WorkflowPlugin extends _server().Plugin {
330
332
  // resuming has high priority
331
333
  if (_this4.pending.length) {
332
334
  next = _this4.pending.shift();
335
+ _this4.getLogger(next[0].workflowId).info(`pending execution (${next[0].id}) ready to process`);
333
336
  } else {
334
337
  const execution = yield _this4.db.getRepository('executions').findOne({
335
338
  filter: {
@@ -339,13 +342,16 @@ class WorkflowPlugin extends _server().Plugin {
339
342
  sort: 'createdAt'
340
343
  });
341
344
  if (execution && execution.workflow.enabled) {
345
+ _this4.getLogger(execution.workflowId).info(`execution (${execution.id}) fetched from db`);
342
346
  next = [execution];
343
347
  }
344
348
  }
345
349
  if (next) {
346
- _this4.process(...next);
347
- } else {
348
- _this4.executing = false;
350
+ yield _this4.process(...next);
351
+ }
352
+ _this4.executing = false;
353
+ if (next) {
354
+ _this4.dispatch();
349
355
  }
350
356
  })();
351
357
  }
@@ -365,8 +371,6 @@ class WorkflowPlugin extends _server().Plugin {
365
371
  } catch (err) {
366
372
  _this5.getLogger(execution.workflowId).error(`execution (${execution.id}) error: ${err.message}`, err);
367
373
  }
368
- _this5.executing = false;
369
- _this5.dispatch();
370
374
  })();
371
375
  }
372
376
  createProcessor(execution, options = {}) {
@@ -47,5 +47,5 @@ export default class Processor {
47
47
  $system: {};
48
48
  $scopes: {};
49
49
  };
50
- getParsedValue(value: any, node?: any): any;
50
+ getParsedValue(value: any, node?: any, additionalScope?: object): any;
51
51
  }
@@ -371,9 +371,9 @@ class Processor {
371
371
  $scopes
372
372
  };
373
373
  }
374
- getParsedValue(value, node) {
374
+ getParsedValue(value, node, additionalScope) {
375
375
  const template = (0, _utils().parse)(value);
376
- const scope = this.getScope(node);
376
+ const scope = Object.assign(this.getScope(node), additionalScope);
377
377
  template.parameters.forEach(({
378
378
  key
379
379
  }) => {
@@ -1,7 +1,7 @@
1
1
  import type { FlowNodeModel } from '../types';
2
2
  declare const _default: {
3
3
  run(node: FlowNodeModel, input: any, processor: any): Promise<{
4
- result: any;
4
+ result: object;
5
5
  status: number;
6
6
  }>;
7
7
  };
@@ -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
  const _excluded = ["appends"];
9
10
  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; }
10
11
  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; }
@@ -29,29 +30,28 @@ var _default = {
29
30
  repository = _node$constructor$dat.repository,
30
31
  model = _node$constructor$dat.model;
31
32
  const options = processor.getParsedValue(params, node);
32
- const result = yield repository.create(_objectSpread(_objectSpread({}, options), {}, {
33
+ const created = yield repository.create(_objectSpread(_objectSpread({}, options), {}, {
33
34
  context: {
34
35
  executionId: processor.execution.id
35
36
  },
36
37
  transaction: processor.transaction
37
38
  }));
38
- if (result && appends.length) {
39
- const includeFields = appends.filter(field => !result.get(field) || !result[field]);
40
- const included = yield model.findByPk(result[model.primaryKeyAttribute], {
41
- attributes: [model.primaryKeyAttribute],
42
- include: includeFields,
39
+ let result = created;
40
+ if (created && appends.length) {
41
+ const includeFields = appends.reduce((set, field) => {
42
+ set.add(field.split('.')[0]);
43
+ set.add(field);
44
+ return set;
45
+ }, new Set());
46
+ result = yield repository.findOne({
47
+ filterByTk: created[model.primaryKeyAttribute],
48
+ appends: Array.from(includeFields),
43
49
  transaction: processor.transaction
44
50
  });
45
- includeFields.forEach(field => {
46
- const value = included.get(field);
47
- result.set(field, Array.isArray(value) ? value.map(item => item.toJSON()) : value.toJSON(), {
48
- raw: true
49
- });
50
- });
51
51
  }
52
52
  return {
53
53
  // NOTE: get() for non-proxied instance (#380)
54
- result: result === null || result === void 0 ? void 0 : result.toJSON(),
54
+ result: (0, _utils.toJSON)(result),
55
55
  status: _constants.JOB_STATUS.RESOLVED
56
56
  };
57
57
  })();
@@ -32,7 +32,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
32
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); }
33
33
  function _default(plugin, more = {}) {
34
34
  const instructions = plugin.instructions;
35
- const natives = ['calculation', 'condition', 'parallel', 'loop', 'delay', 'manual', 'query', 'create', 'update', 'destroy', 'aggregate', 'request'].reduce((result, key) => Object.assign(result, {
35
+ const natives = ['calculation', 'condition', 'parallel', 'loop', 'delay', 'manual', 'query', 'create', 'update', 'destroy', 'aggregate', 'request', 'sql'].reduce((result, key) => Object.assign(result, {
36
36
  [key]: (0, _utils().requireModule)(_path().default.isAbsolute(key) ? key : _path().default.join(__dirname, key))
37
37
  }), {});
38
38
  for (var _i = 0, _Object$entries = Object.entries(_objectSpread(_objectSpread({}, more), natives)); _i < _Object$entries.length; _i++) {