@nocobase/plugin-workflow 0.14.0-alpha.6 → 0.14.0-alpha.8
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/AddButton.d.ts +2 -1
- package/dist/client/Branch.d.ts +4 -2
- package/dist/client/constants.d.ts +2 -0
- package/dist/client/hooks/useGetAriaLabelOfAddButton.d.ts +6 -0
- package/dist/client/index.d.ts +8 -2
- package/dist/client/index.js +101 -98
- package/dist/client/nodes/aggregate.d.ts +6 -3
- package/dist/client/nodes/calculation.d.ts +6 -5
- package/dist/client/nodes/create.d.ts +3 -2
- package/dist/client/nodes/index.d.ts +1 -1
- package/dist/client/nodes/manual/SchemaConfig.d.ts +4 -2
- package/dist/client/nodes/manual/index.d.ts +3 -3
- package/dist/client/nodes/query.d.ts +3 -2
- package/dist/client/schemas/collection.d.ts +1 -0
- package/dist/client/triggers/collection.d.ts +1 -0
- package/dist/client/triggers/form.d.ts +2 -0
- package/dist/client/triggers/index.d.ts +4 -0
- package/dist/client/variable.d.ts +2 -0
- package/dist/externalVersion.js +9 -10
- package/dist/locale/zh-CN.d.ts +5 -3
- package/dist/locale/zh-CN.js +5 -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.js +4 -1
- package/dist/server/Processor.d.ts +5 -5
- package/dist/server/Processor.js +20 -10
- package/dist/server/actions/workflows.d.ts +1 -0
- package/dist/server/actions/workflows.js +13 -52
- package/dist/server/collections/flow_nodes.js +4 -0
- package/dist/server/constants.d.ts +2 -0
- package/dist/server/constants.js +4 -2
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +2 -0
- package/dist/server/instructions/index.d.ts +6 -4
- package/dist/server/instructions/manual/actions.js +9 -1
- package/dist/server/instructions/parallel.js +1 -1
- package/dist/server/migrations/20230221162902-jsonb-to-json.js +0 -16
- package/dist/server/migrations/20230809113132-workflow-options.js +5 -2
- package/dist/server/migrations/20231024172342-add-node-key.d.ts +4 -0
- package/dist/server/migrations/20231024172342-add-node-key.js +80 -0
- package/dist/server/triggers/form.d.ts +3 -3
- package/dist/server/triggers/form.js +17 -12
- package/dist/server/triggers/index.d.ts +2 -0
- package/dist/server/triggers/index.js +1 -1
- package/dist/server/triggers/schedule.js +1 -1
- package/dist/server/utils.js +5 -4
- package/package.json +2 -3
package/dist/server/constants.js
CHANGED
|
@@ -30,7 +30,8 @@ const EXECUTION_STATUS = {
|
|
|
30
30
|
ERROR: -2,
|
|
31
31
|
ABORTED: -3,
|
|
32
32
|
CANCELED: -4,
|
|
33
|
-
REJECTED: -5
|
|
33
|
+
REJECTED: -5,
|
|
34
|
+
RETRY_NEEDED: -6
|
|
34
35
|
};
|
|
35
36
|
const JOB_STATUS = {
|
|
36
37
|
PENDING: 0,
|
|
@@ -39,7 +40,8 @@ const JOB_STATUS = {
|
|
|
39
40
|
ERROR: -2,
|
|
40
41
|
ABORTED: -3,
|
|
41
42
|
CANCELED: -4,
|
|
42
|
-
REJECTED: -5
|
|
43
|
+
REJECTED: -5,
|
|
44
|
+
RETRY_NEEDED: -6
|
|
43
45
|
};
|
|
44
46
|
const BRANCH_INDEX = {
|
|
45
47
|
DEFAULT: null,
|
package/dist/server/index.d.ts
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(server_exports, {
|
|
|
33
33
|
default: () => import_Plugin.default
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(server_exports);
|
|
36
|
+
__reExport(server_exports, require("./utils"), module.exports);
|
|
36
37
|
__reExport(server_exports, require("./constants"), module.exports);
|
|
37
38
|
var import_triggers = require("./triggers");
|
|
38
39
|
var import_Processor = __toESM(require("./Processor"));
|
|
@@ -42,6 +43,7 @@ __reExport(server_exports, require("./types"), module.exports);
|
|
|
42
43
|
0 && (module.exports = {
|
|
43
44
|
Processor,
|
|
44
45
|
Trigger,
|
|
46
|
+
...require("./utils"),
|
|
45
47
|
...require("./constants"),
|
|
46
48
|
...require("./types")
|
|
47
49
|
});
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import { Transactionable } from '@nocobase/database';
|
|
1
2
|
import Plugin from '..';
|
|
2
3
|
import Processor from '../Processor';
|
|
3
4
|
import type { FlowNodeModel } from '../types';
|
|
4
|
-
export
|
|
5
|
+
export interface IJob {
|
|
5
6
|
status: number;
|
|
6
7
|
result?: unknown;
|
|
7
8
|
[key: string]: unknown;
|
|
8
|
-
}
|
|
9
|
-
export type InstructionResult =
|
|
9
|
+
}
|
|
10
|
+
export type InstructionResult = IJob | Promise<IJob> | null;
|
|
10
11
|
export type Runner = (node: FlowNodeModel, input: any, processor: Processor) => InstructionResult;
|
|
11
12
|
export interface Instruction {
|
|
12
13
|
run: Runner;
|
|
13
14
|
resume?: Runner;
|
|
14
|
-
getScope?: (node: FlowNodeModel,
|
|
15
|
+
getScope?: (node: FlowNodeModel, data: any, processor: Processor) => any;
|
|
16
|
+
duplicateConfig?: (node: FlowNodeModel, options: Transactionable) => object | Promise<object>;
|
|
15
17
|
}
|
|
16
18
|
type InstructionConstructor<T> = {
|
|
17
19
|
new (p: Plugin): T;
|
|
@@ -58,9 +58,17 @@ async function submit(context, next) {
|
|
|
58
58
|
return context.throw(403);
|
|
59
59
|
}
|
|
60
60
|
const presetValues = processor.getParsedValue(actionItem.values ?? {}, userJob.nodeId, {
|
|
61
|
+
// @deprecated
|
|
61
62
|
currentUser: currentUser.toJSON(),
|
|
63
|
+
// @deprecated
|
|
62
64
|
currentRecord: values.result[formKey],
|
|
63
|
-
|
|
65
|
+
// @deprecated
|
|
66
|
+
currentTime: /* @__PURE__ */ new Date(),
|
|
67
|
+
$user: currentUser.toJSON(),
|
|
68
|
+
$nForm: values.result[formKey],
|
|
69
|
+
$nDate: {
|
|
70
|
+
now: /* @__PURE__ */ new Date()
|
|
71
|
+
}
|
|
64
72
|
});
|
|
65
73
|
userJob.set({
|
|
66
74
|
status: actionItem.status,
|
|
@@ -48,22 +48,6 @@ class jsonb_to_json_default extends import_server.Migration {
|
|
|
48
48
|
},
|
|
49
49
|
{ transaction }
|
|
50
50
|
);
|
|
51
|
-
await queryInterface.changeColumn(
|
|
52
|
-
db.getCollection("executions").model.getTableName(),
|
|
53
|
-
"context",
|
|
54
|
-
{
|
|
55
|
-
type: import_database.DataTypes.JSON
|
|
56
|
-
},
|
|
57
|
-
{ transaction }
|
|
58
|
-
);
|
|
59
|
-
await queryInterface.changeColumn(
|
|
60
|
-
db.getCollection("jobs").model.getTableName(),
|
|
61
|
-
"result",
|
|
62
|
-
{
|
|
63
|
-
type: import_database.DataTypes.JSON
|
|
64
|
-
},
|
|
65
|
-
{ transaction }
|
|
66
|
-
);
|
|
67
51
|
});
|
|
68
52
|
}
|
|
69
53
|
}
|
|
@@ -23,18 +23,21 @@ module.exports = __toCommonJS(workflow_options_exports);
|
|
|
23
23
|
var import_server = require("@nocobase/server");
|
|
24
24
|
class workflow_options_default extends import_server.Migration {
|
|
25
25
|
async up() {
|
|
26
|
-
const match = await this.app.version.satisfies("<0.
|
|
26
|
+
const match = await this.app.version.satisfies("<0.14.0-alpha.8");
|
|
27
27
|
if (!match) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
const { db } = this.context;
|
|
31
|
-
const WorkflowRepo = db.getRepository("
|
|
31
|
+
const WorkflowRepo = db.getRepository("workflows");
|
|
32
32
|
await db.sequelize.transaction(async (transaction) => {
|
|
33
33
|
const workflows = await WorkflowRepo.find({
|
|
34
34
|
transaction
|
|
35
35
|
});
|
|
36
36
|
await workflows.reduce(
|
|
37
37
|
(promise, workflow) => promise.then(() => {
|
|
38
|
+
if (!workflow.useTransaction) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
38
41
|
workflow.set("options", {
|
|
39
42
|
useTransaction: workflow.get("useTransaction")
|
|
40
43
|
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var add_node_key_exports = {};
|
|
19
|
+
__export(add_node_key_exports, {
|
|
20
|
+
default: () => add_node_key_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(add_node_key_exports);
|
|
23
|
+
var import_sequelize = require("sequelize");
|
|
24
|
+
var import_server = require("@nocobase/server");
|
|
25
|
+
var import_utils = require("@nocobase/utils");
|
|
26
|
+
function migrateNodeConfig(config = {}, nodesMap) {
|
|
27
|
+
Object.keys(config).forEach((key) => {
|
|
28
|
+
const valueType = typeof config[key];
|
|
29
|
+
if (valueType === "string") {
|
|
30
|
+
config[key] = config[key].replace(/{{\s*\$jobsMapByNodeId\.(\d+)(\.[^}]+)?\s*}}/g, (matched, id, path) => {
|
|
31
|
+
return `{{$jobsMapByNodeKey.${nodesMap[id].key}${path || ""}}}`;
|
|
32
|
+
}).replace(/{{\s*\$scopes\.(\d+)(\.[^}]+)?\s*}}/g, (matched, id, path) => {
|
|
33
|
+
return `{{$scopes.${nodesMap[id].key}${path || ""}}}`;
|
|
34
|
+
});
|
|
35
|
+
} else if (valueType === "object" && config[key]) {
|
|
36
|
+
migrateNodeConfig(config[key], nodesMap);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return config;
|
|
40
|
+
}
|
|
41
|
+
class add_node_key_default extends import_server.Migration {
|
|
42
|
+
async up() {
|
|
43
|
+
const match = await this.app.version.satisfies("<0.14.0-alpha.8");
|
|
44
|
+
if (!match) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { db } = this.context;
|
|
48
|
+
const NodeCollection = db.getCollection("flow_nodes");
|
|
49
|
+
const NodeRepo = NodeCollection.repository;
|
|
50
|
+
const tableName = NodeCollection.getTableNameWithSchema();
|
|
51
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
52
|
+
if (!await NodeCollection.getField("key").existsInDb()) {
|
|
53
|
+
await this.queryInterface.addColumn(tableName, "key", import_sequelize.DataTypes.STRING, {
|
|
54
|
+
transaction
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const nodes = await NodeRepo.find({
|
|
58
|
+
transaction
|
|
59
|
+
});
|
|
60
|
+
const nodesMap = nodes.reduce((map, node) => {
|
|
61
|
+
map[node.id] = node;
|
|
62
|
+
if (!node.get("key")) {
|
|
63
|
+
node.set("key", (0, import_utils.uid)());
|
|
64
|
+
}
|
|
65
|
+
return map;
|
|
66
|
+
}, {});
|
|
67
|
+
await nodes.reduce(
|
|
68
|
+
(promise, node) => promise.then(() => {
|
|
69
|
+
node.set("config", migrateNodeConfig(node.config, nodesMap));
|
|
70
|
+
node.changed("config", true);
|
|
71
|
+
return node.save({
|
|
72
|
+
silent: true,
|
|
73
|
+
transaction
|
|
74
|
+
});
|
|
75
|
+
}),
|
|
76
|
+
Promise.resolve()
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -3,9 +3,9 @@ import Plugin from '..';
|
|
|
3
3
|
import { WorkflowModel } from '../types';
|
|
4
4
|
export default class FormTrigger extends Trigger {
|
|
5
5
|
constructor(plugin: Plugin);
|
|
6
|
-
triggerAction
|
|
7
|
-
middleware: (context: any, next: any) => Promise<
|
|
8
|
-
trigger
|
|
6
|
+
triggerAction(context: any, next: any): Promise<any>;
|
|
7
|
+
middleware: (context: any, next: any) => Promise<any>;
|
|
8
|
+
private trigger;
|
|
9
9
|
on(workflow: WorkflowModel): void;
|
|
10
10
|
off(workflow: WorkflowModel): void;
|
|
11
11
|
}
|
|
@@ -23,15 +23,13 @@ module.exports = __toCommonJS(form_exports);
|
|
|
23
23
|
var import_lodash = require("lodash");
|
|
24
24
|
var import__ = require(".");
|
|
25
25
|
var import_database = require("@nocobase/database");
|
|
26
|
+
var import_utils = require("../utils");
|
|
26
27
|
class FormTrigger extends import__.Trigger {
|
|
27
28
|
constructor(plugin) {
|
|
28
29
|
super(plugin);
|
|
29
30
|
plugin.app.resourcer.use(this.middleware);
|
|
30
|
-
plugin.app.actions({
|
|
31
|
-
["workflows:trigger"]: this.triggerAction
|
|
32
|
-
});
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
async triggerAction(context, next) {
|
|
35
33
|
const { triggerWorkflows } = context.action.params;
|
|
36
34
|
if (!triggerWorkflows) {
|
|
37
35
|
return context.throw(400);
|
|
@@ -39,20 +37,27 @@ class FormTrigger extends import__.Trigger {
|
|
|
39
37
|
context.status = 202;
|
|
40
38
|
await next();
|
|
41
39
|
this.trigger(context);
|
|
42
|
-
}
|
|
40
|
+
}
|
|
43
41
|
middleware = async (context, next) => {
|
|
42
|
+
const {
|
|
43
|
+
resourceName,
|
|
44
|
+
actionName,
|
|
45
|
+
params: { triggerWorkflows }
|
|
46
|
+
} = context.action;
|
|
47
|
+
if (resourceName === "workflows" && actionName === "trigger") {
|
|
48
|
+
return this.triggerAction(context, next);
|
|
49
|
+
}
|
|
44
50
|
await next();
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
if (!triggerWorkflows) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!["create", "update"].includes(actionName)) {
|
|
47
55
|
return;
|
|
48
56
|
}
|
|
49
57
|
this.trigger(context);
|
|
50
58
|
};
|
|
51
59
|
async trigger(context) {
|
|
52
|
-
const { triggerWorkflows, values } = context.action.params;
|
|
53
|
-
if (!triggerWorkflows) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
60
|
+
const { triggerWorkflows = "", values } = context.action.params;
|
|
56
61
|
const { currentUser } = context.state;
|
|
57
62
|
const triggers = triggerWorkflows.split(",").map((trigger) => trigger.split("!"));
|
|
58
63
|
const workflowRepo = this.plugin.db.getRepository("workflows");
|
|
@@ -93,7 +98,7 @@ class FormTrigger extends import__.Trigger {
|
|
|
93
98
|
appends
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
|
-
this.plugin.trigger(workflow, { data: payload, user: currentUser });
|
|
101
|
+
this.plugin.trigger(workflow, { data: (0, import_utils.toJSON)(payload), user: (0, import_utils.toJSON)(currentUser) });
|
|
97
102
|
});
|
|
98
103
|
} else {
|
|
99
104
|
const data = trigger[1] ? (0, import_lodash.get)(values, trigger[1]) : values;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Transactionable } from '@nocobase/database';
|
|
1
2
|
import Plugin from '..';
|
|
2
3
|
import type { WorkflowModel } from '../types';
|
|
3
4
|
export declare abstract class Trigger {
|
|
@@ -5,6 +6,7 @@ export declare abstract class Trigger {
|
|
|
5
6
|
constructor(plugin: Plugin);
|
|
6
7
|
abstract on(workflow: WorkflowModel): void;
|
|
7
8
|
abstract off(workflow: WorkflowModel): void;
|
|
9
|
+
duplicateConfig?(workflow: WorkflowModel, options: Transactionable): object | Promise<object>;
|
|
8
10
|
}
|
|
9
11
|
export default function <T extends Trigger>(plugin: any, more?: {
|
|
10
12
|
[key: string]: {
|
|
@@ -31,8 +31,8 @@ __export(triggers_exports, {
|
|
|
31
31
|
default: () => triggers_default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(triggers_exports);
|
|
34
|
-
var import_utils = require("@nocobase/utils");
|
|
35
34
|
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@nocobase/utils");
|
|
36
36
|
class Trigger {
|
|
37
37
|
constructor(plugin) {
|
|
38
38
|
this.plugin = plugin;
|
|
@@ -362,7 +362,7 @@ class ScheduleTrigger extends import__.Trigger {
|
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
364
|
init() {
|
|
365
|
-
if (this.plugin.app.name !== "main") {
|
|
365
|
+
if (this.plugin.app.getPlugin("multi-app-share-collection").enabled && this.plugin.app.name !== "main") {
|
|
366
366
|
return;
|
|
367
367
|
}
|
|
368
368
|
if (this.timer) {
|
package/dist/server/utils.js
CHANGED
|
@@ -20,16 +20,17 @@ __export(utils_exports, {
|
|
|
20
20
|
toJSON: () => toJSON
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(utils_exports);
|
|
23
|
+
var import_database = require("@nocobase/database");
|
|
23
24
|
function toJSON(data) {
|
|
24
|
-
if (typeof data !== "object" || !data) {
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
25
|
if (Array.isArray(data)) {
|
|
28
26
|
return data.map(toJSON);
|
|
29
27
|
}
|
|
28
|
+
if (!(data instanceof import_database.Model) || !data) {
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
30
31
|
const result = data.get();
|
|
31
32
|
Object.keys(data.constructor.associations).forEach((key) => {
|
|
32
|
-
if (result[key] != null) {
|
|
33
|
+
if (result[key] != null && typeof result[key] === "object") {
|
|
33
34
|
result[key] = toJSON(result[key]);
|
|
34
35
|
}
|
|
35
36
|
});
|
package/package.json
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
"displayName.zh-CN": "工作流",
|
|
5
5
|
"description": "A powerful workflow plugin designed to support business process management and automation.",
|
|
6
6
|
"description.zh-CN": "工作流插件,为业务流程管理和自动化提供支持。",
|
|
7
|
-
"version": "0.14.0-alpha.
|
|
7
|
+
"version": "0.14.0-alpha.8",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@ant-design/icons": "5.x",
|
|
12
|
-
"@emotion/css": "^11.7.1",
|
|
13
12
|
"@formily/antd-v5": "1.x",
|
|
14
13
|
"@formily/core": "2.x",
|
|
15
14
|
"@formily/react": "2.x",
|
|
@@ -42,5 +41,5 @@
|
|
|
42
41
|
"@nocobase/test": "0.x",
|
|
43
42
|
"@nocobase/utils": "0.x"
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "59c82fef6e34707802b5841f5ec4d9b3b6b68abb"
|
|
46
45
|
}
|