@bpmnkit/core 1.0.0 → 1.2.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.
Files changed (73) hide show
  1. package/README.md +30 -3
  2. package/dist/bpmn/agentic.js +3 -1
  3. package/dist/bpmn/auto-layout.js +184 -15
  4. package/dist/bpmn/bpmn-builder.js +69 -7
  5. package/dist/bpmn/bpmn-model.d.ts +78 -0
  6. package/dist/bpmn/bpmn-parser.js +195 -37
  7. package/dist/bpmn/bpmn-serializer.js +121 -72
  8. package/dist/bpmn/bpmnlint.d.ts +153 -0
  9. package/dist/bpmn/bpmnlint.js +364 -0
  10. package/dist/bpmn/camunda-compat-data.d.ts +165 -0
  11. package/dist/bpmn/camunda-compat-data.js +423 -0
  12. package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
  13. package/dist/bpmn/camunda-compat-feel.js +338 -0
  14. package/dist/bpmn/camunda-compat.d.ts +120 -0
  15. package/dist/bpmn/camunda-compat.js +1677 -0
  16. package/dist/bpmn/camunda7/juel.d.ts +41 -0
  17. package/dist/bpmn/camunda7/juel.js +333 -0
  18. package/dist/bpmn/camunda7/migrate.d.ts +72 -0
  19. package/dist/bpmn/camunda7/migrate.js +1152 -0
  20. package/dist/bpmn/compact.d.ts +4 -0
  21. package/dist/bpmn/compact.js +80 -0
  22. package/dist/bpmn/full-operations.js +5 -2
  23. package/dist/bpmn/label-style.d.ts +51 -0
  24. package/dist/bpmn/label-style.js +116 -0
  25. package/dist/bpmn/lint.d.ts +23 -3
  26. package/dist/bpmn/lint.js +47 -10
  27. package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
  28. package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
  29. package/dist/bpmn/optimize/deploy.d.ts +8 -2
  30. package/dist/bpmn/optimize/deploy.js +16 -3
  31. package/dist/bpmn/optimize/index.js +11 -2
  32. package/dist/bpmn/optimize/patterns.js +3 -0
  33. package/dist/bpmn/optimize/types.d.ts +14 -0
  34. package/dist/bpmn/optimize/variable-flow.js +4 -1
  35. package/dist/bpmn/process-delta.d.ts +88 -0
  36. package/dist/bpmn/process-delta.js +236 -0
  37. package/dist/bpmn/process-text-writer.d.ts +53 -0
  38. package/dist/bpmn/process-text-writer.js +193 -0
  39. package/dist/bpmn/process-text.d.ts +175 -0
  40. package/dist/bpmn/process-text.js +1255 -0
  41. package/dist/bpmn/process-types.d.ts +112 -0
  42. package/dist/bpmn/process-types.js +490 -0
  43. package/dist/bpmn/svg.js +51 -22
  44. package/dist/doc/docx.d.ts +20 -0
  45. package/dist/doc/docx.js +253 -0
  46. package/dist/doc/html.d.ts +21 -0
  47. package/dist/doc/html.js +303 -0
  48. package/dist/doc/index.d.ts +7 -0
  49. package/dist/doc/index.js +5 -0
  50. package/dist/doc/markdown.d.ts +11 -0
  51. package/dist/doc/markdown.js +160 -0
  52. package/dist/doc/model.d.ts +129 -0
  53. package/dist/doc/model.js +617 -0
  54. package/dist/doc/zip.d.ts +5 -0
  55. package/dist/doc/zip.js +75 -0
  56. package/dist/index.d.ts +22 -0
  57. package/dist/index.js +11 -0
  58. package/dist/layout/annotations.d.ts +4 -2
  59. package/dist/layout/annotations.js +31 -2
  60. package/dist/layout/collaboration/ordering.d.ts +8 -0
  61. package/dist/layout/collaboration/ordering.js +57 -18
  62. package/dist/layout/orthogonal.d.ts +32 -0
  63. package/dist/layout/orthogonal.js +367 -0
  64. package/dist/layout/repair.d.ts +31 -0
  65. package/dist/layout/repair.js +220 -0
  66. package/dist/layout/semantic/route.js +45 -3
  67. package/dist/node/bpmnlint.d.ts +109 -0
  68. package/dist/node/bpmnlint.js +198 -0
  69. package/dist/node/index.d.ts +2 -0
  70. package/dist/node/index.js +1 -0
  71. package/dist/xml/xml-patch.d.ts +21 -0
  72. package/dist/xml/xml-patch.js +27 -1
  73. package/package.json +2 -2
