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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _lodash() {
8
+ const data = require("lodash");
9
+ _lodash = function _lodash() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _server() {
15
+ const data = require("@nocobase/server");
16
+ _server = function _server() {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _utils() {
22
+ const data = require("@nocobase/utils");
23
+ _utils = function _utils() {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ const _excluded = ["forms", "schema", "actions"];
29
+ 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; }
30
+ 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; }
31
+ 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; }
32
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
33
+ 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); }
34
+ 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; }
35
+ 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; }
36
+ 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
+ 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); }); }; }
38
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
39
+ 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."); }
40
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
41
+ 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; }
42
+ 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; } }
43
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
44
+ function findSchema(root, filter, onlyLeaf = false) {
45
+ const result = [];
46
+ if (!root) {
47
+ return result;
48
+ }
49
+ if (filter(root) && (!onlyLeaf || !root.properties)) {
50
+ result.push(root);
51
+ return result;
52
+ }
53
+ if (root.properties) {
54
+ Object.keys(root.properties).forEach(key => {
55
+ result.push(...findSchema(root.properties[key], filter));
56
+ });
57
+ }
58
+ return result;
59
+ }
60
+ function findParent(root, node) {
61
+ return findSchema(root, item => item.properties && Object.values(item.properties).includes(node))[0];
62
+ }
63
+ // 1. all form blocks combine into one, at first form block position
64
+ // 2. add fields move to the form
65
+ // 3. remove all other form blocks except first (should remove ancestors till grid)
66
+ // 4. add 'x-interface-options' property to all fields as collection field
67
+ // 5. make collection fields decorator as `FormCollectionProvider` for form block
68
+ // 6. add form component wrapper for form grid
69
+ // 7. move action footer to form block
70
+ function migrateConfig({
71
+ schema = {},
72
+ actions = []
73
+ }) {
74
+ const blocks = schema.blocks,
75
+ collection = schema.collection;
76
+ if (!blocks) {
77
+ return {
78
+ forms: {}
79
+ };
80
+ }
81
+ const root = {
82
+ properties: blocks
83
+ };
84
+ const formBlocks = findSchema(root, item => {
85
+ return item['x-component'] === 'CardItem' && item['x-designer'] === 'SimpleDesigner' && item.properties.grid['x-initializer'] === 'AddFormField';
86
+ });
87
+ if (!formBlocks.length) {
88
+ return {
89
+ schema: blocks,
90
+ forms: {}
91
+ };
92
+ }
93
+ // 1.
94
+ formBlocks.forEach((formBlock, i) => {
95
+ const formItems = findSchema(formBlock, item => {
96
+ return item['x-component'] === 'CollectionField' && item['x-decorator'] === 'FormItem';
97
+ }, true);
98
+ // 4.
99
+ formItems.forEach(item => {
100
+ Object.assign(item, {
101
+ 'x-interface-options': collection.fields.find(field => field.name === item.name)
102
+ });
103
+ });
104
+ // skip first form block
105
+ if (!i) {
106
+ return;
107
+ }
108
+ // 2.
109
+ Object.assign(formBlocks[0].properties.grid.properties, formBlock.properties.grid.properties);
110
+ // 3.
111
+ const col = findParent(root, formBlock);
112
+ const row = findParent(root, col);
113
+ delete row.properties[col.name];
114
+ if (!Object.keys(row.properties).length) {
115
+ const grid = findParent(root, row);
116
+ delete grid.properties[row.name];
117
+ }
118
+ });
119
+ // 5.
120
+ const _formBlocks = _slicedToArray(formBlocks, 1),
121
+ formBlock = _formBlocks[0];
122
+ Object.assign(formBlock, {
123
+ 'x-decorator': 'FormCollectionProvider',
124
+ 'x-decorator-props': {
125
+ collection
126
+ },
127
+ 'x-component-props': {
128
+ title: '{{t("Form")}}'
129
+ },
130
+ 'x-designer-props': {
131
+ type: 'customForm'
132
+ }
133
+ });
134
+ const formId = (0, _utils().uid)();
135
+ // 6.
136
+ const newFormBlock = {
137
+ [formId]: {
138
+ type: 'void',
139
+ 'x-component': 'FormV2',
140
+ 'x-component-props': {
141
+ useProps: '{{ useFormBlockProps }}'
142
+ },
143
+ properties: {
144
+ grid: Object.assign(formBlock.properties.grid, {
145
+ 'x-initializer': 'AddCustomFormField'
146
+ }),
147
+ // 7.
148
+ actions: {
149
+ type: 'void',
150
+ 'x-decorator': 'ActionBarProvider',
151
+ 'x-component': 'ActionBar',
152
+ 'x-component-props': {
153
+ layout: 'one-column',
154
+ style: {
155
+ marginTop: '1.5em'
156
+ }
157
+ },
158
+ 'x-initializer': 'AddActionButton',
159
+ properties: schema.actions
160
+ }
161
+ }
162
+ }
163
+ };
164
+ delete formBlock.properties.grid;
165
+ Object.assign(formBlock.properties, newFormBlock);
166
+ return {
167
+ schema: blocks,
168
+ forms: {
169
+ [formId]: {
170
+ type: 'custom',
171
+ title: '{{t("Form")}}',
172
+ actions,
173
+ collection
174
+ }
175
+ }
176
+ };
177
+ }
178
+ function migrateUsedConfig(config, manualForms) {
179
+ Object.keys(config).forEach(key => {
180
+ const valueType = typeof config[key];
181
+ if (valueType === 'string') {
182
+ config[key] = config[key].replace(/{{\s*\$jobsMapByNodeId\.(\d+)(\.[^}]+)?\s*}}/g, (matched, id, path) => {
183
+ if (!manualForms[id]) {
184
+ return matched;
185
+ }
186
+ return `{{$jobsMapByNodeId.${id}.${manualForms[id]}${path || ''}}}`;
187
+ });
188
+ } else if (valueType === 'object') {
189
+ migrateUsedConfig(config[key], manualForms);
190
+ }
191
+ });
192
+ return config;
193
+ }
194
+ class _default extends _server().Migration {
195
+ up() {
196
+ var _this = this;
197
+ return _asyncToGenerator(function* () {
198
+ const match = yield _this.app.version.satisfies('<0.9.1-alpha.3');
199
+ if (!match) {
200
+ return;
201
+ }
202
+ const db = _this.context.db;
203
+ const NodeRepo = db.getRepository('flow_nodes');
204
+ const UserJobRepo = db.getRepository('users_jobs');
205
+ yield db.sequelize.transaction( /*#__PURE__*/function () {
206
+ var _ref = _asyncToGenerator(function* (transaction) {
207
+ const nodes = yield NodeRepo.find({
208
+ filter: {
209
+ type: 'manual'
210
+ },
211
+ transaction
212
+ });
213
+ console.log('%d nodes need to be migrated.', nodes.length);
214
+ yield nodes.reduce((promise, node) => promise.then(() => {
215
+ const _node$config = node.config,
216
+ forms = _node$config.forms,
217
+ schema = _node$config.schema,
218
+ actions = _node$config.actions,
219
+ config = _objectWithoutProperties(_node$config, _excluded);
220
+ if (forms) {
221
+ return;
222
+ }
223
+ return node.update({
224
+ config: _objectSpread(_objectSpread({}, config), migrateConfig({
225
+ schema,
226
+ actions
227
+ }))
228
+ }, {
229
+ silent: true,
230
+ transaction
231
+ });
232
+ }), Promise.resolve());
233
+ const usersJobs = yield UserJobRepo.find({
234
+ filter: {
235
+ nodeId: nodes.map(item => item.id)
236
+ },
237
+ appends: ['job', 'node'],
238
+ transaction
239
+ });
240
+ // update all results
241
+ yield usersJobs.reduce((promise, userJob) => promise.then( /*#__PURE__*/_asyncToGenerator(function* () {
242
+ const result = userJob.result,
243
+ job = userJob.job,
244
+ node = userJob.node;
245
+ const forms = node.config.forms;
246
+ const _Object$keys = Object.keys(forms),
247
+ _Object$keys2 = _slicedToArray(_Object$keys, 1),
248
+ formId = _Object$keys2[0];
249
+ if (result) {
250
+ yield userJob.update({
251
+ result: {
252
+ [formId]: result
253
+ }
254
+ }, {
255
+ silent: true,
256
+ transaction
257
+ });
258
+ }
259
+ if (job.result) {
260
+ yield job.update({
261
+ result: {
262
+ [formId]: result
263
+ }
264
+ }, {
265
+ silent: true,
266
+ transaction
267
+ });
268
+ }
269
+ })), Promise.resolve());
270
+ const usedNodes = yield NodeRepo.find({
271
+ filter: {
272
+ type: {
273
+ $notIn: ['delay', 'parallel']
274
+ }
275
+ },
276
+ transaction
277
+ });
278
+ const nodeForms = {};
279
+ nodes.forEach(node => {
280
+ const _Object$keys3 = Object.keys(node.config.forms),
281
+ _Object$keys4 = _slicedToArray(_Object$keys3, 1),
282
+ form = _Object$keys4[0];
283
+ if (form) {
284
+ nodeForms[node.id] = form;
285
+ }
286
+ });
287
+ yield usedNodes.reduce((promise, node) => promise.then( /*#__PURE__*/_asyncToGenerator(function* () {
288
+ yield node.update({
289
+ config: migrateUsedConfig((0, _lodash().cloneDeep)(node.config), nodeForms)
290
+ }, {
291
+ silent: true,
292
+ transaction
293
+ });
294
+ })), Promise.resolve());
295
+ });
296
+ return function (_x2) {
297
+ return _ref.apply(this, arguments);
298
+ };
299
+ }());
300
+ })();
301
+ }
302
+ }
303
+ exports.default = _default;
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _database() {
9
8
  const data = require("@nocobase/database");
10
-
11
9
  _database = function _database() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  class ExecutionModel extends _database().Model {}
19
-
20
15
  exports.default = ExecutionModel;
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _database() {
9
8
  const data = require("@nocobase/database");
10
-
11
9
  _database = function _database() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  class FlowNodeModel extends _database().Model {}
19
-
20
15
  exports.default = FlowNodeModel;
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _database() {
9
8
  const data = require("@nocobase/database");
10
-
11
9
  _database = function _database() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  class JobModel extends _database().Model {}
19
-
20
15
  exports.default = JobModel;
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _database() {
9
8
  const data = require("@nocobase/database");
10
-
11
9
  _database = function _database() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  class WorkflowModel extends _database().Model {}
19
-
20
15
  exports.default = WorkflowModel;
@@ -4,27 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _ = require("..");
9
-
10
8
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
-
12
9
  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."); }
13
-
14
- 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; }
15
-
10
+ 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; } }
16
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
-
18
12
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
19
-
20
13
  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); }
