@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,492 @@
1
+ import { DeployabilityError } from "../../errors.js";
2
+ import { ZEEBE_LATEST_VERSION } from "../../generated/zeebe-rules.js";
3
+ import { parseBpmn } from "../bpmn-parser.js";
4
+ import { serializeBpmn } from "../bpmn-serializer.js";
5
+ import { normalizeCamundaVersion } from "../camunda-compat.js";
6
+ import { ZEEBE_NS, localRef } from "./context.js";
7
+ import { isDeployable, validateDeployableXml } from "./index.js";
8
+ /**
9
+ * Every placeholder value, by field. `<elementId>` stands for the id of the element
10
+ * that gets the value. Values are deterministic so the same input always fills the
11
+ * same way; none of them makes the model do anything useful at runtime.
12
+ */
13
+ export const PLACEHOLDERS = {
14
+ jobType: {
15
+ value: "placeholder-<elementId>",
16
+ where: "zeebe:taskDefinition type of a service task, send task, script task without a script, business rule task without a decision, or message throw/end event without zeebe:publishMessage",
17
+ },
18
+ messageName: {
19
+ value: "placeholder-<elementId>",
20
+ where: "name of a message without one; a missing messageRef gets a new message with this id and name",
21
+ },
22
+ correlationKey: {
23
+ value: '="placeholder-<elementId>"',
24
+ where: "correlationKey of zeebe:subscription (added when missing) or zeebe:publishMessage",
25
+ },
26
+ signalName: {
27
+ value: "placeholder-<elementId>",
28
+ where: "name of a signal without one; a missing signalRef gets a new signal with this id and name",
29
+ },
30
+ errorCode: {
31
+ value: "placeholder-<elementId>",
32
+ where: "errorCode of the error an error end event throws; a missing errorRef gets a new error with this id and code",
33
+ },
34
+ escalationCode: {
35
+ value: "placeholder-<elementId>",
36
+ where: "escalationCode of a thrown escalation; a missing escalationRef gets a new escalation with this id and code",
37
+ },
38
+ timer: {
39
+ value: "PT1H",
40
+ where: "timeDuration of a timer event definition with no duration, date or cycle",
41
+ },
42
+ calledElement: {
43
+ value: "placeholder-<elementId>",
44
+ where: "processId of a call activity's zeebe:calledElement (added when missing)",
45
+ },
46
+ decisionId: {
47
+ value: "placeholder-<elementId>",
48
+ where: "decisionId of a business rule task's zeebe:calledDecision",
49
+ },
50
+ condition: {
51
+ value: "=false",
52
+ where: "condition of a non-default outgoing flow of an exclusive or inclusive gateway, so the flow is never taken",
53
+ },
54
+ };
55
+ /**
56
+ * `modeler:executionPlatform` names Camunda 8 ("Camunda Cloud", any case), as
57
+ * `targetCamundaVersion` reads it: the models `Bpmn.export` and `build()` gate.
58
+ */
59
+ export function targetsCamunda8(definitions) {
60
+ const platform = definitions.unknownAttributes["modeler:executionPlatform"];
61
+ return platform?.toLowerCase().includes("cloud") === true;
62
+ }
63
+ /** Filling one kind of value can reveal the next (a new message then needs a subscription). */
64
+ const MAX_FILL_ROUNDS = 4;
65
+ function check(definitions, options) {
66
+ // The serialized XML, not the model: what is deployed is the XML, so serializer bugs count too.
67
+ return validateDeployableXml(serializeBpmn(definitions), options);
68
+ }
69
+ /** The message of a {@link DeployabilityError}; the Rust twin builds the same bytes. */
70
+ export function deployabilityMessage(camundaVersion, errors) {
71
+ const lines = errors.map((f) => `- ${f.elementIds[0] ?? ""}: ${f.message} (${f.id})`);
72
+ return [`Not deployable on Camunda ${camundaVersion}: ${errors.length} error(s)`, ...lines].join("\n");
73
+ }
74
+ /**
75
+ * Refuses a model Zeebe would reject on deploy, with every reason in one error.
76
+ *
77
+ * The check is {@link validateDeployableXml} on the serialized model, so anything
78
+ * the serializer gets wrong is refused too. With `placeholders: true`, missing
79
+ * required values (job types, message names, correlation keys, ...) are filled
80
+ * with the values in {@link PLACEHOLDERS} on a copy, which is validated again.
81
+ *
82
+ * @param definitions - The model to check; never mutated.
83
+ * @param options - As for {@link validateDeployable}, plus `placeholders`.
84
+ * @returns The model to deploy (the input, or the filled copy), the fills and the warnings.
85
+ * @throws {DeployabilityError} When an error finding remains.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const { definitions, placeholders } = assertDeployable(defs, { placeholders: true })
90
+ * for (const p of placeholders) console.log(`${p.elementId}.${p.field} = ${p.value}`)
91
+ * ```
92
+ */
93
+ export function assertDeployable(definitions, options = {}) {
94
+ const { placeholders: fill = false, ...validateOptions } = options;
95
+ const version = normalizeCamundaVersion(options.camundaVersion) ?? ZEEBE_LATEST_VERSION;
96
+ let result = definitions;
97
+ let findings = check(definitions, validateOptions);
98
+ const fills = [];
99
+ if (fill && !isDeployable(findings)) {
100
+ const copy = structuredClone(definitions);
101
+ // Callers such as the lint plugin pass partial models; filling adds root elements.
102
+ copy.messages ??= [];
103
+ copy.signals ??= [];
104
+ copy.errors ??= [];
105
+ copy.escalations ??= [];
106
+ for (let round = 0; round < MAX_FILL_ROUNDS && !isDeployable(findings); round++) {
107
+ const added = fillPlaceholders(copy, findings);
108
+ if (added.length === 0)
109
+ break;
110
+ fills.push(...added);
111
+ findings = check(copy, validateOptions);
112
+ }
113
+ if (fills.length > 0)
114
+ result = copy;
115
+ }
116
+ const errors = findings.filter((f) => f.severity === "error");
117
+ if (errors.length > 0) {
118
+ throw new DeployabilityError(deployabilityMessage(version, errors), errors, version);
119
+ }
120
+ return { definitions: result, placeholders: fills, warnings: findings };
121
+ }
122
+ /**
123
+ * Refuses BPMN XML Zeebe would reject on deploy: the bytes as they are, for a caller
124
+ * that deploys, writes or returns XML it did not serialize itself (a file, a model's
125
+ * answer). No placeholders: to fill them, parse the XML and call {@link assertDeployable}.
126
+ *
127
+ * @param xml - The document to check.
128
+ * @param options - As for {@link validateDeployableXml}; `camundaVersion` defaults to the
129
+ * document's `modeler:executionPlatformVersion`, else the newest supported version.
130
+ * @returns The findings below severity `error`.
131
+ * @throws {DeployabilityError} When an error finding remains, with the same message
132
+ * {@link assertDeployable} gives.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * assertDeployableXml(readFileSync("order.bpmn", "utf8")) // throws before a deploy would fail
137
+ * ```
138
+ */
139
+ export function assertDeployableXml(xml, options = {}) {
140
+ let declared;
141
+ if (options.camundaVersion === undefined) {
142
+ try {
143
+ declared = parseBpmn(xml).unknownAttributes["modeler:executionPlatformVersion"];
144
+ }
145
+ catch {
146
+ // The validator reports the parse error.
147
+ }
148
+ }
149
+ const camundaVersion = options.camundaVersion ?? declared;
150
+ const findings = validateDeployableXml(xml, { ...options, camundaVersion });
151
+ const version = normalizeCamundaVersion(camundaVersion) ?? ZEEBE_LATEST_VERSION;
152
+ const errors = findings.filter((f) => f.severity === "error");
153
+ if (errors.length > 0) {
154
+ throw new DeployabilityError(deployabilityMessage(version, errors), errors, version);
155
+ }
156
+ return findings;
157
+ }
158
+ const placeholder = (id) => `placeholder-${id}`;
159
+ const blank = (v) => v === undefined || v.trim() === "";
160
+ /** Flow nodes and sequence flows by id, first occurrence winning, as the validator indexes them. */
161
+ function index(defs) {
162
+ const nodes = new Map();
163
+ const flows = new Map();
164
+ /** Start events directly in a process: their messages need no subscription. */
165
+ const processStarts = new Set();
166
+ const walk = (elements, seq, top) => {
167
+ for (const el of elements) {
168
+ if (!nodes.has(el.id))
169
+ nodes.set(el.id, el);
170
+ if (top && el.type === "startEvent")
171
+ processStarts.add(el);
172
+ if ("flowElements" in el && Array.isArray(el.flowElements)) {
173
+ walk(el.flowElements, el.sequenceFlows, false);
174
+ }
175
+ }
176
+ for (const f of seq)
177
+ if (!flows.has(f.id))
178
+ flows.set(f.id, f);
179
+ };
180
+ for (const p of defs.processes)
181
+ walk(p.flowElements, p.sequenceFlows, true);
182
+ return { nodes, flows, processStarts };
183
+ }
184
+ class Filler {
185
+ fills = [];
186
+ defs;
187
+ nodes;
188
+ flows;
189
+ processStarts;
190
+ /** The prefix new zeebe:* elements get: the model's own one for the Zeebe namespace. */
191
+ prefix;
192
+ /** The rule of the finding being filled. */
193
+ rule = "";
194
+ constructor(defs) {
195
+ const { nodes, flows, processStarts } = index(defs);
196
+ this.defs = defs;
197
+ this.nodes = nodes;
198
+ this.flows = flows;
199
+ this.processStarts = processStarts;
200
+ this.prefix =
201
+ Object.entries(defs.namespaces).find(([, uri]) => uri === ZEEBE_NS)?.[0] ?? "zeebe";
202
+ }
203
+ record(elementId, field, value) {
204
+ this.fills.push({ elementId, field, value, rule: this.rule });
205
+ }
206
+ isZeebe(name, local) {
207
+ const colon = name.indexOf(":");
208
+ if (colon < 0 || name.slice(colon + 1) !== local)
209
+ return false;
210
+ const prefix = name.slice(0, colon);
211
+ return ((this.defs.namespaces[prefix] ?? (prefix === "zeebe" ? ZEEBE_NS : undefined)) === ZEEBE_NS);
212
+ }
213
+ zeebe(elements, local) {
214
+ return (elements ?? []).filter((x) => this.isZeebe(x.name, local));
215
+ }
216
+ element(local, attributes) {
217
+ return { name: `${this.prefix}:${local}`, attributes, children: [] };
218
+ }
219
+ /** A job type on a node that has no implementation at all. */
220
+ addJobType(node, others) {
221
+ if (others.length > 0 || this.zeebe(node.extensionElements, "taskDefinition").length > 0)
222
+ return;
223
+ const value = placeholder(node.id);
224
+ node.extensionElements.push(this.element("taskDefinition", { type: value }));
225
+ this.record(node.id, "jobType", value);
226
+ }
227
+ setJobType(node) {
228
+ for (const td of this.zeebe(node.extensionElements, "taskDefinition")) {
229
+ if (!blank(td.attributes.type))
230
+ continue;
231
+ const value = placeholder(node.id);
232
+ td.attributes.type = value;
233
+ this.record(node.id, "jobType", value);
234
+ }
235
+ }
236
+ defsOf(node, type) {
237
+ return (node.eventDefinitions ?? []).filter((d) => d.type === type);
238
+ }
239
+ /**
240
+ * The message a node references, created when the reference does not resolve. A message
241
+ * a node catches gets its subscription here, keyed on the node, so the key does not
242
+ * repeat the generated message id.
243
+ */
244
+ message(node, ref, catches) {
245
+ if (ref !== undefined && this.defs.messages.some((m) => m.id === localRef(ref)))
246
+ return undefined;
247
+ const id = placeholder(node.id);
248
+ if (!this.defs.messages.some((m) => m.id === id)) {
249
+ const message = { id, name: id, unknownAttributes: {} };
250
+ this.defs.messages.push(message);
251
+ this.record(node.id, "messageName", id);
252
+ if (catches && !this.processStarts.has(node)) {
253
+ const key = `="${id}"`;
254
+ message.extensionElements = [this.element("subscription", { correlationKey: key })];
255
+ this.record(node.id, "correlationKey", key);
256
+ }
257
+ }
258
+ return id;
259
+ }
260
+ fill(f) {
261
+ this.rule = f.id;
262
+ const id = f.elementIds[0] ?? "";
263
+ const node = this.nodes.get(id);
264
+ switch (f.id.slice("zeebe/".length)) {
265
+ case "service-task-definition":
266
+ if (node?.type === "serviceTask")
267
+ this.addJobType(node, []);
268
+ break;
269
+ case "script-task-implementation":
270
+ if (node?.type === "scriptTask")
271
+ this.addJobType(node, this.zeebe(node.extensionElements, "script"));
272
+ break;
273
+ case "send-task-implementation":
274
+ if (node?.type === "sendTask")
275
+ this.addJobType(node, this.zeebe(node.extensionElements, "publishMessage"));
276
+ break;
277
+ case "business-rule-task-implementation":
278
+ if (node?.type === "businessRuleTask")
279
+ this.addJobType(node, this.zeebe(node.extensionElements, "calledDecision"));
280
+ break;
281
+ case "message-throw-implementation":
282
+ if (node !== undefined) {
283
+ const publish = this.defsOf(node, "message").flatMap((d) => this.zeebe(d.extensionElements, "publishMessage"));
284
+ this.addJobType(node, publish);
285
+ }
286
+ break;
287
+ case "task-definition-type":
288
+ if (node !== undefined)
289
+ this.setJobType(node);
290
+ break;
291
+ case "message-reference":
292
+ case "message-throw-reference":
293
+ if (node !== undefined) {
294
+ const catches = f.id === "zeebe/message-reference";
295
+ for (const def of this.defsOf(node, "message")) {
296
+ const ref = this.message(node, def.messageRef, catches);
297
+ if (ref !== undefined)
298
+ def.messageRef = ref;
299
+ }
300
+ }
301
+ break;
302
+ case "receive-task-message":
303
+ case "send-task-message":
304
+ if (node !== undefined) {
305
+ const ref = this.message(node, node.messageRef, node.type === "receiveTask");
306
+ if (ref !== undefined)
307
+ node.messageRef = ref;
308
+ }
309
+ break;
310
+ case "message-name": {
311
+ const message = this.defs.messages.find((m) => m.id === id);
312
+ if (message !== undefined && blank(message.name)) {
313
+ message.name = placeholder(id);
314
+ this.record(id, "messageName", message.name);
315
+ }
316
+ break;
317
+ }
318
+ case "message-subscription": {
319
+ const message = this.defs.messages.find((m) => m.id === id);
320
+ if (message === undefined ||
321
+ this.zeebe(message.extensionElements, "subscription").length > 0)
322
+ break;
323
+ const value = `="${placeholder(id)}"`;
324
+ message.extensionElements ??= [];
325
+ message.extensionElements.push(this.element("subscription", { correlationKey: value }));
326
+ this.record(id, "correlationKey", value);
327
+ break;
328
+ }
329
+ case "subscription-correlation-key": {
330
+ const message = this.defs.messages.find((m) => m.id === id);
331
+ this.setCorrelationKey(id, this.zeebe(message?.extensionElements, "subscription"));
332
+ break;
333
+ }
334
+ case "publish-message-correlation-key":
335
+ if (node !== undefined) {
336
+ const holders = [
337
+ node.extensionElements,
338
+ ...this.defsOf(node, "message").map((d) => d.extensionElements),
339
+ ];
340
+ this.setCorrelationKey(id, holders.flatMap((h) => this.zeebe(h, "publishMessage")));
341
+ }
342
+ break;
343
+ case "signal-reference":
344
+ if (node !== undefined) {
345
+ for (const def of this.defsOf(node, "signal")) {
346
+ const ref = def.signalRef;
347
+ if (ref !== undefined && this.defs.signals.some((s) => s.id === localRef(ref)))
348
+ continue;
349
+ const sid = placeholder(node.id);
350
+ if (!this.defs.signals.some((s) => s.id === sid)) {
351
+ this.defs.signals.push({ id: sid, name: sid, unknownAttributes: {} });
352
+ this.record(node.id, "signalName", sid);
353
+ }
354
+ def.signalRef = sid;
355
+ }
356
+ }
357
+ break;
358
+ case "signal-name": {
359
+ const signal = this.defs.signals.find((s) => s.id === id);
360
+ if (signal !== undefined && blank(signal.name)) {
361
+ signal.name = placeholder(id);
362
+ this.record(id, "signalName", signal.name);
363
+ }
364
+ break;
365
+ }
366
+ case "error-end-reference":
367
+ case "error-code":
368
+ if (node !== undefined) {
369
+ for (const def of this.defsOf(node, "error")) {
370
+ const ref = def.errorRef;
371
+ const error = ref === undefined ? undefined : this.defs.errors.find((e) => e.id === localRef(ref));
372
+ const code = placeholder(node.id);
373
+ if (error === undefined) {
374
+ if (!this.defs.errors.some((e) => e.id === code)) {
375
+ this.defs.errors.push({
376
+ id: code,
377
+ name: code,
378
+ errorCode: code,
379
+ unknownAttributes: {},
380
+ });
381
+ this.record(node.id, "errorCode", code);
382
+ }
383
+ def.errorRef = code;
384
+ }
385
+ else if (blank(error.errorCode)) {
386
+ error.errorCode = code;
387
+ this.record(node.id, "errorCode", code);
388
+ }
389
+ }
390
+ }
391
+ break;
392
+ case "escalation-throw-reference":
393
+ if (node !== undefined) {
394
+ for (const def of this.defsOf(node, "escalation")) {
395
+ const ref = def.escalationRef;
396
+ if (ref !== undefined && this.defs.escalations.some((e) => e.id === localRef(ref)))
397
+ continue;
398
+ const code = placeholder(node.id);
399
+ if (!this.defs.escalations.some((e) => e.id === code)) {
400
+ this.defs.escalations.push({
401
+ id: code,
402
+ name: code,
403
+ escalationCode: code,
404
+ unknownAttributes: {},
405
+ });
406
+ this.record(node.id, "escalationCode", code);
407
+ }
408
+ def.escalationRef = code;
409
+ }
410
+ }
411
+ break;
412
+ case "escalation-code": {
413
+ const escalation = this.defs.escalations.find((e) => e.id === id);
414
+ if (escalation !== undefined && blank(escalation.escalationCode)) {
415
+ escalation.escalationCode = placeholder(id);
416
+ this.record(id, "escalationCode", escalation.escalationCode);
417
+ }
418
+ break;
419
+ }
420
+ case "timer-one-value":
421
+ case "intermediate-timer-value":
422
+ if (node !== undefined) {
423
+ for (const def of this.defsOf(node, "timer")) {
424
+ if ([def.timeDuration, def.timeDate, def.timeCycle].some((v) => v !== undefined))
425
+ continue;
426
+ def.timeDuration = PLACEHOLDERS.timer.value;
427
+ this.record(node.id, "timer", def.timeDuration);
428
+ }
429
+ }
430
+ break;
431
+ case "call-activity-called-element":
432
+ if (node?.type === "callActivity" &&
433
+ this.zeebe(node.extensionElements, "calledElement").length === 0) {
434
+ const value = placeholder(node.id);
435
+ node.extensionElements.push(this.element("calledElement", { processId: value }));
436
+ this.record(node.id, "calledElement", value);
437
+ }
438
+ break;
439
+ case "called-element-process-id":
440
+ if (node !== undefined) {
441
+ for (const el of this.zeebe(node.extensionElements, "calledElement")) {
442
+ if (!blank(el.attributes.processId))
443
+ continue;
444
+ el.attributes.processId = placeholder(node.id);
445
+ this.record(node.id, "calledElement", el.attributes.processId);
446
+ }
447
+ }
448
+ break;
449
+ case "called-decision-attributes":
450
+ if (node !== undefined) {
451
+ for (const el of this.zeebe(node.extensionElements, "calledDecision")) {
452
+ if (!blank(el.attributes.decisionId))
453
+ continue;
454
+ el.attributes.decisionId = placeholder(node.id);
455
+ this.record(node.id, "decisionId", el.attributes.decisionId);
456
+ }
457
+ }
458
+ break;
459
+ case "exclusive-flow-condition":
460
+ case "inclusive-flow-condition": {
461
+ const flow = this.flows.get(id);
462
+ if (flow !== undefined && flow.conditionExpression === undefined) {
463
+ flow.conditionExpression = {
464
+ text: PLACEHOLDERS.condition.value,
465
+ attributes: { "xsi:type": "bpmn:tFormalExpression" },
466
+ };
467
+ this.record(id, "condition", PLACEHOLDERS.condition.value);
468
+ }
469
+ break;
470
+ }
471
+ }
472
+ }
473
+ setCorrelationKey(elementId, holders) {
474
+ for (const el of holders) {
475
+ if (!blank(el.attributes.correlationKey))
476
+ continue;
477
+ const value = `="${placeholder(elementId)}"`;
478
+ el.attributes.correlationKey = value;
479
+ this.record(elementId, "correlationKey", value);
480
+ }
481
+ }
482
+ }
483
+ /** Fills what the error findings ask for, in the findings' order; mutates `defs`. */
484
+ function fillPlaceholders(defs, findings) {
485
+ const filler = new Filler(defs);
486
+ for (const f of findings) {
487
+ if (f.severity === "error")
488
+ filler.fill(f);
489
+ }
490
+ return filler.fills;
491
+ }
492
+ //# sourceMappingURL=gate.js.map
@@ -0,0 +1,37 @@
1
+ import type { BpmnDefinitions } from "../bpmn-model.js";
2
+ import type { OptimizationFinding } from "../optimize/types.js";
3
+ import { type ValidateDeployableOptions } from "./context.js";
4
+ export type { ValidateDeployableOptions, ZeebeLimits, ZeebeResolver } from "./context.js";
5
+ /**
6
+ * Checks a model against the rules Zeebe applies when it is deployed
7
+ * (`spec/zeebe-rules.json`), so a model that passes deploys on Camunda 8.
8
+ *
9
+ * Recursive (sub-processes, event sub-processes, ad-hoc sub-processes) and
10
+ * version-aware, and independent of `modeler:executionPlatform`: a caller that
11
+ * targets Camunda 8 asks for it. Findings are `zeebe/<rule>` in the `deploy`
12
+ * category, sorted by rule then document order.
13
+ *
14
+ * @param definitions - The parsed model.
15
+ * @param options - `camundaVersion` (default: the newest supported), a
16
+ * `resolver` for the other resources of the deployment, and length `limits`.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const findings = validateDeployable(Bpmn.parse(xml), { camundaVersion: "8.8" })
21
+ * if (!isDeployable(findings)) throw new Error(findings[0].message)
22
+ * ```
23
+ */
24
+ export declare function validateDeployable(definitions: BpmnDefinitions, options?: ValidateDeployableOptions): OptimizationFinding[];
25
+ /** Whether Zeebe would accept the model: no finding of severity `error`. */
26
+ export declare function isDeployable(findings: readonly OptimizationFinding[]): boolean;
27
+ /**
28
+ * {@link validateDeployable} on BPMN XML, plus the checks Zeebe runs on the text
29
+ * before it builds a model (well-formedness, namespaces, XSD-required attributes,
30
+ * id syntax and uniqueness). This is the full gate for generated XML: BPMN Kit's
31
+ * own parser is tolerant and repairs some of what Zeebe rejects.
32
+ *
33
+ * @param xml - The BPMN XML as it would be deployed.
34
+ * @param options - As for {@link validateDeployable}.
35
+ */
36
+ export declare function validateDeployableXml(xml: string, options?: ValidateDeployableOptions): OptimizationFinding[];
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,106 @@
1
+ import { parseBpmn } from "../bpmn-parser.js";
2
+ import { ZeebeContext } from "./context.js";
3
+ import { checks as events } from "./rules/events.js";
4
+ import { checks as extensions } from "./rules/extensions.js";
5
+ import { checks as gateways } from "./rules/gateways.js";
6
+ import { checks as references } from "./rules/references.js";
7
+ import { checks as structure } from "./rules/structure.js";
8
+ import { checks as tasks } from "./rules/tasks.js";
9
+ import { checkXml } from "./xml.js";
10
+ /**
11
+ * Sections of zeebe-rules.md: structure A-C, events D, references E, tasks F-I,
12
+ * gateways/multi-instance/sub-processes J-L, expressions/extensions/deployment M-O.
13
+ */
14
+ const CHECKS = [
15
+ ...structure,
16
+ ...events,
17
+ ...references,
18
+ ...tasks,
19
+ ...gateways,
20
+ ...extensions,
21
+ ];
22
+ /**
23
+ * Checks a model against the rules Zeebe applies when it is deployed
24
+ * (`spec/zeebe-rules.json`), so a model that passes deploys on Camunda 8.
25
+ *
26
+ * Recursive (sub-processes, event sub-processes, ad-hoc sub-processes) and
27
+ * version-aware, and independent of `modeler:executionPlatform`: a caller that
28
+ * targets Camunda 8 asks for it. Findings are `zeebe/<rule>` in the `deploy`
29
+ * category, sorted by rule then document order.
30
+ *
31
+ * @param definitions - The parsed model.
32
+ * @param options - `camundaVersion` (default: the newest supported), a
33
+ * `resolver` for the other resources of the deployment, and length `limits`.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const findings = validateDeployable(Bpmn.parse(xml), { camundaVersion: "8.8" })
38
+ * if (!isDeployable(findings)) throw new Error(findings[0].message)
39
+ * ```
40
+ */
41
+ export function validateDeployable(definitions, options = {}) {
42
+ const ctx = new ZeebeContext(withRootLists(definitions), options);
43
+ for (const check of CHECKS)
44
+ check(ctx);
45
+ return ctx.finish();
46
+ }
47
+ /** Lint callers may hand over a partial model; missing root-element lists count as empty. */
48
+ function withRootLists(defs) {
49
+ return {
50
+ ...defs,
51
+ processes: defs.processes ?? [],
52
+ messages: defs.messages ?? [],
53
+ errors: defs.errors ?? [],
54
+ signals: defs.signals ?? [],
55
+ escalations: defs.escalations ?? [],
56
+ collaborations: defs.collaborations ?? [],
57
+ diagrams: defs.diagrams ?? [],
58
+ };
59
+ }
60
+ /** Whether Zeebe would accept the model: no finding of severity `error`. */
61
+ export function isDeployable(findings) {
62
+ return !findings.some((f) => f.severity === "error");
63
+ }
64
+ const EMPTY = {
65
+ id: "",
66
+ targetNamespace: "",
67
+ namespaces: {},
68
+ unknownAttributes: {},
69
+ errors: [],
70
+ escalations: [],
71
+ messages: [],
72
+ signals: [],
73
+ collaborations: [],
74
+ processes: [],
75
+ diagrams: [],
76
+ };
77
+ /**
78
+ * {@link validateDeployable} on BPMN XML, plus the checks Zeebe runs on the text
79
+ * before it builds a model (well-formedness, namespaces, XSD-required attributes,
80
+ * id syntax and uniqueness). This is the full gate for generated XML: BPMN Kit's
81
+ * own parser is tolerant and repairs some of what Zeebe rejects.
82
+ *
83
+ * @param xml - The BPMN XML as it would be deployed.
84
+ * @param options - As for {@link validateDeployable}.
85
+ */
86
+ export function validateDeployableXml(xml, options = {}) {
87
+ let definitions;
88
+ let parseError;
89
+ try {
90
+ definitions = parseBpmn(xml);
91
+ }
92
+ catch (err) {
93
+ parseError = err.message;
94
+ }
95
+ const ctx = new ZeebeContext(definitions ?? EMPTY, options);
96
+ const { fatal } = checkXml(xml, ctx);
97
+ if (parseError !== undefined && !fatal) {
98
+ ctx.report("xml-schema", "", `Unable to parse BPMN XML: ${parseError}`, "Fix the XML so it is well-formed BPMN 2.0.");
99
+ }
100
+ if (definitions !== undefined && !fatal && parseError === undefined) {
101
+ for (const check of CHECKS)
102
+ check(ctx);
103
+ }
104
+ return ctx.finish();
105
+ }
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import { type ZeebeCheck } from "../context.js";
2
+ /** Checks for zeebe-rules.md section D, in spec order (see index.ts). */
3
+ export declare const checks: ZeebeCheck[];
4
+ //# sourceMappingURL=events.d.ts.map