@nocobase/plugin-workflow 0.20.0-alpha.9 → 0.21.0-alpha.10

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 (44) 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/useRefreshActionProps.d.ts +3 -0
  10. package/dist/client/hooks/useTriggerWorkflowActionProps.d.ts +1 -1
  11. package/dist/client/hooks/useWorkflowExecuted.d.ts +2 -0
  12. package/dist/client/index.d.ts +12 -14
  13. package/dist/client/index.js +40 -40
  14. package/dist/client/nodes/calculation.d.ts +1 -0
  15. package/dist/client/nodes/create.d.ts +2 -5
  16. package/dist/client/nodes/destroy.d.ts +5 -8
  17. package/dist/client/nodes/index.d.ts +6 -0
  18. package/dist/client/nodes/query.d.ts +5 -8
  19. package/dist/client/nodes/update.d.ts +6 -9
  20. package/dist/client/schemas/collection.d.ts +5 -8
  21. package/dist/client/schemas/executions.d.ts +9 -0
  22. package/dist/client/triggers/collection.d.ts +11 -9
  23. package/dist/client/triggers/index.d.ts +3 -0
  24. package/dist/client/triggers/schedule/OnField.d.ts +1 -1
  25. package/dist/client/utils.d.ts +2 -1
  26. package/dist/externalVersion.js +11 -10
  27. package/dist/locale/zh-CN.json +5 -4
  28. package/dist/node_modules/cron-parser/package.json +1 -1
  29. package/dist/node_modules/lru-cache/package.json +1 -1
  30. package/dist/server/Plugin.d.ts +22 -2
  31. package/dist/server/Plugin.js +60 -30
  32. package/dist/server/Processor.d.ts +50 -1
  33. package/dist/server/Processor.js +49 -2
  34. package/dist/server/collections/executions.js +1 -1
  35. package/dist/server/instructions/CreateInstruction.js +7 -4
  36. package/dist/server/instructions/DestroyInstruction.js +5 -3
  37. package/dist/server/instructions/QueryInstruction.js +5 -3
  38. package/dist/server/instructions/UpdateInstruction.js +5 -3
  39. package/dist/server/migrations/20230411034722-manual-multi-form.js +3 -5
  40. package/dist/server/migrations/20230612021134-manual-collection-block.js +2 -4
  41. package/dist/server/triggers/CollectionTrigger.js +33 -22
  42. package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.js +18 -10
  43. package/package.json +3 -4
  44. package/dist/client/constant.d.ts +0 -2
@@ -20,13 +20,31 @@ export default class Processor {
20
20
  [-6]: -6;
21
21
  };
22
22
  logger: Logger;
23
+ /**
24
+ * @experimental
25
+ */
23
26
  transaction: Transaction;
27
+ /**
28
+ * @experimental
29
+ */
24
30
  nodes: FlowNodeModel[];
31
+ /**
32
+ * @experimental
33
+ */
25
34
  nodesMap: Map<number, FlowNodeModel>;
35
+ /**
36
+ * @experimental
37
+ */
26
38
  jobsMap: Map<number, JobModel>;
39
+ /**
40
+ * @experimental
41
+ */
27
42
  jobsMapByNodeKey: {
28
43
  [key: string]: any;
29
44
  };
45
+ /**
46
+ * @experimental
47
+ */
30
48
  lastSavedJob: JobModel | null;
31
49
  constructor(execution: ExecutionModel, options: ProcessorOptions);
32
50
  private makeNodes;
