@nocobase/plugin-workflow-loop 1.9.0-beta.8 → 1.9.0
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/.env.example
ADDED
package/dist/externalVersion.js
CHANGED
|
@@ -13,9 +13,9 @@ module.exports = {
|
|
|
13
13
|
"antd": "5.24.2",
|
|
14
14
|
"@formily/antd-v5": "1.2.3",
|
|
15
15
|
"@formily/react": "2.3.0",
|
|
16
|
-
"@nocobase/client": "1.9.0
|
|
17
|
-
"@nocobase/plugin-workflow": "1.9.0
|
|
16
|
+
"@nocobase/client": "1.9.0",
|
|
17
|
+
"@nocobase/plugin-workflow": "1.9.0",
|
|
18
18
|
"react-i18next": "11.18.6",
|
|
19
|
-
"@nocobase/evaluators": "1.9.0
|
|
20
|
-
"@nocobase/server": "1.9.0
|
|
19
|
+
"@nocobase/evaluators": "1.9.0",
|
|
20
|
+
"@nocobase/server": "1.9.0"
|
|
21
21
|
};
|
|
@@ -42,6 +42,10 @@ module.exports = __toCommonJS(LoopInstruction_exports);
|
|
|
42
42
|
var import_evaluators = __toESM(require("@nocobase/evaluators"));
|
|
43
43
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
44
44
|
var import_constants = require("../constants");
|
|
45
|
+
function getLoopLimit() {
|
|
46
|
+
const limit = process.env.WORKFLOW_LOOP_LIMIT;
|
|
47
|
+
return limit ? parseInt(limit, 10) : null;
|
|
48
|
+
}
|
|
45
49
|
function getTargetLength(target) {
|
|
46
50
|
let length = 0;
|
|
47
51
|
if (typeof target === "number") {
|
|
@@ -65,16 +69,16 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
65
69
|
const [branch] = processor.getBranches(node);
|
|
66
70
|
const target = processor.getParsedValue(node.config.target, node.id);
|
|
67
71
|
const length = getTargetLength(target);
|
|
68
|
-
const
|
|
72
|
+
const result = { looped: 0, done: 0 };
|
|
69
73
|
if (!branch || !length) {
|
|
70
74
|
return {
|
|
71
75
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
72
|
-
result
|
|
76
|
+
result
|
|
73
77
|
};
|
|
74
78
|
}
|
|
75
79
|
const job = processor.saveJob({
|
|
76
80
|
status: import_plugin_workflow.JOB_STATUS.PENDING,
|
|
77
|
-
result
|
|
81
|
+
result,
|
|
78
82
|
nodeId: node.id,
|
|
79
83
|
nodeKey: node.key,
|
|
80
84
|
upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
|
|
@@ -82,18 +86,29 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
82
86
|
if (node.config.condition) {
|
|
83
87
|
const { checkpoint, calculation, expression, continueOnFalse } = node.config.condition ?? {};
|
|
84
88
|
if ((calculation || expression) && !checkpoint) {
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
while (result.looped < length) {
|
|
90
|
+
const condition = calculateCondition(node, processor);
|
|
91
|
+
if (condition) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
result.looped += 1;
|
|
95
|
+
job.set("result", result);
|
|
87
96
|
if (continueOnFalse) {
|
|
88
|
-
job.set("result", { looped: 1 });
|
|
89
97
|
processor.saveJob(job);
|
|
90
|
-
|
|
91
|
-
job.set({
|
|
92
|
-
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
93
|
-
result: { looped, broken: true }
|
|
94
|
-
});
|
|
95
|
-
return job;
|
|
98
|
+
continue;
|
|
96
99
|
}
|
|
100
|
+
job.set({
|
|
101
|
+
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
102
|
+
result: { ...result, broken: true }
|
|
103
|
+
});
|
|
104
|
+
return job;
|
|
105
|
+
}
|
|
106
|
+
if (result.looped >= length) {
|
|
107
|
+
job.set({
|
|
108
|
+
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
109
|
+
result
|
|
110
|
+
});
|
|
111
|
+
return job;
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
114
|
}
|
|
@@ -111,28 +126,46 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
111
126
|
if (branchJob.id !== job.id && branchJob.status === import_plugin_workflow.JOB_STATUS.PENDING) {
|
|
112
127
|
return null;
|
|
113
128
|
}
|
|
114
|
-
|
|
129
|
+
result.looped += 1;
|
|
115
130
|
const target = processor.getParsedValue(loop.config.target, node.id);
|
|
116
131
|
if (branchJob.status === import_plugin_workflow.JOB_STATUS.RESOLVED || branchJob.status < import_plugin_workflow.JOB_STATUS.PENDING && loop.config.exit === import_constants.EXIT.CONTINUE) {
|
|
117
|
-
|
|
118
|
-
processor.saveJob(job);
|
|
132
|
+
result.done += 1;
|
|
119
133
|
const length = getTargetLength(target);
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
134
|
+
if (loop.config.condition) {
|
|
135
|
+
const { calculation, expression, continueOnFalse } = loop.config.condition ?? {};
|
|
136
|
+
if (calculation || expression) {
|
|
137
|
+
while (result.looped < length) {
|
|
124
138
|
const condition = calculateCondition(loop, processor);
|
|
125
|
-
if (
|
|
139
|
+
if (condition) {
|
|
140
|
+
processor.logger.debug(`loop condition matched, continue inner branch (looped: ${result.looped})`);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (!continueOnFalse) {
|
|
144
|
+
processor.logger.debug(`loop condition not matches, break (looped: ${result.looped})`);
|
|
126
145
|
job.set({
|
|
127
146
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
128
|
-
result: {
|
|
147
|
+
result: { ...result, broken: true }
|
|
129
148
|
});
|
|
130
149
|
return job;
|
|
131
150
|
}
|
|
151
|
+
result.looped += 1;
|
|
152
|
+
processor.logger.debug(`loop condition not matches, try next loop item (looped: ${result.looped})`);
|
|
132
153
|
}
|
|
133
154
|
}
|
|
134
|
-
|
|
135
|
-
|
|
155
|
+
}
|
|
156
|
+
job.set({ result });
|
|
157
|
+
job.changed("result", true);
|
|
158
|
+
processor.saveJob(job);
|
|
159
|
+
if (result.looped < length) {
|
|
160
|
+
const loopLimit = getLoopLimit();
|
|
161
|
+
if (!loopLimit || result.done < loopLimit) {
|
|
162
|
+
await processor.run(branch, job);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
job.set({
|
|
166
|
+
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
167
|
+
result: { ...result, exceeded: true }
|
|
168
|
+
});
|
|
136
169
|
} else {
|
|
137
170
|
job.set({
|
|
138
171
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
@@ -141,7 +174,7 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
141
174
|
} else {
|
|
142
175
|
job.set(
|
|
143
176
|
loop.config.exit ? {
|
|
144
|
-
result: {
|
|
177
|
+
result: { ...result, broken: true },
|
|
145
178
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
146
179
|
} : {
|
|
147
180
|
status: branchJob.status
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "工作流:循环节点",
|
|
5
5
|
"description": "Used to repeat the sub-process processing of each value in an array, and can also be used for fixed times of sub-process processing.",
|
|
6
6
|
"description.zh-CN": "用于对一个数组中的每个值进行重复的子流程处理,也可用于固定次数的重复子流程处理。",
|
|
7
|
-
"version": "1.9.0
|
|
7
|
+
"version": "1.9.0",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/workflow-loop",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@nocobase/server": "1.x",
|
|
23
23
|
"@nocobase/test": "1.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "d92ce9096c2b3b5a8f205ecc0e1dedd64d7ee48b",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"Workflow"
|
|
28
28
|
]
|