@bpmnkit/core 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +25 -3
  2. package/dist/bpmn/agentic.js +3 -1
  3. package/dist/bpmn/auto-layout.js +184 -15
  4. package/dist/bpmn/bpmn-builder.js +69 -7
  5. package/dist/bpmn/bpmn-model.d.ts +78 -0
  6. package/dist/bpmn/bpmn-parser.js +195 -37
  7. package/dist/bpmn/bpmn-serializer.js +121 -72
  8. package/dist/bpmn/bpmnlint.d.ts +153 -0
  9. package/dist/bpmn/bpmnlint.js +364 -0
  10. package/dist/bpmn/camunda-compat-data.d.ts +165 -0
  11. package/dist/bpmn/camunda-compat-data.js +423 -0
  12. package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
  13. package/dist/bpmn/camunda-compat-feel.js +338 -0
  14. package/dist/bpmn/camunda-compat.d.ts +120 -0
  15. package/dist/bpmn/camunda-compat.js +1677 -0
  16. package/dist/bpmn/camunda7/juel.d.ts +41 -0
  17. package/dist/bpmn/camunda7/juel.js +333 -0
  18. package/dist/bpmn/camunda7/migrate.d.ts +72 -0
  19. package/dist/bpmn/camunda7/migrate.js +1152 -0
  20. package/dist/bpmn/full-operations.js +5 -2
  21. package/dist/bpmn/label-style.d.ts +51 -0
  22. package/dist/bpmn/label-style.js +116 -0
  23. package/dist/bpmn/lint.d.ts +23 -3
  24. package/dist/bpmn/lint.js +47 -10
  25. package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
  26. package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
  27. package/dist/bpmn/optimize/deploy.d.ts +8 -2
  28. package/dist/bpmn/optimize/deploy.js +16 -3
  29. package/dist/bpmn/optimize/index.js +11 -2
  30. package/dist/bpmn/optimize/types.d.ts +14 -0
  31. package/dist/bpmn/optimize/variable-flow.js +4 -1
  32. package/dist/bpmn/process-types.d.ts +112 -0
  33. package/dist/bpmn/process-types.js +490 -0
  34. package/dist/bpmn/svg.js +51 -22
  35. package/dist/doc/docx.d.ts +20 -0
  36. package/dist/doc/docx.js +253 -0
  37. package/dist/doc/html.d.ts +21 -0
  38. package/dist/doc/html.js +303 -0
  39. package/dist/doc/index.d.ts +7 -0
  40. package/dist/doc/index.js +5 -0
  41. package/dist/doc/markdown.d.ts +11 -0
  42. package/dist/doc/markdown.js +160 -0
  43. package/dist/doc/model.d.ts +129 -0
  44. package/dist/doc/model.js +617 -0
  45. package/dist/doc/zip.d.ts +5 -0
  46. package/dist/doc/zip.js +75 -0
  47. package/dist/index.d.ts +16 -0
  48. package/dist/index.js +8 -0
  49. package/dist/layout/annotations.d.ts +4 -2
  50. package/dist/layout/annotations.js +31 -2
  51. package/dist/layout/collaboration/ordering.d.ts +8 -0
  52. package/dist/layout/collaboration/ordering.js +57 -18
  53. package/dist/layout/orthogonal.d.ts +32 -0
  54. package/dist/layout/orthogonal.js +367 -0
  55. package/dist/layout/repair.d.ts +31 -0
  56. package/dist/layout/repair.js +220 -0
  57. package/dist/layout/semantic/route.js +45 -3
  58. package/dist/node/bpmnlint.d.ts +109 -0
  59. package/dist/node/bpmnlint.js +198 -0
  60. package/dist/node/index.d.ts +2 -0
  61. package/dist/node/index.js +1 -0
  62. package/dist/xml/xml-patch.d.ts +21 -0
  63. package/dist/xml/xml-patch.js +27 -1
  64. package/package.json +2 -2
