@nocobase/plugin-workflow 0.20.0-alpha.9 → 0.21.0-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 (37) hide show
  1. package/dist/client/ExecutionContextProvider.d.ts +7 -0
  2. package/dist/client/components/CollectionBlockInitializer.d.ts +1 -1
  3. package/dist/client/components/DetailsBlockProvider.d.ts +6 -0
  4. package/dist/client/components/SimpleDesigner.d.ts +2 -0
  5. package/dist/client/components/TriggerOptionRender.d.ts +4 -0
  6. package/dist/client/components/ValueBlock.d.ts +1 -0
  7. package/dist/client/components/index.d.ts +2 -0
  8. package/dist/client/hooks/index.d.ts +3 -0
  9. package/dist/client/hooks/useWorkflowExecuted.d.ts +2 -0
  10. package/dist/client/index.d.ts +12 -12
  11. package/dist/client/index.js +40 -40
  12. package/dist/client/nodes/calculation.d.ts +1 -0
  13. package/dist/client/nodes/create.d.ts +2 -5
  14. package/dist/client/nodes/destroy.d.ts +5 -8
  15. package/dist/client/nodes/query.d.ts +5 -8
  16. package/dist/client/nodes/update.d.ts +6 -9
  17. package/dist/client/schemas/collection.d.ts +5 -8
  18. package/dist/client/triggers/collection.d.ts +11 -9
  19. package/dist/client/triggers/schedule/OnField.d.ts +1 -1
  20. package/dist/client/utils.d.ts +2 -1
  21. package/dist/externalVersion.js +11 -10
  22. package/dist/locale/zh-CN.json +3 -3
  23. package/dist/node_modules/cron-parser/package.json +1 -1
  24. package/dist/node_modules/lru-cache/package.json +1 -1
  25. package/dist/server/Plugin.d.ts +3 -1
  26. package/dist/server/Plugin.js +20 -8
  27. package/dist/server/collections/executions.js +1 -1
  28. package/dist/server/instructions/CreateInstruction.js +7 -4
  29. package/dist/server/instructions/DestroyInstruction.js +5 -3
  30. package/dist/server/instructions/QueryInstruction.js +5 -3
  31. package/dist/server/instructions/UpdateInstruction.js +5 -3
  32. package/dist/server/migrations/20230411034722-manual-multi-form.js +3 -5
  33. package/dist/server/migrations/20230612021134-manual-collection-block.js +2 -4
  34. package/dist/server/triggers/CollectionTrigger.js +33 -22
  35. package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.js +18 -10
  36. package/package.json +3 -3
  37. package/dist/client/constant.d.ts +0 -2
