@bpmnkit/core 0.3.0 → 0.5.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/README.md +128 -19
- package/dist/bpmn/bpmn-builder.d.ts +111 -7
- package/dist/bpmn/bpmn-builder.js +334 -134
- package/dist/bpmn/builder-coverage.d.ts +59 -0
- package/dist/bpmn/builder-coverage.js +62 -0
- package/dist/bpmn/compact.d.ts +14 -0
- package/dist/bpmn/compact.js +42 -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/full-operations.js +2 -0
- package/dist/bpmn/stable-ids.d.ts +30 -0
- package/dist/bpmn/stable-ids.js +134 -0
- package/dist/form/form-builder.js +27 -32
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/layout/types.js +4 -0
- package/package.json +3 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which fluent-builder method covers each BPMN element type.
|
|
3
|
+
*
|
|
4
|
+
* The fluent builder is hand-written, one method per element type, while
|
|
5
|
+
* `BpmnElementType` grows whenever the model learns a new construct. Nothing
|
|
6
|
+
* connected the two, so types reached the parser, the serialiser, the layout
|
|
7
|
+
* and the compact/JSON path while the builder — the surface most callers and
|
|
8
|
+
* every code-generating agent actually use — silently lacked a method. An agent
|
|
9
|
+
* that cannot say `.manualTask()` edits the XML by hand instead.
|
|
10
|
+
*
|
|
11
|
+
* This table closes that loop. It is a `Record` keyed by `BpmnElementType`, so
|
|
12
|
+
* **adding a member to that union fails `tsc` here until the new type is either
|
|
13
|
+
* given a builder method or exempted with a reason**. The check is compile-time
|
|
14
|
+
* and total; it cannot be forgotten, and it cannot pass by accident.
|
|
15
|
+
*
|
|
16
|
+
* `tests/builder-coverage.test.ts` carries the runtime half: every `method`
|
|
17
|
+
* named here must exist on all three flow builders, and every `exempt` entry
|
|
18
|
+
* must still have no method of that name — so an exemption someone outgrows
|
|
19
|
+
* fails rather than lingers.
|
|
20
|
+
*
|
|
21
|
+
* Run `pnpm --filter @bpmnkit/core check:builder` to print the table.
|
|
22
|
+
*/
|
|
23
|
+
import type { BpmnElementType } from "./bpmn-model.js";
|
|
24
|
+
/** An element type the fluent builder exposes a method for. */
|
|
25
|
+
export interface BuilderMethodEntry {
|
|
26
|
+
/** Method name, present on every flow builder. */
|
|
27
|
+
readonly method: string;
|
|
28
|
+
/**
|
|
29
|
+
* The `type` the method stamps, when it differs from the key.
|
|
30
|
+
*
|
|
31
|
+
* Only `eventSubProcess` needs this: BPMN 2.0 has no `bpmn:eventSubProcess`
|
|
32
|
+
* element, so the builder emits the spec form — `subProcess` with
|
|
33
|
+
* `triggeredByEvent="true"`. The key exists because the parser accepts the
|
|
34
|
+
* non-standard element and round-trips it.
|
|
35
|
+
*/
|
|
36
|
+
readonly emits?: BpmnElementType;
|
|
37
|
+
}
|
|
38
|
+
/** An element type the fluent builder deliberately has no method for. */
|
|
39
|
+
export interface BuilderExemptEntry {
|
|
40
|
+
/** Why a method would be wrong — not merely why one is missing. */
|
|
41
|
+
readonly exempt: string;
|
|
42
|
+
}
|
|
43
|
+
export type BuilderSupport = BuilderMethodEntry | BuilderExemptEntry;
|
|
44
|
+
/** Narrows a {@link BuilderSupport} to the entries that name a method. */
|
|
45
|
+
export declare function hasBuilderMethod(support: BuilderSupport): support is BuilderMethodEntry;
|
|
46
|
+
/**
|
|
47
|
+
* Every `BpmnElementType`, mapped to the builder method that creates it.
|
|
48
|
+
*
|
|
49
|
+
* Adding a type to the union without adding it here is a compile error.
|
|
50
|
+
*/
|
|
51
|
+
export declare const BUILDER_COVERAGE: Record<BpmnElementType, BuilderSupport>;
|
|
52
|
+
/**
|
|
53
|
+
* The builders the table applies to — every class that builds a flow chain.
|
|
54
|
+
*
|
|
55
|
+
* `DiagramBuilder` is excluded on purpose: it assembles collaborations,
|
|
56
|
+
* participants and message flows, and never adds flow elements itself.
|
|
57
|
+
*/
|
|
58
|
+
export declare const FLOW_BUILDER_NAMES: readonly ["ProcessBuilder", "BranchBuilder", "SubProcessContentBuilder"];
|
|
59
|
+
//# sourceMappingURL=builder-coverage.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Narrows a {@link BuilderSupport} to the entries that name a method. */
|
|
2
|
+
export function hasBuilderMethod(support) {
|
|
3
|
+
return "method" in support;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Data elements are not sequence-flow participants, and the fluent builder has
|
|
7
|
+
* no data-association API. Every builder method appends to the chain and wires
|
|
8
|
+
* a sequence flow from the previous node, so a `.dataObject()` would either
|
|
9
|
+
* emit invalid BPMN or leave an orphan shape. Parsing and serialising keep
|
|
10
|
+
* these types; authoring them is a separate API, not a chain method.
|
|
11
|
+
*/
|
|
12
|
+
const NOT_A_CHAIN_PARTICIPANT = "Connected by data associations, not sequence flows; the chain has nowhere to put it";
|
|
13
|
+
/**
|
|
14
|
+
* Every `BpmnElementType`, mapped to the builder method that creates it.
|
|
15
|
+
*
|
|
16
|
+
* Adding a type to the union without adding it here is a compile error.
|
|
17
|
+
*/
|
|
18
|
+
export const BUILDER_COVERAGE = {
|
|
19
|
+
// ---- Events ----
|
|
20
|
+
startEvent: { method: "startEvent" },
|
|
21
|
+
endEvent: { method: "endEvent" },
|
|
22
|
+
intermediateThrowEvent: { method: "intermediateThrowEvent" },
|
|
23
|
+
intermediateCatchEvent: { method: "intermediateCatchEvent" },
|
|
24
|
+
boundaryEvent: { method: "boundaryEvent" },
|
|
25
|
+
// ---- Activities ----
|
|
26
|
+
task: { method: "task" },
|
|
27
|
+
serviceTask: { method: "serviceTask" },
|
|
28
|
+
scriptTask: { method: "scriptTask" },
|
|
29
|
+
userTask: { method: "userTask" },
|
|
30
|
+
sendTask: { method: "sendTask" },
|
|
31
|
+
receiveTask: { method: "receiveTask" },
|
|
32
|
+
businessRuleTask: { method: "businessRuleTask" },
|
|
33
|
+
manualTask: { method: "manualTask" },
|
|
34
|
+
callActivity: { method: "callActivity" },
|
|
35
|
+
// ---- Gateways ----
|
|
36
|
+
exclusiveGateway: { method: "exclusiveGateway" },
|
|
37
|
+
parallelGateway: { method: "parallelGateway" },
|
|
38
|
+
inclusiveGateway: { method: "inclusiveGateway" },
|
|
39
|
+
eventBasedGateway: { method: "eventBasedGateway" },
|
|
40
|
+
complexGateway: { method: "complexGateway" },
|
|
41
|
+
// ---- Containers ----
|
|
42
|
+
subProcess: { method: "subProcess" },
|
|
43
|
+
adHocSubProcess: { method: "adHocSubProcess" },
|
|
44
|
+
eventSubProcess: { method: "eventSubProcess", emits: "subProcess" },
|
|
45
|
+
transaction: { method: "transaction" },
|
|
46
|
+
// ---- Data ----
|
|
47
|
+
dataObject: { exempt: NOT_A_CHAIN_PARTICIPANT },
|
|
48
|
+
dataObjectReference: { exempt: NOT_A_CHAIN_PARTICIPANT },
|
|
49
|
+
dataStoreReference: { exempt: NOT_A_CHAIN_PARTICIPANT },
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The builders the table applies to — every class that builds a flow chain.
|
|
53
|
+
*
|
|
54
|
+
* `DiagramBuilder` is excluded on purpose: it assembles collaborations,
|
|
55
|
+
* participants and message flows, and never adds flow elements itself.
|
|
56
|
+
*/
|
|
57
|
+
export const FLOW_BUILDER_NAMES = [
|
|
58
|
+
"ProcessBuilder",
|
|
59
|
+
"BranchBuilder",
|
|
60
|
+
"SubProcessContentBuilder",
|
|
61
|
+
];
|
|
62
|
+
//# sourceMappingURL=builder-coverage.js.map
|
package/dist/bpmn/compact.d.ts
CHANGED
|
@@ -5,8 +5,20 @@ export interface CompactElement {
|
|
|
5
5
|
id: string;
|
|
6
6
|
type: BpmnElementType;
|
|
7
7
|
name?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Free-text `<bpmn:documentation>`. Not decoration: on an ad-hoc sub-process
|
|
10
|
+
* child it is the tool description the AI Agent connector hands the LLM, and
|
|
11
|
+
* on a start event it is where the process input contract is written.
|
|
12
|
+
*/
|
|
13
|
+
documentation?: string;
|
|
8
14
|
/** Zeebe job type (serviceTask: zeebe:taskDefinition.type) */
|
|
9
15
|
jobType?: string;
|
|
16
|
+
/** dataObjectReference: id of the dataObject it points at. */
|
|
17
|
+
dataObjectRef?: string;
|
|
18
|
+
/** dataStoreReference: id of the data store it points at. */
|
|
19
|
+
dataStoreRef?: string;
|
|
20
|
+
/** dataObject / dataObjectReference: marks a collection. */
|
|
21
|
+
isCollection?: boolean;
|
|
10
22
|
/**
|
|
11
23
|
* Zeebe task headers (key→value).
|
|
12
24
|
* For the Camunda HTTP connector use jobType "io.camunda:http-json:1" and set:
|
|
@@ -50,6 +62,8 @@ export interface CompactFlow {
|
|
|
50
62
|
export interface CompactProcess {
|
|
51
63
|
id: string;
|
|
52
64
|
name?: string;
|
|
65
|
+
/** Free-text `<bpmn:documentation>` on the process itself. */
|
|
66
|
+
documentation?: string;
|
|
53
67
|
elements: CompactElement[];
|
|
54
68
|
flows: CompactFlow[];
|
|
55
69
|
}
|
package/dist/bpmn/compact.js
CHANGED
|
@@ -8,6 +8,8 @@ function compactifyElement(el) {
|
|
|
8
8
|
const result = { id: el.id, type: el.type };
|
|
9
9
|
if (el.name)
|
|
10
10
|
result.name = el.name;
|
|
11
|
+
if (el.documentation)
|
|
12
|
+
result.documentation = el.documentation;
|
|
11
13
|
const jobType = findAttr(ext, "zeebe:taskDefinition", "type");
|
|
12
14
|
if (jobType)
|
|
13
15
|
result.jobType = jobType;
|
|
@@ -57,6 +59,15 @@ function compactifyElement(el) {
|
|
|
57
59
|
if (el.cancelActivity === false)
|
|
58
60
|
result.interrupting = false;
|
|
59
61
|
}
|
|
62
|
+
if (el.type === "dataObjectReference" && el.dataObjectRef !== undefined) {
|
|
63
|
+
result.dataObjectRef = el.dataObjectRef;
|
|
64
|
+
}
|
|
65
|
+
if (el.type === "dataStoreReference" && el.dataStoreRef !== undefined) {
|
|
66
|
+
result.dataStoreRef = el.dataStoreRef;
|
|
67
|
+
}
|
|
68
|
+
if ((el.type === "dataObject" || el.type === "dataObjectReference") && el.isCollection) {
|
|
69
|
+
result.isCollection = true;
|
|
70
|
+
}
|
|
60
71
|
// Recurse into sub-process container children
|
|
61
72
|
if ("flowElements" in el && Array.isArray(el.flowElements) && el.flowElements.length > 0) {
|
|
62
73
|
const seqFlows = "sequenceFlows" in el && Array.isArray(el.sequenceFlows) ? el.sequenceFlows : [];
|
|
@@ -99,6 +110,7 @@ export function compactify(defs) {
|
|
|
99
110
|
processes: defs.processes.map((process) => ({
|
|
100
111
|
id: process.id,
|
|
101
112
|
name: process.name,
|
|
113
|
+
documentation: process.documentation,
|
|
102
114
|
elements: process.flowElements.map(compactifyElement),
|
|
103
115
|
flows: process.sequenceFlows.map((sf) => {
|
|
104
116
|
const f = { id: sf.id, from: sf.sourceRef, to: sf.targetRef };
|
|
@@ -230,6 +242,7 @@ export function buildFlowElement(el, incoming, outgoing) {
|
|
|
230
242
|
const base = {
|
|
231
243
|
id: el.id,
|
|
232
244
|
name: el.name,
|
|
245
|
+
documentation: el.documentation,
|
|
233
246
|
incoming,
|
|
234
247
|
outgoing,
|
|
235
248
|
extensionElements: makeExtensions(el),
|
|
@@ -291,8 +304,34 @@ export function buildFlowElement(el, incoming, outgoing) {
|
|
|
291
304
|
return { ...base, type: "eventBasedGateway" };
|
|
292
305
|
case "complexGateway":
|
|
293
306
|
return { ...base, type: "complexGateway" };
|
|
294
|
-
|
|
295
|
-
|
|
307
|
+
// Data elements are not sequence-flow participants; they carry a
|
|
308
|
+
// reference instead, and dropping that reference is what made them
|
|
309
|
+
// round-trip as bare tasks before.
|
|
310
|
+
case "dataObject":
|
|
311
|
+
return {
|
|
312
|
+
...base,
|
|
313
|
+
type: "dataObject",
|
|
314
|
+
...(el.isCollection !== undefined ? { isCollection: el.isCollection } : {}),
|
|
315
|
+
};
|
|
316
|
+
case "dataObjectReference":
|
|
317
|
+
return {
|
|
318
|
+
...base,
|
|
319
|
+
type: "dataObjectReference",
|
|
320
|
+
...(el.dataObjectRef !== undefined ? { dataObjectRef: el.dataObjectRef } : {}),
|
|
321
|
+
...(el.isCollection !== undefined ? { isCollection: el.isCollection } : {}),
|
|
322
|
+
};
|
|
323
|
+
case "dataStoreReference":
|
|
324
|
+
return {
|
|
325
|
+
...base,
|
|
326
|
+
type: "dataStoreReference",
|
|
327
|
+
...(el.dataStoreRef !== undefined ? { dataStoreRef: el.dataStoreRef } : {}),
|
|
328
|
+
};
|
|
329
|
+
default: {
|
|
330
|
+
// Exhaustive: a new BpmnElementType fails here rather than silently
|
|
331
|
+
// expanding to a task, which is how the data types were lost.
|
|
332
|
+
const unhandled = el.type;
|
|
333
|
+
throw new Error(`Unhandled BPMN element type in expand(): ${String(unhandled)}`);
|
|
334
|
+
}
|
|
296
335
|
}
|
|
297
336
|
}
|
|
298
337
|
function buildDiagram(processId, process) {
|
|
@@ -345,6 +384,7 @@ function expandProcess(compact) {
|
|
|
345
384
|
const process = {
|
|
346
385
|
id: compact.id,
|
|
347
386
|
name: compact.name,
|
|
387
|
+
documentation: compact.documentation,
|
|
348
388
|
isExecutable: true,
|
|
349
389
|
extensionElements: [],
|
|
350
390
|
flowElements,
|
|
@@ -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
|
|
@@ -178,6 +178,8 @@ function patchElement(element, patch) {
|
|
|
178
178
|
return misplaced;
|
|
179
179
|
if (patch.name !== undefined)
|
|
180
180
|
element.name = patch.name;
|
|
181
|
+
if (patch.documentation !== undefined)
|
|
182
|
+
element.documentation = patch.documentation;
|
|
181
183
|
if (patch.attachedTo !== undefined && "attachedToRef" in element) {
|
|
182
184
|
element.attachedToRef = patch.attachedTo;
|
|
183
185
|
}
|
|
@@ -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
|