@bpmnkit/core 0.0.8
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/README.md +185 -0
- package/dist/bpmn/auto-layout.d.ts +10 -0
- package/dist/bpmn/auto-layout.js +203 -0
- package/dist/bpmn/bpmn-builder.d.ts +381 -0
- package/dist/bpmn/bpmn-builder.js +1223 -0
- package/dist/bpmn/bpmn-model.d.ts +403 -0
- package/dist/bpmn/bpmn-model.js +2 -0
- package/dist/bpmn/bpmn-parser.d.ts +4 -0
- package/dist/bpmn/bpmn-parser.js +642 -0
- package/dist/bpmn/bpmn-serializer.d.ts +4 -0
- package/dist/bpmn/bpmn-serializer.js +515 -0
- package/dist/bpmn/compact.d.ts +91 -0
- package/dist/bpmn/compact.js +349 -0
- package/dist/bpmn/di-color.d.ts +9 -0
- package/dist/bpmn/di-color.js +32 -0
- package/dist/bpmn/index.d.ts +105 -0
- package/dist/bpmn/index.js +176 -0
- package/dist/bpmn/optimize/feel.d.ts +4 -0
- package/dist/bpmn/optimize/feel.js +186 -0
- package/dist/bpmn/optimize/flow.d.ts +4 -0
- package/dist/bpmn/optimize/flow.js +323 -0
- package/dist/bpmn/optimize/index.d.ts +5 -0
- package/dist/bpmn/optimize/index.js +51 -0
- package/dist/bpmn/optimize/naming.d.ts +8 -0
- package/dist/bpmn/optimize/naming.js +145 -0
- package/dist/bpmn/optimize/tasks.d.ts +4 -0
- package/dist/bpmn/optimize/tasks.js +273 -0
- package/dist/bpmn/optimize/types.d.ts +44 -0
- package/dist/bpmn/optimize/types.js +2 -0
- package/dist/bpmn/optimize/utils.d.ts +23 -0
- package/dist/bpmn/optimize/utils.js +129 -0
- package/dist/bpmn/rest-connector.d.ts +48 -0
- package/dist/bpmn/rest-connector.js +69 -0
- package/dist/bpmn/svg.d.ts +35 -0
- package/dist/bpmn/svg.js +557 -0
- package/dist/bpmn/type-guards.d.ts +136 -0
- package/dist/bpmn/type-guards.js +211 -0
- package/dist/bpmn/utils.d.ts +88 -0
- package/dist/bpmn/utils.js +207 -0
- package/dist/bpmn/zeebe-extensions.d.ts +72 -0
- package/dist/bpmn/zeebe-extensions.js +96 -0
- package/dist/dmn/compact.d.ts +44 -0
- package/dist/dmn/compact.js +125 -0
- package/dist/dmn/dmn-builder.d.ts +59 -0
- package/dist/dmn/dmn-builder.js +144 -0
- package/dist/dmn/dmn-layout.d.ts +57 -0
- package/dist/dmn/dmn-layout.js +256 -0
- package/dist/dmn/dmn-model.d.ts +158 -0
- package/dist/dmn/dmn-model.js +2 -0
- package/dist/dmn/dmn-parser.d.ts +4 -0
- package/dist/dmn/dmn-parser.js +275 -0
- package/dist/dmn/dmn-serializer.d.ts +4 -0
- package/dist/dmn/dmn-serializer.js +296 -0
- package/dist/dmn/index.d.ts +28 -0
- package/dist/dmn/index.js +51 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.js +66 -0
- package/dist/form/compact.d.ts +20 -0
- package/dist/form/compact.js +146 -0
- package/dist/form/form-builder.d.ts +111 -0
- package/dist/form/form-builder.js +347 -0
- package/dist/form/form-model.d.ts +221 -0
- package/dist/form/form-model.js +2 -0
- package/dist/form/form-parser.d.ts +4 -0
- package/dist/form/form-parser.js +514 -0
- package/dist/form/form-serializer.d.ts +4 -0
- package/dist/form/form-serializer.js +240 -0
- package/dist/form/index.d.ts +27 -0
- package/dist/form/index.js +43 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +19 -0
- package/dist/layout/bench.d.ts +86 -0
- package/dist/layout/bench.js +225 -0
- package/dist/layout/coordinates.d.ts +62 -0
- package/dist/layout/coordinates.js +868 -0
- package/dist/layout/crossing.d.ts +8 -0
- package/dist/layout/crossing.js +60 -0
- package/dist/layout/graph.d.ts +28 -0
- package/dist/layout/graph.js +126 -0
- package/dist/layout/index.d.ts +7 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/layers.d.ts +13 -0
- package/dist/layout/layers.js +49 -0
- package/dist/layout/layout-engine.d.ts +21 -0
- package/dist/layout/layout-engine.js +191 -0
- package/dist/layout/overlap.d.ts +10 -0
- package/dist/layout/overlap.js +70 -0
- package/dist/layout/routing.d.ts +26 -0
- package/dist/layout/routing.js +439 -0
- package/dist/layout/subprocess.d.ts +14 -0
- package/dist/layout/subprocess.js +77 -0
- package/dist/layout/types.d.ts +72 -0
- package/dist/layout/types.js +37 -0
- package/dist/types/id-generator.d.ts +8 -0
- package/dist/types/id-generator.js +31 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +2 -0
- package/dist/types/xml-element.d.ts +12 -0
- package/dist/types/xml-element.js +2 -0
- package/dist/xml/index.d.ts +2 -0
- package/dist/xml/index.js +2 -0
- package/dist/xml/xml-parser.d.ts +13 -0
- package/dist/xml/xml-parser.js +271 -0
- package/package.json +38 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { serializeXml } from "../xml/xml-parser.js";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Namespace prefix resolution
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
function nsPrefix(namespaces, uri) {
|
|
6
|
+
for (const [prefix, u] of Object.entries(namespaces)) {
|
|
7
|
+
if (u === uri)
|
|
8
|
+
return prefix;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
function bpmnPrefix(ns) {
|
|
13
|
+
return nsPrefix(ns, "http://www.omg.org/spec/BPMN/20100524/MODEL") ?? "bpmn";
|
|
14
|
+
}
|
|
15
|
+
function bpmndiPrefix(ns) {
|
|
16
|
+
return nsPrefix(ns, "http://www.omg.org/spec/BPMN/20100524/DI") ?? "bpmndi";
|
|
17
|
+
}
|
|
18
|
+
function dcPrefix(ns) {
|
|
19
|
+
return nsPrefix(ns, "http://www.omg.org/spec/DD/20100524/DC") ?? "dc";
|
|
20
|
+
}
|
|
21
|
+
function diPrefix(ns) {
|
|
22
|
+
return nsPrefix(ns, "http://www.omg.org/spec/DD/20100524/DI") ?? "di";
|
|
23
|
+
}
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Helpers
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
function el(name, attributes, children, text) {
|
|
28
|
+
return { name, attributes, children, text };
|
|
29
|
+
}
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Event definitions
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
function serializeEventDefinitions(defs, bp) {
|
|
34
|
+
return defs.map((d) => {
|
|
35
|
+
switch (d.type) {
|
|
36
|
+
case "timer": {
|
|
37
|
+
const children = [];
|
|
38
|
+
if (d.timeDuration !== undefined) {
|
|
39
|
+
children.push(el(`${bp}:timeDuration`, d.timeDurationAttributes ?? {}, [], d.timeDuration));
|
|
40
|
+
}
|
|
41
|
+
if (d.timeDate !== undefined) {
|
|
42
|
+
children.push(el(`${bp}:timeDate`, d.timeDateAttributes ?? {}, [], d.timeDate));
|
|
43
|
+
}
|
|
44
|
+
if (d.timeCycle !== undefined) {
|
|
45
|
+
children.push(el(`${bp}:timeCycle`, d.timeCycleAttributes ?? {}, [], d.timeCycle));
|
|
46
|
+
}
|
|
47
|
+
return el(`${bp}:timerEventDefinition`, d.id ? { id: d.id } : {}, children);
|
|
48
|
+
}
|
|
49
|
+
case "error": {
|
|
50
|
+
const attrs = {};
|
|
51
|
+
if (d.id)
|
|
52
|
+
attrs.id = d.id;
|
|
53
|
+
if (d.errorRef)
|
|
54
|
+
attrs.errorRef = d.errorRef;
|
|
55
|
+
return el(`${bp}:errorEventDefinition`, attrs, []);
|
|
56
|
+
}
|
|
57
|
+
case "escalation": {
|
|
58
|
+
const attrs = {};
|
|
59
|
+
if (d.id)
|
|
60
|
+
attrs.id = d.id;
|
|
61
|
+
if (d.escalationRef)
|
|
62
|
+
attrs.escalationRef = d.escalationRef;
|
|
63
|
+
return el(`${bp}:escalationEventDefinition`, attrs, []);
|
|
64
|
+
}
|
|
65
|
+
case "message": {
|
|
66
|
+
const attrs = {};
|
|
67
|
+
if (d.id)
|
|
68
|
+
attrs.id = d.id;
|
|
69
|
+
if (d.messageRef)
|
|
70
|
+
attrs.messageRef = d.messageRef;
|
|
71
|
+
return el(`${bp}:messageEventDefinition`, attrs, []);
|
|
72
|
+
}
|
|
73
|
+
case "signal": {
|
|
74
|
+
const attrs = {};
|
|
75
|
+
if (d.id)
|
|
76
|
+
attrs.id = d.id;
|
|
77
|
+
if (d.signalRef)
|
|
78
|
+
attrs.signalRef = d.signalRef;
|
|
79
|
+
return el(`${bp}:signalEventDefinition`, attrs, []);
|
|
80
|
+
}
|
|
81
|
+
case "conditional": {
|
|
82
|
+
const attrs = {};
|
|
83
|
+
if (d.id)
|
|
84
|
+
attrs.id = d.id;
|
|
85
|
+
const condChildren = [];
|
|
86
|
+
if (d.condition !== undefined) {
|
|
87
|
+
condChildren.push(el(`${bp}:condition`, {}, [], d.condition));
|
|
88
|
+
}
|
|
89
|
+
return el(`${bp}:conditionalEventDefinition`, attrs, condChildren);
|
|
90
|
+
}
|
|
91
|
+
case "link": {
|
|
92
|
+
const attrs = {};
|
|
93
|
+
if (d.id)
|
|
94
|
+
attrs.id = d.id;
|
|
95
|
+
if (d.name)
|
|
96
|
+
attrs.name = d.name;
|
|
97
|
+
return el(`${bp}:linkEventDefinition`, attrs, []);
|
|
98
|
+
}
|
|
99
|
+
case "cancel": {
|
|
100
|
+
const attrs = {};
|
|
101
|
+
if (d.id)
|
|
102
|
+
attrs.id = d.id;
|
|
103
|
+
return el(`${bp}:cancelEventDefinition`, attrs, []);
|
|
104
|
+
}
|
|
105
|
+
case "terminate": {
|
|
106
|
+
const attrs = {};
|
|
107
|
+
if (d.id)
|
|
108
|
+
attrs.id = d.id;
|
|
109
|
+
return el(`${bp}:terminateEventDefinition`, attrs, []);
|
|
110
|
+
}
|
|
111
|
+
case "compensate": {
|
|
112
|
+
const attrs = {};
|
|
113
|
+
if (d.id)
|
|
114
|
+
attrs.id = d.id;
|
|
115
|
+
if (d.activityRef)
|
|
116
|
+
attrs.activityRef = d.activityRef;
|
|
117
|
+
return el(`${bp}:compensateEventDefinition`, attrs, []);
|
|
118
|
+
}
|
|
119
|
+
default: {
|
|
120
|
+
const _exhaustive = d;
|
|
121
|
+
throw new Error(`Unknown event definition type: ${_exhaustive.type}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Extension elements
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
function serializeExtensionElements(extensions, bp) {
|
|
130
|
+
if (extensions.length === 0)
|
|
131
|
+
return [];
|
|
132
|
+
return [el(`${bp}:extensionElements`, {}, extensions)];
|
|
133
|
+
}
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Multi-instance loop
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
function serializeLoopCharacteristics(lc, bp) {
|
|
138
|
+
if (!lc)
|
|
139
|
+
return [];
|
|
140
|
+
return [
|
|
141
|
+
el(`${bp}:multiInstanceLoopCharacteristics`, {}, [
|
|
142
|
+
...serializeExtensionElements(lc.extensionElements, bp),
|
|
143
|
+
]),
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
// Flow elements
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
function flowRefs(refs, tag, bp) {
|
|
150
|
+
return refs.map((r) => el(`${bp}:${tag}`, {}, [], r));
|
|
151
|
+
}
|
|
152
|
+
function serializeFlowElement(fe, ns) {
|
|
153
|
+
const bp = bpmnPrefix(ns);
|
|
154
|
+
const attrs = { id: fe.id, ...fe.unknownAttributes };
|
|
155
|
+
if (fe.name !== undefined)
|
|
156
|
+
attrs.name = fe.name;
|
|
157
|
+
const children = [];
|
|
158
|
+
// Documentation
|
|
159
|
+
if (fe.documentation !== undefined) {
|
|
160
|
+
children.push(el(`${bp}:documentation`, {}, [], fe.documentation));
|
|
161
|
+
}
|
|
162
|
+
// Extension elements
|
|
163
|
+
children.push(...serializeExtensionElements(fe.extensionElements, bp));
|
|
164
|
+
// Incoming / outgoing
|
|
165
|
+
children.push(...flowRefs(fe.incoming, "incoming", bp));
|
|
166
|
+
children.push(...flowRefs(fe.outgoing, "outgoing", bp));
|
|
167
|
+
switch (fe.type) {
|
|
168
|
+
case "startEvent":
|
|
169
|
+
case "endEvent":
|
|
170
|
+
case "intermediateCatchEvent":
|
|
171
|
+
case "intermediateThrowEvent":
|
|
172
|
+
children.push(...serializeEventDefinitions(fe.eventDefinitions, bp));
|
|
173
|
+
break;
|
|
174
|
+
case "boundaryEvent":
|
|
175
|
+
attrs.attachedToRef = fe.attachedToRef;
|
|
176
|
+
if (fe.cancelActivity !== undefined)
|
|
177
|
+
attrs.cancelActivity = String(fe.cancelActivity);
|
|
178
|
+
children.push(...serializeEventDefinitions(fe.eventDefinitions, bp));
|
|
179
|
+
break;
|
|
180
|
+
case "task":
|
|
181
|
+
case "serviceTask":
|
|
182
|
+
case "scriptTask":
|
|
183
|
+
case "userTask":
|
|
184
|
+
case "sendTask":
|
|
185
|
+
case "receiveTask":
|
|
186
|
+
case "businessRuleTask":
|
|
187
|
+
case "manualTask":
|
|
188
|
+
case "callActivity":
|
|
189
|
+
children.push(...serializeLoopCharacteristics(fe.loopCharacteristics, bp));
|
|
190
|
+
break;
|
|
191
|
+
case "adHocSubProcess":
|
|
192
|
+
children.push(...serializeLoopCharacteristics(fe.loopCharacteristics, bp));
|
|
193
|
+
children.push(...serializeProcessContents(fe, ns));
|
|
194
|
+
break;
|
|
195
|
+
case "subProcess":
|
|
196
|
+
if (fe.triggeredByEvent !== undefined)
|
|
197
|
+
attrs.triggeredByEvent = String(fe.triggeredByEvent);
|
|
198
|
+
children.push(...serializeLoopCharacteristics(fe.loopCharacteristics, bp));
|
|
199
|
+
children.push(...serializeProcessContents(fe, ns));
|
|
200
|
+
break;
|
|
201
|
+
case "eventSubProcess":
|
|
202
|
+
children.push(...serializeProcessContents(fe, ns));
|
|
203
|
+
break;
|
|
204
|
+
case "transaction":
|
|
205
|
+
children.push(...serializeLoopCharacteristics(fe.loopCharacteristics, bp));
|
|
206
|
+
children.push(...serializeProcessContents(fe, ns));
|
|
207
|
+
break;
|
|
208
|
+
case "exclusiveGateway":
|
|
209
|
+
if (fe.default !== undefined)
|
|
210
|
+
attrs.default = fe.default;
|
|
211
|
+
break;
|
|
212
|
+
case "inclusiveGateway":
|
|
213
|
+
if (fe.default !== undefined)
|
|
214
|
+
attrs.default = fe.default;
|
|
215
|
+
break;
|
|
216
|
+
case "complexGateway":
|
|
217
|
+
if (fe.default !== undefined)
|
|
218
|
+
attrs.default = fe.default;
|
|
219
|
+
break;
|
|
220
|
+
case "parallelGateway":
|
|
221
|
+
case "eventBasedGateway":
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
return el(`${bp}:${fe.type}`, attrs, children);
|
|
225
|
+
}
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// Sequence flows
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
function serializeSequenceFlow(sf, bp) {
|
|
230
|
+
const attrs = {
|
|
231
|
+
id: sf.id,
|
|
232
|
+
sourceRef: sf.sourceRef,
|
|
233
|
+
targetRef: sf.targetRef,
|
|
234
|
+
...sf.unknownAttributes,
|
|
235
|
+
};
|
|
236
|
+
if (sf.name !== undefined)
|
|
237
|
+
attrs.name = sf.name;
|
|
238
|
+
const children = [];
|
|
239
|
+
children.push(...serializeExtensionElements(sf.extensionElements, bp));
|
|
240
|
+
if (sf.conditionExpression) {
|
|
241
|
+
children.push(el(`${bp}:conditionExpression`, sf.conditionExpression.attributes, [], sf.conditionExpression.text));
|
|
242
|
+
}
|
|
243
|
+
return el(`${bp}:sequenceFlow`, attrs, children);
|
|
244
|
+
}
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// Annotations
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
function serializeTextAnnotation(ta, bp) {
|
|
249
|
+
const children = [];
|
|
250
|
+
if (ta.text !== undefined) {
|
|
251
|
+
children.push(el(`${bp}:text`, {}, [], ta.text));
|
|
252
|
+
}
|
|
253
|
+
return el(`${bp}:textAnnotation`, { id: ta.id, ...ta.unknownAttributes }, children);
|
|
254
|
+
}
|
|
255
|
+
function serializeAssociation(a, bp) {
|
|
256
|
+
const attrs = {
|
|
257
|
+
id: a.id,
|
|
258
|
+
sourceRef: a.sourceRef,
|
|
259
|
+
targetRef: a.targetRef,
|
|
260
|
+
...a.unknownAttributes,
|
|
261
|
+
};
|
|
262
|
+
if (a.associationDirection !== undefined)
|
|
263
|
+
attrs.associationDirection = a.associationDirection;
|
|
264
|
+
return el(`${bp}:association`, attrs, []);
|
|
265
|
+
}
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
// Process contents
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
function serializeProcessContents(p, ns) {
|
|
270
|
+
const bp = bpmnPrefix(ns);
|
|
271
|
+
const children = [];
|
|
272
|
+
for (const fe of p.flowElements) {
|
|
273
|
+
children.push(serializeFlowElement(fe, ns));
|
|
274
|
+
}
|
|
275
|
+
for (const sf of p.sequenceFlows) {
|
|
276
|
+
children.push(serializeSequenceFlow(sf, bp));
|
|
277
|
+
}
|
|
278
|
+
for (const ta of p.textAnnotations) {
|
|
279
|
+
children.push(serializeTextAnnotation(ta, bp));
|
|
280
|
+
}
|
|
281
|
+
for (const a of p.associations) {
|
|
282
|
+
children.push(serializeAssociation(a, bp));
|
|
283
|
+
}
|
|
284
|
+
return children;
|
|
285
|
+
}
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
// Lanes
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
function serializeLane(lane, bp) {
|
|
290
|
+
const attrs = { id: lane.id, ...lane.unknownAttributes };
|
|
291
|
+
if (lane.name !== undefined)
|
|
292
|
+
attrs.name = lane.name;
|
|
293
|
+
const children = lane.flowNodeRefs.map((ref) => el(`${bp}:flowNodeRef`, {}, [], ref));
|
|
294
|
+
if (lane.childLaneSet) {
|
|
295
|
+
children.push(serializeLaneSet(lane.childLaneSet, bp));
|
|
296
|
+
}
|
|
297
|
+
return el(`${bp}:lane`, attrs, children);
|
|
298
|
+
}
|
|
299
|
+
function serializeLaneSet(laneSet, bp) {
|
|
300
|
+
const attrs = {};
|
|
301
|
+
if (laneSet.id)
|
|
302
|
+
attrs.id = laneSet.id;
|
|
303
|
+
return el(`${bp}:laneSet`, attrs, laneSet.lanes.map((l) => serializeLane(l, bp)));
|
|
304
|
+
}
|
|
305
|
+
// ---------------------------------------------------------------------------
|
|
306
|
+
// Process
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
function serializeProcess(process, ns) {
|
|
309
|
+
const bp = bpmnPrefix(ns);
|
|
310
|
+
const attrs = { id: process.id, ...process.unknownAttributes };
|
|
311
|
+
if (process.name !== undefined)
|
|
312
|
+
attrs.name = process.name;
|
|
313
|
+
if (process.isExecutable)
|
|
314
|
+
attrs.isExecutable = "true";
|
|
315
|
+
const children = [];
|
|
316
|
+
children.push(...serializeExtensionElements(process.extensionElements, bp));
|
|
317
|
+
if (process.laneSet) {
|
|
318
|
+
children.push(serializeLaneSet(process.laneSet, bp));
|
|
319
|
+
}
|
|
320
|
+
children.push(...serializeProcessContents(process, ns));
|
|
321
|
+
return el(`${bp}:process`, attrs, children);
|
|
322
|
+
}
|
|
323
|
+
// ---------------------------------------------------------------------------
|
|
324
|
+
// Collaboration
|
|
325
|
+
// ---------------------------------------------------------------------------
|
|
326
|
+
function serializeParticipant(p, bp) {
|
|
327
|
+
const attrs = { id: p.id, ...p.unknownAttributes };
|
|
328
|
+
if (p.name !== undefined)
|
|
329
|
+
attrs.name = p.name;
|
|
330
|
+
if (p.processRef !== undefined)
|
|
331
|
+
attrs.processRef = p.processRef;
|
|
332
|
+
return el(`${bp}:participant`, attrs, []);
|
|
333
|
+
}
|
|
334
|
+
function serializeMessageFlow(mf, bp) {
|
|
335
|
+
const attrs = {
|
|
336
|
+
id: mf.id,
|
|
337
|
+
sourceRef: mf.sourceRef,
|
|
338
|
+
targetRef: mf.targetRef,
|
|
339
|
+
...mf.unknownAttributes,
|
|
340
|
+
};
|
|
341
|
+
if (mf.name !== undefined)
|
|
342
|
+
attrs.name = mf.name;
|
|
343
|
+
return el(`${bp}:messageFlow`, attrs, []);
|
|
344
|
+
}
|
|
345
|
+
function serializeCollaboration(c, ns) {
|
|
346
|
+
const bp = bpmnPrefix(ns);
|
|
347
|
+
const children = [];
|
|
348
|
+
for (const p of c.participants) {
|
|
349
|
+
children.push(serializeParticipant(p, bp));
|
|
350
|
+
}
|
|
351
|
+
for (const mf of c.messageFlows) {
|
|
352
|
+
children.push(serializeMessageFlow(mf, bp));
|
|
353
|
+
}
|
|
354
|
+
for (const ta of c.textAnnotations) {
|
|
355
|
+
children.push(serializeTextAnnotation(ta, bp));
|
|
356
|
+
}
|
|
357
|
+
for (const a of c.associations) {
|
|
358
|
+
children.push(serializeAssociation(a, bp));
|
|
359
|
+
}
|
|
360
|
+
return el(`${bp}:collaboration`, { id: c.id, ...c.unknownAttributes }, children);
|
|
361
|
+
}
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// Root elements
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
function serializeError(e, bp) {
|
|
366
|
+
const attrs = { id: e.id };
|
|
367
|
+
if (e.name !== undefined)
|
|
368
|
+
attrs.name = e.name;
|
|
369
|
+
if (e.errorCode !== undefined)
|
|
370
|
+
attrs.errorCode = e.errorCode;
|
|
371
|
+
return el(`${bp}:error`, attrs, []);
|
|
372
|
+
}
|
|
373
|
+
function serializeEscalation(e, bp) {
|
|
374
|
+
const attrs = { id: e.id };
|
|
375
|
+
if (e.name !== undefined)
|
|
376
|
+
attrs.name = e.name;
|
|
377
|
+
if (e.escalationCode !== undefined)
|
|
378
|
+
attrs.escalationCode = e.escalationCode;
|
|
379
|
+
return el(`${bp}:escalation`, attrs, []);
|
|
380
|
+
}
|
|
381
|
+
function serializeMessage(m, bp) {
|
|
382
|
+
const attrs = { id: m.id, ...m.unknownAttributes };
|
|
383
|
+
if (m.name !== undefined)
|
|
384
|
+
attrs.name = m.name;
|
|
385
|
+
return el(`${bp}:message`, attrs, []);
|
|
386
|
+
}
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
// Diagram interchange
|
|
389
|
+
// ---------------------------------------------------------------------------
|
|
390
|
+
function serializeDiShape(shape, bdi, dc) {
|
|
391
|
+
const attrs = {
|
|
392
|
+
id: shape.id,
|
|
393
|
+
bpmnElement: shape.bpmnElement,
|
|
394
|
+
...shape.unknownAttributes,
|
|
395
|
+
};
|
|
396
|
+
if (shape.isMarkerVisible !== undefined)
|
|
397
|
+
attrs.isMarkerVisible = String(shape.isMarkerVisible);
|
|
398
|
+
if (shape.isExpanded !== undefined)
|
|
399
|
+
attrs.isExpanded = String(shape.isExpanded);
|
|
400
|
+
if (shape.isHorizontal !== undefined)
|
|
401
|
+
attrs.isHorizontal = String(shape.isHorizontal);
|
|
402
|
+
const children = [
|
|
403
|
+
el(`${dc}:Bounds`, {
|
|
404
|
+
x: String(shape.bounds.x),
|
|
405
|
+
y: String(shape.bounds.y),
|
|
406
|
+
width: String(shape.bounds.width),
|
|
407
|
+
height: String(shape.bounds.height),
|
|
408
|
+
}, []),
|
|
409
|
+
];
|
|
410
|
+
if (shape.label) {
|
|
411
|
+
const labelChildren = [];
|
|
412
|
+
if (shape.label.bounds) {
|
|
413
|
+
labelChildren.push(el(`${dc}:Bounds`, {
|
|
414
|
+
x: String(shape.label.bounds.x),
|
|
415
|
+
y: String(shape.label.bounds.y),
|
|
416
|
+
width: String(shape.label.bounds.width),
|
|
417
|
+
height: String(shape.label.bounds.height),
|
|
418
|
+
}, []));
|
|
419
|
+
}
|
|
420
|
+
children.push(el(`${bdi}:BPMNLabel`, {}, labelChildren));
|
|
421
|
+
}
|
|
422
|
+
return el(`${bdi}:BPMNShape`, attrs, children);
|
|
423
|
+
}
|
|
424
|
+
function serializeDiEdge(edge, bdi, dc, dip) {
|
|
425
|
+
const attrs = {
|
|
426
|
+
id: edge.id,
|
|
427
|
+
bpmnElement: edge.bpmnElement,
|
|
428
|
+
...edge.unknownAttributes,
|
|
429
|
+
};
|
|
430
|
+
const children = edge.waypoints.map((w) => el(`${dip}:waypoint`, { x: String(w.x), y: String(w.y) }, []));
|
|
431
|
+
if (edge.label) {
|
|
432
|
+
const labelChildren = [];
|
|
433
|
+
if (edge.label.bounds) {
|
|
434
|
+
labelChildren.push(el(`${dc}:Bounds`, {
|
|
435
|
+
x: String(edge.label.bounds.x),
|
|
436
|
+
y: String(edge.label.bounds.y),
|
|
437
|
+
width: String(edge.label.bounds.width),
|
|
438
|
+
height: String(edge.label.bounds.height),
|
|
439
|
+
}, []));
|
|
440
|
+
}
|
|
441
|
+
children.push(el(`${bdi}:BPMNLabel`, {}, labelChildren));
|
|
442
|
+
}
|
|
443
|
+
return el(`${bdi}:BPMNEdge`, attrs, children);
|
|
444
|
+
}
|
|
445
|
+
function serializeDiagram(diagram, ns) {
|
|
446
|
+
const bdi = bpmndiPrefix(ns);
|
|
447
|
+
const dc = dcPrefix(ns);
|
|
448
|
+
const dip = diPrefix(ns);
|
|
449
|
+
const planeChildren = [];
|
|
450
|
+
for (const s of diagram.plane.shapes) {
|
|
451
|
+
planeChildren.push(serializeDiShape(s, bdi, dc));
|
|
452
|
+
}
|
|
453
|
+
for (const e of diagram.plane.edges) {
|
|
454
|
+
planeChildren.push(serializeDiEdge(e, bdi, dc, dip));
|
|
455
|
+
}
|
|
456
|
+
const plane = el(`${bdi}:BPMNPlane`, {
|
|
457
|
+
id: diagram.plane.id,
|
|
458
|
+
bpmnElement: diagram.plane.bpmnElement,
|
|
459
|
+
}, planeChildren);
|
|
460
|
+
return el(`${bdi}:BPMNDiagram`, { id: diagram.id }, [plane]);
|
|
461
|
+
}
|
|
462
|
+
// ---------------------------------------------------------------------------
|
|
463
|
+
// Public API
|
|
464
|
+
// ---------------------------------------------------------------------------
|
|
465
|
+
/** Serialize a BpmnDefinitions model to a BPMN XML string. */
|
|
466
|
+
export function serializeBpmn(definitions) {
|
|
467
|
+
const ns = definitions.namespaces;
|
|
468
|
+
const bp = bpmnPrefix(ns);
|
|
469
|
+
const attrs = {};
|
|
470
|
+
// Namespace declarations
|
|
471
|
+
for (const [prefix, uri] of Object.entries(ns)) {
|
|
472
|
+
if (prefix === "") {
|
|
473
|
+
attrs.xmlns = uri;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
attrs[`xmlns:${prefix}`] = uri;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
attrs.id = definitions.id;
|
|
480
|
+
attrs.targetNamespace = definitions.targetNamespace;
|
|
481
|
+
if (definitions.exporter !== undefined)
|
|
482
|
+
attrs.exporter = definitions.exporter;
|
|
483
|
+
if (definitions.exporterVersion !== undefined)
|
|
484
|
+
attrs.exporterVersion = definitions.exporterVersion;
|
|
485
|
+
// Unknown attributes (modeler:*, camunda:*, etc.)
|
|
486
|
+
for (const [key, value] of Object.entries(definitions.unknownAttributes)) {
|
|
487
|
+
attrs[key] = value;
|
|
488
|
+
}
|
|
489
|
+
const children = [];
|
|
490
|
+
// Root elements: errors, escalations, messages first
|
|
491
|
+
for (const e of definitions.escalations) {
|
|
492
|
+
children.push(serializeEscalation(e, bp));
|
|
493
|
+
}
|
|
494
|
+
for (const e of definitions.errors) {
|
|
495
|
+
children.push(serializeError(e, bp));
|
|
496
|
+
}
|
|
497
|
+
for (const m of definitions.messages) {
|
|
498
|
+
children.push(serializeMessage(m, bp));
|
|
499
|
+
}
|
|
500
|
+
// Collaborations
|
|
501
|
+
for (const c of definitions.collaborations) {
|
|
502
|
+
children.push(serializeCollaboration(c, ns));
|
|
503
|
+
}
|
|
504
|
+
// Processes
|
|
505
|
+
for (const p of definitions.processes) {
|
|
506
|
+
children.push(serializeProcess(p, ns));
|
|
507
|
+
}
|
|
508
|
+
// Diagrams
|
|
509
|
+
for (const d of definitions.diagrams) {
|
|
510
|
+
children.push(serializeDiagram(d, ns));
|
|
511
|
+
}
|
|
512
|
+
const root = el(`${bp}:definitions`, attrs, children);
|
|
513
|
+
return serializeXml(root);
|
|
514
|
+
}
|
|
515
|
+
//# sourceMappingURL=bpmn-serializer.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { BpmnDefinitions, BpmnElementType } from "./bpmn-model.js";
|
|
2
|
+
/** A single BPMN flow node in compact form. */
|
|
3
|
+
export interface CompactElement {
|
|
4
|
+
id: string;
|
|
5
|
+
type: BpmnElementType;
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Zeebe job type (serviceTask: zeebe:taskDefinition.type) */
|
|
8
|
+
jobType?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Zeebe task headers (key→value).
|
|
11
|
+
* For the Camunda HTTP connector use jobType "io.camunda:http-json:1" and set:
|
|
12
|
+
* url, method, and optionally headers/body/connectionTimeoutInSeconds.
|
|
13
|
+
*/
|
|
14
|
+
taskHeaders?: Record<string, string>;
|
|
15
|
+
/** Called process ID (callActivity: zeebe:calledElement.processId) */
|
|
16
|
+
calledProcess?: string;
|
|
17
|
+
/** Linked form ID (userTask: zeebe:formDefinition.formId) */
|
|
18
|
+
formId?: string;
|
|
19
|
+
/** Linked decision ID (businessRuleTask: zeebe:calledDecision.decisionId) */
|
|
20
|
+
decisionId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Primary output variable.
|
|
23
|
+
* - For businessRuleTask: stored in zeebe:calledDecision.resultVariable.
|
|
24
|
+
* - For serviceTask with jobType: stored as a zeebe:ioMapping output (source "= response").
|
|
25
|
+
*/
|
|
26
|
+
resultVariable?: string;
|
|
27
|
+
/** Event definition type (timer, error, message, signal, …) */
|
|
28
|
+
eventType?: string;
|
|
29
|
+
/** Boundary event: host element ID */
|
|
30
|
+
attachedTo?: string;
|
|
31
|
+
/** Boundary event: false = non-interrupting */
|
|
32
|
+
interrupting?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** A sequence flow in compact form. */
|
|
35
|
+
export interface CompactFlow {
|
|
36
|
+
id: string;
|
|
37
|
+
from: string;
|
|
38
|
+
to: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
/** FEEL condition expression */
|
|
41
|
+
condition?: string;
|
|
42
|
+
}
|
|
43
|
+
/** A single process in compact form. */
|
|
44
|
+
export interface CompactProcess {
|
|
45
|
+
id: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
elements: CompactElement[];
|
|
48
|
+
flows: CompactFlow[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Token-efficient representation of a {@link BpmnDefinitions} document.
|
|
52
|
+
* Produced by {@link compactify}; restored to full form by {@link expand}.
|
|
53
|
+
*/
|
|
54
|
+
export interface CompactDiagram {
|
|
55
|
+
id: string;
|
|
56
|
+
processes: CompactProcess[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Converts a {@link BpmnDefinitions} model into a token-efficient
|
|
60
|
+
* {@link CompactDiagram} representation suitable for AI contexts (LLM prompts,
|
|
61
|
+
* MCP tool calls, etc.). The compact format is typically 5–15× smaller than
|
|
62
|
+
* raw BPMN XML.
|
|
63
|
+
*
|
|
64
|
+
* Use {@link expand} to restore a compact diagram back to a full model with
|
|
65
|
+
* auto-generated layout.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { Bpmn, compactify, expand } from "@bpmnkit/core"
|
|
70
|
+
*
|
|
71
|
+
* const defs = Bpmn.parse(xml)
|
|
72
|
+
* const compact = compactify(defs) // send to AI
|
|
73
|
+
* const restored = expand(compact) // get back BpmnDefinitions
|
|
74
|
+
* const xml2 = Bpmn.export(restored)
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function compactify(defs: BpmnDefinitions): CompactDiagram;
|
|
78
|
+
/**
|
|
79
|
+
* Restores a {@link CompactDiagram} (produced by {@link compactify} or an AI
|
|
80
|
+
* model) back to a full {@link BpmnDefinitions} with auto-generated layout.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const compact = await askAI(prompt) // AI returns CompactDiagram JSON
|
|
85
|
+
* const defs = expand(compact)
|
|
86
|
+
* const xml = Bpmn.export(defs)
|
|
87
|
+
* editor.loadXml(xml)
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function expand(compact: CompactDiagram): BpmnDefinitions;
|
|
91
|
+
//# sourceMappingURL=compact.d.ts.map
|