@nocobase/plugin-workflow-loop 1.9.0-beta.8 → 2.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,10 +12,10 @@ module.exports = {
12
12
  "@ant-design/icons": "5.6.1",
13
13
  "antd": "5.24.2",
14
14
  "@formily/antd-v5": "1.2.3",
15
- "@formily/react": "2.3.0",
16
- "@nocobase/client": "1.9.0-beta.8",
17
- "@nocobase/plugin-workflow": "1.9.0-beta.8",
15
+ "@formily/react": "2.3.7",
16
+ "@nocobase/client": "2.0.0-alpha.2",
17
+ "@nocobase/plugin-workflow": "2.0.0-alpha.2",
18
18
  "react-i18next": "11.18.6",
19
- "@nocobase/evaluators": "1.9.0-beta.8",
20
- "@nocobase/server": "1.9.0-beta.8"
19
+ "@nocobase/evaluators": "2.0.0-alpha.2",
20
+ "@nocobase/server": "2.0.0-alpha.2"
21
21
  };
@@ -22,6 +22,7 @@ export default class extends Instruction {
22
22
  status: 1;
23
23
  result: {
24
24
  looped: number;
25
+ done: number;
25
26
  };
26
27
  }>;
27
28
  resume(node: FlowNodeModel, branchJob: any, processor: Processor): Promise<JobModel>;
@@ -65,16 +65,16 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
65
65
  const [branch] = processor.getBranches(node);
66
66
  const target = processor.getParsedValue(node.config.target, node.id);
67
67
  const length = getTargetLength(target);
68
- const looped = 0;
68
+ const result = { looped: 0, done: 0 };
69
69
  if (!branch || !length) {
70
70
  return {
71
71
  status: import_plugin_workflow.JOB_STATUS.RESOLVED,
72
- result: { looped }
72
+ result
73
73
  };
74
74
  }
75
75
  const job = processor.saveJob({
76
76
  status: import_plugin_workflow.JOB_STATUS.PENDING,
77
- result: { looped },
77
+ result,
78
78
  nodeId: node.id,
79
79
  nodeKey: node.key,
80
80
  upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
@@ -82,18 +82,29 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
82
82
  if (node.config.condition) {
83
83
  const { checkpoint, calculation, expression, continueOnFalse } = node.config.condition ?? {};
84
84
  if ((calculation || expression) && !checkpoint) {
85
- const condition = calculateCondition(node, processor);
86
- if (!condition) {
85
+ while (result.looped < length) {
86
+ const condition = calculateCondition(node, processor);
87
+ if (condition) {
88
+ break;
89
+ }
90
+ result.looped += 1;
91
+ job.set("result", result);
87
92
  if (continueOnFalse) {
88
- job.set("result", { looped: 1 });
89
93
  processor.saveJob(job);
90
- } else {
91
- job.set({
92
- status: import_plugin_workflow.JOB_STATUS.RESOLVED,
93
- result: { looped, broken: true }
94
- });
95
- return job;
94
+ continue;
96
95
  }
96
+ job.set({
97
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED,
98
+ result: { ...result, broken: true }
99
+ });
100
+ return job;
101
+ }
102
+ if (result.looped >= length) {
103
+ job.set({
104
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED,
105
+ result
106
+ });
107
+ return job;
97
108
  }
98
109
  }
99
110
  }
@@ -111,26 +122,37 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
111
122
  if (branchJob.id !== job.id && branchJob.status === import_plugin_workflow.JOB_STATUS.PENDING) {
112
123
  return null;
113
124
  }
114
- const nextIndex = result.looped + 1;
125
+ result.looped += 1;
115
126
  const target = processor.getParsedValue(loop.config.target, node.id);
116
127
  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
- job.set({ result: { looped: nextIndex } });
118
- processor.saveJob(job);
128
+ result.done += 1;
119
129
  const length = getTargetLength(target);
120
- if (nextIndex < length) {
121
- if (loop.config.condition) {
122
- const { calculation, expression, continueOnFalse } = loop.config.condition ?? {};
123
- if (calculation || expression) {
130
+ if (loop.config.condition) {
131
+ const { calculation, expression, continueOnFalse } = loop.config.condition ?? {};
132
+ if (calculation || expression) {
133
+ while (result.looped < length) {
124
134
  const condition = calculateCondition(loop, processor);
125
- if (!condition && !continueOnFalse) {
135
+ if (condition) {
136
+ processor.logger.debug(`loop condition matched, continue inner branch (looped: ${result.looped})`);
137
+ break;
138
+ }
139
+ if (!continueOnFalse) {
140
+ processor.logger.debug(`loop condition not matches, break (looped: ${result.looped})`);
126
141
  job.set({
127
142
  status: import_plugin_workflow.JOB_STATUS.RESOLVED,
128
- result: { looped: nextIndex, broken: true }
143
+ result: { ...result, broken: true }
129
144
  });
130
145
  return job;
131
146
  }
147
+ result.looped += 1;
148
+ processor.logger.debug(`loop condition not matches, try next loop item (looped: ${result.looped})`);
132
149
  }
133
150
  }
151
+ }
152
+ job.set({ result });
153
+ job.changed("result", true);
154
+ processor.saveJob(job);
155
+ if (result.looped < length) {
134
156
  await processor.run(branch, job);
135
157
  return;
136
158
  } else {
@@ -141,7 +163,7 @@ class LoopInstruction_default extends import_plugin_workflow.Instruction {
141
163
  } else {
142
164
  job.set(
143
165
  loop.config.exit ? {
144
- result: { looped: result.looped, broken: true },
166
+ result: { ...result, broken: true },
145
167
  status: import_plugin_workflow.JOB_STATUS.RESOLVED
146
168
  } : {
147
169
  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-beta.8",
7
+ "version": "2.0.0-alpha.2",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow-loop",
@@ -15,14 +15,14 @@
15
15
  "react-i18next": "^11.15.1"
16
16
  },
17
17
  "peerDependencies": {
18
- "@nocobase/client": "1.x",
19
- "@nocobase/database": "1.x",
20
- "@nocobase/evaluators": "1.x",
18
+ "@nocobase/client": "2.x",
19
+ "@nocobase/database": "2.x",
20
+ "@nocobase/evaluators": "2.x",
21
21
  "@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
22
- "@nocobase/server": "1.x",
23
- "@nocobase/test": "1.x"
22
+ "@nocobase/server": "2.x",
23
+ "@nocobase/test": "2.x"
24
24
  },
25
- "gitHead": "f3d4f3d1ba7adbf4d4c60e656c23da45565769c8",
25
+ "gitHead": "1322f486b248bef53ed8c8f42f0a39dfd02125fd",
26
26
  "keywords": [
27
27
  "Workflow"
28
28
  ]