21
-
22
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
23
-
24
15
  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); } }
25
-
26
16
  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); }); }; }
27
-
28
17
  const MODE_BITMAP = {
29
18
  CREATE: 1,
30
19
  UPDATE: 2,
@@ -34,48 +23,42 @@ const MODE_BITMAP_EVENTS = new Map();
34
23
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreateWithAssociations');
35
24
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdateWithAssociations');
36
25
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
37
-
38
26
  function getHookId(workflow, type) {
39
27
  return `${type}#${workflow.id}`;
40
28
  }
41
-
42
29
  function getFieldRawName(collection, name) {
43
30
  const field = collection.getField(name);
44
-
45
31
  if (field && field.type === 'belongsTo') {
46
32
  return field.foreignKey;
47
33
  }
48
-
49
34
  return name;
50
- } // async function, should return promise
51
-
52
-
35
+ }
36
+ // async function, should return promise
53
37
  function handler(_x, _x2, _x3) {
54
38
  return _handler.apply(this, arguments);
55
39
  }
56
-
57
40
  function _handler() {
58
41
  _handler = _asyncToGenerator(function* (workflow, data, options) {
59
42
  var _condition$$and;
60
-
61
43
  const _workflow$config3 = workflow.config,
62
- collectionName = _workflow$config3.collection,
63
- condition = _workflow$config3.condition,
64
- changed = _workflow$config3.changed;
44
+ collectionName = _workflow$config3.collection,
45
+ condition = _workflow$config3.condition,
46
+ changed = _workflow$config3.changed,
47
+ mode = _workflow$config3.mode,
48
+ appends = _workflow$config3.appends;
65
49
  const collection = data.constructor.database.getCollection(collectionName);
66
50
  const transaction = options.transaction,
67
- context = options.context; // NOTE: if no configured fields changed, do not trigger
68
-
51
+ context = options.context;
52
+ const repository = collection.repository,
53
+ model = collection.model;
54
+ // NOTE: if no configured fields changed, do not trigger
69
55
  if (changed && changed.length && changed.filter(name => !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(collection.getField(name).type)).every(name => !data.changedWithAssociations(getFieldRawName(collection, name)))) {
70
56
  return;
71
- } // NOTE: if no configured condition match, do not trigger
72
-
73
-
57
+ }
58
+ // NOTE: if no configured condition match, do not trigger
74
59
  if (condition && ((_condition$$and = condition.$and) === null || _condition$$and === void 0 ? void 0 : _condition$$and.length)) {
75
60
  // TODO: change to map filter format to calculation format
76
61
  // const calculation = toCalculation(condition);
77
- const repository = collection.repository,
78
- model = collection.model;
79
62
  const count = yield repository.count({
80
63
  filter: {
81
64
  $and: [condition, {
@@ -85,50 +68,55 @@ function _handler() {
85
68
  context,
86
69
  transaction
87
70
  });
88
-
89
71
  if (!count) {
90
72
  return;
91
73
  }
92
74
  }
93
-
75
+ if ((appends === null || appends === void 0 ? 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,
80
+ transaction
81
+ });
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
+ }
94
89
  this.plugin.trigger(workflow, {
95
- data: data.get()
90
+ data: data.toJSON()
96
91
  }, {
97
92
  context
98
93
  });
99
94
  });
100
95
  return _handler.apply(this, arguments);
101
96
  }
102
-
103
97
  class CollectionTrigger extends _.Trigger {
104
98
  constructor(...args) {
105
99
  super(...args);
106
100
  this.events = new Map();
107
101
  }
108
-
109
102
  on(workflow) {
110
103
  const db = this.plugin.app.db;
111
104
  const _workflow$config = workflow.config,
112
- collection = _workflow$config.collection,
113
- mode = _workflow$config.mode;
105
+ collection = _workflow$config.collection,
106
+ mode = _workflow$config.mode;
114
107
  const Collection = db.getCollection(collection);
115
-
116
108
  if (!Collection) {
117
109
  return;
118
110
  }
119
-
120
111
  var _iterator = _createForOfIteratorHelper(MODE_BITMAP_EVENTS.entries()),
121
- _step;
122
-
112
+ _step;
123
113
  try {
124
114
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
125
115
  let _step$value = _slicedToArray(_step.value, 2),
126
- key = _step$value[0],
127
- type = _step$value[1];
128
-
116
+ key = _step$value[0],
117
+ type = _step$value[1];
129
118
  const event = `${collection}.${type}`;
130
119
  const name = getHookId(workflow, event);
131
-
132
120
  if (mode & key) {
133
121
  if (!this.events.has(name)) {
134
122
  const listener = handler.bind(this, workflow);
@@ -137,7 +125,6 @@ class CollectionTrigger extends _.Trigger {
137
125
  }
138
126
  } else {
139
127
  const listener = this.events.get(name);
140
-
141
128
  if (listener) {
142
129
  db.off(event, listener);
143
130
  this.events.delete(name);
@@ -150,33 +137,26 @@ class CollectionTrigger extends _.Trigger {
150
137
  _iterator.f();
151
138
  }
152
139
  }
153
-
154
140
  off(workflow) {
155
141
  const db = this.plugin.app.db;
156
142
  const _workflow$config2 = workflow.config,
157
- collection = _workflow$config2.collection,
158
- mode = _workflow$config2.mode;
143
+ collection = _workflow$config2.collection,
144
+ mode = _workflow$config2.mode;
159
145
  const Collection = db.getCollection(collection);
160
-
161
146
  if (!Collection) {
162
147
  return;
163
148
  }
164
-
165
149
  var _iterator2 = _createForOfIteratorHelper(MODE_BITMAP_EVENTS.entries()),
166
- _step2;
167
-
150
+ _step2;
168
151
  try {
169
152
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
170
153
  let _step2$value = _slicedToArray(_step2.value, 2),
171
- key = _step2$value[0],
172
- type = _step2$value[1];
173
-
154
+ key = _step2$value[0],
155
+ type = _step2$value[1];
174
156
  const event = `${collection}.${type}`;
175
157
  const name = getHookId(workflow, event);
176
-
177
158
  if (mode & key) {
178
159
  const listener = this.events.get(name);
179
-
180
160
  if (listener) {
181
161
  db.off(event, listener);
182
162
  this.events.delete(name);
@@ -189,7 +169,5 @@ class CollectionTrigger extends _.Trigger {
189
169
  _iterator2.f();
190
170
  }
191
171
  }
192
-
193
172
  }
194
-
195
173
  exports.default = CollectionTrigger;
@@ -5,61 +5,42 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Trigger = void 0;
7
7
  exports.default = _default;
8
-
9
8
  function _path() {
10
9
  const data = _interopRequireDefault(require("path"));
11
-
12
10
  _path = function _path() {
13
11
  return data;
14
12
  };
15
-
16
13
  return data;
17
14
  }
18
-
19
15
  function _utils() {
20
16
  const data = require("@nocobase/utils");
21
-
22
17
  _utils = function _utils() {
23
18
  return data;
24
19
  };
25
-
26
20
  return data;
27
21
  }
28
-
29
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
23
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
32
-
33
24
  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."); }
34
-
35
25
  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); }
36
-
37
26
  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; }
38
-
39
- 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; }
40
-
27
+ 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; } }
41
28
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
42
-
43
29
  class Trigger {
44
30
  constructor(plugin) {
45
31
  this.plugin = void 0;
46
32
  this.plugin = plugin;
47
33
  }
48
-
49
34
  }
50
-
51
35
  exports.Trigger = Trigger;
52
-
53
36
  function _default(plugin, more = {}) {
54
37
  const triggers = plugin.triggers;
55
38
  triggers.register('collection', new ((0, _utils().requireModule)(_path().default.join(__dirname, 'collection')))(plugin));
56
39
  triggers.register('schedule', new ((0, _utils().requireModule)(_path().default.join(__dirname, 'schedule')))(plugin));
57
-
58
40
  for (var _i = 0, _Object$entries = Object.entries(more); _i < _Object$entries.length; _i++) {
59
41
  const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
60
- name = _Object$entries$_i[0],
61
- TClass = _Object$entries$_i[1];
62
-
42
+ name = _Object$entries$_i[0],
43
+ TClass = _Object$entries$_i[1];
63
44
  triggers.register(name, new TClass(plugin));
64
45
  }
65
46
  }