@bpmnkit/core 1.9.0 → 1.10.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 (108) hide show
  1. package/agent-cards/bpmn.md +3 -3
  2. package/builder-reference.md +11 -9
  3. package/dist/bpmn/auto-layout.js +82 -26
  4. package/dist/bpmn/bpmn-builder.d.ts +84 -7
  5. package/dist/bpmn/bpmn-builder.js +313 -78
  6. package/dist/bpmn/bpmn-model.d.ts +2 -0
  7. package/dist/bpmn/bpmn-parser.js +68 -76
  8. package/dist/bpmn/bpmn-serializer.js +60 -19
  9. package/dist/bpmn/bpmnlint.js +4 -69
  10. package/dist/bpmn/builder-rules.d.ts +20 -0
  11. package/dist/bpmn/builder-rules.js +120 -0
  12. package/dist/bpmn/camunda-compat-data.d.ts +10 -148
  13. package/dist/bpmn/camunda-compat-data.js +16 -407
  14. package/dist/bpmn/camunda-compat-feel.d.ts +3 -0
  15. package/dist/bpmn/camunda-compat-feel.js +1 -1
  16. package/dist/bpmn/camunda-compat.js +7 -6
  17. package/dist/bpmn/camunda7/export.js +4 -1
  18. package/dist/bpmn/camunda7/juel.js +2 -1
  19. package/dist/bpmn/camunda7/migrate.d.ts +23 -0
  20. package/dist/bpmn/camunda7/migrate.js +75 -3
  21. package/dist/bpmn/compact-stream.js +2 -1
  22. package/dist/bpmn/compact.d.ts +80 -4
  23. package/dist/bpmn/compact.js +220 -38
  24. package/dist/bpmn/feel-condition.d.ts +9 -0
  25. package/dist/bpmn/feel-condition.js +19 -0
  26. package/dist/bpmn/full-operations.js +31 -4
  27. package/dist/bpmn/index.d.ts +13 -3
  28. package/dist/bpmn/index.js +16 -15
  29. package/dist/bpmn/operations.d.ts +4 -4
  30. package/dist/bpmn/operations.js +14 -2
  31. package/dist/bpmn/optimize/bpmnlint-rules.js +7 -40
  32. package/dist/bpmn/optimize/index.js +15 -1
  33. package/dist/bpmn/optimize/tasks.js +12 -3
  34. package/dist/bpmn/process-delta.d.ts +18 -0
  35. package/dist/bpmn/process-delta.js +20 -2
  36. package/dist/bpmn/process-text-writer.js +27 -1
  37. package/dist/bpmn/process-text.d.ts +9 -3
  38. package/dist/bpmn/process-text.js +122 -16
  39. package/dist/bpmn/stable-ids.d.ts +2 -0
  40. package/dist/bpmn/stable-ids.js +8 -0
  41. package/dist/bpmn/zeebe-extensions.js +2 -1
  42. package/dist/bpmn/zeebe-placement.js +6 -129
  43. package/dist/bpmn/zeebe-validate/context.d.ts +132 -0
  44. package/dist/bpmn/zeebe-validate/context.js +241 -0
  45. package/dist/bpmn/zeebe-validate/gate.d.ts +87 -0
  46. package/dist/bpmn/zeebe-validate/gate.js +492 -0
  47. package/dist/bpmn/zeebe-validate/index.d.ts +37 -0
  48. package/dist/bpmn/zeebe-validate/index.js +106 -0
  49. package/dist/bpmn/zeebe-validate/rules/events.d.ts +4 -0
  50. package/dist/bpmn/zeebe-validate/rules/events.js +580 -0
  51. package/dist/bpmn/zeebe-validate/rules/extensions.d.ts +4 -0
  52. package/dist/bpmn/zeebe-validate/rules/extensions.js +411 -0
  53. package/dist/bpmn/zeebe-validate/rules/gateways.d.ts +3 -0
  54. package/dist/bpmn/zeebe-validate/rules/gateways.js +296 -0
  55. package/dist/bpmn/zeebe-validate/rules/references.d.ts +3 -0
  56. package/dist/bpmn/zeebe-validate/rules/references.js +495 -0
  57. package/dist/bpmn/zeebe-validate/rules/structure.d.ts +3 -0
  58. package/dist/bpmn/zeebe-validate/rules/structure.js +629 -0
  59. package/dist/bpmn/zeebe-validate/rules/tasks.d.ts +4 -0
  60. package/dist/bpmn/zeebe-validate/rules/tasks.js +446 -0
  61. package/dist/bpmn/zeebe-validate/xml.d.ts +15 -0
  62. package/dist/bpmn/zeebe-validate/xml.js +1062 -0
  63. package/dist/bpmn/zeebe-validate/xsd.d.ts +19 -0
  64. package/dist/bpmn/zeebe-validate/xsd.js +350 -0
  65. package/dist/connectors/apply-element.d.ts +5 -2
  66. package/dist/connectors/apply-element.js +6 -0
  67. package/dist/connectors/apply-many.d.ts +9 -2
  68. package/dist/connectors/apply-many.js +17 -2
  69. package/dist/connectors/apply.d.ts +4 -2
  70. package/dist/connectors/deployability.d.ts +27 -0
  71. package/dist/connectors/deployability.js +41 -0
  72. package/dist/connectors/index.d.ts +1 -0
  73. package/dist/connectors/lines.d.ts +10 -0
  74. package/dist/connectors/lines.js +13 -4
  75. package/dist/dmn/dmn-model.d.ts +24 -4
  76. package/dist/dmn/dmn-parser.js +37 -3
  77. package/dist/dmn/dmn-serializer.js +48 -47
  78. package/dist/dmn/lint.js +4 -11
  79. package/dist/errors.d.ts +30 -1
  80. package/dist/errors.js +31 -0
  81. package/dist/form/form-model.d.ts +11 -0
  82. package/dist/form/form-parser.d.ts +1 -0
  83. package/dist/form/form-parser.js +48 -12
  84. package/dist/form/form-serializer.js +40 -17
  85. package/dist/form/lint.js +6 -40
  86. package/dist/generated/bpmn-elements.d.ts +5 -0
  87. package/dist/generated/bpmn-elements.js +151 -0
  88. package/dist/generated/camunda-compat-data.d.ts +148 -0
  89. package/dist/generated/camunda-compat-data.js +371 -0
  90. package/dist/generated/dmn-elements.d.ts +12 -0
  91. package/dist/generated/dmn-elements.js +45 -0
  92. package/dist/generated/form-elements.d.ts +5 -0
  93. package/dist/generated/form-elements.js +45 -0
  94. package/dist/generated/lint-rules.d.ts +17 -0
  95. package/dist/generated/lint-rules.js +116 -0
  96. package/dist/generated/zeebe-elements.d.ts +10 -0
  97. package/dist/generated/zeebe-elements.js +168 -0
  98. package/dist/generated/zeebe-rules.d.ts +25 -0
  99. package/dist/generated/zeebe-rules.js +202 -0
  100. package/dist/index.d.ts +10 -4
  101. package/dist/index.js +4 -1
  102. package/dist/layout/annotations.js +21 -1
  103. package/dist/layout/orthogonal.js +9 -3
  104. package/dist/plan/compile.d.ts +26 -1
  105. package/dist/plan/compile.js +48 -6
  106. package/dist/plan/merge.d.ts +2 -1
  107. package/dist/plan/merge.js +13 -5
  108. package/package.json +2 -2
