@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.
- package/agent-cards/bpmn.md +4 -2
- package/builder-reference.md +11 -9
- package/dist/bpmn/auto-layout.js +82 -26
- package/dist/bpmn/bpmn-builder.d.ts +84 -7
- package/dist/bpmn/bpmn-builder.js +321 -76
- package/dist/bpmn/bpmn-model.d.ts +2 -0
- package/dist/bpmn/bpmn-parser.js +68 -76
- package/dist/bpmn/bpmn-serializer.js +60 -19
- package/dist/bpmn/bpmnlint.js +4 -69
- package/dist/bpmn/builder-rules.d.ts +20 -0
- package/dist/bpmn/builder-rules.js +120 -0
- package/dist/bpmn/camunda-compat-data.d.ts +10 -148
- package/dist/bpmn/camunda-compat-data.js +16 -407
- package/dist/bpmn/camunda-compat-feel.d.ts +3 -0
- package/dist/bpmn/camunda-compat-feel.js +1 -1
- package/dist/bpmn/camunda-compat.js +7 -6
- package/dist/bpmn/camunda7/export.js +4 -1
- package/dist/bpmn/camunda7/juel.js +2 -1
- package/dist/bpmn/camunda7/migrate.d.ts +23 -0
- package/dist/bpmn/camunda7/migrate.js +75 -3
- package/dist/bpmn/compact-stream.js +2 -1
- package/dist/bpmn/compact.d.ts +80 -4
- package/dist/bpmn/compact.js +220 -38
- package/dist/bpmn/feel-condition.d.ts +9 -0
- package/dist/bpmn/feel-condition.js +19 -0
- package/dist/bpmn/full-operations.js +31 -4
- package/dist/bpmn/index.d.ts +17 -1
- package/dist/bpmn/index.js +19 -25
- package/dist/bpmn/operations.d.ts +4 -4
- package/dist/bpmn/operations.js +14 -2
- package/dist/bpmn/optimize/bpmnlint-rules.js +7 -40
- package/dist/bpmn/optimize/index.js +15 -1
- package/dist/bpmn/optimize/tasks.js +12 -3
- package/dist/bpmn/process-delta.d.ts +18 -0
- package/dist/bpmn/process-delta.js +20 -2
- package/dist/bpmn/process-text-writer.js +27 -1
- package/dist/bpmn/process-text.d.ts +9 -3
- package/dist/bpmn/process-text.js +122 -16
- package/dist/bpmn/stable-ids.d.ts +2 -0
- package/dist/bpmn/stable-ids.js +8 -0
- package/dist/bpmn/xsd-guards.d.ts +8 -0
- package/dist/bpmn/xsd-guards.js +56 -0
- package/dist/bpmn/zeebe-extensions.js +2 -1
- package/dist/bpmn/zeebe-placement.js +6 -129
- package/dist/bpmn/zeebe-validate/context.d.ts +132 -0
- package/dist/bpmn/zeebe-validate/context.js +241 -0
- package/dist/bpmn/zeebe-validate/gate.d.ts +87 -0
- package/dist/bpmn/zeebe-validate/gate.js +492 -0
- package/dist/bpmn/zeebe-validate/index.d.ts +37 -0
- package/dist/bpmn/zeebe-validate/index.js +106 -0
- package/dist/bpmn/zeebe-validate/rules/events.d.ts +4 -0
- package/dist/bpmn/zeebe-validate/rules/events.js +580 -0
- package/dist/bpmn/zeebe-validate/rules/extensions.d.ts +4 -0
- package/dist/bpmn/zeebe-validate/rules/extensions.js +411 -0
- package/dist/bpmn/zeebe-validate/rules/gateways.d.ts +3 -0
- package/dist/bpmn/zeebe-validate/rules/gateways.js +296 -0
- package/dist/bpmn/zeebe-validate/rules/references.d.ts +3 -0
- package/dist/bpmn/zeebe-validate/rules/references.js +495 -0
- package/dist/bpmn/zeebe-validate/rules/structure.d.ts +3 -0
- package/dist/bpmn/zeebe-validate/rules/structure.js +629 -0
- package/dist/bpmn/zeebe-validate/rules/tasks.d.ts +4 -0
- package/dist/bpmn/zeebe-validate/rules/tasks.js +446 -0
- package/dist/bpmn/zeebe-validate/xml.d.ts +15 -0
- package/dist/bpmn/zeebe-validate/xml.js +1062 -0
- package/dist/bpmn/zeebe-validate/xsd.d.ts +19 -0
- package/dist/bpmn/zeebe-validate/xsd.js +350 -0
- package/dist/connectors/apply-element.d.ts +5 -2
- package/dist/connectors/apply-element.js +6 -0
- package/dist/connectors/apply-many.d.ts +9 -2
- package/dist/connectors/apply-many.js +17 -2
- package/dist/connectors/apply.d.ts +4 -2
- package/dist/connectors/deployability.d.ts +27 -0
- package/dist/connectors/deployability.js +41 -0
- package/dist/connectors/index.d.ts +1 -0
- package/dist/connectors/lines.d.ts +10 -0
- package/dist/connectors/lines.js +13 -4
- package/dist/dmn/dmn-model.d.ts +24 -4
- package/dist/dmn/dmn-parser.js +37 -3
- package/dist/dmn/dmn-serializer.js +48 -47
- package/dist/dmn/lint.js +4 -11
- package/dist/errors.d.ts +30 -1
- package/dist/errors.js +31 -0
- package/dist/form/form-model.d.ts +11 -0
- package/dist/form/form-parser.d.ts +1 -0
- package/dist/form/form-parser.js +48 -12
- package/dist/form/form-serializer.js +40 -17
- package/dist/form/lint.js +6 -40
- package/dist/generated/bpmn-elements.d.ts +5 -0
- package/dist/generated/bpmn-elements.js +151 -0
- package/dist/generated/camunda-compat-data.d.ts +148 -0
- package/dist/generated/camunda-compat-data.js +371 -0
- package/dist/generated/dmn-elements.d.ts +12 -0
- package/dist/generated/dmn-elements.js +45 -0
- package/dist/generated/form-elements.d.ts +5 -0
- package/dist/generated/form-elements.js +45 -0
- package/dist/generated/lint-rules.d.ts +17 -0
- package/dist/generated/lint-rules.js +116 -0
- package/dist/generated/zeebe-elements.d.ts +10 -0
- package/dist/generated/zeebe-elements.js +168 -0
- package/dist/generated/zeebe-rules.d.ts +25 -0
- package/dist/generated/zeebe-rules.js +202 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.js +4 -1
- package/dist/layout/annotations.js +21 -1
- package/dist/layout/orthogonal.js +9 -3
- package/dist/plan/compile.d.ts +26 -1
- package/dist/plan/compile.js +48 -6
- package/dist/plan/merge.d.ts +2 -1
- package/dist/plan/merge.js +13 -5
- package/package.json +2 -2
package/dist/bpmn/compact.js
CHANGED
|
@@ -2,9 +2,12 @@ import { packAnnotations } from "../layout/annotations.js";
|
|
|
2
2
|
import { layoutProcess } from "../layout/index.js";
|
|
3
3
|
import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
|
|
4
4
|
import { addAnnotationShapes } from "./auto-layout.js";
|
|
5
|
+
import { normalizeCamundaVersion } from "./camunda-compat.js";
|
|
6
|
+
import { toFeelCondition } from "./feel-condition.js";
|
|
5
7
|
import { restConnectorTaskType } from "./rest-connector.js";
|
|
6
|
-
import { assignEventDefinitionIds } from "./stable-ids.js";
|
|
7
|
-
import { makeConditionalDefinition } from "./zeebe-extensions.js";
|
|
8
|
+
import { assignEventDefinitionIds, rootDefinitionId } from "./stable-ids.js";
|
|
9
|
+
import { makeConditionalDefinition, zeebeExtensionsToXmlElements } from "./zeebe-extensions.js";
|
|
10
|
+
import { assertDeployable } from "./zeebe-validate/gate.js";
|
|
8
11
|
// ── Default flows ────────────────────────────────────────────────────────────
|
|
9
12
|
/**
|
|
10
13
|
* The gateway types that carry a `bpmn:default`. No other element in this model
|
|
@@ -44,9 +47,57 @@ export function defaultFlows(elements, flows) {
|
|
|
44
47
|
function findAttr(ext, name, attr) {
|
|
45
48
|
return ext.find((e) => e.name === name)?.attributes[attr];
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
/** The names and codes an element's event definition or `messageRef` resolves to. */
|
|
51
|
+
function compactifyReferences(el, result, roots) {
|
|
52
|
+
const message = (ref) => {
|
|
53
|
+
// `?? []`: callers such as the lint plugin pass partial models.
|
|
54
|
+
const found = ref === undefined ? undefined : (roots.messages ?? []).find((m) => m.id === ref);
|
|
55
|
+
if (found?.name)
|
|
56
|
+
result.messageName = found.name;
|
|
57
|
+
const key = found?.extensionElements?.find((x) => x.name === "zeebe:subscription")?.attributes
|
|
58
|
+
.correlationKey;
|
|
59
|
+
if (key)
|
|
60
|
+
result.correlationKey = key;
|
|
61
|
+
};
|
|
62
|
+
if (el.type === "receiveTask")
|
|
63
|
+
message(el.messageRef);
|
|
64
|
+
const def = "eventDefinitions" in el ? el.eventDefinitions[0] : undefined;
|
|
65
|
+
switch (def?.type) {
|
|
66
|
+
case "timer":
|
|
67
|
+
if (def.timeDate)
|
|
68
|
+
result.timerDate = def.timeDate;
|
|
69
|
+
if (def.timeCycle)
|
|
70
|
+
result.timerCycle = def.timeCycle;
|
|
71
|
+
break;
|
|
72
|
+
case "message":
|
|
73
|
+
message(def.messageRef);
|
|
74
|
+
break;
|
|
75
|
+
case "signal": {
|
|
76
|
+
const name = roots.signals?.find((x) => x.id === def.signalRef)?.name;
|
|
77
|
+
if (name)
|
|
78
|
+
result.signalName = name;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case "error": {
|
|
82
|
+
const code = (roots.errors ?? []).find((x) => x.id === def.errorRef)?.errorCode;
|
|
83
|
+
if (code)
|
|
84
|
+
result.errorCode = code;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "escalation": {
|
|
88
|
+
const code = (roots.escalations ?? []).find((x) => x.id === def.escalationRef)?.escalationCode;
|
|
89
|
+
if (code)
|
|
90
|
+
result.escalationCode = code;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function compactifyElement(el, roots) {
|
|
48
96
|
const ext = el.extensionElements;
|
|
49
|
-
|
|
97
|
+
// A parsed event sub-process is a subProcess triggered by an event; expanded as a plain
|
|
98
|
+
// sub-process it would lose its trigger, and Zeebe refuses its typed start event there.
|
|
99
|
+
const type = el.type === "subProcess" && el.triggeredByEvent ? "eventSubProcess" : el.type;
|
|
100
|
+
const result = { id: el.id, type };
|
|
50
101
|
if (el.name)
|
|
51
102
|
result.name = el.name;
|
|
52
103
|
if (el.documentation)
|
|
@@ -166,7 +217,10 @@ function compactifyElement(el) {
|
|
|
166
217
|
result.timerDuration = def.timeDuration;
|
|
167
218
|
if (def?.type === "conditional" && def.condition !== undefined)
|
|
168
219
|
result.condition = def.condition;
|
|
220
|
+
if (def?.type === "link" && def.name !== undefined)
|
|
221
|
+
result.linkName = def.name;
|
|
169
222
|
}
|
|
223
|
+
compactifyReferences(el, result, roots);
|
|
170
224
|
const loop = "loopCharacteristics" in el ? el.loopCharacteristics : undefined;
|
|
171
225
|
const zeebeLoop = loop?.extensionElements.find((x) => x.name === "zeebe:loopCharacteristics");
|
|
172
226
|
const collection = zeebeLoop?.attributes.inputCollection;
|
|
@@ -188,6 +242,8 @@ function compactifyElement(el) {
|
|
|
188
242
|
if (el.cancelActivity === false)
|
|
189
243
|
result.interrupting = false;
|
|
190
244
|
}
|
|
245
|
+
if (el.type === "startEvent" && el.isInterrupting === false)
|
|
246
|
+
result.interrupting = false;
|
|
191
247
|
if (el.type === "dataObjectReference" && el.dataObjectRef !== undefined) {
|
|
192
248
|
result.dataObjectRef = el.dataObjectRef;
|
|
193
249
|
}
|
|
@@ -201,7 +257,7 @@ function compactifyElement(el) {
|
|
|
201
257
|
if ("flowElements" in el && Array.isArray(el.flowElements) && el.flowElements.length > 0) {
|
|
202
258
|
const seqFlows = "sequenceFlows" in el && Array.isArray(el.sequenceFlows) ? el.sequenceFlows : [];
|
|
203
259
|
result.children = {
|
|
204
|
-
elements: el.flowElements.map(compactifyElement),
|
|
260
|
+
elements: el.flowElements.map((child) => compactifyElement(child, roots)),
|
|
205
261
|
flows: compactifyFlows(el.flowElements, seqFlows),
|
|
206
262
|
};
|
|
207
263
|
}
|
|
@@ -252,7 +308,7 @@ export function compactify(defs) {
|
|
|
252
308
|
id: process.id,
|
|
253
309
|
name: process.name,
|
|
254
310
|
documentation: process.documentation,
|
|
255
|
-
elements: process.flowElements.map(compactifyElement),
|
|
311
|
+
elements: process.flowElements.map((el) => compactifyElement(el, defs)),
|
|
256
312
|
flows: compactifyFlows(process.flowElements, process.sequenceFlows),
|
|
257
313
|
})),
|
|
258
314
|
};
|
|
@@ -499,7 +555,7 @@ export function makeExtensions(el) {
|
|
|
499
555
|
el.jobType &&
|
|
500
556
|
!el.decisionId &&
|
|
501
557
|
!isConnectorJobType(el.jobType) &&
|
|
502
|
-
el.outputs
|
|
558
|
+
!Object.hasOwn(el.outputs ?? {}, el.resultVariable)) {
|
|
503
559
|
// A job worker's result: map its `response` variable to the result variable
|
|
504
560
|
ioMapping.push({
|
|
505
561
|
name: "zeebe:output",
|
|
@@ -512,7 +568,7 @@ export function makeExtensions(el) {
|
|
|
512
568
|
}
|
|
513
569
|
return ext;
|
|
514
570
|
}
|
|
515
|
-
function buildSubContent(children) {
|
|
571
|
+
function buildSubContent(children, roots) {
|
|
516
572
|
if (!children || children.elements.length === 0) {
|
|
517
573
|
return {
|
|
518
574
|
flowElements: [],
|
|
@@ -534,13 +590,15 @@ function buildSubContent(children) {
|
|
|
534
590
|
}
|
|
535
591
|
const defaults = defaultFlows(children.elements, children.flows);
|
|
536
592
|
return {
|
|
537
|
-
flowElements: children.elements.map((child) => buildFlowElement(child, inc.get(child.id) ?? [], out.get(child.id) ?? [], defaults.get(child.id))),
|
|
593
|
+
flowElements: children.elements.map((child) => buildFlowElement(child, inc.get(child.id) ?? [], out.get(child.id) ?? [], defaults.get(child.id), roots)),
|
|
538
594
|
sequenceFlows: children.flows.map((f) => ({
|
|
539
595
|
id: f.id,
|
|
540
596
|
name: f.name,
|
|
541
597
|
sourceRef: f.from,
|
|
542
598
|
targetRef: f.to,
|
|
543
|
-
conditionExpression: f.condition
|
|
599
|
+
conditionExpression: f.condition
|
|
600
|
+
? { text: toFeelCondition(f.condition), attributes: {} }
|
|
601
|
+
: undefined,
|
|
544
602
|
extensionElements: [],
|
|
545
603
|
unknownAttributes: {},
|
|
546
604
|
})),
|
|
@@ -557,9 +615,108 @@ function templateAttributes(el) {
|
|
|
557
615
|
? { "zeebe:modelerTemplate": id }
|
|
558
616
|
: { "zeebe:modelerTemplate": id, "zeebe:modelerTemplateVersion": String(version) };
|
|
559
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* The root elements {@link expand} writes for the names and codes elements carry:
|
|
620
|
+
* one message per name and correlation key, one signal per name, one error or
|
|
621
|
+
* escalation per code. Ids are made as the builder makes them (`Message_<name>`).
|
|
622
|
+
*/
|
|
623
|
+
export class CompactRoots {
|
|
624
|
+
messages = [];
|
|
625
|
+
errors = [];
|
|
626
|
+
signals = [];
|
|
627
|
+
escalations = [];
|
|
628
|
+
message(name, correlationKey) {
|
|
629
|
+
const key = (m) => m.extensionElements?.find((x) => x.name === "zeebe:subscription")?.attributes.correlationKey;
|
|
630
|
+
let found = this.messages.find((m) => m.name === name && key(m) === correlationKey);
|
|
631
|
+
if (found === undefined) {
|
|
632
|
+
found = {
|
|
633
|
+
id: rootDefinitionId("Message", name, this.messages),
|
|
634
|
+
name,
|
|
635
|
+
unknownAttributes: {},
|
|
636
|
+
};
|
|
637
|
+
if (correlationKey !== undefined) {
|
|
638
|
+
found.extensionElements = zeebeExtensionsToXmlElements({
|
|
639
|
+
subscription: { correlationKey },
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
this.messages.push(found);
|
|
643
|
+
}
|
|
644
|
+
return found.id;
|
|
645
|
+
}
|
|
646
|
+
signal(name) {
|
|
647
|
+
let found = this.signals.find((x) => x.name === name);
|
|
648
|
+
if (found === undefined) {
|
|
649
|
+
found = { id: rootDefinitionId("Signal", name, this.signals), name, unknownAttributes: {} };
|
|
650
|
+
this.signals.push(found);
|
|
651
|
+
}
|
|
652
|
+
return found.id;
|
|
653
|
+
}
|
|
654
|
+
error(code) {
|
|
655
|
+
let found = this.errors.find((x) => x.errorCode === code);
|
|
656
|
+
if (found === undefined) {
|
|
657
|
+
found = {
|
|
658
|
+
id: rootDefinitionId("Error", code, this.errors),
|
|
659
|
+
name: code,
|
|
660
|
+
errorCode: code,
|
|
661
|
+
unknownAttributes: {},
|
|
662
|
+
};
|
|
663
|
+
this.errors.push(found);
|
|
664
|
+
}
|
|
665
|
+
return found.id;
|
|
666
|
+
}
|
|
667
|
+
escalation(code) {
|
|
668
|
+
let found = this.escalations.find((x) => x.escalationCode === code);
|
|
669
|
+
if (found === undefined) {
|
|
670
|
+
found = {
|
|
671
|
+
id: rootDefinitionId("Escalation", code, this.escalations),
|
|
672
|
+
name: code,
|
|
673
|
+
escalationCode: code,
|
|
674
|
+
unknownAttributes: {},
|
|
675
|
+
};
|
|
676
|
+
this.escalations.push(found);
|
|
677
|
+
}
|
|
678
|
+
return found.id;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/** The element's event definition, with the names, codes and times it carries. */
|
|
682
|
+
function eventDefinitionOf(el, roots) {
|
|
683
|
+
const made = el.eventType ? makeEventDef(el.eventType) : undefined;
|
|
684
|
+
switch (made?.type) {
|
|
685
|
+
case "timer":
|
|
686
|
+
return {
|
|
687
|
+
...made,
|
|
688
|
+
...(el.timerDuration ? { timeDuration: el.timerDuration } : {}),
|
|
689
|
+
...(el.timerDate ? { timeDate: el.timerDate } : {}),
|
|
690
|
+
...(el.timerCycle ? { timeCycle: el.timerCycle } : {}),
|
|
691
|
+
};
|
|
692
|
+
case "conditional":
|
|
693
|
+
return el.condition !== undefined ? makeConditionalDefinition(el.condition) : made;
|
|
694
|
+
case "link":
|
|
695
|
+
return el.linkName !== undefined ? { ...made, name: el.linkName } : made;
|
|
696
|
+
case "message":
|
|
697
|
+
return roots && el.messageName
|
|
698
|
+
? { ...made, messageRef: roots.message(el.messageName, el.correlationKey || undefined) }
|
|
699
|
+
: made;
|
|
700
|
+
case "signal":
|
|
701
|
+
return roots && el.signalName ? { ...made, signalRef: roots.signal(el.signalName) } : made;
|
|
702
|
+
case "error":
|
|
703
|
+
return roots && el.errorCode ? { ...made, errorRef: roots.error(el.errorCode) } : made;
|
|
704
|
+
case "escalation":
|
|
705
|
+
return roots && el.escalationCode
|
|
706
|
+
? { ...made, escalationRef: roots.escalation(el.escalationCode) }
|
|
707
|
+
: made;
|
|
708
|
+
default:
|
|
709
|
+
return made;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* One compact element as a flow element. `roots`, when given, receives the
|
|
714
|
+
* messages, signals, errors and escalations the element names; without it the
|
|
715
|
+
* names and codes are not written.
|
|
716
|
+
*/
|
|
560
717
|
export function buildFlowElement(el, incoming, outgoing,
|
|
561
718
|
/** Id of the outgoing flow marked `isDefault`, for a gateway that has one. */
|
|
562
|
-
defaultFlow) {
|
|
719
|
+
defaultFlow, roots) {
|
|
563
720
|
const base = {
|
|
564
721
|
id: el.id,
|
|
565
722
|
name: el.name,
|
|
@@ -569,22 +726,17 @@ defaultFlow) {
|
|
|
569
726
|
extensionElements: makeExtensions(el),
|
|
570
727
|
unknownAttributes: templateAttributes(el),
|
|
571
728
|
};
|
|
572
|
-
const
|
|
573
|
-
const eventDef = made?.type === "timer" && el.timerDuration
|
|
574
|
-
? { ...made, timeDuration: el.timerDuration }
|
|
575
|
-
: made?.type === "conditional" && el.condition !== undefined
|
|
576
|
-
? makeConditionalDefinition(el.condition)
|
|
577
|
-
: made;
|
|
729
|
+
const eventDef = eventDefinitionOf(el, roots);
|
|
578
730
|
const eventDefs = eventDef ? [eventDef] : [];
|
|
579
731
|
// Zeebe rejects an id-less definition at deploy time; the builder derives the same ids.
|
|
580
732
|
assignEventDefinitionIds(el.id, eventDefs);
|
|
581
|
-
const subContent = buildSubContent(el.children);
|
|
733
|
+
const subContent = buildSubContent(el.children, roots);
|
|
582
734
|
const loop = el.multiInstance && {
|
|
583
735
|
loopCharacteristics: {
|
|
584
736
|
isSequential: el.multiInstance.sequential || undefined,
|
|
585
737
|
completionCondition: el.multiInstance.completionCondition
|
|
586
738
|
? {
|
|
587
|
-
text: el.multiInstance.completionCondition,
|
|
739
|
+
text: toFeelCondition(el.multiInstance.completionCondition),
|
|
588
740
|
attributes: { "xsi:type": "bpmn:tFormalExpression" },
|
|
589
741
|
}
|
|
590
742
|
: undefined,
|
|
@@ -608,7 +760,13 @@ defaultFlow) {
|
|
|
608
760
|
};
|
|
609
761
|
switch (el.type) {
|
|
610
762
|
case "startEvent":
|
|
611
|
-
return {
|
|
763
|
+
return {
|
|
764
|
+
...base,
|
|
765
|
+
type: "startEvent",
|
|
766
|
+
eventDefinitions: eventDefs,
|
|
767
|
+
// An event sub-process's start: `false` lets the scope go on
|
|
768
|
+
...(el.interrupting === false ? { isInterrupting: false } : {}),
|
|
769
|
+
};
|
|
612
770
|
case "endEvent":
|
|
613
771
|
return { ...base, type: "endEvent", eventDefinitions: eventDefs };
|
|
614
772
|
case "intermediateCatchEvent":
|
|
@@ -636,7 +794,14 @@ defaultFlow) {
|
|
|
636
794
|
case "sendTask":
|
|
637
795
|
return { ...base, type: "sendTask", ...loop };
|
|
638
796
|
case "receiveTask":
|
|
639
|
-
return {
|
|
797
|
+
return {
|
|
798
|
+
...base,
|
|
799
|
+
type: "receiveTask",
|
|
800
|
+
...(roots && el.messageName
|
|
801
|
+
? { messageRef: roots.message(el.messageName, el.correlationKey || undefined) }
|
|
802
|
+
: {}),
|
|
803
|
+
...loop,
|
|
804
|
+
};
|
|
640
805
|
case "manualTask":
|
|
641
806
|
return { ...base, type: "manualTask", ...loop };
|
|
642
807
|
case "task":
|
|
@@ -736,7 +901,7 @@ function buildDiagram(processId, process) {
|
|
|
736
901
|
},
|
|
737
902
|
};
|
|
738
903
|
}
|
|
739
|
-
function expandProcess(compact) {
|
|
904
|
+
function expandProcess(compact, roots) {
|
|
740
905
|
const incoming = new Map();
|
|
741
906
|
const outgoing = new Map();
|
|
742
907
|
for (const f of compact.flows) {
|
|
@@ -748,13 +913,15 @@ function expandProcess(compact) {
|
|
|
748
913
|
incoming.set(f.to, inc);
|
|
749
914
|
}
|
|
750
915
|
const defaults = defaultFlows(compact.elements, compact.flows);
|
|
751
|
-
const flowElements = compact.elements.map((el) => buildFlowElement(el, incoming.get(el.id) ?? [], outgoing.get(el.id) ?? [], defaults.get(el.id)));
|
|
916
|
+
const flowElements = compact.elements.map((el) => buildFlowElement(el, incoming.get(el.id) ?? [], outgoing.get(el.id) ?? [], defaults.get(el.id), roots));
|
|
752
917
|
const sequenceFlows = compact.flows.map((f) => ({
|
|
753
918
|
id: f.id,
|
|
754
919
|
name: f.name,
|
|
755
920
|
sourceRef: f.from,
|
|
756
921
|
targetRef: f.to,
|
|
757
|
-
conditionExpression: f.condition
|
|
922
|
+
conditionExpression: f.condition
|
|
923
|
+
? { text: toFeelCondition(f.condition), attributes: {} }
|
|
924
|
+
: undefined,
|
|
758
925
|
extensionElements: [],
|
|
759
926
|
unknownAttributes: {},
|
|
760
927
|
}));
|
|
@@ -794,9 +961,16 @@ function expandProcess(compact) {
|
|
|
794
961
|
* Restores a {@link CompactDiagram} (produced by {@link compactify} or an AI
|
|
795
962
|
* model) back to a full {@link BpmnDefinitions} with auto-generated layout.
|
|
796
963
|
*
|
|
964
|
+
* The result targets Camunda 8: it carries `modeler:executionPlatform="Camunda
|
|
965
|
+
* Cloud"` (and the diagram's `executionPlatformVersion`, when it names one), so a
|
|
966
|
+
* later `Bpmn.export` checks it the same way.
|
|
967
|
+
* Then `assertDeployable` refuses what Zeebe would reject, unless
|
|
968
|
+
* `options.validate` is `false`.
|
|
969
|
+
*
|
|
797
970
|
* @throws {Error} When the diagram cannot be valid BPMN — a flow or boundary
|
|
798
971
|
* event naming an element that is not in its scope, a duplicate or missing id,
|
|
799
972
|
* or an unknown `eventType`. The message lists every problem at once.
|
|
973
|
+
* @throws {DeployabilityError} When the gate runs and Zeebe would reject the model.
|
|
800
974
|
*
|
|
801
975
|
* @example
|
|
802
976
|
* ```typescript
|
|
@@ -806,21 +980,25 @@ function expandProcess(compact) {
|
|
|
806
980
|
* editor.loadXml(xml)
|
|
807
981
|
* ```
|
|
808
982
|
*/
|
|
809
|
-
export function expand(compact) {
|
|
983
|
+
export function expand(compact, options = {}) {
|
|
810
984
|
assertCompactDiagram(compact, "expand");
|
|
811
985
|
const problems = compactProblems(compact);
|
|
812
986
|
if (problems.length > 0) {
|
|
813
987
|
throw new Error(`expand: invalid CompactDiagram — ${problems.join("; ")}`);
|
|
814
988
|
}
|
|
989
|
+
const roots = new CompactRoots();
|
|
815
990
|
const processes = [];
|
|
816
991
|
const diagrams = [];
|
|
817
992
|
for (const cp of compact.processes) {
|
|
818
|
-
const { process, diagram } = expandProcess(cp);
|
|
993
|
+
const { process, diagram } = expandProcess(cp, roots);
|
|
819
994
|
processes.push(process);
|
|
820
995
|
diagrams.push(diagram);
|
|
821
996
|
}
|
|
997
|
+
const gate = options.validate !== false;
|
|
822
998
|
const platform = compact.executionPlatformVersion;
|
|
823
|
-
|
|
999
|
+
// Gated output is Camunda 8 output: marking it so makes `Bpmn.export`'s "auto" check agree.
|
|
1000
|
+
const camunda8 = gate || platform !== undefined;
|
|
1001
|
+
const definitions = {
|
|
824
1002
|
id: compact.id,
|
|
825
1003
|
targetNamespace: "http://bpmn.io/schema/bpmn",
|
|
826
1004
|
namespaces: {
|
|
@@ -829,21 +1007,25 @@ export function expand(compact) {
|
|
|
829
1007
|
dc: "http://www.omg.org/spec/DD/20100524/DC",
|
|
830
1008
|
di: "http://www.omg.org/spec/DD/20100524/DI",
|
|
831
1009
|
zeebe: "http://camunda.org/schema/zeebe/1.0",
|
|
832
|
-
...(
|
|
1010
|
+
...(camunda8 ? { modeler: "http://camunda.org/schema/modeler/1.0" } : {}),
|
|
833
1011
|
},
|
|
834
|
-
unknownAttributes:
|
|
835
|
-
? {}
|
|
836
|
-
: {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
messages: [],
|
|
843
|
-
signals: [],
|
|
1012
|
+
unknownAttributes: {
|
|
1013
|
+
...(camunda8 ? { "modeler:executionPlatform": "Camunda Cloud" } : {}),
|
|
1014
|
+
...(platform === undefined ? {} : { "modeler:executionPlatformVersion": platform }),
|
|
1015
|
+
},
|
|
1016
|
+
errors: roots.errors,
|
|
1017
|
+
escalations: roots.escalations,
|
|
1018
|
+
messages: roots.messages,
|
|
1019
|
+
signals: roots.signals,
|
|
844
1020
|
collaborations: [],
|
|
845
1021
|
processes,
|
|
846
1022
|
diagrams,
|
|
847
1023
|
};
|
|
1024
|
+
if (!gate)
|
|
1025
|
+
return definitions;
|
|
1026
|
+
return assertDeployable(definitions, {
|
|
1027
|
+
camundaVersion: normalizeCamundaVersion(options.camundaVersion ?? platform),
|
|
1028
|
+
placeholders: options.placeholders ?? false,
|
|
1029
|
+
}).definitions;
|
|
848
1030
|
}
|
|
849
1031
|
//# sourceMappingURL=compact.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a condition into the form Zeebe deploys: a FEEL expression with a
|
|
3
|
+
* leading `=`. Zeebe reads text without `=` as a static value and rejects it
|
|
4
|
+
* on a condition. A Camunda 7 `${…}` goes through the migration's JUEL
|
|
5
|
+
* converter; one it cannot translate is left as written, so the lint and
|
|
6
|
+
* deploy checks still name it instead of us guessing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toFeelCondition(text: string): string;
|
|
9
|
+
//# sourceMappingURL=feel-condition.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { translateJuelToFeel } from "./camunda7/juel.js";
|
|
2
|
+
/**
|
|
3
|
+
* Turns a condition into the form Zeebe deploys: a FEEL expression with a
|
|
4
|
+
* leading `=`. Zeebe reads text without `=` as a static value and rejects it
|
|
5
|
+
* on a condition. A Camunda 7 `${…}` goes through the migration's JUEL
|
|
6
|
+
* converter; one it cannot translate is left as written, so the lint and
|
|
7
|
+
* deploy checks still name it instead of us guessing.
|
|
8
|
+
*/
|
|
9
|
+
export function toFeelCondition(text) {
|
|
10
|
+
const trimmed = text.trim();
|
|
11
|
+
if (trimmed === "" || trimmed.startsWith("="))
|
|
12
|
+
return text;
|
|
13
|
+
if (/^[$#]\{[\s\S]*\}$/.test(trimmed)) {
|
|
14
|
+
const translated = translateJuelToFeel(trimmed);
|
|
15
|
+
return translated.ok ? `=${translated.feel}` : text;
|
|
16
|
+
}
|
|
17
|
+
return `=${trimmed}`;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=feel-condition.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
|
|
2
|
-
import { buildFlowElement, defaultFlows, makeEventDef, } from "./compact.js";
|
|
2
|
+
import { buildFlowElement, compactify, defaultFlows, makeEventDef, } from "./compact.js";
|
|
3
3
|
import { assignEventDefinitionIds } from "./stable-ids.js";
|
|
4
4
|
import { assertZeebePlacement, bpmnElementName, ensureZeebeExtension, isZeebePlacementAllowed, zeebeExtensionsToXmlElements, } from "./zeebe-extensions.js";
|
|
5
5
|
/** Thrown by {@link applyBpmnOperations} in strict mode. */
|
|
@@ -128,6 +128,16 @@ const ROOT_FIELDS = [
|
|
|
128
128
|
["escalationCode", "escalation", "escalationCode"],
|
|
129
129
|
["signalName", "signal", "name"],
|
|
130
130
|
];
|
|
131
|
+
/** The compact fields that live on root elements or timer definitions, compared before patching. */
|
|
132
|
+
const ROOT_COMPACT_FIELDS = [
|
|
133
|
+
"messageName",
|
|
134
|
+
"correlationKey",
|
|
135
|
+
"signalName",
|
|
136
|
+
"errorCode",
|
|
137
|
+
"escalationCode",
|
|
138
|
+
"timerDate",
|
|
139
|
+
"timerCycle",
|
|
140
|
+
];
|
|
131
141
|
const TIMER_FIELDS = [
|
|
132
142
|
["timerDuration", "timeDuration"],
|
|
133
143
|
["timerDate", "timeDate"],
|
|
@@ -173,15 +183,19 @@ function referenceCount(definitions, kind, id) {
|
|
|
173
183
|
* leaves the element as it was. Returns the reason, or nothing.
|
|
174
184
|
*/
|
|
175
185
|
function misplacedEventFields(definitions, element, patch) {
|
|
176
|
-
for (const [field, kind] of ROOT_FIELDS) {
|
|
186
|
+
for (const [field, kind, attribute] of ROOT_FIELDS) {
|
|
177
187
|
if (patch[field] === undefined)
|
|
178
188
|
continue;
|
|
179
189
|
const definition = eventDefinitionOf(element, kind);
|
|
180
190
|
if (!definition)
|
|
181
191
|
return `${field} needs a ${kind} event definition, and "${element.id}" has none`;
|
|
182
192
|
const ref = asRecord(definition)[refKey(kind)];
|
|
193
|
+
const root = rootsOf(definitions, kind).find((candidate) => candidate.id === ref);
|
|
194
|
+
// Restating the value a shared root already holds changes nothing for anyone
|
|
195
|
+
if (root !== undefined && root[attribute] === patch[field])
|
|
196
|
+
continue;
|
|
183
197
|
if (typeof ref === "string" &&
|
|
184
|
-
|
|
198
|
+
root !== undefined &&
|
|
185
199
|
referenceCount(definitions, kind, ref) > 1) {
|
|
186
200
|
return `${field}: the ${kind} "${ref}" is shared by ${referenceCount(definitions, kind, ref)} elements; changing it would change them all`;
|
|
187
201
|
}
|
|
@@ -476,7 +490,9 @@ function setResultVariable(element, resultVariable) {
|
|
|
476
490
|
* does not model stays exactly as it was.
|
|
477
491
|
*/
|
|
478
492
|
function patchElement(definitions, element, patch) {
|
|
479
|
-
|
|
493
|
+
// compactify reads a `subProcess triggeredByEvent` as an eventSubProcess: the same element
|
|
494
|
+
const type = element.type === "subProcess" && element.triggeredByEvent ? "eventSubProcess" : element.type;
|
|
495
|
+
if (patch.type !== undefined && patch.type !== type) {
|
|
480
496
|
return `changing type (${element.type} → ${patch.type}) needs a delete and an insert, so that what the new element should carry is explicit`;
|
|
481
497
|
}
|
|
482
498
|
const misplaced = misplacedExtensions(element, patch);
|
|
@@ -516,6 +532,9 @@ function patchElement(definitions, element, patch) {
|
|
|
516
532
|
}
|
|
517
533
|
if (patch.decisionId !== undefined) {
|
|
518
534
|
setExtensionAttribute(element, "zeebe:calledDecision", "decisionId", patch.decisionId);
|
|
535
|
+
// Camunda will not deploy a decision without the variable its result goes to
|
|
536
|
+
const decision = ensureExtension(element, "zeebe:calledDecision");
|
|
537
|
+
decision.attributes.resultVariable ??= patch.resultVariable ?? "result";
|
|
519
538
|
}
|
|
520
539
|
if (patch.script !== undefined) {
|
|
521
540
|
const script = ensureExtension(element, "zeebe:script");
|
|
@@ -811,6 +830,9 @@ function reconcileDefaultFlows(definitions, compact) {
|
|
|
811
830
|
*/
|
|
812
831
|
function operationsForCompact(definitions, compact) {
|
|
813
832
|
const operations = [];
|
|
833
|
+
// The names and codes the model holds now: patching one unchanged would trip over a
|
|
834
|
+
// root element shared by several events, which the compact view cannot tell apart.
|
|
835
|
+
const current = new Map(compactify(definitions).processes.flatMap((p) => p.elements.map((e) => [e.id, e])));
|
|
814
836
|
for (const compactProcess of compact.processes) {
|
|
815
837
|
const process = definitions.processes.find((candidate) => candidate.id === compactProcess.id);
|
|
816
838
|
if (!process)
|
|
@@ -851,6 +873,11 @@ function operationsForCompact(definitions, compact) {
|
|
|
851
873
|
continue;
|
|
852
874
|
if (present.includes(id)) {
|
|
853
875
|
const { id: _id, children: _children, ...patch } = element;
|
|
876
|
+
const now = current.get(id);
|
|
877
|
+
for (const key of ROOT_COMPACT_FIELDS) {
|
|
878
|
+
if (patch[key] === now?.[key])
|
|
879
|
+
delete patch[key];
|
|
880
|
+
}
|
|
854
881
|
operations.push({ op: "update", id, patch });
|
|
855
882
|
}
|
|
856
883
|
else {
|
package/dist/bpmn/index.d.ts
CHANGED
|
@@ -26,6 +26,19 @@ export declare const SAMPLE_BPMN_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"
|
|
|
26
26
|
*
|
|
27
27
|
* @see node_modules/@bpmnkit/core/agent-cards/bpmn.md — runnable script and traps (~1k tokens)
|
|
28
28
|
*/
|
|
29
|
+
/** Options for {@link Bpmn.export}. */
|
|
30
|
+
export interface ExportOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Whether to refuse a model Zeebe would reject on deploy (see `assertDeployable`):
|
|
33
|
+
* - `"auto"` (default): throws a `DeployabilityError` when the model targets Camunda 8
|
|
34
|
+
* (`modeler:executionPlatform="Camunda Cloud"`), checked for its
|
|
35
|
+
* `executionPlatformVersion`; a model for another engine is not checked.
|
|
36
|
+
* - `"error"`: throws whatever the platform.
|
|
37
|
+
* - `"warn"`: checks whatever the platform and logs the error's message with `console.warn`.
|
|
38
|
+
* - `false`: no check, e.g. for a work-in-progress diagram an editor saves.
|
|
39
|
+
*/
|
|
40
|
+
validate?: "auto" | "error" | "warn" | false;
|
|
41
|
+
}
|
|
29
42
|
export declare const Bpmn: {
|
|
30
43
|
/**
|
|
31
44
|
* Create a new BPMN process using the fluent builder API.
|
|
@@ -100,7 +113,10 @@ export declare const Bpmn: {
|
|
|
100
113
|
* Serialise a {@link BpmnDefinitions} model back to BPMN 2.0 XML.
|
|
101
114
|
*
|
|
102
115
|
* @param definitions - The typed BPMN model to export.
|
|
116
|
+
* @param options - `validate`: `"auto"` (default) refuses a Camunda 8 model Zeebe would reject,
|
|
117
|
+
* `"error"` refuses any such model, `"warn"` logs instead, `false` skips the check.
|
|
103
118
|
* @returns A BPMN 2.0 XML string.
|
|
119
|
+
* @throws {DeployabilityError} When the check runs, fails, and `validate` is not `"warn"`.
|
|
104
120
|
*
|
|
105
121
|
* @example
|
|
106
122
|
* ```typescript
|
|
@@ -108,7 +124,7 @@ export declare const Bpmn: {
|
|
|
108
124
|
* fs.writeFileSync("diagram.bpmn", xml, "utf-8")
|
|
109
125
|
* ```
|
|
110
126
|
*/
|
|
111
|
-
readonly export: (definitions: BpmnDefinitions) => string;
|
|
127
|
+
readonly export: (definitions: BpmnDefinitions, options?: ExportOptions) => string;
|
|
112
128
|
/**
|
|
113
129
|
* Returns a minimal valid BPMN XML string containing one process with a
|
|
114
130
|
* single start event. Useful for "New Diagram" / empty-canvas actions.
|
package/dist/bpmn/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { DeployabilityError } from "../errors.js";
|
|
1
2
|
import { applyAutoLayout } from "./auto-layout.js";
|
|
2
3
|
import { DiagramBuilder, ProcessBuilder } from "./bpmn-builder.js";
|
|
3
4
|
import { parseBpmn } from "./bpmn-parser.js";
|
|
4
5
|
import { serializeBpmn } from "./bpmn-serializer.js";
|
|
6
|
+
import { normalizeCamundaVersion } from "./camunda-compat.js";
|
|
7
|
+
import { assertDeployable, targetsCamunda8 } from "./zeebe-validate/gate.js";
|
|
5
8
|
/** A minimal 3-element BPMN diagram useful for first-launch or "New Diagram" defaults. */
|
|
6
9
|
export const SAMPLE_BPMN_XML = `<?xml version="1.0" encoding="UTF-8"?>
|
|
7
10
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
@@ -45,30 +48,6 @@ export const SAMPLE_BPMN_XML = `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
45
48
|
</bpmndi:BPMNPlane>
|
|
46
49
|
</bpmndi:BPMNDiagram>
|
|
47
50
|
</bpmn:definitions>`;
|
|
48
|
-
/**
|
|
49
|
-
* Entry point for all BPMN operations — parsing, building, exporting, and
|
|
50
|
-
* creating empty diagrams.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* import { Bpmn } from "@bpmnkit/core"
|
|
55
|
-
*
|
|
56
|
-
* // Parse existing XML
|
|
57
|
-
* const defs = Bpmn.parse(xml)
|
|
58
|
-
*
|
|
59
|
-
* // Build a new process
|
|
60
|
-
* const defs2 = Bpmn.createProcess("order")
|
|
61
|
-
* .startEvent("start")
|
|
62
|
-
* .serviceTask("task", { name: "Process", taskType: "process" })
|
|
63
|
-
* .endEvent("end")
|
|
64
|
-
* .withAutoLayout()
|
|
65
|
-
* .build()
|
|
66
|
-
*
|
|
67
|
-
* const xml2 = Bpmn.export(defs2)
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @see node_modules/@bpmnkit/core/agent-cards/bpmn.md — runnable script and traps (~1k tokens)
|
|
71
|
-
*/
|
|
72
51
|
export const Bpmn = {
|
|
73
52
|
/**
|
|
74
53
|
* Create a new BPMN process using the fluent builder API.
|
|
@@ -151,7 +130,10 @@ export const Bpmn = {
|
|
|
151
130
|
* Serialise a {@link BpmnDefinitions} model back to BPMN 2.0 XML.
|
|
152
131
|
*
|
|
153
132
|
* @param definitions - The typed BPMN model to export.
|
|
133
|
+
* @param options - `validate`: `"auto"` (default) refuses a Camunda 8 model Zeebe would reject,
|
|
134
|
+
* `"error"` refuses any such model, `"warn"` logs instead, `false` skips the check.
|
|
154
135
|
* @returns A BPMN 2.0 XML string.
|
|
136
|
+
* @throws {DeployabilityError} When the check runs, fails, and `validate` is not `"warn"`.
|
|
155
137
|
*
|
|
156
138
|
* @example
|
|
157
139
|
* ```typescript
|
|
@@ -159,7 +141,19 @@ export const Bpmn = {
|
|
|
159
141
|
* fs.writeFileSync("diagram.bpmn", xml, "utf-8")
|
|
160
142
|
* ```
|
|
161
143
|
*/
|
|
162
|
-
export(definitions) {
|
|
144
|
+
export(definitions, options = {}) {
|
|
145
|
+
const mode = options.validate ?? "auto";
|
|
146
|
+
if (mode !== false && (mode !== "auto" || targetsCamunda8(definitions))) {
|
|
147
|
+
const camundaVersion = normalizeCamundaVersion(definitions.unknownAttributes["modeler:executionPlatformVersion"]);
|
|
148
|
+
try {
|
|
149
|
+
assertDeployable(definitions, { camundaVersion });
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
if (mode !== "warn" || !(err instanceof DeployabilityError))
|
|
153
|
+
throw err;
|
|
154
|
+
console.warn(err.message);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
163
157
|
return serializeBpmn(definitions);
|
|
164
158
|
},
|
|
165
159
|
/**
|