@@ -32,6 +32,7 @@ __export(CollectionTrigger_exports, {
32
32
  module.exports = __toCommonJS(CollectionTrigger_exports);
33
33
  var import__ = __toESM(require("."));
34
34
  var import_utils = require("../utils");
35
+ var import_data_source_manager = require("@nocobase/data-source-manager");
35
36
  const MODE_BITMAP = {
36
37
  CREATE: 1,
37
38
  UPDATE: 2,
@@ -46,24 +47,27 @@ function getHookId(workflow, type) {
46
47
  }
47
48
  function getFieldRawName(collection, name) {
48
49
  const field = collection.getField(name);
49
- if (field && field.type === "belongsTo") {
50
- return field.foreignKey;
50
+ if (field && field.options.type === "belongsTo") {
51
+ return field.options.foreignKey;
51
52
  }
52
53
  return name;
53
54
  }
54
55
  async function handler(workflow, data, options) {
55
- var _a;
56
- const { collection: collectionName, condition, changed, mode, appends } = workflow.config;
57
- const collection = data.constructor.database.getCollection(collectionName);
56
+ var _a, _b;
57
+ const { condition, changed, mode, appends } = workflow.config;
58
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(workflow.config.collection);
59
+ const collection = (_a = this.workflow.app.dataSourceManager) == null ? void 0 : _a.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
58
60
  const { transaction, context } = options;
59
- const { repository, model } = collection;
60
- if (changed && changed.length && changed.filter((name) => !["linkTo", "hasOne", "hasMany", "belongsToMany"].includes(collection.getField(name).type)).every((name) => !data.changedWithAssociations(getFieldRawName(collection, name)))) {
61
+ const { repository, filterTargetKey } = collection;
62
+ if (changed && changed.length && changed.filter(
63
+ (name) => !["linkTo", "hasOne", "hasMany", "belongsToMany"].includes(collection.getField(name).options.type)
64
+ ).every((name) => !data.changedWithAssociations(getFieldRawName(collection, name)))) {
61
65
  return;
62
66
  }
63
- if (condition && ((_a = condition.$and) == null ? void 0 : _a.length)) {
67
+ if (condition && ((_b = condition.$and) == null ? void 0 : _b.length)) {
64
68
  const count = await repository.count({
65
69
  filter: {
66
- $and: [condition, { [model.primaryKeyAttribute]: data[model.primaryKeyAttribute] }]
70
+ $and: [condition, { [filterTargetKey]: data[filterTargetKey] }]
67
71
  },
68
72
  context,
69
73
  transaction
@@ -80,7 +84,7 @@ async function handler(workflow, data, options) {
80
84
  return set;
81
85
  }, /* @__PURE__ */ new Set());
82
86
  result = await repository.findOne({
83
- filterByTk: data[model.primaryKeyAttribute],
87
+ filterByTk: data[filterTargetKey],
84
88
  appends: Array.from(includeFields),
85
89
  transaction
86
90
  });
@@ -91,7 +95,7 @@ async function handler(workflow, data, options) {
91
95
  workflow,
92
96
  { data: json, stack: context == null ? void 0 : context.stack },
93
97
  {
94
- transaction
98
+ transaction: this.workflow.useDataSourceTransaction(dataSourceName, transaction)
95
99
  }
96
100
  );
97
101
  } else {
@@ -101,15 +105,19 @@ async function handler(workflow, data, options) {
101
105
  class CollectionTrigger extends import__.default {
102
106
  events = /* @__PURE__ */ new Map();
103
107
  on(workflow) {
104
- const { db } = this.workflow.app;
108
+ var _a, _b;
105
109
  const { collection, mode } = workflow.config;
106
- const Collection2 = db.getCollection(collection);
107
- if (!Collection2) {
110
+ if (!collection) {
111
+ return;
112
+ }
113
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
114
+ const { db } = ((_b = (_a = this.workflow.app.dataSourceManager) == null ? void 0 : _a.dataSources.get(dataSourceName)) == null ? void 0 : _b.collectionManager) ?? {};
115
+ if (!db || !db.getCollection(collectionName)) {
108
116
  return;
109
117
  }
110
118
  for (const [key, type] of MODE_BITMAP_EVENTS.entries()) {
111
- const event = `${collection}.${type}`;
112
- const name = getHookId(workflow, event);
119
+ const event = `${collectionName}.${type}`;
120
+ const name = getHookId(workflow, `${collection}.${type}`);
113
121
  if (mode & key) {
114
122
  if (!this.events.has(name)) {
115
123
  const listener = handler.bind(this, workflow);
@@ -126,19 +134,22 @@ class CollectionTrigger extends import__.default {
126
134
  }
127
135
  }
128
136
  off(workflow) {
129
- const { db } = this.workflow.app;
137
+ var _a;
130
138
  const { collection, mode } = workflow.config;
131
- const Collection2 = db.getCollection(collection);
132
- if (!Collection2) {
139
+ if (!collection) {
140
+ return;
141
+ }
142
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
143
+ const { db } = ((_a = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName)) == null ? void 0 : _a.collectionManager) ?? {};
144
+ if (!db || !db.getCollection(collectionName)) {
133
145
  return;
134
146
  }
135
147
  for (const [key, type] of MODE_BITMAP_EVENTS.entries()) {
136
- const event = `${collection}.${type}`;
137
- const name = getHookId(workflow, event);
148
+ const name = getHookId(workflow, `${collection}.${type}`);
138
149
  if (mode & key) {
139
150
  const listener = this.events.get(name);
140
151
  if (listener) {
141
- db.off(event, listener);
152
+ db.off(`${collectionName}.${type}`, listener);
142
153
  this.events.delete(name);
143
154
  }
144
155
  }
@@ -33,6 +33,7 @@ module.exports = __toCommonJS(DateFieldScheduleTrigger_exports);
33
33
  var import_database = require("@nocobase/database");
34
34
  var import_cron_parser = __toESM(require("cron-parser"));
35
35
  var import_utils = require("./utils");
36
+ var import_data_source_manager = require("@nocobase/data-source-manager");
36
37
  function getOnTimestampWithOffset({ field, offset = 0, unit = 1e3 }, now) {
37
38
  if (!field) {
38
39
  return null;
@@ -257,8 +258,9 @@ class ScheduleTrigger {
257
258
  return nextTime;
258
259
  }
259
260
  schedule(workflow, record, nextTime, toggle = true, options = {}) {
260
- const { model } = this.workflow.app.db.getCollection(workflow.config.collection);
261
- const recordPk = record.get(model.primaryKeyAttribute);
261
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(workflow.config.collection);
262
+ const { filterTargetKey } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
263
+ const recordPk = record.get(filterTargetKey);
262
264
  if (toggle) {
263
265
  const nextInterval = Math.max(0, nextTime - Date.now());
264
266
  const key = `${workflow.id}:${recordPk}@${nextTime}`;
@@ -279,8 +281,9 @@ class ScheduleTrigger {
279
281
  }
280
282
  }
281
283
  async trigger(workflow, record, nextTime, { transaction } = {}) {
282
- const { repository, model } = this.workflow.app.db.getCollection(workflow.config.collection);
283
- const recordPk = record.get(model.primaryKeyAttribute);
284
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(workflow.config.collection);
285
+ const { repository, filterTargetKey } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
286
+ const recordPk = record.get(filterTargetKey);
284
287
  const data = await repository.findOne({
285
288
  filterByTk: recordPk,
286
289
  appends: workflow.config.appends,
@@ -303,7 +306,9 @@ class ScheduleTrigger {
303
306
  on(workflow) {
304
307
  this.inspect([workflow]);
305
308
  const { collection } = workflow.config;
306
- const event = `${collection}.afterSaveWithAssociations`;
309
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
310
+ const event = `${collectionName}.afterSaveWithAssociations`;
311
+ const eventKey = `${collection}.afterSaveWithAssociations`;
307
312
  const name = getHookId(workflow, event);
308
313
  if (this.events.has(name)) {
309
314
  return;
@@ -313,7 +318,7 @@ class ScheduleTrigger {
313
318
  return this.schedule(workflow, data, nextTime, Boolean(nextTime), { transaction });
314
319
  };
315
320
  this.events.set(name, listener);
316
- this.workflow.app.db.on(event, listener);
321
+ this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.db.on(event, listener);
317
322
  }
318
323
  off(workflow) {
319
324
  for (const [key, timer] of this.cache.entries()) {
@@ -323,12 +328,15 @@ class ScheduleTrigger {
323
328
  }
324
329
  }
325
330
  const { collection } = workflow.config;
326
- const event = `${collection}.afterSave`;
331
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
332
+ const event = `${collectionName}.afterSaveWithAssociations`;
333
+ const eventKey = `${collection}.afterSaveWithAssociations`;
327
334
  const name = getHookId(workflow, event);
328
- if (this.events.has(name)) {
335
+ if (this.events.has(eventKey)) {
329
336
  const listener = this.events.get(name);
330
- this.events.delete(name);
331
- this.workflow.app.db.off(event, listener);
337
+ const { db } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager;
338
+ db.off(event, listener);
339
+ this.events.delete(eventKey);
332
340
  }
333
341
  }
334
342
  }
package/package.json CHANGED
@@ -4,13 +4,13 @@
4
4
  "displayName.zh-CN": "工作流",
5
5
  "description": "A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.",
6
6
  "description.zh-CN": "一个强大的 BPM 工具,为业务自动化提供基础支持,并且可任意扩展更多的触发器和节点。",
7
- "version": "0.20.0-alpha.9",
7
+ "version": "0.21.0-alpha.2",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow",
11
11
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow",
12
12
  "dependencies": {
13
- "@nocobase/plugin-workflow-test": "0.20.0-alpha.9"
13
+ "@nocobase/plugin-workflow-test": "0.21.0-alpha.2"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@ant-design/icons": "5.x",
@@ -45,7 +45,7 @@
45
45
  "@nocobase/test": "0.x",
46
46
  "@nocobase/utils": "0.x"
47
47
  },
48
- "gitHead": "5473d9039cfdb649a8c8c625edefc9a3ac464be5",
48
+ "gitHead": "90628f2e2da846208fb2d7966ddb4e467d187ffb",
49
49
  "keywords": [
50
50
  "Workflow"
51
51
  ]
@@ -1,2 +0,0 @@
1
- export declare const getWorkflowDetailPath: (id: string | number) => string;
2
- export declare const getWorkflowExecutionsPath: (id: string | number) => string;