@bpmnkit/core 1.0.0 → 1.2.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 +30 -3
- package/dist/bpmn/agentic.js +3 -1
- package/dist/bpmn/auto-layout.js +184 -15
- package/dist/bpmn/bpmn-builder.js +69 -7
- package/dist/bpmn/bpmn-model.d.ts +78 -0
- package/dist/bpmn/bpmn-parser.js +195 -37
- package/dist/bpmn/bpmn-serializer.js +121 -72
- package/dist/bpmn/bpmnlint.d.ts +153 -0
- package/dist/bpmn/bpmnlint.js +364 -0
- package/dist/bpmn/camunda-compat-data.d.ts +165 -0
- package/dist/bpmn/camunda-compat-data.js +423 -0
- package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
- package/dist/bpmn/camunda-compat-feel.js +338 -0
- package/dist/bpmn/camunda-compat.d.ts +120 -0
- package/dist/bpmn/camunda-compat.js +1677 -0
- package/dist/bpmn/camunda7/juel.d.ts +41 -0
- package/dist/bpmn/camunda7/juel.js +333 -0
- package/dist/bpmn/camunda7/migrate.d.ts +72 -0
- package/dist/bpmn/camunda7/migrate.js +1152 -0
- package/dist/bpmn/compact.d.ts +4 -0
- package/dist/bpmn/compact.js +80 -0
- package/dist/bpmn/full-operations.js +5 -2
- package/dist/bpmn/label-style.d.ts +51 -0
- package/dist/bpmn/label-style.js +116 -0
- package/dist/bpmn/lint.d.ts +23 -3
- package/dist/bpmn/lint.js +47 -10
- package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
- package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
- package/dist/bpmn/optimize/deploy.d.ts +8 -2
- package/dist/bpmn/optimize/deploy.js +16 -3
- package/dist/bpmn/optimize/index.js +11 -2
- package/dist/bpmn/optimize/patterns.js +3 -0
- package/dist/bpmn/optimize/types.d.ts +14 -0
- package/dist/bpmn/optimize/variable-flow.js +4 -1
- package/dist/bpmn/process-delta.d.ts +88 -0
- package/dist/bpmn/process-delta.js +236 -0
- package/dist/bpmn/process-text-writer.d.ts +53 -0
- package/dist/bpmn/process-text-writer.js +193 -0
- package/dist/bpmn/process-text.d.ts +175 -0
- package/dist/bpmn/process-text.js +1255 -0
- package/dist/bpmn/process-types.d.ts +112 -0
- package/dist/bpmn/process-types.js +490 -0
- package/dist/bpmn/svg.js +51 -22
- package/dist/doc/docx.d.ts +20 -0
- package/dist/doc/docx.js +253 -0
- package/dist/doc/html.d.ts +21 -0
- package/dist/doc/html.js +303 -0
- package/dist/doc/index.d.ts +7 -0
- package/dist/doc/index.js +5 -0
- package/dist/doc/markdown.d.ts +11 -0
- package/dist/doc/markdown.js +160 -0
- package/dist/doc/model.d.ts +129 -0
- package/dist/doc/model.js +617 -0
- package/dist/doc/zip.d.ts +5 -0
- package/dist/doc/zip.js +75 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +11 -0
- package/dist/layout/annotations.d.ts +4 -2
- package/dist/layout/annotations.js +31 -2
- package/dist/layout/collaboration/ordering.d.ts +8 -0
- package/dist/layout/collaboration/ordering.js +57 -18
- package/dist/layout/orthogonal.d.ts +32 -0
- package/dist/layout/orthogonal.js +367 -0
- package/dist/layout/repair.d.ts +31 -0
- package/dist/layout/repair.js +220 -0
- package/dist/layout/semantic/route.js +45 -3
- package/dist/node/bpmnlint.d.ts +109 -0
- package/dist/node/bpmnlint.js +198 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/xml/xml-patch.d.ts +21 -0
- package/dist/xml/xml-patch.js +27 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BpmnProcess } from "../bpmn-model.js";
|
|
1
|
+
import type { BpmnMessage, BpmnProcess } from "../bpmn-model.js";
|
|
2
2
|
import type { OptimizationFinding } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Given a bundled connector template id and the set of value keys bound on
|
|
@@ -12,5 +12,11 @@ export type ConnectorRequirementsResolver = (templateId: string, boundKeys: stri
|
|
|
12
12
|
* deployment time (`apps/reebe/crates/reebe-bpmn/src/validator.rs`), so a
|
|
13
13
|
* process that passes this profile deploys without a validation error.
|
|
14
14
|
*/
|
|
15
|
-
export declare function analyzeDeploy(p: BpmnProcess, resolveConnectorRequirements?: ConnectorRequirementsResolver
|
|
15
|
+
export declare function analyzeDeploy(p: BpmnProcess, resolveConnectorRequirements?: ConnectorRequirementsResolver,
|
|
16
|
+
/**
|
|
17
|
+
* The document's root messages. Camunda reads a catch's correlation key from
|
|
18
|
+
* the `zeebe:subscription` on the message it references; without these only
|
|
19
|
+
* a key placed on the element itself is seen.
|
|
20
|
+
*/
|
|
21
|
+
messages?: readonly BpmnMessage[]): OptimizationFinding[];
|
|
16
22
|
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -7,9 +7,22 @@ function findExt(el, name) {
|
|
|
7
7
|
* deployment time (`apps/reebe/crates/reebe-bpmn/src/validator.rs`), so a
|
|
8
8
|
* process that passes this profile deploys without a validation error.
|
|
9
9
|
*/
|
|
10
|
-
export function analyzeDeploy(p, resolveConnectorRequirements
|
|
10
|
+
export function analyzeDeploy(p, resolveConnectorRequirements,
|
|
11
|
+
/**
|
|
12
|
+
* The document's root messages. Camunda reads a catch's correlation key from
|
|
13
|
+
* the `zeebe:subscription` on the message it references; without these only
|
|
14
|
+
* a key placed on the element itself is seen.
|
|
15
|
+
*/
|
|
16
|
+
messages = []) {
|
|
11
17
|
const findings = [];
|
|
12
18
|
const processId = p.id;
|
|
19
|
+
const messageById = new Map(messages.map((message) => [message.id, message]));
|
|
20
|
+
const hasCorrelationKey = (element, messageRef) => {
|
|
21
|
+
if (findExt(element, "zeebe:subscription")?.attributes.correlationKey)
|
|
22
|
+
return true;
|
|
23
|
+
const message = messageRef === undefined ? undefined : messageById.get(messageRef);
|
|
24
|
+
return (message?.extensionElements?.some((ext) => ext.name.endsWith(":subscription") && Boolean(ext.attributes.correlationKey)) ?? false);
|
|
25
|
+
};
|
|
13
26
|
if (p.isExecutable !== true) {
|
|
14
27
|
findings.push({
|
|
15
28
|
id: "deploy/process-not-executable",
|
|
@@ -86,9 +99,9 @@ export function analyzeDeploy(p, resolveConnectorRequirements) {
|
|
|
86
99
|
? undefined
|
|
87
100
|
: el.eventDefinitions.find((d) => d.type === "message");
|
|
88
101
|
const isMessageCatch = el.type === "receiveTask" ? el.messageRef !== undefined : messageDef !== undefined;
|
|
102
|
+
const messageRef = el.type === "receiveTask" ? el.messageRef : messageDef?.messageRef;
|
|
89
103
|
if (isMessageCatch) {
|
|
90
|
-
|
|
91
|
-
if (!subscription?.attributes.correlationKey) {
|
|
104
|
+
if (!hasCorrelationKey(el, messageRef)) {
|
|
92
105
|
findings.push({
|
|
93
106
|
id: "deploy/message-catch-no-correlation",
|
|
94
107
|
category: "deploy",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { analyzeCamundaCompat, dedupeCamundaCompat } from "../camunda-compat.js";
|
|
1
2
|
import { analyzeAgentic } from "./agentic.js";
|
|
2
3
|
import { analyzeDeploy } from "./deploy.js";
|
|
3
4
|
import { analyzeFeelSyntax } from "./feel-syntax.js";
|
|
@@ -29,12 +30,13 @@ function resolveOptions(opts) {
|
|
|
29
30
|
reuseThreshold: opts?.reuseThreshold ?? 2,
|
|
30
31
|
categories: opts?.categories ?? [...ALL_CATEGORIES],
|
|
31
32
|
resolveConnectorRequirements: opts?.resolveConnectorRequirements,
|
|
33
|
+
camundaVersion: opts?.camundaVersion,
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
/** Run static analysis on a BPMN definitions object. */
|
|
35
37
|
export function optimize(defs, options) {
|
|
36
38
|
const resolved = resolveOptions(options);
|
|
37
|
-
|
|
39
|
+
let findings = [];
|
|
38
40
|
for (const process of defs.processes) {
|
|
39
41
|
if (resolved.categories.includes("feel")) {
|
|
40
42
|
findings.push(...analyzeFeel(process, resolved));
|
|
@@ -58,7 +60,7 @@ export function optimize(defs, options) {
|
|
|
58
60
|
findings.push(...analyzeVariableFlow(process));
|
|
59
61
|
}
|
|
60
62
|
if (resolved.categories.includes("deploy") || resolved.categories.includes("connector")) {
|
|
61
|
-
const deployFindings = analyzeDeploy(process, resolved.resolveConnectorRequirements);
|
|
63
|
+
const deployFindings = analyzeDeploy(process, resolved.resolveConnectorRequirements, defs.messages);
|
|
62
64
|
findings.push(...deployFindings.filter((f) => (f.category === "deploy" && resolved.categories.includes("deploy")) ||
|
|
63
65
|
(f.category === "connector" && resolved.categories.includes("connector"))));
|
|
64
66
|
}
|
|
@@ -66,6 +68,13 @@ export function optimize(defs, options) {
|
|
|
66
68
|
findings.push(...analyzeAgentic(process));
|
|
67
69
|
}
|
|
68
70
|
}
|
|
71
|
+
// Camunda-version compatibility findings are deployability findings (category
|
|
72
|
+
// `deploy`, ids `compat/…`); a version pinned by a `.bpmnlintrc` asks for them
|
|
73
|
+
// even when the `deploy` category is off, as on a model that names no platform.
|
|
74
|
+
if (resolved.categories.includes("deploy") || options?.camundaVersion !== undefined) {
|
|
75
|
+
findings.push(...analyzeCamundaCompat(defs, resolved.camundaVersion));
|
|
76
|
+
findings = dedupeCamundaCompat(findings);
|
|
77
|
+
}
|
|
69
78
|
const byCategory = Object.fromEntries(ALL_CATEGORIES.map((c) => [c, findings.filter((f) => f.category === c).length]));
|
|
70
79
|
const bySeverity = Object.fromEntries(["info", "warning", "error"].map((s) => [
|
|
71
80
|
s,
|
|
@@ -227,6 +227,9 @@ export function analyzePatterns(p) {
|
|
|
227
227
|
if (el.type !== "exclusiveGateway")
|
|
228
228
|
continue;
|
|
229
229
|
const outflows = bySource.get(el.id) ?? [];
|
|
230
|
+
// Several ways in and one out is a join, which is what a join should look like.
|
|
231
|
+
if ((byTarget.get(el.id) ?? []).length > 1)
|
|
232
|
+
continue;
|
|
230
233
|
if (outflows.length === 1) {
|
|
231
234
|
findings.push({
|
|
232
235
|
id: "pattern/gateway-single-outgoing",
|
|
@@ -20,6 +20,11 @@ export interface OptimizationFinding {
|
|
|
20
20
|
produces?: string[];
|
|
21
21
|
/** Data-flow: variable names consumed (read) by the associated element. */
|
|
22
22
|
consumes?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The bpmnlint rule this finding was reported under, when a `.bpmnlintrc`
|
|
25
|
+
* governs it (see `applyBpmnlintConfig`).
|
|
26
|
+
*/
|
|
27
|
+
bpmnlintRule?: string;
|
|
23
28
|
}
|
|
24
29
|
export interface OptimizationReport {
|
|
25
30
|
findings: OptimizationFinding[];
|
|
@@ -44,6 +49,14 @@ export interface OptimizeOptions {
|
|
|
44
49
|
* are skipped (core has no dependency on the connector catalog).
|
|
45
50
|
*/
|
|
46
51
|
resolveConnectorRequirements?: (templateId: string, boundKeys: string[]) => string[];
|
|
52
|
+
/**
|
|
53
|
+
* The Camunda 8 version the `compat/…` findings check against, e.g. `"8.6"`.
|
|
54
|
+
* Given explicitly, the compatibility check runs even when the `deploy`
|
|
55
|
+
* category is not requested.
|
|
56
|
+
* Defaults to the model's `modeler:executionPlatformVersion`; without either,
|
|
57
|
+
* `compat` reports nothing.
|
|
58
|
+
*/
|
|
59
|
+
camundaVersion?: string;
|
|
47
60
|
}
|
|
48
61
|
export interface ResolvedOptions {
|
|
49
62
|
feelLengthThreshold: number;
|
|
@@ -53,5 +66,6 @@ export interface ResolvedOptions {
|
|
|
53
66
|
reuseThreshold: number;
|
|
54
67
|
categories: OptimizationCategory[];
|
|
55
68
|
resolveConnectorRequirements?: (templateId: string, boundKeys: string[]) => string[];
|
|
69
|
+
camundaVersion?: string;
|
|
56
70
|
}
|
|
57
71
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { parseExpression } from "@bpmnkit/feel";
|
|
1
|
+
import { builtinNames, parseExpression } from "@bpmnkit/feel";
|
|
2
2
|
import { buildFlowIndex, readZeebeIoMapping, readZeebeTaskType } from "./utils.js";
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// FEEL built-in names (excluded from variable references)
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
|
+
// The engine's own registry, so a built-in added there is never mistaken for a
|
|
7
|
+
// variable here. The names listed below were here first and stay as a floor.
|
|
6
8
|
const FEEL_BUILTINS = new Set([
|
|
9
|
+
...builtinNames(),
|
|
7
10
|
"string",
|
|
8
11
|
"string length",
|
|
9
12
|
"substring",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A change script: what a language model writes to change a diagram that
|
|
3
|
+
* already exists, in the line format of {@link PROCESS_TEXT_GUIDE}.
|
|
4
|
+
*
|
|
5
|
+
* Writing the whole diagram again works for a draft of ten nodes. For a
|
|
6
|
+
* diagram someone drew and shared, it costs output in proportion to the
|
|
7
|
+
* diagram rather than to the change, and anything the line format cannot
|
|
8
|
+
* express — lanes, data objects, the inside of a sub-process — would be lost
|
|
9
|
+
* on the way back. A change script names only what changes, so what it does
|
|
10
|
+
* not mention stays as it was by construction
|
|
11
|
+
* (`doc/drop-ai-feedback-edits-analysis.md` §3).
|
|
12
|
+
*
|
|
13
|
+
* This module only reads the script. Resolving its ids against a diagram and
|
|
14
|
+
* applying it is the editor's `applyProcessDelta`, which keeps the layout.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
import type { BpmnElementType } from "./bpmn-model.js";
|
|
19
|
+
import type { CompactFlow } from "./compact.js";
|
|
20
|
+
import { type ProcessTextProblem } from "./process-text.js";
|
|
21
|
+
/**
|
|
22
|
+
* Kind words the writer uses for element types the line format cannot create.
|
|
23
|
+
* A script may restate them on an existing node; it cannot declare a new one.
|
|
24
|
+
*/
|
|
25
|
+
export declare const FIXED_KINDS: Readonly<Record<string, BpmnElementType>>;
|
|
26
|
+
/**
|
|
27
|
+
* How to write a change script — the part of a system prompt that teaches it,
|
|
28
|
+
* after {@link PROCESS_TEXT_GUIDE}. A test parses its example and expects no
|
|
29
|
+
* problems.
|
|
30
|
+
*/
|
|
31
|
+
export declare const PROCESS_DELTA_GUIDE = "Change script \u2014 write only what changes, one line each:\na > new[kind Name] > b add nodes and flows; an existing node is written by its id only\na >(Label: condition) b add a flow; restating an existing flow with a new label changes it\nx[kind Name] an existing id declared again changes its kind or name\n- a > b remove the flow from a to b\n- x remove node x and its flows\n@2 x y feedback item 2 is answered by the changes to x and y\nRules:\n- Use the ids of the diagram you were given. Never repeat a line that changes nothing.\n- A new node written between two connected nodes (a > new > b) replaces the flow a > b.\n- Removing a node with one way in and one way out joins the two.\n- End with one @ line for each feedback item you answered.\n\nExample:\ncheck > second[user Second approval] > pay\nreview[user Review application]\n- notify\n@1 second\n@2 review";
|
|
32
|
+
/** A node the script declares: a new one, or a change to an existing one. */
|
|
33
|
+
export interface DeltaNode {
|
|
34
|
+
/** The id as written. */
|
|
35
|
+
id: string;
|
|
36
|
+
/** The kind, when the declaration names one. Absent: a rename only. */
|
|
37
|
+
type?: BpmnElementType;
|
|
38
|
+
/** The event trigger after `kind:`. */
|
|
39
|
+
trigger?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
/** Boundary host, from `on=`. */
|
|
42
|
+
on?: string;
|
|
43
|
+
/** Zeebe job type, from `job=`. */
|
|
44
|
+
jobType?: string;
|
|
45
|
+
/** `nonint`: a non-interrupting boundary or start event. */
|
|
46
|
+
interrupting?: false;
|
|
47
|
+
line: number;
|
|
48
|
+
}
|
|
49
|
+
/** A flow the script adds, or restates with a new label. */
|
|
50
|
+
export interface DeltaFlow extends Pick<CompactFlow, "from" | "to" | "name" | "condition"> {
|
|
51
|
+
isDefault?: true;
|
|
52
|
+
line: number;
|
|
53
|
+
}
|
|
54
|
+
/** What {@link parseProcessDelta} read. Nothing is resolved against a diagram yet. */
|
|
55
|
+
export interface ProcessDelta {
|
|
56
|
+
/** Declarations, in the order written. A node declared twice is kept once, first wins. */
|
|
57
|
+
nodes: DeltaNode[];
|
|
58
|
+
/** Flows, in the order written. */
|
|
59
|
+
flows: DeltaFlow[];
|
|
60
|
+
/** `- x` lines. */
|
|
61
|
+
removedNodes: {
|
|
62
|
+
id: string;
|
|
63
|
+
line: number;
|
|
64
|
+
}[];
|
|
65
|
+
/** `- a > b` lines, one entry per arrow. */
|
|
66
|
+
removedFlows: {
|
|
67
|
+
from: string;
|
|
68
|
+
to: string;
|
|
69
|
+
line: number;
|
|
70
|
+
}[];
|
|
71
|
+
/** `@n` lines: the feedback item, and the ids the script says answer it. */
|
|
72
|
+
addressed: {
|
|
73
|
+
item: number;
|
|
74
|
+
ids: string[];
|
|
75
|
+
line: number;
|
|
76
|
+
}[];
|
|
77
|
+
/** Lines, or parts of lines, that were left out. */
|
|
78
|
+
problems: ProcessTextProblem[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Reads a change script ({@link PROCESS_DELTA_GUIDE}).
|
|
82
|
+
*
|
|
83
|
+
* Never throws: what it cannot read is reported in `problems` and left out.
|
|
84
|
+
* Ids are taken as written; whether they name anything is for the caller to
|
|
85
|
+
* decide against the diagram the script was written for.
|
|
86
|
+
*/
|
|
87
|
+
export declare function parseProcessDelta(text: string): ProcessDelta;
|
|
88
|
+
//# sourceMappingURL=process-delta.d.ts.map
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A change script: what a language model writes to change a diagram that
|
|
3
|
+
* already exists, in the line format of {@link PROCESS_TEXT_GUIDE}.
|
|
4
|
+
*
|
|
5
|
+
* Writing the whole diagram again works for a draft of ten nodes. For a
|
|
6
|
+
* diagram someone drew and shared, it costs output in proportion to the
|
|
7
|
+
* diagram rather than to the change, and anything the line format cannot
|
|
8
|
+
* express — lanes, data objects, the inside of a sub-process — would be lost
|
|
9
|
+
* on the way back. A change script names only what changes, so what it does
|
|
10
|
+
* not mention stays as it was by construction
|
|
11
|
+
* (`doc/drop-ai-feedback-edits-analysis.md` §3).
|
|
12
|
+
*
|
|
13
|
+
* This module only reads the script. Resolving its ids against a diagram and
|
|
14
|
+
* applying it is the editor's `applyProcessDelta`, which keeps the layout.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
import { ALIASES, KINDS, TRIGGERS, edgeLabel, tokenizePath, } from "./process-text.js";
|
|
19
|
+
/**
|
|
20
|
+
* Kind words the writer uses for element types the line format cannot create.
|
|
21
|
+
* A script may restate them on an existing node; it cannot declare a new one.
|
|
22
|
+
*/
|
|
23
|
+
export const FIXED_KINDS = {
|
|
24
|
+
sub: "subProcess",
|
|
25
|
+
adhoc: "adHocSubProcess",
|
|
26
|
+
transaction: "transaction",
|
|
27
|
+
complex: "complexGateway",
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* How to write a change script — the part of a system prompt that teaches it,
|
|
31
|
+
* after {@link PROCESS_TEXT_GUIDE}. A test parses its example and expects no
|
|
32
|
+
* problems.
|
|
33
|
+
*/
|
|
34
|
+
export const PROCESS_DELTA_GUIDE = `Change script — write only what changes, one line each:
|
|
35
|
+
a > new[kind Name] > b add nodes and flows; an existing node is written by its id only
|
|
36
|
+
a >(Label: condition) b add a flow; restating an existing flow with a new label changes it
|
|
37
|
+
x[kind Name] an existing id declared again changes its kind or name
|
|
38
|
+
- a > b remove the flow from a to b
|
|
39
|
+
- x remove node x and its flows
|
|
40
|
+
@2 x y feedback item 2 is answered by the changes to x and y
|
|
41
|
+
Rules:
|
|
42
|
+
- Use the ids of the diagram you were given. Never repeat a line that changes nothing.
|
|
43
|
+
- A new node written between two connected nodes (a > new > b) replaces the flow a > b.
|
|
44
|
+
- Removing a node with one way in and one way out joins the two.
|
|
45
|
+
- End with one @ line for each feedback item you answered.
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
check > second[user Second approval] > pay
|
|
49
|
+
review[user Review application]
|
|
50
|
+
- notify
|
|
51
|
+
@1 second
|
|
52
|
+
@2 review`;
|
|
53
|
+
/**
|
|
54
|
+
* One id, or several separated by commas. Not by spaces: a model's prose bullet
|
|
55
|
+
* ("- review is removed") would otherwise remove every word that is an id.
|
|
56
|
+
*/
|
|
57
|
+
const ID_LIST = /^[A-Za-z_][\w.-]*(\s*,\s*[A-Za-z_][\w.-]*)*$/;
|
|
58
|
+
/** A line that ends in an arrow: the path goes on below, as in the line format. */
|
|
59
|
+
const DANGLING = /\s*-{0,2}>\s*(\([^()]*\))?\s*$/;
|
|
60
|
+
/** Reads one declaration's bracket text. */
|
|
61
|
+
function readSpec(id, spec, line, problems) {
|
|
62
|
+
const node = { id, line };
|
|
63
|
+
const bar = spec.indexOf("|");
|
|
64
|
+
const head = (bar < 0 ? spec : spec.slice(0, bar)).trim();
|
|
65
|
+
const attrs = bar < 0 ? "" : spec.slice(bar + 1);
|
|
66
|
+
const space = head.search(/\s/);
|
|
67
|
+
const word = space < 0 ? head : head.slice(0, space);
|
|
68
|
+
const [kindWord = "", trigger] = word.toLowerCase().split(":");
|
|
69
|
+
const type = KINDS[kindWord] ?? ALIASES[kindWord] ?? FIXED_KINDS[kindWord];
|
|
70
|
+
if (type === undefined) {
|
|
71
|
+
// `review[Review application]`: no kind, so the whole head is the new name.
|
|
72
|
+
if (head)
|
|
73
|
+
node.name = head;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
node.type = type;
|
|
77
|
+
const name = space < 0 ? "" : head.slice(space + 1).trim();
|
|
78
|
+
if (name)
|
|
79
|
+
node.name = name;
|
|
80
|
+
if (trigger !== undefined) {
|
|
81
|
+
if (TRIGGERS.has(trigger))
|
|
82
|
+
node.trigger = trigger;
|
|
83
|
+
else
|
|
84
|
+
problems.push({ line, message: `unknown trigger "${trigger}" for "${id}"; ignored` });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const attr of attrs.split(/[\s,|]+/).filter(Boolean)) {
|
|
88
|
+
const [key, value] = attr.split("=", 2);
|
|
89
|
+
if (key === "on" && value)
|
|
90
|
+
node.on = value;
|
|
91
|
+
else if (key === "job" && value)
|
|
92
|
+
node.jobType = value;
|
|
93
|
+
else if (key === "nonint" && value === undefined)
|
|
94
|
+
node.interrupting = false;
|
|
95
|
+
else
|
|
96
|
+
problems.push({ line, message: `unknown attribute "${attr}" on "${id}"; ignored` });
|
|
97
|
+
}
|
|
98
|
+
return node;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Reads a change script ({@link PROCESS_DELTA_GUIDE}).
|
|
102
|
+
*
|
|
103
|
+
* Never throws: what it cannot read is reported in `problems` and left out.
|
|
104
|
+
* Ids are taken as written; whether they name anything is for the caller to
|
|
105
|
+
* decide against the diagram the script was written for.
|
|
106
|
+
*/
|
|
107
|
+
export function parseProcessDelta(text) {
|
|
108
|
+
const delta = {
|
|
109
|
+
nodes: [],
|
|
110
|
+
flows: [],
|
|
111
|
+
removedNodes: [],
|
|
112
|
+
removedFlows: [],
|
|
113
|
+
addressed: [],
|
|
114
|
+
problems: [],
|
|
115
|
+
};
|
|
116
|
+
const declared = new Map();
|
|
117
|
+
let carry;
|
|
118
|
+
const path = (raw, n) => {
|
|
119
|
+
const tokens = tokenizePath(raw);
|
|
120
|
+
if ("error" in tokens) {
|
|
121
|
+
delta.problems.push({ line: n, message: tokens.error });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (tokens.note !== undefined) {
|
|
125
|
+
delta.problems.push({ line: n, message: `ignored the note "${tokens.note}"` });
|
|
126
|
+
}
|
|
127
|
+
for (const ref of tokens.refs) {
|
|
128
|
+
if (ref.spec === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
const node = readSpec(ref.id, ref.spec, n, delta.problems);
|
|
131
|
+
const earlier = declared.get(ref.id);
|
|
132
|
+
if (earlier) {
|
|
133
|
+
delta.problems.push({
|
|
134
|
+
line: n,
|
|
135
|
+
message: `"${ref.id}" is already declared on line ${earlier.line}; ignored "${ref.spec}"`,
|
|
136
|
+
});
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
declared.set(ref.id, node);
|
|
140
|
+
delta.nodes.push(node);
|
|
141
|
+
}
|
|
142
|
+
tokens.labels.forEach((raw, k) => {
|
|
143
|
+
const from = tokens.refs[k]?.id;
|
|
144
|
+
const to = tokens.refs[k + 1]?.id;
|
|
145
|
+
if (from === undefined || to === undefined)
|
|
146
|
+
return;
|
|
147
|
+
// The condition is kept as written, FEEL or not: restating a flow in another
|
|
148
|
+
// expression language must not change it. The applier checks a condition
|
|
149
|
+
// it is about to write.
|
|
150
|
+
const edge = edgeLabel(raw);
|
|
151
|
+
const flow = { from, to, line: n };
|
|
152
|
+
if (edge.name !== undefined)
|
|
153
|
+
flow.name = edge.name;
|
|
154
|
+
if (edge.condition !== undefined)
|
|
155
|
+
flow.condition = edge.condition;
|
|
156
|
+
if (edge.isDefault)
|
|
157
|
+
flow.isDefault = true;
|
|
158
|
+
delta.flows.push(flow);
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const removal = (rest, n) => {
|
|
162
|
+
if (ID_LIST.test(rest) && !rest.includes(">")) {
|
|
163
|
+
for (const id of rest.split(/[\s,]+/).filter(Boolean)) {
|
|
164
|
+
delta.removedNodes.push({ id, line: n });
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (!rest.includes(">")) {
|
|
169
|
+
delta.problems.push({
|
|
170
|
+
line: n,
|
|
171
|
+
message: `expected "- <id>" or "- <id> > <id>" at "${rest.slice(0, 30)}"`,
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const tokens = tokenizePath(rest);
|
|
176
|
+
if ("error" in tokens) {
|
|
177
|
+
delta.problems.push({ line: n, message: tokens.error });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
for (let k = 0; k + 1 < tokens.refs.length; k++) {
|
|
181
|
+
const from = tokens.refs[k]?.id;
|
|
182
|
+
const to = tokens.refs[k + 1]?.id;
|
|
183
|
+
if (from !== undefined && to !== undefined)
|
|
184
|
+
delta.removedFlows.push({ from, to, line: n });
|
|
185
|
+
}
|
|
186
|
+
if (tokens.refs.some((ref) => ref.spec !== undefined)) {
|
|
187
|
+
delta.problems.push({ line: n, message: "a removal names ids only; ignored the brackets" });
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const lines = text.split(/\r?\n/);
|
|
191
|
+
lines.forEach((raw, index) => {
|
|
192
|
+
const n = index + 1;
|
|
193
|
+
let line = raw.trim();
|
|
194
|
+
if (carry !== undefined) {
|
|
195
|
+
if (line === "")
|
|
196
|
+
return;
|
|
197
|
+
line = `${carry.text} ${line}`;
|
|
198
|
+
carry = undefined;
|
|
199
|
+
}
|
|
200
|
+
if (line === "" || line.startsWith("```") || line.startsWith("//") || line.startsWith("#")) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (line.startsWith("@")) {
|
|
204
|
+
const match = /^@\s*(\d+)\s*:?\s*(.*)$/.exec(line);
|
|
205
|
+
const item = match ? Number.parseInt(match[1] ?? "", 10) : Number.NaN;
|
|
206
|
+
if (!match || !Number.isFinite(item)) {
|
|
207
|
+
delta.problems.push({ line: n, message: `expected "@<feedback number> <ids>"` });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const ids = (match[2] ?? "").split(/[\s,]+/).filter((id) => /^[A-Za-z_][\w.-]*$/.test(id));
|
|
211
|
+
delta.addressed.push({ item, ids, line: n });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// `- x` removes; `-> x` is an arrow a model wrote at the start of a line.
|
|
215
|
+
const removed = /^-(?![->])\s*(.*)$/.exec(line);
|
|
216
|
+
if (removed) {
|
|
217
|
+
removal((removed[1] ?? "").trim(), n);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (DANGLING.test(line)) {
|
|
221
|
+
carry = { text: line, line: n };
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
path(line, n);
|
|
225
|
+
});
|
|
226
|
+
if (carry !== undefined) {
|
|
227
|
+
const { text: rest, line } = carry;
|
|
228
|
+
delta.problems.push({
|
|
229
|
+
line,
|
|
230
|
+
message: 'the line ends with ">" and nothing follows; read without it',
|
|
231
|
+
});
|
|
232
|
+
path(rest.replace(DANGLING, ""), line);
|
|
233
|
+
}
|
|
234
|
+
return delta;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=process-delta.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes an existing diagram in the line format of {@link PROCESS_TEXT_GUIDE},
|
|
3
|
+
* so a language model can read it — and answer with a change script
|
|
4
|
+
* ({@link PROCESS_DELTA_GUIDE}) that names its nodes by id.
|
|
5
|
+
*
|
|
6
|
+
* Written ids are short aliases: a Modeler id such as `Activity_0x9k2lm` costs
|
|
7
|
+
* several tokens and tells the model nothing, so each node is written under a
|
|
8
|
+
* name-derived alias (`review_application`) and the map back to the real id is
|
|
9
|
+
* returned beside the text. An id that is already short and readable is kept.
|
|
10
|
+
*
|
|
11
|
+
* Only what the format can express is written: the first process's flow nodes
|
|
12
|
+
* and sequence flows. Lanes, data objects, annotations, event sub-processes and
|
|
13
|
+
* the inside of a sub-process are left out. A script cannot name what it was
|
|
14
|
+
* never shown, so those parts cannot be changed by it either.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
import type { BpmnDefinitions } from "./bpmn-model.js";
|
|
19
|
+
/** What {@link writeProcessText} wrote. */
|
|
20
|
+
export interface WrittenProcessText {
|
|
21
|
+
/** The diagram in the line format. */
|
|
22
|
+
text: string;
|
|
23
|
+
/** Every written id, mapped to the element id it stands for. */
|
|
24
|
+
aliases: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A name as it can be written inside brackets: on one line, with no bracket
|
|
28
|
+
* or bar to end the declaration early. The change applier compares a restated
|
|
29
|
+
* name against this, so writing it back unchanged is no rename.
|
|
30
|
+
*/
|
|
31
|
+
export declare function writableName(name: string): string;
|
|
32
|
+
/** A flow name as it can be written in an arrow label, which a colon or parenthesis would end. */
|
|
33
|
+
export declare function writableLabel(name: string): string;
|
|
34
|
+
/** A FEEL condition without its leading `=`, on one line. */
|
|
35
|
+
export declare function writableCondition(condition: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Writes the first process of `definitions` in the line format.
|
|
38
|
+
*
|
|
39
|
+
* Paths start at the start events and follow the flows; each flow is written
|
|
40
|
+
* once and each node is declared where it first appears. A boundary event
|
|
41
|
+
* starts its own line once its host has been declared, and a node no path
|
|
42
|
+
* reaches is declared on a line of its own, so nothing the format can express
|
|
43
|
+
* is left out.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const { text, aliases } = writeProcessText(Bpmn.parse(xml))
|
|
48
|
+
* // text: "# Order\nstart[start Order placed] > check_order[service Check order] > …"
|
|
49
|
+
* // aliases: { start: "StartEvent_1", check_order: "Activity_0x9k2lm", … }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function writeProcessText(definitions: BpmnDefinitions): WrittenProcessText;
|
|
53
|
+
//# sourceMappingURL=process-text-writer.d.ts.map
|