gbflowengine 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +271 -3
- package/dist/gbflowengine.css +1 -0
- package/dist/gbflowengine.js +18363 -0
- package/dist/gbflowengine.js.map +1 -0
- package/dist/gbflowengine.umd.cjs +5 -0
- package/dist/gbflowengine.umd.cjs.map +1 -0
- package/package.json +84 -6
- package/src/center/DefinitionInspect.vue +291 -0
- package/src/center/FlowCenter.vue +33 -0
- package/src/center/index.js +29 -0
- package/src/center/storage.js +748 -0
- package/src/core/flow/condition.js +160 -0
- package/src/core/flow/customNode.js +385 -0
- package/src/core/flow/defaults.js +124 -0
- package/src/core/flow/flowConstant.js +265 -0
- package/src/core/flow/flowNodeUtils.js +30 -0
- package/src/core/flow/index.js +47 -0
- package/src/core/flow/node.js +44 -0
- package/src/core/flow/nodeFactory.js +58 -0
- package/src/core/flow/prediction.js +325 -0
- package/src/core/flow/runtime/auto.js +83 -0
- package/src/core/flow/runtime/decide.js +329 -0
- package/src/core/flow/runtime/event.js +28 -0
- package/src/core/flow/runtime/execute.js +357 -0
- package/src/core/flow/runtime/helpers.js +52 -0
- package/src/core/flow/runtime/query.js +146 -0
- package/src/core/flow/runtime/reject.js +137 -0
- package/src/core/flow/runtime/token.js +269 -0
- package/src/core/flow/runtime.js +129 -0
- package/src/core/flow/schema.js +864 -0
- package/src/definition/FlowDefinitionDesigner.vue +338 -0
- package/src/definition/index.js +9 -0
- package/src/index.js +39 -0
- package/src/storage.js +200 -0
- package/src/testing/FlowTestPanel.vue +2502 -0
- package/src/testing/UserConfigDrawer.vue +376 -0
- package/src/testing/diagram/FlowProgressDiagram.vue +318 -0
- package/src/testing/diagramModel.js +517 -0
- package/src/testing/index.js +23 -0
- package/src/testing/mock.js +246 -0
- package/src/testing/oaExecutors.js +51 -0
- package/src/testing/oaSeed.js +467 -0
- package/src/testing/sample.js +412 -0
- package/src/testing/seed.js +122 -0
- package/src/utils/format.js +27 -0
- package/src/visual/FlowCanvas.vue +441 -0
- package/src/visual/NodeProgressDetail.vue +43 -0
- package/src/visual/NodeStatusBadge.vue +17 -0
- package/src/visual/NodeWrap.vue +47 -0
- package/src/visual/ScWorkflow.vue +50 -0
- package/src/visual/SelectDialog.vue +460 -0
- package/src/visual/conditionHelpers.js +117 -0
- package/src/visual/index.js +6 -0
- package/src/visual/nodes/AddNode.vue +223 -0
- package/src/visual/nodes/ApproverNode.vue +348 -0
- package/src/visual/nodes/BranchNode.vue +442 -0
- package/src/visual/nodes/CustomNode.vue +339 -0
- package/src/visual/nodes/EndNode.vue +22 -0
- package/src/visual/nodes/PassNode.vue +101 -0
- package/src/visual/nodes/PromoterNode.vue +135 -0
- package/src/visual/nodes/RejectNode.vue +101 -0
- package/src/visual/nodes/SendNode.vue +152 -0
- package/src/visual/styles.scss +879 -0
- package/src/visual/useScNodeStatus.js +18 -0
- package/src/workbench/OaWorkbench.vue +1341 -0
- package/src/workbench/components/ApprovalWorkspace.vue +2090 -0
- package/src/workbench/components/CategoryIcon.vue +74 -0
- package/src/workbench/components/NotificationIcon.vue +73 -0
- package/src/workbench/components/ProcessSteps.vue +557 -0
- package/src/workbench/components/ResubmitDialog.vue +227 -0
- package/src/workbench/components/SidebarNav.vue +138 -0
- package/src/workbench/components/StartFlowDialog.vue +1058 -0
- package/src/workbench/components/UserAvatar.vue +68 -0
- package/src/workbench/custom-tasks.js +130 -0
- package/src/workbench/model.js +1080 -0
- package/src/workbench/pages/DesignPage.vue +798 -0
- package/src/workbench/pages/HomePage.vue +1050 -0
- package/src/workbench/pages/MonitorPage.vue +1029 -0
- package/src/workbench/pages/NotificationsPage.vue +554 -0
- package/src/workbench/pages/RequestsPage.vue +644 -0
- package/src/workbench/pages/TaskCenterPage.vue +1155 -0
- package/src/workbench/pages/TemplatesPage.vue +680 -0
- package/src/workbench/persistence.js +89 -0
- package/src/workbench/shared.js +18 -0
- package/src/workbench/styles.scss +555 -0
- package/src/workbench/useWorkbench.js +955 -0
- package/types/center.d.ts +5 -0
- package/types/core.d.ts +479 -0
- package/types/definition.d.ts +4 -0
- package/types/index.d.ts +34 -0
- package/types/testing.d.ts +20 -0
- package/types/visual.d.ts +20 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// [文件] gbflowengine·runtime·token —— 令牌流转 —— 分支拆分、汇聚点进出、完成判定
|
|
2
|
+
|
|
3
|
+
// [设计] 方法以对象字面量导出,由 runtime.js 末尾 Object.assign 装配到 FlowRuntime.prototype(同一 this,调用形状不变)。
|
|
4
|
+
|
|
5
|
+
import { RUNNING, COMPLETED } from './helpers.js'
|
|
6
|
+
export const tokenMethods = {
|
|
7
|
+
|
|
8
|
+
_split(node, token, branches) {
|
|
9
|
+
const validBranches = branches.filter(Boolean)
|
|
10
|
+
const joinTarget = node.childNode ? node.childNode.nodeId : null
|
|
11
|
+
const groupId = `${node.nodeId}:${this.seq.token}`
|
|
12
|
+
let expected = validBranches.length
|
|
13
|
+
|
|
14
|
+
this.state.tokens = this.state.tokens.filter((item) => item.id !== token.id)
|
|
15
|
+
|
|
16
|
+
const group =
|
|
17
|
+
joinTarget !== null
|
|
18
|
+
? {
|
|
19
|
+
groupId,
|
|
20
|
+
targetId: joinTarget,
|
|
21
|
+
expected,
|
|
22
|
+
waiting: [],
|
|
23
|
+
createdBy: node.nodeId,
|
|
24
|
+
continuations: [...token.continuations]
|
|
25
|
+
}
|
|
26
|
+
: null
|
|
27
|
+
if (group) {
|
|
28
|
+
this.joinGroups.set(groupId, group)
|
|
29
|
+
token.continuations = []
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
validBranches.forEach((branch) => {
|
|
33
|
+
const childToken = this._createToken(branch.childNode ? branch.childNode.nodeId : null)
|
|
34
|
+
childToken.joins = [
|
|
35
|
+
...token.joins,
|
|
36
|
+
...(group
|
|
37
|
+
? [
|
|
38
|
+
{
|
|
39
|
+
groupId,
|
|
40
|
+
targetId: joinTarget,
|
|
41
|
+
expected,
|
|
42
|
+
createdBy: node.nodeId,
|
|
43
|
+
continuations: [...group.continuations]
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
: [])
|
|
47
|
+
]
|
|
48
|
+
childToken.continuations = group ? [] : []
|
|
49
|
+
if (!branch.childNode) {
|
|
50
|
+
if (group) {
|
|
51
|
+
// An empty branch still counts towards the join.
|
|
52
|
+
group.waiting.push(childToken)
|
|
53
|
+
childToken.blockedJoinGroup = groupId
|
|
54
|
+
childToken.nodeId = joinTarget
|
|
55
|
+
} else {
|
|
56
|
+
childToken.joins = token.joins
|
|
57
|
+
childToken.nodeId = null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this.state.tokens.push(childToken)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
this.state.history.push(
|
|
64
|
+
this._event('split', {
|
|
65
|
+
nodeId: node.nodeId,
|
|
66
|
+
branchIds: validBranches.map((branch) => branch.nodeId),
|
|
67
|
+
type: node.type
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
if (group && group.waiting.length >= expected) {
|
|
72
|
+
this._releaseJoin(group)
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
_placeAt(token, nodeId) {
|
|
77
|
+
if (nodeId === null || nodeId === undefined) {
|
|
78
|
+
this._nextAfterChain(token)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
token.nodeId = nodeId
|
|
82
|
+
const join = token.joins[token.joins.length - 1]
|
|
83
|
+
if (join && join.targetId !== null && String(join.targetId) === String(nodeId)) {
|
|
84
|
+
this._arriveAtJoin(token)
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
this._step(token)
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
_advanceTo(token, nodeId) {
|
|
91
|
+
if (nodeId === null || nodeId === undefined) {
|
|
92
|
+
this._nextAfterChain(token)
|
|
93
|
+
} else {
|
|
94
|
+
this._placeAt(token, nodeId)
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
_advanceFrom(node, token) {
|
|
99
|
+
if (node.childNode) {
|
|
100
|
+
this._placeAt(token, node.childNode.nodeId)
|
|
101
|
+
} else {
|
|
102
|
+
this._nextAfterChain(token)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
_nextAfterChain(token) {
|
|
107
|
+
if (token.continuations.length) {
|
|
108
|
+
const next = token.continuations.pop()
|
|
109
|
+
this._advanceTo(token, next)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
const join = token.joins[token.joins.length - 1]
|
|
113
|
+
if (join) {
|
|
114
|
+
if (join.targetId !== null) {
|
|
115
|
+
token.nodeId = join.targetId
|
|
116
|
+
this._arriveAtJoin(token)
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
token.joins = token.joins.slice(0, -1)
|
|
120
|
+
if (token.joins.length) {
|
|
121
|
+
this._nextAfterChain(token)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this._finishToken(token)
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Join groups are runtime-only in earlier snapshots; rebuild them from the
|
|
130
|
+
* join descriptors persisted on each token so a restored instance does not
|
|
131
|
+
* silently skip the node after a parallel split.
|
|
132
|
+
*/
|
|
133
|
+
_restoreJoinGroups() {
|
|
134
|
+
this.joinGroups.clear()
|
|
135
|
+
;(this.state.tokens || []).forEach((token) => {
|
|
136
|
+
;(token.joins || []).forEach((join) => {
|
|
137
|
+
if (!join || join.groupId === undefined || join.groupId === null) return
|
|
138
|
+
if (join.targetId === null || join.targetId === undefined) return
|
|
139
|
+
let group = this.joinGroups.get(join.groupId)
|
|
140
|
+
if (!group) {
|
|
141
|
+
group = {
|
|
142
|
+
groupId: join.groupId,
|
|
143
|
+
targetId: join.targetId,
|
|
144
|
+
expected: Math.max(1, Number(join.expected) || 1),
|
|
145
|
+
waiting: [],
|
|
146
|
+
createdBy:
|
|
147
|
+
join.createdBy ?? (String(join.groupId).includes(':')
|
|
148
|
+
? String(join.groupId).slice(0, String(join.groupId).lastIndexOf(':'))
|
|
149
|
+
: null),
|
|
150
|
+
continuations: Array.isArray(join.continuations) ? [...join.continuations] : []
|
|
151
|
+
}
|
|
152
|
+
this.joinGroups.set(join.groupId, group)
|
|
153
|
+
}
|
|
154
|
+
if (
|
|
155
|
+
String(token.blockedJoinGroup) === String(join.groupId) &&
|
|
156
|
+
!group.waiting.some((item) => item.id === token.id)
|
|
157
|
+
) {
|
|
158
|
+
group.waiting.push(token)
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
_releaseReadyJoins() {
|
|
165
|
+
const ready = [...this.joinGroups.values()].filter(
|
|
166
|
+
(group) => group.waiting.length >= group.expected
|
|
167
|
+
)
|
|
168
|
+
ready.forEach((group) => {
|
|
169
|
+
if (this.joinGroups.has(group.groupId)) this._releaseJoin(group)
|
|
170
|
+
})
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
_arriveAtJoin(token) {
|
|
174
|
+
const join = token.joins[token.joins.length - 1]
|
|
175
|
+
const group = this.joinGroups.get(join.groupId)
|
|
176
|
+
if (!group) {
|
|
177
|
+
this._warn('JOIN_GROUP_MISSING', `分支汇聚组 ${join.groupId} 不存在,流程已暂停以避免跳过节点`)
|
|
178
|
+
token.blockedJoinGroup = join.groupId
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
if (!group.waiting.some((item) => item.id === token.id)) {
|
|
182
|
+
group.waiting.push(token)
|
|
183
|
+
}
|
|
184
|
+
token.blockedJoinGroup = join.groupId
|
|
185
|
+
if (group.waiting.length >= group.expected) {
|
|
186
|
+
this._releaseJoin(group)
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
_releaseJoin(group) {
|
|
191
|
+
const [first, ...rest] = group.waiting
|
|
192
|
+
rest.forEach((token) => {
|
|
193
|
+
token.blockedJoinGroup = null
|
|
194
|
+
this.state.tokens = this.state.tokens.filter((item) => item.id !== token.id)
|
|
195
|
+
})
|
|
196
|
+
this.joinGroups.delete(group.groupId)
|
|
197
|
+
if (!first) return
|
|
198
|
+
first.blockedJoinGroup = null
|
|
199
|
+
first.joins = first.joins.filter((join) => join.groupId !== group.groupId)
|
|
200
|
+
first.continuations = [...(group.continuations || []), ...first.continuations]
|
|
201
|
+
first.nodeId = group.targetId
|
|
202
|
+
this.state.history.push(
|
|
203
|
+
this._event('join', { nodeId: group.createdBy, targetId: group.targetId })
|
|
204
|
+
)
|
|
205
|
+
this._emit('onJoin', {
|
|
206
|
+
runtime: this,
|
|
207
|
+
groupId: group.groupId,
|
|
208
|
+
targetId: group.targetId
|
|
209
|
+
})
|
|
210
|
+
this._step(first)
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
_finishToken(token) {
|
|
214
|
+
this.state.tokens = this.state.tokens.filter((item) => item.id !== token.id)
|
|
215
|
+
const join = token.joins[token.joins.length - 1]
|
|
216
|
+
if (join) {
|
|
217
|
+
const group = this.joinGroups.get(join.groupId)
|
|
218
|
+
if (group && !group.waiting.some((item) => item.id === token.id)) {
|
|
219
|
+
group.waiting.push(token)
|
|
220
|
+
if (group.waiting.length >= group.expected) {
|
|
221
|
+
this._releaseJoin(group)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
_checkFinished() {
|
|
228
|
+
if (this.state.status !== RUNNING) return
|
|
229
|
+
const orphanedJoins = this.state.tokens.filter(
|
|
230
|
+
(token) => token.blockedJoinGroup && !this.joinGroups.has(token.blockedJoinGroup)
|
|
231
|
+
)
|
|
232
|
+
if (orphanedJoins.length) {
|
|
233
|
+
this._warn(
|
|
234
|
+
'JOIN_STATE_MISSING',
|
|
235
|
+
'检测到等待中的分支汇聚组缺失,流程保持运行中,请检查实例存档'
|
|
236
|
+
)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
const hasActiveTokens = this.state.tokens.length > 0
|
|
240
|
+
const hasPendingTasks = this.state.tasks.some((task) => task.status === 'pending')
|
|
241
|
+
if (!hasActiveTokens && !hasPendingTasks) {
|
|
242
|
+
this._finishFlow(COMPLETED)
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
_finishFlow(status) {
|
|
247
|
+
this.state.status = status
|
|
248
|
+
this.state.endedAt = new Date().toISOString()
|
|
249
|
+
this.state.tasks.forEach((task) => {
|
|
250
|
+
if (task.status === 'pending' && status !== COMPLETED) task.status = 'cancelled'
|
|
251
|
+
})
|
|
252
|
+
this.state.tokens = []
|
|
253
|
+
this.joinGroups.clear()
|
|
254
|
+
this.state.history.push(this._event('finished', { status }))
|
|
255
|
+
this._emit('onFinished', { runtime: this, status, state: this.getState() })
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
_createToken(nodeId) {
|
|
259
|
+
this.seq.token += 1
|
|
260
|
+
return {
|
|
261
|
+
id: `token_${this.seq.token}`,
|
|
262
|
+
nodeId,
|
|
263
|
+
continuations: [],
|
|
264
|
+
joins: [],
|
|
265
|
+
blockedTaskId: null,
|
|
266
|
+
blockedJoinGroup: null
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// [文件] gbflowengine·FlowRuntime —— 流程运行时(对外入口)
|
|
2
|
+
//
|
|
3
|
+
// [设计] 1455 行单类按职责拆到 ./runtime/*:helpers(常量与纯工具)/ query(状态查询与审批人解析)/
|
|
4
|
+
// decide(发起·审批·转办·加签·重提·撤销)/ execute(执行内核)/ token(令牌流转与汇聚)/
|
|
5
|
+
// reject(驳回与重提)/ auto(自动推进)/ event(事件与告警)。
|
|
6
|
+
// 各模块以对象字面量导出方法组,由本文件末尾 Object.assign 装配到 FlowRuntime.prototype ——
|
|
7
|
+
// 仍是同一个 this、同一套私有方法调用,调用方形状与拆分前完全一致。
|
|
8
|
+
// [坑] 装配必须发生在任何实例创建之前:Object.assign 在模块求值时执行,而实例只能在 import 之后 new。
|
|
9
|
+
|
|
10
|
+
import { FlowNodeType } from './flowConstant.js'
|
|
11
|
+
import { selectBranchNode, selectInclusiveBranches } from './condition.js'
|
|
12
|
+
import { clone, deriveCycle, maxIdSuffix, RUNNING, IDLE, COMPLETED, REJECTED, CANCELLED, REVOKED } from './runtime/helpers.js'
|
|
13
|
+
import { queryMethods } from './runtime/query.js'
|
|
14
|
+
import { decideMethods } from './runtime/decide.js'
|
|
15
|
+
import { executeMethods } from './runtime/execute.js'
|
|
16
|
+
import { tokenMethods } from './runtime/token.js'
|
|
17
|
+
import { rejectMethods } from './runtime/reject.js'
|
|
18
|
+
import { autoMethods } from './runtime/auto.js'
|
|
19
|
+
import { eventMethods } from './runtime/event.js'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A deterministic, storage-agnostic workflow runtime. It is intentionally
|
|
23
|
+
* UI-free so the same engine can run in a browser, a worker, or tests.
|
|
24
|
+
* The runtime only mutates its own state; the workflow definition is cloned.
|
|
25
|
+
*/
|
|
26
|
+
export class FlowRuntime {
|
|
27
|
+
constructor({ workflow, data = {}, context = {}, state = null, handlers = null } = {}) {
|
|
28
|
+
if (!workflow) throw new Error('FlowRuntime: workflow is required')
|
|
29
|
+
this.workflow = clone(workflow)
|
|
30
|
+
this.context = context || {}
|
|
31
|
+
this.handlers = handlers || this.context.handlers || {}
|
|
32
|
+
this.nodeIndex = new Map()
|
|
33
|
+
this.parentIndex = new Map()
|
|
34
|
+
this.joinGroups = new Map()
|
|
35
|
+
this.seq = { token: 0, task: 0, cc: 0, event: 0 }
|
|
36
|
+
this._indexTree(this.workflow, null)
|
|
37
|
+
this.state = state
|
|
38
|
+
? clone(state)
|
|
39
|
+
: {
|
|
40
|
+
status: IDLE,
|
|
41
|
+
initiator: null,
|
|
42
|
+
tokens: [],
|
|
43
|
+
tasks: [],
|
|
44
|
+
ccRecords: [],
|
|
45
|
+
history: [],
|
|
46
|
+
variables: clone(data),
|
|
47
|
+
warnings: [],
|
|
48
|
+
startedAt: null,
|
|
49
|
+
endedAt: null
|
|
50
|
+
}
|
|
51
|
+
this.state.cycle = deriveCycle(this.state)
|
|
52
|
+
if (this.state.startedAt) {
|
|
53
|
+
this.seq.token = Math.max(this.seq.token, maxIdSuffix(this.state.tokens, 'token_'))
|
|
54
|
+
this.seq.task = Math.max(this.seq.task, maxIdSuffix(this.state.tasks, 'task_'))
|
|
55
|
+
this.seq.cc = Math.max(this.seq.cc, maxIdSuffix(this.state.ccRecords, 'cc_'))
|
|
56
|
+
this.seq.event = Math.max(this.seq.event, maxIdSuffix(this.state.history, 'event_'))
|
|
57
|
+
}
|
|
58
|
+
this._restoreJoinGroups()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static restore({ workflow, state, context = {}, handlers = null }) {
|
|
62
|
+
return new FlowRuntime({ workflow, state, context, handlers })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_indexTree(node, parent) {
|
|
66
|
+
if (!node) return
|
|
67
|
+
this.nodeIndex.set(String(node.nodeId), node)
|
|
68
|
+
this.parentIndex.set(String(node.nodeId), parent)
|
|
69
|
+
if (node.childNode) this._indexTree(node.childNode, node)
|
|
70
|
+
node.branchList?.forEach((branch) => this._indexTree(branch, node))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Object.assign(
|
|
75
|
+
FlowRuntime.prototype,
|
|
76
|
+
queryMethods,
|
|
77
|
+
decideMethods,
|
|
78
|
+
executeMethods,
|
|
79
|
+
tokenMethods,
|
|
80
|
+
rejectMethods,
|
|
81
|
+
autoMethods,
|
|
82
|
+
eventMethods
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
export function createFlowRuntime(options) {
|
|
86
|
+
return new FlowRuntime(options)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Evaluates all branch node conditions without executing business nodes.
|
|
91
|
+
* Useful for previewing which paths a form submission will take.
|
|
92
|
+
*/
|
|
93
|
+
export function evaluateBranches(workflow, data = {}) {
|
|
94
|
+
const result = []
|
|
95
|
+
const visit = (node) => {
|
|
96
|
+
if (!node) return
|
|
97
|
+
if (node.type === FlowNodeType.BRANCH) {
|
|
98
|
+
const selected = selectBranchNode(node, data)
|
|
99
|
+
result.push({
|
|
100
|
+
nodeId: node.nodeId,
|
|
101
|
+
nodeName: node.nodeName,
|
|
102
|
+
type: node.type,
|
|
103
|
+
selectedBranchId: selected?.nodeId ?? null,
|
|
104
|
+
selectedBranchName: selected?.nodeName ?? null
|
|
105
|
+
})
|
|
106
|
+
} else if (node.type === FlowNodeType.INCLUSIVE) {
|
|
107
|
+
const selected = selectInclusiveBranches(node, data)
|
|
108
|
+
result.push({
|
|
109
|
+
nodeId: node.nodeId,
|
|
110
|
+
nodeName: node.nodeName,
|
|
111
|
+
type: node.type,
|
|
112
|
+
selectedBranchIds: selected.map((branch) => branch.nodeId)
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
if (node.childNode) visit(node.childNode)
|
|
116
|
+
node.branchList?.forEach(visit)
|
|
117
|
+
}
|
|
118
|
+
visit(workflow)
|
|
119
|
+
return result
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
RUNNING as RUNTIME_RUNNING,
|
|
124
|
+
COMPLETED as RUNTIME_COMPLETED,
|
|
125
|
+
REJECTED as RUNTIME_REJECTED,
|
|
126
|
+
CANCELLED as RUNTIME_CANCELLED,
|
|
127
|
+
REVOKED as RUNTIME_REVOKED,
|
|
128
|
+
IDLE as RUNTIME_IDLE
|
|
129
|
+
}
|