@@ -0,0 +1,916 @@
1
+ /**
2
+ * Native equivalents of bpmnlint rules BPMN Kit had no finding for, or whose
3
+ * finding checks only the top-level process or a different set of elements.
4
+ *
5
+ * These are opt-in: nothing here runs unless a `.bpmnlintrc` enables the
6
+ * bpmnlint rule it stands in for (see `../bpmnlint.ts`). The default
7
+ * `casen lint` report is unchanged by their existence — several of them
8
+ * (`no-inclusive-gateway`, `standard-size`, …) are house style rather than
9
+ * correctness, and a team that never asked for them should not see them.
10
+ *
11
+ * Every rule walks every scope — processes and the sub-processes nested in
12
+ * them — because bpmnlint does. Connectivity is read from the sequence flows
13
+ * of each scope rather than from the `<incoming>`/`<outgoing>` children, which
14
+ * hand-written and generated XML routinely omits.
15
+ */
16
+ function isSubContainer(el) {
17
+ return (el.type === "subProcess" ||
18
+ el.type === "adHocSubProcess" ||
19
+ el.type === "eventSubProcess" ||
20
+ el.type === "transaction");
21
+ }
22
+ function isEventSubProcess(el) {
23
+ return el.type === "eventSubProcess" || (el.type === "subProcess" && el.triggeredByEvent === true);
24
+ }
25
+ function indexFlows(flows) {
26
+ const bySource = new Map();
27
+ const byTarget = new Map();
28
+ for (const flow of flows) {
29
+ bySource.set(flow.sourceRef, [...(bySource.get(flow.sourceRef) ?? []), flow]);
30
+ byTarget.set(flow.targetRef, [...(byTarget.get(flow.targetRef) ?? []), flow]);
31
+ }
32
+ return { bySource, byTarget };
33
+ }
34
+ /** Every process and every sub-process nested in it, outermost first. */
35
+ function allScopes(defs) {
36
+ const scopes = [];
37
+ const visit = (container, kind, eventSubProcess, processId, executable) => {
38
+ scopes.push({
39
+ container,
40
+ kind,
41
+ processId,
42
+ executable,
43
+ eventSubProcess,
44
+ ...indexFlows(container.sequenceFlows),
45
+ });
46
+ for (const el of container.flowElements) {
47
+ if (isSubContainer(el))
48
+ visit(el, el.type, isEventSubProcess(el), processId, executable);
49
+ }
50
+ };
51
+ for (const process of defs.processes) {
52
+ visit(process, "process", false, process.id, process.isExecutable === true);
53
+ }
54
+ return scopes;
55
+ }
56
+ // ---------------------------------------------------------------------------
57
+ // Element classification (bpmn-moddle's type hierarchy, flattened)
58
+ // ---------------------------------------------------------------------------
59
+ const EVENT_TYPES = new Set([
60
+ "startEvent",
61
+ "endEvent",
62
+ "intermediateThrowEvent",
63
+ "intermediateCatchEvent",
64
+ "boundaryEvent",
65
+ ]);
66
+ /** `bpmn:Task` and its subtypes — call activities and sub-processes are not tasks. */
67
+ const TASK_TYPES = new Set([
68
+ "task",
69
+ "serviceTask",
70
+ "scriptTask",
71
+ "userTask",
72
+ "sendTask",
73
+ "receiveTask",
74
+ "businessRuleTask",
75
+ "manualTask",
76
+ ]);
77
+ const GATEWAY_TYPES = new Set([
78
+ "exclusiveGateway",
79
+ "parallelGateway",
80
+ "inclusiveGateway",
81
+ "eventBasedGateway",
82
+ "complexGateway",
83
+ ]);
84
+ function isEvent(el) {
85
+ return EVENT_TYPES.has(el.type);
86
+ }
87
+ function isActivity(el) {
88
+ return TASK_TYPES.has(el.type) || el.type === "callActivity" || isSubContainer(el);
89
+ }
90
+ function isGateway(el) {
91
+ return GATEWAY_TYPES.has(el.type);
92
+ }
93
+ /** `bpmn:FlowNode` — everything except data objects and their references. */
94
+ function isFlowNode(el) {
95
+ return isEvent(el) || isActivity(el) || isGateway(el);
96
+ }
97
+ function eventDefinitionsOf(el) {
98
+ return "eventDefinitions" in el ? el.eventDefinitions : [];
99
+ }
100
+ /**
101
+ * The default flow id. Gateways model it; an activity keeps its `default` in
102
+ * `unknownAttributes`, which the parser preserves.
103
+ */
104
+ function defaultFlowOf(el) {
105
+ if (el === undefined)
106
+ return undefined;
107
+ if ("default" in el && el.default !== undefined)
108
+ return el.default;
109
+ return el.unknownAttributes.default;
110
+ }
111
+ function hasCondition(flow) {
112
+ return flow.conditionExpression !== undefined;
113
+ }
114
+ /**
115
+ * The default flow as bpmn-moddle reads it: only activities and exclusive,
116
+ * inclusive and complex gateways have a `default` property. On any other
117
+ * element the attribute is foreign, and bpmnlint does not see it.
118
+ */
119
+ function modelledDefaultOf(el) {
120
+ const hasDefault = isActivity(el) ||
121
+ el.type === "exclusiveGateway" ||
122
+ el.type === "inclusiveGateway" ||
123
+ el.type === "complexGateway";
124
+ return hasDefault ? defaultFlowOf(el) : undefined;
125
+ }
126
+ /** Has event definitions, all of one type — bpmnlint's `isLinkEvent` and `isCompensationEvent`. */
127
+ function onlyDefinitions(el, type) {
128
+ const defs = eventDefinitionsOf(el);
129
+ return defs.length > 0 && defs.every((d) => d.type === type);
130
+ }
131
+ function isBlank(name) {
132
+ return (name ?? "").trim() === "";
133
+ }
134
+ // ---------------------------------------------------------------------------
135
+ // Rules — keyed by the bpmnlint rule they implement
136
+ // ---------------------------------------------------------------------------
137
+ const SUB_SCOPE_KINDS = new Set(["subProcess", "eventSubProcess", "transaction"]);
138
+ const RULES = {
139
+ "ad-hoc-sub-process": {
140
+ category: "flow",
141
+ check({ scopes }, report) {
142
+ for (const scope of scopes) {
143
+ if (scope.kind !== "adHocSubProcess")
144
+ continue;
145
+ for (const el of scope.container.flowElements) {
146
+ if (el.type !== "startEvent" && el.type !== "endEvent")
147
+ continue;
148
+ report("flow/ad-hoc-start-end-event", `${el.type === "startEvent" ? "Start" : "End"} event "${el.id}" is not allowed in ad-hoc sub-process "${scope.container.id}".`, "Remove it — an ad-hoc sub-process has no start or end events; its activities run on demand.", scope.processId, [el.id]);
149
+ }
150
+ }
151
+ },
152
+ },
153
+ "conditional-event": {
154
+ category: "flow",
155
+ check({ scopes }, report) {
156
+ for (const scope of scopes) {
157
+ if (!scope.executable)
158
+ continue;
159
+ for (const el of scope.container.flowElements) {
160
+ const def = eventDefinitionsOf(el).find((d) => d.type === "conditional");
161
+ if (def?.type !== "conditional" || (def.condition ?? "").trim() !== "")
162
+ continue;
163
+ report("flow/conditional-event-no-condition", `Conditional event "${el.id}" has no condition.`, "Add the condition that should trigger the event.", scope.processId, [el.id]);
164
+ }
165
+ }
166
+ },
167
+ },
168
+ // Stands in for `feel/empty-condition` while configured (see `replaces` in
169
+ // `../bpmnlint.ts`), so it shares that finding's category.
170
+ "conditional-flows": {
171
+ category: "feel",
172
+ check({ scopes }, report) {
173
+ for (const scope of scopes) {
174
+ for (const el of scope.container.flowElements) {
175
+ const outgoing = scope.bySource.get(el.id) ?? [];
176
+ const defaultFlow = modelledDefaultOf(el);
177
+ if (defaultFlow === undefined && !outgoing.some(hasCondition))
178
+ continue;
179
+ for (const flow of outgoing) {
180
+ if (hasCondition(flow) || flow.id === defaultFlow)
181
+ continue;
182
+ report("feel/missing-condition", `Sequence flow "${flow.id}" leaves "${el.id}", which routes by condition, but has no condition and is not the default flow.`, "Add a condition expression, or make this flow the default.", scope.processId, [flow.id]);
183
+ }
184
+ }
185
+ }
186
+ },
187
+ },
188
+ "end-event-required": {
189
+ category: "flow",
190
+ check({ scopes }, report) {
191
+ // Top-level processes are covered by `flow/no-end-event`.
192
+ for (const scope of scopes) {
193
+ if (!SUB_SCOPE_KINDS.has(scope.kind))
194
+ continue;
195
+ if (scope.container.flowElements.some((el) => el.type === "endEvent"))
196
+ continue;
197
+ report("flow/sub-process-no-end-event", `Sub-process "${scope.container.id}" has no end event.`, "Add an end event so the sub-process completes explicitly.", scope.processId, [scope.container.id]);
198
+ }
199
+ },
200
+ },
201
+ "event-based-gateway": {
202
+ category: "flow",
203
+ check({ scopes }, report) {
204
+ for (const scope of scopes) {
205
+ for (const el of scope.container.flowElements) {
206
+ if (el.type !== "eventBasedGateway")
207
+ continue;
208
+ const outgoing = scope.bySource.get(el.id) ?? [];
209
+ if (outgoing.length < 2) {
210
+ report("flow/event-gateway-invalid", `Event-based gateway "${el.id}" has ${outgoing.length} outgoing flow${outgoing.length === 1 ? "" : "s"}; it needs at least 2.`, "Connect the gateway to two or more catch events — it waits for the first of them.", scope.processId, [el.id]);
211
+ }
212
+ for (const flow of outgoing.filter(hasCondition)) {
213
+ report("flow/event-gateway-invalid", `Sequence flow "${flow.id}" leaves event-based gateway "${el.id}" with a condition.`, "Remove the condition — the event that arrives first decides the path.", scope.processId, [flow.id]);
214
+ }
215
+ }
216
+ }
217
+ },
218
+ },
219
+ "event-sub-process-typed-start-event": {
220
+ category: "flow",
221
+ check({ scopes }, report) {
222
+ for (const scope of scopes) {
223
+ if (!scope.eventSubProcess)
224
+ continue;
225
+ for (const el of scope.container.flowElements) {
226
+ if (el.type !== "startEvent" || el.eventDefinitions.length > 0)
227
+ continue;
228
+ report("flow/event-sub-process-untyped-start", `Start event "${el.id}" of event sub-process "${scope.container.id}" has no event definition.`, "Give the start event a trigger (message, timer, error, signal, …).", scope.processId, [el.id]);
229
+ }
230
+ }
231
+ },
232
+ },
233
+ "fake-join": {
234
+ category: "flow",
235
+ check({ scopes }, report) {
236
+ for (const scope of scopes) {
237
+ for (const el of scope.container.flowElements) {
238
+ if (!isActivity(el) && !isEvent(el))
239
+ continue;
240
+ // `flow/multi-incoming-task` already covers the top level, except start events.
241
+ if (scope.kind === "process" && el.type !== "startEvent")
242
+ continue;
243
+ const incoming = (scope.byTarget.get(el.id) ?? []).length;
244
+ if (incoming <= 1)
245
+ continue;
246
+ report("flow/multi-incoming-task", `Element "${el.id}" (${el.type}) has ${incoming} incoming flows, which do not join.`, "Join the flows with a gateway before this element.", scope.processId, [el.id]);
247
+ }
248
+ }
249
+ },
250
+ },
251
+ global: {
252
+ category: "pattern",
253
+ check({ defs, scopes }, report) {
254
+ const referenced = new Set();
255
+ for (const scope of scopes) {
256
+ for (const el of scope.container.flowElements) {
257
+ for (const def of eventDefinitionsOf(el)) {
258
+ if (def.type === "error" && def.errorRef)
259
+ referenced.add(`error:${def.errorRef}`);
260
+ if (def.type === "escalation" && def.escalationRef)
261
+ referenced.add(`escalation:${def.escalationRef}`);
262
+ if (def.type === "message" && def.messageRef)
263
+ referenced.add(`message:${def.messageRef}`);
264
+ if (def.type === "signal" && def.signalRef)
265
+ referenced.add(`signal:${def.signalRef}`);
266
+ }
267
+ if ((el.type === "sendTask" || el.type === "receiveTask") && el.messageRef) {
268
+ referenced.add(`message:${el.messageRef}`);
269
+ }
270
+ }
271
+ }
272
+ for (const collaboration of defs.collaborations) {
273
+ for (const flow of collaboration.messageFlows) {
274
+ if (flow.messageRef)
275
+ referenced.add(`message:${flow.messageRef}`);
276
+ }
277
+ }
278
+ const groups = [
279
+ ["error", defs.errors],
280
+ ["escalation", defs.escalations],
281
+ ["message", defs.messages],
282
+ ["signal", defs.signals],
283
+ ];
284
+ for (const [kind, elements] of groups) {
285
+ for (const element of elements) {
286
+ // bpmnlint's `hasName` is `name?.trim() !== ""`: a missing name attribute
287
+ // passes, and only an empty or blank one is reported.
288
+ if (element.name !== undefined && element.name.trim() === "") {
289
+ report("pattern/global-element", `Global ${kind} "${element.id}" has no name.`, `Name the ${kind} so the events referring to it say what they mean.`, defs.id, [element.id]);
290
+ }
291
+ if (!referenced.has(`${kind}:${element.id}`)) {
292
+ report("pattern/global-element", `Global ${kind} "${element.id}" is not referenced by any element.`, `Remove the unused ${kind}, or reference it from the event that should use it.`, defs.id, [element.id]);
293
+ }
294
+ if (elements.filter((other) => other.name === element.name).length > 1) {
295
+ report("pattern/global-element", `Global ${kind} "${element.id}" shares its name with another ${kind}.`, `Give each ${kind} a unique name, or reuse one ${kind} instead of declaring it twice.`, defs.id, [element.id]);
296
+ }
297
+ }
298
+ }
299
+ },
300
+ },
301
+ "label-required": {
302
+ category: "naming",
303
+ check({ defs, scopes }, report) {
304
+ const missing = (id, what, processId) => report("naming/missing-label", `${what} "${id}" has no label.`, "Name it, so the diagram says what it does or means.", processId, [id]);
305
+ for (const collaboration of defs.collaborations) {
306
+ for (const participant of collaboration.participants) {
307
+ if (isBlank(participant.name))
308
+ missing(participant.id, "Participant", defs.id);
309
+ }
310
+ }
311
+ const lanes = (list, processId) => {
312
+ for (const lane of list) {
313
+ if (isBlank(lane.name))
314
+ missing(lane.id, "Lane", processId);
315
+ if (lane.childLaneSet)
316
+ lanes(lane.childLaneSet.lanes, processId);
317
+ }
318
+ };
319
+ for (const process of defs.processes)
320
+ lanes(process.laneSet?.lanes ?? [], process.id);
321
+ for (const scope of scopes) {
322
+ for (const el of scope.container.flowElements) {
323
+ // Sub-processes, parallel and event-based gateways and joins need no label.
324
+ if (!isFlowNode(el) || isSubContainer(el))
325
+ continue;
326
+ if (el.type === "parallelGateway" || el.type === "eventBasedGateway")
327
+ continue;
328
+ if (isGateway(el) && (scope.bySource.get(el.id) ?? []).length <= 1)
329
+ continue;
330
+ if (isBlank(el.name))
331
+ missing(el.id, `${el.type} element`, scope.processId);
332
+ }
333
+ for (const flow of scope.container.sequenceFlows) {
334
+ if (hasCondition(flow) && isBlank(flow.name)) {
335
+ missing(flow.id, "Conditional sequence flow", scope.processId);
336
+ }
337
+ }
338
+ }
339
+ },
340
+ },
341
+ "link-event": {
342
+ category: "flow",
343
+ check({ scopes }, report) {
344
+ for (const scope of scopes) {
345
+ const links = scope.container.flowElements.flatMap((el) => {
346
+ if (!isEvent(el))
347
+ return [];
348
+ const def = eventDefinitionsOf(el).find((d) => d.type === "link");
349
+ return def?.type === "link" ? [{ el, name: def.name ?? "" }] : [];
350
+ });
351
+ const byName = new Map();
352
+ for (const { el, name } of links) {
353
+ if (name === "") {
354
+ report("flow/link-event-mismatch", `Link event "${el.id}" has no link name.`, "Name the link — a throw and its catch are paired by name.", scope.processId, [el.id]);
355
+ continue;
356
+ }
357
+ byName.set(name, [...(byName.get(name) ?? []), el]);
358
+ }
359
+ for (const [name, events] of byName) {
360
+ const isCatch = (el) => el.type === "intermediateCatchEvent" ||
361
+ el.type === "startEvent" ||
362
+ el.type === "boundaryEvent";
363
+ const catches = events.filter(isCatch);
364
+ if (events.length === 1) {
365
+ const [only] = events;
366
+ report("flow/link-event-mismatch", `Link ${isCatch(only) ? "throw" : "catch"} event with link name "${name}" is missing in this scope.`, "Add the matching link event in the same process or sub-process.", scope.processId, [only.id]);
367
+ }
368
+ else if (catches.length > 1) {
369
+ for (const el of catches) {
370
+ report("flow/link-event-mismatch", `Duplicate link catch event with link name "${name}" in this scope.`, "Keep one catch event per link name.", scope.processId, [el.id]);
371
+ }
372
+ }
373
+ else if (catches.length === 0) {
374
+ for (const el of events) {
375
+ report("flow/link-event-mismatch", `Link catch event with link name "${name}" is missing in this scope.`, "Add a link catch event with the same name.", scope.processId, [el.id]);
376
+ }
377
+ }
378
+ }
379
+ }
380
+ },
381
+ },
382
+ "no-bpmndi": {
383
+ category: "pattern",
384
+ check({ defs }, report) {
385
+ const drawn = new Set();
386
+ for (const diagram of defs.diagrams) {
387
+ for (const shape of diagram.plane.shapes)
388
+ drawn.add(shape.bpmnElement);
389
+ for (const edge of diagram.plane.edges)
390
+ drawn.add(edge.bpmnElement);
391
+ }
392
+ const missing = (id, processId) => {
393
+ if (drawn.has(id))
394
+ return;
395
+ report("pattern/missing-di", `Element "${id}" has no diagram information (BPMNDI).`, "Open and save the file in a modeler, or run `casen bpmn layout`, to draw it.", processId, [id]);
396
+ };
397
+ const lanes = (list, processId) => {
398
+ for (const lane of list) {
399
+ missing(lane.id, processId);
400
+ if (lane.childLaneSet)
401
+ lanes(lane.childLaneSet.lanes, processId);
402
+ }
403
+ };
404
+ const container = (c, processId) => {
405
+ for (const el of c.flowElements) {
406
+ if (el.type !== "dataObject")
407
+ missing(el.id, processId);
408
+ if (isSubContainer(el))
409
+ container(el, processId);
410
+ }
411
+ for (const flow of c.sequenceFlows)
412
+ missing(flow.id, processId);
413
+ for (const artifact of [...c.textAnnotations, ...c.associations, ...c.groups]) {
414
+ missing(artifact.id, processId);
415
+ }
416
+ };
417
+ for (const collaboration of defs.collaborations) {
418
+ for (const participant of collaboration.participants)
419
+ missing(participant.id, defs.id);
420
+ for (const flow of collaboration.messageFlows)
421
+ missing(flow.id, defs.id);
422
+ for (const artifact of [
423
+ ...collaboration.textAnnotations,
424
+ ...collaboration.associations,
425
+ ...collaboration.groups,
426
+ ]) {
427
+ missing(artifact.id, defs.id);
428
+ }
429
+ }
430
+ for (const process of defs.processes) {
431
+ container(process, process.id);
432
+ if (process.laneSet)
433
+ lanes(process.laneSet.lanes, process.id);
434
+ }
435
+ },
436
+ },
437
+ "no-complex-gateway": {
438
+ category: "pattern",
439
+ check({ scopes }, report) {
440
+ discouraged(scopes, report, "complexGateway", "pattern/complex-gateway", "complex gateway");
441
+ },
442
+ },
443
+ "no-disconnected": {
444
+ category: "flow",
445
+ check({ scopes }, report) {
446
+ for (const scope of scopes) {
447
+ if (scope.kind === "adHocSubProcess")
448
+ continue;
449
+ for (const el of scope.container.flowElements) {
450
+ const checked = TASK_TYPES.has(el.type) || isGateway(el) || isSubContainer(el) || isEvent(el);
451
+ if (!checked || isEventSubProcess(el) || el.isForCompensation === true)
452
+ continue;
453
+ const defs = eventDefinitionsOf(el);
454
+ if (el.type === "boundaryEvent" && defs.length === 1 && defs[0]?.type === "compensate")
455
+ continue;
456
+ if ((scope.byTarget.get(el.id) ?? []).length > 0)
457
+ continue;
458
+ if ((scope.bySource.get(el.id) ?? []).length > 0)
459
+ continue;
460
+ report("flow/disconnected", `Element "${el.id}" (${el.type}) is not connected to any sequence flow.`, "Connect it to the process flow or remove it.", scope.processId, [el.id]);
461
+ }
462
+ }
463
+ },
464
+ },
465
+ "no-duplicate-sequence-flows": {
466
+ category: "flow",
467
+ check({ scopes }, report) {
468
+ for (const scope of scopes) {
469
+ const seen = new Set();
470
+ for (const flow of scope.container.sequenceFlows) {
471
+ const key = `${flow.sourceRef}#${flow.targetRef}#${flow.conditionExpression?.text ?? ""}`;
472
+ if (!seen.has(key)) {
473
+ seen.add(key);
474
+ continue;
475
+ }
476
+ report("flow/duplicate-sequence-flow", `Sequence flow "${flow.id}" duplicates another flow from "${flow.sourceRef}" to "${flow.targetRef}".`, "Remove the duplicate — two identical flows spawn two tokens.", scope.processId, [flow.id, flow.sourceRef, flow.targetRef]);
477
+ }
478
+ }
479
+ },
480
+ },
481
+ "no-gateway-join-fork": {
482
+ category: "flow",
483
+ check({ scopes }, report) {
484
+ // `flow/mixed-gateway` from `optimize()` covers the top level.
485
+ for (const scope of scopes) {
486
+ if (scope.kind === "process")
487
+ continue;
488
+ for (const el of scope.container.flowElements) {
489
+ if (!isGateway(el))
490
+ continue;
491
+ const incoming = (scope.byTarget.get(el.id) ?? []).length;
492
+ const outgoing = (scope.bySource.get(el.id) ?? []).length;
493
+ if (incoming <= 1 || outgoing <= 1)
494
+ continue;
495
+ report("flow/mixed-gateway", `Gateway "${el.id}" (${el.type}) has ${incoming} incoming and ${outgoing} outgoing flows — it both joins and forks.`, "Split it into a joining gateway followed by a forking one.", scope.processId, [el.id]);
496
+ }
497
+ }
498
+ },
499
+ },
500
+ "no-implicit-end": {
501
+ category: "flow",
502
+ check({ defs, scopes }, report) {
503
+ const processes = new Map(defs.processes.map((p) => [p.id, p]));
504
+ for (const scope of scopes) {
505
+ // Activities of an ad-hoc sub-process start and end on demand.
506
+ if (scope.kind === "adHocSubProcess")
507
+ continue;
508
+ // bpmnlint looks for a compensation handler's association in the
509
+ // enclosing process only, not in the sub-process that holds the event.
510
+ const associations = processes.get(scope.processId)?.associations ?? [];
511
+ for (const el of scope.container.flowElements) {
512
+ if (!isFlowNode(el) || el.type === "endEvent" || isEventSubProcess(el))
513
+ continue;
514
+ if (el.type === "intermediateThrowEvent" && onlyDefinitions(el, "link"))
515
+ continue;
516
+ if (isActivity(el) && el.isForCompensation === true)
517
+ continue;
518
+ if (el.type === "boundaryEvent" &&
519
+ onlyDefinitions(el, "compensate") &&
520
+ associations.some((a) => a.sourceRef === el.id))
521
+ continue;
522
+ if ((scope.bySource.get(el.id) ?? []).length > 0)
523
+ continue;
524
+ report("flow/implicit-end", `Element "${el.id}" (${el.type}) has no outgoing sequence flow, so it ends the flow implicitly.`, "Connect it to an end event.", scope.processId, [el.id]);
525
+ }
526
+ }
527
+ },
528
+ },
529
+ "no-implicit-start": {
530
+ category: "flow",
531
+ check({ scopes }, report) {
532
+ for (const scope of scopes) {
533
+ if (scope.kind === "adHocSubProcess")
534
+ continue;
535
+ for (const el of scope.container.flowElements) {
536
+ if (!isFlowNode(el) || isEventSubProcess(el))
537
+ continue;
538
+ if (el.type === "startEvent" || el.type === "boundaryEvent")
539
+ continue;
540
+ if (el.type === "intermediateCatchEvent" && onlyDefinitions(el, "link"))
541
+ continue;
542
+ if (isActivity(el) && el.isForCompensation === true)
543
+ continue;
544
+ if ((scope.byTarget.get(el.id) ?? []).length > 0)
545
+ continue;
546
+ report("flow/implicit-start", `Element "${el.id}" (${el.type}) has no incoming sequence flow, so it starts the flow implicitly.`, "Connect it from a start event or an upstream element.", scope.processId, [el.id]);
547
+ }
548
+ }
549
+ },
550
+ },
551
+ "no-implicit-split": {
552
+ category: "flow",
553
+ check({ scopes }, report) {
554
+ for (const scope of scopes) {
555
+ for (const el of scope.container.flowElements) {
556
+ if (!isActivity(el) && !isEvent(el))
557
+ continue;
558
+ const defaultFlow = defaultFlowOf(el);
559
+ const unconditional = (scope.bySource.get(el.id) ?? []).filter((flow) => !hasCondition(flow) && flow.id !== defaultFlow);
560
+ if (unconditional.length <= 1)
561
+ continue;
562
+ report("flow/implicit-split", `Element "${el.id}" (${el.type}) splits the flow implicitly into ${unconditional.length} unconditional flows.`, "Model the split with an explicit parallel gateway.", scope.processId, [el.id]);
563
+ }
564
+ }
565
+ },
566
+ },
567
+ "no-inclusive-gateway": {
568
+ category: "pattern",
569
+ check({ scopes }, report) {
570
+ discouraged(scopes, report, "inclusiveGateway", "pattern/inclusive-gateway", "inclusive gateway");
571
+ },
572
+ },
573
+ "no-overlapping-elements": {
574
+ category: "pattern",
575
+ check({ defs }, report) {
576
+ checkOverlaps(defs, report);
577
+ },
578
+ },
579
+ "single-blank-start-event": {
580
+ category: "flow",
581
+ check({ scopes }, report) {
582
+ for (const scope of scopes) {
583
+ const blank = scope.container.flowElements.filter((el) => el.type === "startEvent" && el.eventDefinitions.length === 0);
584
+ if (blank.length <= 1)
585
+ continue;
586
+ const what = scope.kind === "process" ? "Process" : "Sub-process";
587
+ report("flow/multiple-blank-start-events", `${what} "${scope.container.id}" has ${blank.length} blank start events.`, "Keep one blank start event per scope; give the others a trigger or remove them.", scope.processId, [scope.container.id]);
588
+ }
589
+ },
590
+ },
591
+ "single-event-definition": {
592
+ category: "flow",
593
+ check({ scopes }, report) {
594
+ for (const scope of scopes) {
595
+ for (const el of scope.container.flowElements) {
596
+ const count = eventDefinitionsOf(el).length;
597
+ if (count <= 1)
598
+ continue;
599
+ report("flow/multiple-event-definitions", `Event "${el.id}" has ${count} event definitions.`, "Keep one event definition per event; split the others into separate events.", scope.processId, [el.id]);
600
+ }
601
+ }
602
+ },
603
+ },
604
+ "standard-size": {
605
+ category: "pattern",
606
+ check({ defs, options }, report) {
607
+ checkStandardSizes(defs, options, report);
608
+ },
609
+ },
610
+ "start-event-required": {
611
+ category: "flow",
612
+ check({ scopes }, report) {
613
+ // Top-level processes are covered by `flow/no-start-event`.
614
+ for (const scope of scopes) {
615
+ if (!SUB_SCOPE_KINDS.has(scope.kind))
616
+ continue;
617
+ if (scope.container.flowElements.some((el) => el.type === "startEvent"))
618
+ continue;
619
+ report("flow/sub-process-no-start-event", `Sub-process "${scope.container.id}" has no start event.`, "Add a start event so it is clear where the sub-process begins.", scope.processId, [scope.container.id]);
620
+ }
621
+ },
622
+ },
623
+ "sub-process-blank-start-event": {
624
+ category: "flow",
625
+ check({ scopes }, report) {
626
+ for (const scope of scopes) {
627
+ if (scope.kind === "process" || scope.eventSubProcess)
628
+ continue;
629
+ for (const el of scope.container.flowElements) {
630
+ if (el.type !== "startEvent" || el.eventDefinitions.length === 0)
631
+ continue;
632
+ report("flow/sub-process-typed-start", `Start event "${el.id}" of sub-process "${scope.container.id}" has an event definition.`, "A sub-process is entered through its sequence flow — make the start event blank.", scope.processId, [el.id]);
633
+ }
634
+ }
635
+ },
636
+ },
637
+ "superfluous-gateway": {
638
+ category: "flow",
639
+ check({ scopes }, report) {
640
+ // `flow/redundant-gateway` from `optimize()` covers the top level.
641
+ for (const scope of scopes) {
642
+ if (scope.kind === "process")
643
+ continue;
644
+ for (const el of scope.container.flowElements) {
645
+ if (!isGateway(el))
646
+ continue;
647
+ const incoming = (scope.byTarget.get(el.id) ?? []).length;
648
+ const outgoing = (scope.bySource.get(el.id) ?? []).length;
649
+ if (incoming !== 1 || outgoing !== 1)
650
+ continue;
651
+ report("flow/redundant-gateway", `Gateway "${el.id}" (${el.type}) has only 1 incoming and 1 outgoing flow — it is redundant.`, "Remove this gateway and connect its source directly to its target.", scope.processId, [el.id]);
652
+ }
653
+ }
654
+ },
655
+ },
656
+ "superfluous-label": {
657
+ category: "naming",
658
+ check({ scopes }, report) {
659
+ for (const scope of scopes) {
660
+ const byId = new Map(scope.container.flowElements.map((el) => [el.id, el]));
661
+ for (const flow of scope.container.sequenceFlows) {
662
+ if ((flow.name ?? "").trim() === "" || hasCondition(flow))
663
+ continue;
664
+ const source = byId.get(flow.sourceRef);
665
+ if (defaultFlowOf(source) === flow.id)
666
+ continue;
667
+ const decisionFork = (source?.type === "exclusiveGateway" || source?.type === "inclusiveGateway") &&
668
+ (scope.bySource.get(source.id) ?? []).length > 1;
669
+ if (decisionFork)
670
+ continue;
671
+ report("naming/superfluous-flow-label", `Sequence flow "${flow.id}" is labeled "${flow.name}" but carries no condition.`, "Remove the label — only conditional, default and decision-gateway flows need one.", scope.processId, [flow.id]);
672
+ }
673
+ }
674
+ },
675
+ },
676
+ "superfluous-termination": {
677
+ category: "flow",
678
+ check({ scopes }, report) {
679
+ for (const scope of scopes) {
680
+ if (scope.kind === "adHocSubProcess")
681
+ continue;
682
+ const ends = scope.container.flowElements.filter((el) => isFlowNode(el) && (scope.bySource.get(el.id) ?? []).length === 0);
683
+ const isTerminate = (el) => el.type === "endEvent" && el.eventDefinitions.some((d) => d.type === "terminate");
684
+ const isInterruptingEventSub = (el) => isEventSubProcess(el) &&
685
+ isSubContainer(el) &&
686
+ el.flowElements.some((c) => c.type === "startEvent" && c.isInterrupting !== false);
687
+ const terminates = ends.filter(isTerminate);
688
+ if (terminates.length !== 1)
689
+ continue;
690
+ if (!ends.every((el) => isTerminate(el) || isInterruptingEventSub(el)))
691
+ continue;
692
+ for (const el of terminates) {
693
+ report("flow/superfluous-termination", `Terminate end event "${el.id}" is the only way this scope ends, so terminating is superfluous.`, "Use a plain end event.", scope.processId, [el.id]);
694
+ }
695
+ }
696
+ },
697
+ },
698
+ };
699
+ function discouraged(scopes, report, type, id, label) {
700
+ for (const scope of scopes) {
701
+ for (const el of scope.container.flowElements) {
702
+ if (el.type !== type)
703
+ continue;
704
+ report(id, `Element "${el.id}" is a ${label}, which this project's lint configuration discourages.`, "Model the routing with exclusive or parallel gateways instead.", scope.processId, [el.id]);
705
+ }
706
+ }
707
+ }
708
+ // ---------------------------------------------------------------------------
709
+ // Geometry rules
710
+ // ---------------------------------------------------------------------------
711
+ function validBounds(bounds) {
712
+ return (bounds !== undefined &&
713
+ Number.isFinite(bounds.x) &&
714
+ Number.isFinite(bounds.y) &&
715
+ Number.isFinite(bounds.width) &&
716
+ Number.isFinite(bounds.height));
717
+ }
718
+ /** Touching counts as a collision, as it does in bpmnlint. */
719
+ function collides(a, b) {
720
+ return (a.x + a.width >= b.x && b.x + b.width >= a.x && a.y + a.height >= b.y && b.y + b.height >= a.y);
721
+ }
722
+ function inside(child, parent) {
723
+ return (child.x >= parent.x &&
724
+ child.y >= parent.y &&
725
+ child.x + child.width <= parent.x + parent.width &&
726
+ child.y + child.height <= parent.y + parent.height);
727
+ }
728
+ function shapeIndex(defs) {
729
+ const shapes = new Map();
730
+ for (const diagram of defs.diagrams) {
731
+ for (const shape of diagram.plane.shapes)
732
+ shapes.set(shape.bpmnElement, shape);
733
+ }
734
+ return shapes;
735
+ }
736
+ function checkOverlaps(defs, report) {
737
+ const shapes = shapeIndex(defs);
738
+ const overlapping = new Map();
739
+ const outside = new Map();
740
+ const pairwise = (elements, processId) => {
741
+ for (let i = 0; i < elements.length; i++) {
742
+ const a = elements[i];
743
+ for (let j = i + 1; j < elements.length; j++) {
744
+ const b = elements[j];
745
+ // A boundary event sits on its host by design.
746
+ if (a.attachedToRef === b.id || b.attachedToRef === a.id)
747
+ continue;
748
+ const boundsA = shapes.get(a.id)?.bounds;
749
+ const boundsB = shapes.get(b.id)?.bounds;
750
+ if (!validBounds(boundsA) || !validBounds(boundsB))
751
+ continue;
752
+ if (!collides(boundsA, boundsB))
753
+ continue;
754
+ overlapping.set(a.id, processId);
755
+ overlapping.set(b.id, processId);
756
+ }
757
+ }
758
+ };
759
+ const container = (c, processId, parent) => {
760
+ const drawn = c.flowElements.filter((el) => shapes.has(el.id));
761
+ pairwise(drawn, processId);
762
+ for (const el of drawn) {
763
+ // Data store references may sit outside their parent for historical reasons.
764
+ if (el.type === "dataStoreReference")
765
+ continue;
766
+ const bounds = shapes.get(el.id)?.bounds;
767
+ if (validBounds(bounds) && validBounds(parent) && !inside(bounds, parent)) {
768
+ outside.set(el.id, processId);
769
+ }
770
+ }
771
+ for (const el of c.flowElements) {
772
+ if (!isSubContainer(el))
773
+ continue;
774
+ const shape = shapes.get(el.id);
775
+ container(el, processId, shape?.isExpanded === true ? shape.bounds : undefined);
776
+ }
777
+ };
778
+ const participantBounds = new Map();
779
+ for (const collaboration of defs.collaborations) {
780
+ pairwise(collaboration.participants, defs.id);
781
+ for (const participant of collaboration.participants) {
782
+ const bounds = shapes.get(participant.id)?.bounds;
783
+ if (participant.processRef && bounds)
784
+ participantBounds.set(participant.processRef, bounds);
785
+ }
786
+ }
787
+ for (const process of defs.processes) {
788
+ container(process, process.id, participantBounds.get(process.id));
789
+ }
790
+ for (const [id, processId] of overlapping) {
791
+ report("pattern/overlapping-elements", `Element "${id}" overlaps another element.`, "Move the shapes apart so neither hides the other.", processId, [id]);
792
+ }
793
+ for (const [id, processId] of outside) {
794
+ report("pattern/overlapping-elements", `Element "${id}" lies outside its parent's boundary.`, "Move it inside the pool or sub-process it belongs to.", processId, [id]);
795
+ }
796
+ }
797
+ /** bpmn-js's default sizes, as bpmnlint copies them. Overridable per type. */
798
+ const DEFAULT_SIZES = {
799
+ "bpmn:Task": { width: 100, height: 80 },
800
+ "bpmn:CallActivity": { width: 100, height: 80 },
801
+ "bpmn:SubProcess": { width: 100, height: 80 },
802
+ "bpmn:Gateway": { width: 50, height: 50 },
803
+ "bpmn:Event": { width: 36, height: 36 },
804
+ "bpmn:DataObjectReference": { width: 36, height: 50 },
805
+ "bpmn:DataStoreReference": { width: 50, height: 50 },
806
+ "bpmn:Participant": { width: 60, height: 60 },
807
+ };
808
+ function sizeType(el) {
809
+ if (isSubContainer(el))
810
+ return "bpmn:SubProcess";
811
+ if (el.type === "callActivity")
812
+ return "bpmn:CallActivity";
813
+ if (TASK_TYPES.has(el.type))
814
+ return "bpmn:Task";
815
+ if (isGateway(el))
816
+ return "bpmn:Gateway";
817
+ if (isEvent(el))
818
+ return "bpmn:Event";
819
+ if (el.type === "dataObjectReference")
820
+ return "bpmn:DataObjectReference";
821
+ if (el.type === "dataStoreReference")
822
+ return "bpmn:DataStoreReference";
823
+ return undefined;
824
+ }
825
+ function checkStandardSizes(defs, options, report) {
826
+ const overrides = typeof options === "object" && options !== null ? options : {};
827
+ const sizes = { ...DEFAULT_SIZES, ...overrides };
828
+ const elements = new Map();
829
+ for (const scope of allScopes(defs)) {
830
+ for (const el of scope.container.flowElements) {
831
+ elements.set(el.id, { el, processId: scope.processId });
832
+ }
833
+ }
834
+ const participants = new Map(defs.collaborations.flatMap((c) => c.participants).map((p) => [p.id, p]));
835
+ for (const diagram of defs.diagrams) {
836
+ for (const shape of diagram.plane.shapes) {
837
+ let expected;
838
+ let processId = defs.id;
839
+ const participant = participants.get(shape.bpmnElement);
840
+ if (participant !== undefined) {
841
+ // A pool with content follows its content; an empty one has one fixed breadth.
842
+ if (participant.processRef)
843
+ continue;
844
+ const size = sizes["bpmn:Participant"];
845
+ const horizontal = shape.isHorizontal !== false;
846
+ const value = horizontal ? size?.height : size?.width;
847
+ if (typeof value !== "number")
848
+ continue;
849
+ expected = horizontal ? { height: value } : { width: value };
850
+ }
851
+ else {
852
+ const found = elements.get(shape.bpmnElement);
853
+ if (found === undefined)
854
+ continue;
855
+ if (isSubContainer(found.el) && shape.isExpanded === true)
856
+ continue;
857
+ const type = sizeType(found.el);
858
+ const size = type === undefined ? undefined : sizes[type];
859
+ if (typeof size !== "object" || size === null)
860
+ continue;
861
+ expected = size;
862
+ processId = found.processId;
863
+ }
864
+ const { width, height } = shape.bounds;
865
+ const widthOff = typeof expected.width === "number" && width !== expected.width;
866
+ const heightOff = typeof expected.height === "number" && height !== expected.height;
867
+ if (!widthOff && !heightOff)
868
+ continue;
869
+ const want = typeof expected.height !== "number"
870
+ ? `width ${expected.width}`
871
+ : typeof expected.width !== "number"
872
+ ? `height ${expected.height}`
873
+ : `${expected.width}x${expected.height}`;
874
+ report("pattern/non-standard-size", `Element "${shape.bpmnElement}" is ${width}x${height}; the standard size is ${want}.`, "Resize it to the standard size so diagrams across the project read alike.", processId, [shape.bpmnElement]);
875
+ }
876
+ }
877
+ }
878
+ // ---------------------------------------------------------------------------
879
+ // Entry point
880
+ // ---------------------------------------------------------------------------
881
+ /** The bpmnlint rules this module implements natively. */
882
+ export const NATIVE_BPMNLINT_RULES = Object.keys(RULES);
883
+ /**
884
+ * Runs the native equivalents of the given bpmnlint rules.
885
+ *
886
+ * Findings come back at `warning` severity; the caller applies the severity
887
+ * the `.bpmnlintrc` asked for.
888
+ *
889
+ * @param defs - The model to check.
890
+ * @param rules - bpmnlint rule name → that rule's options from the config.
891
+ * @param categories - When given, rules outside these categories are skipped.
892
+ */
893
+ export function analyzeBpmnlintRules(defs, rules, categories) {
894
+ const findings = [];
895
+ const scopes = allScopes(defs);
896
+ for (const [name, options] of rules) {
897
+ const rule = RULES[name];
898
+ if (rule === undefined)
899
+ continue;
900
+ if (categories !== undefined && !categories.includes(rule.category))
901
+ continue;
902
+ rule.check({ defs, scopes, options }, (id, message, suggestion, processId, elementIds) => {
903
+ findings.push({
904
+ id,
905
+ category: rule.category,
906
+ severity: "warning",
907
+ message,
908
+ suggestion,
909
+ processId,
910
+ elementIds,
911
+ });
912
+ });
913
+ }
914
+ return findings;
915
+ }
916
+ //# sourceMappingURL=bpmnlint-rules.js.map