@bpmnkit/core 1.8.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 (110) hide show
  1. package/agent-cards/bpmn.md +4 -2
  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 +321 -76
  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 +17 -1
  28. package/dist/bpmn/index.js +19 -25
  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/xsd-guards.d.ts +8 -0
  42. package/dist/bpmn/xsd-guards.js +56 -0
  43. package/dist/bpmn/zeebe-extensions.js +2 -1
  44. package/dist/bpmn/zeebe-placement.js +6 -129
  45. package/dist/bpmn/zeebe-validate/context.d.ts +132 -0
  46. package/dist/bpmn/zeebe-validate/context.js +241 -0
  47. package/dist/bpmn/zeebe-validate/gate.d.ts +87 -0
  48. package/dist/bpmn/zeebe-validate/gate.js +492 -0
  49. package/dist/bpmn/zeebe-validate/index.d.ts +37 -0
  50. package/dist/bpmn/zeebe-validate/index.js +106 -0
  51. package/dist/bpmn/zeebe-validate/rules/events.d.ts +4 -0
  52. package/dist/bpmn/zeebe-validate/rules/events.js +580 -0
  53. package/dist/bpmn/zeebe-validate/rules/extensions.d.ts +4 -0
  54. package/dist/bpmn/zeebe-validate/rules/extensions.js +411 -0
  55. package/dist/bpmn/zeebe-validate/rules/gateways.d.ts +3 -0
  56. package/dist/bpmn/zeebe-validate/rules/gateways.js +296 -0
  57. package/dist/bpmn/zeebe-validate/rules/references.d.ts +3 -0
  58. package/dist/bpmn/zeebe-validate/rules/references.js +495 -0
  59. package/dist/bpmn/zeebe-validate/rules/structure.d.ts +3 -0
  60. package/dist/bpmn/zeebe-validate/rules/structure.js +629 -0
  61. package/dist/bpmn/zeebe-validate/rules/tasks.d.ts +4 -0
  62. package/dist/bpmn/zeebe-validate/rules/tasks.js +446 -0
  63. package/dist/bpmn/zeebe-validate/xml.d.ts +15 -0
  64. package/dist/bpmn/zeebe-validate/xml.js +1062 -0
  65. package/dist/bpmn/zeebe-validate/xsd.d.ts +19 -0
  66. package/dist/bpmn/zeebe-validate/xsd.js +350 -0
  67. package/dist/connectors/apply-element.d.ts +5 -2
  68. package/dist/connectors/apply-element.js +6 -0
  69. package/dist/connectors/apply-many.d.ts +9 -2
  70. package/dist/connectors/apply-many.js +17 -2
  71. package/dist/connectors/apply.d.ts +4 -2
  72. package/dist/connectors/deployability.d.ts +27 -0
  73. package/dist/connectors/deployability.js +41 -0
  74. package/dist/connectors/index.d.ts +1 -0
  75. package/dist/connectors/lines.d.ts +10 -0
  76. package/dist/connectors/lines.js +13 -4
  77. package/dist/dmn/dmn-model.d.ts +24 -4
  78. package/dist/dmn/dmn-parser.js +37 -3
  79. package/dist/dmn/dmn-serializer.js +48 -47
  80. package/dist/dmn/lint.js +4 -11
  81. package/dist/errors.d.ts +30 -1
  82. package/dist/errors.js +31 -0
  83. package/dist/form/form-model.d.ts +11 -0
  84. package/dist/form/form-parser.d.ts +1 -0
  85. package/dist/form/form-parser.js +48 -12
  86. package/dist/form/form-serializer.js +40 -17
  87. package/dist/form/lint.js +6 -40
  88. package/dist/generated/bpmn-elements.d.ts +5 -0
  89. package/dist/generated/bpmn-elements.js +151 -0
  90. package/dist/generated/camunda-compat-data.d.ts +148 -0
  91. package/dist/generated/camunda-compat-data.js +371 -0
  92. package/dist/generated/dmn-elements.d.ts +12 -0
  93. package/dist/generated/dmn-elements.js +45 -0
  94. package/dist/generated/form-elements.d.ts +5 -0
  95. package/dist/generated/form-elements.js +45 -0
  96. package/dist/generated/lint-rules.d.ts +17 -0
  97. package/dist/generated/lint-rules.js +116 -0
  98. package/dist/generated/zeebe-elements.d.ts +10 -0
  99. package/dist/generated/zeebe-elements.js +168 -0
  100. package/dist/generated/zeebe-rules.d.ts +25 -0
  101. package/dist/generated/zeebe-rules.js +202 -0
  102. package/dist/index.d.ts +11 -4
  103. package/dist/index.js +4 -1
  104. package/dist/layout/annotations.js +21 -1
  105. package/dist/layout/orthogonal.js +9 -3
  106. package/dist/plan/compile.d.ts +26 -1
  107. package/dist/plan/compile.js +48 -6
  108. package/dist/plan/merge.d.ts +2 -1
  109. package/dist/plan/merge.js +13 -5
  110. package/package.json +2 -2
