@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.
- package/dist/client/ExecutionContextProvider.d.ts +7 -0
- package/dist/client/components/CollectionBlockInitializer.d.ts +1 -1
- package/dist/client/components/DetailsBlockProvider.d.ts +6 -0
- package/dist/client/components/SimpleDesigner.d.ts +2 -0
- package/dist/client/components/TriggerOptionRender.d.ts +4 -0
- package/dist/client/components/ValueBlock.d.ts +1 -0
- package/dist/client/components/index.d.ts +2 -0
- package/dist/client/hooks/index.d.ts +3 -0
- package/dist/client/hooks/useWorkflowExecuted.d.ts +2 -0
- package/dist/client/index.d.ts +12 -12
- package/dist/client/index.js +40 -40
- package/dist/client/nodes/calculation.d.ts +1 -0
- package/dist/client/nodes/create.d.ts +2 -5
- package/dist/client/nodes/destroy.d.ts +5 -8
- package/dist/client/nodes/query.d.ts +5 -8
- package/dist/client/nodes/update.d.ts +6 -9
- package/dist/client/schemas/collection.d.ts +5 -8
- package/dist/client/triggers/collection.d.ts +11 -9
- package/dist/client/triggers/schedule/OnField.d.ts +1 -1
- package/dist/client/utils.d.ts +2 -1
- package/dist/externalVersion.js +11 -10
- package/dist/locale/zh-CN.json +3 -3
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/server/Plugin.d.ts +3 -1
- package/dist/server/Plugin.js +20 -8
- package/dist/server/collections/executions.js +1 -1
- package/dist/server/instructions/CreateInstruction.js +7 -4
- package/dist/server/instructions/DestroyInstruction.js +5 -3
- package/dist/server/instructions/QueryInstruction.js +5 -3
- package/dist/server/instructions/UpdateInstruction.js +5 -3
- package/dist/server/migrations/20230411034722-manual-multi-form.js +3 -5
- package/dist/server/migrations/20230612021134-manual-collection-block.js +2 -4
- package/dist/server/triggers/CollectionTrigger.js +33 -22
- package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.js +18 -10
- package/package.json +3 -3
- 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 {
|
|
57
|
-
const
|
|
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,
|
|
60
|
-
if (changed && changed.length && changed.filter(
|
|
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 && ((
|
|
67
|
+
if (condition && ((_b = condition.$and) == null ? void 0 : _b.length)) {
|
|
64
68
|
const count = await repository.count({
|
|
65
69
|
filter: {
|
|
66
|
-
$and: [condition, { [
|
|
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[
|
|
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
|
-
|
|
108
|
+
var _a, _b;
|
|
105
109
|
const { collection, mode } = workflow.config;
|
|
106
|
-
|
|
107
|
-
|
|
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 = `${
|
|
112
|
-
const name = getHookId(workflow,
|
|
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
|
-
|
|
137
|
+
var _a;
|
|
130
138
|
const { collection, mode } = workflow.config;
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
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(
|
|
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
|
|
261
|
-
const
|
|
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
|
|
283
|
-
const
|
|
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
|
|
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
|
|
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(
|
|
335
|
+
if (this.events.has(eventKey)) {
|
|
329
336
|
const listener = this.events.get(name);
|
|
330
|
-
this.
|
|
331
|
-
|
|
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.
|
|
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.
|
|
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": "
|
|
48
|
+
"gitHead": "90628f2e2da846208fb2d7966ddb4e467d187ffb",
|
|
49
49
|
"keywords": [
|
|
50
50
|
"Workflow"
|
|
51
51
|
]
|