@zerodep-dev/flow-ts-engine 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/client/client.d.ts +112 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +67 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/endpoint.d.ts +20 -0
- package/dist/client/endpoint.d.ts.map +1 -0
- package/dist/client/endpoint.js +153 -0
- package/dist/client/endpoint.js.map +1 -0
- package/dist/client/http.d.ts +30 -0
- package/dist/client/http.d.ts.map +1 -0
- package/dist/client/http.js +67 -0
- package/dist/client/http.js.map +1 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +11 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/port.d.ts +24 -0
- package/dist/client/port.d.ts.map +1 -0
- package/dist/client/port.js +53 -0
- package/dist/client/port.js.map +1 -0
- package/dist/client/protocol.d.ts +26 -0
- package/dist/client/protocol.d.ts.map +1 -0
- package/dist/client/protocol.js +13 -0
- package/dist/client/protocol.js.map +1 -0
- package/dist/commands/admin.d.ts +41 -0
- package/dist/commands/admin.d.ts.map +1 -0
- package/dist/commands/admin.js +228 -0
- package/dist/commands/admin.js.map +1 -0
- package/dist/commands/complete.d.ts +36 -0
- package/dist/commands/complete.d.ts.map +1 -0
- package/dist/commands/complete.js +289 -0
- package/dist/commands/complete.js.map +1 -0
- package/dist/commands/dispatch.d.ts +11 -0
- package/dist/commands/dispatch.d.ts.map +1 -0
- package/dist/commands/dispatch.js +77 -0
- package/dist/commands/dispatch.js.map +1 -0
- package/dist/commands/operate.d.ts +14 -0
- package/dist/commands/operate.d.ts.map +1 -0
- package/dist/commands/operate.js +72 -0
- package/dist/commands/operate.js.map +1 -0
- package/dist/commands/operations.d.ts +75 -0
- package/dist/commands/operations.d.ts.map +1 -0
- package/dist/commands/operations.js +417 -0
- package/dist/commands/operations.js.map +1 -0
- package/dist/commands/signal.d.ts +9 -0
- package/dist/commands/signal.d.ts.map +1 -0
- package/dist/commands/signal.js +78 -0
- package/dist/commands/signal.js.map +1 -0
- package/dist/commands/start.d.ts +41 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +186 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/submission.d.ts +20 -0
- package/dist/commands/submission.d.ts.map +1 -0
- package/dist/commands/submission.js +29 -0
- package/dist/commands/submission.js.map +1 -0
- package/dist/core/channels.d.ts +13 -0
- package/dist/core/channels.d.ts.map +1 -0
- package/dist/core/channels.js +13 -0
- package/dist/core/channels.js.map +1 -0
- package/dist/core/context.d.ts +76 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +148 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/entities.d.ts +392 -0
- package/dist/core/entities.d.ts.map +1 -0
- package/dist/core/entities.js +282 -0
- package/dist/core/entities.js.map +1 -0
- package/dist/core/errors.d.ts +35 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +18 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/engine.d.ts +146 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +85 -0
- package/dist/engine.js.map +1 -0
- package/dist/extensions.d.ts +198 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +7 -0
- package/dist/extensions.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/jobs.d.ts +27 -0
- package/dist/jobs/jobs.d.ts.map +1 -0
- package/dist/jobs/jobs.js +299 -0
- package/dist/jobs/jobs.js.map +1 -0
- package/dist/notify/collect.d.ts +38 -0
- package/dist/notify/collect.d.ts.map +1 -0
- package/dist/notify/collect.js +100 -0
- package/dist/notify/collect.js.map +1 -0
- package/dist/notify/inbox.d.ts +26 -0
- package/dist/notify/inbox.d.ts.map +1 -0
- package/dist/notify/inbox.js +87 -0
- package/dist/notify/inbox.js.map +1 -0
- package/dist/org/directory.d.ts +74 -0
- package/dist/org/directory.d.ts.map +1 -0
- package/dist/org/directory.js +254 -0
- package/dist/org/directory.js.map +1 -0
- package/dist/org/entities.d.ts +69 -0
- package/dist/org/entities.d.ts.map +1 -0
- package/dist/org/entities.js +39 -0
- package/dist/org/entities.js.map +1 -0
- package/dist/org/index.d.ts +5 -0
- package/dist/org/index.d.ts.map +1 -0
- package/dist/org/index.js +5 -0
- package/dist/org/index.js.map +1 -0
- package/dist/proxy/proxies.d.ts +18 -0
- package/dist/proxy/proxies.d.ts.map +1 -0
- package/dist/proxy/proxies.js +102 -0
- package/dist/proxy/proxies.js.map +1 -0
- package/dist/publish/project.d.ts +45 -0
- package/dist/publish/project.d.ts.map +1 -0
- package/dist/publish/project.js +176 -0
- package/dist/publish/project.js.map +1 -0
- package/dist/publish/publish.d.ts +42 -0
- package/dist/publish/publish.d.ts.map +1 -0
- package/dist/publish/publish.js +274 -0
- package/dist/publish/publish.js.map +1 -0
- package/dist/queries/queries.d.ts +24 -0
- package/dist/queries/queries.d.ts.map +1 -0
- package/dist/queries/queries.js +326 -0
- package/dist/queries/queries.js.map +1 -0
- package/dist/queries/stats.d.ts +9 -0
- package/dist/queries/stats.d.ts.map +1 -0
- package/dist/queries/stats.js +189 -0
- package/dist/queries/stats.js.map +1 -0
- package/dist/runtime/assignees.d.ts +32 -0
- package/dist/runtime/assignees.d.ts.map +1 -0
- package/dist/runtime/assignees.js +93 -0
- package/dist/runtime/assignees.js.map +1 -0
- package/dist/runtime/calls.d.ts +18 -0
- package/dist/runtime/calls.d.ts.map +1 -0
- package/dist/runtime/calls.js +182 -0
- package/dist/runtime/calls.js.map +1 -0
- package/dist/runtime/countersign.d.ts +26 -0
- package/dist/runtime/countersign.d.ts.map +1 -0
- package/dist/runtime/countersign.js +63 -0
- package/dist/runtime/countersign.js.map +1 -0
- package/dist/runtime/execution.d.ts +150 -0
- package/dist/runtime/execution.d.ts.map +1 -0
- package/dist/runtime/execution.js +792 -0
- package/dist/runtime/execution.js.map +1 -0
- package/dist/runtime/next-steps.d.ts +56 -0
- package/dist/runtime/next-steps.d.ts.map +1 -0
- package/dist/runtime/next-steps.js +145 -0
- package/dist/runtime/next-steps.js.map +1 -0
- package/dist/runtime/state.d.ts +26 -0
- package/dist/runtime/state.d.ts.map +1 -0
- package/dist/runtime/state.js +32 -0
- package/dist/runtime/state.js.map +1 -0
- package/dist/testing/scenarios.d.ts +35 -0
- package/dist/testing/scenarios.d.ts.map +1 -0
- package/dist/testing/scenarios.js +63 -0
- package/dist/testing/scenarios.js.map +1 -0
- package/dist/testing/simulate.d.ts +55 -0
- package/dist/testing/simulate.d.ts.map +1 -0
- package/dist/testing/simulate.js +122 -0
- package/dist/testing/simulate.js.map +1 -0
- package/dist/testing/testing.d.ts +31 -0
- package/dist/testing/testing.d.ts.map +1 -0
- package/dist/testing/testing.js +54 -0
- package/dist/testing/testing.js.map +1 -0
- package/dist/types.d.ts +283 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/views.d.ts +317 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +9 -0
- package/dist/views.js.map +1 -0
- package/package.json +76 -3
- package/src/client/client.ts +194 -0
- package/src/client/endpoint.ts +174 -0
- package/src/client/http.ts +99 -0
- package/src/client/index.ts +12 -0
- package/src/client/port.ts +78 -0
- package/src/client/protocol.ts +36 -0
- package/src/commands/admin.ts +308 -0
- package/src/commands/complete.ts +368 -0
- package/src/commands/dispatch.ts +106 -0
- package/src/commands/operate.ts +110 -0
- package/src/commands/operations.ts +524 -0
- package/src/commands/signal.ts +96 -0
- package/src/commands/start.ts +255 -0
- package/src/commands/submission.ts +51 -0
- package/src/core/channels.ts +14 -0
- package/src/core/context.ts +252 -0
- package/src/core/entities.ts +335 -0
- package/src/core/errors.ts +42 -0
- package/src/engine.ts +247 -0
- package/src/extensions.ts +231 -0
- package/src/index.ts +77 -0
- package/src/jobs/jobs.ts +320 -0
- package/src/notify/collect.ts +155 -0
- package/src/notify/inbox.ts +107 -0
- package/src/org/directory.ts +332 -0
- package/src/org/entities.ts +62 -0
- package/src/org/index.ts +21 -0
- package/src/proxy/proxies.ts +132 -0
- package/src/publish/project.ts +230 -0
- package/src/publish/publish.ts +314 -0
- package/src/queries/queries.ts +427 -0
- package/src/queries/stats.ts +207 -0
- package/src/runtime/assignees.ts +121 -0
- package/src/runtime/calls.ts +196 -0
- package/src/runtime/countersign.ts +83 -0
- package/src/runtime/execution.ts +915 -0
- package/src/runtime/next-steps.ts +213 -0
- package/src/runtime/state.ts +55 -0
- package/src/testing/scenarios.ts +95 -0
- package/src/testing/simulate.ts +190 -0
- package/src/testing/testing.ts +84 -0
- package/src/types.ts +286 -0
- package/src/views.ts +334 -0
- package/README.md +0 -3
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 实例上的操作:撤回、终止、跳转、暂停与恢复、催办、改单据数据、迁移到另一个版本。
|
|
3
|
+
*/
|
|
4
|
+
import { or } from '@zerodep-dev/easy-query-ts';
|
|
5
|
+
import { processGraph, type ProcessDefinition } from '@zerodep-dev/flow-ts-model';
|
|
6
|
+
import { FlowDefinition, FlowInstance, FlowJob, FlowWorkItem } from '../core/entities.ts';
|
|
7
|
+
import { FlowError } from '../core/errors.ts';
|
|
8
|
+
import { renameNodes } from '../runtime/state.ts';
|
|
9
|
+
import type { Actor, FlowCommand, RunResult } from '../types.ts';
|
|
10
|
+
import type { EngineCore } from '../core/context.ts';
|
|
11
|
+
|
|
12
|
+
/** 手动催办的间隔:同一份待办一小时内只催一次 */
|
|
13
|
+
const REMIND_INTERVAL_MS = 3_600_000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 发起人此刻能不能撤回:按流程的 withdraw 设置(默认没人处理过之前),别人处理过、或设成 beforeClaim 时有人认领了就不行。
|
|
17
|
+
* 撤回命令与实例详情的 actions 共用
|
|
18
|
+
*/
|
|
19
|
+
export function withdrawable(
|
|
20
|
+
definition: ProcessDefinition,
|
|
21
|
+
items: readonly {
|
|
22
|
+
readonly state: string;
|
|
23
|
+
readonly completedBy: string | null;
|
|
24
|
+
readonly assignment: string;
|
|
25
|
+
}[],
|
|
26
|
+
startedBy: string,
|
|
27
|
+
): boolean {
|
|
28
|
+
const mode = definition.settings?.withdraw ?? 'beforeAction';
|
|
29
|
+
if (mode === 'never') return false;
|
|
30
|
+
if (items.some((w) => w.state === 'done' && w.completedBy !== startedBy)) return false;
|
|
31
|
+
return !(mode === 'beforeClaim' && items.some((w) => w.assignment === 'claimed'));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 节点允许催办(环节上写了 allow.remind: false 的不行) */
|
|
35
|
+
export function remindable(definition: ProcessDefinition, node: string): boolean {
|
|
36
|
+
const found = definition.nodes.find((n) => n.id === node);
|
|
37
|
+
return found?.type !== 'task' || found.allow?.remind !== false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 实例上的操作:装进引擎核心(core.admin),别的模块经它调用 */
|
|
41
|
+
export function createAdmin(core: EngineCore) {
|
|
42
|
+
const { withInstance } = core;
|
|
43
|
+
|
|
44
|
+
async function withdraw(
|
|
45
|
+
command: Extract<FlowCommand, { type: 'withdraw' }>,
|
|
46
|
+
actor: Actor,
|
|
47
|
+
): Promise<RunResult> {
|
|
48
|
+
return withInstance(
|
|
49
|
+
command.instance,
|
|
50
|
+
actor,
|
|
51
|
+
async (exec, tx) => {
|
|
52
|
+
if (exec.status !== 'active')
|
|
53
|
+
throw new FlowError('instance-not-active', `实例 ${command.instance} 不在进行中`);
|
|
54
|
+
if (exec.instance.startedBy !== actor.id)
|
|
55
|
+
throw new FlowError('forbidden', '只有发起人能撤回');
|
|
56
|
+
const items = await tx
|
|
57
|
+
.queryable(FlowWorkItem)
|
|
58
|
+
.where((w) => w.instanceId.eq(command.instance))
|
|
59
|
+
.toList();
|
|
60
|
+
if (!withdrawable(exec.definition, items, actor.id))
|
|
61
|
+
throw new FlowError('forbidden', '已经有人处理了,不能撤回');
|
|
62
|
+
await exec.finish('withdrawn', 'withdrawn', command.comment ?? null);
|
|
63
|
+
},
|
|
64
|
+
command,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function terminate(
|
|
69
|
+
command: Extract<FlowCommand, { type: 'terminate' }>,
|
|
70
|
+
actor: Actor,
|
|
71
|
+
): Promise<RunResult> {
|
|
72
|
+
if (!actor.admin) throw new FlowError('forbidden', '只有管理员能终止');
|
|
73
|
+
return withInstance(
|
|
74
|
+
command.instance,
|
|
75
|
+
actor,
|
|
76
|
+
async (exec) => {
|
|
77
|
+
if (exec.finished)
|
|
78
|
+
throw new FlowError('instance-not-active', `实例 ${command.instance} 已经结束`);
|
|
79
|
+
await exec.finish('terminated', command.result ?? 'terminated', command.comment ?? null);
|
|
80
|
+
},
|
|
81
|
+
command,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 管理员跳转:取消所有开着的待办、清掉等待状态,从指定节点重新走 */
|
|
86
|
+
async function jump(
|
|
87
|
+
command: Extract<FlowCommand, { type: 'jump' }>,
|
|
88
|
+
actor: Actor,
|
|
89
|
+
): Promise<RunResult> {
|
|
90
|
+
if (!actor.admin) throw new FlowError('forbidden', '只有管理员能跳转');
|
|
91
|
+
return withInstance(
|
|
92
|
+
command.instance,
|
|
93
|
+
actor,
|
|
94
|
+
async (exec) => {
|
|
95
|
+
if (exec.status !== 'active') {
|
|
96
|
+
throw new FlowError('instance-not-active', `实例 ${command.instance} 不在进行中`);
|
|
97
|
+
}
|
|
98
|
+
const target = exec.graph.node(command.node);
|
|
99
|
+
if (!target || target.type === 'start') {
|
|
100
|
+
throw new FlowError('invalid-input', `不能跳到 ${command.node}`, { field: 'node' });
|
|
101
|
+
}
|
|
102
|
+
await exec.cancelWhere(() => []);
|
|
103
|
+
exec.current.clear();
|
|
104
|
+
exec.state.waiting = {};
|
|
105
|
+
exec.state.queues = {};
|
|
106
|
+
exec.addEvent('instance.jumped', {
|
|
107
|
+
comment: command.comment ?? null,
|
|
108
|
+
data: { to: command.node },
|
|
109
|
+
});
|
|
110
|
+
await exec.enter(command.node, 'jump');
|
|
111
|
+
},
|
|
112
|
+
command,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function suspendOrResume(
|
|
117
|
+
command: Extract<FlowCommand, { type: 'suspend' | 'resume' }>,
|
|
118
|
+
actor: Actor,
|
|
119
|
+
): Promise<RunResult> {
|
|
120
|
+
if (!actor.admin) throw new FlowError('forbidden', '只有管理员能暂停、恢复');
|
|
121
|
+
return withInstance(
|
|
122
|
+
command.instance,
|
|
123
|
+
actor,
|
|
124
|
+
async (exec) => {
|
|
125
|
+
const from = command.type === 'suspend' ? 'active' : 'suspended';
|
|
126
|
+
if (exec.status !== from) {
|
|
127
|
+
throw new FlowError(
|
|
128
|
+
'instance-not-active',
|
|
129
|
+
`实例 ${command.instance} 不是${from === 'active' ? '进行中' : '暂停'}的`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
exec.status = command.type === 'suspend' ? 'suspended' : 'active';
|
|
133
|
+
exec.addEvent(command.type === 'suspend' ? 'instance.suspended' : 'instance.resumed', {
|
|
134
|
+
comment: command.type === 'suspend' ? (command.comment ?? null) : null,
|
|
135
|
+
});
|
|
136
|
+
if (command.type === 'resume') await core.calls.resumeWaitingCalls(exec);
|
|
137
|
+
},
|
|
138
|
+
command,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function remind(
|
|
143
|
+
command: Extract<FlowCommand, { type: 'remind' }>,
|
|
144
|
+
actor: Actor,
|
|
145
|
+
): Promise<RunResult> {
|
|
146
|
+
return withInstance(
|
|
147
|
+
command.instance,
|
|
148
|
+
actor,
|
|
149
|
+
async (exec, tx) => {
|
|
150
|
+
if (exec.status !== 'active')
|
|
151
|
+
throw new FlowError('instance-not-active', `实例 ${command.instance} 不在进行中`);
|
|
152
|
+
if (exec.instance.startedBy !== actor.id && !actor.admin) {
|
|
153
|
+
throw new FlowError('forbidden', '只有发起人或管理员能催办');
|
|
154
|
+
}
|
|
155
|
+
const items = await tx
|
|
156
|
+
.queryable(FlowWorkItem)
|
|
157
|
+
.where((w) => [
|
|
158
|
+
w.instanceId.eq(command.instance),
|
|
159
|
+
w.state.eq('open'),
|
|
160
|
+
...(command.workItem !== undefined ? [w.id.eq(command.workItem)] : []),
|
|
161
|
+
])
|
|
162
|
+
.toList();
|
|
163
|
+
// 环节关掉了催办(allow.remind: false):点名催它时报错,催全部时跳过它
|
|
164
|
+
if (
|
|
165
|
+
command.workItem !== undefined &&
|
|
166
|
+
items[0] &&
|
|
167
|
+
!remindable(exec.definition, items[0].node)
|
|
168
|
+
)
|
|
169
|
+
throw new FlowError('forbidden', `节点 ${items[0].nodeName} 不允许催办`);
|
|
170
|
+
// 同一份待办一小时内只催一次(同 Java 版):带条件地记下催办的时刻,没记上的不催
|
|
171
|
+
const notBefore = new Date(exec.now.getTime() - REMIND_INTERVAL_MS);
|
|
172
|
+
for (const item of items.filter((i) => remindable(exec.definition, i.node))) {
|
|
173
|
+
const marked = await tx
|
|
174
|
+
.update(FlowWorkItem)
|
|
175
|
+
.set({ remindedAt: exec.now })
|
|
176
|
+
.where((w) => [w.id.eq(item.id), or(w.remindedAt.isNull(), w.remindedAt.lt(notBefore))])
|
|
177
|
+
.execute();
|
|
178
|
+
if (marked === 0) continue;
|
|
179
|
+
exec.addEvent('workItem.reminded', {
|
|
180
|
+
workItemId: item.id,
|
|
181
|
+
node: item.node,
|
|
182
|
+
comment: command.message ?? null,
|
|
183
|
+
data: { reason: 'manual' },
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
command,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 管理员改单据数据:只记真的变了的字段,改前、改后各一份 */
|
|
192
|
+
async function changeData(
|
|
193
|
+
command: Extract<FlowCommand, { type: 'changeData' }>,
|
|
194
|
+
actor: Actor,
|
|
195
|
+
): Promise<RunResult> {
|
|
196
|
+
if (!actor.admin) throw new FlowError('forbidden', '只有管理员能改单据数据');
|
|
197
|
+
return withInstance(
|
|
198
|
+
command.instance,
|
|
199
|
+
actor,
|
|
200
|
+
async (exec) => {
|
|
201
|
+
const changes: Record<string, { before: unknown; after: unknown }> = {};
|
|
202
|
+
for (const [name, after] of Object.entries(command.variables)) {
|
|
203
|
+
const before = exec.variables[name] ?? null;
|
|
204
|
+
if (JSON.stringify(before) !== JSON.stringify(after)) changes[name] = { before, after };
|
|
205
|
+
}
|
|
206
|
+
if (Object.keys(changes).length === 0) return;
|
|
207
|
+
exec.setVariables(command.variables);
|
|
208
|
+
exec.addEvent('instance.dataChanged', {
|
|
209
|
+
comment: command.comment ?? null,
|
|
210
|
+
data: { form: changes },
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
command,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** 管理员迁移版本(同 Java 版):先核对正在用的节点在新版本里都有、类型相同,再换版本、改待办与作业 */
|
|
218
|
+
async function migrate(
|
|
219
|
+
command: Extract<FlowCommand, { type: 'migrate' }>,
|
|
220
|
+
actor: Actor,
|
|
221
|
+
): Promise<RunResult> {
|
|
222
|
+
if (!actor.admin) throw new FlowError('forbidden', '只有管理员能迁移版本');
|
|
223
|
+
if (!command.comment?.trim()) {
|
|
224
|
+
throw new FlowError('invalid-input', '迁移要写原因', { field: 'comment', code: 'required' });
|
|
225
|
+
}
|
|
226
|
+
return withInstance(
|
|
227
|
+
command.instance,
|
|
228
|
+
actor,
|
|
229
|
+
async (exec, tx) => {
|
|
230
|
+
if (exec.finished)
|
|
231
|
+
throw new FlowError('instance-not-active', `实例 ${command.instance} 已经结束`);
|
|
232
|
+
const target = await tx
|
|
233
|
+
.queryable(FlowDefinition)
|
|
234
|
+
.where((d) => [d.processKey.eq(exec.instance.processKey), d.version.eq(command.version)])
|
|
235
|
+
.first();
|
|
236
|
+
if (!target) {
|
|
237
|
+
throw new FlowError(
|
|
238
|
+
'not-found',
|
|
239
|
+
`没有 ${exec.instance.processKey} 的第 ${command.version} 版`,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const to = processGraph(target.model);
|
|
243
|
+
const live = await tx
|
|
244
|
+
.queryable(FlowWorkItem)
|
|
245
|
+
.where((w) => [w.instanceId.eq(exec.instance.id), w.state.in(['open', 'waiting'])])
|
|
246
|
+
.toList();
|
|
247
|
+
const inUse = new Set([...exec.current, ...live.map((w) => w.node)]);
|
|
248
|
+
const mapping: Record<string, string> = {};
|
|
249
|
+
for (const node of inUse) {
|
|
250
|
+
const next = command.nodes?.[node] ?? node;
|
|
251
|
+
const before = exec.graph.node(node);
|
|
252
|
+
const after = to.node(next);
|
|
253
|
+
if (!before || !after || before.type !== after.type) {
|
|
254
|
+
throw new FlowError(
|
|
255
|
+
'invalid-input',
|
|
256
|
+
`节点 ${node} 在第 ${command.version} 版里没有对应的节点`,
|
|
257
|
+
{
|
|
258
|
+
field: `nodes.${node}`,
|
|
259
|
+
code: 'no-matching-node',
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
mapping[node] = next;
|
|
264
|
+
}
|
|
265
|
+
const renamed = Object.entries(mapping).filter(([from, next]) => from !== next);
|
|
266
|
+
for (const [from, next] of renamed) {
|
|
267
|
+
await tx
|
|
268
|
+
.update(FlowWorkItem)
|
|
269
|
+
.set({ node: next, nodeName: to.node(next)!.name })
|
|
270
|
+
.where((w) => [w.instanceId.eq(exec.instance.id), w.node.eq(from)])
|
|
271
|
+
.execute();
|
|
272
|
+
await tx
|
|
273
|
+
.update(FlowJob)
|
|
274
|
+
.set({ node: next })
|
|
275
|
+
.where((j) => [j.instanceId.eq(exec.instance.id), j.node.eq(from)])
|
|
276
|
+
.execute();
|
|
277
|
+
}
|
|
278
|
+
for (const item of live.filter((w) => w.signGroup && mapping[w.node] !== w.node)) {
|
|
279
|
+
const round = item.signGroup!.slice(item.signGroup!.lastIndexOf('#'));
|
|
280
|
+
await tx
|
|
281
|
+
.update(FlowWorkItem)
|
|
282
|
+
.set({ signGroup: `${mapping[item.node]}${round}` })
|
|
283
|
+
.where((w) => w.id.eq(item.id))
|
|
284
|
+
.execute();
|
|
285
|
+
}
|
|
286
|
+
Object.assign(exec.state, renameNodes(exec.state, mapping));
|
|
287
|
+
const current = [...exec.current].map((node) => mapping[node] ?? node);
|
|
288
|
+
exec.current.clear();
|
|
289
|
+
for (const node of current) exec.current.add(node);
|
|
290
|
+
await tx
|
|
291
|
+
.update(FlowInstance)
|
|
292
|
+
.set({ definitionId: target.id, version: target.version })
|
|
293
|
+
.where((i) => i.id.eq(exec.instance.id))
|
|
294
|
+
.execute();
|
|
295
|
+
exec.addEvent('instance.migrated', {
|
|
296
|
+
comment: command.comment,
|
|
297
|
+
data: { fromVersion: exec.instance.version, toVersion: target.version, nodes: mapping },
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
command,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return { withdraw, terminate, jump, suspendOrResume, remind, changeData, migrate };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** createAdmin 给出的函数 */
|
|
308
|
+
export type Admin = ReturnType<typeof createAdmin>;
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理待办:选结果、收单据的值、守卫;一份待办处理完后会签判断、加签交回、按结果往下走(退回、终止、提级)。
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
fieldStates,
|
|
6
|
+
gatewayPairs,
|
|
7
|
+
formManifest,
|
|
8
|
+
type Outcome,
|
|
9
|
+
type TaskNode,
|
|
10
|
+
} from '@zerodep-dev/flow-ts-model';
|
|
11
|
+
import { decideCountersign } from '../runtime/countersign.ts';
|
|
12
|
+
import { FlowWorkItem, type FlowDb } from '../core/entities.ts';
|
|
13
|
+
import { FlowError } from '../core/errors.ts';
|
|
14
|
+
import { Execution, type WorkItemRow } from '../runtime/execution.ts';
|
|
15
|
+
import type { Actor, FlowCommand, RunResult } from '../types.ts';
|
|
16
|
+
import type { EngineCore } from '../core/context.ts';
|
|
17
|
+
import { submit, throwFormErrors } from './submission.ts';
|
|
18
|
+
import { checkPicks, picksOf, stepsAfter } from '../runtime/next-steps.ts';
|
|
19
|
+
|
|
20
|
+
/** 这份待办能选的结果:加签的人不能退回(退回由原来的处理人决定) */
|
|
21
|
+
export function outcomesFor(node: TaskNode, item: WorkItemRow): readonly Outcome[] {
|
|
22
|
+
return item.parentItemId === null
|
|
23
|
+
? node.outcomes
|
|
24
|
+
: node.outcomes.filter((o) => (o.kind ?? 'approve') !== 'return');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 退回时能选的节点:沿前进的连线往上游找、走到过的人工节点;已经汇合了的并行区域里的节点不算(那些分支已经结束)
|
|
29
|
+
*/
|
|
30
|
+
export function returnTargets(
|
|
31
|
+
{ definition, graph, state }: Pick<Execution, 'definition' | 'graph' | 'state'>,
|
|
32
|
+
from: string,
|
|
33
|
+
): string[] {
|
|
34
|
+
const pairs = gatewayPairs(definition);
|
|
35
|
+
const ancestors = new Set<string>();
|
|
36
|
+
const queue = [from];
|
|
37
|
+
while (queue.length > 0) {
|
|
38
|
+
const id = queue.shift()!;
|
|
39
|
+
for (const edge of graph.incoming(id)) {
|
|
40
|
+
if (edge.kind === 'return' || edge.kind === 'escalate' || ancestors.has(edge.from)) continue;
|
|
41
|
+
ancestors.add(edge.from);
|
|
42
|
+
queue.push(edge.from);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const closed = (id: string) =>
|
|
46
|
+
definition.nodes.some((n) => {
|
|
47
|
+
const join = pairs.joinOf(n.id);
|
|
48
|
+
return join !== undefined && ancestors.has(join) && pairs.region(n.id).has(id);
|
|
49
|
+
});
|
|
50
|
+
// 按定义里的先后(流程的顺序):最近的上游在最后
|
|
51
|
+
return definition.nodes
|
|
52
|
+
.map((node) => node.id)
|
|
53
|
+
.filter(
|
|
54
|
+
(id) =>
|
|
55
|
+
ancestors.has(id) && graph.node(id)?.type === 'task' && state.rounds[id] && !closed(id),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 处理待办:装进引擎核心(core.tasks),别的模块经它调用 */
|
|
60
|
+
export function createTasks(core: EngineCore) {
|
|
61
|
+
const { options, withInstance, instanceOfItem, openItem, isCandidate } = core;
|
|
62
|
+
|
|
63
|
+
async function complete(
|
|
64
|
+
command: Extract<FlowCommand, { type: 'complete' }>,
|
|
65
|
+
actor: Actor,
|
|
66
|
+
): Promise<RunResult> {
|
|
67
|
+
return withInstance(
|
|
68
|
+
await instanceOfItem(command.workItem),
|
|
69
|
+
actor,
|
|
70
|
+
async (exec, tx) => {
|
|
71
|
+
const item = await openItem(exec, tx, command.workItem);
|
|
72
|
+
if (!isCandidate(item, actor)) {
|
|
73
|
+
throw new FlowError('forbidden', `${actor.id} 不能处理待办 ${item.id}`);
|
|
74
|
+
}
|
|
75
|
+
const node = exec.node(item.node) as TaskNode;
|
|
76
|
+
const outcome = outcomesFor(node, item).find((o) => o.key === command.outcome);
|
|
77
|
+
if (!outcome) {
|
|
78
|
+
throw new FlowError('invalid-input', `节点 ${node.name} 没有结果 ${command.outcome}`, {
|
|
79
|
+
field: 'outcome',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (outcome.comment === 'required' && !command.comment?.trim()) {
|
|
83
|
+
throw new FlowError('invalid-input', `“${outcome.label}”要写意见`, { field: 'comment' });
|
|
84
|
+
}
|
|
85
|
+
// 这一步改了哪些值、原来是什么:撤回这一步时恢复
|
|
86
|
+
const before = Object.fromEntries(
|
|
87
|
+
Object.keys(command.variables ?? {}).map((key) => [key, exec.variables[key] ?? null]),
|
|
88
|
+
);
|
|
89
|
+
// 驳回、退回、终止不要求把单据填全(值照旧要合格):财务不予报销时不用先填核定金额
|
|
90
|
+
const kind = outcome.kind ?? 'approve';
|
|
91
|
+
applySubmission(exec, node, command.variables, {
|
|
92
|
+
required: kind !== 'reject' && kind !== 'return' && kind !== 'terminate',
|
|
93
|
+
});
|
|
94
|
+
for (const name of outcome.guards ?? []) {
|
|
95
|
+
const guard = exec.extension('guards', name);
|
|
96
|
+
if (!guard) throw new FlowError('invalid-definition', `没有注册守卫 ${name}`);
|
|
97
|
+
const verdict = await guard({
|
|
98
|
+
...exec.context(),
|
|
99
|
+
node: node.id,
|
|
100
|
+
outcome: outcome.key,
|
|
101
|
+
actor,
|
|
102
|
+
});
|
|
103
|
+
if (verdict !== true) throw new FlowError('guard-rejected', verdict, { guard: name });
|
|
104
|
+
}
|
|
105
|
+
exec.state.picks = {
|
|
106
|
+
...exec.state.picks,
|
|
107
|
+
...checkPicks(
|
|
108
|
+
picksOf(await stepsAfter(options, exec, node, outcome, actor.id)),
|
|
109
|
+
command.picks,
|
|
110
|
+
),
|
|
111
|
+
};
|
|
112
|
+
await finishItem(exec, tx, item, node, outcome.key, {
|
|
113
|
+
actor: actor.id,
|
|
114
|
+
comment: command.comment ?? null,
|
|
115
|
+
returnTo: command.returnTo,
|
|
116
|
+
before,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
command,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 一份待办处理完:带状态条件写成 done、记事件,会签判断这一组结束了没有,结束了按结果往下走。
|
|
125
|
+
* 人处理(complete)与超时自动处理(overdue 作业,actor 为 null)共用
|
|
126
|
+
*/
|
|
127
|
+
async function finishItem(
|
|
128
|
+
exec: Execution,
|
|
129
|
+
tx: FlowDb,
|
|
130
|
+
item: WorkItemRow,
|
|
131
|
+
node: TaskNode,
|
|
132
|
+
outcomeKey: string,
|
|
133
|
+
by: {
|
|
134
|
+
actor: string | null;
|
|
135
|
+
comment: string | null;
|
|
136
|
+
returnTo?: string | undefined;
|
|
137
|
+
/** 这一步改过的单据值原来是什么(记进事件,撤回这一步时恢复) */
|
|
138
|
+
before?: Readonly<Record<string, unknown>>;
|
|
139
|
+
},
|
|
140
|
+
): Promise<void> {
|
|
141
|
+
// 后加签:结果先挂着,打开排队的加签待办,等他们办完(signerDone)再生效
|
|
142
|
+
const after = (w: any) => [
|
|
143
|
+
w.parentItemId.eq(item.id),
|
|
144
|
+
w.state.eq('waiting'),
|
|
145
|
+
w.arrival.eq('addSign.after'),
|
|
146
|
+
];
|
|
147
|
+
if (
|
|
148
|
+
(await tx
|
|
149
|
+
.queryable(FlowWorkItem)
|
|
150
|
+
.where(after as never)
|
|
151
|
+
.count()) > 0
|
|
152
|
+
) {
|
|
153
|
+
await tx
|
|
154
|
+
.update(FlowWorkItem)
|
|
155
|
+
.set({ state: 'waiting', pendingOutcome: outcomeKey, comment: by.comment })
|
|
156
|
+
.where((w) => [w.id.eq(item.id), w.state.eq('open')])
|
|
157
|
+
.expectRows(1, () => new FlowError('already-handled', `待办 ${item.id} 已经处理过`))
|
|
158
|
+
.execute();
|
|
159
|
+
await tx
|
|
160
|
+
.update(FlowWorkItem)
|
|
161
|
+
.set({ state: 'open' })
|
|
162
|
+
.where(after as never)
|
|
163
|
+
.execute();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await tx
|
|
167
|
+
.update(FlowWorkItem)
|
|
168
|
+
.set({
|
|
169
|
+
draft: null,
|
|
170
|
+
state: 'done',
|
|
171
|
+
outcome: outcomeKey,
|
|
172
|
+
comment: by.comment,
|
|
173
|
+
completedAt: exec.now,
|
|
174
|
+
completedBy: by.actor,
|
|
175
|
+
assignee: by.actor ?? item.assignee,
|
|
176
|
+
})
|
|
177
|
+
.where((w) => [w.id.eq(item.id), w.state.eq('open')])
|
|
178
|
+
.expectRows(1, () => new FlowError('already-handled', `待办 ${item.id} 已经处理过`))
|
|
179
|
+
.execute();
|
|
180
|
+
exec.addEvent('workItem.completed', {
|
|
181
|
+
workItemId: item.id,
|
|
182
|
+
node: node.id,
|
|
183
|
+
outcome: outcomeKey,
|
|
184
|
+
comment: by.comment,
|
|
185
|
+
actor: by.actor,
|
|
186
|
+
data: {
|
|
187
|
+
outcomeLabel: node.outcomes.find((o) => o.key === outcomeKey)?.label ?? outcomeKey,
|
|
188
|
+
...(by.before && Object.keys(by.before).length > 0 ? { before: by.before } : {}),
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
if (item.parentItemId !== null) return signerDone(exec, tx, item, node);
|
|
192
|
+
if (by.actor) {
|
|
193
|
+
exec.state.handledBy[node.id] = by.actor;
|
|
194
|
+
exec.lastHandler = by.actor;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let decided = outcomeKey;
|
|
198
|
+
if (node.multi && item.signGroup) {
|
|
199
|
+
const group = item.signGroup;
|
|
200
|
+
// 会签组的键只在实例里唯一
|
|
201
|
+
const votes = await tx
|
|
202
|
+
.queryable(FlowWorkItem)
|
|
203
|
+
.where((w) => [w.instanceId.eq(item.instanceId), w.signGroup.eq(group)])
|
|
204
|
+
.toList();
|
|
205
|
+
const queue = exec.state.queues[group] ?? [];
|
|
206
|
+
const rule =
|
|
207
|
+
exec.logic?.countersign?.[node.multi.complete] ??
|
|
208
|
+
options.extensions?.countersign?.[node.multi.complete];
|
|
209
|
+
const result = decideCountersign(
|
|
210
|
+
node.multi,
|
|
211
|
+
node.outcomes,
|
|
212
|
+
votes,
|
|
213
|
+
queue.length,
|
|
214
|
+
rule && { rule, node: node.id, chosen: outcomeKey },
|
|
215
|
+
);
|
|
216
|
+
if (result === undefined) {
|
|
217
|
+
const [next, ...rest] = queue;
|
|
218
|
+
if (node.multi.complete === 'sequential' && next !== undefined) {
|
|
219
|
+
exec.state.queues[group] = rest;
|
|
220
|
+
if (rest.length === 0) delete exec.state.queues[group];
|
|
221
|
+
await exec.insertItem(node, item.round, 'forward', {
|
|
222
|
+
assignee: next,
|
|
223
|
+
assignment: 'direct',
|
|
224
|
+
state: 'open',
|
|
225
|
+
signGroup: group,
|
|
226
|
+
signSeq: (item.signSeq ?? 0) + 1,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
delete exec.state.queues[group];
|
|
232
|
+
await exec.cancelWhere((w) => [w.signGroup.eq(group)]);
|
|
233
|
+
exec.addEvent('countersign.decided', { node: node.id, outcome: result });
|
|
234
|
+
decided = result;
|
|
235
|
+
}
|
|
236
|
+
exec.current.delete(node.id);
|
|
237
|
+
await advanceFromTask(exec, node, decided, by.returnTo);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 加签(委托)的人办完一份:同一份待办下的都办完了,前加签与委托回到原来的处理人,后加签让挂着的结果生效——
|
|
242
|
+
* 加签的人里有选了非通过结果的,按第一个这样的结果走
|
|
243
|
+
*/
|
|
244
|
+
function signerDone(exec: Execution, tx: FlowDb, signer: WorkItemRow, node: TaskNode) {
|
|
245
|
+
return settleParent(exec, tx, signer.parentItemId!, node);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** 原来那份待办下的加签都办完(或减掉)了:恢复它 */
|
|
249
|
+
async function settleParent(exec: Execution, tx: FlowDb, parentId: number, node: TaskNode) {
|
|
250
|
+
const siblings = await tx
|
|
251
|
+
.queryable(FlowWorkItem)
|
|
252
|
+
.where((w) => w.parentItemId.eq(parentId))
|
|
253
|
+
.orderBy((w) => w.id)
|
|
254
|
+
.toList();
|
|
255
|
+
if (siblings.some((w) => w.state === 'open' || w.state === 'waiting')) return;
|
|
256
|
+
const parent = await tx.queryable(FlowWorkItem).findOrThrow(parentId);
|
|
257
|
+
if (parent.state !== 'waiting') return;
|
|
258
|
+
await tx
|
|
259
|
+
.update(FlowWorkItem)
|
|
260
|
+
.set({ state: 'open', pendingOutcome: null })
|
|
261
|
+
.where((w) => w.id.eq(parent.id))
|
|
262
|
+
.execute();
|
|
263
|
+
const reopened = { ...parent, state: 'open' as const, pendingOutcome: null };
|
|
264
|
+
if (parent.pendingOutcome === null) {
|
|
265
|
+
exec.addEvent('workItem.resumed', { workItemId: parent.id, node: node.id });
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const kindOf = (key: string | null) =>
|
|
269
|
+
node.outcomes.find((o) => o.key === key)?.kind ?? 'approve';
|
|
270
|
+
const objection = siblings.find((w) => w.state === 'done' && kindOf(w.outcome) !== 'approve');
|
|
271
|
+
await finishItem(exec, tx, reopened, node, objection?.outcome ?? parent.pendingOutcome, {
|
|
272
|
+
actor: parent.assignee,
|
|
273
|
+
comment: parent.comment,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 处理时提交的变量:流程声明了变量时按环节的表单权限合并(只收能改的,必填的要有值,其余用存着的;0004 的 4.5),
|
|
279
|
+
* 没声明的变量照旧直接写进去
|
|
280
|
+
*/
|
|
281
|
+
function applySubmission(
|
|
282
|
+
exec: Execution,
|
|
283
|
+
node: TaskNode,
|
|
284
|
+
submitted: Readonly<Record<string, unknown>> = {},
|
|
285
|
+
{ required }: { readonly required: boolean },
|
|
286
|
+
): void {
|
|
287
|
+
const manifest = formManifest(exec.definition);
|
|
288
|
+
const declared = Object.keys(manifest);
|
|
289
|
+
const others = Object.fromEntries(
|
|
290
|
+
Object.entries(submitted).filter(([name]) => !declared.includes(name)),
|
|
291
|
+
);
|
|
292
|
+
if (declared.length > 0) {
|
|
293
|
+
const states = fieldStates(manifest, { access: node.form, read: exec.read });
|
|
294
|
+
const { values, errors } = submit(
|
|
295
|
+
manifest,
|
|
296
|
+
states,
|
|
297
|
+
exec.variables,
|
|
298
|
+
submitted,
|
|
299
|
+
options.extensions?.fieldTypes,
|
|
300
|
+
);
|
|
301
|
+
throwFormErrors(manifest, required ? errors : errors.filter((e) => e.code !== 'required'));
|
|
302
|
+
exec.setVariables(values);
|
|
303
|
+
}
|
|
304
|
+
if (Object.keys(others).length > 0) exec.setVariables(others);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function advanceFromTask(
|
|
308
|
+
exec: Execution,
|
|
309
|
+
node: TaskNode,
|
|
310
|
+
key: string,
|
|
311
|
+
returnTo?: string,
|
|
312
|
+
): Promise<void> {
|
|
313
|
+
const outcome = node.outcomes.find((o) => o.key === key)!;
|
|
314
|
+
const kind = outcome.kind ?? 'approve';
|
|
315
|
+
if (kind === 'terminate') return exec.finish('terminated', outcome.result ?? key);
|
|
316
|
+
if (kind === 'return' && outcome.target === 'choose') {
|
|
317
|
+
if (!returnTo) {
|
|
318
|
+
throw new FlowError('invalid-input', '退回要选退回到哪个节点', {
|
|
319
|
+
field: 'returnTo',
|
|
320
|
+
code: 'required',
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (!returnTargets(exec, node.id).includes(returnTo)) {
|
|
324
|
+
throw new FlowError('invalid-input', `${returnTo} 不是上游走到过的人工节点`, {
|
|
325
|
+
field: 'returnTo',
|
|
326
|
+
code: 'not-upstream',
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
const target = exec.graph.node(returnTo);
|
|
330
|
+
if (
|
|
331
|
+
!target ||
|
|
332
|
+
target.type !== 'task' ||
|
|
333
|
+
!exec.state.rounds[target.id] ||
|
|
334
|
+
target.id === node.id
|
|
335
|
+
) {
|
|
336
|
+
throw new FlowError(
|
|
337
|
+
'invalid-input',
|
|
338
|
+
`退回的目标 ${returnTo ?? '(没写)'} 不是走过的人工节点`,
|
|
339
|
+
{
|
|
340
|
+
field: 'returnTo',
|
|
341
|
+
},
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
exec.state.returnedFrom[target.id] = node.id;
|
|
345
|
+
exec.addEvent('node.left', { node: node.id, outcome: key, data: { returnTo: target.id } });
|
|
346
|
+
await exec.leaveRegions(node.id, target.id);
|
|
347
|
+
return exec.enter(target.id, 'return');
|
|
348
|
+
}
|
|
349
|
+
// 被退回后重新提交:退回它的节点写了 returnTo: 'resubmit' 时直接回到那里,不再从头走
|
|
350
|
+
const returnedFrom = exec.state.returnedFrom[node.id];
|
|
351
|
+
delete exec.state.returnedFrom[node.id];
|
|
352
|
+
const returner = returnedFrom ? exec.graph.node(returnedFrom) : undefined;
|
|
353
|
+
if (kind === 'approve' && returner?.type === 'task' && returner.returnTo === 'resubmit') {
|
|
354
|
+
exec.addEvent('node.left', {
|
|
355
|
+
node: node.id,
|
|
356
|
+
outcome: key,
|
|
357
|
+
data: { resubmitTo: returner.id },
|
|
358
|
+
});
|
|
359
|
+
return exec.enter(returner.id, 'resubmit');
|
|
360
|
+
}
|
|
361
|
+
return exec.leave(node.id, key);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return { complete, finishItem, signerDone, settleParent, applySubmission, advanceFromTask };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** createTasks 给出的函数 */
|
|
368
|
+
export type Tasks = ReturnType<typeof createTasks>;
|