@@ -0,0 +1,495 @@
1
+ import { evaluate, parseExpression } from "@bpmnkit/feel";
2
+ import { feelError, feelFailure, isExpression, staticValueMessage, } from "../context.js";
3
+ function eventDefinitions(node) {
4
+ switch (node.type) {
5
+ case "startEvent":
6
+ case "endEvent":
7
+ case "intermediateCatchEvent":
8
+ case "intermediateThrowEvent":
9
+ case "boundaryEvent":
10
+ return node.eventDefinitions;
11
+ default:
12
+ return [];
13
+ }
14
+ }
15
+ /** Every event definition of the type, in document order, with the node that owns it. */
16
+ function defsOf(ctx, type, nodeTypes) {
17
+ const out = [];
18
+ for (const entry of ctx.nodes) {
19
+ if (nodeTypes !== undefined && !nodeTypes.includes(entry.node.type))
20
+ continue;
21
+ for (const def of eventDefinitions(entry.node)) {
22
+ if (def.type === type)
23
+ out.push({ entry, def: def });
24
+ }
25
+ }
26
+ return out;
27
+ }
28
+ const CATCH = ["intermediateCatchEvent", "boundaryEvent"];
29
+ const THROW = ["intermediateThrowEvent", "endEvent"];
30
+ /** Zeebe's `getAttributeValue(...) == null || isEmpty()`. */
31
+ function blank(value) {
32
+ return value === undefined || value === "";
33
+ }
34
+ /** Start events of the process itself, which Zeebe validates as process start events. */
35
+ function isProcessStart(entry) {
36
+ return entry.node.type === "startEvent" && entry.scope.kind === "process";
37
+ }
38
+ /** Start events of the sub-processes directly in a process (Zeebe's `p.getChildElementsByType(SubProcess)`). */
39
+ function isSubProcessStart(entry) {
40
+ return (entry.node.type === "startEvent" &&
41
+ entry.scope.kind !== "process" &&
42
+ entry.scope.parent?.kind === "process");
43
+ }
44
+ /** Zeebe's `ResultType` name of a FEEL value. */
45
+ function resultType(value) {
46
+ if (value === null)
47
+ return "NULL";
48
+ if (typeof value === "string")
49
+ return "STRING";
50
+ if (typeof value === "number")
51
+ return "NUMBER";
52
+ if (typeof value === "boolean")
53
+ return "BOOLEAN";
54
+ if (Array.isArray(value))
55
+ return "ARRAY";
56
+ switch (value.type) {
57
+ case "date":
58
+ return "DATE";
59
+ case "time":
60
+ return "TIME";
61
+ case "date-time":
62
+ return "DATE_TIME";
63
+ case "days-time-duration":
64
+ return "DURATION";
65
+ case "years-months-duration":
66
+ return "PERIOD";
67
+ default:
68
+ return "OBJECT";
69
+ }
70
+ }
71
+ /**
72
+ * What the start event name validators say about a name that has to be known
73
+ * without variables: the evaluated string, or Zeebe's message. Variables are
74
+ * `null` there, so `=x` is a NULL, not a failure.
75
+ */
76
+ function constantName(name, what) {
77
+ if (!isExpression(name))
78
+ return { value: name };
79
+ const detail = `Expected constant expression but found '${name}', which could not be evaluated without context: `;
80
+ const { ast, errors } = parseExpression(name.slice(1));
81
+ if (ast === null || errors.length > 0)
82
+ return { problem: `${detail}${feelFailure(name)}` };
83
+ // Signal names are evaluated with a context whose variable lookup is null, which
84
+ // feel-scala turns into a failure; message names get an empty answer, a NULL.
85
+ let touchedVariable = false;
86
+ const vars = new Proxy({}, {
87
+ getOwnPropertyDescriptor() {
88
+ touchedVariable = true;
89
+ return undefined;
90
+ },
91
+ get() {
92
+ touchedVariable = true;
93
+ return undefined;
94
+ },
95
+ });
96
+ let value;
97
+ try {
98
+ value = evaluate(ast, { vars });
99
+ }
100
+ catch (e) {
101
+ return { problem: `${detail}${e instanceof Error ? e.message : String(e)}` };
102
+ }
103
+ if (touchedVariable && what === "signal") {
104
+ return {
105
+ problem: `${detail}failed to evaluate expression '${name.slice(1)}' : java.lang.NullPointerException: Cannot invoke "io.camunda.zeebe.util.Either.fold(java.util.function.Function, java.util.function.Function)" because the return value of "io.camunda.zeebe.el.EvaluationContext.getVariable(String)" is null`,
106
+ };
107
+ }
108
+ if (typeof value === "string")
109
+ return { value };
110
+ return {
111
+ problem: `Expected constant expression of type String for ${what} name '${name}', but was ${resultType(value)}`,
112
+ };
113
+ }
114
+ /** The message, or `undefined` when the reference is absent or dangling. */
115
+ function messageOf(ctx, ref) {
116
+ return ctx.message(ref);
117
+ }
118
+ // ---------------------------------------------------------------------------
119
+ // Messages: Z61-Z73
120
+ // ---------------------------------------------------------------------------
121
+ const MESSAGE_REFERENCE_RULES = (ctx) => {
122
+ // Z61: every message definition that is not on a throw event (start, catch, boundary).
123
+ for (const { entry, def } of defsOf(ctx, "message")) {
124
+ if (THROW.includes(entry.node.type))
125
+ continue;
126
+ if (messageOf(ctx, def.messageRef) === undefined) {
127
+ ctx.report("message-reference", entry.node.id, "Must reference a message", "Reference a message with messageRef on the message event definition.");
128
+ }
129
+ }
130
+ // Z72
131
+ for (const { node } of ctx.nodes) {
132
+ if (node.type === "receiveTask" && messageOf(ctx, node.messageRef) === undefined) {
133
+ ctx.report("receive-task-message", node.id, "Must reference a message", "Set messageRef on the receive task to a message.");
134
+ }
135
+ }
136
+ };
137
+ function messageUsage(ctx, message) {
138
+ const refs = (type) => defsOf(ctx, type).filter(({ def }) => messageOf(ctx, def.messageRef) === message);
139
+ const all = refs("message");
140
+ const byNode = (types) => all.some(({ entry }) => types.includes(entry.node.type));
141
+ const taskRef = (type) => ctx.nodes.some(({ node }) => node.type === type && messageOf(ctx, node.messageRef) === message);
142
+ return {
143
+ catches: byNode(CATCH) || taskRef("receiveTask"),
144
+ throws: byNode(THROW) || taskRef("sendTask"),
145
+ subProcessStarts: all.filter(({ entry }) => isSubProcessStart(entry)).length,
146
+ processStarts: all.filter(({ entry }) => isProcessStart(entry)).length,
147
+ };
148
+ }
149
+ const MESSAGE_ROOT_RULES = (ctx) => {
150
+ for (const message of ctx.defs.messages) {
151
+ const usage = messageUsage(ctx, message);
152
+ const name = message.name;
153
+ const nameMissing = () => ctx.report("message-name", message.id, "Name must be present and not empty", "Give the message a non-empty name.");
154
+ if (usage.catches || usage.subProcessStarts === 1) {
155
+ if (blank(name))
156
+ nameMissing();
157
+ // Z63
158
+ if (ctx.zeebe(message, "subscription").length !== 1) {
159
+ ctx.report("message-subscription", message.id, "Must have exactly one zeebe:subscription extension element", "Add one zeebe:subscription with a correlationKey to the message.");
160
+ }
161
+ }
162
+ else if (usage.throws) {
163
+ if (blank(name))
164
+ nameMissing();
165
+ }
166
+ else if (usage.processStarts === 1) {
167
+ if (blank(name))
168
+ nameMissing();
169
+ }
170
+ // Z64 / Z65: every zeebe:subscription, referenced or not.
171
+ for (const sub of ctx.zeebe(message, "subscription")) {
172
+ const key = sub.attributes.correlationKey;
173
+ if (key === undefined || key === "") {
174
+ ctx.report("subscription-correlation-key", message.id, "Attribute 'correlationKey' must be present and not empty", "Set correlationKey on zeebe:subscription to a FEEL expression such as '=orderId'.");
175
+ // Zeebe's expression check treats an empty key as missing: one rejection, not two.
176
+ continue;
177
+ }
178
+ if (!isExpression(key)) {
179
+ ctx.report("correlation-key-expression", message.id, staticValueMessage(key), "Start the correlationKey with '=' so it is a FEEL expression.");
180
+ }
181
+ else if (feelError(key) !== undefined) {
182
+ ctx.report("correlation-key-expression", message.id, feelFailure(key), "Fix the FEEL syntax of the correlationKey.");
183
+ }
184
+ }
185
+ // Z66
186
+ if (name !== undefined && feelError(name) !== undefined) {
187
+ ctx.report("message-name-expression", message.id, feelFailure(name), "Fix the FEEL syntax of the message name.");
188
+ }
189
+ }
190
+ };
191
+ const MESSAGE_START_RULES = (ctx) => {
192
+ for (const { entry, def } of defsOf(ctx, "message", ["startEvent"])) {
193
+ if (!isProcessStart(entry))
194
+ continue;
195
+ const name = messageOf(ctx, def.messageRef)?.name;
196
+ if (name === undefined)
197
+ continue;
198
+ const result = constantName(name, "message");
199
+ if ("problem" in result) {
200
+ // Z67
201
+ ctx.report("message-start-name-constant", entry.node.id, result.problem, "Use a static message name, or a FEEL expression that needs no variables.");
202
+ }
203
+ else if (result.value.length > ctx.limits.maxNameLength) {
204
+ // Z68
205
+ ctx.report("message-start-name-length", entry.node.id, `Expected message name '${result.value}' to be at most ${ctx.limits.maxNameLength} characters long (configured max-name-length), but was ${result.value.length} characters.`, "Shorten the message name.");
206
+ }
207
+ }
208
+ };
209
+ /** The `zeebe:publishMessage` elements of a message throw event or send task. */
210
+ function publishMessages(ctx, holder) {
211
+ return ctx.zeebe(holder, "publishMessage");
212
+ }
213
+ const MESSAGE_THROW_RULES = (ctx) => {
214
+ for (const entry of ctx.nodes) {
215
+ const node = entry.node;
216
+ if (node.type !== "intermediateThrowEvent" && node.type !== "endEvent")
217
+ continue;
218
+ const def = node.eventDefinitions.find((d) => d.type === "message");
219
+ if (def === undefined || def.type !== "message")
220
+ continue;
221
+ const publish = publishMessages(ctx, def).length;
222
+ const task = ctx.zeebe(node, "taskDefinition").length;
223
+ const exactlyOne = (publish === 1 && task === 0) || (publish === 0 && task === 1);
224
+ if (!exactlyOne) {
225
+ // Z69
226
+ ctx.report("message-throw-implementation", node.id, "Must have either one 'zeebe:publishMessage' or one 'zeebe:taskDefinition' extension element", "Add a zeebe:publishMessage to the message event definition, or a zeebe:taskDefinition to the event.");
227
+ }
228
+ else if (task === 0 && messageOf(ctx, def.messageRef) === undefined) {
229
+ // Z70
230
+ ctx.report("message-throw-reference", node.id, "Must reference a message", "Reference a message with messageRef on the message event definition.");
231
+ }
232
+ }
233
+ // Z71: Zeebe checks every zeebe:publishMessage, wherever it sits.
234
+ for (const { node } of ctx.nodes) {
235
+ const holders = [node];
236
+ for (const def of eventDefinitions(node)) {
237
+ if (def.type === "message")
238
+ holders.push(def);
239
+ }
240
+ for (const holder of holders) {
241
+ for (const publish of publishMessages(ctx, holder)) {
242
+ if (blank(publish.attributes.correlationKey)) {
243
+ ctx.report("publish-message-correlation-key", node.id, "Attribute 'correlationKey' must be present and not empty", "Set correlationKey on zeebe:publishMessage to a FEEL expression such as '=orderId'.");
244
+ }
245
+ }
246
+ }
247
+ }
248
+ };
249
+ const RECEIVE_TASK_RULES = (ctx) => {
250
+ for (const { node } of ctx.nodes) {
251
+ if (node.type !== "receiveTask")
252
+ continue;
253
+ const message = messageOf(ctx, node.messageRef);
254
+ if (message === undefined)
255
+ continue;
256
+ const clash = ctx.boundaries(node.id).some(({ node: boundary }) => eventDefinitions(boundary).some((def) => {
257
+ if (def.type !== "message")
258
+ return false;
259
+ const other = messageOf(ctx, def.messageRef);
260
+ return other?.name !== undefined && other.name !== "" && other.name === message.name;
261
+ }));
262
+ if (clash) {
263
+ // Z73
264
+ ctx.report("receive-task-boundary-message", node.id, "Cannot reference the same message name as a boundary event", "Give the receive task and its boundary event messages different names.");
265
+ }
266
+ }
267
+ };
268
+ // ---------------------------------------------------------------------------
269
+ // Signals: Z74-Z76
270
+ // ---------------------------------------------------------------------------
271
+ function signalUsage(ctx, signal) {
272
+ const all = defsOf(ctx, "signal").filter(({ def }) => ctx.signal(def.signalRef) === signal);
273
+ const byNode = (types) => all.some(({ entry }) => types.includes(entry.node.type));
274
+ return {
275
+ roles: byNode(CATCH) || byNode(THROW),
276
+ subProcessStarts: all.filter(({ entry }) => isSubProcessStart(entry)).length,
277
+ processStarts: all.filter(({ entry }) => isProcessStart(entry)).length,
278
+ };
279
+ }
280
+ const SIGNAL_RULES = (ctx) => {
281
+ // Z74
282
+ for (const { entry, def } of defsOf(ctx, "signal")) {
283
+ if (ctx.signal(def.signalRef) === undefined) {
284
+ ctx.report("signal-reference", entry.node.id, "Must reference a signal", "Reference a signal with signalRef on the signal event definition.");
285
+ }
286
+ }
287
+ for (const signal of ctx.defs.signals) {
288
+ const usage = signalUsage(ctx, signal);
289
+ // Z75
290
+ if ((usage.roles || usage.subProcessStarts === 1 || usage.processStarts > 0) &&
291
+ blank(signal.name)) {
292
+ ctx.report("signal-name", signal.id, "Name must be present and not empty", "Give the signal a non-empty name.");
293
+ }
294
+ // Z76, FEEL part
295
+ if (signal.name !== undefined && feelError(signal.name) !== undefined) {
296
+ ctx.report("signal-name-expression", signal.id, feelFailure(signal.name), "Fix the FEEL syntax of the signal name.");
297
+ }
298
+ }
299
+ // Z76, start events: no variables at deploy time
300
+ for (const { entry, def } of defsOf(ctx, "signal", ["startEvent"])) {
301
+ if (!isProcessStart(entry))
302
+ continue;
303
+ const name = ctx.signal(def.signalRef)?.name;
304
+ if (name === undefined)
305
+ continue;
306
+ const result = constantName(name, "signal");
307
+ if ("problem" in result) {
308
+ ctx.report("signal-name-expression", entry.node.id, result.problem, "Use a static signal name, or a FEEL expression that needs no variables.");
309
+ }
310
+ }
311
+ };
312
+ // ---------------------------------------------------------------------------
313
+ // Errors and escalations: Z77-Z82
314
+ // ---------------------------------------------------------------------------
315
+ const ERROR_RULES = (ctx) => {
316
+ for (const { entry, def } of defsOf(ctx, "error")) {
317
+ const error = ctx.error(def.errorRef);
318
+ if (entry.node.type === "endEvent") {
319
+ if (error === undefined) {
320
+ // Z77
321
+ ctx.report("error-end-reference", entry.node.id, "Must reference an error", "Reference an error with errorRef on the error event definition.");
322
+ }
323
+ else if (blank(error.errorCode)) {
324
+ // Z78
325
+ ctx.report("error-code", entry.node.id, "ErrorCode must be present and not empty", "Set an errorCode on the error.");
326
+ }
327
+ }
328
+ else if (error?.errorCode?.startsWith("=")) {
329
+ // Z79: the code is matched literally, so a FEEL expression can never match
330
+ ctx.report("error-catch-code-expression", entry.node.id, "The errorCode of the error catch event is not allowed to be an expression", "Use a literal errorCode, without a leading '='.");
331
+ }
332
+ }
333
+ };
334
+ const ESCALATION_RULES = (ctx) => {
335
+ for (const { entry, def } of defsOf(ctx, "escalation")) {
336
+ const escalation = ctx.escalation(def.escalationRef);
337
+ const type = entry.node.type;
338
+ if ((type === "intermediateThrowEvent" || type === "endEvent") && escalation === undefined) {
339
+ // Z80
340
+ ctx.report("escalation-throw-reference", entry.node.id, "Must reference an escalation", "Reference an escalation with escalationRef on the escalation event definition.");
341
+ }
342
+ const isCatch = type === "startEvent" || type === "intermediateCatchEvent" || type === "boundaryEvent";
343
+ if (isCatch && escalation?.escalationCode?.startsWith("=")) {
344
+ // Z82
345
+ ctx.report("escalation-catch-code-expression", entry.node.id, "The escalationCode of the escalation catch event is not allowed to be an expression", "Use a literal escalationCode, without a leading '='.");
346
+ }
347
+ }
348
+ // Z81
349
+ const thrown = new Set();
350
+ for (const { entry, def } of defsOf(ctx, "escalation")) {
351
+ if ((entry.node.type === "intermediateThrowEvent" || entry.node.type === "endEvent") &&
352
+ def.escalationRef !== undefined) {
353
+ thrown.add(def.escalationRef);
354
+ }
355
+ }
356
+ for (const escalation of ctx.defs.escalations) {
357
+ if (thrown.has(escalation.id) && blank(escalation.escalationCode)) {
358
+ ctx.report("escalation-code", escalation.id, "EscalationCode must be present and not empty", "Set an escalationCode on the escalation.");
359
+ }
360
+ }
361
+ };
362
+ // ---------------------------------------------------------------------------
363
+ // Links: Z83-Z85
364
+ // ---------------------------------------------------------------------------
365
+ function isWithin(scope, ancestor) {
366
+ for (let s = scope; s !== undefined; s = s.parent) {
367
+ if (s === ancestor)
368
+ return true;
369
+ }
370
+ return false;
371
+ }
372
+ const LINK_RULES = (ctx) => {
373
+ const links = defsOf(ctx, "link");
374
+ // Z83
375
+ for (const { entry, def } of links) {
376
+ if (blank(def.name)) {
377
+ ctx.report("link-name", entry.node.id, "Link name must be present and not empty.", "Give the link event definition a name.");
378
+ }
379
+ }
380
+ const named = (type) => links.filter(({ entry, def }) => entry.node.type === type && !blank(def.name));
381
+ const catches = named("intermediateCatchEvent");
382
+ const throws = named("intermediateThrowEvent");
383
+ // Zeebe runs this for the process and for every sub-process: the catch events are
384
+ // collected through nested sub-processes, the throw events only directly in it.
385
+ for (const scope of ctx.scopes) {
386
+ const below = catches.filter(({ entry }) => isWithin(entry.scope, scope));
387
+ const counts = new Map();
388
+ for (const { def } of below)
389
+ counts.set(def.name ?? "", (counts.get(def.name ?? "") ?? 0) + 1);
390
+ for (const [name, count] of counts) {
391
+ if (count > 1) {
392
+ // Z85
393
+ ctx.report("duplicate-link-catch", scope.id, `Multiple intermediate catch link event definitions with the same name '${name}' are not allowed.`, "Give each link catch event its own name.");
394
+ }
395
+ }
396
+ const direct = new Set(below.filter(({ entry }) => entry.scope === scope).map(({ def }) => def.name));
397
+ for (const { entry, def } of throws) {
398
+ if (entry.scope !== scope || direct.has(def.name))
399
+ continue;
400
+ // Z84
401
+ ctx.report("link-throw-catch", scope.id, `Can't find an catch link event for the throw link event with the name '${def.name}'.`, "Add a link catch event with the same name in the same scope.");
402
+ }
403
+ }
404
+ };
405
+ // ---------------------------------------------------------------------------
406
+ // Compensation: Z86-Z89
407
+ // ---------------------------------------------------------------------------
408
+ const ACTIVITY_TYPES = [
409
+ "task",
410
+ "serviceTask",
411
+ "scriptTask",
412
+ "userTask",
413
+ "businessRuleTask",
414
+ "sendTask",
415
+ "receiveTask",
416
+ "manualTask",
417
+ "callActivity",
418
+ "subProcess",
419
+ "eventSubProcess",
420
+ "adHocSubProcess",
421
+ "transaction",
422
+ ];
423
+ const SUB_PROCESS_TYPES = [
424
+ "subProcess",
425
+ "adHocSubProcess",
426
+ "transaction",
427
+ ];
428
+ const TASK_TYPES = [
429
+ "task",
430
+ "serviceTask",
431
+ "scriptTask",
432
+ "userTask",
433
+ "businessRuleTask",
434
+ "sendTask",
435
+ "receiveTask",
436
+ "manualTask",
437
+ ];
438
+ const COMPENSATION_RULES = (ctx) => {
439
+ for (const { entry, def } of defsOf(ctx, "compensate")) {
440
+ const ref = def.activityRef;
441
+ const target = ref === undefined ? undefined : ctx.node(ref);
442
+ const activity = target !== undefined && ACTIVITY_TYPES.includes(target.node.type) ? target : undefined;
443
+ if (activity === undefined) {
444
+ if (ref !== undefined && ref !== "") {
445
+ // Z86
446
+ ctx.report("compensation-activity-exists", entry.node.id, `The referenced compensation activity '${ref}' doesn't exist`, "Point activityRef at an existing activity.");
447
+ }
448
+ continue;
449
+ }
450
+ const id = activity.node.id;
451
+ const hasHandler = ctx
452
+ .boundaries(id)
453
+ .some(({ node }) => eventDefinitions(node).some((d) => d.type === "compensate"));
454
+ // A sub-process triggered by an event is not an embedded sub-process.
455
+ const embedded = SUB_PROCESS_TYPES.includes(activity.node.type) &&
456
+ activity.node.triggeredByEvent !== true;
457
+ if (!hasHandler && !embedded) {
458
+ // Z87
459
+ ctx.report("compensation-activity-handler", entry.node.id, `The referenced compensation activity '${id}' must have either a compensation boundary event or be a subprocess`, "Attach a compensation boundary event to the activity, or reference an embedded sub-process.");
460
+ }
461
+ const scope = entry.scope;
462
+ const sameScope = activity.scope === scope ||
463
+ (scope.kind === "eventSubProcess" && activity.scope === scope.parent);
464
+ if (!sameScope) {
465
+ // Z88
466
+ ctx.report("compensation-activity-scope", entry.node.id, `The referenced compensation activity '${id}' must be in the same scope as the compensation throw event`, "Reference an activity from the same scope as the compensation throw event.");
467
+ }
468
+ }
469
+ for (const { node } of ctx.nodes) {
470
+ if (!TASK_TYPES.includes(node.type) || node.isForCompensation !== true)
471
+ continue;
472
+ if (ctx.incoming(node.id).length > 0) {
473
+ ctx.report("compensation-handler-flows", node.id, "A compensation handler should have no incoming sequence flows", "Remove the incoming sequence flows of the compensation handler.");
474
+ }
475
+ if (ctx.outgoing(node.id).length > 0) {
476
+ ctx.report("compensation-handler-flows", node.id, "A compensation handler should have no outgoing sequence flows", "Remove the outgoing sequence flows of the compensation handler.");
477
+ }
478
+ if (ctx.boundaries(node.id).length > 0) {
479
+ ctx.report("compensation-handler-flows", node.id, "A compensation handler should have no boundary events", "Remove the boundary events of the compensation handler.");
480
+ }
481
+ }
482
+ };
483
+ export const checks = [
484
+ MESSAGE_REFERENCE_RULES,
485
+ MESSAGE_ROOT_RULES,
486
+ MESSAGE_START_RULES,
487
+ MESSAGE_THROW_RULES,
488
+ RECEIVE_TASK_RULES,
489
+ SIGNAL_RULES,
490
+ ERROR_RULES,
491
+ ESCALATION_RULES,
492
+ LINK_RULES,
493
+ COMPENSATION_RULES,
494
+ ];
495
+ //# sourceMappingURL=references.js.map
@@ -0,0 +1,3 @@
1
+ import type { ZeebeCheck } from "../context.js";
2
+ export declare const checks: ZeebeCheck[];
3
+ //# sourceMappingURL=structure.d.ts.map