@nocobase/plugin-workflow 2.1.0-alpha.1 → 2.1.0-alpha.11
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/LICENSE +201 -661
- package/README.md +79 -10
- package/dist/client/93d3f3f8ced1c194.js +10 -0
- package/dist/client/AddNodeContext.d.ts +1 -0
- package/dist/client/NodeClipboardContext.d.ts +11 -0
- package/dist/client/NodeDragContext.d.ts +11 -0
- package/dist/client/c46a9a8d11a5be44.js +10 -0
- package/dist/client/cd221313681d6736.js +10 -0
- package/dist/client/e9463c8cd2a45481.js +10 -0
- package/dist/client/hooks/{useWorkflowFilterActionProps.d.ts → useResourceFilterActionProps.d.ts} +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +1 -1
- package/dist/client/models/NodeDetailsGridModel.d.ts +13 -0
- package/dist/client/models/NodeDetailsModel.d.ts +34 -0
- package/dist/client/models/NodeValueModel.d.ts +15 -0
- package/dist/client/models/TaskCardCommonItemModel.d.ts +14 -0
- package/dist/client/models/index.d.ts +11 -0
- package/dist/client/nodeVariableUtils.d.ts +14 -0
- package/dist/client/nodes/calculation.d.ts +7 -0
- package/dist/client/nodes/create.d.ts +23 -0
- package/dist/client/nodes/destroy.d.ts +10 -0
- package/dist/client/nodes/index.d.ts +24 -0
- package/dist/client/nodes/output.d.ts +53 -0
- package/dist/client/nodes/query.d.ts +23 -0
- package/dist/client/nodes/update.d.ts +11 -0
- package/dist/client/schemas/executions.d.ts +41 -22
- package/dist/client/style.d.ts +4 -0
- package/dist/client/triggers/collection.d.ts +27 -1
- package/dist/client/triggers/index.d.ts +14 -0
- package/dist/client/triggers/schedule/constants.d.ts +4 -0
- package/dist/client/triggers/schedule/index.d.ts +28 -0
- package/dist/common/collections/executions.d.ts +22 -22
- package/dist/common/collections/executions.js +12 -0
- package/dist/common/collections/jobs.js +4 -0
- package/dist/common/collections/workflows.d.ts +22 -9
- package/dist/common/collections/workflows.js +9 -1
- package/dist/externalVersion.js +12 -12
- package/dist/locale/de-DE.json +10 -3
- package/dist/locale/en-US.json +22 -3
- package/dist/locale/es-ES.json +10 -3
- package/dist/locale/fr-FR.json +10 -3
- package/dist/locale/hu-HU.json +10 -2
- package/dist/locale/id-ID.json +10 -2
- package/dist/locale/it-IT.json +10 -3
- package/dist/locale/ja-JP.json +10 -5
- package/dist/locale/ko-KR.json +10 -3
- package/dist/locale/nl-NL.json +10 -3
- package/dist/locale/pt-BR.json +10 -3
- package/dist/locale/ru-RU.json +10 -3
- package/dist/locale/tr-TR.json +10 -3
- package/dist/locale/uk-UA.json +10 -3
- package/dist/locale/vi-VN.json +10 -2
- package/dist/locale/zh-CN.json +28 -5
- package/dist/locale/zh-TW.json +10 -3
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +178 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1067 -0
- package/dist/node_modules/joi/lib/types/link.js +168 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/server/Dispatcher.d.ts +3 -2
- package/dist/server/Dispatcher.js +76 -62
- package/dist/server/Plugin.d.ts +1 -0
- package/dist/server/Plugin.js +32 -1
- package/dist/server/Processor.d.ts +9 -0
- package/dist/server/Processor.js +6 -1
- package/dist/server/actions/index.js +2 -0
- package/dist/server/actions/nodes.d.ts +7 -0
- package/dist/server/actions/nodes.js +315 -4
- package/dist/server/actions/workflows.d.ts +6 -0
- package/dist/server/actions/workflows.js +38 -0
- package/dist/server/instructions/ConditionInstruction.js +4 -1
- package/dist/server/instructions/CreateInstruction.d.ts +3 -0
- package/dist/server/instructions/CreateInstruction.js +21 -0
- package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
- package/dist/server/instructions/DestroyInstruction.js +22 -0
- package/dist/server/instructions/EndInstruction.d.ts +2 -0
- package/dist/server/instructions/EndInstruction.js +4 -0
- package/dist/server/instructions/OutputInstruction.d.ts +21 -0
- package/dist/server/instructions/OutputInstruction.js +54 -0
- package/dist/server/instructions/QueryInstruction.d.ts +3 -0
- package/dist/server/instructions/QueryInstruction.js +21 -0
- package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
- package/dist/server/instructions/UpdateInstruction.js +22 -0
- package/dist/server/instructions/index.d.ts +4 -0
- package/dist/server/instructions/index.js +18 -0
- package/dist/server/repositories/WorkflowRepository.js +2 -1
- package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
- package/dist/server/triggers/CollectionTrigger.js +23 -0
- package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
- package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
- package/dist/server/triggers/index.d.ts +3 -0
- package/dist/server/triggers/index.js +18 -0
- package/dist/server/utils.d.ts +2 -0
- package/dist/server/utils.js +22 -2
- package/dist/swagger/index.d.ts +814 -62
- package/dist/swagger/index.js +975 -205
- package/package.json +4 -3
- package/dist/client/27bd65abee87cafa.js +0 -10
- package/dist/client/80d4cd8911e03c27.js +0 -10
- package/dist/client/bfc2a351589613e1.js +0 -10
- package/dist/client/e078314a62391f36.js +0 -10
|
@@ -36,9 +36,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var nodes_exports = {};
|
|
38
38
|
__export(nodes_exports, {
|
|
39
|
+
NodeValidationError: () => NodeValidationError,
|
|
39
40
|
create: () => create,
|
|
40
41
|
destroy: () => destroy,
|
|
41
42
|
destroyBranch: () => destroyBranch,
|
|
43
|
+
duplicate: () => duplicate,
|
|
44
|
+
move: () => move,
|
|
42
45
|
test: () => test,
|
|
43
46
|
update: () => update
|
|
44
47
|
});
|
|
@@ -46,19 +49,44 @@ module.exports = __toCommonJS(nodes_exports);
|
|
|
46
49
|
var import_actions = require("@nocobase/actions");
|
|
47
50
|
var import_database = require("@nocobase/database");
|
|
48
51
|
var import__ = __toESM(require(".."));
|
|
52
|
+
class NodeValidationError extends Error {
|
|
53
|
+
status = 400;
|
|
54
|
+
errors;
|
|
55
|
+
constructor(errors) {
|
|
56
|
+
super("Node validation failed");
|
|
57
|
+
this.name = "NodeValidationError";
|
|
58
|
+
this.errors = errors;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function validateNode(context, plugin, { type, config }) {
|
|
62
|
+
if (!type) {
|
|
63
|
+
context.throw(400, "Node type is required");
|
|
64
|
+
}
|
|
65
|
+
const instruction = plugin.instructions.get(type);
|
|
66
|
+
if (!instruction) {
|
|
67
|
+
context.throw(400, `Node type "${type}" is not registered`);
|
|
68
|
+
}
|
|
69
|
+
if (config && typeof instruction.validateConfig === "function") {
|
|
70
|
+
const errors = instruction.validateConfig(config);
|
|
71
|
+
if (errors) {
|
|
72
|
+
throw new NodeValidationError(errors);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
49
76
|
async function create(context, next) {
|
|
50
77
|
const { db } = context;
|
|
51
78
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
52
|
-
const { whitelist, blacklist, updateAssociationValues, values
|
|
79
|
+
const { whitelist, blacklist, updateAssociationValues, values } = context.action.params;
|
|
53
80
|
const workflowPlugin = context.app.pm.get(import__.default);
|
|
54
81
|
context.body = await db.sequelize.transaction(async (transaction) => {
|
|
55
|
-
const workflow = workflowPlugin.enabledCache.get(Number.parseInt(
|
|
82
|
+
const workflow = workflowPlugin.enabledCache.get(Number.parseInt(context.action.sourceId, 10)) || await repository.getSourceModel(transaction);
|
|
56
83
|
if (!workflow.versionStats) {
|
|
57
84
|
workflow.versionStats = await workflow.getVersionStats({ transaction });
|
|
58
85
|
}
|
|
59
86
|
if (workflow.versionStats.executed > 0) {
|
|
60
87
|
context.throw(400, "Node could not be created in executed workflow");
|
|
61
88
|
}
|
|
89
|
+
validateNode(context, workflowPlugin, values);
|
|
62
90
|
const NODES_LIMIT = process.env.WORKFLOW_NODES_LIMIT ? parseInt(process.env.WORKFLOW_NODES_LIMIT, 10) : null;
|
|
63
91
|
if (NODES_LIMIT) {
|
|
64
92
|
const nodesCount = await workflow.countNodes({ transaction });
|
|
@@ -133,6 +161,117 @@ async function create(context, next) {
|
|
|
133
161
|
});
|
|
134
162
|
await next();
|
|
135
163
|
}
|
|
164
|
+
async function duplicate(context, next) {
|
|
165
|
+
const { db } = context;
|
|
166
|
+
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
167
|
+
const { whitelist, blacklist, filterByTk, values = {} } = context.action.params;
|
|
168
|
+
const workflowPlugin = context.app.pm.get(import__.default);
|
|
169
|
+
context.body = await db.sequelize.transaction(async (transaction) => {
|
|
170
|
+
const origin = filterByTk ? await repository.findOne({ filterByTk, transaction }) : null;
|
|
171
|
+
if (!origin) {
|
|
172
|
+
return context.throw(404, "Node not found");
|
|
173
|
+
}
|
|
174
|
+
const workflow = workflowPlugin.enabledCache.get(origin.workflowId) || await db.getRepository("workflows").findOne({
|
|
175
|
+
filterByTk: origin.workflowId,
|
|
176
|
+
transaction
|
|
177
|
+
});
|
|
178
|
+
if (!workflow) {
|
|
179
|
+
return context.throw(400, "Workflow not found");
|
|
180
|
+
}
|
|
181
|
+
if (!workflow.versionStats) {
|
|
182
|
+
workflow.versionStats = await workflow.getVersionStats({ transaction });
|
|
183
|
+
}
|
|
184
|
+
if (workflow.versionStats.executed > 0) {
|
|
185
|
+
context.throw(400, "Node could not be created in executed workflow");
|
|
186
|
+
}
|
|
187
|
+
const NODES_LIMIT = process.env.WORKFLOW_NODES_LIMIT ? parseInt(process.env.WORKFLOW_NODES_LIMIT, 10) : null;
|
|
188
|
+
if (NODES_LIMIT) {
|
|
189
|
+
const nodesCount = await workflow.countNodes({ transaction });
|
|
190
|
+
if (nodesCount >= NODES_LIMIT) {
|
|
191
|
+
context.throw(400, `The number of nodes in a workflow cannot exceed ${NODES_LIMIT}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
let nextConfig = values.config;
|
|
195
|
+
if (!nextConfig) {
|
|
196
|
+
const instruction = workflowPlugin.instructions.get(origin.type);
|
|
197
|
+
if (instruction && typeof instruction.duplicateConfig === "function") {
|
|
198
|
+
nextConfig = await instruction.duplicateConfig(origin, { origin: origin ?? void 0, transaction });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const instance = await repository.create({
|
|
202
|
+
values: {
|
|
203
|
+
config: nextConfig ?? origin.config,
|
|
204
|
+
upstreamId: values.upstreamId,
|
|
205
|
+
branchIndex: values.branchIndex,
|
|
206
|
+
type: origin.type,
|
|
207
|
+
title: origin.title,
|
|
208
|
+
workflowId: origin.workflowId
|
|
209
|
+
},
|
|
210
|
+
whitelist,
|
|
211
|
+
blacklist,
|
|
212
|
+
context,
|
|
213
|
+
transaction
|
|
214
|
+
});
|
|
215
|
+
if (!instance.upstreamId) {
|
|
216
|
+
const previousHead = await repository.findOne({
|
|
217
|
+
filter: {
|
|
218
|
+
id: {
|
|
219
|
+
$ne: instance.id
|
|
220
|
+
},
|
|
221
|
+
workflowId: origin.workflowId,
|
|
222
|
+
upstreamId: null
|
|
223
|
+
},
|
|
224
|
+
transaction
|
|
225
|
+
});
|
|
226
|
+
if (previousHead) {
|
|
227
|
+
await previousHead.setUpstream(instance, { transaction });
|
|
228
|
+
await instance.setDownstream(previousHead, { transaction });
|
|
229
|
+
instance.set("downstream", previousHead);
|
|
230
|
+
}
|
|
231
|
+
return instance;
|
|
232
|
+
}
|
|
233
|
+
const upstream = await instance.getUpstream({ transaction });
|
|
234
|
+
if (instance.branchIndex == null) {
|
|
235
|
+
const downstream = await upstream.getDownstream({ transaction });
|
|
236
|
+
if (downstream) {
|
|
237
|
+
await downstream.setUpstream(instance, { transaction });
|
|
238
|
+
await instance.setDownstream(downstream, { transaction });
|
|
239
|
+
instance.set("downstream", downstream);
|
|
240
|
+
}
|
|
241
|
+
await upstream.update(
|
|
242
|
+
{
|
|
243
|
+
downstreamId: instance.id
|
|
244
|
+
},
|
|
245
|
+
{ transaction }
|
|
246
|
+
);
|
|
247
|
+
upstream.set("downstream", instance);
|
|
248
|
+
} else {
|
|
249
|
+
const [downstream] = await upstream.getBranches({
|
|
250
|
+
where: {
|
|
251
|
+
id: {
|
|
252
|
+
[import_database.Op.ne]: instance.id
|
|
253
|
+
},
|
|
254
|
+
branchIndex: instance.branchIndex
|
|
255
|
+
},
|
|
256
|
+
transaction
|
|
257
|
+
});
|
|
258
|
+
if (downstream) {
|
|
259
|
+
await downstream.update(
|
|
260
|
+
{
|
|
261
|
+
upstreamId: instance.id,
|
|
262
|
+
branchIndex: null
|
|
263
|
+
},
|
|
264
|
+
{ transaction }
|
|
265
|
+
);
|
|
266
|
+
await instance.setDownstream(downstream, { transaction });
|
|
267
|
+
instance.set("downstream", downstream);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
instance.set("upstream", upstream);
|
|
271
|
+
return instance;
|
|
272
|
+
});
|
|
273
|
+
await next();
|
|
274
|
+
}
|
|
136
275
|
function searchBranchNodes(nodes, from) {
|
|
137
276
|
const branchHeads = nodes.filter((item) => item.upstreamId === from.id && item.branchIndex != null);
|
|
138
277
|
return branchHeads.reduce(
|
|
@@ -336,19 +475,187 @@ async function destroyBranch(context, next) {
|
|
|
336
475
|
context.body = deletedBranchHead;
|
|
337
476
|
await next();
|
|
338
477
|
}
|
|
478
|
+
async function move(context, next) {
|
|
479
|
+
const { db } = context;
|
|
480
|
+
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
481
|
+
const { filterByTk, values = {} } = context.action.params;
|
|
482
|
+
const rawUpstreamId = values.upstreamId;
|
|
483
|
+
const rawBranchIndex = values.branchIndex;
|
|
484
|
+
const upstreamId = rawUpstreamId == null || rawUpstreamId === "" ? null : rawUpstreamId;
|
|
485
|
+
let branchIndex = rawBranchIndex == null || rawBranchIndex === "" ? null : Number.parseInt(rawBranchIndex, 10);
|
|
486
|
+
if (rawBranchIndex != null && rawBranchIndex !== "" && Number.isNaN(branchIndex)) {
|
|
487
|
+
context.throw(400, "branchIndex must be a number");
|
|
488
|
+
}
|
|
489
|
+
if (upstreamId == null) {
|
|
490
|
+
branchIndex = null;
|
|
491
|
+
}
|
|
492
|
+
const fields = ["id", "key", "upstreamId", "downstreamId", "branchIndex", "workflowId"];
|
|
493
|
+
context.body = await db.sequelize.transaction(async (transaction) => {
|
|
494
|
+
const instance = await repository.findOne({
|
|
495
|
+
filterByTk,
|
|
496
|
+
fields,
|
|
497
|
+
appends: ["upstream", "downstream", "workflow.versionStats"],
|
|
498
|
+
transaction
|
|
499
|
+
});
|
|
500
|
+
if (!instance) {
|
|
501
|
+
context.throw(404, "Node not found");
|
|
502
|
+
}
|
|
503
|
+
if (instance.workflow.versionStats.executed > 0) {
|
|
504
|
+
context.throw(400, "Nodes in executed workflow could not be moved");
|
|
505
|
+
}
|
|
506
|
+
if (upstreamId != null && String(upstreamId) === String(instance.id)) {
|
|
507
|
+
context.throw(400, "Invalid upstream node");
|
|
508
|
+
}
|
|
509
|
+
const sameUpstream = (instance.upstreamId ?? null) == (upstreamId ?? null);
|
|
510
|
+
const sameBranchIndex = (instance.branchIndex ?? null) == (branchIndex ?? null);
|
|
511
|
+
if (sameUpstream && sameBranchIndex) {
|
|
512
|
+
context.throw(400, "Node does not need to be moved");
|
|
513
|
+
}
|
|
514
|
+
const { upstream: oldUpstream, downstream: oldDownstream } = instance.get();
|
|
515
|
+
if (oldUpstream && oldUpstream.downstreamId === instance.id) {
|
|
516
|
+
await oldUpstream.update(
|
|
517
|
+
{
|
|
518
|
+
downstreamId: oldDownstream ? oldDownstream.id : null
|
|
519
|
+
},
|
|
520
|
+
{ transaction }
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
if (oldDownstream && oldDownstream.upstreamId === instance.id) {
|
|
524
|
+
await oldDownstream.update(
|
|
525
|
+
{
|
|
526
|
+
upstreamId: oldUpstream ? oldUpstream.id : null,
|
|
527
|
+
branchIndex: instance.branchIndex ?? null
|
|
528
|
+
},
|
|
529
|
+
{ transaction }
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
let targetUpstream = null;
|
|
533
|
+
if (upstreamId != null) {
|
|
534
|
+
targetUpstream = await repository.findOne({
|
|
535
|
+
filterByTk: upstreamId,
|
|
536
|
+
fields,
|
|
537
|
+
transaction
|
|
538
|
+
});
|
|
539
|
+
if (!targetUpstream) {
|
|
540
|
+
context.throw(404, "Upstream node not found");
|
|
541
|
+
}
|
|
542
|
+
if (targetUpstream.workflowId !== instance.workflowId) {
|
|
543
|
+
context.throw(400, "Upstream node is not in the same workflow");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
let newDownstream = null;
|
|
547
|
+
if (!targetUpstream) {
|
|
548
|
+
const previousHead = await repository.findOne({
|
|
549
|
+
filter: {
|
|
550
|
+
workflowId: instance.workflowId,
|
|
551
|
+
upstreamId: null,
|
|
552
|
+
id: {
|
|
553
|
+
[import_database.Op.ne]: instance.id
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
fields,
|
|
557
|
+
transaction
|
|
558
|
+
});
|
|
559
|
+
if (previousHead) {
|
|
560
|
+
await previousHead.update(
|
|
561
|
+
{
|
|
562
|
+
upstreamId: instance.id,
|
|
563
|
+
branchIndex: null
|
|
564
|
+
},
|
|
565
|
+
{ transaction }
|
|
566
|
+
);
|
|
567
|
+
newDownstream = previousHead;
|
|
568
|
+
}
|
|
569
|
+
await instance.update(
|
|
570
|
+
{
|
|
571
|
+
upstreamId: null,
|
|
572
|
+
branchIndex: null,
|
|
573
|
+
downstreamId: newDownstream ? newDownstream.id : null
|
|
574
|
+
},
|
|
575
|
+
{ transaction }
|
|
576
|
+
);
|
|
577
|
+
return instance;
|
|
578
|
+
}
|
|
579
|
+
if (branchIndex == null) {
|
|
580
|
+
if (targetUpstream.downstreamId) {
|
|
581
|
+
newDownstream = await repository.findOne({
|
|
582
|
+
filterByTk: targetUpstream.downstreamId,
|
|
583
|
+
fields,
|
|
584
|
+
transaction
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
if (newDownstream) {
|
|
588
|
+
await newDownstream.update(
|
|
589
|
+
{
|
|
590
|
+
upstreamId: instance.id,
|
|
591
|
+
branchIndex: null
|
|
592
|
+
},
|
|
593
|
+
{ transaction }
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
await targetUpstream.update(
|
|
597
|
+
{
|
|
598
|
+
downstreamId: instance.id
|
|
599
|
+
},
|
|
600
|
+
{ transaction }
|
|
601
|
+
);
|
|
602
|
+
await instance.update(
|
|
603
|
+
{
|
|
604
|
+
upstreamId: targetUpstream.id,
|
|
605
|
+
branchIndex: null,
|
|
606
|
+
downstreamId: newDownstream ? newDownstream.id : null
|
|
607
|
+
},
|
|
608
|
+
{ transaction }
|
|
609
|
+
);
|
|
610
|
+
return instance;
|
|
611
|
+
}
|
|
612
|
+
const branchHead = await repository.findOne({
|
|
613
|
+
filter: {
|
|
614
|
+
upstreamId: targetUpstream.id,
|
|
615
|
+
branchIndex
|
|
616
|
+
},
|
|
617
|
+
fields,
|
|
618
|
+
transaction
|
|
619
|
+
});
|
|
620
|
+
if (branchHead) {
|
|
621
|
+
await branchHead.update(
|
|
622
|
+
{
|
|
623
|
+
upstreamId: instance.id,
|
|
624
|
+
branchIndex: null
|
|
625
|
+
},
|
|
626
|
+
{ transaction }
|
|
627
|
+
);
|
|
628
|
+
newDownstream = branchHead;
|
|
629
|
+
}
|
|
630
|
+
await instance.update(
|
|
631
|
+
{
|
|
632
|
+
upstreamId: targetUpstream.id,
|
|
633
|
+
branchIndex,
|
|
634
|
+
downstreamId: newDownstream ? newDownstream.id : null
|
|
635
|
+
},
|
|
636
|
+
{ transaction }
|
|
637
|
+
);
|
|
638
|
+
return instance;
|
|
639
|
+
});
|
|
640
|
+
await next();
|
|
641
|
+
}
|
|
339
642
|
async function update(context, next) {
|
|
340
643
|
const { db } = context;
|
|
341
644
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
342
645
|
const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;
|
|
646
|
+
const workflowPlugin = context.app.pm.get(import__.default);
|
|
343
647
|
context.body = await db.sequelize.transaction(async (transaction) => {
|
|
344
|
-
const
|
|
648
|
+
const instance = await repository.findOne({
|
|
345
649
|
filterByTk,
|
|
346
650
|
appends: ["workflow.versionStats.executed"],
|
|
347
651
|
transaction
|
|
348
652
|
});
|
|
349
|
-
if (workflow.versionStats.executed > 0) {
|
|
653
|
+
if (instance.workflow.versionStats.executed > 0) {
|
|
350
654
|
context.throw(400, "Nodes in executed workflow could not be reconfigured");
|
|
351
655
|
}
|
|
656
|
+
const type = values.type ?? instance.type;
|
|
657
|
+
const config = values.config ?? instance.config;
|
|
658
|
+
validateNode(context, workflowPlugin, { type, config });
|
|
352
659
|
return repository.update({
|
|
353
660
|
filterByTk,
|
|
354
661
|
values,
|
|
@@ -373,6 +680,7 @@ async function test(context, next) {
|
|
|
373
680
|
if (typeof instruction.test !== "function") {
|
|
374
681
|
context.throw(400, `test method of instruction "${type}" not implemented`);
|
|
375
682
|
}
|
|
683
|
+
validateNode(context, plugin, { type, config });
|
|
376
684
|
try {
|
|
377
685
|
context.body = await instruction.test(config);
|
|
378
686
|
} catch (error) {
|
|
@@ -382,9 +690,12 @@ async function test(context, next) {
|
|
|
382
690
|
}
|
|
383
691
|
// Annotate the CommonJS export names for ESM import in node:
|
|
384
692
|
0 && (module.exports = {
|
|
693
|
+
NodeValidationError,
|
|
385
694
|
create,
|
|
386
695
|
destroy,
|
|
387
696
|
destroyBranch,
|
|
697
|
+
duplicate,
|
|
698
|
+
move,
|
|
388
699
|
test,
|
|
389
700
|
update
|
|
390
701
|
});
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Context } from '@nocobase/actions';
|
|
10
|
+
export declare class WorkflowValidationError extends Error {
|
|
11
|
+
status: number;
|
|
12
|
+
errors: Record<string, string>;
|
|
13
|
+
constructor(errors: Record<string, string>);
|
|
14
|
+
}
|
|
15
|
+
export declare function create(context: Context, next: any): Promise<void>;
|
|
10
16
|
export declare function update(context: Context, next: any): Promise<void>;
|
|
11
17
|
export declare function destroy(context: Context, next: any): Promise<void>;
|
|
12
18
|
export declare function revision(context: Context, next: any): Promise<void>;
|
|
@@ -36,6 +36,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var workflows_exports = {};
|
|
38
38
|
__export(workflows_exports, {
|
|
39
|
+
WorkflowValidationError: () => WorkflowValidationError,
|
|
40
|
+
create: () => create,
|
|
39
41
|
destroy: () => destroy,
|
|
40
42
|
execute: () => execute,
|
|
41
43
|
revision: () => revision,
|
|
@@ -46,7 +48,38 @@ module.exports = __toCommonJS(workflows_exports);
|
|
|
46
48
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
47
49
|
var import_database = require("@nocobase/database");
|
|
48
50
|
var import_Plugin = __toESM(require("../Plugin"));
|
|
51
|
+
class WorkflowValidationError extends Error {
|
|
52
|
+
status = 400;
|
|
53
|
+
errors;
|
|
54
|
+
constructor(errors) {
|
|
55
|
+
super("Workflow validation failed");
|
|
56
|
+
this.name = "WorkflowValidationError";
|
|
57
|
+
this.errors = errors;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function validateWorkflow(context, plugin, { type, config }) {
|
|
61
|
+
if (!type) {
|
|
62
|
+
context.throw(400, "Trigger type is required");
|
|
63
|
+
}
|
|
64
|
+
const trigger = plugin.triggers.get(type);
|
|
65
|
+
if (!trigger) {
|
|
66
|
+
context.throw(400, `Trigger type "${type}" is not registered`);
|
|
67
|
+
}
|
|
68
|
+
if (config && typeof trigger.validateConfig === "function") {
|
|
69
|
+
const errors = trigger.validateConfig(config);
|
|
70
|
+
if (errors) {
|
|
71
|
+
throw new WorkflowValidationError(errors);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function create(context, next) {
|
|
76
|
+
const plugin = context.app.pm.get(import_Plugin.default);
|
|
77
|
+
const { values } = context.action.params;
|
|
78
|
+
validateWorkflow(context, plugin, values);
|
|
79
|
+
return import_actions.default.create(context, next);
|
|
80
|
+
}
|
|
49
81
|
async function update(context, next) {
|
|
82
|
+
const plugin = context.app.pm.get(import_Plugin.default);
|
|
50
83
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
51
84
|
const { filterByTk, values } = context.action.params;
|
|
52
85
|
context.action.mergeParams({
|
|
@@ -60,6 +93,9 @@ async function update(context, next) {
|
|
|
60
93
|
if (workflow.versionStats.executed > 0) {
|
|
61
94
|
return context.throw(400, "config of executed workflow can not be updated");
|
|
62
95
|
}
|
|
96
|
+
const type = values.type ?? workflow.type;
|
|
97
|
+
const config = values.config ?? workflow.config;
|
|
98
|
+
validateWorkflow(context, plugin, { type, config });
|
|
63
99
|
}
|
|
64
100
|
return import_actions.default.update(context, next);
|
|
65
101
|
}
|
|
@@ -180,6 +216,8 @@ async function execute(context, next) {
|
|
|
180
216
|
}
|
|
181
217
|
// Annotate the CommonJS export names for ESM import in node:
|
|
182
218
|
0 && (module.exports = {
|
|
219
|
+
WorkflowValidationError,
|
|
220
|
+
create,
|
|
183
221
|
destroy,
|
|
184
222
|
execute,
|
|
185
223
|
revision,
|
|
@@ -81,7 +81,10 @@ class ConditionInstruction extends import__.Instruction {
|
|
|
81
81
|
if (branchJob.status === import_constants.JOB_STATUS.RESOLVED) {
|
|
82
82
|
return job;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
if (branchJob.status === import_constants.JOB_STATUS.PENDING) {
|
|
85
|
+
return processor.exit(branchJob.status);
|
|
86
|
+
}
|
|
87
|
+
return branchJob;
|
|
85
88
|
}
|
|
86
89
|
async test({ engine, calculation, expression = "" }) {
|
|
87
90
|
const evaluator = import_evaluators.evaluators.get(engine);
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import Joi from 'joi';
|
|
9
10
|
import type Processor from '../Processor';
|
|
10
11
|
import type { FlowNodeModel } from '../types';
|
|
11
12
|
import { Instruction } from '.';
|
|
12
13
|
export declare class CreateInstruction extends Instruction {
|
|
14
|
+
configSchema: Joi.ObjectSchema<any>;
|
|
15
|
+
validateConfig(config: Record<string, any>): Record<string, string>;
|
|
13
16
|
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
14
17
|
result: any;
|
|
15
18
|
status: 1;
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
27
|
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var CreateInstruction_exports = {};
|
|
28
38
|
__export(CreateInstruction_exports, {
|
|
@@ -30,11 +40,22 @@ __export(CreateInstruction_exports, {
|
|
|
30
40
|
default: () => CreateInstruction_default
|
|
31
41
|
});
|
|
32
42
|
module.exports = __toCommonJS(CreateInstruction_exports);
|
|
43
|
+
var import_joi = __toESM(require("joi"));
|
|
33
44
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
34
45
|
var import_constants = require("../constants");
|
|
35
46
|
var import_utils = require("../utils");
|
|
36
47
|
var import__ = require(".");
|
|
37
48
|
class CreateInstruction extends import__.Instruction {
|
|
49
|
+
configSchema = import_joi.default.object({
|
|
50
|
+
collection: import_joi.default.string().required().messages({ "any.required": "Collection is not configured" })
|
|
51
|
+
});
|
|
52
|
+
validateConfig(config) {
|
|
53
|
+
const errors = super.validateConfig(config);
|
|
54
|
+
if (errors) {
|
|
55
|
+
return errors;
|
|
56
|
+
}
|
|
57
|
+
return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
|
|
58
|
+
}
|
|
38
59
|
async run(node, input, processor) {
|
|
39
60
|
const { collection, params: { appends = [], ...params } = {} } = node.config;
|
|
40
61
|
const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import Joi from 'joi';
|
|
9
10
|
import { Instruction } from '.';
|
|
10
11
|
import type Processor from '../Processor';
|
|
11
12
|
import type { FlowNodeModel } from '../types';
|
|
12
13
|
export declare class DestroyInstruction extends Instruction {
|
|
14
|
+
configSchema: Joi.ObjectSchema<any>;
|
|
15
|
+
validateConfig(config: Record<string, any>): Record<string, string>;
|
|
13
16
|
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
14
17
|
result: any;
|
|
15
18
|
status: 1;
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
27
|
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var DestroyInstruction_exports = {};
|
|
28
38
|
__export(DestroyInstruction_exports, {
|
|
@@ -30,10 +40,22 @@ __export(DestroyInstruction_exports, {
|
|
|
30
40
|
default: () => DestroyInstruction_default
|
|
31
41
|
});
|
|
32
42
|
module.exports = __toCommonJS(DestroyInstruction_exports);
|
|
43
|
+
var import_joi = __toESM(require("joi"));
|
|
33
44
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
34
45
|
var import__ = require(".");
|
|
35
46
|
var import_constants = require("../constants");
|
|
47
|
+
var import_utils = require("../utils");
|
|
36
48
|
class DestroyInstruction extends import__.Instruction {
|
|
49
|
+
configSchema = import_joi.default.object({
|
|
50
|
+
collection: import_joi.default.string().required().messages({ "any.required": "Collection is not configured" })
|
|
51
|
+
});
|
|
52
|
+
validateConfig(config) {
|
|
53
|
+
const errors = super.validateConfig(config);
|
|
54
|
+
if (errors) {
|
|
55
|
+
return errors;
|
|
56
|
+
}
|
|
57
|
+
return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
|
|
58
|
+
}
|
|
37
59
|
async run(node, input, processor) {
|
|
38
60
|
const { collection, params = {} } = node.config;
|
|
39
61
|
const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import Joi from 'joi';
|
|
9
10
|
import Instruction from '.';
|
|
10
11
|
import Processor from '../Processor';
|
|
11
12
|
import { FlowNodeModel } from '../types';
|
|
12
13
|
export default class extends Instruction {
|
|
14
|
+
configSchema: Joi.ObjectSchema<any>;
|
|
13
15
|
run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<any>;
|
|
14
16
|
}
|
|
@@ -39,9 +39,13 @@ __export(EndInstruction_exports, {
|
|
|
39
39
|
default: () => EndInstruction_default
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(EndInstruction_exports);
|
|
42
|
+
var import_joi = __toESM(require("joi"));
|
|
42
43
|
var import__ = __toESM(require("."));
|
|
43
44
|
var import_constants = require("../constants");
|
|
44
45
|
class EndInstruction_default extends import__.default {
|
|
46
|
+
configSchema = import_joi.default.object({
|
|
47
|
+
endStatus: import_joi.default.number().valid(import_constants.JOB_STATUS.RESOLVED, import_constants.JOB_STATUS.FAILED)
|
|
48
|
+
});
|
|
45
49
|
async run(node, prevJob, processor) {
|
|
46
50
|
const { endStatus = import_constants.JOB_STATUS.RESOLVED } = node.config;
|
|
47
51
|
processor.saveJob({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Instruction } from '.';
|
|
10
|
+
import Processor from '../Processor';
|
|
11
|
+
import { FlowNodeModel } from '../types';
|
|
12
|
+
export default class ExecutionResultInstruction extends Instruction {
|
|
13
|
+
run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
|
|
14
|
+
result: any;
|
|
15
|
+
status: -1;
|
|
16
|
+
} | {
|
|
17
|
+
result: any;
|
|
18
|
+
status: 1;
|
|
19
|
+
}>;
|
|
20
|
+
resume(node: FlowNodeModel, job: any, processor: Processor): Promise<any>;
|
|
21
|
+
}
|