@bpmnkit/core 0.0.23 → 0.0.25

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.
@@ -4,136 +4,9 @@ const POOL_HEADER = 30;
4
4
  const LANE_HEADER = 30;
5
5
  const PADDING = 20;
6
6
  const POOL_GAP = 30;
7
- const CHAIN_GAP = 30;
8
- const CHAIN_V_GAP = 20;
9
7
  const ANN_H = 50;
10
8
  const ANN_GAP = 60;
11
9
  const ANN_PADDING = 20;
12
- /**
13
- * Reposition boundary events to the bottom edge of their host task, then walk
14
- * each boundary event's exclusive downstream chain and place those nodes
15
- * horizontally to the right of the host task. Re-routes all affected edges.
16
- */
17
- function repositionBoundaryEvents(flowElements, result) {
18
- // Collect boundary events grouped by host task id
19
- const boundaryMap = new Map();
20
- for (const el of flowElements) {
21
- if (el.type !== "boundaryEvent")
22
- continue;
23
- const list = boundaryMap.get(el.attachedToRef) ?? [];
24
- list.push(el.id);
25
- boundaryMap.set(el.attachedToRef, list);
26
- }
27
- if (boundaryMap.size === 0)
28
- return;
29
- const nodeById = new Map(result.nodes.map((n) => [n.id, n]));
30
- // Build successor / predecessor maps from edges for chain walking
31
- const succIds = new Map();
32
- const predIds = new Map();
33
- for (const edge of result.edges) {
34
- const se = succIds.get(edge.sourceRef) ?? [];
35
- se.push(edge.targetRef);
36
- succIds.set(edge.sourceRef, se);
37
- const ps = predIds.get(edge.targetRef) ?? new Set();
38
- ps.add(edge.sourceRef);
39
- predIds.set(edge.targetRef, ps);
40
- }
41
- for (const [hostId, beIds] of boundaryMap) {
42
- const hostNode = nodeById.get(hostId);
43
- if (!hostNode)
44
- continue;
45
- for (let i = 0; i < beIds.length; i++) {
46
- const beId = beIds[i];
47
- if (!beId)
48
- continue;
49
- const beNode = nodeById.get(beId);
50
- if (!beNode)
51
- continue;
52
- const bW = beNode.bounds.width;
53
- const bH = beNode.bounds.height;
54
- // Place boundary event at bottom-right of host task, stacking leftward
55
- const rightEdge = hostNode.bounds.x + hostNode.bounds.width;
56
- beNode.bounds.x = Math.round(rightEdge - bW / 2 - i * (bW + 4));
57
- beNode.bounds.y = Math.round(hostNode.bounds.y + hostNode.bounds.height - bH / 2);
58
- if (beNode.labelBounds) {
59
- beNode.labelBounds.x = beNode.bounds.x + Math.round(bW / 2 - beNode.labelBounds.width / 2);
60
- beNode.labelBounds.y = beNode.bounds.y + bH + 4;
61
- }
62
- // Collect nodes exclusively reachable from this boundary event (in BFS order)
63
- const chainSet = new Set([beId]);
64
- const chainOrder = [];
65
- const queue = [...(succIds.get(beId) ?? [])];
66
- while (queue.length > 0) {
67
- const id = queue.shift();
68
- if (!id || chainSet.has(id))
69
- continue;
70
- // Include only if every predecessor is already in the chain
71
- const preds = predIds.get(id) ?? new Set();
72
- if ([...preds].every((p) => chainSet.has(p))) {
73
- chainSet.add(id);
74
- chainOrder.push(id);
75
- queue.push(...(succIds.get(id) ?? []));
76
- }
77
- }
78
- // Find tallest chain element to compute center Y below boundary event.
79
- // Each boundary event's chain gets its own vertical lane to avoid overlaps.
80
- let maxChainH = 0;
81
- for (const id of chainOrder) {
82
- const n = nodeById.get(id);
83
- if (n)
84
- maxChainH = Math.max(maxChainH, n.bounds.height);
85
- }
86
- const laneOffset = i * (maxChainH + CHAIN_V_GAP + 10);
87
- const chainCenterY = Math.round(beNode.bounds.y + bH + CHAIN_V_GAP + maxChainH / 2 + laneOffset);
88
- const chainStartX = Math.max(Math.round(beNode.bounds.x + bW / 2) + CHAIN_GAP, hostNode.bounds.x + hostNode.bounds.width + CHAIN_GAP);
89
- let curX = chainStartX;
90
- for (const id of chainOrder) {
91
- const n = nodeById.get(id);
92
- if (!n)
93
- continue;
94
- n.bounds.x = curX;
95
- n.bounds.y = chainCenterY - Math.round(n.bounds.height / 2);
96
- if (n.labelBounds) {
97
- n.labelBounds.x = n.bounds.x + Math.round(n.bounds.width / 2 - n.labelBounds.width / 2);
98
- n.labelBounds.y = n.bounds.y + n.bounds.height + 4;
99
- }
100
- curX += n.bounds.width + CHAIN_GAP;
101
- }
102
- // Re-route all edges touching the boundary event or its chain
103
- for (const edge of result.edges) {
104
- if (!chainSet.has(edge.sourceRef))
105
- continue;
106
- const src = nodeById.get(edge.sourceRef);
107
- const tgt = nodeById.get(edge.targetRef);
108
- if (!src || !tgt)
109
- continue;
110
- if (edge.sourceRef === beId) {
111
- // Boundary event → first chain node: route down then right
112
- const srcX = Math.round(src.bounds.x + bW / 2);
113
- const srcY = Math.round(src.bounds.y + bH);
114
- const tgtX = Math.round(tgt.bounds.x);
115
- const tgtY = Math.round(tgt.bounds.y + tgt.bounds.height / 2);
116
- edge.waypoints = [
117
- { x: srcX, y: srcY },
118
- { x: srcX, y: tgtY },
119
- { x: tgtX, y: tgtY },
120
- ];
121
- }
122
- else {
123
- // Within chain: straight horizontal edge
124
- const srcX = Math.round(src.bounds.x + src.bounds.width);
125
- const srcY = Math.round(src.bounds.y + src.bounds.height / 2);
126
- const tgtX = Math.round(tgt.bounds.x);
127
- const tgtY = Math.round(tgt.bounds.y + tgt.bounds.height / 2);
128
- edge.waypoints = [
129
- { x: srcX, y: srcY },
130
- { x: tgtX, y: tgtY },
131
- ];
132
- }
133
- }
134
- }
135
- }
136
- }
137
10
  function contentBbox(nodes, extra) {
138
11
  let minX = Number.POSITIVE_INFINITY;
139
12
  let minY = Number.POSITIVE_INFINITY;
@@ -432,11 +305,8 @@ export function applyAutoLayout(defs) {
432
305
  const participantId = processToParticipant.get(process.id);
433
306
  const lanes = process.laneSet?.lanes ?? [];
434
307
  const hasLanes = lanes.length > 0;
308
+ // layoutProcess now handles boundary event repositioning internally.
435
309
  const result = layoutProcess(process);
436
- // Post-process boundary events: reposition each boundary event to the bottom
437
- // of its host task, then walk its exclusive downstream chain and reposition
438
- // those nodes horizontally to the right of the host task.
439
- repositionBoundaryEvents(process.flowElements, result);
440
310
  // Re-resolve edge crossings after boundary events moved shapes
441
311
  const nodeMap = new Map(result.nodes.map((n) => [n.id, n]));
442
312
  resolveEdgeCrossings(result.edges, nodeMap);
@@ -1,8 +1,9 @@
1
- import type { BpmnDefinitions, BpmnFlowElement, BpmnSequenceFlow } from "./bpmn-model.js";
1
+ import type { BpmnAssociation, BpmnDefinitions, BpmnError, BpmnEscalation, BpmnFlowElement, BpmnMessage, BpmnSequenceFlow, BpmnSignal, BpmnTextAnnotation } from "./bpmn-model.js";
2
2
  import type { RestConnectorConfig } from "./rest-connector.js";
3
3
  /** Options shared by all element methods. */
4
4
  export interface ElementOptions {
5
5
  name?: string;
6
+ isForCompensation?: boolean;
6
7
  }
7
8
  /** Options for creating a start event. */
8
9
  export interface StartEventOptions extends ElementOptions {
@@ -25,6 +26,11 @@ export interface StartEventOptions extends ElementOptions {
25
26
  modelerTemplateVersion?: string;
26
27
  /** Zeebe modeler template icon (data URI). */
27
28
  modelerTemplateIcon?: string;
29
+ /**
30
+ * Non-interrupting flag — only meaningful for start events inside event sub-processes.
31
+ * Pass `false` to emit `isInterrupting="false"`. Omit for the default interrupting behavior.
32
+ */
33
+ isInterrupting?: boolean;
28
34
  }
29
35
  /** Options for creating a service task. */
30
36
  export interface ServiceTaskOptions {
@@ -53,6 +59,8 @@ export interface ServiceTaskOptions {
53
59
  modelerTemplateVersion?: string;
54
60
  /** Zeebe modeler template icon (data URI). */
55
61
  modelerTemplateIcon?: string;
62
+ /** Mark this task as a compensation handler. */
63
+ isForCompensation?: boolean;
56
64
  }
57
65
  /** Options for creating a script task. */
58
66
  export interface ScriptTaskOptions {
@@ -62,6 +70,8 @@ export interface ScriptTaskOptions {
62
70
  expression: string;
63
71
  /** Variable name to store the result. */
64
72
  resultVariable: string;
73
+ /** Mark this task as a compensation handler. */
74
+ isForCompensation?: boolean;
65
75
  }
66
76
  /** Options for creating a user task. */
67
77
  export interface UserTaskOptions {
@@ -69,6 +79,10 @@ export interface UserTaskOptions {
69
79
  name?: string;
70
80
  /** Form key or form reference. */
71
81
  formId?: string;
82
+ /** Emit <zeebe:userTask /> to mark as a Camunda 8 native user task. */
83
+ zeebeUserTask?: boolean;
84
+ /** Mark this task as a compensation handler. */
85
+ isForCompensation?: boolean;
72
86
  }
73
87
  /** Options for creating a call activity. */
74
88
  export interface CallActivityOptions {
@@ -78,6 +92,8 @@ export interface CallActivityOptions {
78
92
  processId: string;
79
93
  /** Whether to propagate all child variables. */
80
94
  propagateAllChildVariables?: boolean;
95
+ /** Mark this activity as a compensation handler. */
96
+ isForCompensation?: boolean;
81
97
  }
82
98
  /** Options for creating a business rule task. */
83
99
  export interface BusinessRuleTaskOptions {
@@ -89,6 +105,8 @@ export interface BusinessRuleTaskOptions {
89
105
  decisionId?: string;
90
106
  /** Variable to store the result. */
91
107
  resultVariable?: string;
108
+ /** Mark this task as a compensation handler. */
109
+ isForCompensation?: boolean;
92
110
  }
93
111
  /** Options for gateway elements. */
94
112
  export interface GatewayOptions extends ElementOptions {
@@ -116,6 +134,23 @@ export interface IntermediateThrowEventOptions extends ElementOptions {
116
134
  signalName?: string;
117
135
  /** Escalation code — creates an escalation throw event (aspirational). */
118
136
  escalationCode?: string;
137
+ /** Emit a compensateEventDefinition. */
138
+ compensation?: boolean;
139
+ /** Activity to compensate (activityRef attribute on compensateEventDefinition). */
140
+ activityRef?: string;
141
+ }
142
+ /** Options for an end event. */
143
+ export interface EndEventOptions extends ElementOptions {
144
+ /** Error code — creates an error end event. */
145
+ errorCode?: string;
146
+ /** Error code — creates an error end event. Alias for errorCode. */
147
+ errorRef?: string;
148
+ /** Message name — creates a message end event. */
149
+ messageName?: string;
150
+ /** Signal name — creates a signal end event. */
151
+ signalName?: string;
152
+ /** Escalation code — creates an escalation end event. */
153
+ escalationCode?: string;
119
154
  }
120
155
  /** Options for a boundary event. */
121
156
  export interface BoundaryEventOptions extends ElementOptions {
@@ -125,7 +160,7 @@ export interface BoundaryEventOptions extends ElementOptions {
125
160
  cancelActivity?: boolean;
126
161
  /** Error code — creates an error boundary event. */
127
162
  errorCode?: string;
128
- /** Error reference ID. */
163
+ /** Error code — creates an error boundary event. Alias for errorCode. */
129
164
  errorRef?: string;
130
165
  /** Timer duration — creates a timer boundary event (aspirational). */
131
166
  timerDuration?: string;
@@ -137,6 +172,8 @@ export interface BoundaryEventOptions extends ElementOptions {
137
172
  messageName?: string;
138
173
  /** Signal name — creates a signal boundary event (aspirational). */
139
174
  signalName?: string;
175
+ /** Creates a compensation boundary event. */
176
+ compensation?: boolean;
140
177
  }
141
178
  /** Multi-instance loop configuration. */
142
179
  export interface MultiInstanceOptions {
@@ -212,7 +249,16 @@ export declare class BranchBuilder {
212
249
  /** @internal – true once connectTo() has been called, meaning the branch end is already wired */
213
250
  _connected: boolean;
214
251
  /** @internal */
215
- constructor(gatewayId: string, branchName: string);
252
+ readonly _textAnnotations: BpmnTextAnnotation[];
253
+ /** @internal */
254
+ readonly _associations: BpmnAssociation[];
255
+ private readonly _annCounters;
256
+ private readonly rootErrors;
257
+ private readonly rootMessages;
258
+ private readonly rootSignals;
259
+ private readonly rootEscalations;
260
+ /** @internal */
261
+ constructor(gatewayId: string, branchName: string, rootErrors?: BpmnError[], rootMessages?: BpmnMessage[], rootSignals?: BpmnSignal[], rootEscalations?: BpmnEscalation[]);
216
262
  /** Set a FEEL condition expression on this branch's outgoing sequence flow. */
217
263
  condition(expression: string): this;
218
264
  /** Mark this branch as the gateway's default (no-condition) flow. */
@@ -225,6 +271,10 @@ export declare class BranchBuilder {
225
271
  connectTo(targetId: string): this;
226
272
  /** @internal – ID of the last element added (or the gateway if branch is empty) */
227
273
  get _lastNodeId(): string;
274
+ /** Attach a text annotation to the element at the current cursor position. */
275
+ textAnnotation(text: string): this;
276
+ /** Attach a text annotation to an element by explicit ID. */
277
+ annotate(elementId: string, text: string): this;
228
278
  serviceTask(id: string, options: ServiceTaskOptions): this;
229
279
  userTask(id: string, options?: UserTaskOptions): this;
230
280
  scriptTask(id: string, options: ScriptTaskOptions): this;
@@ -232,8 +282,10 @@ export declare class BranchBuilder {
232
282
  receiveTask(id: string, options?: ElementOptions): this;
233
283
  businessRuleTask(id: string, options?: BusinessRuleTaskOptions): this;
234
284
  callActivity(id: string, options: CallActivityOptions): this;
285
+ /** Add an abstract task with no Zeebe extensions. */
286
+ task(id: string, options?: ElementOptions): this;
235
287
  startEvent(id?: string, options?: StartEventOptions): this;
236
- endEvent(id?: string, options?: ElementOptions): this;
288
+ endEvent(id?: string, options?: EndEventOptions): this;
237
289
  intermediateThrowEvent(id?: string, options?: IntermediateThrowEventOptions): this;
238
290
  intermediateCatchEvent(id?: string, options?: IntermediateCatchEventOptions): this;
239
291
  exclusiveGateway(id: string, options?: GatewayOptions): this;
@@ -247,16 +299,39 @@ export declare class SubProcessContentBuilder {
247
299
  readonly _elements: BpmnFlowElement[];
248
300
  /** @internal */
249
301
  readonly _flows: BpmnSequenceFlow[];
302
+ /** @internal */
303
+ readonly _textAnnotations: BpmnTextAnnotation[];
304
+ /** @internal */
305
+ readonly _associations: BpmnAssociation[];
306
+ private readonly _annCounters;
250
307
  private lastNodeId;
308
+ private currentGatewayId;
309
+ private openBranchEnds;
251
310
  private addElement;
252
311
  startEvent(id?: string, options?: StartEventOptions): this;
253
- endEvent(id?: string, options?: ElementOptions): this;
312
+ endEvent(id?: string, options?: EndEventOptions): this;
313
+ intermediateThrowEvent(id?: string, options?: IntermediateThrowEventOptions): this;
314
+ intermediateCatchEvent(id?: string, options?: IntermediateCatchEventOptions): this;
254
315
  serviceTask(id: string, options: ServiceTaskOptions): this;
255
- userTask(id: string, options?: UserTaskOptions): this;
256
316
  scriptTask(id: string, options: ScriptTaskOptions): this;
317
+ userTask(id: string, options?: UserTaskOptions): this;
318
+ businessRuleTask(id: string, options?: BusinessRuleTaskOptions): this;
257
319
  callActivity(id: string, options: CallActivityOptions): this;
258
- intermediateThrowEvent(id?: string, options?: IntermediateThrowEventOptions): this;
259
- intermediateCatchEvent(id?: string, options?: IntermediateCatchEventOptions): this;
320
+ sendTask(id: string, options?: ElementOptions): this;
321
+ receiveTask(id: string, options?: ElementOptions): this;
322
+ /** Add an abstract task with no Zeebe extensions. */
323
+ task(id: string, options?: ElementOptions): this;
324
+ exclusiveGateway(id: string, options?: GatewayOptions): this;
325
+ parallelGateway(id: string, options?: ElementOptions): this;
326
+ inclusiveGateway(id: string, options?: GatewayOptions): this;
327
+ eventBasedGateway(id: string, options?: ElementOptions): this;
328
+ /** Attach a text annotation to the element at the current cursor position. */
329
+ textAnnotation(text: string): this;
330
+ /** Attach a text annotation to an element by explicit ID. */
331
+ annotate(elementId: string, text: string): this;
332
+ branch(name: string, callback: (b: BranchBuilder) => void): this;
333
+ connectTo(targetId: string): this;
334
+ element(elementId: string): this;
260
335
  }
261
336
  /** Fluent builder for constructing BPMN processes. */
262
337
  export declare class ProcessBuilder {
@@ -268,13 +343,29 @@ export declare class ProcessBuilder {
268
343
  private readonly sequenceFlows;
269
344
  private readonly rootErrors;
270
345
  private readonly rootMessages;
346
+ private readonly rootSignals;
347
+ private readonly rootEscalations;
348
+ private readonly _textAnnotations;
349
+ private readonly _associations;
350
+ private readonly _annCounters;
271
351
  private lastNodeId;
272
352
  private currentGatewayId;
273
353
  private openBranchEnds;
274
354
  private _autoLayout;
355
+ private _executionPlatformVersion;
356
+ private _serviceTaskDefaults;
357
+ private _savedMainFlowId;
275
358
  constructor(processId: string);
276
359
  /** Enable auto-layout: `build()` will run the layout engine and populate diagram interchange data. */
277
360
  withAutoLayout(): this;
361
+ /** Set the Camunda execution platform version stamped into the BPMN definitions. Defaults to `"8.9.0"`. */
362
+ executionPlatformVersion(version: string): this;
363
+ /** Set process-wide defaults applied to subsequently added elements. */
364
+ defaults(options: {
365
+ serviceTask?: {
366
+ retries?: string;
367
+ };
368
+ }): this;
278
369
  /** Set the display name for this process. */
279
370
  name(name: string): this;
280
371
  /** Set whether this process is executable. */
@@ -291,8 +382,14 @@ export declare class ProcessBuilder {
291
382
  * is completely disconnected.
292
383
  */
293
384
  addStartEvent(id?: string, options?: StartEventOptions): this;
385
+ /**
386
+ * Alias for `addStartEvent()` — begins a new disconnected parallel path.
387
+ *
388
+ * Use this for readability when modeling processes with multiple independent paths.
389
+ */
390
+ disconnectedStartEvent(id?: string, options?: StartEventOptions): this;
294
391
  /** Add an end event. */
295
- endEvent(id?: string, options?: ElementOptions): this;
392
+ endEvent(id?: string, options?: EndEventOptions): this;
296
393
  /** Add an intermediate throw event (none, message, signal, escalation). */
297
394
  intermediateThrowEvent(id?: string, options?: IntermediateThrowEventOptions): this;
298
395
  /** Add an intermediate catch event (timer, message, signal). */
@@ -304,6 +401,15 @@ export declare class ProcessBuilder {
304
401
  * They start a new outgoing chain from the boundary event itself.
305
402
  */
306
403
  boundaryEvent(id: string, options: BoundaryEventOptions): this;
404
+ /**
405
+ * Attach a boundary event to the preceding task and build its outgoing path,
406
+ * then restore the builder cursor to the preceding task so the main flow continues.
407
+ *
408
+ * @param id - ID for the boundary event element.
409
+ * @param options - Boundary event options (without `attachedTo` — inferred from cursor).
410
+ * @param handler - Callback that chains elements from the boundary event.
411
+ */
412
+ withBoundary(id: string, options: Omit<BoundaryEventOptions, "attachedTo">, handler: (b: ProcessBuilder) => void): this;
307
413
  /** Add a service task with Zeebe task definition and optional IO mappings. */
308
414
  serviceTask(id: string, options: ServiceTaskOptions): this;
309
415
  /** Add a REST connector task — syntactic sugar over `serviceTask()`. */
@@ -320,6 +426,8 @@ export declare class ProcessBuilder {
320
426
  businessRuleTask(id: string, options?: BusinessRuleTaskOptions): this;
321
427
  /** Add a call activity referencing another process. */
322
428
  callActivity(id: string, options: CallActivityOptions): this;
429
+ /** Add an abstract task with no Zeebe extensions. */
430
+ task(id: string, options?: ElementOptions): this;
323
431
  /** Add an exclusive gateway (XOR split/join). */
324
432
  exclusiveGateway(id: string, options?: GatewayOptions): this;
325
433
  /** Add a parallel gateway (AND split/join). */
@@ -359,23 +467,38 @@ export declare class ProcessBuilder {
359
467
  adHocSubProcess(id: string, content: (b: SubProcessContentBuilder) => void, options?: AdHocSubProcessOptions): this;
360
468
  /** Add a sub-process (aspirational). */
361
469
  subProcess(id: string, content: (b: SubProcessContentBuilder) => void, options?: SubProcessOptions): this;
362
- /** Add an event sub-process (aspirational). */
470
+ /** Add an event sub-process. Triggered by its start event — no incoming or outgoing sequence flows. */
363
471
  eventSubProcess(id: string, content: (b: SubProcessContentBuilder) => void, options?: ElementOptions): this;
472
+ /** Attach a text annotation to the element at the current cursor position. */
473
+ textAnnotation(text: string): this;
474
+ /** Attach a text annotation to any flow element by explicit ID. */
475
+ annotate(elementId: string, text: string): this;
364
476
  /**
365
477
  * Build the complete BPMN definitions model.
366
478
  *
367
479
  * Resolves all forward-referenced `incoming` / `outgoing` arrays and wraps
368
480
  * the process in a {@link BpmnDefinitions} ready for XML serialization.
369
481
  */
370
- build(): BpmnDefinitions;
371
- private buildDiagram;
372
- /**
373
- * Insert matching join gateways where split-gateway branches converge
374
- * on a non-gateway target. BPMN best practice: every split has a join.
375
- */
376
- private insertJoinGateways;
377
- /** Trace backward from a node to find which split gateway it belongs to. */
378
- private traceBackToSplit;
482
+ build(options?: {
483
+ strict?: boolean;
484
+ }): BpmnDefinitions;
485
+ private validate;
379
486
  private addFlowElement;
380
487
  }
488
+ /**
489
+ * Builder for a complete BPMN definitions document containing one or more processes.
490
+ * Use `Bpmn.createDiagram(id?)` to obtain an instance.
491
+ */
492
+ export declare class DiagramBuilder {
493
+ private readonly _id;
494
+ private readonly _processes;
495
+ private readonly _errors;
496
+ private readonly _messages;
497
+ private _executionPlatformVersion;
498
+ constructor(id: string);
499
+ /** Set the Camunda execution platform version stamped into the BPMN definitions. Defaults to `"8.9.0"`. */
500
+ executionPlatformVersion(version: string): this;
501
+ process(id: string, callback: (b: ProcessBuilder) => void): this;
502
+ build(): BpmnDefinitions;
503
+ }
381
504
  //# sourceMappingURL=bpmn-builder.d.ts.map