@@ -0,0 +1,1152 @@
1
+ import { parseExpression } from "@bpmnkit/feel";
2
+ import { ValidationError } from "../../errors.js";
3
+ import { detectExecutionPlatform } from "../lint.js";
4
+ import { bpmnElementName, isZeebePlacementAllowed } from "../zeebe-extensions.js";
5
+ import { containsJuel, feelString, isFeelName, translateJuelToFeel } from "./juel.js";
6
+ const CAMUNDA7_NS = "http://camunda.org/schema/1.0/bpmn";
7
+ const ZEEBE_NS = "http://camunda.org/schema/zeebe/1.0";
8
+ const MODELER_NS = "http://camunda.org/schema/modeler/1.0";
9
+ const DEFAULT_PLATFORM_VERSION = "8.8.0";
10
+ /** The event definitions and loop of a flow element, which carry attributes of their own. */
11
+ function nestedHolders(owner) {
12
+ const holders = [];
13
+ if ("eventDefinitions" in owner && Array.isArray(owner.eventDefinitions)) {
14
+ holders.push(...owner.eventDefinitions);
15
+ }
16
+ if ("loopCharacteristics" in owner && owner.loopCharacteristics !== undefined) {
17
+ holders.push(owner.loopCharacteristics);
18
+ }
19
+ return holders;
20
+ }
21
+ function localName(name) {
22
+ const colon = name.indexOf(":");
23
+ return colon === -1 ? name : name.slice(colon + 1);
24
+ }
25
+ /**
26
+ * Converts a Camunda 7 model to Camunda 8, as far as that can be done
27
+ * mechanically, and reports what it could not do. The input is not modified.
28
+ *
29
+ * What cannot be converted stays in the output verbatim — Camunda 8 ignores
30
+ * `camunda:` content — and has a `manual` or `unsupported` finding saying why.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const { definitions, report } = convertCamunda7(Bpmn.parse(xml))
35
+ * for (const f of report.findings) console.log(f.severity, f.elementId, f.message)
36
+ * const c8Xml = Bpmn.export(definitions)
37
+ * ```
38
+ */
39
+ export function convertCamunda7(definitions, options = {}) {
40
+ // A Camunda 8 model's job-worker user tasks would silently become Camunda user tasks.
41
+ if (detectExecutionPlatform(definitions).id === "camunda-cloud") {
42
+ throw new ValidationError("The model already targets Camunda 8 (modeler:executionPlatform names Camunda Cloud); there is nothing to migrate.");
43
+ }
44
+ const draft = structuredClone(definitions);
45
+ const converter = new Converter(draft, options);
46
+ converter.run();
47
+ return { definitions: draft, report: converter.report() };
48
+ }
49
+ /**
50
+ * Reports what migrating a Camunda 7 model to Camunda 8 takes, element by
51
+ * element, without changing it. Same findings as {@link convertCamunda7}.
52
+ */
53
+ export function analyzeCamunda7(definitions, options = {}) {
54
+ return convertCamunda7(definitions, options).report;
55
+ }
56
+ /** `com.acme.ShipOrderDelegate` → `shipOrderDelegate`, the Spring bean name the class gets by default. */
57
+ function beanName(className) {
58
+ const simple = className.slice(className.lastIndexOf(".") + 1).replace(/\$/g, "");
59
+ return simple.charAt(0).toLowerCase() + simple.slice(1);
60
+ }
61
+ const ISO_DATE_TIME_WITH_ZONE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
62
+ class Converter {
63
+ definitions;
64
+ options;
65
+ findings = [];
66
+ prefix;
67
+ processId = "";
68
+ /** Per owner: the attribute keys and extension elements a rule has accounted for. */
69
+ handledAttributes = new Set();
70
+ handledElements = new Set();
71
+ constructor(definitions, options) {
72
+ this.definitions = definitions;
73
+ this.options = options;
74
+ this.prefix = Object.entries(definitions.namespaces).find(([, uri]) => uri === CAMUNDA7_NS)?.[0];
75
+ }
76
+ run() {
77
+ const d = this.definitions;
78
+ for (const error of d.errors) {
79
+ this.withOwner({
80
+ id: error.id,
81
+ type: "error",
82
+ extensionElements: error.extensionElements ?? [],
83
+ unknownAttributes: error.unknownAttributes ?? {},
84
+ }, (owner) => {
85
+ if (this.attr(owner, "errorMessage") !== undefined) {
86
+ this.add(owner, "camunda:errorMessage", "unsupported", "Camunda 8 errors carry only an error code.", "Have the worker pass the message along when it throws the error.", false);
87
+ this.keepAttr(owner, "errorMessage");
88
+ }
89
+ });
90
+ }
91
+ for (const message of d.messages) {
92
+ if (message.name !== undefined && containsJuel(message.name)) {
93
+ this.findings.push({
94
+ elementId: message.id,
95
+ elementType: "message",
96
+ processId: "",
97
+ construct: "bpmn:message name expression",
98
+ severity: "manual",
99
+ message: `Message name "${message.name}" is a JUEL expression.`,
100
+ suggestion: "Rewrite it as a FEEL expression (=…), or use a static name.",
101
+ applied: false,
102
+ });
103
+ }
104
+ }
105
+ for (const process of d.processes)
106
+ this.convertProcess(process);
107
+ this.setExecutionPlatform();
108
+ }
109
+ report() {
110
+ const counts = { convertible: 0, manual: 0, unsupported: 0 };
111
+ for (const finding of this.findings)
112
+ counts[finding.severity] += 1;
113
+ return { findings: this.findings, counts, total: this.findings.length };
114
+ }
115
+ // -----------------------------------------------------------------------
116
+ // Plumbing
117
+ // -----------------------------------------------------------------------
118
+ key(local) {
119
+ return `${this.prefix ?? "camunda"}:${local}`;
120
+ }
121
+ attr(holder, local) {
122
+ return this.prefix === undefined ? undefined : holder.unknownAttributes?.[this.key(local)];
123
+ }
124
+ /** Marks an attribute as accounted for and removes it — its Camunda 8 form was written. */
125
+ dropAttr(holder, local) {
126
+ this.handledAttributes.add(this.key(local));
127
+ if (holder.unknownAttributes !== undefined)
128
+ delete holder.unknownAttributes[this.key(local)];
129
+ }
130
+ /** Marks an attribute as accounted for and leaves it in place. */
131
+ keepAttr(_holder, local) {
132
+ this.handledAttributes.add(this.key(local));
133
+ }
134
+ exts(owner, local) {
135
+ if (this.prefix === undefined)
136
+ return [];
137
+ return owner.extensionElements.filter((element) => element.name === this.key(local));
138
+ }
139
+ dropExt(owner, element) {
140
+ this.handledElements.add(element);
141
+ const index = owner.extensionElements.indexOf(element);
142
+ if (index !== -1)
143
+ owner.extensionElements.splice(index, 1);
144
+ }
145
+ keepExt(element) {
146
+ this.handledElements.add(element);
147
+ }
148
+ add(owner, construct, severity, message, suggestion, applied) {
149
+ this.findings.push({
150
+ elementId: owner.id,
151
+ elementType: owner.type,
152
+ processId: this.processId,
153
+ construct,
154
+ severity,
155
+ message,
156
+ suggestion,
157
+ applied,
158
+ });
159
+ }
160
+ /** Finds or creates a `zeebe:` extension, or returns undefined where the schema forbids it. */
161
+ zeebe(owner, local) {
162
+ const name = `zeebe:${local}`;
163
+ if (!isZeebePlacementAllowed(bpmnElementName(owner), name))
164
+ return undefined;
165
+ const existing = owner.extensionElements.find((element) => element.name === name);
166
+ if (existing !== undefined)
167
+ return existing;
168
+ const created = { name, attributes: {}, children: [] };
169
+ owner.extensionElements.push(created);
170
+ return created;
171
+ }
172
+ hasZeebe(owner, local) {
173
+ return owner.extensionElements.some((element) => element.name === `zeebe:${local}`);
174
+ }
175
+ /**
176
+ * Runs the rules for one owner, then reports every Camunda 7 attribute or
177
+ * extension element no rule accounted for, so nothing passes unmentioned.
178
+ */
179
+ withOwner(owner, rules) {
180
+ this.handledAttributes = new Set();
181
+ this.handledElements = new Set();
182
+ const attributes = [owner, ...nestedHolders(owner)].flatMap((holder) => Object.entries(holder.unknownAttributes ?? {}).filter(([key]) => this.prefix !== undefined && key.startsWith(`${this.prefix}:`)));
183
+ const elements = owner.extensionElements.filter((element) => this.prefix !== undefined && element.name.startsWith(`${this.prefix}:`));
184
+ rules(owner);
185
+ for (const [key, value] of attributes) {
186
+ if (this.handledAttributes.has(key))
187
+ continue;
188
+ this.add(owner, `camunda:${localName(key)}`, "manual", `Camunda 7 attribute ${key}="${value}" has no automatic conversion.`, "Review it against the Camunda 8 documentation; it is kept in the file, where Camunda 8 ignores it.", false);
189
+ }
190
+ for (const element of elements) {
191
+ if (this.handledElements.has(element))
192
+ continue;
193
+ this.add(owner, `camunda:${localName(element.name)}`, "manual", `Camunda 7 extension <${element.name}> has no automatic conversion.`, "Review it against the Camunda 8 documentation; it is kept in the file, where Camunda 8 ignores it.", false);
194
+ }
195
+ }
196
+ /**
197
+ * A value that may be static or JUEL, as a Camunda 8 attribute value:
198
+ * static text stays static, a provable `${…}` becomes `=feel`.
199
+ */
200
+ staticOrExpression(value, multiInstance = false) {
201
+ if (!containsJuel(value))
202
+ return { ok: true, value };
203
+ const result = translateJuelToFeel(value, { multiInstance });
204
+ return result.ok ? { ok: true, value: `=${result.feel}` } : { ok: false, reason: result.reason };
205
+ }
206
+ /** A value that is always an expression in Camunda 8 (IO mapping source): literals become FEEL literals. */
207
+ feelValue(text) {
208
+ const trimmed = (text ?? "").trim();
209
+ if (trimmed === "")
210
+ return { ok: true, value: "null" };
211
+ if (!containsJuel(trimmed))
212
+ return { ok: true, value: feelString(trimmed) };
213
+ const result = translateJuelToFeel(trimmed);
214
+ return result.ok ? { ok: true, value: result.feel } : { ok: false, reason: result.reason };
215
+ }
216
+ // -----------------------------------------------------------------------
217
+ // Process and containers
218
+ // -----------------------------------------------------------------------
219
+ convertProcess(process) {
220
+ this.processId = process.id;
221
+ // The spread shares the process's arrays and records, so rules write through to it.
222
+ this.withOwner({ ...process, type: "process" }, (owner) => {
223
+ const versionTag = this.attr(owner, "versionTag");
224
+ if (versionTag !== undefined) {
225
+ const tag = this.zeebe(owner, "versionTag");
226
+ if (tag !== undefined) {
227
+ tag.attributes.value = versionTag;
228
+ this.dropAttr(owner, "versionTag");
229
+ this.add(owner, "camunda:versionTag", "convertible", `Version tag "${versionTag}" moved to zeebe:versionTag.`, "zeebe:versionTag", true);
230
+ }
231
+ }
232
+ const ttl = this.attr(owner, "historyTimeToLive");
233
+ if (ttl !== undefined) {
234
+ this.keepAttr(owner, "historyTimeToLive");
235
+ this.add(owner, "camunda:historyTimeToLive", "unsupported", `Camunda 8 has no per-process history time to live (was "${ttl}").`, "Configure data retention for the cluster (Operate, Tasklist and Optimize archiving).", false);
236
+ }
237
+ for (const local of ["candidateStarterGroups", "candidateStarterUsers"]) {
238
+ if (this.attr(owner, local) === undefined)
239
+ continue;
240
+ this.keepAttr(owner, local);
241
+ this.add(owner, `camunda:${local}`, "unsupported", "Camunda 8 does not restrict who may start a process in the model.", "Grant CREATE_PROCESS_INSTANCE on the process definition through authorizations.", false);
242
+ }
243
+ if (this.attr(owner, "isStartableInTasklist") !== undefined) {
244
+ this.keepAttr(owner, "isStartableInTasklist");
245
+ this.add(owner, "camunda:isStartableInTasklist", "unsupported", "Camunda 8 decides Tasklist start visibility outside the model.", "Use a start form and authorizations to control starting from Tasklist.", false);
246
+ }
247
+ for (const local of ["jobPriority", "taskPriority"]) {
248
+ if (this.attr(owner, local) === undefined)
249
+ continue;
250
+ this.keepAttr(owner, local);
251
+ this.add(owner, `camunda:${local}`, "manual", "Camunda 7 job/external-task priorities order its own job executor and fetch-and-lock; Camunda 8 prioritises worker jobs differently.", "If priority matters, set zeebe:jobPriorityDefinition (job prioritization) and check its semantics.", false);
252
+ }
253
+ this.convertCommon(owner);
254
+ });
255
+ this.convertContainer(process.flowElements, process.sequenceFlows);
256
+ }
257
+ convertContainer(elements, flows) {
258
+ for (const element of elements) {
259
+ this.withOwner(element, () => this.convertElement(element));
260
+ if (element.type === "subProcess" ||
261
+ element.type === "adHocSubProcess" ||
262
+ element.type === "eventSubProcess" ||
263
+ element.type === "transaction") {
264
+ this.convertContainer(element.flowElements, element.sequenceFlows);
265
+ }
266
+ }
267
+ for (const flow of flows) {
268
+ this.withOwner({ ...flow, type: "sequenceFlow" }, (owner) => this.convertFlow(flow, owner));
269
+ }
270
+ }
271
+ convertElement(element) {
272
+ this.convertAsync(element);
273
+ switch (element.type) {
274
+ case "serviceTask":
275
+ case "sendTask":
276
+ this.convertImplementation(element);
277
+ break;
278
+ case "businessRuleTask":
279
+ if (this.attr(element, "decisionRef") !== undefined)
280
+ this.convertDecision(element);
281
+ else
282
+ this.convertImplementation(element);
283
+ break;
284
+ case "userTask":
285
+ this.convertUserTask(element);
286
+ break;
287
+ case "callActivity":
288
+ this.convertCallActivity(element);
289
+ break;
290
+ case "scriptTask":
291
+ this.convertScriptTask(element);
292
+ break;
293
+ case "receiveTask":
294
+ this.checkCorrelation(element, element.messageRef);
295
+ break;
296
+ case "startEvent":
297
+ this.convertStartEvent(element);
298
+ this.convertEventDefinitions(element, element.eventDefinitions);
299
+ break;
300
+ case "intermediateCatchEvent":
301
+ case "boundaryEvent":
302
+ this.convertEventDefinitions(element, element.eventDefinitions);
303
+ for (const definition of element.eventDefinitions) {
304
+ if (definition.type === "message")
305
+ this.checkCorrelation(element, definition.messageRef);
306
+ }
307
+ break;
308
+ case "intermediateThrowEvent":
309
+ case "endEvent":
310
+ this.convertEventDefinitions(element, element.eventDefinitions);
311
+ if (element.eventDefinitions.some((definition) => definition.type === "message")) {
312
+ this.convertMessageThrow(element);
313
+ }
314
+ break;
315
+ default:
316
+ break;
317
+ }
318
+ if ("loopCharacteristics" in element && element.loopCharacteristics !== undefined) {
319
+ this.convertLoop(element, element.loopCharacteristics);
320
+ }
321
+ this.convertStandardLoop(element);
322
+ this.convertCommon(element);
323
+ this.convertRetryCycle(element);
324
+ }
325
+ // -----------------------------------------------------------------------
326
+ // Rules shared by every element
327
+ // -----------------------------------------------------------------------
328
+ convertAsync(owner) {
329
+ const present = ["asyncBefore", "asyncAfter", "async", "exclusive", "jobPriority"].filter((local) => this.attr(owner, local) !== undefined);
330
+ if (present.length === 0)
331
+ return;
332
+ for (const local of present)
333
+ this.dropAttr(owner, local);
334
+ this.add(owner, present.map((local) => `camunda:${local}`).join(", "), "convertible", "Dropped: Camunda 8 has no asynchronous continuations. The engine commits after every step and every job-based task is already a wait state, so there is no transaction boundary to place and no job executor job to prioritise.", "Nothing to model. A failure no longer rolls back to the last async boundary: a job failure retries the job, and an expression failure raises an incident on the element.", true);
335
+ }
336
+ convertCommon(owner) {
337
+ for (const io of this.exts(owner, "inputOutput"))
338
+ this.convertInputOutput(owner, io);
339
+ for (const properties of this.exts(owner, "properties")) {
340
+ const target = this.zeebe(owner, "properties");
341
+ if (target === undefined)
342
+ continue;
343
+ for (const property of properties.children) {
344
+ target.children.push({
345
+ name: "zeebe:property",
346
+ attributes: {
347
+ name: property.attributes.name ?? "",
348
+ value: property.attributes.value ?? "",
349
+ },
350
+ children: [],
351
+ });
352
+ }
353
+ this.dropExt(owner, properties);
354
+ this.add(owner, "camunda:properties", "convertible", "Extension properties moved to zeebe:properties.", "zeebe:properties", true);
355
+ }
356
+ for (const listener of this.exts(owner, "executionListener")) {
357
+ this.keepExt(listener);
358
+ const event = listener.attributes.event ?? "start";
359
+ if (event === "take") {
360
+ this.add(owner, "camunda:executionListener", "unsupported", "Camunda 8 has no listener on taking a sequence flow.", "Move the logic into a task or an end listener on the source element.", false);
361
+ continue;
362
+ }
363
+ this.add(owner, "camunda:executionListener", "manual", `Execution listener on "${event}" (${describeImplementation(listener, this.prefix)}) runs Java or script code in the engine.`, `Implement it as a job worker and declare it with zeebe:executionListeners (eventType="${event}", type="<job type>").`, false);
364
+ }
365
+ for (const local of ["formData", "formProperty"]) {
366
+ for (const form of this.exts(owner, local)) {
367
+ this.keepExt(form);
368
+ this.add(owner, `camunda:${local}`, "manual", "Generated task forms have no Camunda 8 equivalent.", "Rebuild the form as a Camunda Form and link it with zeebe:formDefinition formId.", false);
369
+ }
370
+ }
371
+ for (const errorDefinition of this.exts(owner, "errorEventDefinition")) {
372
+ this.keepExt(errorDefinition);
373
+ this.add(owner, "camunda:errorEventDefinition", "manual", "External-task error event definitions evaluate an expression on the worker's result in the engine.", "Throw the BPMN error from the job worker (throw-error command) instead.", false);
374
+ }
375
+ }
376
+ convertInputOutput(owner, io) {
377
+ const mapping = this.zeebe(owner, "ioMapping");
378
+ if (mapping === undefined) {
379
+ this.keepExt(io);
380
+ this.add(owner, "camunda:inputOutput", "manual", `Camunda 8 does not allow input/output mappings on ${owner.type}.`, "Move the mappings to a neighbouring activity.", false);
381
+ return;
382
+ }
383
+ const kept = [];
384
+ let converted = 0;
385
+ for (const parameter of io.children) {
386
+ const direction = localName(parameter.name) === "inputParameter" ? "input" : "output";
387
+ const target = parameter.attributes.name ?? "";
388
+ const value = this.parameterValue(parameter);
389
+ if (!value.ok || !isFeelPath(target)) {
390
+ kept.push(parameter);
391
+ const reason = value.ok ? `"${target}" is not a valid Camunda 8 target name` : value.reason;
392
+ this.add(owner, `camunda:${direction}Parameter`, "manual", `${direction === "input" ? "Input" : "Output"} parameter "${target}" was not converted: ${reason}.`, `Write it as <zeebe:${direction} source="=…" target="${target}"/> by hand.`, false);
393
+ continue;
394
+ }
395
+ mapping.children.push({
396
+ name: `zeebe:${direction}`,
397
+ attributes: { source: `=${value.value}`, target },
398
+ children: [],
399
+ });
400
+ converted++;
401
+ }
402
+ if (mapping.children.length === 0)
403
+ owner.extensionElements.splice(owner.extensionElements.indexOf(mapping), 1);
404
+ if (kept.length === 0)
405
+ this.dropExt(owner, io);
406
+ else {
407
+ io.children = kept;
408
+ this.keepExt(io);
409
+ }
410
+ if (converted > 0) {
411
+ this.add(owner, "camunda:inputOutput", "convertible", `${converted} input/output parameter${converted === 1 ? "" : "s"} moved to zeebe:ioMapping, JUEL translated to FEEL.`, "zeebe:ioMapping", true);
412
+ }
413
+ }
414
+ parameterValue(parameter) {
415
+ const [child] = parameter.children;
416
+ if (child === undefined)
417
+ return this.feelValue(parameter.text);
418
+ return this.structuredValue(child);
419
+ }
420
+ structuredValue(element) {
421
+ const local = localName(element.name);
422
+ if (local === "list") {
423
+ const items = [];
424
+ for (const item of element.children) {
425
+ const value = item.children[0] === undefined
426
+ ? this.feelValue(item.text)
427
+ : this.structuredValue(item.children[0]);
428
+ if (!value.ok)
429
+ return value;
430
+ items.push(value.value);
431
+ }
432
+ return { ok: true, value: `[${items.join(", ")}]` };
433
+ }
434
+ if (local === "map") {
435
+ const entries = [];
436
+ for (const entry of element.children) {
437
+ const value = entry.children[0] === undefined
438
+ ? this.feelValue(entry.text)
439
+ : this.structuredValue(entry.children[0]);
440
+ if (!value.ok)
441
+ return value;
442
+ entries.push(`${feelString(entry.attributes.key ?? "")}: ${value.value}`);
443
+ }
444
+ return { ok: true, value: `{${entries.join(", ")}}` };
445
+ }
446
+ if (local === "script") {
447
+ const format = (element.attributes.scriptFormat ?? "").toLowerCase();
448
+ if (format === "feel" && element.attributes.resource === undefined) {
449
+ return this.checkedFeel(element.text ?? "");
450
+ }
451
+ return { ok: false, reason: `it is a ${element.attributes.scriptFormat ?? "script"} script` };
452
+ }
453
+ return { ok: false, reason: `<${element.name}> is not a value Camunda 8 can express` };
454
+ }
455
+ checkedFeel(text) {
456
+ const trimmed = text.trim();
457
+ if (trimmed === "")
458
+ return { ok: false, reason: "the FEEL script is empty" };
459
+ return parseExpression(trimmed).errors.length === 0
460
+ ? { ok: true, value: trimmed }
461
+ : { ok: false, reason: "the FEEL script does not parse" };
462
+ }
463
+ convertRetryCycle(owner) {
464
+ for (const cycle of this.exts(owner, "failedJobRetryTimeCycle")) {
465
+ const text = (cycle.text ?? "").trim();
466
+ const definition = owner.extensionElements.find((element) => element.name === "zeebe:taskDefinition");
467
+ if (definition === undefined) {
468
+ this.keepExt(cycle);
469
+ this.add(owner, "camunda:failedJobRetryTimeCycle", "unsupported", `Retry cycle "${text}" retried an asynchronous continuation; in Camunda 8 only jobs have retries.`, "A failure on this element raises an incident; resolve it in Operate.", false);
470
+ continue;
471
+ }
472
+ const repeat = /^R(\d+)\/(P\S+)$/.exec(text);
473
+ const list = text.split(",").map((part) => part.trim());
474
+ const retries = repeat?.[1] ?? (list.every((part) => /^P\S+$/.test(part)) ? String(list.length) : undefined);
475
+ if (retries === undefined) {
476
+ this.keepExt(cycle);
477
+ this.add(owner, "camunda:failedJobRetryTimeCycle", "manual", `Retry cycle "${text}" is not an R<n>/<duration> or a duration list.`, 'Set zeebe:taskDefinition retries="<n>" and the back-off in the worker.', false);
478
+ continue;
479
+ }
480
+ if (definition.attributes.retries === undefined)
481
+ definition.attributes.retries = retries;
482
+ this.dropExt(owner, cycle);
483
+ this.add(owner, "camunda:failedJobRetryTimeCycle", "convertible", `Retry count ${retries} moved to zeebe:taskDefinition retries.`, "zeebe:taskDefinition retries", true);
484
+ const intervals = repeat === null ? list : [repeat[2] ?? ""];
485
+ // A zero interval retries at once, which is what Camunda 8 does without a back-off.
486
+ if (intervals.every((interval) => /^P(T?0+[SMHD]|0+[DWMY])$/.test(interval)))
487
+ continue;
488
+ this.add(owner, "camunda:failedJobRetryTimeCycle", "manual", `The retry interval (${repeat?.[2] ?? list.join(", ")}) is not part of the Camunda 8 model.`, "Pass it as the retry back-off when the worker fails the job (fail-job retryBackOff).", false);
489
+ }
490
+ }
491
+ convertStandardLoop(owner) {
492
+ for (const child of owner.unknownChildren ?? []) {
493
+ if (localName(child.name) !== "standardLoopCharacteristics")
494
+ continue;
495
+ this.add(owner, "bpmn:standardLoopCharacteristics", "unsupported", "Camunda 8 does not support standard (while) loops.", "Model the loop with a gateway and a sequence flow back, or as a multi-instance activity.", false);
496
+ }
497
+ }
498
+ // -----------------------------------------------------------------------
499
+ // Implementations: service, send, business rule, message throw
500
+ // -----------------------------------------------------------------------
501
+ /** `source` holds the implementation attributes: the element, or a message throw's event definition. */
502
+ convertImplementation(owner, source = owner) {
503
+ const read = (local) => this.attr(source, local);
504
+ const drop = (local) => this.dropAttr(source, local);
505
+ const type = read("type");
506
+ const topic = read("topic");
507
+ const className = read("class");
508
+ const delegateExpression = read("delegateExpression");
509
+ const expression = read("expression");
510
+ if (type === "external" && topic !== undefined) {
511
+ const jobType = this.staticOrExpression(topic);
512
+ if (!jobType.ok) {
513
+ this.keepAttr(owner, "type");
514
+ this.keepAttr(owner, "topic");
515
+ this.add(owner, "camunda:topic", "manual", `Topic expression "${topic}" could not be translated: ${jobType.reason}.`, "Set zeebe:taskDefinition type by hand.", false);
516
+ return;
517
+ }
518
+ const definition = this.zeebe(owner, "taskDefinition");
519
+ if (definition === undefined)
520
+ return;
521
+ definition.attributes.type = jobType.value;
522
+ drop("type");
523
+ drop("topic");
524
+ this.add(owner, "camunda:type=external", "convertible", `External task topic "${topic}" became job type "${jobType.value}".`, "zeebe:taskDefinition type — point the external task worker at the Camunda 8 job API with the same type.", true);
525
+ const priority = read("taskPriority");
526
+ if (priority !== undefined) {
527
+ this.keepAttr(owner, "taskPriority");
528
+ this.add(owner, "camunda:taskPriority", "manual", `External task priority "${priority}" was not converted.`, "If priority matters, set zeebe:jobPriorityDefinition and check its range and semantics.", false);
529
+ }
530
+ for (const error of this.exts(owner, "errorEventDefinition"))
531
+ this.keepExt(error);
532
+ return;
533
+ }
534
+ const delegate = className !== undefined
535
+ ? { attribute: "class", value: className, jobType: beanName(className) }
536
+ : delegateExpression !== undefined
537
+ ? {
538
+ attribute: "delegateExpression",
539
+ value: delegateExpression,
540
+ jobType: /^[$#]\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}$/.exec(delegateExpression.trim())?.[1] ??
541
+ owner.id,
542
+ }
543
+ : expression !== undefined
544
+ ? { attribute: "expression", value: expression, jobType: owner.id }
545
+ : undefined;
546
+ if (delegate !== undefined) {
547
+ const definition = this.zeebe(owner, "taskDefinition");
548
+ if (definition === undefined)
549
+ return;
550
+ definition.attributes.type = delegate.jobType;
551
+ const headers = [
552
+ {
553
+ name: "zeebe:header",
554
+ attributes: { key: delegate.attribute, value: delegate.value },
555
+ children: [],
556
+ },
557
+ ];
558
+ const resultVariable = read("resultVariable");
559
+ if (delegate.attribute === "expression" && resultVariable !== undefined) {
560
+ headers.push({
561
+ name: "zeebe:header",
562
+ attributes: { key: "resultVariable", value: resultVariable },
563
+ children: [],
564
+ });
565
+ drop("resultVariable");
566
+ }
567
+ headers.push(...this.convertFields(owner));
568
+ const taskHeaders = this.zeebe(owner, "taskHeaders");
569
+ taskHeaders?.children.push(...headers);
570
+ drop(delegate.attribute);
571
+ this.add(owner, `camunda:${delegate.attribute}`, "manual", `${DELEGATE_LABEL[delegate.attribute] ?? delegate.attribute} "${delegate.value}" runs inside the Camunda 7 engine; Camunda 8 runs no user code in the engine.`, `Implement a job worker for type "${delegate.jobType}" (written as zeebe:taskDefinition type; the original is kept as the "${delegate.attribute}" task header, which the Camunda 7 adapter pattern can dispatch on).`, true);
572
+ return;
573
+ }
574
+ for (const connector of this.exts(owner, "connector")) {
575
+ this.keepExt(connector);
576
+ const id = connector.children.find((child) => localName(child.name) === "connectorId")?.text ??
577
+ "connector";
578
+ this.add(owner, "camunda:connector", "manual", `Camunda 7 connector "${id}" has no Camunda 8 equivalent with the same inputs.`, id.startsWith("http")
579
+ ? "Use the Camunda 8 REST connector (io.camunda:http-json:1) and map its inputs."
580
+ : "Use a Camunda 8 connector or a job worker.", false);
581
+ }
582
+ }
583
+ /** Field injections with a static string become task headers; expression fields are left for a person. */
584
+ convertFields(owner) {
585
+ const headers = [];
586
+ for (const field of this.exts(owner, "field")) {
587
+ const name = field.attributes.name ?? "";
588
+ const stringChild = field.children.find((child) => localName(child.name) === "string");
589
+ const value = field.attributes.stringValue ?? stringChild?.text;
590
+ if (value !== undefined && field.attributes.expression === undefined) {
591
+ headers.push({ name: "zeebe:header", attributes: { key: name, value }, children: [] });
592
+ this.dropExt(owner, field);
593
+ this.add(owner, "camunda:field", "convertible", `Field injection "${name}" became a task header.`, "zeebe:taskHeaders — read it from the job's custom headers.", true);
594
+ continue;
595
+ }
596
+ this.keepExt(field);
597
+ this.add(owner, "camunda:field", "manual", `Field injection "${name}" is an expression evaluated by the engine.`, "Map the value with an input mapping and read it as a job variable.", false);
598
+ }
599
+ return headers;
600
+ }
601
+ convertMessageThrow(owner) {
602
+ // Camunda 7 puts the implementation on the message event definition; Modeler never
603
+ // writes it on the event itself, but a hand-written file might.
604
+ const implemented = (holder) => ["class", "delegateExpression", "expression", "type"].some((local) => this.attr(holder, local) !== undefined);
605
+ const definitions = "eventDefinitions" in owner ? owner.eventDefinitions : [];
606
+ const source = [
607
+ ...definitions.filter((definition) => definition.type === "message"),
608
+ owner,
609
+ ].find(implemented);
610
+ if (source !== undefined)
611
+ this.convertImplementation(owner, source);
612
+ }
613
+ convertDecision(owner) {
614
+ const decisionRef = this.attr(owner, "decisionRef") ?? "";
615
+ const decisionId = this.staticOrExpression(decisionRef);
616
+ if (!decisionId.ok) {
617
+ this.keepAttr(owner, "decisionRef");
618
+ this.add(owner, "camunda:decisionRef", "manual", `Decision reference "${decisionRef}" could not be translated: ${decisionId.reason}.`, "Set zeebe:calledDecision decisionId by hand.", false);
619
+ return;
620
+ }
621
+ const called = this.zeebe(owner, "calledDecision");
622
+ if (called === undefined)
623
+ return;
624
+ called.attributes.decisionId = decisionId.value;
625
+ this.dropAttr(owner, "decisionRef");
626
+ const resultVariable = this.attr(owner, "resultVariable");
627
+ if (resultVariable !== undefined) {
628
+ called.attributes.resultVariable = resultVariable;
629
+ this.dropAttr(owner, "resultVariable");
630
+ this.add(owner, "camunda:decisionRef", "convertible", `Decision "${decisionRef}" → zeebe:calledDecision, result in "${resultVariable}".`, "zeebe:calledDecision", true);
631
+ }
632
+ else {
633
+ called.attributes.resultVariable = "decisionResult";
634
+ this.add(owner, "camunda:decisionRef", "manual", `Decision "${decisionRef}" → zeebe:calledDecision. Camunda 7 had no result variable; Camunda 8 requires one, so "decisionResult" was set.`, "Rename resultVariable to what downstream elements expect.", true);
635
+ }
636
+ this.convertBinding(owner, called, "decisionRef");
637
+ const mapper = this.attr(owner, "mapDecisionResult");
638
+ if (mapper === "singleEntry") {
639
+ this.dropAttr(owner, "mapDecisionResult");
640
+ this.add(owner, "camunda:mapDecisionResult", "convertible", 'Result mapper "singleEntry" matches Camunda 8, which stores a single output value as-is.', "Nothing to model.", true);
641
+ }
642
+ else {
643
+ if (mapper !== undefined)
644
+ this.keepAttr(owner, "mapDecisionResult");
645
+ this.add(owner, "camunda:mapDecisionResult", "manual", `Camunda 7 result mapper "${mapper ?? "resultList"}"${mapper === undefined ? " (the default)" : ""} shapes the result differently from Camunda 8, which stores the decision's own result: a value for one output, a context for several, a list for collect hit policies.`, "Check what downstream elements read, and add an output mapping if they expect the Camunda 7 shape.", false);
646
+ }
647
+ if (this.attr(owner, "decisionRefTenantId") !== undefined) {
648
+ this.keepAttr(owner, "decisionRefTenantId");
649
+ this.add(owner, "camunda:decisionRefTenantId", "unsupported", "Camunda 8 resolves the decision in the process's own tenant.", "Deploy the decision to the same tenant as the process.", false);
650
+ }
651
+ }
652
+ /** `camunda:<ref>Binding` / `<ref>Version` / `<ref>VersionTag` → `bindingType` / `versionTag`. */
653
+ convertBinding(owner, target, ref) {
654
+ const binding = this.attr(owner, `${ref}Binding`);
655
+ if (binding === undefined)
656
+ return;
657
+ if (binding === "latest" || binding === "deployment") {
658
+ target.attributes.bindingType = binding;
659
+ this.dropAttr(owner, `${ref}Binding`);
660
+ return;
661
+ }
662
+ if (binding === "versionTag") {
663
+ const tag = this.attr(owner, `${ref}VersionTag`);
664
+ if (tag !== undefined && !containsJuel(tag)) {
665
+ target.attributes.bindingType = "versionTag";
666
+ target.attributes.versionTag = tag;
667
+ this.dropAttr(owner, `${ref}Binding`);
668
+ this.dropAttr(owner, `${ref}VersionTag`);
669
+ return;
670
+ }
671
+ }
672
+ this.keepAttr(owner, `${ref}Binding`);
673
+ this.keepAttr(owner, `${ref}Version`);
674
+ this.keepAttr(owner, `${ref}VersionTag`);
675
+ this.add(owner, `camunda:${ref}Binding`, "manual", `Binding "${binding}" pins a version number; Camunda 8 binds by latest, deployment or version tag.`, 'Tag the target with a version tag and use bindingType="versionTag", or use "deployment".', false);
676
+ }
677
+ // -----------------------------------------------------------------------
678
+ // User tasks and forms
679
+ // -----------------------------------------------------------------------
680
+ convertUserTask(owner) {
681
+ if (!this.hasZeebe(owner, "userTask")) {
682
+ this.zeebe(owner, "userTask");
683
+ this.add(owner, "bpmn:userTask", "convertible", "Implemented as a Camunda user task (zeebe:userTask).", "zeebe:userTask", true);
684
+ }
685
+ const assignment = {};
686
+ for (const local of ["assignee", "candidateUsers", "candidateGroups"]) {
687
+ const value = this.attr(owner, local);
688
+ if (value === undefined)
689
+ continue;
690
+ const converted = this.staticOrExpression(value);
691
+ if (!converted.ok) {
692
+ this.keepAttr(owner, local);
693
+ this.add(owner, `camunda:${local}`, "manual", `${local} "${value}" could not be translated: ${converted.reason}.`, `Set zeebe:assignmentDefinition ${local} by hand.`, false);
694
+ continue;
695
+ }
696
+ assignment[local] = converted.value;
697
+ this.dropAttr(owner, local);
698
+ const listExpression = local !== "assignee" && converted.value.startsWith("=");
699
+ this.add(owner, `camunda:${local}`, listExpression ? "manual" : "convertible", listExpression
700
+ ? `${local} expression became "${converted.value}". Camunda 7 accepted a comma-separated string or a collection here; Camunda 8 requires a list of strings.`
701
+ : `${local} became zeebe:assignmentDefinition ${local}="${converted.value}".`, listExpression
702
+ ? "Make sure the expression evaluates to a list of strings."
703
+ : "zeebe:assignmentDefinition", true);
704
+ }
705
+ if (Object.keys(assignment).length > 0) {
706
+ const definition = this.zeebe(owner, "assignmentDefinition");
707
+ if (definition !== undefined)
708
+ Object.assign(definition.attributes, assignment);
709
+ }
710
+ const schedule = {};
711
+ for (const local of ["dueDate", "followUpDate"]) {
712
+ const value = this.attr(owner, local);
713
+ if (value === undefined)
714
+ continue;
715
+ const converted = this.staticOrExpression(value);
716
+ const valid = converted.ok &&
717
+ (converted.value.startsWith("=") || ISO_DATE_TIME_WITH_ZONE.test(converted.value));
718
+ if (!converted.ok || !valid) {
719
+ this.keepAttr(owner, local);
720
+ this.add(owner, `camunda:${local}`, "manual", `${local} "${value}" is ${converted.ok ? "not an ISO 8601 date-time with a zone offset, which Camunda 8 requires" : `not translatable: ${converted.reason}`}.`, `Set zeebe:taskSchedule ${local} by hand.`, false);
721
+ continue;
722
+ }
723
+ schedule[local] = converted.value;
724
+ this.dropAttr(owner, local);
725
+ this.add(owner, `camunda:${local}`, "convertible", `${local} became zeebe:taskSchedule ${local}="${converted.value}".`, "zeebe:taskSchedule — the value must be an ISO 8601 date-time.", true);
726
+ }
727
+ if (Object.keys(schedule).length > 0) {
728
+ const definition = this.zeebe(owner, "taskSchedule");
729
+ if (definition !== undefined)
730
+ Object.assign(definition.attributes, schedule);
731
+ }
732
+ const priority = this.attr(owner, "priority");
733
+ if (priority !== undefined) {
734
+ const converted = this.staticOrExpression(priority);
735
+ const number = Number(priority);
736
+ const inRange = /^\d+$/.test(priority) && number >= 0 && number <= 100;
737
+ if (converted.ok && (inRange || converted.value.startsWith("="))) {
738
+ const definition = this.zeebe(owner, "priorityDefinition");
739
+ if (definition !== undefined)
740
+ definition.attributes.priority = converted.value;
741
+ this.dropAttr(owner, "priority");
742
+ this.add(owner, "camunda:priority", inRange ? "convertible" : "manual", inRange
743
+ ? `Priority ${priority} became zeebe:priorityDefinition.`
744
+ : `Priority expression became "${converted.value}".`, inRange
745
+ ? "zeebe:priorityDefinition"
746
+ : "Camunda 8 priorities range from 0 to 100; make sure the expression stays in range.", true);
747
+ }
748
+ else {
749
+ this.keepAttr(owner, "priority");
750
+ this.add(owner, "camunda:priority", "manual", `Priority "${priority}" is outside Camunda 8's 0–100 range or not translatable.`, "Rescale it to 0–100 and set zeebe:priorityDefinition.", false);
751
+ }
752
+ }
753
+ this.convertForm(owner);
754
+ for (const listener of this.exts(owner, "taskListener")) {
755
+ this.keepExt(listener);
756
+ const event = listener.attributes.event ?? "create";
757
+ const c8Event = TASK_LISTENER_EVENTS[event];
758
+ if (c8Event === undefined) {
759
+ this.add(owner, "camunda:taskListener", "unsupported", `Camunda 8 has no task listener event like "${event}".`, event === "timeout"
760
+ ? "Model the timeout with a timer boundary event."
761
+ : "Move the logic elsewhere.", false);
762
+ continue;
763
+ }
764
+ this.add(owner, "camunda:taskListener", "manual", `Task listener on "${event}" (${describeImplementation(listener, this.prefix)}) runs code in the engine.`, `Implement it as a job worker and declare it with zeebe:taskListeners (eventType="${c8Event}").`, false);
765
+ }
766
+ }
767
+ convertStartEvent(owner) {
768
+ if (this.attr(owner, "initiator") !== undefined) {
769
+ this.keepAttr(owner, "initiator");
770
+ this.add(owner, "camunda:initiator", "unsupported", "Camunda 8 does not record the starting user in a variable.", "Pass the user as a variable when creating the instance.", false);
771
+ }
772
+ this.convertForm(owner);
773
+ }
774
+ convertForm(owner) {
775
+ const formRef = this.attr(owner, "formRef");
776
+ if (formRef !== undefined) {
777
+ const formId = this.staticOrExpression(formRef);
778
+ const definition = formId.ok && !formId.value.startsWith("=") ? this.zeebe(owner, "formDefinition") : undefined;
779
+ if (definition === undefined) {
780
+ this.keepAttr(owner, "formRef");
781
+ this.add(owner, "camunda:formRef", "manual", `Form reference "${formRef}" is an expression; a Camunda 8 form id is static.`, "Set zeebe:formDefinition formId by hand.", false);
782
+ }
783
+ else {
784
+ definition.attributes.formId = formRef;
785
+ this.dropAttr(owner, "formRef");
786
+ this.convertBinding(owner, definition, "formRef");
787
+ this.add(owner, "camunda:formRef", "convertible", `Camunda Form "${formRef}" linked with zeebe:formDefinition formId.`, "Deploy the .form file with the process; Camunda 7 and 8 share the form-js schema.", true);
788
+ }
789
+ }
790
+ const formKey = this.attr(owner, "formKey");
791
+ if (formKey === undefined)
792
+ return;
793
+ if (formKey.startsWith("camunda-forms:")) {
794
+ this.keepAttr(owner, "formKey");
795
+ this.add(owner, "camunda:formKey", "manual", `Form key "${formKey}" points at a .form file by path; Camunda 8 links forms by the id inside the file.`, "Open the .form file, and set zeebe:formDefinition formId to its id.", false);
796
+ return;
797
+ }
798
+ const definition = owner.type === "userTask" ? this.zeebe(owner, "formDefinition") : undefined;
799
+ if (definition === undefined) {
800
+ this.keepAttr(owner, "formKey");
801
+ this.add(owner, "camunda:formKey", "manual", `Form key "${formKey}" on a ${owner.type} has no Camunda 8 counterpart.`, "Link a Camunda Form with zeebe:formDefinition formId.", false);
802
+ return;
803
+ }
804
+ definition.attributes.externalReference = formKey;
805
+ this.dropAttr(owner, "formKey");
806
+ const embedded = formKey.startsWith("embedded:");
807
+ this.add(owner, "camunda:formKey", embedded ? "manual" : "convertible", `Form key "${formKey}" became a custom form reference (zeebe:formDefinition externalReference).`, embedded
808
+ ? "Tasklist does not render embedded HTML forms: rebuild it as a Camunda Form, or serve it from a custom task application that reads externalReference."
809
+ : "Your task application resolves externalReference; Tasklist does not show custom forms.", true);
810
+ }
811
+ // -----------------------------------------------------------------------
812
+ // Call activities
813
+ // -----------------------------------------------------------------------
814
+ convertCallActivity(owner) {
815
+ const calledElement = owner.unknownAttributes.calledElement;
816
+ if (calledElement !== undefined) {
817
+ const processId = this.staticOrExpression(calledElement);
818
+ const target = processId.ok ? this.zeebe(owner, "calledElement") : undefined;
819
+ if (!processId.ok || target === undefined) {
820
+ this.add(owner, "calledElement", "manual", `Called element "${calledElement}" could not be translated${processId.ok ? "" : `: ${processId.reason}`}.`, "Set zeebe:calledElement processId by hand.", false);
821
+ }
822
+ else {
823
+ target.attributes.processId = processId.value;
824
+ this.convertBinding(owner, target, "calledElement");
825
+ this.add(owner, "calledElement", "convertible", `Calls "${processId.value}" through zeebe:calledElement.`, "zeebe:calledElement", true);
826
+ this.convertVariablePassing(owner, target);
827
+ }
828
+ }
829
+ if (this.attr(owner, "calledElementTenantId") !== undefined) {
830
+ this.keepAttr(owner, "calledElementTenantId");
831
+ this.add(owner, "camunda:calledElementTenantId", "unsupported", "Camunda 8 calls the process in the caller's tenant.", "Deploy the called process to the same tenant.", false);
832
+ }
833
+ for (const local of ["variableMappingClass", "variableMappingDelegateExpression"]) {
834
+ if (this.attr(owner, local) === undefined)
835
+ continue;
836
+ this.keepAttr(owner, local);
837
+ this.add(owner, `camunda:${local}`, "manual", "Delegated variable mapping runs Java in the engine.", "Express the mapping as zeebe:ioMapping inputs and outputs.", false);
838
+ }
839
+ if (owner.unknownAttributes.caseRef !== undefined ||
840
+ this.attr(owner, "caseRef") !== undefined) {
841
+ this.keepAttr(owner, "caseRef");
842
+ this.add(owner, "caseRef", "unsupported", "Camunda 8 has no CMMN.", "Model the case as a BPMN process (ad-hoc sub-process).", false);
843
+ }
844
+ }
845
+ /**
846
+ * Camunda 7 passes nothing across a call activity unless `camunda:in` /
847
+ * `camunda:out` say so; Camunda 8 passes everything by default. Both
848
+ * directions are pinned so the converted model keeps Camunda 7's scope.
849
+ */
850
+ convertVariablePassing(owner, calledElement) {
851
+ const ins = this.exts(owner, "in");
852
+ const outs = this.exts(owner, "out");
853
+ const allIn = ins.some((element) => element.attributes.variables === "all");
854
+ const allOut = outs.some((element) => element.attributes.variables === "all");
855
+ let mapped = 0;
856
+ const mapping = (direction, element) => {
857
+ const target = element.attributes.target;
858
+ const source = element.attributes.sourceExpression !== undefined
859
+ ? this.feelValue(element.attributes.sourceExpression)
860
+ : element.attributes.source !== undefined && isFeelName(element.attributes.source)
861
+ ? { ok: true, value: element.attributes.source }
862
+ : {
863
+ ok: false,
864
+ reason: `"${element.attributes.source ?? ""}" is not a valid FEEL name`,
865
+ };
866
+ if (target === undefined ||
867
+ !isFeelPath(target) ||
868
+ !source.ok ||
869
+ element.attributes.local === "true") {
870
+ return false;
871
+ }
872
+ const io = this.zeebe(owner, "ioMapping");
873
+ io?.children.push({
874
+ name: `zeebe:${direction}`,
875
+ attributes: { source: `=${source.value}`, target },
876
+ children: [],
877
+ });
878
+ mapped++;
879
+ return true;
880
+ };
881
+ for (const element of ins) {
882
+ if (element.attributes.variables === "all" && element.attributes.local !== "true") {
883
+ this.dropExt(owner, element);
884
+ continue;
885
+ }
886
+ const businessKey = element.attributes.businessKey;
887
+ if (businessKey !== undefined) {
888
+ if (/^[$#]\{\s*execution\.processBusinessKey\s*\}$/.test(businessKey.trim())) {
889
+ this.dropExt(owner, element);
890
+ this.add(owner, "camunda:in businessKey", "convertible", "Passing the parent's business key is Camunda 8's default: a child instance inherits the parent's business ID (Camunda 8.9+).", "Nothing to model on 8.9+. On earlier versions pass the key as a variable.", true);
891
+ }
892
+ else {
893
+ this.keepExt(element);
894
+ this.add(owner, "camunda:in businessKey", "manual", `Business key expression "${businessKey}" was not converted.`, 'Set zeebe:calledElement businessId="=…" (Camunda 8.10+).', false);
895
+ }
896
+ continue;
897
+ }
898
+ if (mapping("input", element))
899
+ this.dropExt(owner, element);
900
+ else {
901
+ this.keepExt(element);
902
+ this.add(owner, "camunda:in", "manual", `Input variable mapping to "${element.attributes.target ?? ""}" was not converted.`, "Write it as a zeebe:input mapping by hand.", false);
903
+ }
904
+ }
905
+ for (const element of outs) {
906
+ if (element.attributes.variables === "all" && element.attributes.local !== "true") {
907
+ this.dropExt(owner, element);
908
+ continue;
909
+ }
910
+ if (mapping("output", element))
911
+ this.dropExt(owner, element);
912
+ else {
913
+ this.keepExt(element);
914
+ this.add(owner, "camunda:out", "manual", `Output variable mapping to "${element.attributes.target ?? ""}" was not converted.`, "Write it as a zeebe:output mapping by hand.", false);
915
+ }
916
+ }
917
+ if (!allIn)
918
+ calledElement.attributes.propagateAllParentVariables = "false";
919
+ const hasOutputs = owner.extensionElements.some((element) => element.name === "zeebe:ioMapping" &&
920
+ element.children.some((child) => child.name === "zeebe:output"));
921
+ if (!allOut && !hasOutputs)
922
+ calledElement.attributes.propagateAllChildVariables = "false";
923
+ if (ins.length + outs.length > 0 || !allIn) {
924
+ this.add(owner, "camunda:in / camunda:out", "convertible", `Variable passing kept as in Camunda 7: ${allIn ? "all parent variables" : `${mapped > 0 ? "only mapped" : "no"} parent variables`} in, ${allOut ? "all child variables" : hasOutputs ? "only mapped child variables" : "no child variables"} out.`, "zeebe:calledElement propagateAllParentVariables / propagateAllChildVariables and zeebe:ioMapping", true);
925
+ }
926
+ }
927
+ // -----------------------------------------------------------------------
928
+ // Scripts
929
+ // -----------------------------------------------------------------------
930
+ convertScriptTask(owner) {
931
+ const format = owner.unknownAttributes.scriptFormat ?? "";
932
+ const children = owner.unknownChildren ?? [];
933
+ const script = children.find((child) => localName(child.name) === "script");
934
+ const resource = this.attr(owner, "resource");
935
+ if (resource !== undefined) {
936
+ this.keepAttr(owner, "resource");
937
+ this.add(owner, "camunda:resource", "manual", `External script resource "${resource}" is not part of the model.`, "Inline it as a FEEL zeebe:script, or implement it as a job worker.", false);
938
+ return;
939
+ }
940
+ const text = (script?.text ?? "").trim();
941
+ const normalised = format.toLowerCase();
942
+ const converted = normalised === "feel"
943
+ ? this.checkedFeel(text)
944
+ : normalised === "juel"
945
+ ? (() => {
946
+ const result = translateJuelToFeel(text);
947
+ return result.ok
948
+ ? { ok: true, value: result.feel }
949
+ : { ok: false, reason: result.reason };
950
+ })()
951
+ : { ok: false, reason: `${format || "untyped"} scripts do not run in Camunda 8` };
952
+ const resultVariable = this.attr(owner, "resultVariable");
953
+ if (!converted.ok || resultVariable === undefined) {
954
+ if (resultVariable !== undefined)
955
+ this.keepAttr(owner, "resultVariable");
956
+ this.add(owner, `scriptFormat="${format}"`, "manual", converted.ok
957
+ ? "A FEEL script without camunda:resultVariable: Camunda 8 requires a result variable."
958
+ : `Script was not converted: ${converted.reason}.`, "Rewrite it as a FEEL expression in zeebe:script (expression, resultVariable), or implement it as a job worker with zeebe:taskDefinition.", false);
959
+ return;
960
+ }
961
+ const target = this.zeebe(owner, "script");
962
+ if (target === undefined)
963
+ return;
964
+ target.attributes.expression = `=${converted.value}`;
965
+ target.attributes.resultVariable = resultVariable;
966
+ this.dropAttr(owner, "resultVariable");
967
+ Reflect.deleteProperty(owner.unknownAttributes, "scriptFormat");
968
+ if (script !== undefined)
969
+ children.splice(children.indexOf(script), 1);
970
+ this.add(owner, `scriptFormat="${format}"`, "convertible", `${format.toUpperCase()} script became zeebe:script, result in "${resultVariable}".`, "zeebe:script", true);
971
+ }
972
+ // -----------------------------------------------------------------------
973
+ // Events, conditions, loops
974
+ // -----------------------------------------------------------------------
975
+ checkCorrelation(owner, messageRef) {
976
+ if (messageRef === undefined || this.hasZeebe(owner, "subscription"))
977
+ return;
978
+ const message = this.definitions.messages.find((candidate) => candidate.id === messageRef);
979
+ if (message?.extensionElements?.some((element) => element.name === "zeebe:subscription"))
980
+ return;
981
+ this.add(owner, "message correlation", "manual", `Camunda 7 correlates message "${message?.name ?? messageRef}" by API call (business key, process variables or instance id); the model names no key, and Camunda 8 requires one.`, `Add <zeebe:subscription correlationKey="=…"/> to message "${messageRef}", naming the variable publishers correlate on.`, false);
982
+ }
983
+ convertEventDefinitions(owner, definitions) {
984
+ for (const definition of definitions) {
985
+ if (definition.type === "timer") {
986
+ for (const part of ["timeDuration", "timeDate", "timeCycle"]) {
987
+ const value = definition[part];
988
+ if (value === undefined)
989
+ continue;
990
+ const trimmed = value.trim();
991
+ if (containsJuel(trimmed)) {
992
+ const converted = this.staticOrExpression(trimmed);
993
+ if (converted.ok) {
994
+ definition[part] = converted.value;
995
+ this.add(owner, `timer ${part}`, "convertible", `Timer expression "${trimmed}" became "${converted.value}".`, "FEEL timer expression", true);
996
+ }
997
+ else {
998
+ this.add(owner, `timer ${part}`, "manual", `Timer expression "${trimmed}" was not translated: ${converted.reason}.`, "Rewrite it as a FEEL expression returning an ISO 8601 duration, date-time or cycle.", false);
999
+ }
1000
+ }
1001
+ else if (part === "timeCycle" && !trimmed.startsWith("R") && /\s/.test(trimmed)) {
1002
+ this.add(owner, "timer timeCycle", "manual", `Cron cycle "${trimmed}" uses Camunda 7's Quartz-style syntax.`, "Check it against Camunda 8's cron syntax, or use an ISO 8601 repeating interval.", false);
1003
+ }
1004
+ }
1005
+ }
1006
+ if (definition.type === "conditional" && definition.condition !== undefined) {
1007
+ const converted = this.condition(definition.condition, definition.conditionAttributes ?? {});
1008
+ if (converted.ok) {
1009
+ definition.condition = converted.value;
1010
+ this.add(owner, "conditional event condition", "convertible", `Condition became "${converted.value}".`, "FEEL condition (conditional events need Camunda 8.9+)", true);
1011
+ }
1012
+ else {
1013
+ this.add(owner, "conditional event condition", "manual", `Condition "${definition.condition}" was not translated: ${converted.reason}.`, "Rewrite it as a FEEL expression.", false);
1014
+ }
1015
+ }
1016
+ }
1017
+ for (const definition of definitions) {
1018
+ for (const local of ["variableName", "variableEvents"]) {
1019
+ const value = this.attr(definition, local);
1020
+ if (value === undefined)
1021
+ continue;
1022
+ this.keepAttr(definition, local);
1023
+ this.add(owner, `camunda:${local}`, "manual", `Conditional event filter ${local}="${value}" is not converted.`, "Use zeebe:conditionalFilter (variableNames, variableEvents).", false);
1024
+ }
1025
+ for (const local of ["errorCodeVariable", "errorMessageVariable", "escalationCodeVariable"]) {
1026
+ const value = this.attr(definition, local);
1027
+ if (value === undefined)
1028
+ continue;
1029
+ this.keepAttr(definition, local);
1030
+ this.add(owner, `camunda:${local}`, "manual", `Camunda 8 does not write the caught code or message into "${value}".`, "Have the thrower pass the values as variables and map them with an output mapping on the catch event.", false);
1031
+ }
1032
+ }
1033
+ }
1034
+ /** A condition text as `=feel`, when its JUEL is provable. */
1035
+ condition(text, attributes) {
1036
+ const language = attributes.language;
1037
+ if (language !== undefined && language.toLowerCase() !== "juel") {
1038
+ return { ok: false, reason: `it is a ${language} script condition` };
1039
+ }
1040
+ const trimmed = text.trim();
1041
+ if (trimmed.startsWith("="))
1042
+ return { ok: true, value: trimmed };
1043
+ if (!containsJuel(trimmed))
1044
+ return { ok: false, reason: "it is not a JUEL expression" };
1045
+ const result = translateJuelToFeel(trimmed);
1046
+ return result.ok ? { ok: true, value: `=${result.feel}` } : { ok: false, reason: result.reason };
1047
+ }
1048
+ convertFlow(flow, owner) {
1049
+ if (flow.conditionExpression !== undefined) {
1050
+ const { text, attributes } = flow.conditionExpression;
1051
+ const converted = this.condition(text, attributes);
1052
+ if (converted.ok && converted.value !== text.trim()) {
1053
+ flow.conditionExpression.text = converted.value;
1054
+ Reflect.deleteProperty(flow.conditionExpression.attributes, "language");
1055
+ this.add(owner, "conditionExpression", "convertible", `Condition "${text.trim()}" became "${converted.value}".`, "FEEL condition", true);
1056
+ }
1057
+ else if (!converted.ok) {
1058
+ this.add(owner, "conditionExpression", "manual", `Condition "${text.trim()}" was not translated: ${converted.reason}.`, "Rewrite it as a FEEL expression (=…).", false);
1059
+ }
1060
+ }
1061
+ this.convertCommon(owner);
1062
+ }
1063
+ convertLoop(owner, loop) {
1064
+ if (!loop.extensionElements.some((element) => element.name === "zeebe:loopCharacteristics")) {
1065
+ const collection = this.attr(loop, "collection");
1066
+ const elementVariable = this.attr(loop, "elementVariable");
1067
+ if (collection !== undefined) {
1068
+ const source = containsJuel(collection)
1069
+ ? this.staticOrExpression(collection)
1070
+ : isFeelName(collection)
1071
+ ? { ok: true, value: `=${collection}` }
1072
+ : { ok: false, reason: `"${collection}" is not a valid FEEL name` };
1073
+ if (source.ok) {
1074
+ const attributes = { inputCollection: source.value };
1075
+ if (elementVariable !== undefined)
1076
+ attributes.inputElement = elementVariable;
1077
+ this.dropAttr(loop, "collection");
1078
+ this.dropAttr(loop, "elementVariable");
1079
+ loop.extensionElements.push({
1080
+ name: "zeebe:loopCharacteristics",
1081
+ attributes,
1082
+ children: [],
1083
+ });
1084
+ this.add(owner, "camunda:collection", "convertible", `Multi-instance over "${collection}" became zeebe:loopCharacteristics inputCollection="${source.value}"${attributes.inputElement === undefined ? "" : ` inputElement="${attributes.inputElement}"`}.`, "zeebe:loopCharacteristics", true);
1085
+ }
1086
+ else {
1087
+ this.keepAttr(loop, "collection");
1088
+ this.keepAttr(loop, "elementVariable");
1089
+ this.add(owner, "camunda:collection", "manual", `Multi-instance collection "${collection}" was not translated: ${source.reason}.`, "Set zeebe:loopCharacteristics inputCollection by hand.", false);
1090
+ }
1091
+ }
1092
+ else if (loop.loopCardinality !== undefined) {
1093
+ this.add(owner, "loopCardinality", "manual", `Camunda 8 has no loop cardinality ("${loop.loopCardinality.text.trim()}"); a multi-instance activity iterates over a collection.`, 'Set zeebe:loopCharacteristics inputCollection, e.g. "=for i in 1..n return i" when n ≥ 1.', false);
1094
+ }
1095
+ else {
1096
+ this.add(owner, "multiInstanceLoopCharacteristics", "manual", "The multi-instance activity names no collection.", "Set zeebe:loopCharacteristics inputCollection (and inputElement).", false);
1097
+ }
1098
+ }
1099
+ if (loop.completionCondition !== undefined) {
1100
+ const text = loop.completionCondition.text.trim();
1101
+ if (containsJuel(text)) {
1102
+ const converted = this.staticOrExpression(text, true);
1103
+ if (converted.ok) {
1104
+ loop.completionCondition.text = converted.value;
1105
+ this.add(owner, "completionCondition", "convertible", `Completion condition became "${converted.value}" (nrOf… variables renamed to numberOf…).`, "FEEL completion condition", true);
1106
+ }
1107
+ else {
1108
+ this.add(owner, "completionCondition", "manual", `Completion condition "${text}" was not translated: ${converted.reason}.`, "Rewrite it as a FEEL expression.", false);
1109
+ }
1110
+ }
1111
+ }
1112
+ }
1113
+ setExecutionPlatform() {
1114
+ const d = this.definitions;
1115
+ const version = this.options.executionPlatformVersion ?? DEFAULT_PLATFORM_VERSION;
1116
+ const before = d.unknownAttributes["modeler:executionPlatform"];
1117
+ d.namespaces.zeebe ??= ZEEBE_NS;
1118
+ d.namespaces.modeler ??= MODELER_NS;
1119
+ d.unknownAttributes["modeler:executionPlatform"] = "Camunda Cloud";
1120
+ d.unknownAttributes["modeler:executionPlatformVersion"] = version;
1121
+ this.processId = "";
1122
+ this.add({ id: d.id, type: "definitions" }, "modeler:executionPlatform", "convertible", `Execution platform set to Camunda Cloud ${version}${before === undefined ? "" : ` (was ${before})`}.`, "Camunda Modeler opens the file as a Camunda 8 diagram.", true);
1123
+ }
1124
+ }
1125
+ const DELEGATE_LABEL = {
1126
+ class: "Java delegate class",
1127
+ delegateExpression: "Delegate expression",
1128
+ expression: "Expression",
1129
+ };
1130
+ const TASK_LISTENER_EVENTS = {
1131
+ create: "creating",
1132
+ assignment: "assigning",
1133
+ update: "updating",
1134
+ complete: "completing",
1135
+ delete: "canceling",
1136
+ };
1137
+ function describeImplementation(listener, prefix) {
1138
+ for (const key of ["class", "delegateExpression", "expression"]) {
1139
+ const value = listener.attributes[key];
1140
+ if (value !== undefined)
1141
+ return `${key} "${value}"`;
1142
+ }
1143
+ const script = listener.children.find((child) => child.name === `${prefix ?? "camunda"}:script`);
1144
+ return script === undefined
1145
+ ? "no implementation"
1146
+ : `${script.attributes.scriptFormat ?? "script"} script`;
1147
+ }
1148
+ /** A Camunda 8 mapping target: a FEEL name, optionally a dotted path into a context. */
1149
+ function isFeelPath(target) {
1150
+ return target.split(".").every((part) => isFeelName(part));
1151
+ }
1152
+ //# sourceMappingURL=migrate.js.map