@bpmnkit/core 0.3.0 → 0.4.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/dist/bpmn/bpmn-builder.d.ts +71 -0
- package/dist/bpmn/bpmn-builder.js +240 -106
- package/dist/bpmn/builder-coverage.d.ts +59 -0
- package/dist/bpmn/builder-coverage.js +62 -0
- package/dist/bpmn/compact.d.ts +6 -0
- package/dist/bpmn/compact.js +37 -2
- package/dist/bpmn/element-catalog.d.ts +31 -0
- package/dist/bpmn/element-catalog.js +50 -0
- package/dist/bpmn/element-shape.d.ts +49 -0
- package/dist/bpmn/element-shape.js +182 -0
- package/dist/bpmn/stable-ids.d.ts +30 -0
- package/dist/bpmn/stable-ids.js +134 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/layout/types.js +4 -0
- package/package.json +2 -1
package/dist/bpmn/compact.js
CHANGED
|
@@ -57,6 +57,15 @@ function compactifyElement(el) {
|
|
|
57
57
|
if (el.cancelActivity === false)
|
|
58
58
|
result.interrupting = false;
|
|
59
59
|
}
|
|
60
|
+
if (el.type === "dataObjectReference" && el.dataObjectRef !== undefined) {
|
|
61
|
+
result.dataObjectRef = el.dataObjectRef;
|
|
62
|
+
}
|
|
63
|
+
if (el.type === "dataStoreReference" && el.dataStoreRef !== undefined) {
|
|
64
|
+
result.dataStoreRef = el.dataStoreRef;
|
|
65
|
+
}
|
|
66
|
+
if ((el.type === "dataObject" || el.type === "dataObjectReference") && el.isCollection) {
|
|
67
|
+
result.isCollection = true;
|
|
68
|
+
}
|
|
60
69
|
// Recurse into sub-process container children
|
|
61
70
|
if ("flowElements" in el && Array.isArray(el.flowElements) && el.flowElements.length > 0) {
|
|
62
71
|
const seqFlows = "sequenceFlows" in el && Array.isArray(el.sequenceFlows) ? el.sequenceFlows : [];
|
|
@@ -291,8 +300,34 @@ export function buildFlowElement(el, incoming, outgoing) {
|
|
|
291
300
|
return { ...base, type: "eventBasedGateway" };
|
|
292
301
|
case "complexGateway":
|
|
293
302
|
return { ...base, type: "complexGateway" };
|
|
294
|
-
|
|
295
|
-
|
|
303
|
+
// Data elements are not sequence-flow participants; they carry a
|
|
304
|
+
// reference instead, and dropping that reference is what made them
|
|
305
|
+
// round-trip as bare tasks before.
|
|
306
|
+
case "dataObject":
|
|
307
|
+
return {
|
|
308
|
+
...base,
|
|
309
|
+
type: "dataObject",
|
|
310
|
+
...(el.isCollection !== undefined ? { isCollection: el.isCollection } : {}),
|
|
311
|
+
};
|
|
312
|
+
case "dataObjectReference":
|
|
313
|
+
return {
|
|
314
|
+
...base,
|
|
315
|
+
type: "dataObjectReference",
|
|
316
|
+
...(el.dataObjectRef !== undefined ? { dataObjectRef: el.dataObjectRef } : {}),
|
|
317
|
+
...(el.isCollection !== undefined ? { isCollection: el.isCollection } : {}),
|
|
318
|
+
};
|
|
319
|
+
case "dataStoreReference":
|
|
320
|
+
return {
|
|
321
|
+
...base,
|
|
322
|
+
type: "dataStoreReference",
|
|
323
|
+
...(el.dataStoreRef !== undefined ? { dataStoreRef: el.dataStoreRef } : {}),
|
|
324
|
+
};
|
|
325
|
+
default: {
|
|
326
|
+
// Exhaustive: a new BpmnElementType fails here rather than silently
|
|
327
|
+
// expanding to a task, which is how the data types were lost.
|
|
328
|
+
const unhandled = el.type;
|
|
329
|
+
throw new Error(`Unhandled BPMN element type in expand(): ${String(unhandled)}`);
|
|
330
|
+
}
|
|
296
331
|
}
|
|
297
332
|
}
|
|
298
333
|
function buildDiagram(processId, process) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every BPMN element type, grouped.
|
|
3
|
+
*
|
|
4
|
+
* Tool schemas, CLI help and prompts all want to say "here are the element
|
|
5
|
+
* types you can use", and each one used to say it as a hand-written string.
|
|
6
|
+
* Those strings drift: the MCP tool schema advertised 18 types while the
|
|
7
|
+
* compact path accepted 23, so five constructs — `receiveTask`, `task`,
|
|
8
|
+
* `complexGateway`, `transaction`, `eventSubProcess` — worked but no caller
|
|
9
|
+
* could discover them.
|
|
10
|
+
*
|
|
11
|
+
* This is the one list. Like `BUILDER_COVERAGE`, it is a total `Record` keyed
|
|
12
|
+
* by `BpmnElementType`, so **adding a member to that union fails `tsc` here
|
|
13
|
+
* until the new type is placed in a group** — and every generated description
|
|
14
|
+
* picks it up automatically.
|
|
15
|
+
*/
|
|
16
|
+
import type { BpmnElementType } from "./bpmn-model.js";
|
|
17
|
+
/** The coarse families a modeller picks from. */
|
|
18
|
+
export type ElementTypeGroup = "event" | "task" | "gateway" | "container" | "data";
|
|
19
|
+
/** Group labels, in the order a description should list them. */
|
|
20
|
+
export declare const ELEMENT_GROUP_ORDER: readonly ElementTypeGroup[];
|
|
21
|
+
/**
|
|
22
|
+
* Every `BpmnElementType`, mapped to its group.
|
|
23
|
+
*
|
|
24
|
+
* Adding a type to the union without placing it here is a compile error.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ELEMENT_TYPE_GROUPS: Record<BpmnElementType, ElementTypeGroup>;
|
|
27
|
+
/** Every element type in the given group, in declaration order. */
|
|
28
|
+
export declare function elementTypesInGroup(group: ElementTypeGroup): BpmnElementType[];
|
|
29
|
+
/** Every element type the SDK models, in declaration order. */
|
|
30
|
+
export declare function allElementTypes(): BpmnElementType[];
|
|
31
|
+
//# sourceMappingURL=element-catalog.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Group labels, in the order a description should list them. */
|
|
2
|
+
export const ELEMENT_GROUP_ORDER = [
|
|
3
|
+
"event",
|
|
4
|
+
"task",
|
|
5
|
+
"gateway",
|
|
6
|
+
"container",
|
|
7
|
+
"data",
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Every `BpmnElementType`, mapped to its group.
|
|
11
|
+
*
|
|
12
|
+
* Adding a type to the union without placing it here is a compile error.
|
|
13
|
+
*/
|
|
14
|
+
export const ELEMENT_TYPE_GROUPS = {
|
|
15
|
+
startEvent: "event",
|
|
16
|
+
endEvent: "event",
|
|
17
|
+
intermediateThrowEvent: "event",
|
|
18
|
+
intermediateCatchEvent: "event",
|
|
19
|
+
boundaryEvent: "event",
|
|
20
|
+
task: "task",
|
|
21
|
+
serviceTask: "task",
|
|
22
|
+
scriptTask: "task",
|
|
23
|
+
userTask: "task",
|
|
24
|
+
sendTask: "task",
|
|
25
|
+
receiveTask: "task",
|
|
26
|
+
businessRuleTask: "task",
|
|
27
|
+
manualTask: "task",
|
|
28
|
+
callActivity: "task",
|
|
29
|
+
exclusiveGateway: "gateway",
|
|
30
|
+
parallelGateway: "gateway",
|
|
31
|
+
inclusiveGateway: "gateway",
|
|
32
|
+
eventBasedGateway: "gateway",
|
|
33
|
+
complexGateway: "gateway",
|
|
34
|
+
subProcess: "container",
|
|
35
|
+
adHocSubProcess: "container",
|
|
36
|
+
eventSubProcess: "container",
|
|
37
|
+
transaction: "container",
|
|
38
|
+
dataObject: "data",
|
|
39
|
+
dataObjectReference: "data",
|
|
40
|
+
dataStoreReference: "data",
|
|
41
|
+
};
|
|
42
|
+
/** Every element type in the given group, in declaration order. */
|
|
43
|
+
export function elementTypesInGroup(group) {
|
|
44
|
+
return Object.keys(ELEMENT_TYPE_GROUPS).filter((type) => ELEMENT_TYPE_GROUPS[type] === group);
|
|
45
|
+
}
|
|
46
|
+
/** Every element type the SDK models, in declaration order. */
|
|
47
|
+
export function allElementTypes() {
|
|
48
|
+
return Object.keys(ELEMENT_TYPE_GROUPS);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=element-catalog.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building a flow element of a given type, and changing the type of one that
|
|
3
|
+
* already exists.
|
|
4
|
+
*
|
|
5
|
+
* `createFlowElement` is the single place that knows which fields each
|
|
6
|
+
* `BpmnElementType` carries. Its switch is exhaustive — the `default` branch
|
|
7
|
+
* assigns to `never`, so **adding a member to `BpmnElementType` fails `tsc`
|
|
8
|
+
* here** rather than falling through to a plausible-looking wrong shape.
|
|
9
|
+
*
|
|
10
|
+
* `retypeElement` is what lets a caller change a task's type without hand-
|
|
11
|
+
* editing XML: the reason the SDK's own users reached for the file. It keeps
|
|
12
|
+
* identity and wiring, and carries over anything both the old and new type can
|
|
13
|
+
* hold.
|
|
14
|
+
*/
|
|
15
|
+
import type { XmlElement } from "../types/xml-element.js";
|
|
16
|
+
import type { BpmnElementType, BpmnFlowElement } from "./bpmn-model.js";
|
|
17
|
+
export interface CreateFlowElementOptions {
|
|
18
|
+
name?: string;
|
|
19
|
+
documentation?: string;
|
|
20
|
+
extensionElements?: XmlElement[];
|
|
21
|
+
}
|
|
22
|
+
/** True when the type holds nested flow elements. */
|
|
23
|
+
export declare function isContainerType(type: BpmnElementType): boolean;
|
|
24
|
+
/** True when the type can carry a multi-instance marker. */
|
|
25
|
+
export declare function isLoopCapableType(type: BpmnElementType): boolean;
|
|
26
|
+
/** True when the type carries event definitions. */
|
|
27
|
+
export declare function isEventType(type: BpmnElementType): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Build an empty flow element of the given type.
|
|
30
|
+
*
|
|
31
|
+
* The switch is exhaustive over `BpmnElementType`; the `default` branch exists
|
|
32
|
+
* only to make that a compile error rather than a silent wrong shape.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createFlowElement(id: string, type: BpmnElementType, options?: CreateFlowElementOptions): BpmnFlowElement;
|
|
35
|
+
/**
|
|
36
|
+
* Return a copy of `el` with a different `type`, keeping everything the new
|
|
37
|
+
* type can still hold.
|
|
38
|
+
*
|
|
39
|
+
* Kept: id, name, documentation, incoming/outgoing flows, compensation flag,
|
|
40
|
+
* extension elements and unmodelled attributes — so retyping never breaks the
|
|
41
|
+
* graph around the element. Carried over when *both* types support them:
|
|
42
|
+
* nested content (container → container), the multi-instance marker, and event
|
|
43
|
+
* definitions. Anything the new type cannot hold is dropped, which is the
|
|
44
|
+
* point: a `serviceTask` retyped to `manualTask` should not keep a job worker.
|
|
45
|
+
*
|
|
46
|
+
* Returns `el` unchanged when the type already matches.
|
|
47
|
+
*/
|
|
48
|
+
export declare function retypeElement(el: BpmnFlowElement, type: BpmnElementType): BpmnFlowElement;
|
|
49
|
+
//# sourceMappingURL=element-shape.d.ts.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building a flow element of a given type, and changing the type of one that
|
|
3
|
+
* already exists.
|
|
4
|
+
*
|
|
5
|
+
* `createFlowElement` is the single place that knows which fields each
|
|
6
|
+
* `BpmnElementType` carries. Its switch is exhaustive — the `default` branch
|
|
7
|
+
* assigns to `never`, so **adding a member to `BpmnElementType` fails `tsc`
|
|
8
|
+
* here** rather than falling through to a plausible-looking wrong shape.
|
|
9
|
+
*
|
|
10
|
+
* `retypeElement` is what lets a caller change a task's type without hand-
|
|
11
|
+
* editing XML: the reason the SDK's own users reached for the file. It keeps
|
|
12
|
+
* identity and wiring, and carries over anything both the old and new type can
|
|
13
|
+
* hold.
|
|
14
|
+
*/
|
|
15
|
+
import { bpmnElementName, isZeebePlacementAllowed } from "./zeebe-extensions.js";
|
|
16
|
+
/** Container types — the ones that hold their own flow elements and flows. */
|
|
17
|
+
const CONTAINER_TYPES = new Set([
|
|
18
|
+
"subProcess",
|
|
19
|
+
"adHocSubProcess",
|
|
20
|
+
"eventSubProcess",
|
|
21
|
+
"transaction",
|
|
22
|
+
]);
|
|
23
|
+
/** Types that can carry `loopCharacteristics` (a multi-instance marker). */
|
|
24
|
+
const LOOP_CAPABLE_TYPES = new Set([
|
|
25
|
+
"task",
|
|
26
|
+
"serviceTask",
|
|
27
|
+
"scriptTask",
|
|
28
|
+
"userTask",
|
|
29
|
+
"sendTask",
|
|
30
|
+
"receiveTask",
|
|
31
|
+
"businessRuleTask",
|
|
32
|
+
"manualTask",
|
|
33
|
+
"callActivity",
|
|
34
|
+
"subProcess",
|
|
35
|
+
"adHocSubProcess",
|
|
36
|
+
"transaction",
|
|
37
|
+
]);
|
|
38
|
+
/** Event types — the ones that carry `eventDefinitions`. */
|
|
39
|
+
const EVENT_TYPES = new Set([
|
|
40
|
+
"startEvent",
|
|
41
|
+
"endEvent",
|
|
42
|
+
"intermediateThrowEvent",
|
|
43
|
+
"intermediateCatchEvent",
|
|
44
|
+
"boundaryEvent",
|
|
45
|
+
]);
|
|
46
|
+
/** True when the type holds nested flow elements. */
|
|
47
|
+
export function isContainerType(type) {
|
|
48
|
+
return CONTAINER_TYPES.has(type);
|
|
49
|
+
}
|
|
50
|
+
/** True when the type can carry a multi-instance marker. */
|
|
51
|
+
export function isLoopCapableType(type) {
|
|
52
|
+
return LOOP_CAPABLE_TYPES.has(type);
|
|
53
|
+
}
|
|
54
|
+
/** True when the type carries event definitions. */
|
|
55
|
+
export function isEventType(type) {
|
|
56
|
+
return EVENT_TYPES.has(type);
|
|
57
|
+
}
|
|
58
|
+
function emptyContainer() {
|
|
59
|
+
return {
|
|
60
|
+
flowElements: [],
|
|
61
|
+
sequenceFlows: [],
|
|
62
|
+
textAnnotations: [],
|
|
63
|
+
associations: [],
|
|
64
|
+
groups: [],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build an empty flow element of the given type.
|
|
69
|
+
*
|
|
70
|
+
* The switch is exhaustive over `BpmnElementType`; the `default` branch exists
|
|
71
|
+
* only to make that a compile error rather than a silent wrong shape.
|
|
72
|
+
*/
|
|
73
|
+
export function createFlowElement(id, type, options) {
|
|
74
|
+
const base = {
|
|
75
|
+
id,
|
|
76
|
+
name: options?.name,
|
|
77
|
+
incoming: [],
|
|
78
|
+
outgoing: [],
|
|
79
|
+
documentation: options?.documentation,
|
|
80
|
+
extensionElements: options?.extensionElements ?? [],
|
|
81
|
+
unknownAttributes: {},
|
|
82
|
+
};
|
|
83
|
+
switch (type) {
|
|
84
|
+
case "startEvent":
|
|
85
|
+
case "endEvent":
|
|
86
|
+
case "intermediateThrowEvent":
|
|
87
|
+
case "intermediateCatchEvent":
|
|
88
|
+
return { ...base, type, eventDefinitions: [] };
|
|
89
|
+
case "boundaryEvent":
|
|
90
|
+
return { ...base, type, attachedToRef: "", eventDefinitions: [] };
|
|
91
|
+
case "task":
|
|
92
|
+
case "serviceTask":
|
|
93
|
+
case "scriptTask":
|
|
94
|
+
case "userTask":
|
|
95
|
+
case "sendTask":
|
|
96
|
+
case "receiveTask":
|
|
97
|
+
case "businessRuleTask":
|
|
98
|
+
case "manualTask":
|
|
99
|
+
case "callActivity":
|
|
100
|
+
return { ...base, type };
|
|
101
|
+
case "exclusiveGateway":
|
|
102
|
+
case "parallelGateway":
|
|
103
|
+
case "inclusiveGateway":
|
|
104
|
+
case "eventBasedGateway":
|
|
105
|
+
case "complexGateway":
|
|
106
|
+
return { ...base, type };
|
|
107
|
+
case "subProcess":
|
|
108
|
+
case "adHocSubProcess":
|
|
109
|
+
case "eventSubProcess":
|
|
110
|
+
case "transaction":
|
|
111
|
+
return { ...base, type, ...emptyContainer() };
|
|
112
|
+
case "dataObject":
|
|
113
|
+
case "dataObjectReference":
|
|
114
|
+
case "dataStoreReference":
|
|
115
|
+
return { ...base, type };
|
|
116
|
+
default: {
|
|
117
|
+
const unhandled = type;
|
|
118
|
+
throw new Error(`Unhandled BPMN element type: ${String(unhandled)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Return a copy of `el` with a different `type`, keeping everything the new
|
|
124
|
+
* type can still hold.
|
|
125
|
+
*
|
|
126
|
+
* Kept: id, name, documentation, incoming/outgoing flows, compensation flag,
|
|
127
|
+
* extension elements and unmodelled attributes — so retyping never breaks the
|
|
128
|
+
* graph around the element. Carried over when *both* types support them:
|
|
129
|
+
* nested content (container → container), the multi-instance marker, and event
|
|
130
|
+
* definitions. Anything the new type cannot hold is dropped, which is the
|
|
131
|
+
* point: a `serviceTask` retyped to `manualTask` should not keep a job worker.
|
|
132
|
+
*
|
|
133
|
+
* Returns `el` unchanged when the type already matches.
|
|
134
|
+
*/
|
|
135
|
+
export function retypeElement(el, type) {
|
|
136
|
+
if (el.type === type)
|
|
137
|
+
return el;
|
|
138
|
+
// Keep only the extensions the Zeebe schema allows on the new element. This
|
|
139
|
+
// is what stops a serviceTask retyped to manualTask carrying a job worker
|
|
140
|
+
// the engine would then refuse to deploy. Extensions the descriptor says
|
|
141
|
+
// nothing about — anyone else's namespace — are kept.
|
|
142
|
+
const ownerName = bpmnElementName({ type });
|
|
143
|
+
const extensionElements = el.extensionElements.filter((ext) => isZeebePlacementAllowed(ownerName, ext.name));
|
|
144
|
+
const next = createFlowElement(el.id, type, {
|
|
145
|
+
name: el.name,
|
|
146
|
+
documentation: el.documentation,
|
|
147
|
+
extensionElements,
|
|
148
|
+
});
|
|
149
|
+
next.incoming = [...el.incoming];
|
|
150
|
+
next.outgoing = [...el.outgoing];
|
|
151
|
+
next.unknownAttributes = { ...el.unknownAttributes };
|
|
152
|
+
if (el.isForCompensation !== undefined)
|
|
153
|
+
next.isForCompensation = el.isForCompensation;
|
|
154
|
+
if (isContainerType(el.type) && isContainerType(type) && "flowElements" in el) {
|
|
155
|
+
const target = next;
|
|
156
|
+
target.flowElements = el.flowElements;
|
|
157
|
+
target.sequenceFlows = el.sequenceFlows;
|
|
158
|
+
target.textAnnotations = el.textAnnotations;
|
|
159
|
+
target.associations = el.associations;
|
|
160
|
+
target.groups = el.groups;
|
|
161
|
+
}
|
|
162
|
+
if (isLoopCapableType(el.type) && isLoopCapableType(type) && "loopCharacteristics" in el) {
|
|
163
|
+
const loop = el.loopCharacteristics;
|
|
164
|
+
if (loop) {
|
|
165
|
+
;
|
|
166
|
+
next.loopCharacteristics = loop;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (isEventType(el.type) && isEventType(type) && "eventDefinitions" in el) {
|
|
170
|
+
;
|
|
171
|
+
next.eventDefinitions = el.eventDefinitions;
|
|
172
|
+
}
|
|
173
|
+
// A boundary event is meaningless without its host, so keep the attachment
|
|
174
|
+
// when retyping between boundary events; when the source was not one, the
|
|
175
|
+
// caller must set it.
|
|
176
|
+
if (el.type === "boundaryEvent" && type === "boundaryEvent") {
|
|
177
|
+
;
|
|
178
|
+
next.attachedToRef = el.attachedToRef;
|
|
179
|
+
}
|
|
180
|
+
return next;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=element-shape.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BpmnFlowElement, BpmnSequenceFlow } from "./bpmn-model.js";
|
|
2
|
+
/**
|
|
3
|
+
* Replaces generated sequence-flow ids in one scope (a process or a
|
|
4
|
+
* sub-process) with ids derived from the flows themselves, and rewrites the
|
|
5
|
+
* `default` attributes that name them.
|
|
6
|
+
*
|
|
7
|
+
* Run it after the topology is final — after join inference and any pending
|
|
8
|
+
* splice — and before `incoming`/`outgoing` are recomputed.
|
|
9
|
+
*
|
|
10
|
+
* @param elements - The scope's flow elements. Their ids are reserved, and
|
|
11
|
+
* gateway `default` references are rewritten.
|
|
12
|
+
* @param flows - The scope's sequence flows, mutated in place.
|
|
13
|
+
* @param preserve - Ids to leave alone, for flows the builder did not create:
|
|
14
|
+
* continuing a parsed document must not renumber what it was handed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assignStableFlowIds(elements: BpmnFlowElement[], flows: BpmnSequenceFlow[], preserve?: ReadonlySet<string>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Derives a root definition's id from what callers look it up by — a message or
|
|
19
|
+
* signal name, an error or escalation code — so the same declaration keeps the
|
|
20
|
+
* same id across rebuilds.
|
|
21
|
+
*
|
|
22
|
+
* @param prefix - Element kind, e.g. `"Message"`.
|
|
23
|
+
* @param source - The name or code the definition is resolved by.
|
|
24
|
+
* @param existing - Definitions of the same kind already declared, whose ids
|
|
25
|
+
* the result is deduped against.
|
|
26
|
+
*/
|
|
27
|
+
export declare function rootDefinitionId(prefix: string, source: string, existing: ReadonlyArray<{
|
|
28
|
+
id: string;
|
|
29
|
+
}>): string;
|
|
30
|
+
//# sourceMappingURL=stable-ids.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable, content-derived ids for the parts of a model the caller does not name:
|
|
3
|
+
* sequence flows, and the root messages, errors, signals and escalations that
|
|
4
|
+
* event options declare.
|
|
5
|
+
*
|
|
6
|
+
* The fluent builder used to mint these with `generateId()`, so rebuilding an
|
|
7
|
+
* unchanged model produced different BPMN every time — noisy diffs, and a
|
|
8
|
+
* review that cannot tell a renamed edge from a new one. These ids come from
|
|
9
|
+
* the model instead: for a flow, the endpoints it connects plus a discriminator
|
|
10
|
+
* when one pair carries several flows; for a root definition, the name or code
|
|
11
|
+
* it is looked up by.
|
|
12
|
+
*
|
|
13
|
+
* Flow ids are assigned in a pass over a finished scope rather than at creation
|
|
14
|
+
* time, because a flow's endpoints are not final when it is created —
|
|
15
|
+
* `insertAfter()` re-points a flow's source, and `insertJoinGateways()`
|
|
16
|
+
* re-points its target.
|
|
17
|
+
*/
|
|
18
|
+
import { slugify, uniqueId } from "../plan/slug.js";
|
|
19
|
+
/** Longest id this produces; anything longer is truncated and hashed. */
|
|
20
|
+
const MAX_ID_LENGTH = 200;
|
|
21
|
+
/**
|
|
22
|
+
* FNV-1a, base36. Not a checksum anyone verifies — just a short, stable
|
|
23
|
+
* discriminator for two flows the model distinguishes only by a long string.
|
|
24
|
+
*/
|
|
25
|
+
function shortHash(text) {
|
|
26
|
+
let hash = 0x811c9dc5;
|
|
27
|
+
for (let i = 0; i < text.length; i++) {
|
|
28
|
+
hash ^= text.charCodeAt(i);
|
|
29
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
30
|
+
}
|
|
31
|
+
return hash.toString(36);
|
|
32
|
+
}
|
|
33
|
+
/** Keeps an id an XML NCName: letters, digits, `_` and `-`, never leading with a digit. */
|
|
34
|
+
function ncName(text) {
|
|
35
|
+
const cleaned = text.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[^A-Za-z_]+/, "");
|
|
36
|
+
return cleaned.length > 0 ? cleaned : "x";
|
|
37
|
+
}
|
|
38
|
+
/** Truncates over-long ids, keeping them distinct by appending a hash of what was dropped. */
|
|
39
|
+
function capLength(id) {
|
|
40
|
+
if (id.length <= MAX_ID_LENGTH)
|
|
41
|
+
return id;
|
|
42
|
+
const suffix = `_${shortHash(id)}`;
|
|
43
|
+
return id.slice(0, MAX_ID_LENGTH - suffix.length) + suffix;
|
|
44
|
+
}
|
|
45
|
+
/** The id a flow gets when it is the only one between its two endpoints. */
|
|
46
|
+
function baseId(flow) {
|
|
47
|
+
return capLength(`Flow_${ncName(flow.sourceRef)}_${ncName(flow.targetRef)}`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What tells two flows between the same endpoints apart, in order of how
|
|
51
|
+
* readable it is: the branch name, then the condition, then nothing — leaving
|
|
52
|
+
* `uniqueId` to number genuinely identical edges.
|
|
53
|
+
*/
|
|
54
|
+
function discriminator(flow) {
|
|
55
|
+
if (flow.name !== undefined && flow.name.trim().length > 0)
|
|
56
|
+
return ncName(slugify(flow.name));
|
|
57
|
+
const condition = flow.conditionExpression?.text;
|
|
58
|
+
if (condition !== undefined && condition.trim().length > 0)
|
|
59
|
+
return `c${shortHash(condition)}`;
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Replaces generated sequence-flow ids in one scope (a process or a
|
|
64
|
+
* sub-process) with ids derived from the flows themselves, and rewrites the
|
|
65
|
+
* `default` attributes that name them.
|
|
66
|
+
*
|
|
67
|
+
* Run it after the topology is final — after join inference and any pending
|
|
68
|
+
* splice — and before `incoming`/`outgoing` are recomputed.
|
|
69
|
+
*
|
|
70
|
+
* @param elements - The scope's flow elements. Their ids are reserved, and
|
|
71
|
+
* gateway `default` references are rewritten.
|
|
72
|
+
* @param flows - The scope's sequence flows, mutated in place.
|
|
73
|
+
* @param preserve - Ids to leave alone, for flows the builder did not create:
|
|
74
|
+
* continuing a parsed document must not renumber what it was handed.
|
|
75
|
+
*/
|
|
76
|
+
export function assignStableFlowIds(elements, flows, preserve) {
|
|
77
|
+
const renamable = preserve === undefined ? flows : flows.filter((flow) => !preserve.has(flow.id));
|
|
78
|
+
if (renamable.length === 0)
|
|
79
|
+
return;
|
|
80
|
+
// Reserved up front so a derived id can never land on an element id or on a
|
|
81
|
+
// flow id this pass is not allowed to touch.
|
|
82
|
+
const taken = new Set(elements.map((element) => element.id));
|
|
83
|
+
if (preserve !== undefined) {
|
|
84
|
+
for (const flow of flows)
|
|
85
|
+
if (preserve.has(flow.id))
|
|
86
|
+
taken.add(flow.id);
|
|
87
|
+
}
|
|
88
|
+
// Flows sharing a base id all get a discriminator, so which one was built
|
|
89
|
+
// first — and so the order branches were declared in — does not decide who
|
|
90
|
+
// keeps the short id.
|
|
91
|
+
const byBase = new Map();
|
|
92
|
+
for (const flow of renamable) {
|
|
93
|
+
const base = baseId(flow);
|
|
94
|
+
const group = byBase.get(base);
|
|
95
|
+
if (group)
|
|
96
|
+
group.push(flow);
|
|
97
|
+
else
|
|
98
|
+
byBase.set(base, [flow]);
|
|
99
|
+
}
|
|
100
|
+
const renamed = new Map();
|
|
101
|
+
for (const [base, group] of byBase) {
|
|
102
|
+
for (const flow of group) {
|
|
103
|
+
const qualifier = group.length > 1 ? discriminator(flow) : undefined;
|
|
104
|
+
const id = uniqueId(qualifier === undefined ? base : capLength(`${base}_${qualifier}`), taken);
|
|
105
|
+
if (id !== flow.id)
|
|
106
|
+
renamed.set(flow.id, id);
|
|
107
|
+
flow.id = id;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (renamed.size === 0)
|
|
111
|
+
return;
|
|
112
|
+
for (const element of elements) {
|
|
113
|
+
if (!("default" in element) || element.default === undefined)
|
|
114
|
+
continue;
|
|
115
|
+
const replacement = renamed.get(element.default);
|
|
116
|
+
if (replacement !== undefined)
|
|
117
|
+
element.default = replacement;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Derives a root definition's id from what callers look it up by — a message or
|
|
122
|
+
* signal name, an error or escalation code — so the same declaration keeps the
|
|
123
|
+
* same id across rebuilds.
|
|
124
|
+
*
|
|
125
|
+
* @param prefix - Element kind, e.g. `"Message"`.
|
|
126
|
+
* @param source - The name or code the definition is resolved by.
|
|
127
|
+
* @param existing - Definitions of the same kind already declared, whose ids
|
|
128
|
+
* the result is deduped against.
|
|
129
|
+
*/
|
|
130
|
+
export function rootDefinitionId(prefix, source, existing) {
|
|
131
|
+
const taken = new Set(existing.map((definition) => definition.id));
|
|
132
|
+
return uniqueId(capLength(`${prefix}_${ncName(slugify(source))}`), taken);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=stable-ids.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,9 @@ export type { BenchmarkResult, BoundingBox, ElementComparison, ElementPosition,
|
|
|
56
56
|
export type { Bounds, LayoutEdge, LayoutNode, LayoutResult, Waypoint } from "./layout/index.js";
|
|
57
57
|
export { ELEMENT_SIZES, GRID_CELL_HEIGHT, GRID_CELL_WIDTH } from "./layout/index.js";
|
|
58
58
|
export { compactify, expand } from "./bpmn/compact.js";
|
|
59
|
+
export { ELEMENT_GROUP_ORDER, ELEMENT_TYPE_GROUPS, allElementTypes, elementTypesInGroup, } from "./bpmn/element-catalog.js";
|
|
60
|
+
export type { ElementTypeGroup } from "./bpmn/element-catalog.js";
|
|
61
|
+
export { createFlowElement, retypeElement } from "./bpmn/element-shape.js";
|
|
59
62
|
export { applyOperations } from "./bpmn/operations.js";
|
|
60
63
|
export type { BpmnOperation } from "./bpmn/operations.js";
|
|
61
64
|
export { applyBpmnOperations, reconcileCompact, OperationError } from "./bpmn/full-operations.js";
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ export { layoutProcess, layoutFlowNodes } from "./layout/index.js";
|
|
|
30
30
|
export { benchmarkLayout, compareLayouts, formatBenchmarkResult, generateAutoLayout, parseReferenceLayout, } from "./layout/index.js";
|
|
31
31
|
export { ELEMENT_SIZES, GRID_CELL_HEIGHT, GRID_CELL_WIDTH } from "./layout/index.js";
|
|
32
32
|
export { compactify, expand } from "./bpmn/compact.js";
|
|
33
|
+
export { ELEMENT_GROUP_ORDER, ELEMENT_TYPE_GROUPS, allElementTypes, elementTypesInGroup, } from "./bpmn/element-catalog.js";
|
|
34
|
+
export { createFlowElement, retypeElement } from "./bpmn/element-shape.js";
|
|
33
35
|
export { applyOperations } from "./bpmn/operations.js";
|
|
34
36
|
export { applyBpmnOperations, reconcileCompact, OperationError } from "./bpmn/full-operations.js";
|
|
35
37
|
export { buildValidationDmn, findValidationStructure, getValidationInputNames, insertValidationStructure, removeValidationStructure, validationDecisionId, } from "./bpmn/input-validation.js";
|
package/dist/layout/types.js
CHANGED
|
@@ -24,6 +24,10 @@ export const ELEMENT_SIZES = {
|
|
|
24
24
|
adHocSubProcess: { width: 100, height: 80 },
|
|
25
25
|
eventSubProcess: { width: 100, height: 80 },
|
|
26
26
|
transaction: { width: 100, height: 80 },
|
|
27
|
+
// Data elements are drawn as the page and cylinder glyphs, not as activities.
|
|
28
|
+
dataObject: { width: 36, height: 50 },
|
|
29
|
+
dataObjectReference: { width: 36, height: 50 },
|
|
30
|
+
dataStoreReference: { width: 50, height: 50 },
|
|
27
31
|
};
|
|
28
32
|
/** Virtual grid cell dimensions for element placement. */
|
|
29
33
|
export const GRID_CELL_WIDTH = 150;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bpmnkit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"check": "biome check .",
|
|
53
53
|
"test": "vitest run",
|
|
54
54
|
"check:descriptors": "tsx scripts/descriptor-report.ts",
|
|
55
|
+
"check:builder": "tsx scripts/builder-report.ts",
|
|
55
56
|
"generate:placement": "tsx scripts/generate-zeebe-placement.ts",
|
|
56
57
|
"check:placement": "tsx scripts/generate-zeebe-placement.ts --check",
|
|
57
58
|
"format-bpmn": "node scripts/format-bpmn.mjs"
|