@@ -37,15 +55,43 @@ export default class Processor {
37
55
  private exec;
38
56
  run(node: any, input?: any): any;
39
57
  end(node: any, job: JobModel): Promise<any>;
40
- recall(node: any, job: any): Promise<any>;
58
+ private recall;
41
59
  exit(s?: number): Promise<any>;
60
+ /**
61
+ * @experimental
62
+ * @param {JobModel | Record<string, any>} payload
63
+ * @returns {JobModel}
64
+ */
42
65
  saveJob(payload: any): Promise<any>;
66
+ /**
67
+ * @experimental
68
+ */
43
69
  getBranches(node: FlowNodeModel): FlowNodeModel[];
70
+ /**
71
+ * @experimental
72
+ * find the first node in current branch
73
+ */
44
74
  findBranchStartNode(node: FlowNodeModel, parent?: FlowNodeModel): FlowNodeModel | null;
75
+ /**
76
+ * @experimental
77
+ * find the node start current branch
78
+ */
45
79
  findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null;
80
+ /**
81
+ * @experimental
82
+ */
46
83
  findBranchEndNode(node: FlowNodeModel): FlowNodeModel | null;
84
+ /**
85
+ * @experimental
86
+ */
47
87
  findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null;
88
+ /**
89
+ * @experimental
90
+ */
48
91
  findBranchLastJob(node: FlowNodeModel, job: JobModel): JobModel | null;
92
+ /**
93
+ * @experimental
94
+ */
49
95
  getScope(sourceNodeId: number): {
50
96
  $context: any;
51
97
  $jobsMapByNodeKey: {
@@ -54,5 +100,8 @@ export default class Processor {
54
100
  $system: {};
55
101
  $scopes: {};
56
102
  };
103
+ /**
104
+ * @experimental
105
+ */
57
106
  getParsedValue(value: any, sourceNodeId: number, additionalScope?: object): any;
58
107
  }
@@ -42,11 +42,29 @@ class Processor {
42
42
  [import_constants.JOB_STATUS.RETRY_NEEDED]: import_constants.EXECUTION_STATUS.RETRY_NEEDED
43
43
  };
44
44
  logger;
45
+ /**
46
+ * @experimental
47
+ */
45
48
  transaction;
49
+ /**
50
+ * @experimental
51
+ */
46
52
  nodes = [];
53
+ /**
54
+ * @experimental
55
+ */
47
56
  nodesMap = /* @__PURE__ */ new Map();
57
+ /**
58
+ * @experimental
59
+ */
48
60
  jobsMap = /* @__PURE__ */ new Map();
61
+ /**
62
+ * @experimental
63
+ */
49
64
  jobsMapByNodeKey = {};
65
+ /**
66
+ * @experimental
67
+ */
50
68
  lastSavedJob = null;
51
69
  // make dual linked nodes list then cache
52
70
  makeNodes(nodes = []) {
@@ -185,6 +203,11 @@ class Processor {
185
203
  return null;
186
204
  }
187
205
  // TODO(optimize)
206
+ /**
207
+ * @experimental
208
+ * @param {JobModel | Record<string, any>} payload
209
+ * @returns {JobModel}
210
+ */
188
211
  async saveJob(payload) {
189
212
  const { database } = this.execution.constructor;
190
213
  const { transaction } = this;
@@ -209,10 +232,16 @@ class Processor {
209
232
  this.jobsMapByNodeKey[job.nodeKey] = job.result;
210
233
  return job;
211
234
  }
235
+ /**
236
+ * @experimental
237
+ */
212
238
  getBranches(node) {
213
239
  return this.nodes.filter((item) => item.upstream === node && item.branchIndex !== null).sort((a, b) => Number(a.branchIndex) - Number(b.branchIndex));
214
240
  }
215
- // find the first node in current branch
241
+ /**
242
+ * @experimental
243
+ * find the first node in current branch
244
+ */
216
245
  findBranchStartNode(node, parent) {
217
246
  for (let n = node; n; n = n.upstream) {
218
247
  if (!parent) {
@@ -227,7 +256,10 @@ class Processor {
227
256
  }
228
257
  return null;
229
258
  }
230
- // find the node start current branch
259
+ /**
260
+ * @experimental
261
+ * find the node start current branch
262
+ */
231
263
  findBranchParentNode(node) {
232
264
  for (let n = node; n; n = n.upstream) {
233
265
  if (n.branchIndex !== null) {
@@ -236,6 +268,9 @@ class Processor {
236
268
  }
237
269
  return null;
238
270
  }
271
+ /**
272
+ * @experimental
273
+ */
239
274
  findBranchEndNode(node) {
240
275
  for (let n = node; n; n = n.downstream) {
241
276
  if (!n.downstream) {
@@ -244,6 +279,9 @@ class Processor {
244
279
  }
245
280
  return null;
246
281
  }
282
+ /**
283
+ * @experimental
284
+ */
247
285
  findBranchParentJob(job, node) {
248
286
  for (let j = job; j; j = this.jobsMap.get(j.upstreamId)) {
249
287
  if (j.nodeId === node.id) {
@@ -252,6 +290,9 @@ class Processor {
252
290
  }
253
291
  return null;
254
292
  }
293
+ /**
294
+ * @experimental
295
+ */
255
296
  findBranchLastJob(node, job) {
256
297
  const allJobs = Array.from(this.jobsMap.values());
257
298
  const branchJobs = [];
@@ -268,6 +309,9 @@ class Processor {
268
309
  }
269
310
  return null;
270
311
  }
312
+ /**
313
+ * @experimental
314
+ */
271
315
  getScope(sourceNodeId) {
272
316
  const node = this.nodesMap.get(sourceNodeId);
273
317
  const systemFns = {};
@@ -292,6 +336,9 @@ class Processor {
292
336
  $scopes
293
337
  };
294
338
  }
339
+ /**
340
+ * @experimental
341
+ */
295
342
  getParsedValue(value, sourceNodeId, additionalScope) {
296
343
  const template = (0, import_utils.parse)(value);
297
344
  const scope = Object.assign(this.getScope(sourceNodeId), additionalScope);
@@ -32,7 +32,7 @@ var executions_default = {
32
32
  name: "workflow"
33
33
  },
34
34
  {
35
- type: "uid",
35
+ type: "string",
36
36
  name: "key"
37
37
  },
38
38
  {
@@ -21,20 +21,23 @@ __export(CreateInstruction_exports, {
21
21
  default: () => CreateInstruction_default
22
22
  });
23
23
  module.exports = __toCommonJS(CreateInstruction_exports);
24
+ var import_data_source_manager = require("@nocobase/data-source-manager");
24
25
  var import_constants = require("../constants");
25
26
  var import_utils = require("../utils");
26
27
  var import__ = require(".");
27
28
  class CreateInstruction extends import__.Instruction {
28
29
  async run(node, input, processor) {
29
30
  const { collection, params: { appends = [], ...params } = {} } = node.config;
30
- const { repository, model } = node.constructor.database.getCollection(collection);
31
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
32
+ const { repository, filterTargetKey } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
31
33
  const options = processor.getParsedValue(params, node.id);
34
+ const transaction = this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction);
32
35
  const created = await repository.create({
33
36
  ...options,
34
37
  context: {
35
38
  stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id)))
36
39
  },
37
- transaction: processor.transaction
40
+ transaction
38
41
  });
39
42
  let result = created;
40
43
  if (created && appends.length) {
@@ -44,9 +47,9 @@ class CreateInstruction extends import__.Instruction {
44
47
  return set;
45
48
  }, /* @__PURE__ */ new Set());
46
49
  result = await repository.findOne({
47
- filterByTk: created[model.primaryKeyAttribute],
50
+ filterByTk: created[filterTargetKey],
48
51
  appends: Array.from(includeFields),
49
- transaction: processor.transaction
52
+ transaction
50
53
  });
51
54
  }
52
55
  return {
@@ -21,19 +21,21 @@ __export(DestroyInstruction_exports, {
21
21
  default: () => DestroyInstruction_default
22
22
  });
23
23
  module.exports = __toCommonJS(DestroyInstruction_exports);
24
+ var import_data_source_manager = require("@nocobase/data-source-manager");
24
25
  var import__ = require(".");
25
26
  var import_constants = require("../constants");
26
27
  class DestroyInstruction extends import__.Instruction {
27
28
  async run(node, input, processor) {
28
29
  const { collection, params = {} } = node.config;
29
- const repo = node.constructor.database.getRepository(collection);
30
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
31
+ const { repository } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
30
32
  const options = processor.getParsedValue(params, node.id);
31
- const result = await repo.destroy({
33
+ const result = await repository.destroy({
32
34
  ...options,
33
35
  context: {
34
36
  stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id)))
35
37
  },
36
- transaction: processor.transaction
38
+ transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction)
37
39
  });
38
40
  return {
39
41
  result,
@@ -22,13 +22,15 @@ __export(QueryInstruction_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(QueryInstruction_exports);
24
24
  var import_actions = require("@nocobase/actions");
25
+ var import_data_source_manager = require("@nocobase/data-source-manager");
25
26
  var import_constants = require("../constants");
26
27
  var import_utils = require("../utils");
27
28
  var import__ = require(".");
28
29
  class QueryInstruction extends import__.Instruction {
29
30
  async run(node, input, processor) {
30
31
  const { collection, multiple, params = {}, failOnEmpty = false } = node.config;
31
- const repo = node.constructor.database.getRepository(collection);
32
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
33
+ const { repository } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
32
34
  const {
33
35
  page = import_actions.DEFAULT_PAGE,
34
36
  pageSize = import_actions.DEFAULT_PER_PAGE,
@@ -42,7 +44,7 @@ class QueryInstruction extends import__.Instruction {
42
44
  return set;
43
45
  }, /* @__PURE__ */ new Set())
44
46
  ) : options.appends;
45
- const result = await (multiple ? repo.find : repo.findOne).call(repo, {
47
+ const result = await (multiple ? repository.find : repository.findOne).call(repository, {
46
48
  ...options,
47
49
  ...import_actions.utils.pageArgsToLimitArgs(page, pageSize),
48
50
  sort: sort.filter((item) => item.field).map((item) => {
@@ -50,7 +52,7 @@ class QueryInstruction extends import__.Instruction {
50
52
  return `${((_a = item.direction) == null ? void 0 : _a.toLowerCase()) === "desc" ? "-" : ""}${item.field}`;
51
53
  }),
52
54
  appends,
53
- transaction: processor.transaction
55
+ transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction)
54
56
  });
55
57
  if (failOnEmpty && (multiple ? !result.length : !result)) {
56
58
  return {
@@ -21,19 +21,21 @@ __export(UpdateInstruction_exports, {
21
21
  default: () => UpdateInstruction_default
22
22
  });
23
23
  module.exports = __toCommonJS(UpdateInstruction_exports);
24
+ var import_data_source_manager = require("@nocobase/data-source-manager");
24
25
  var import_constants = require("../constants");
25
26
  var import__ = require(".");
26
27
  class UpdateInstruction extends import__.Instruction {
27
28
  async run(node, input, processor) {
28
29
  const { collection, params = {} } = node.config;
29
- const repo = node.constructor.database.getRepository(collection);
30
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
31
+ const { repository } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
30
32
  const options = processor.getParsedValue(params, node.id);
31
- const result = await repo.update({
33
+ const result = await repository.update({
32
34
  ...options,
33
35
  context: {
34
36
  stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id)))
35
37
  },
36
- transaction: processor.transaction
38
+ transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction)
37
39
  });
38
40
  return {
39
41
  result: result.length ?? result,
@@ -112,12 +112,10 @@ function migrateConfig({ schema = {}, actions = [] }) {
112
112
  [formId]: {
113
113
  type: "void",
114
114
  "x-component": "FormV2",
115
- "x-component-props": {
116
- useProps: "{{ useFormBlockProps }}"
117
- },
115
+ "x-use-component-props": "useFormBlockProps",
118
116
  properties: {
119
117
  grid: Object.assign(formBlock.properties.grid, {
120
- "x-initializer": "AddCustomFormField"
118
+ "x-initializer": "workflowManual:customForm:configureFields"
121
119
  }),
122
120
  // 7.
123
121
  actions: {
@@ -130,7 +128,7 @@ function migrateConfig({ schema = {}, actions = [] }) {
130
128
  marginTop: "1.5em"
131
129
  }
132
130
  },
133
- "x-initializer": "AddActionButton",
131
+ "x-initializer": "workflowManual:form:configureActions",
134
132
  properties: schema.actions
135
133
  }
136
134
  }
@@ -67,15 +67,13 @@ function migrateSchema(schema = {}) {
67
67
  type: "void",
68
68
  name: id,
69
69
  "x-component": "FormV2",
70
- "x-component-props": {
71
- useProps: "{{useDetailsBlockProps}}"
72
- },
70
+ "x-use-component-props": "useDetailsBlockProps",
73
71
  properties: {
74
72
  grid: {
75
73
  type: "void",
76
74
  name: "grid",
77
75
  "x-component": "Grid",
78
- "x-initializer": "ReadPrettyFormItemInitializers",
76
+ "x-initializer": "details:configureFields",
79
77
  properties: grid.properties
80
78
  }
81
79
  }
@@ -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.10",
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.10"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@ant-design/icons": "5.x",
@@ -19,7 +19,6 @@
19
19
  "@formily/react": "2.x",
20
20
  "@types/ejs": "^3.1.1",
21
21
  "antd": "5.x",
22
- "axios": "^0.26.1",
23
22
  "classnames": "^2.3.1",
24
23
  "cron-parser": "4.4.0",
25
24
  "dayjs": "^1.11.8",
@@ -45,7 +44,7 @@
45
44
  "@nocobase/test": "0.x",
46
45
  "@nocobase/utils": "0.x"
47
46
  },
48
- "gitHead": "5473d9039cfdb649a8c8c625edefc9a3ac464be5",
47
+ "gitHead": "98adf5ec996a4f359c6ca1c4a6ac837c43b6e268",
49
48
  "keywords": [
50
49
  "Workflow"
51
50
  ]
@@ -1,2 +0,0 @@
1
- export declare const getWorkflowDetailPath: (id: string | number) => string;
2
- export declare const getWorkflowExecutionsPath: (id: string | number) => string;