@bpmnkit/core 1.0.0 → 1.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/README.md +25 -3
- package/dist/bpmn/agentic.js +3 -1
- package/dist/bpmn/auto-layout.js +184 -15
- package/dist/bpmn/bpmn-builder.js +69 -7
- package/dist/bpmn/bpmn-model.d.ts +78 -0
- package/dist/bpmn/bpmn-parser.js +195 -37
- package/dist/bpmn/bpmn-serializer.js +121 -72
- package/dist/bpmn/bpmnlint.d.ts +153 -0
- package/dist/bpmn/bpmnlint.js +364 -0
- package/dist/bpmn/camunda-compat-data.d.ts +165 -0
- package/dist/bpmn/camunda-compat-data.js +423 -0
- package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
- package/dist/bpmn/camunda-compat-feel.js +338 -0
- package/dist/bpmn/camunda-compat.d.ts +120 -0
- package/dist/bpmn/camunda-compat.js +1677 -0
- package/dist/bpmn/camunda7/juel.d.ts +41 -0
- package/dist/bpmn/camunda7/juel.js +333 -0
- package/dist/bpmn/camunda7/migrate.d.ts +72 -0
- package/dist/bpmn/camunda7/migrate.js +1152 -0
- package/dist/bpmn/full-operations.js +5 -2
- package/dist/bpmn/label-style.d.ts +51 -0
- package/dist/bpmn/label-style.js +116 -0
- package/dist/bpmn/lint.d.ts +23 -3
- package/dist/bpmn/lint.js +47 -10
- package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
- package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
- package/dist/bpmn/optimize/deploy.d.ts +8 -2
- package/dist/bpmn/optimize/deploy.js +16 -3
- package/dist/bpmn/optimize/index.js +11 -2
- package/dist/bpmn/optimize/types.d.ts +14 -0
- package/dist/bpmn/optimize/variable-flow.js +4 -1
- package/dist/bpmn/process-types.d.ts +112 -0
- package/dist/bpmn/process-types.js +490 -0
- package/dist/bpmn/svg.js +51 -22
- package/dist/doc/docx.d.ts +20 -0
- package/dist/doc/docx.js +253 -0
- package/dist/doc/html.d.ts +21 -0
- package/dist/doc/html.js +303 -0
- package/dist/doc/index.d.ts +7 -0
- package/dist/doc/index.js +5 -0
- package/dist/doc/markdown.d.ts +11 -0
- package/dist/doc/markdown.js +160 -0
- package/dist/doc/model.d.ts +129 -0
- package/dist/doc/model.js +617 -0
- package/dist/doc/zip.d.ts +5 -0
- package/dist/doc/zip.js +75 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +8 -0
- package/dist/layout/annotations.d.ts +4 -2
- package/dist/layout/annotations.js +31 -2
- package/dist/layout/collaboration/ordering.d.ts +8 -0
- package/dist/layout/collaboration/ordering.js +57 -18
- package/dist/layout/orthogonal.d.ts +32 -0
- package/dist/layout/orthogonal.js +367 -0
- package/dist/layout/repair.d.ts +31 -0
- package/dist/layout/repair.js +220 -0
- package/dist/layout/semantic/route.js +45 -3
- package/dist/node/bpmnlint.d.ts +109 -0
- package/dist/node/bpmnlint.js +198 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/xml/xml-patch.d.ts +21 -0
- package/dist/xml/xml-patch.js +27 -1
- package/package.json +2 -2
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
import { exportSvg } from "../bpmn/svg.js";
|
|
2
|
+
// ── Labels ───────────────────────────────────────────────────────────────────
|
|
3
|
+
const TYPE_LABELS = {
|
|
4
|
+
startEvent: "Start event",
|
|
5
|
+
endEvent: "End event",
|
|
6
|
+
intermediateThrowEvent: "Intermediate throw event",
|
|
7
|
+
intermediateCatchEvent: "Intermediate catch event",
|
|
8
|
+
boundaryEvent: "Boundary event",
|
|
9
|
+
task: "Task",
|
|
10
|
+
serviceTask: "Service task",
|
|
11
|
+
scriptTask: "Script task",
|
|
12
|
+
userTask: "User task",
|
|
13
|
+
sendTask: "Send task",
|
|
14
|
+
receiveTask: "Receive task",
|
|
15
|
+
businessRuleTask: "Business rule task",
|
|
16
|
+
manualTask: "Manual task",
|
|
17
|
+
callActivity: "Call activity",
|
|
18
|
+
exclusiveGateway: "Exclusive gateway",
|
|
19
|
+
parallelGateway: "Parallel gateway",
|
|
20
|
+
inclusiveGateway: "Inclusive gateway",
|
|
21
|
+
eventBasedGateway: "Event-based gateway",
|
|
22
|
+
complexGateway: "Complex gateway",
|
|
23
|
+
subProcess: "Sub-process",
|
|
24
|
+
adHocSubProcess: "Ad-hoc sub-process",
|
|
25
|
+
eventSubProcess: "Event sub-process",
|
|
26
|
+
transaction: "Transaction",
|
|
27
|
+
dataObject: "Data object",
|
|
28
|
+
dataObjectReference: "Data object",
|
|
29
|
+
dataStoreReference: "Data store",
|
|
30
|
+
};
|
|
31
|
+
const EVENT_KIND = {
|
|
32
|
+
timer: "Timer",
|
|
33
|
+
error: "Error",
|
|
34
|
+
escalation: "Escalation",
|
|
35
|
+
message: "Message",
|
|
36
|
+
signal: "Signal",
|
|
37
|
+
conditional: "Conditional",
|
|
38
|
+
link: "Link",
|
|
39
|
+
cancel: "Cancel",
|
|
40
|
+
terminate: "Terminate",
|
|
41
|
+
compensate: "Compensation",
|
|
42
|
+
};
|
|
43
|
+
function eventDefinitionsOf(el) {
|
|
44
|
+
return "eventDefinitions" in el ? el.eventDefinitions : [];
|
|
45
|
+
}
|
|
46
|
+
function typeLabelOf(el) {
|
|
47
|
+
const base = TYPE_LABELS[el.type];
|
|
48
|
+
const defs = eventDefinitionsOf(el);
|
|
49
|
+
const first = defs[0];
|
|
50
|
+
let label = base;
|
|
51
|
+
if (first) {
|
|
52
|
+
const kind = defs.length > 1 ? "Multiple" : EVENT_KIND[first.type];
|
|
53
|
+
label = `${kind} ${base.charAt(0).toLowerCase()}${base.slice(1)}`;
|
|
54
|
+
}
|
|
55
|
+
if (el.type === "boundaryEvent" && el.cancelActivity === false)
|
|
56
|
+
label += " (non-interrupting)";
|
|
57
|
+
if (el.type === "startEvent" && el.isInterrupting === false)
|
|
58
|
+
label += " (non-interrupting)";
|
|
59
|
+
if (el.type === "subProcess" && el.triggeredByEvent)
|
|
60
|
+
label = "Event sub-process";
|
|
61
|
+
return label;
|
|
62
|
+
}
|
|
63
|
+
// ── Raw extension lookups ────────────────────────────────────────────────────
|
|
64
|
+
function localName(name) {
|
|
65
|
+
const i = name.indexOf(":");
|
|
66
|
+
return i >= 0 ? name.slice(i + 1) : name;
|
|
67
|
+
}
|
|
68
|
+
function child(elements, name) {
|
|
69
|
+
return elements?.find((e) => localName(e.name) === name);
|
|
70
|
+
}
|
|
71
|
+
function children(elements, name) {
|
|
72
|
+
return (elements ?? []).filter((e) => localName(e.name) === name);
|
|
73
|
+
}
|
|
74
|
+
function nonEmpty(value) {
|
|
75
|
+
return value !== undefined && value.trim() !== "";
|
|
76
|
+
}
|
|
77
|
+
// ── ISO 8601 durations ───────────────────────────────────────────────────────
|
|
78
|
+
const DURATION_UNITS = [
|
|
79
|
+
[/(\d+(?:\.\d+)?)Y/, "year"],
|
|
80
|
+
[/(\d+(?:\.\d+)?)M/, "month"],
|
|
81
|
+
[/(\d+(?:\.\d+)?)W/, "week"],
|
|
82
|
+
[/(\d+(?:\.\d+)?)D/, "day"],
|
|
83
|
+
];
|
|
84
|
+
const TIME_UNITS = [
|
|
85
|
+
[/(\d+(?:\.\d+)?)H/, "hour"],
|
|
86
|
+
[/(\d+(?:\.\d+)?)M/, "minute"],
|
|
87
|
+
[/(\d+(?:\.\d+)?)S/, "second"],
|
|
88
|
+
];
|
|
89
|
+
/** `PT48H` → `48 hours`. Returns undefined for anything that is not a plain ISO duration. */
|
|
90
|
+
export function humanizeDuration(value) {
|
|
91
|
+
const m = /^P(?!$)([^T]*)(?:T(?=.)(.*))?$/.exec(value.trim());
|
|
92
|
+
if (!m)
|
|
93
|
+
return undefined;
|
|
94
|
+
const date = m[1] ?? "";
|
|
95
|
+
const time = m[2] ?? "";
|
|
96
|
+
if (!/^(\d+(\.\d+)?[YMWD])*$/.test(date) || !/^(\d+(\.\d+)?[HMS])*$/.test(time))
|
|
97
|
+
return undefined;
|
|
98
|
+
const parts = [];
|
|
99
|
+
const push = (n, unit) => parts.push(`${n} ${unit}${n === "1" ? "" : "s"}`);
|
|
100
|
+
for (const [re, unit] of DURATION_UNITS) {
|
|
101
|
+
const hit = re.exec(date);
|
|
102
|
+
if (hit?.[1])
|
|
103
|
+
push(hit[1], unit);
|
|
104
|
+
}
|
|
105
|
+
for (const [re, unit] of TIME_UNITS) {
|
|
106
|
+
const hit = re.exec(time);
|
|
107
|
+
if (hit?.[1])
|
|
108
|
+
push(hit[1], unit);
|
|
109
|
+
}
|
|
110
|
+
return parts.length > 0 ? parts.join(" ") : undefined;
|
|
111
|
+
}
|
|
112
|
+
function describeTimerValue(value) {
|
|
113
|
+
const trimmed = value.trim();
|
|
114
|
+
const plain = humanizeDuration(trimmed);
|
|
115
|
+
if (plain)
|
|
116
|
+
return `${trimmed} (${plain})`;
|
|
117
|
+
const cycle = /^R(\d*)\/(P[^/]+)$/.exec(trimmed);
|
|
118
|
+
const every = cycle?.[2] ? humanizeDuration(cycle[2]) : undefined;
|
|
119
|
+
if (cycle && every) {
|
|
120
|
+
const times = cycle[1] ? `, ${cycle[1]} times` : "";
|
|
121
|
+
return `${trimmed} (every ${every}${times})`;
|
|
122
|
+
}
|
|
123
|
+
return trimmed;
|
|
124
|
+
}
|
|
125
|
+
// ── Flow ordering ────────────────────────────────────────────────────────────
|
|
126
|
+
/**
|
|
127
|
+
* Orders a scope's elements by the flow rather than by the XML.
|
|
128
|
+
*
|
|
129
|
+
* Reverse post-order of a depth-first walk from the start events, with each
|
|
130
|
+
* element's successors visited last-first so the first outgoing branch is
|
|
131
|
+
* printed first and a branch stays together up to its join. Back edges (loops)
|
|
132
|
+
* are ignored by construction. Boundary events follow their host's normal
|
|
133
|
+
* successors. Anything the walk cannot reach — event sub-processes, orphans,
|
|
134
|
+
* data objects — is appended in XML order, each ordered the same way.
|
|
135
|
+
*/
|
|
136
|
+
function flowOrder(elements, flows) {
|
|
137
|
+
const byId = new Map(elements.map((e) => [e.id, e]));
|
|
138
|
+
const successors = new Map();
|
|
139
|
+
for (const e of elements)
|
|
140
|
+
successors.set(e.id, []);
|
|
141
|
+
for (const f of flows) {
|
|
142
|
+
if (byId.has(f.sourceRef) && byId.has(f.targetRef))
|
|
143
|
+
successors.get(f.sourceRef)?.push(f.targetRef);
|
|
144
|
+
}
|
|
145
|
+
for (const e of elements) {
|
|
146
|
+
if (e.type === "boundaryEvent" && byId.has(e.attachedToRef)) {
|
|
147
|
+
successors.get(e.attachedToRef)?.push(e.id);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const visited = new Set();
|
|
151
|
+
const walk = (roots) => {
|
|
152
|
+
const post = [];
|
|
153
|
+
// Iterative DFS: a deep process must not blow the stack.
|
|
154
|
+
for (const root of [...roots].reverse()) {
|
|
155
|
+
if (visited.has(root))
|
|
156
|
+
continue;
|
|
157
|
+
visited.add(root);
|
|
158
|
+
const stack = [
|
|
159
|
+
{ id: root, next: [...(successors.get(root) ?? [])] },
|
|
160
|
+
];
|
|
161
|
+
while (stack.length > 0) {
|
|
162
|
+
const top = stack[stack.length - 1];
|
|
163
|
+
if (!top)
|
|
164
|
+
break;
|
|
165
|
+
const nextId = top.next.pop();
|
|
166
|
+
if (nextId === undefined) {
|
|
167
|
+
post.push(top.id);
|
|
168
|
+
stack.pop();
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (visited.has(nextId))
|
|
172
|
+
continue;
|
|
173
|
+
visited.add(nextId);
|
|
174
|
+
stack.push({ id: nextId, next: [...(successors.get(nextId) ?? [])] });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return post.reverse().flatMap((id) => byId.get(id) ?? []);
|
|
178
|
+
};
|
|
179
|
+
const starts = elements.filter((e) => e.type === "startEvent").map((e) => e.id);
|
|
180
|
+
const ordered = walk(starts);
|
|
181
|
+
for (const e of elements) {
|
|
182
|
+
if (!visited.has(e.id))
|
|
183
|
+
ordered.push(...walk([e.id]));
|
|
184
|
+
}
|
|
185
|
+
return ordered;
|
|
186
|
+
}
|
|
187
|
+
function isScope(el) {
|
|
188
|
+
return "flowElements" in el;
|
|
189
|
+
}
|
|
190
|
+
function displayName(el) {
|
|
191
|
+
return nonEmpty(el.name) ? el.name.trim() : el.id;
|
|
192
|
+
}
|
|
193
|
+
function collectNames(elements, into) {
|
|
194
|
+
for (const el of elements) {
|
|
195
|
+
into.set(el.id, displayName(el));
|
|
196
|
+
if (isScope(el))
|
|
197
|
+
collectNames(el.flowElements, into);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function laneMapOf(laneSet) {
|
|
201
|
+
const lanes = [];
|
|
202
|
+
const byElement = new Map();
|
|
203
|
+
const visit = (set, path) => {
|
|
204
|
+
for (const lane of set?.lanes ?? []) {
|
|
205
|
+
const name = displayName(lane);
|
|
206
|
+
lanes.push({
|
|
207
|
+
id: lane.id,
|
|
208
|
+
name,
|
|
209
|
+
path,
|
|
210
|
+
documentation: lane.documentation,
|
|
211
|
+
refs: lane.flowNodeRefs,
|
|
212
|
+
});
|
|
213
|
+
// Inner lanes are visited after, so the innermost lane wins.
|
|
214
|
+
for (const ref of lane.flowNodeRefs)
|
|
215
|
+
byElement.set(ref, name);
|
|
216
|
+
visit(lane.childLaneSet, [...path, name]);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
visit(laneSet, []);
|
|
220
|
+
return { lanes, byElement };
|
|
221
|
+
}
|
|
222
|
+
function describeEventDefinition(def, ctx) {
|
|
223
|
+
const out = [];
|
|
224
|
+
switch (def.type) {
|
|
225
|
+
case "timer": {
|
|
226
|
+
if (nonEmpty(def.timeDuration))
|
|
227
|
+
out.push({ label: "Timer duration", value: describeTimerValue(def.timeDuration) });
|
|
228
|
+
if (nonEmpty(def.timeDate))
|
|
229
|
+
out.push({ label: "Timer date", value: def.timeDate.trim() });
|
|
230
|
+
if (nonEmpty(def.timeCycle))
|
|
231
|
+
out.push({ label: "Timer cycle", value: describeTimerValue(def.timeCycle) });
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case "message": {
|
|
235
|
+
const msg = ctx.defs.messages.find((m) => m.id === def.messageRef);
|
|
236
|
+
if (msg) {
|
|
237
|
+
out.push({ label: "Message", value: displayName(msg) });
|
|
238
|
+
const key = child(msg.extensionElements, "subscription")?.attributes.correlationKey;
|
|
239
|
+
if (nonEmpty(key))
|
|
240
|
+
out.push({ label: "Correlation key", value: key });
|
|
241
|
+
}
|
|
242
|
+
else if (nonEmpty(def.messageRef)) {
|
|
243
|
+
out.push({ label: "Message", value: def.messageRef });
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case "error": {
|
|
248
|
+
const err = ctx.defs.errors.find((e) => e.id === def.errorRef);
|
|
249
|
+
if (err) {
|
|
250
|
+
out.push({ label: "Error", value: displayName(err) });
|
|
251
|
+
if (nonEmpty(err.errorCode))
|
|
252
|
+
out.push({ label: "Error code", value: err.errorCode });
|
|
253
|
+
}
|
|
254
|
+
else if (nonEmpty(def.errorRef)) {
|
|
255
|
+
out.push({ label: "Error", value: def.errorRef });
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
out.push({ label: "Error", value: "Any error" });
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case "escalation": {
|
|
263
|
+
const esc = ctx.defs.escalations.find((e) => e.id === def.escalationRef);
|
|
264
|
+
if (esc) {
|
|
265
|
+
out.push({ label: "Escalation", value: displayName(esc) });
|
|
266
|
+
if (nonEmpty(esc.escalationCode))
|
|
267
|
+
out.push({ label: "Escalation code", value: esc.escalationCode });
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case "signal": {
|
|
272
|
+
const sig = ctx.defs.signals.find((s) => s.id === def.signalRef);
|
|
273
|
+
if (sig)
|
|
274
|
+
out.push({ label: "Signal", value: displayName(sig) });
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case "conditional":
|
|
278
|
+
if (nonEmpty(def.condition))
|
|
279
|
+
out.push({ label: "Condition", value: def.condition.trim() });
|
|
280
|
+
break;
|
|
281
|
+
case "link":
|
|
282
|
+
if (nonEmpty(def.name))
|
|
283
|
+
out.push({ label: "Link", value: def.name });
|
|
284
|
+
break;
|
|
285
|
+
case "compensate":
|
|
286
|
+
if (nonEmpty(def.activityRef))
|
|
287
|
+
out.push({
|
|
288
|
+
label: "Compensates",
|
|
289
|
+
value: ctx.names.get(def.activityRef) ?? def.activityRef,
|
|
290
|
+
});
|
|
291
|
+
break;
|
|
292
|
+
case "cancel":
|
|
293
|
+
case "terminate":
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
function describeLoop(loop) {
|
|
299
|
+
if (!loop)
|
|
300
|
+
return [];
|
|
301
|
+
const zeebe = child(loop.extensionElements, "loopCharacteristics")?.attributes ?? {};
|
|
302
|
+
const mode = loop.isSequential ? "Sequential" : "Parallel";
|
|
303
|
+
let value = mode;
|
|
304
|
+
if (nonEmpty(zeebe.inputCollection)) {
|
|
305
|
+
value += ` over ${zeebe.inputCollection}`;
|
|
306
|
+
if (nonEmpty(zeebe.inputElement))
|
|
307
|
+
value += ` as ${zeebe.inputElement}`;
|
|
308
|
+
}
|
|
309
|
+
else if (loop.loopCardinality && nonEmpty(loop.loopCardinality.text)) {
|
|
310
|
+
value += `, ${loop.loopCardinality.text.trim()} times`;
|
|
311
|
+
}
|
|
312
|
+
const out = [{ label: "Multi-instance", value }];
|
|
313
|
+
if (nonEmpty(zeebe.outputCollection)) {
|
|
314
|
+
const el = nonEmpty(zeebe.outputElement) ? ` ← ${zeebe.outputElement}` : "";
|
|
315
|
+
out.push({ label: "Collects into", value: `${zeebe.outputCollection}${el}` });
|
|
316
|
+
}
|
|
317
|
+
if (loop.completionCondition && nonEmpty(loop.completionCondition.text)) {
|
|
318
|
+
out.push({ label: "Completes when", value: loop.completionCondition.text.trim() });
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
322
|
+
function describeOutgoing(el, outgoing, ctx) {
|
|
323
|
+
if (outgoing.length === 0)
|
|
324
|
+
return [];
|
|
325
|
+
const defaultFlow = "default" in el ? el.default : undefined;
|
|
326
|
+
const lines = outgoing.map((f) => {
|
|
327
|
+
const target = ctx.names.get(f.targetRef) ?? f.targetRef;
|
|
328
|
+
const label = nonEmpty(f.name) ? `${f.name.trim()} → ${target}` : `→ ${target}`;
|
|
329
|
+
if (f.id === defaultFlow)
|
|
330
|
+
return `${label} (default)`;
|
|
331
|
+
if (f.conditionExpression && nonEmpty(f.conditionExpression.text)) {
|
|
332
|
+
return `${label} when ${f.conditionExpression.text.trim()}`;
|
|
333
|
+
}
|
|
334
|
+
return label;
|
|
335
|
+
});
|
|
336
|
+
return [{ label: outgoing.length > 1 ? "Next steps" : "Next step", value: lines }];
|
|
337
|
+
}
|
|
338
|
+
function describeElement(el, outgoing, ctx) {
|
|
339
|
+
const props = [];
|
|
340
|
+
const ext = el.extensionElements;
|
|
341
|
+
const attr = (name, key) => child(ext, name)?.attributes[key];
|
|
342
|
+
const name = displayName(el);
|
|
343
|
+
const template = el.unknownAttributes["zeebe:modelerTemplate"];
|
|
344
|
+
if (nonEmpty(template))
|
|
345
|
+
props.push({ label: "Template", value: template });
|
|
346
|
+
if (el.type === "boundaryEvent") {
|
|
347
|
+
props.push({ label: "Attached to", value: ctx.names.get(el.attachedToRef) ?? el.attachedToRef });
|
|
348
|
+
}
|
|
349
|
+
for (const def of eventDefinitionsOf(el))
|
|
350
|
+
props.push(...describeEventDefinition(def, ctx));
|
|
351
|
+
if (el.type === "sendTask" || el.type === "receiveTask") {
|
|
352
|
+
const msg = ctx.defs.messages.find((m) => m.id === el.messageRef);
|
|
353
|
+
if (msg) {
|
|
354
|
+
props.push({ label: "Message", value: displayName(msg) });
|
|
355
|
+
const key = child(msg.extensionElements, "subscription")?.attributes.correlationKey;
|
|
356
|
+
if (nonEmpty(key))
|
|
357
|
+
props.push({ label: "Correlation key", value: key });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const jobType = attr("taskDefinition", "type");
|
|
361
|
+
if (nonEmpty(jobType))
|
|
362
|
+
props.push({ label: "Job type", value: jobType });
|
|
363
|
+
const retries = attr("taskDefinition", "retries");
|
|
364
|
+
if (nonEmpty(retries))
|
|
365
|
+
props.push({ label: "Retries", value: retries });
|
|
366
|
+
const script = child(ext, "script")?.attributes;
|
|
367
|
+
if (script && nonEmpty(script.expression)) {
|
|
368
|
+
props.push({ label: "Script", value: script.expression });
|
|
369
|
+
if (nonEmpty(script.resultVariable))
|
|
370
|
+
props.push({ label: "Result variable", value: script.resultVariable });
|
|
371
|
+
}
|
|
372
|
+
const decisionId = attr("calledDecision", "decisionId");
|
|
373
|
+
if (nonEmpty(decisionId)) {
|
|
374
|
+
const prop = { label: "Called decision", value: decisionId };
|
|
375
|
+
if (ctx.decisionIds.has(decisionId))
|
|
376
|
+
prop.link = { kind: "decision", id: decisionId };
|
|
377
|
+
props.push(prop);
|
|
378
|
+
const rv = attr("calledDecision", "resultVariable");
|
|
379
|
+
if (nonEmpty(rv))
|
|
380
|
+
props.push({ label: "Result variable", value: rv });
|
|
381
|
+
ctx.decisionCallers.set(decisionId, [...(ctx.decisionCallers.get(decisionId) ?? []), name]);
|
|
382
|
+
}
|
|
383
|
+
const calledElement = child(ext, "calledElement")?.attributes;
|
|
384
|
+
if (calledElement && nonEmpty(calledElement.processId)) {
|
|
385
|
+
props.push({ label: "Called process", value: calledElement.processId });
|
|
386
|
+
}
|
|
387
|
+
const form = child(ext, "formDefinition")?.attributes;
|
|
388
|
+
if (form) {
|
|
389
|
+
if (nonEmpty(form.formId)) {
|
|
390
|
+
const prop = { label: "Form", value: form.formId };
|
|
391
|
+
if (ctx.formIds.has(form.formId))
|
|
392
|
+
prop.link = { kind: "form", id: form.formId };
|
|
393
|
+
props.push(prop);
|
|
394
|
+
ctx.formUsers.set(form.formId, [...(ctx.formUsers.get(form.formId) ?? []), name]);
|
|
395
|
+
}
|
|
396
|
+
else if (nonEmpty(form.externalReference)) {
|
|
397
|
+
props.push({ label: "Form", value: form.externalReference });
|
|
398
|
+
}
|
|
399
|
+
else if (nonEmpty(form.formKey)) {
|
|
400
|
+
props.push({ label: "Form", value: form.formKey });
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const assignment = child(ext, "assignmentDefinition")?.attributes ?? {};
|
|
404
|
+
if (nonEmpty(assignment.assignee))
|
|
405
|
+
props.push({ label: "Assignee", value: assignment.assignee });
|
|
406
|
+
if (nonEmpty(assignment.candidateGroups))
|
|
407
|
+
props.push({ label: "Candidate groups", value: assignment.candidateGroups });
|
|
408
|
+
if (nonEmpty(assignment.candidateUsers))
|
|
409
|
+
props.push({ label: "Candidate users", value: assignment.candidateUsers });
|
|
410
|
+
const schedule = child(ext, "taskSchedule")?.attributes ?? {};
|
|
411
|
+
if (nonEmpty(schedule.dueDate))
|
|
412
|
+
props.push({ label: "Due date", value: schedule.dueDate });
|
|
413
|
+
if (nonEmpty(schedule.followUpDate))
|
|
414
|
+
props.push({ label: "Follow-up date", value: schedule.followUpDate });
|
|
415
|
+
const priority = attr("priorityDefinition", "priority");
|
|
416
|
+
if (nonEmpty(priority))
|
|
417
|
+
props.push({ label: "Priority", value: priority });
|
|
418
|
+
const headers = children(child(ext, "taskHeaders")?.children, "header");
|
|
419
|
+
if (headers.length > 0) {
|
|
420
|
+
props.push({
|
|
421
|
+
label: "Task headers",
|
|
422
|
+
value: headers.map((h) => `${h.attributes.key ?? ""} = ${h.attributes.value ?? ""}`),
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
const io = child(ext, "ioMapping");
|
|
426
|
+
const mapping = (kind) => children(io?.children, kind).map((m) => `${m.attributes.target ?? ""} ← ${m.attributes.source ?? ""}`);
|
|
427
|
+
const inputs = mapping("input");
|
|
428
|
+
if (inputs.length > 0)
|
|
429
|
+
props.push({ label: "Inputs", value: inputs });
|
|
430
|
+
const outputs = mapping("output");
|
|
431
|
+
if (outputs.length > 0)
|
|
432
|
+
props.push({ label: "Outputs", value: outputs });
|
|
433
|
+
if ("loopCharacteristics" in el)
|
|
434
|
+
props.push(...describeLoop(el.loopCharacteristics));
|
|
435
|
+
if (el.type === "adHocSubProcess" &&
|
|
436
|
+
el.completionCondition &&
|
|
437
|
+
nonEmpty(el.completionCondition.text)) {
|
|
438
|
+
props.push({ label: "Completes when", value: el.completionCondition.text.trim() });
|
|
439
|
+
}
|
|
440
|
+
props.push(...describeOutgoing(el, outgoing, ctx));
|
|
441
|
+
return props;
|
|
442
|
+
}
|
|
443
|
+
function documentScope(scope, lanes, inheritedLane, prefix, depth, ctx, into) {
|
|
444
|
+
// Flows are read from the scope, not from `outgoing`, which many files omit.
|
|
445
|
+
const bySource = new Map();
|
|
446
|
+
for (const f of scope.sequenceFlows) {
|
|
447
|
+
bySource.set(f.sourceRef, [...(bySource.get(f.sourceRef) ?? []), f]);
|
|
448
|
+
}
|
|
449
|
+
const ordered = flowOrder(scope.flowElements, scope.sequenceFlows);
|
|
450
|
+
ordered.forEach((el, i) => {
|
|
451
|
+
const number = `${prefix}${i + 1}`;
|
|
452
|
+
const lane = lanes.get(el.id) ?? inheritedLane;
|
|
453
|
+
const doc = {
|
|
454
|
+
id: el.id,
|
|
455
|
+
type: el.type,
|
|
456
|
+
typeLabel: typeLabelOf(el),
|
|
457
|
+
number,
|
|
458
|
+
depth,
|
|
459
|
+
properties: describeElement(el, bySource.get(el.id) ?? [], ctx),
|
|
460
|
+
};
|
|
461
|
+
if (nonEmpty(el.name))
|
|
462
|
+
doc.name = el.name.trim();
|
|
463
|
+
if (lane !== undefined)
|
|
464
|
+
doc.lane = lane;
|
|
465
|
+
if (nonEmpty(el.documentation))
|
|
466
|
+
doc.documentation = el.documentation.trim();
|
|
467
|
+
into.push(doc);
|
|
468
|
+
if (isScope(el)) {
|
|
469
|
+
documentScope(el, lanes, lane, `${number}.`, depth + 1, ctx, into);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
function flattenFormFields(components, path, into) {
|
|
474
|
+
for (const c of components) {
|
|
475
|
+
const rec = c;
|
|
476
|
+
const str = (k) => (typeof rec[k] === "string" ? rec[k].trim() : "");
|
|
477
|
+
const label = str("label") || str("dateLabel");
|
|
478
|
+
if (Array.isArray(rec.components)) {
|
|
479
|
+
flattenFormFields(rec.components, label ? [...path, label] : path, into);
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
// Only components that bind data are fields; text, images and buttons are layout.
|
|
483
|
+
const key = str("key") || str("dataSource");
|
|
484
|
+
if (!key)
|
|
485
|
+
continue;
|
|
486
|
+
const values = Array.isArray(rec.values)
|
|
487
|
+
? rec.values.map((v) => String(v.label ?? "")).join(", ")
|
|
488
|
+
: "";
|
|
489
|
+
const validate = rec.validate;
|
|
490
|
+
into.push({
|
|
491
|
+
label: [...path, label].filter((s) => s !== "").join(" / "),
|
|
492
|
+
key,
|
|
493
|
+
type: c.type,
|
|
494
|
+
required: validate?.required === true,
|
|
495
|
+
options: values || str("valuesKey") || str("valuesExpression"),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Collects everything a process document needs from a parsed model, in flow
|
|
501
|
+
* order. The HTML, Markdown and Word renderers all draw from this, so a custom
|
|
502
|
+
* renderer can too.
|
|
503
|
+
*/
|
|
504
|
+
export function buildProcessDocumentation(defs, options = {}) {
|
|
505
|
+
const decisionsIn = (options.decisions ?? []).flatMap((d) => d.decisions);
|
|
506
|
+
const formsIn = options.forms ?? [];
|
|
507
|
+
const ctx = {
|
|
508
|
+
defs,
|
|
509
|
+
names: new Map(),
|
|
510
|
+
decisionIds: new Set(decisionsIn.map((d) => d.id)),
|
|
511
|
+
formIds: new Set(formsIn.map((f) => f.id)),
|
|
512
|
+
decisionCallers: new Map(),
|
|
513
|
+
formUsers: new Map(),
|
|
514
|
+
};
|
|
515
|
+
for (const p of defs.processes)
|
|
516
|
+
collectNames(p.flowElements, ctx.names);
|
|
517
|
+
const participants = defs.collaborations.flatMap((c) => c.participants);
|
|
518
|
+
for (const part of participants)
|
|
519
|
+
ctx.names.set(part.id, displayName(part));
|
|
520
|
+
// Pools first, in pool order; processes without a pool after, in XML order.
|
|
521
|
+
const poolOrder = participants.flatMap((part) => defs.processes.filter((p) => p.id === part.processRef).map((p) => ({ p, part })));
|
|
522
|
+
const unpooled = defs.processes
|
|
523
|
+
.filter((p) => !participants.some((part) => part.processRef === p.id))
|
|
524
|
+
.map((p) => ({ p, part: undefined }));
|
|
525
|
+
const processes = [...poolOrder, ...unpooled].map(({ p, part }) => {
|
|
526
|
+
const laneInfo = laneMapOf(p.laneSet);
|
|
527
|
+
const elements = [];
|
|
528
|
+
documentScope(p, laneInfo.byElement, undefined, "", 0, ctx, elements);
|
|
529
|
+
const rank = new Map(elements.map((e, i) => [e.id, i]));
|
|
530
|
+
const lanes = laneInfo.lanes.map((l) => {
|
|
531
|
+
const lane = {
|
|
532
|
+
id: l.id,
|
|
533
|
+
name: l.name,
|
|
534
|
+
path: l.path,
|
|
535
|
+
elements: [...l.refs]
|
|
536
|
+
.filter((r) => rank.has(r))
|
|
537
|
+
.sort((a, b) => (rank.get(a) ?? 0) - (rank.get(b) ?? 0))
|
|
538
|
+
.map((r) => ctx.names.get(r) ?? r),
|
|
539
|
+
};
|
|
540
|
+
if (nonEmpty(l.documentation))
|
|
541
|
+
lane.documentation = l.documentation.trim();
|
|
542
|
+
return lane;
|
|
543
|
+
});
|
|
544
|
+
const doc = {
|
|
545
|
+
id: p.id,
|
|
546
|
+
title: part && nonEmpty(part.name) ? part.name.trim() : displayName(p),
|
|
547
|
+
executable: p.isExecutable === true,
|
|
548
|
+
lanes,
|
|
549
|
+
elements,
|
|
550
|
+
};
|
|
551
|
+
if (part && nonEmpty(part.name))
|
|
552
|
+
doc.participant = part.name.trim();
|
|
553
|
+
const text = nonEmpty(p.documentation) ? p.documentation : part?.documentation;
|
|
554
|
+
if (nonEmpty(text))
|
|
555
|
+
doc.documentation = text.trim();
|
|
556
|
+
return doc;
|
|
557
|
+
});
|
|
558
|
+
const messageFlows = defs.collaborations.flatMap((c) => c.messageFlows.map((mf) => {
|
|
559
|
+
const out = {
|
|
560
|
+
id: mf.id,
|
|
561
|
+
from: ctx.names.get(mf.sourceRef) ?? mf.sourceRef,
|
|
562
|
+
to: ctx.names.get(mf.targetRef) ?? mf.targetRef,
|
|
563
|
+
};
|
|
564
|
+
if (nonEmpty(mf.name))
|
|
565
|
+
out.name = mf.name.trim();
|
|
566
|
+
const msg = defs.messages.find((m) => m.id === mf.messageRef);
|
|
567
|
+
if (msg)
|
|
568
|
+
out.message = displayName(msg);
|
|
569
|
+
if (nonEmpty(mf.documentation))
|
|
570
|
+
out.documentation = mf.documentation.trim();
|
|
571
|
+
return out;
|
|
572
|
+
}));
|
|
573
|
+
const decisions = decisionsIn.flatMap((d) => {
|
|
574
|
+
const table = d.decisionTable;
|
|
575
|
+
if (!table)
|
|
576
|
+
return [];
|
|
577
|
+
return [
|
|
578
|
+
{
|
|
579
|
+
id: d.id,
|
|
580
|
+
name: displayName(d),
|
|
581
|
+
hitPolicy: table.aggregation
|
|
582
|
+
? `${table.hitPolicy ?? "COLLECT"} (${table.aggregation})`
|
|
583
|
+
: (table.hitPolicy ?? "UNIQUE"),
|
|
584
|
+
inputs: table.inputs.map((i) => i.label?.trim() || i.inputExpression.text?.trim() || i.id),
|
|
585
|
+
outputs: table.outputs.map((o) => o.label?.trim() || o.name?.trim() || o.id),
|
|
586
|
+
rules: table.rules.map((r) => [
|
|
587
|
+
...r.inputEntries.map((e) => e.text.trim() || "-"),
|
|
588
|
+
...r.outputEntries.map((e) => e.text.trim()),
|
|
589
|
+
r.description?.trim() ?? "",
|
|
590
|
+
]),
|
|
591
|
+
calledBy: ctx.decisionCallers.get(d.id) ?? [],
|
|
592
|
+
},
|
|
593
|
+
];
|
|
594
|
+
});
|
|
595
|
+
const forms = formsIn.map((f) => {
|
|
596
|
+
const fields = [];
|
|
597
|
+
flattenFormFields(f.components, [], fields);
|
|
598
|
+
return { id: f.id, fields, usedBy: ctx.formUsers.get(f.id) ?? [] };
|
|
599
|
+
});
|
|
600
|
+
const firstTitle = processes[0]?.title;
|
|
601
|
+
const doc = {
|
|
602
|
+
title: nonEmpty(options.title) ? options.title.trim() : (firstTitle ?? defs.id),
|
|
603
|
+
processes,
|
|
604
|
+
messageFlows,
|
|
605
|
+
decisions,
|
|
606
|
+
forms,
|
|
607
|
+
};
|
|
608
|
+
if (nonEmpty(options.subtitle))
|
|
609
|
+
doc.subtitle = options.subtitle.trim();
|
|
610
|
+
if (nonEmpty(defs.documentation))
|
|
611
|
+
doc.documentation = defs.documentation.trim();
|
|
612
|
+
if (options.diagram !== false && (defs.diagrams[0]?.plane.shapes.length ?? 0) > 0) {
|
|
613
|
+
doc.diagramSvg = exportSvg(defs, { theme: "light", padding: 40 });
|
|
614
|
+
}
|
|
615
|
+
return doc;
|
|
616
|
+
}
|
|
617
|
+
//# sourceMappingURL=model.js.map
|
package/dist/doc/zip.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// A minimal ZIP writer (STORE, no compression) — enough for an OOXML package.
|
|
2
|
+
// Timestamps are fixed so the same input always yields the same bytes.
|
|
3
|
+
const CRC_TABLE = (() => {
|
|
4
|
+
const t = new Uint32Array(256);
|
|
5
|
+
for (let i = 0; i < 256; i++) {
|
|
6
|
+
let c = i;
|
|
7
|
+
for (let j = 0; j < 8; j++)
|
|
8
|
+
c = c & 1 ? (c >>> 1) ^ 0xedb88320 : c >>> 1;
|
|
9
|
+
t[i] = c;
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
})();
|
|
13
|
+
function crc32(data) {
|
|
14
|
+
let crc = 0xffffffff;
|
|
15
|
+
for (const byte of data)
|
|
16
|
+
crc = (crc >>> 8) ^ (CRC_TABLE[(crc ^ byte) & 0xff] ?? 0);
|
|
17
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
18
|
+
}
|
|
19
|
+
/** 1980-01-01 00:00, the earliest DOS date. Zero is not a valid date and some readers reject it. */
|
|
20
|
+
const DOS_DATE = 0x0021;
|
|
21
|
+
export function zipStore(files) {
|
|
22
|
+
const enc = new TextEncoder();
|
|
23
|
+
const parts = [];
|
|
24
|
+
const central = [];
|
|
25
|
+
let offset = 0;
|
|
26
|
+
let centralSize = 0;
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
const name = enc.encode(file.name);
|
|
29
|
+
const crc = crc32(file.data);
|
|
30
|
+
const size = file.data.length;
|
|
31
|
+
const local = new Uint8Array(30 + name.length);
|
|
32
|
+
const lv = new DataView(local.buffer);
|
|
33
|
+
lv.setUint32(0, 0x04034b50, true);
|
|
34
|
+
lv.setUint16(4, 20, true);
|
|
35
|
+
lv.setUint16(6, 0x0800, true); // UTF-8 names
|
|
36
|
+
lv.setUint16(12, DOS_DATE, true);
|
|
37
|
+
lv.setUint32(14, crc, true);
|
|
38
|
+
lv.setUint32(18, size, true);
|
|
39
|
+
lv.setUint32(22, size, true);
|
|
40
|
+
lv.setUint16(26, name.length, true);
|
|
41
|
+
local.set(name, 30);
|
|
42
|
+
parts.push(local, file.data);
|
|
43
|
+
const cd = new Uint8Array(46 + name.length);
|
|
44
|
+
const cv = new DataView(cd.buffer);
|
|
45
|
+
cv.setUint32(0, 0x02014b50, true);
|
|
46
|
+
cv.setUint16(4, 20, true);
|
|
47
|
+
cv.setUint16(6, 20, true);
|
|
48
|
+
cv.setUint16(8, 0x0800, true);
|
|
49
|
+
cv.setUint16(14, DOS_DATE, true);
|
|
50
|
+
cv.setUint32(16, crc, true);
|
|
51
|
+
cv.setUint32(20, size, true);
|
|
52
|
+
cv.setUint32(24, size, true);
|
|
53
|
+
cv.setUint16(28, name.length, true);
|
|
54
|
+
cv.setUint32(42, offset, true);
|
|
55
|
+
cd.set(name, 46);
|
|
56
|
+
central.push(cd);
|
|
57
|
+
offset += local.length + size;
|
|
58
|
+
centralSize += cd.length;
|
|
59
|
+
}
|
|
60
|
+
const eocd = new Uint8Array(22);
|
|
61
|
+
const ev = new DataView(eocd.buffer);
|
|
62
|
+
ev.setUint32(0, 0x06054b50, true);
|
|
63
|
+
ev.setUint16(8, files.length, true);
|
|
64
|
+
ev.setUint16(10, files.length, true);
|
|
65
|
+
ev.setUint32(12, centralSize, true);
|
|
66
|
+
ev.setUint32(16, offset, true);
|
|
67
|
+
const out = new Uint8Array(offset + centralSize + eocd.length);
|
|
68
|
+
let pos = 0;
|
|
69
|
+
for (const part of [...parts, ...central, eocd]) {
|
|
70
|
+
out.set(part, pos);
|
|
71
|
+
pos += part.length;
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=zip.js.map
|