@@ -0,0 +1,629 @@
1
+ function eventDefinitions(node) {
2
+ switch (node.type) {
3
+ case "startEvent":
4
+ case "endEvent":
5
+ case "intermediateCatchEvent":
6
+ case "intermediateThrowEvent":
7
+ case "boundaryEvent":
8
+ return node.eventDefinitions;
9
+ default:
10
+ return [];
11
+ }
12
+ }
13
+ function isEventSubProcess(node) {
14
+ return (node.type === "eventSubProcess" ||
15
+ (node.type === "subProcess" && node.triggeredByEvent === true));
16
+ }
17
+ function isActivity(node) {
18
+ switch (node.type) {
19
+ case "task":
20
+ case "serviceTask":
21
+ case "userTask":
22
+ case "scriptTask":
23
+ case "sendTask":
24
+ case "receiveTask":
25
+ case "businessRuleTask":
26
+ case "manualTask":
27
+ case "callActivity":
28
+ case "subProcess":
29
+ case "adHocSubProcess":
30
+ case "eventSubProcess":
31
+ case "transaction":
32
+ return true;
33
+ default:
34
+ return false;
35
+ }
36
+ }
37
+ function children(node) {
38
+ return "flowElements" in node && Array.isArray(node.flowElements) ? node.flowElements : [];
39
+ }
40
+ function startEvents(elements) {
41
+ return elements.filter((e) => e.type === "startEvent");
42
+ }
43
+ function executable(ctx) {
44
+ return new Set(ctx.defs.processes.filter((p) => p.isExecutable === true).map((p) => p.id));
45
+ }
46
+ function scopes(ctx) {
47
+ const ids = executable(ctx);
48
+ return ctx.scopes.filter((s) => ids.has(s.processId));
49
+ }
50
+ function executableProcesses(ctx) {
51
+ return ctx.defs.processes.filter((p) => p.isExecutable === true);
52
+ }
53
+ function nodes(ctx) {
54
+ const ids = executable(ctx);
55
+ return ctx.nodes.filter((n) => ids.has(n.scope.processId));
56
+ }
57
+ function* descendants(el) {
58
+ yield el;
59
+ for (const child of el.children)
60
+ yield* descendants(child);
61
+ }
62
+ function localName(name) {
63
+ return name.slice(name.indexOf(":") + 1);
64
+ }
65
+ const MODEL = "http://www.omg.org/spec/BPMN/20100524/MODEL";
66
+ /** Whether a verbatim element name is in the BPMN model namespace. */
67
+ function isBpmn(ctx, name) {
68
+ const colon = name.indexOf(":");
69
+ const prefix = colon < 0 ? "" : name.slice(0, colon);
70
+ return (ctx.defs.namespaces[prefix] ?? (prefix === "bpmn" ? MODEL : undefined)) === MODEL;
71
+ }
72
+ /** BPMN elements BPMN Kit keeps verbatim whose `name` Zeebe's NameLengthValidator checks. */
73
+ const NAMED = new Set([
74
+ "dataInput",
75
+ "dataOutput",
76
+ "dataState",
77
+ "dataStore",
78
+ "inputSet",
79
+ "outputSet",
80
+ "interface",
81
+ "operation",
82
+ "resource",
83
+ "resourceParameter",
84
+ "resourceRole",
85
+ "performer",
86
+ "humanPerformer",
87
+ "potentialOwner",
88
+ "correlationKey",
89
+ "correlationProperty",
90
+ "property",
91
+ "lane",
92
+ "laneSet",
93
+ "category",
94
+ ]);
95
+ // ---------------------------------------------------------------------------
96
+ // A. ids, executable processes, lengths
97
+ // ---------------------------------------------------------------------------
98
+ const ID_MESSAGE = "Element id must be present and not empty.";
99
+ const ID_SUGGESTION = "Give the element a non-empty id.";
100
+ /**
101
+ * Empty ids on modelled elements (only reachable for models built in memory:
102
+ * XML with an empty id already fails the XSD) and `zeebe:userTaskForm` without
103
+ * an id, which the XSD does not see.
104
+ */
105
+ const idPresent = (ctx) => {
106
+ for (const process of executableProcesses(ctx)) {
107
+ if (process.id === "")
108
+ ctx.report("id-present", "", ID_MESSAGE, ID_SUGGESTION);
109
+ for (const form of ctx.zeebe(process, "userTaskForm"))
110
+ if ((form.attributes.id ?? "") === "")
111
+ ctx.report("id-present", process.id, ID_MESSAGE, ID_SUGGESTION);
112
+ }
113
+ for (const { node, scope } of nodes(ctx))
114
+ if (node.id === "")
115
+ ctx.report("id-present", scope.id, ID_MESSAGE, ID_SUGGESTION);
116
+ const ids = executable(ctx);
117
+ for (const { flow, scope } of ctx.flows)
118
+ if (flow.id === "" && ids.has(scope.processId))
119
+ ctx.report("id-present", scope.id, ID_MESSAGE, ID_SUGGESTION);
120
+ for (const el of [...ctx.defs.messages, ...ctx.defs.signals, ...ctx.defs.escalations])
121
+ if (el.id === "")
122
+ ctx.report("id-present", "", ID_MESSAGE, ID_SUGGESTION);
123
+ };
124
+ const executableProcess = (ctx) => {
125
+ if (executableProcesses(ctx).length === 0)
126
+ ctx.report("executable-process", ctx.defs.id, "Must contain at least one executable process", 'Mark the process isExecutable="true".');
127
+ };
128
+ /**
129
+ * Every id and name Zeebe checks the configured length of, with the element a
130
+ * finding names: the flow node, flow, process or root element, or the one that
131
+ * owns a nested element (event definition, loop, property, ...).
132
+ */
133
+ function lengthTargets(ctx) {
134
+ const out = [];
135
+ // zeebe:property names in extension elements; ids and names of the BPMN elements BPMN Kit keeps verbatim.
136
+ const xml = (owner, trees, verbatim) => {
137
+ for (const tree of trees)
138
+ for (const el of descendants(tree)) {
139
+ if (ctx.isZeebe(el.name, "property"))
140
+ out.push({ owner, name: el.attributes.name });
141
+ else if (verbatim && isBpmn(ctx, el.name))
142
+ out.push({
143
+ owner,
144
+ id: el.attributes.id,
145
+ name: NAMED.has(localName(el.name)) ? el.attributes.name : undefined,
146
+ });
147
+ }
148
+ };
149
+ const laneSet = (owner, set) => {
150
+ if (set === undefined)
151
+ return;
152
+ out.push({ owner, id: set.id, name: set.name });
153
+ for (const lane of set.lanes) {
154
+ out.push({ owner: lane.id, id: lane.id, name: lane.name });
155
+ laneSet(lane.id, lane.childLaneSet);
156
+ }
157
+ };
158
+ const ids = executable(ctx);
159
+ for (const process of ctx.defs.processes) {
160
+ if (!ids.has(process.id))
161
+ continue;
162
+ out.push({ owner: process.id, id: process.id, name: process.name });
163
+ laneSet(process.id, process.laneSet);
164
+ xml(process.id, process.extensionElements, false);
165
+ xml(process.id, process.unknownChildren ?? [], true);
166
+ }
167
+ for (const scope of scopes(ctx)) {
168
+ const container = scope.container;
169
+ const process = ctx.defs.processes.find((p) => p.id === scope.id);
170
+ const artifacts = container ?? process;
171
+ for (const a of [
172
+ ...(artifacts?.textAnnotations ?? []),
173
+ ...(artifacts?.associations ?? []),
174
+ ...(artifacts?.groups ?? []),
175
+ ])
176
+ out.push({ owner: a.id, id: a.id });
177
+ }
178
+ for (const { node } of nodes(ctx)) {
179
+ out.push({ owner: node.id, id: node.id, name: node.name });
180
+ for (const def of eventDefinitions(node)) {
181
+ out.push({ owner: node.id, id: def.id });
182
+ if (def.type === "link")
183
+ out.push({ owner: node.id, name: def.name });
184
+ }
185
+ const loop = node.loopCharacteristics;
186
+ if (loop !== undefined)
187
+ out.push({ owner: node.id, id: loop.id });
188
+ for (const p of node.properties ?? [])
189
+ out.push({ owner: node.id, id: p.id, name: p.name });
190
+ for (const a of [...(node.dataInputAssociations ?? []), ...(node.dataOutputAssociations ?? [])])
191
+ out.push({ owner: node.id, id: a.id });
192
+ xml(node.id, node.extensionElements, false);
193
+ xml(node.id, node.unknownChildren ?? [], true);
194
+ }
195
+ for (const { flow, scope } of ctx.flows) {
196
+ if (!ids.has(scope.processId))
197
+ continue;
198
+ out.push({ owner: flow.id, id: flow.id, name: flow.name });
199
+ if (flow.conditionExpression !== undefined)
200
+ out.push({ owner: flow.id, id: flow.conditionExpression.attributes.id });
201
+ xml(flow.id, flow.extensionElements, false);
202
+ }
203
+ for (const el of [
204
+ ...ctx.defs.messages,
205
+ ...ctx.defs.errors,
206
+ ...ctx.defs.signals,
207
+ ...ctx.defs.escalations,
208
+ ]) {
209
+ out.push({ owner: el.id, id: el.id, name: el.name });
210
+ xml(el.id, el.extensionElements ?? [], false);
211
+ }
212
+ for (const c of ctx.defs.collaborations) {
213
+ out.push({ owner: c.id, id: c.id, name: c.name });
214
+ for (const p of c.participants)
215
+ out.push({ owner: p.id, id: p.id, name: p.name });
216
+ for (const f of c.messageFlows)
217
+ out.push({ owner: f.id, id: f.id, name: f.name });
218
+ for (const a of [...c.textAnnotations, ...c.associations, ...c.groups])
219
+ out.push({ owner: a.id, id: a.id });
220
+ }
221
+ for (const root of ctx.defs.unknownChildren ?? [])
222
+ xml(root.attributes.id ?? ctx.defs.id, [root], true);
223
+ for (const cat of ctx.defs.categories ?? []) {
224
+ out.push({ owner: cat.id ?? "", id: cat.id, name: cat.name });
225
+ for (const v of cat.categoryValues)
226
+ out.push({ owner: v.id, id: v.id });
227
+ }
228
+ out.push({ owner: ctx.defs.id, name: ctx.defs.unknownAttributes.name });
229
+ return out;
230
+ }
231
+ const lengths = (ctx) => {
232
+ const { maxIdLength, maxNameLength, maxWorkerTypeLength } = ctx.limits;
233
+ for (const t of lengthTargets(ctx)) {
234
+ if (t.id !== undefined && t.id.length > maxIdLength)
235
+ ctx.report("id-length", t.owner, `IDs must not be longer than the configured max-id-length of ${maxIdLength} characters.`, `Shorten the id to at most ${maxIdLength} characters.`);
236
+ if (t.name !== undefined && t.name.length > maxNameLength)
237
+ ctx.report("name-length", t.owner, `Names must not be longer than the configured max-name-length of ${maxNameLength} characters.`, `Shorten the name to at most ${maxNameLength} characters.`);
238
+ }
239
+ for (const { node } of nodes(ctx))
240
+ for (const td of ctx.zeebe(node, "taskDefinition")) {
241
+ const type = td.attributes.type;
242
+ if (type !== undefined && type.length > maxWorkerTypeLength)
243
+ ctx.report("worker-type-length", node.id, `Worker types must not be longer than the configured max-worker-type-length of ${maxWorkerTypeLength} characters.`, `Shorten the job type to at most ${maxWorkerTypeLength} characters.`);
244
+ }
245
+ };
246
+ // ---------------------------------------------------------------------------
247
+ // B. supported elements and event definitions
248
+ // ---------------------------------------------------------------------------
249
+ /** Flow elements Zeebe rejects, by BPMN Kit type or verbatim XML name, with Zeebe's class name. */
250
+ const UNSUPPORTED = new Map([
251
+ ["complexGateway", "ComplexGateway"],
252
+ ["transaction", "Transaction"],
253
+ ["implicitThrowEvent", "ImplicitThrowEvent"],
254
+ ["callChoreography", "CallChoreography"],
255
+ ["choreographyTask", "ChoreographyTask"],
256
+ ["subChoreography", "SubChoreography"],
257
+ ]);
258
+ function unsupportedMessage(type) {
259
+ return `Elements of type '${type}' are currently not supported. Please refer to the documentation for a list of supported elements: https://docs.camunda.io/docs/components/modeler/bpmn/bpmn-coverage/`;
260
+ }
261
+ const elementType = (ctx) => {
262
+ for (const { node } of nodes(ctx)) {
263
+ const type = UNSUPPORTED.get(node.type);
264
+ if (type !== undefined)
265
+ ctx.report("element-type", node.id, unsupportedMessage(type), "Use an element Zeebe supports.");
266
+ }
267
+ // Flow elements BPMN Kit does not model stay verbatim in the container's unknown children.
268
+ for (const scope of scopes(ctx)) {
269
+ const owner = scope.container ?? ctx.defs.processes.find((p) => p.id === scope.id);
270
+ for (const el of owner?.unknownChildren ?? []) {
271
+ const type = UNSUPPORTED.get(localName(el.name));
272
+ if (type !== undefined && (el.name.startsWith("bpmn:") || !el.name.includes(":")))
273
+ ctx.report("element-type", el.attributes.id ?? scope.id, unsupportedMessage(type), "Use an element Zeebe supports.");
274
+ }
275
+ }
276
+ };
277
+ const SUPPORTED_DEFINITIONS = [
278
+ "message",
279
+ "timer",
280
+ "error",
281
+ "terminate",
282
+ "signal",
283
+ "link",
284
+ "escalation",
285
+ "compensate",
286
+ "conditional",
287
+ ];
288
+ const eventDefinitionType = (ctx) => {
289
+ for (const { node } of nodes(ctx))
290
+ for (const def of eventDefinitions(node))
291
+ if (!SUPPORTED_DEFINITIONS.includes(def.type))
292
+ ctx.report("event-definition-type", node.id, "Event definition of this type is not supported", "Use an event definition Zeebe supports.");
293
+ };
294
+ const ESP_START_TYPES = [
295
+ "timer",
296
+ "message",
297
+ "error",
298
+ "signal",
299
+ "escalation",
300
+ "conditional",
301
+ ];
302
+ const NON_INTERRUPTING_TYPES = [
303
+ "message",
304
+ "timer",
305
+ "signal",
306
+ "escalation",
307
+ "conditional",
308
+ ];
309
+ const NON_INTERRUPTING = "Non-Interrupting event of this type is not allowed";
310
+ /** Zeebe validates the first start event of an event sub-process (`SubProcessValidator`). */
311
+ const eventSubProcessStart = (ctx) => {
312
+ for (const { node } of nodes(ctx)) {
313
+ if (!isEventSubProcess(node))
314
+ continue;
315
+ const [start] = startEvents(children(node));
316
+ if (start === undefined)
317
+ continue;
318
+ for (const def of start.eventDefinitions) {
319
+ if (!ESP_START_TYPES.includes(def.type))
320
+ ctx.report("event-sub-process-start-type", node.id, "Start events in event subprocesses must be one of: message, timer, error, signal, escalation or conditional", "Give the event sub-process start event a message, timer, error, signal, escalation or conditional definition.");
321
+ if (start.isInterrupting === false && !NON_INTERRUPTING_TYPES.includes(def.type))
322
+ ctx.report("non-interrupting-type", node.id, NON_INTERRUPTING, "Make the start event interrupting, or use a message, timer, signal, escalation or conditional trigger.");
323
+ }
324
+ }
325
+ };
326
+ const ICE_TYPES = ["message", "timer", "signal", "link", "conditional"];
327
+ const BOUNDARY_TYPES = [
328
+ "timer",
329
+ "message",
330
+ "error",
331
+ "signal",
332
+ "escalation",
333
+ "compensate",
334
+ "conditional",
335
+ ];
336
+ const END_TYPES = [
337
+ "error",
338
+ "message",
339
+ "terminate",
340
+ "signal",
341
+ "escalation",
342
+ "compensate",
343
+ ];
344
+ const eventTypes = (ctx) => {
345
+ for (const { node } of nodes(ctx)) {
346
+ if (node.type === "intermediateCatchEvent") {
347
+ const [only] = node.eventDefinitions;
348
+ if (node.eventDefinitions.length === 1 &&
349
+ only !== undefined &&
350
+ !ICE_TYPES.includes(only.type))
351
+ ctx.report("intermediate-catch-type", node.id, "Event definition must be one of: message, timer, signal, link or conditional", "Use a message, timer, signal, link or conditional catch event.");
352
+ }
353
+ else if (node.type === "boundaryEvent") {
354
+ for (const def of node.eventDefinitions)
355
+ if (!BOUNDARY_TYPES.includes(def.type))
356
+ ctx.report("boundary-type", node.id, "Boundary events must be one of: timer, message, error, signal, escalation, conditional", "Use a timer, message, error, signal, escalation, compensation or conditional boundary event.");
357
+ }
358
+ else if (node.type === "endEvent") {
359
+ for (const def of node.eventDefinitions)
360
+ if (!END_TYPES.includes(def.type))
361
+ ctx.report("end-event-type", node.id, "End events must be one of: none, error, message, terminate, signal, escalation or compensation", "Use a none, error, message, terminate, signal, escalation or compensation end event.");
362
+ }
363
+ }
364
+ };
365
+ const boundaryEvents = (ctx) => {
366
+ for (const { node } of nodes(ctx)) {
367
+ if (node.type !== "boundaryEvent")
368
+ continue;
369
+ const interrupting = node.cancelActivity !== false;
370
+ for (const def of node.eventDefinitions) {
371
+ if (def.type === "escalation") {
372
+ const host = ctx.node(node.attachedToRef)?.node.type;
373
+ const supported = host === "subProcess" ||
374
+ host === "eventSubProcess" ||
375
+ host === "adHocSubProcess" ||
376
+ host === "transaction" ||
377
+ host === "callActivity";
378
+ if (!supported)
379
+ ctx.report("escalation-boundary-host", node.id, "An escalation boundary event should only be attached to a subprocess, or a call activity.", "Attach the escalation boundary event to a sub-process or a call activity.");
380
+ }
381
+ if (!interrupting && !NON_INTERRUPTING_TYPES.includes(def.type))
382
+ ctx.report("non-interrupting-type", node.id, NON_INTERRUPTING, "Make the boundary event interrupting, or use a message, timer, signal, escalation or conditional trigger.");
383
+ }
384
+ }
385
+ };
386
+ // ---------------------------------------------------------------------------
387
+ // C. start events and duplicate triggers per scope (ModelUtil)
388
+ // ---------------------------------------------------------------------------
389
+ /** Each value that occurs more than once, in first-occurrence order. */
390
+ function duplicates(values) {
391
+ const out = [];
392
+ values.forEach((v, i) => {
393
+ if (values.indexOf(v) !== i && !out.includes(v))
394
+ out.push(v);
395
+ });
396
+ return out;
397
+ }
398
+ const processStartEvents = (ctx) => {
399
+ for (const process of executableProcesses(ctx)) {
400
+ const starts = startEvents(process.flowElements);
401
+ if (starts.length === 0)
402
+ ctx.report("process-start-event", process.id, "Must have at least one start event", "Add a start event to the process.");
403
+ else if (starts.filter((s) => s.eventDefinitions.length === 0).length > 1)
404
+ ctx.report("multiple-none-start", process.id, "Multiple none start events are not allowed", "Keep one none start event and give the others a trigger.");
405
+ }
406
+ };
407
+ function messageNames(ctx, defs) {
408
+ const out = [];
409
+ for (const d of defs) {
410
+ if (d.type !== "message")
411
+ continue;
412
+ const name = ctx.message(d.messageRef)?.name;
413
+ if (name !== undefined && name !== "")
414
+ out.push(name);
415
+ }
416
+ return out;
417
+ }
418
+ function signalNames(ctx, defs) {
419
+ const out = [];
420
+ for (const d of defs) {
421
+ if (d.type !== "signal")
422
+ continue;
423
+ const name = ctx.signal(d.signalRef)?.name;
424
+ if (name !== undefined && name !== "")
425
+ out.push(name);
426
+ }
427
+ return out;
428
+ }
429
+ function linkNames(defs) {
430
+ const out = [];
431
+ for (const d of defs)
432
+ if (d.type === "link" && d.name !== undefined && d.name !== "")
433
+ out.push(d.name);
434
+ return out;
435
+ }
436
+ /** `ModelUtil.verifyNoDuplicatedEventDefinition`: message, signal and link names. */
437
+ function verifyNames(ctx, { names, owner, definitions }) {
438
+ for (const name of duplicates(messageNames(ctx, definitions)))
439
+ ctx.report(names, owner, `Multiple message event definitions with the same name '${name}' are not allowed.`, "Use a different message for each of these events.");
440
+ for (const name of duplicates(signalNames(ctx, definitions)))
441
+ ctx.report(names, owner, `Multiple signal event definitions with the same name '${name}' are not allowed.`, "Use a different signal for each of these events.");
442
+ for (const name of duplicates(linkNames(definitions)))
443
+ ctx.report(names, owner, `Multiple intermediate catch link event definitions with the same name '${name}' are not allowed.`, "Give each link catch event a unique name.");
444
+ }
445
+ /** `ModelUtil.verifyNoDuplicatedErrorHandler` and its escalation twin. */
446
+ function verifyHandlers(ctx, owner, defs) {
447
+ const handlers = (kind, resolve) => {
448
+ const refs = defs.filter((d) => d.type === kind).map(resolve);
449
+ if (refs.length === 0)
450
+ return;
451
+ const word = kind === "error" ? "error" : "escalation";
452
+ const catchAll = kind === "error"
453
+ ? "The same scope can not contain more than one error catch event without error code. An error catch event without error code catches all errors."
454
+ : "The same scope can not contain more than one escalation catch event without escalation code. An escalation catch event without escalation code catches all escalations.";
455
+ const rule = kind === "error" ? "duplicate-error-catch" : "duplicate-escalation-catch";
456
+ const suggestion = `Give each ${word} catch event of the scope a different ${word} code.`;
457
+ if (refs.filter((r) => r === undefined).length > 1)
458
+ ctx.report(rule, owner, catchAll, suggestion);
459
+ const codes = refs.filter((r) => r !== undefined).map((r) => r?.code);
460
+ const seen = [];
461
+ for (const code of codes) {
462
+ if (seen.includes(code))
463
+ continue;
464
+ seen.push(code);
465
+ if (codes.filter((c) => c === code).length < 2)
466
+ continue;
467
+ ctx.report(rule, owner, code === undefined
468
+ ? catchAll
469
+ : `Multiple ${word} catch events with the same ${word} code '${code}' are not supported on the same scope.`, suggestion);
470
+ }
471
+ };
472
+ handlers("error", (d) => {
473
+ const error = d.type === "error" ? ctx.error(d.errorRef) : undefined;
474
+ return error === undefined ? undefined : { code: error.errorCode };
475
+ });
476
+ handlers("escalation", (d) => {
477
+ const escalation = d.type === "escalation" ? ctx.escalation(d.escalationRef) : undefined;
478
+ return escalation === undefined ? undefined : { code: escalation.escalationCode };
479
+ });
480
+ }
481
+ /**
482
+ * The scope rule ProcessValidator and SubProcessValidator apply to the process
483
+ * and to every sub-process (embedded, event, ad-hoc, transaction): duplicate
484
+ * triggers among the start events of the scope's direct event sub-processes.
485
+ * Their duplicate link catch names are `duplicate-link-catch` (references.ts).
486
+ */
487
+ const scopeDuplicates = (ctx) => {
488
+ for (const scope of scopes(ctx)) {
489
+ const espStarts = scope.flowElements
490
+ .filter(isEventSubProcess)
491
+ .flatMap((esp) => startEvents(children(esp)))
492
+ .flatMap((s) => s.eventDefinitions);
493
+ verifyNames(ctx, {
494
+ names: "duplicate-event-sub-process-trigger",
495
+ owner: scope.id,
496
+ definitions: espStarts,
497
+ });
498
+ verifyHandlers(ctx, scope.id, espStarts);
499
+ }
500
+ };
501
+ const processStartDuplicates = (ctx) => {
502
+ for (const process of executableProcesses(ctx)) {
503
+ const defs = startEvents(process.flowElements).flatMap((s) => s.eventDefinitions);
504
+ verifyNames(ctx, {
505
+ names: "duplicate-signal-start",
506
+ owner: process.id,
507
+ definitions: defs.filter((d) => d.type === "signal"),
508
+ });
509
+ // Start events referring to the same message count once here; MessageValidator reports those.
510
+ const referred = [];
511
+ const messages = defs.filter((d) => {
512
+ if (d.type !== "message")
513
+ return false;
514
+ const message = ctx.message(d.messageRef)?.id;
515
+ if (referred.includes(message))
516
+ return false;
517
+ referred.push(message);
518
+ return true;
519
+ });
520
+ verifyNames(ctx, { names: "duplicate-message-start", owner: process.id, definitions: messages });
521
+ }
522
+ };
523
+ function conditions(starts) {
524
+ const out = [];
525
+ for (const s of starts)
526
+ for (const d of s.eventDefinitions)
527
+ if (d.type === "conditional" && d.condition !== undefined)
528
+ out.push(d.condition);
529
+ return out;
530
+ }
531
+ const conditionalStarts = (ctx) => {
532
+ for (const process of executableProcesses(ctx)) {
533
+ for (const text of duplicates(conditions(startEvents(process.flowElements))))
534
+ ctx.report("duplicate-conditional-start", process.id, `Duplicate condition expression '${text}' found in conditional start events of process '${process.id}'. Condition expressions for conditional start events must be unique within a process.`, "Give each conditional start event a different condition.");
535
+ const espStarts = process.flowElements
536
+ .filter(isEventSubProcess)
537
+ .flatMap((esp) => startEvents(children(esp)));
538
+ for (const text of duplicates(conditions(espStarts)))
539
+ ctx.report("duplicate-event-sub-process-condition", process.id, `Duplicate condition expression '${text}' found in conditional start events of event subprocesses in process '${process.id}'. Condition expressions for conditional start events in event subprocesses must be unique within a process.`, "Give each conditional event sub-process start a different condition.");
540
+ }
541
+ };
542
+ /** ActivityValidator: the boundary events attached to each activity from the same scope. */
543
+ const boundaryDuplicates = (ctx) => {
544
+ for (const { node, scope } of nodes(ctx)) {
545
+ if (!isActivity(node))
546
+ continue;
547
+ const defs = scope.flowElements
548
+ .filter((e) => e.type === "boundaryEvent" && e.attachedToRef === node.id)
549
+ .flatMap(eventDefinitions);
550
+ verifyNames(ctx, { names: "duplicate-boundary-trigger", owner: node.id, definitions: defs });
551
+ verifyHandlers(ctx, node.id, defs);
552
+ }
553
+ };
554
+ const PROCESS_SINGLE_EXTENSIONS = ["versionTag", "jobPriorityDefinition", "case"];
555
+ const processExtensions = (ctx) => {
556
+ for (const process of executableProcesses(ctx))
557
+ for (const local of PROCESS_SINGLE_EXTENSIONS) {
558
+ // zeebe:jobPriorityDefinition and zeebe:case exist from 8.10, the version of the case marker rule.
559
+ if (local !== "versionTag" && !ctx.applies("case-marker"))
560
+ continue;
561
+ if (ctx.zeebe(process, local).length > 1)
562
+ ctx.report("duplicate-process-extension", process.id, `Must have exactly one 'zeebe:${local}' extension element when exists. Please check process definition XML and retain only one extension element.`, `Keep a single zeebe:${local} on the process.`);
563
+ }
564
+ };
565
+ const caseMarker = (ctx) => {
566
+ for (const process of executableProcesses(ctx))
567
+ for (const c of ctx.zeebe(process, "case")) {
568
+ const title = c.attributes.title;
569
+ if (title === undefined || title.trim() === "")
570
+ ctx.report("case-marker", process.id, "Attribute 'title' must be present and not empty", "Set the case title to a variable name.");
571
+ else if (title.startsWith("="))
572
+ ctx.report("case-marker", process.id, "Attribute 'title' must be a variable name, not an expression", "Set the case title to a variable name without '='.");
573
+ }
574
+ const misplaced = (owner, type, el) => {
575
+ if (ctx.zeebe(el, "case").length > 0)
576
+ ctx.report("case-marker", owner, `The case marker 'zeebe:case' is only allowed on a process, but was found on '${type}'`, "Move zeebe:case to the process.");
577
+ };
578
+ for (const { node } of nodes(ctx))
579
+ misplaced(node.id, node.type === "eventSubProcess" ? "subProcess" : node.type, node);
580
+ const ids = executable(ctx);
581
+ for (const { flow, scope } of ctx.flows)
582
+ if (ids.has(scope.processId))
583
+ misplaced(flow.id, "sequenceFlow", flow);
584
+ for (const m of ctx.defs.messages)
585
+ misplaced(m.id, "message", m);
586
+ for (const e of ctx.defs.errors)
587
+ misplaced(e.id, "error", e);
588
+ for (const s of ctx.defs.signals)
589
+ misplaced(s.id, "signal", s);
590
+ for (const e of ctx.defs.escalations)
591
+ misplaced(e.id, "escalation", e);
592
+ };
593
+ /** Checks for zeebe-rules.md sections A-C (see index.ts), in spec order. */
594
+ /**
595
+ * Z26, from the message's side (MessageValidator): one message may start at most
596
+ * one top-level start event across every process of the file, executable or not.
597
+ */
598
+ const sharedStartMessage = (ctx) => {
599
+ for (const message of ctx.defs.messages) {
600
+ let count = 0;
601
+ for (const process of ctx.defs.processes)
602
+ for (const el of process.flowElements)
603
+ if (el.type === "startEvent")
604
+ for (const def of el.eventDefinitions)
605
+ if (def.type === "message" && ctx.message(def.messageRef) === message)
606
+ count += 1;
607
+ if (count > 1)
608
+ ctx.report("duplicate-message-start", message.id, "A message cannot be referred by more than one start event", "Give each message start event its own message.");
609
+ }
610
+ };
611
+ export const checks = [
612
+ idPresent,
613
+ executableProcess,
614
+ lengths,
615
+ elementType,
616
+ eventDefinitionType,
617
+ eventSubProcessStart,
618
+ eventTypes,
619
+ boundaryEvents,
620
+ processStartEvents,
621
+ scopeDuplicates,
622
+ processStartDuplicates,
623
+ sharedStartMessage,
624
+ conditionalStarts,
625
+ boundaryDuplicates,
626
+ processExtensions,
627
+ caseMarker,
628
+ ];
629
+ //# sourceMappingURL=structure.js.map
@@ -0,0 +1,4 @@
1
+ import { type ZeebeCheck } from "../context.js";
2
+ /** Checks for zeebe-rules.md section F (see index.ts), in spec order. */
3
+ export declare const checks: ZeebeCheck[];
4
+ //# sourceMappingURL=tasks.d.ts.map