@bpmnkit/core 1.1.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 +5 -0
- package/dist/bpmn/compact.d.ts +4 -0
- package/dist/bpmn/compact.js +80 -0
- package/dist/bpmn/optimize/patterns.js +3 -0
- 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/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -335,6 +335,10 @@ const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
|
|
|
335
335
|
| `compactify(defs)` | Convert to compact `CompactDiagram` |
|
|
336
336
|
| `expand(compact)` | Restore full `BpmnDefinitions` |
|
|
337
337
|
| `createCompactStream(opts?)` | Read a diagram out of a model's token stream, frame by frame |
|
|
338
|
+
| `parseProcessText(text)` | Read a process a model wrote in the line format (`PROCESS_TEXT_GUIDE`); never throws |
|
|
339
|
+
| `createProcessTextStream()` | Read the line format while it streams, one finished line at a time |
|
|
340
|
+
| `writeProcessText(defs)` | Write an existing diagram in the line format, for a model to read; returns the text and an alias → element id map |
|
|
341
|
+
| `parseProcessDelta(text)` | Read a change script (`PROCESS_DELTA_GUIDE`): only what changes, by id; never throws |
|
|
338
342
|
| `generateId(prefix)` | Generate a unique short ID |
|
|
339
343
|
|
|
340
344
|
### Process documentation
|
|
@@ -374,6 +378,7 @@ const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
|
|
|
374
378
|
| [`@bpmnkit/patterns`](https://www.npmjs.com/package/@bpmnkit/patterns) | Domain process patterns for BPMNKit AIKit |
|
|
375
379
|
| [`@bpmnkit/reebe-wasm`](https://www.npmjs.com/package/@bpmnkit/reebe-wasm) | WebAssembly BPMN engine for browser simulation |
|
|
376
380
|
| [`@bpmnkit/worker-client`](https://www.npmjs.com/package/@bpmnkit/worker-client) | Thin Zeebe REST client for standalone workers |
|
|
381
|
+
| [`@bpmnkit/flow`](https://www.npmjs.com/package/@bpmnkit/flow) | Code-first durable flows that derive BPMN, job types and workers |
|
|
377
382
|
| [`@bpmnkit/user-tasks`](https://www.npmjs.com/package/@bpmnkit/user-tasks) | Embeddable user task widget for Camunda 8 |
|
|
378
383
|
| [`@bpmnkit/cli-sdk`](https://www.npmjs.com/package/@bpmnkit/cli-sdk) | Plugin authoring SDK for the casen CLI |
|
|
379
384
|
| [`@bpmnkit/create-casen-plugin`](https://www.npmjs.com/package/@bpmnkit/create-casen-plugin) | Scaffold a new casen CLI plugin in seconds |
|
package/dist/bpmn/compact.d.ts
CHANGED
|
@@ -134,6 +134,10 @@ defaultFlow?: string): BpmnFlowElement;
|
|
|
134
134
|
* Restores a {@link CompactDiagram} (produced by {@link compactify} or an AI
|
|
135
135
|
* model) back to a full {@link BpmnDefinitions} with auto-generated layout.
|
|
136
136
|
*
|
|
137
|
+
* @throws {Error} When the diagram cannot be valid BPMN — a flow or boundary
|
|
138
|
+
* event naming an element that is not in its scope, a duplicate or missing id,
|
|
139
|
+
* or an unknown `eventType`. The message lists every problem at once.
|
|
140
|
+
*
|
|
137
141
|
* @example
|
|
138
142
|
* ```typescript
|
|
139
143
|
* const compact = await askAI(prompt) // AI returns CompactDiagram JSON
|
package/dist/bpmn/compact.js
CHANGED
|
@@ -165,6 +165,78 @@ export function compactify(defs) {
|
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
// ── Expand ───────────────────────────────────────────────────────────────────
|
|
168
|
+
const EVENT_TYPES = new Set([
|
|
169
|
+
"timer",
|
|
170
|
+
"error",
|
|
171
|
+
"message",
|
|
172
|
+
"signal",
|
|
173
|
+
"escalation",
|
|
174
|
+
"cancel",
|
|
175
|
+
"terminate",
|
|
176
|
+
"conditional",
|
|
177
|
+
"link",
|
|
178
|
+
"compensate",
|
|
179
|
+
]);
|
|
180
|
+
/**
|
|
181
|
+
* Every reason `compact` cannot become valid BPMN, as sentences naming the ids
|
|
182
|
+
* involved.
|
|
183
|
+
*
|
|
184
|
+
* `expand` used to build whatever it was given: an edge to an element that was
|
|
185
|
+
* never written came out as a `targetRef` pointing at nothing, a repeated id
|
|
186
|
+
* came out twice, a flow without an id came out without one, and an unknown
|
|
187
|
+
* `eventType` was dropped. Each is XML a modeler or an engine rejects later,
|
|
188
|
+
* with no trace back to here. A model writing the diagram makes all four
|
|
189
|
+
* mistakes, so the check is total and reports them together — one error that
|
|
190
|
+
* lists every problem is what a caller can hand back for a repair.
|
|
191
|
+
*/
|
|
192
|
+
function compactProblems(compact) {
|
|
193
|
+
const problems = [];
|
|
194
|
+
const seen = new Set();
|
|
195
|
+
const claim = (id, what) => {
|
|
196
|
+
if (seen.has(id))
|
|
197
|
+
problems.push(`duplicate id "${id}" (${what})`);
|
|
198
|
+
seen.add(id);
|
|
199
|
+
};
|
|
200
|
+
const checkScope = (elements, flows, scope) => {
|
|
201
|
+
const ids = new Set();
|
|
202
|
+
for (const el of elements) {
|
|
203
|
+
if (typeof el.id !== "string" || el.id === "") {
|
|
204
|
+
problems.push(`a ${el.type} in ${scope} has no id`);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
claim(el.id, el.type);
|
|
208
|
+
ids.add(el.id);
|
|
209
|
+
if (el.eventType !== undefined && !EVENT_TYPES.has(el.eventType)) {
|
|
210
|
+
problems.push(`element "${el.id}" has unknown eventType "${el.eventType}" (expected one of ${[...EVENT_TYPES].join(", ")})`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const el of elements) {
|
|
214
|
+
if (el.type === "boundaryEvent" && (el.attachedTo === undefined || !ids.has(el.attachedTo))) {
|
|
215
|
+
problems.push(el.attachedTo === undefined
|
|
216
|
+
? `boundary event "${el.id}" has no attachedTo`
|
|
217
|
+
: `boundary event "${el.id}" is attached to "${el.attachedTo}", which is not an element in ${scope}`);
|
|
218
|
+
}
|
|
219
|
+
if (el.children)
|
|
220
|
+
checkScope(el.children.elements, el.children.flows, `"${el.id}"`);
|
|
221
|
+
}
|
|
222
|
+
for (const flow of flows) {
|
|
223
|
+
const label = `flow ${flow.id ? `"${flow.id}"` : `from "${flow.from}" to "${flow.to}"`}`;
|
|
224
|
+
if (typeof flow.id !== "string" || flow.id === "")
|
|
225
|
+
problems.push(`${label} has no id`);
|
|
226
|
+
else
|
|
227
|
+
claim(flow.id, "sequence flow");
|
|
228
|
+
for (const end of [flow.from, flow.to]) {
|
|
229
|
+
if (!ids.has(end))
|
|
230
|
+
problems.push(`${label} references "${end}", which is not an element in ${scope}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
for (const process of compact.processes) {
|
|
235
|
+
claim(process.id, "process");
|
|
236
|
+
checkScope(process.elements, process.flows, `process "${process.id}"`);
|
|
237
|
+
}
|
|
238
|
+
return problems;
|
|
239
|
+
}
|
|
168
240
|
export function makeEventDef(eventType) {
|
|
169
241
|
switch (eventType) {
|
|
170
242
|
case "timer":
|
|
@@ -445,6 +517,10 @@ function expandProcess(compact) {
|
|
|
445
517
|
* Restores a {@link CompactDiagram} (produced by {@link compactify} or an AI
|
|
446
518
|
* model) back to a full {@link BpmnDefinitions} with auto-generated layout.
|
|
447
519
|
*
|
|
520
|
+
* @throws {Error} When the diagram cannot be valid BPMN — a flow or boundary
|
|
521
|
+
* event naming an element that is not in its scope, a duplicate or missing id,
|
|
522
|
+
* or an unknown `eventType`. The message lists every problem at once.
|
|
523
|
+
*
|
|
448
524
|
* @example
|
|
449
525
|
* ```typescript
|
|
450
526
|
* const compact = await askAI(prompt) // AI returns CompactDiagram JSON
|
|
@@ -455,6 +531,10 @@ function expandProcess(compact) {
|
|
|
455
531
|
*/
|
|
456
532
|
export function expand(compact) {
|
|
457
533
|
assertCompactDiagram(compact, "expand");
|
|
534
|
+
const problems = compactProblems(compact);
|
|
535
|
+
if (problems.length > 0) {
|
|
536
|
+
throw new Error(`expand: invalid CompactDiagram — ${problems.join("; ")}`);
|
|
537
|
+
}
|
|
458
538
|
const processes = [];
|
|
459
539
|
const diagrams = [];
|
|
460
540
|
for (const cp of compact.processes) {
|
|
@@ -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",
|
|
@@ -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
|