@nocobase/plugin-workflow 0.7.0-alpha.31 → 0.7.0-alpha.34
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/esm/actions/index.js +8 -2
- package/esm/actions/index.js.map +1 -1
- package/esm/actions/{flow_nodes.d.ts → nodes.d.ts} +1 -0
- package/esm/actions/{flow_nodes.js → nodes.js} +67 -19
- package/esm/actions/nodes.js.map +1 -0
- package/esm/actions/workflows.d.ts +3 -0
- package/esm/actions/workflows.js +163 -0
- package/esm/actions/workflows.js.map +1 -0
- package/esm/collections/flow_nodes.js +2 -9
- package/esm/collections/flow_nodes.js.map +1 -1
- package/esm/collections/workflows.js +23 -0
- package/esm/collections/workflows.js.map +1 -1
- package/esm/instructions/create.d.ts +1 -1
- package/esm/instructions/create.js +3 -2
- package/esm/instructions/create.js.map +1 -1
- package/esm/instructions/destroy.js +1 -1
- package/esm/instructions/destroy.js.map +1 -1
- package/esm/instructions/parallel.js +1 -1
- package/esm/instructions/parallel.js.map +1 -1
- package/esm/instructions/query.js +5 -1
- package/esm/instructions/query.js.map +1 -1
- package/esm/instructions/update.d.ts +2 -1
- package/esm/instructions/update.js +1 -1
- package/esm/instructions/update.js.map +1 -1
- package/esm/models/Execution.d.ts +2 -1
- package/esm/models/Execution.js +6 -6
- package/esm/models/Execution.js.map +1 -1
- package/esm/models/Workflow.d.ts +1 -0
- package/esm/models/Workflow.js +3 -0
- package/esm/models/Workflow.js.map +1 -1
- package/lib/actions/index.js +8 -2
- package/lib/actions/index.js.map +1 -1
- package/lib/actions/{flow_nodes.d.ts → nodes.d.ts} +1 -0
- package/lib/actions/{flow_nodes.js → nodes.js} +69 -39
- package/lib/actions/nodes.js.map +1 -0
- package/lib/actions/workflows.d.ts +3 -0
- package/lib/actions/workflows.js +168 -0
- package/lib/actions/workflows.js.map +1 -0
- package/lib/collections/flow_nodes.js +2 -9
- package/lib/collections/flow_nodes.js.map +1 -1
- package/lib/collections/workflows.js +23 -0
- package/lib/collections/workflows.js.map +1 -1
- package/lib/instructions/create.d.ts +1 -1
- package/lib/instructions/create.js +3 -2
- package/lib/instructions/create.js.map +1 -1
- package/lib/instructions/destroy.js +1 -1
- package/lib/instructions/destroy.js.map +1 -1
- package/lib/instructions/parallel.js +1 -1
- package/lib/instructions/parallel.js.map +1 -1
- package/lib/instructions/query.js +5 -1
- package/lib/instructions/query.js.map +1 -1
- package/lib/instructions/update.d.ts +2 -1
- package/lib/instructions/update.js +1 -1
- package/lib/instructions/update.js.map +1 -1
- package/lib/models/Execution.d.ts +2 -1
- package/lib/models/Execution.js +6 -6
- package/lib/models/Execution.js.map +1 -1
- package/lib/models/Workflow.d.ts +1 -0
- package/lib/models/Workflow.js +3 -0
- package/lib/models/Workflow.js.map +1 -1
- package/package.json +7 -7
- package/esm/actions/flow_nodes.js.map +0 -1
- package/lib/actions/flow_nodes.js.map +0 -1
package/esm/actions/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as workflows from './workflows';
|
|
2
|
+
import * as nodes from './nodes';
|
|
2
3
|
function make(name, mod) {
|
|
3
4
|
return Object.keys(mod).reduce((result, key) => (Object.assign(Object.assign({}, result), { [`${name}:${key}`]: mod[key] })), {});
|
|
4
5
|
}
|
|
5
6
|
export default function (app) {
|
|
6
|
-
app.actions(Object.assign({}, make('
|
|
7
|
+
app.actions(Object.assign(Object.assign(Object.assign({}, make('workflows', workflows)), make('workflows.nodes', {
|
|
8
|
+
create: nodes.create,
|
|
9
|
+
destroy: nodes.destroy
|
|
10
|
+
})), make('flow_nodes', {
|
|
11
|
+
update: nodes.update
|
|
12
|
+
})));
|
|
7
13
|
}
|
|
8
14
|
//# sourceMappingURL=index.js.map
|
package/esm/actions/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,SAAS,IAAI,CAAC,IAAI,EAAE,GAAG;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iCAC3C,MAAM,KACT,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAC5B,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AAED,MAAM,CAAC,OAAO,WAAU,GAAG;IACzB,GAAG,CAAC,OAAO,+CACN,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAC5B,IAAI,CAAC,iBAAiB,EAAE;QACzB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,GACC,IAAI,CAAC,YAAY,EAAE;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,EACF,CAAC;AACL,CAAC","sourcesContent":["import * as workflows from './workflows';\nimport * as nodes from './nodes';\n\nfunction make(name, mod) {\n return Object.keys(mod).reduce((result, key) => ({\n ...result,\n [`${name}:${key}`]: mod[key]\n }), {})\n}\n\nexport default function(app) {\n app.actions({\n ...make('workflows', workflows),\n ...make('workflows.nodes', {\n create: nodes.create,\n destroy: nodes.destroy\n }),\n ...make('flow_nodes', {\n update: nodes.update\n })\n });\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Context } from '@nocobase/actions';
|
|
2
2
|
export declare function create(context: Context, next: any): Promise<void>;
|
|
3
3
|
export declare function destroy(context: Context, next: any): Promise<void>;
|
|
4
|
+
export declare function update(context: Context, next: any): Promise<void>;
|
|
@@ -8,12 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Op } from 'sequelize';
|
|
11
|
-
import
|
|
11
|
+
import { utils } from '@nocobase/actions';
|
|
12
12
|
export function create(context, next) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const { db } = context;
|
|
15
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
16
|
+
const { whitelist, blacklist, updateAssociationValues, values, associatedIndex: workflowId } = context.action.params;
|
|
17
|
+
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const workflow = yield repository.getSourceModel(transaction);
|
|
19
|
+
if (workflow.executed) {
|
|
20
|
+
context.throw(400, 'Node could not be created in executed workflow');
|
|
21
|
+
}
|
|
22
|
+
const instance = yield repository.create({
|
|
23
|
+
values,
|
|
24
|
+
whitelist,
|
|
25
|
+
blacklist,
|
|
26
|
+
updateAssociationValues,
|
|
27
|
+
context,
|
|
28
|
+
transaction
|
|
29
|
+
});
|
|
17
30
|
if (!instance.upstreamId) {
|
|
18
31
|
const previousHead = yield repository.findOne({
|
|
19
32
|
filter: {
|
|
@@ -21,26 +34,27 @@ export function create(context, next) {
|
|
|
21
34
|
$ne: instance.id
|
|
22
35
|
},
|
|
23
36
|
upstreamId: null
|
|
24
|
-
}
|
|
37
|
+
},
|
|
38
|
+
transaction
|
|
25
39
|
});
|
|
26
40
|
if (previousHead) {
|
|
27
|
-
yield previousHead.setUpstream(instance);
|
|
28
|
-
yield instance.setDownstream(previousHead);
|
|
41
|
+
yield previousHead.setUpstream(instance, { transaction });
|
|
42
|
+
yield instance.setDownstream(previousHead, { transaction });
|
|
29
43
|
instance.set('downstream', previousHead);
|
|
30
44
|
}
|
|
31
|
-
return
|
|
45
|
+
return instance;
|
|
32
46
|
}
|
|
33
|
-
const upstream = yield instance.getUpstream();
|
|
47
|
+
const upstream = yield instance.getUpstream({ transaction });
|
|
34
48
|
if (instance.branchIndex == null) {
|
|
35
|
-
const downstream = yield upstream.getDownstream();
|
|
49
|
+
const downstream = yield upstream.getDownstream({ transaction });
|
|
36
50
|
if (downstream) {
|
|
37
|
-
yield downstream.setUpstream(instance);
|
|
38
|
-
yield instance.setDownstream(downstream);
|
|
51
|
+
yield downstream.setUpstream(instance, { transaction });
|
|
52
|
+
yield instance.setDownstream(downstream, { transaction });
|
|
39
53
|
instance.set('downstream', downstream);
|
|
40
54
|
}
|
|
41
55
|
yield upstream.update({
|
|
42
56
|
downstreamId: instance.id
|
|
43
|
-
});
|
|
57
|
+
}, { transaction });
|
|
44
58
|
upstream.set('downstream', instance);
|
|
45
59
|
}
|
|
46
60
|
else {
|
|
@@ -50,20 +64,21 @@ export function create(context, next) {
|
|
|
50
64
|
[Op.ne]: instance.id
|
|
51
65
|
},
|
|
52
66
|
branchIndex: instance.branchIndex
|
|
53
|
-
}
|
|
67
|
+
},
|
|
68
|
+
transaction
|
|
54
69
|
});
|
|
55
70
|
if (downstream) {
|
|
56
71
|
yield downstream.update({
|
|
57
72
|
upstreamId: instance.id,
|
|
58
73
|
branchIndex: null
|
|
59
|
-
});
|
|
60
|
-
yield instance.setDownstream(downstream);
|
|
74
|
+
}, { transaction });
|
|
75
|
+
yield instance.setDownstream(downstream, { transaction });
|
|
61
76
|
instance.set('downstream', downstream);
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
79
|
instance.set('upstream', upstream);
|
|
65
|
-
yield next();
|
|
66
80
|
}));
|
|
81
|
+
yield next();
|
|
67
82
|
});
|
|
68
83
|
}
|
|
69
84
|
function searchBranchNodes(nodes, from) {
|
|
@@ -80,10 +95,14 @@ function searchBranchDownstreams(nodes, from) {
|
|
|
80
95
|
}
|
|
81
96
|
export function destroy(context, next) {
|
|
82
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const repository = utils.getRepositoryFromParams(context);
|
|
84
98
|
const { db } = context;
|
|
99
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
85
100
|
const { filterByTk } = context.action.params;
|
|
86
101
|
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const workflow = yield repository.getSourceModel(transaction);
|
|
103
|
+
if (workflow.executed) {
|
|
104
|
+
context.throw(400, 'Nodes in executed workflow could not be deleted');
|
|
105
|
+
}
|
|
87
106
|
const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];
|
|
88
107
|
const instance = yield repository.findOne({
|
|
89
108
|
filterByTk,
|
|
@@ -136,4 +155,33 @@ export function destroy(context, next) {
|
|
|
136
155
|
yield next();
|
|
137
156
|
});
|
|
138
157
|
}
|
|
139
|
-
|
|
158
|
+
export function update(context, next) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const { db } = context;
|
|
161
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
162
|
+
const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;
|
|
163
|
+
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
// TODO(optimize): duplicated instance query
|
|
165
|
+
const { workflow } = yield repository.findOne({
|
|
166
|
+
filterByTk,
|
|
167
|
+
appends: ['workflow.executed'],
|
|
168
|
+
transaction
|
|
169
|
+
});
|
|
170
|
+
if (workflow.executed) {
|
|
171
|
+
context.throw(400, 'Nodes in executed workflow could not be reconfigured');
|
|
172
|
+
}
|
|
173
|
+
return repository.update({
|
|
174
|
+
filterByTk,
|
|
175
|
+
values,
|
|
176
|
+
whitelist,
|
|
177
|
+
blacklist,
|
|
178
|
+
filter,
|
|
179
|
+
updateAssociationValues,
|
|
180
|
+
context,
|
|
181
|
+
transaction
|
|
182
|
+
});
|
|
183
|
+
}));
|
|
184
|
+
yield next();
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=nodes.js.map
|
|
@@ -0,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AK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5G,OAAO,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAM,WAAW,EAAC,EAAE;YAChE,4CAA4C;YAC5C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;gBAC5C,UAAU;gBACV,OAAO,EAAE,CAAC,mBAAmB,CAAC;gBAC9B,WAAW;aACZ,CAAC,CAAC;YACH,IAAI,QAAQ,CAAC,QAAQ,EAAE;gBACrB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,sDAAsD,CAAC,CAAC;aAC5E;YAED,OAAO,UAAU,CAAC,MAAM,CAAC;gBACvB,UAAU;gBACV,MAAM;gBACN,SAAS;gBACT,SAAS;gBACT,MAAM;gBACN,uBAAuB;gBACvB,OAAO;gBACP,WAAW;aACZ,CAAC,CAAC;QACL,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA","sourcesContent":["import { Op } from 'sequelize';\nimport { Context, utils } from '@nocobase/actions';\nimport { MultipleRelationRepository } from '@nocobase/database';\nimport WorkflowModel from '../models/Workflow';\n\nexport async function create(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context) as MultipleRelationRepository;\n const { whitelist, blacklist, updateAssociationValues, values, associatedIndex: workflowId } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const workflow = await repository.getSourceModel(transaction) as WorkflowModel;\n if (workflow.executed) {\n context.throw(400, 'Node could not be created in executed workflow');\n }\n\n const instance = await repository.create({\n values,\n whitelist,\n blacklist,\n updateAssociationValues,\n context,\n transaction\n });\n\n if (!instance.upstreamId) {\n const previousHead = await repository.findOne({\n filter: {\n id: {\n $ne: instance.id\n },\n upstreamId: null\n },\n transaction\n });\n if (previousHead) {\n await previousHead.setUpstream(instance, { transaction });\n await instance.setDownstream(previousHead, { transaction });\n instance.set('downstream', previousHead);\n }\n return instance;\n }\n\n const upstream = await instance.getUpstream({ transaction });\n\n if (instance.branchIndex == null) {\n const downstream = await upstream.getDownstream({ transaction });\n\n if (downstream) {\n await downstream.setUpstream(instance, { transaction });\n await instance.setDownstream(downstream, { transaction });\n instance.set('downstream', downstream);\n }\n\n await upstream.update({\n downstreamId: instance.id\n }, { transaction });\n\n upstream.set('downstream', instance);\n } else {\n const [downstream] = await upstream.getBranches({\n where: {\n id: {\n [Op.ne]: instance.id\n },\n branchIndex: instance.branchIndex\n },\n transaction\n });\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.id,\n branchIndex: null\n }, { transaction });\n await instance.setDownstream(downstream, { transaction });\n instance.set('downstream', downstream);\n }\n }\n\n instance.set('upstream', upstream);\n });\n\n await next();\n}\n\nfunction searchBranchNodes(nodes, from): any[] {\n const branchHeads = nodes\n .filter((item: any) => item.upstreamId === from.id && item.branchIndex != null);\n return branchHeads.reduce((flatten: any[], head) => flatten.concat(searchBranchDownstreams(nodes, head)), []) as any[];\n}\n\nfunction searchBranchDownstreams(nodes, from) {\n let result = [];\n for (let search = from; search; search = search.downstream) {\n result = [...result, search, ...searchBranchNodes(nodes, search)];\n }\n return result;\n}\n\nexport async function destroy(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context) as MultipleRelationRepository;\n const { filterByTk } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const workflow = await repository.getSourceModel(transaction) as WorkflowModel;\n if (workflow.executed) {\n context.throw(400, 'Nodes in executed workflow could not be deleted');\n }\n\n const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];\n const instance = await repository.findOne({\n filterByTk,\n fields: [...fields, 'workflowId'],\n appends: ['upstream', 'downstream'],\n transaction\n });\n const { upstream, downstream } = instance.get();\n\n if (upstream && upstream.downstreamId === instance.id) {\n await upstream.update({\n downstreamId: instance.downstreamId\n }, { transaction });\n }\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.upstreamId,\n branchIndex: instance.branchIndex\n }, { transaction });\n }\n\n const nodes = await repository.find({\n filter: {\n workflowId: instance.workflowId\n },\n fields,\n transaction\n });\n const nodesMap = new Map();\n // make map\n nodes.forEach(item => {\n nodesMap.set(item.id, item);\n });\n // overwrite\n nodesMap.set(instance.id, instance);\n // make linked list\n nodes.forEach(item => {\n if (item.upstreamId) {\n item.upstream = nodesMap.get(item.upstreamId);\n }\n if (item.downstreamId) {\n item.downstream = nodesMap.get(item.downstreamId);\n }\n });\n\n const branchNodes = searchBranchNodes(nodes, instance);\n\n await repository.destroy({\n filterByTk: [instance.id, ...branchNodes.map(item => item.id)],\n transaction\n });\n\n return instance;\n });\n\n await next();\n}\n\nexport async function update(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context);\n const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;\n context.body = await db.sequelize.transaction(async transaction => {\n // TODO(optimize): duplicated instance query\n const { workflow } = await repository.findOne({\n filterByTk,\n appends: ['workflow.executed'],\n transaction\n });\n if (workflow.executed) {\n context.throw(400, 'Nodes in executed workflow could not be reconfigured');\n }\n\n return repository.update({\n filterByTk,\n values,\n whitelist,\n blacklist,\n filter,\n updateAssociationValues,\n context,\n transaction\n });\n });\n\n await next();\n}\n"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
14
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
import { utils } from '@nocobase/actions';
|
|
18
|
+
import { Op } from '@nocobase/database';
|
|
19
|
+
export function update(context, next) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const { db } = context;
|
|
22
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
23
|
+
const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;
|
|
24
|
+
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const others = {};
|
|
26
|
+
if (values.enabled) {
|
|
27
|
+
values.current = true;
|
|
28
|
+
others.enabled = false;
|
|
29
|
+
}
|
|
30
|
+
if (values.current) {
|
|
31
|
+
others.current = false;
|
|
32
|
+
yield repository.update({
|
|
33
|
+
filter: {
|
|
34
|
+
key: values.key,
|
|
35
|
+
id: {
|
|
36
|
+
[Op.ne]: filterByTk
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
values: others,
|
|
40
|
+
context,
|
|
41
|
+
transaction
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const instance = yield repository.update({
|
|
45
|
+
filterByTk,
|
|
46
|
+
values,
|
|
47
|
+
whitelist,
|
|
48
|
+
blacklist,
|
|
49
|
+
filter,
|
|
50
|
+
updateAssociationValues,
|
|
51
|
+
context,
|
|
52
|
+
transaction
|
|
53
|
+
});
|
|
54
|
+
return instance;
|
|
55
|
+
}));
|
|
56
|
+
yield next();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function typeOf(value) {
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
return 'array';
|
|
62
|
+
}
|
|
63
|
+
else if (value instanceof Date) {
|
|
64
|
+
return 'date';
|
|
65
|
+
}
|
|
66
|
+
else if (value === null) {
|
|
67
|
+
return 'null';
|
|
68
|
+
}
|
|
69
|
+
return typeof value;
|
|
70
|
+
}
|
|
71
|
+
function migrateConfig(config, oldToNew) {
|
|
72
|
+
function migrate(value) {
|
|
73
|
+
switch (typeOf(value)) {
|
|
74
|
+
case 'object':
|
|
75
|
+
return Object.keys(value).reduce((result, key) => (Object.assign(Object.assign({}, result), { [key]: migrate(value[key]) })), {});
|
|
76
|
+
case 'array':
|
|
77
|
+
return value.map(item => migrate(item));
|
|
78
|
+
case 'string':
|
|
79
|
+
return value
|
|
80
|
+
.replace(/(\{\{\$jobsMapByNodeId\.)(\d+)/, (_, prefix, id) => `${prefix}${oldToNew.get(Number.parseInt(id, 10)).id}`);
|
|
81
|
+
default:
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return migrate(config);
|
|
86
|
+
}
|
|
87
|
+
export function duplicate(context, next) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const { db } = context;
|
|
90
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
91
|
+
const { filterByTk } = context.action.params;
|
|
92
|
+
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
var e_1, _a, e_2, _b;
|
|
94
|
+
var _c, _d;
|
|
95
|
+
const origin = yield repository.findOne({
|
|
96
|
+
filterByTk,
|
|
97
|
+
appends: ['nodes'],
|
|
98
|
+
context,
|
|
99
|
+
transaction
|
|
100
|
+
});
|
|
101
|
+
const instance = yield repository.create({
|
|
102
|
+
values: {
|
|
103
|
+
key: origin.key,
|
|
104
|
+
title: origin.title,
|
|
105
|
+
description: origin.description,
|
|
106
|
+
type: origin.type,
|
|
107
|
+
config: origin.config
|
|
108
|
+
},
|
|
109
|
+
transaction
|
|
110
|
+
});
|
|
111
|
+
const originalNodesMap = new Map();
|
|
112
|
+
origin.nodes.forEach((node) => {
|
|
113
|
+
originalNodesMap.set(node.id, node);
|
|
114
|
+
});
|
|
115
|
+
const oldToNew = new Map();
|
|
116
|
+
const newToOld = new Map();
|
|
117
|
+
try {
|
|
118
|
+
for (var _e = __asyncValues(origin.nodes), _f; _f = yield _e.next(), !_f.done;) {
|
|
119
|
+
const node = _f.value;
|
|
120
|
+
const newNode = yield instance.createNode({
|
|
121
|
+
type: node.type,
|
|
122
|
+
config: node.config,
|
|
123
|
+
title: node.title,
|
|
124
|
+
branchIndex: node.branchIndex
|
|
125
|
+
}, { transaction });
|
|
126
|
+
// NOTE: keep original node references for later replacement
|
|
127
|
+
oldToNew.set(node.id, newNode);
|
|
128
|
+
newToOld.set(newNode.id, node);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
132
|
+
finally {
|
|
133
|
+
try {
|
|
134
|
+
if (_f && !_f.done && (_a = _e.return)) yield _a.call(_e);
|
|
135
|
+
}
|
|
136
|
+
finally { if (e_1) throw e_1.error; }
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
for (var _g = __asyncValues(oldToNew.entries()), _h; _h = yield _g.next(), !_h.done;) {
|
|
140
|
+
const [oldId, newNode] = _h.value;
|
|
141
|
+
const oldNode = originalNodesMap.get(oldId);
|
|
142
|
+
const newUpstream = oldNode.upstreamId ? oldToNew.get(oldNode.upstreamId) : null;
|
|
143
|
+
const newDownstream = oldNode.downstreamId ? oldToNew.get(oldNode.downstreamId) : null;
|
|
144
|
+
yield newNode.update({
|
|
145
|
+
upstreamId: (_c = newUpstream === null || newUpstream === void 0 ? void 0 : newUpstream.id) !== null && _c !== void 0 ? _c : null,
|
|
146
|
+
downstreamId: (_d = newDownstream === null || newDownstream === void 0 ? void 0 : newDownstream.id) !== null && _d !== void 0 ? _d : null,
|
|
147
|
+
config: migrateConfig(oldNode.config, oldToNew)
|
|
148
|
+
}, { transaction });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
152
|
+
finally {
|
|
153
|
+
try {
|
|
154
|
+
if (_h && !_h.done && (_b = _g.return)) yield _b.call(_g);
|
|
155
|
+
}
|
|
156
|
+
finally { if (e_2) throw e_2.error; }
|
|
157
|
+
}
|
|
158
|
+
return instance;
|
|
159
|
+
}));
|
|
160
|
+
yield next();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=workflows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/actions/workflows.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,OAAO,EAAW,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAIxC,MAAM,UAAgB,MAAM,CAAC,OAAgB,EAAE,IAAI;;QACjD,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;QACvB,MAAM,UAAU,GAAG,KAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAAC,MAAM,CAA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C,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,WAAA,CAAA;oBAC/B,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;oBACjF,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;oBAEvF,MAAM,OAAO,CAAC,MAAM,CAAC;wBACnB,UAAU,EAAE,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,EAAE,mCAAI,IAAI;wBACnC,YAAY,EAAE,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,EAAE,mCAAI,IAAI;wBACvC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;qBAChD,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;iBACrB;;;;;;;;;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA","sourcesContent":["import parse from 'json-templates';\n\nimport { Context, utils } from '@nocobase/actions';\nimport { Op } from '@nocobase/database';\n\n\n\nexport async function update(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context);\n const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const others: { enabled?: boolean, current?: boolean } = {};\n\n if (values.enabled) {\n values.current = true;\n others.enabled = false;\n }\n\n if (values.current) {\n others.current = false;\n await repository.update({\n filter: {\n key: values.key,\n id: {\n [Op.ne]: filterByTk\n }\n },\n values: others,\n context,\n transaction\n });\n }\n\n const instance = await repository.update({\n filterByTk,\n values,\n whitelist,\n blacklist,\n filter,\n updateAssociationValues,\n context,\n transaction\n });\n\n return instance;\n });\n\n await next();\n}\n\nfunction typeOf(value) {\n if (Array.isArray(value)) {\n return 'array';\n } else if (value instanceof Date) {\n return 'date';\n } else if (value === null) {\n return 'null';\n }\n\n return typeof value;\n}\n\nfunction migrateConfig(config, oldToNew) {\n function migrate(value) {\n switch (typeOf(value)) {\n case 'object':\n return Object.keys(value).reduce((result, key) => ({ ...result, [key]: migrate(value[key]) }), {});\n case 'array':\n return value.map(item => migrate(item));\n case 'string':\n return value\n .replace(\n /(\\{\\{\\$jobsMapByNodeId\\.)(\\d+)/,\n (_, prefix, id) => `${prefix}${oldToNew.get(Number.parseInt(id, 10)).id}`\n );\n default:\n return value;\n }\n }\n\n return migrate(config);\n}\n\nexport async function duplicate(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context);\n const { filterByTk } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const origin = await repository.findOne({\n filterByTk,\n appends: ['nodes'],\n context,\n transaction\n });\n\n const instance = await repository.create({\n values: {\n key: origin.key,\n title: origin.title,\n description: origin.description,\n type: origin.type,\n config: origin.config\n },\n transaction\n });\n\n const originalNodesMap = new Map();\n origin.nodes.forEach((node) => {\n originalNodesMap.set(node.id, node);\n });\n\n const oldToNew = new Map();\n const newToOld = new Map();\n for await (const node of origin.nodes) {\n const newNode = await instance.createNode({\n type: node.type,\n config: node.config,\n title: node.title,\n branchIndex: node.branchIndex\n }, { transaction });\n // NOTE: keep original node references for later replacement\n oldToNew.set(node.id, newNode);\n newToOld.set(newNode.id, node);\n }\n\n for await (const [oldId, newNode] of oldToNew.entries()) {\n const oldNode = originalNodesMap.get(oldId);\n const newUpstream = oldNode.upstreamId ? oldToNew.get(oldNode.upstreamId) : null;\n const newDownstream = oldNode.downstreamId ? oldToNew.get(oldNode.downstreamId) : null;\n\n await newNode.update({\n upstreamId: newUpstream?.id ?? null,\n downstreamId: newDownstream?.id ?? null,\n config: migrateConfig(oldNode.config, oldToNew)\n }, { transaction });\n }\n\n return instance;\n });\n\n await next();\n}\n"]}
|
|
@@ -38,7 +38,7 @@ export default {
|
|
|
38
38
|
type: 'integer',
|
|
39
39
|
title: 'branch index'
|
|
40
40
|
},
|
|
41
|
-
// for reasons:
|
|
41
|
+
// Note: for reasons:
|
|
42
42
|
// 1. redirect type node to solve cycle flow.
|
|
43
43
|
// 2. recognize as real next node after branches.
|
|
44
44
|
{
|
|
@@ -51,14 +51,7 @@ export default {
|
|
|
51
51
|
interface: 'select',
|
|
52
52
|
type: 'string',
|
|
53
53
|
name: 'type',
|
|
54
|
-
title: '类型'
|
|
55
|
-
// TODO: data for test only now
|
|
56
|
-
dataSource: [
|
|
57
|
-
{ label: '数据处理', value: 'data' },
|
|
58
|
-
{ label: '数据查询', value: 'query' },
|
|
59
|
-
{ label: '等待人工输入', value: 'prompt' },
|
|
60
|
-
{ label: '条件判断', value: 'condition' },
|
|
61
|
-
]
|
|
54
|
+
title: '类型'
|
|
62
55
|
},
|
|
63
56
|
{
|
|
64
57
|
interface: 'json',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow_nodes.js","sourceRoot":"","sources":["../../src/collections/flow_nodes.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,YAAY;IAClB,0BAA0B;IAC1B,KAAK,EAAE,gBAAgB;IACvB,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,IAAI;SACZ;QACD,4BAA4B;QAC5B;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,WAAW;SAClB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,YAAY;SACrB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,YAAY;YACpB,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,YAAY;SACzB;QACD,mFAAmF;QACnF,mFAAmF;QACnF,6CAA6C;QAC7C;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,cAAc;SACtB;QACD,
|
|
1
|
+
{"version":3,"file":"flow_nodes.js","sourceRoot":"","sources":["../../src/collections/flow_nodes.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,YAAY;IAClB,0BAA0B;IAC1B,KAAK,EAAE,gBAAgB;IACvB,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,IAAI;SACZ;QACD,4BAA4B;QAC5B;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,WAAW;SAClB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,YAAY;SACrB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,YAAY;YACpB,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,YAAY;SACzB;QACD,mFAAmF;QACnF,mFAAmF;QACnF,6CAA6C;QAC7C;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,cAAc;SACtB;QACD,qBAAqB;QACrB,6CAA6C;QAC7C,iDAAiD;QACjD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,YAAY;SACrB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,EAAE;SACjB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'flow_nodes',\n // model: 'FlowNodeModel',\n title: 'Workflow Nodes',\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '名称'\n },\n // which workflow belongs to\n {\n interface: 'linkTo',\n name: 'workflow',\n type: 'belongsTo',\n },\n {\n interface: 'linkTo',\n name: 'upstream',\n type: 'belongsTo',\n target: 'flow_nodes'\n },\n {\n interface: 'linkTo',\n name: 'branches',\n type: 'hasMany',\n target: 'flow_nodes',\n sourceKey: 'id',\n foreignKey: 'upstreamId',\n },\n // only works when upstream node is branching type, such as condition and parallel.\n // put here because the design of flow-links model is not really necessary for now.\n // or it should be put into flow-links model.\n {\n interface: 'select',\n name: 'branchIndex',\n type: 'integer',\n title: 'branch index'\n },\n // Note: for reasons:\n // 1. redirect type node to solve cycle flow.\n // 2. recognize as real next node after branches.\n {\n interface: 'linkTo',\n name: 'downstream',\n type: 'belongsTo',\n target: 'flow_nodes'\n },\n {\n interface: 'select',\n type: 'string',\n name: 'type',\n title: '类型'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'config',\n title: '配置',\n defaultValue: {}\n }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -3,6 +3,10 @@ export default {
|
|
|
3
3
|
model: 'WorkflowModel',
|
|
4
4
|
title: '自动化',
|
|
5
5
|
fields: [
|
|
6
|
+
{
|
|
7
|
+
name: 'key',
|
|
8
|
+
type: 'uid'
|
|
9
|
+
},
|
|
6
10
|
{
|
|
7
11
|
interface: 'string',
|
|
8
12
|
type: 'string',
|
|
@@ -58,6 +62,25 @@ export default {
|
|
|
58
62
|
name: 'executions',
|
|
59
63
|
target: 'executions',
|
|
60
64
|
title: '触发执行'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
name: 'executed',
|
|
69
|
+
defaultValue: false
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
name: 'current',
|
|
74
|
+
defaultValue: false
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: 'hasMany',
|
|
78
|
+
name: 'revisions',
|
|
79
|
+
target: 'workflows',
|
|
80
|
+
foreignKey: 'key',
|
|
81
|
+
sourceKey: 'key',
|
|
82
|
+
// NOTE: no constraints needed here because tricky self-referencing
|
|
83
|
+
constraints: false
|
|
61
84
|
}
|
|
62
85
|
]
|
|
63
86
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/collections/workflows.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI;SACf;QACD;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,KAAK;SACpB;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;SACf;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,EAAE;SACjB;QACD;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,gBAAgB;YACtB,YAAY,EAAE,IAAI;SACnB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'workflows',\n model: 'WorkflowModel',\n title: '自动化',\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '工作流名称',\n required: true\n },\n {\n interface: 'boolean',\n type: 'boolean',\n name: 'enabled',\n title: '启用',\n defaultValue: false\n },\n {\n interface: 'textarea',\n type: 'text',\n name: 'description',\n title: '描述'\n },\n {\n interface: 'select',\n type: 'string',\n title: '触发方式',\n name: 'type',\n required: true\n },\n {\n interface: 'json',\n type: 'jsonb',\n title: '触发配置',\n name: 'config',\n required: true,\n defaultValue: {}\n },\n {\n interface: 'boolean',\n type: 'boolean',\n title: '使用事务',\n name: 'useTransaction',\n defaultValue: true\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'nodes',\n target: 'flow_nodes',\n title: '流程节点'\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'executions',\n target: 'executions',\n title: '触发执行'\n }\n ]\n} as CollectionOptions;\n"]}
|
|
1
|
+
{"version":3,"file":"workflows.js","s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QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,UAAU;YAChB,YAAY,EAAE,KAAK;SACpB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,YAAY,EAAE,KAAK;SACpB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,WAAW;YACnB,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,KAAK;YAChB,mEAAmE;YACnE,WAAW,EAAE,KAAK;SACnB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'workflows',\n model: 'WorkflowModel',\n title: '自动化',\n fields: [\n {\n name: 'key',\n type: 'uid'\n },\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '工作流名称',\n required: true\n },\n {\n interface: 'boolean',\n type: 'boolean',\n name: 'enabled',\n title: '启用',\n defaultValue: false\n },\n {\n interface: 'textarea',\n type: 'text',\n name: 'description',\n title: '描述'\n },\n {\n interface: 'select',\n type: 'string',\n title: '触发方式',\n name: 'type',\n required: true\n },\n {\n interface: 'json',\n type: 'jsonb',\n title: '触发配置',\n name: 'config',\n required: true,\n defaultValue: {}\n },\n {\n interface: 'boolean',\n type: 'boolean',\n title: '使用事务',\n name: 'useTransaction',\n defaultValue: true\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'nodes',\n target: 'flow_nodes',\n title: '流程节点'\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'executions',\n target: 'executions',\n title: '触发执行'\n },\n {\n type: 'boolean',\n name: 'executed',\n defaultValue: false\n },\n {\n type: 'boolean',\n name: 'current',\n defaultValue: false\n },\n {\n type: 'hasMany',\n name: 'revisions',\n target: 'workflows',\n foreignKey: 'key',\n sourceKey: 'key',\n // NOTE: no constraints needed here because tricky self-referencing\n constraints: false\n }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -14,9 +14,10 @@ export default {
|
|
|
14
14
|
const { collection, params = {} } = this.config;
|
|
15
15
|
const repo = this.constructor.database.getRepository(collection);
|
|
16
16
|
const options = execution.getParsedValue(params);
|
|
17
|
-
const result = yield repo.create(Object.assign(Object.assign({}, options), { transaction: execution.
|
|
17
|
+
const result = yield repo.create(Object.assign(Object.assign({}, options), { transaction: execution.tx }));
|
|
18
18
|
return {
|
|
19
|
-
|
|
19
|
+
// NOTE: get() for non-proxied instance (#380)
|
|
20
|
+
result: result.get(),
|
|
20
21
|
status: JOB_STATUS.RESOLVED
|
|
21
22
|
};
|
|
22
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/instructions/create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,iCAC3B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/instructions/create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,iCAC3B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,8CAA8C;gBAC9C,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE;gBACpB,MAAM,EAAE,UAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.create({\n ...options,\n transaction: execution.tx\n });\n\n return {\n // NOTE: get() for non-proxied instance (#380)\n result: result.get(),\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
const { collection, params = {} } = this.config;
|
|
15
15
|
const repo = this.constructor.database.getRepository(collection);
|
|
16
16
|
const options = execution.getParsedValue(params);
|
|
17
|
-
const result = yield repo.destroy(Object.assign(Object.assign({}, options), { transaction: execution.
|
|
17
|
+
const result = yield repo.destroy(Object.assign(Object.assign({}, options), { transaction: execution.tx }));
|
|
18
18
|
return {
|
|
19
19
|
result,
|
|
20
20
|
status: JOB_STATUS.RESOLVED
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/instructions/destroy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,iCAC5B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/instructions/destroy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,iCAC5B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,UAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.destroy({\n ...options,\n transaction: execution.tx\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -78,7 +78,7 @@ export default {
|
|
|
78
78
|
status: StatusGetters[mode](newResult)
|
|
79
79
|
});
|
|
80
80
|
if (job.status === JOB_STATUS.PENDING) {
|
|
81
|
-
yield job.save({ transaction: execution.
|
|
81
|
+
yield job.save({ transaction: execution.tx });
|
|
82
82
|
return execution.end(this, job);
|
|
83
83
|
}
|
|
84
84
|
return job;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.js","sourceRoot":"","sources":["../../src/instructions/parallel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,MAAM,aAAa,GAAG;IACpB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM;QACxB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC3D,OAAO,UAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC5D,OAAO,UAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IACD,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC;YAC5D,CAAC,CAAC,UAAU,CAAC,QAAQ;YACrB,CAAC,CAAC,CACA,MAAM,CAAC,IAAI,CAAC,CAAC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G,CAAC,MAAM,KAAK,UAAU,CAAC,OAAO,EAAE;gBACrC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC9C,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;aACjC;YAED,OAAO,GAAG,CAAC;QACb,CAAC;KAAA;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport ExecutionModel from \"../models/Execution\";\nimport FlowNodeModel from \"../models/FlowNode\";\nimport JobModel from \"../models/Job\";\n\nexport const PARALLEL_MODE = {\n ALL: 'all',\n ANY: 'any',\n RACE: 'race'\n} as const;\n\nconst StatusGetters = {\n [PARALLEL_MODE.ALL](result) {\n if (result.some(j => j && j.status === JOB_STATUS.REJECTED)) {\n return JOB_STATUS.REJECTED;\n }\n if (result.every(j => j && j.status === JOB_STATUS.RESOLVED)) {\n return JOB_STATUS.RESOLVED;\n }\n return JOB_STATUS.PENDING;\n },\n [PARALLEL_MODE.ANY](result) {\n return result.some(j => j && j.status === JOB_STATUS.RESOLVED)\n ? JOB_STATUS.RESOLVED\n : (\n result.some(j => j && j.status === JOB_STATUS.PENDING)\n ? JOB_STATUS.PENDING\n : JOB_STATUS.REJECTED\n )\n },\n [PARALLEL_MODE.RACE](result) {\n return result.some(j => j && j.status === JOB_STATUS.RESOLVED)\n ? JOB_STATUS.RESOLVED\n : (\n result.some(j => j && j.status === JOB_STATUS.REJECTED)\n ? JOB_STATUS.REJECTED\n : JOB_STATUS.PENDING\n )\n }\n};\n\nexport default {\n async run(this: FlowNodeModel, prevJob: JobModel, execution: ExecutionModel) {\n const branches = execution.nodes\n .filter(item => item.upstream === this && item.branchIndex !== null)\n .sort((a, b) => a.branchIndex - b.branchIndex);\n\n const job = await execution.saveJob({\n status: JOB_STATUS.PENDING,\n result: Array(branches.length).fill(null),\n nodeId: this.id,\n upstreamId: prevJob?.id ?? null\n });\n\n // NOTE:\n // use `reduce` but not `Promise.all` here to avoid racing manupulating db.\n // for users, this is almost equivalent to `Promise.all`,\n // because of the delay is not significant sensible.\n // another better aspect of this is, it could handle sequenced branches in future.\n await branches.reduce((promise: Promise<any>, branch) => promise.then(() => execution.run(branch, job)), Promise.resolve());\n\n return execution.end(this, job);\n },\n\n async resume(this, branchJob, execution: ExecutionModel) {\n const job = execution.findBranchParentJob(branchJob, this);\n\n const { result, status } = job;\n // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.\n if (status !== JOB_STATUS.PENDING) {\n return null;\n }\n\n // find the index of the node which start the branch\n const jobNode = execution.nodesMap.get(branchJob.nodeId);\n const { branchIndex } = execution.findBranchStartNode(jobNode);\n const { mode = PARALLEL_MODE.ALL } = this.config || {};\n\n const newResult = [...result.slice(0, branchIndex), branchJob.get(), ...result.slice(branchIndex + 1)];\n job.set({\n result: newResult,\n status: StatusGetters[mode](newResult)\n });\n\n if (job.status === JOB_STATUS.PENDING) {\n await job.save({ transaction: execution.tx });\n return execution.end(this, job);\n }\n\n return job;\n }\n};\n"]}
|
|
@@ -14,7 +14,11 @@ export default {
|
|
|
14
14
|
const { collection, multiple, params = {} } = this.config;
|
|
15
15
|
const repo = this.constructor.database.getRepository(collection);
|
|
16
16
|
const options = execution.getParsedValue(params);
|
|
17
|
-
const result = yield (multiple ? repo.find : repo.findOne).call(repo, Object.assign(Object.assign({}, options), {
|
|
17
|
+
const result = yield (multiple ? repo.find : repo.findOne).call(repo, Object.assign(Object.assign({}, options), {
|
|
18
|
+
// NOTE: `raw` to avoid getting undefined value from Proxied model instance (#380)
|
|
19
|
+
// e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
|
|
20
|
+
// so the properties can not be get by json-templates(object-path)
|
|
21
|
+
raw: true, transaction: execution.tx }));
|
|
18
22
|
return {
|
|
19
23
|
result,
|
|
20
24
|
status: JOB_STATUS.RESOLVED
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/instructions/query.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,QAAQ,EACR,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,kCAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/instructions/query.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,QAAQ,EACR,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,kCAC/D,OAAO;gBACV,kFAAkF;gBAClF,mEAAmE;gBACnE,kEAAkE;gBAClE,GAAG,EAAE,IAAI,EACT,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,UAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n multiple,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await (multiple ? repo.find : repo.findOne).call(repo, {\n ...options,\n // NOTE: `raw` to avoid getting undefined value from Proxied model instance (#380)\n // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false\n // so the properties can not be get by json-templates(object-path)\n raw: true,\n transaction: execution.tx\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n};\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import ExecutionModel from "../models/Execution";
|
|
1
2
|
import FlowNodeModel from "../models/FlowNode";
|
|
2
3
|
declare const _default: {
|
|
3
|
-
run(this: FlowNodeModel, input: any, execution:
|
|
4
|
+
run(this: FlowNodeModel, input: any, execution: ExecutionModel): Promise<{
|
|
4
5
|
result: import("@nocobase/database").Model<any, any> | import("@nocobase/database").Model<any, any>[];
|
|
5
6
|
status: number;
|
|
6
7
|
}>;
|