@bpmnkit/core 1.1.0 → 1.3.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 +31 -0
- package/dist/bpmn/bpmn-builder.d.ts +8 -0
- package/dist/bpmn/bpmn-builder.js +6 -2
- package/dist/bpmn/compact.d.ts +37 -5
- package/dist/bpmn/compact.js +218 -30
- package/dist/bpmn/connector-line.d.ts +46 -0
- package/dist/bpmn/connector-line.js +135 -0
- package/dist/bpmn/optimize/patterns.js +4 -3
- package/dist/bpmn/process-delta.d.ts +91 -0
- package/dist/bpmn/process-delta.js +259 -0
- package/dist/bpmn/process-text-writer.d.ts +63 -0
- package/dist/bpmn/process-text-writer.js +202 -0
- package/dist/bpmn/process-text.d.ts +200 -0
- package/dist/bpmn/process-text.js +1568 -0
- package/dist/bpmn/rest-connector.d.ts +6 -0
- package/dist/bpmn/rest-connector.js +6 -0
- package/dist/bpmn/secrets.d.ts +15 -0
- package/dist/bpmn/secrets.js +59 -0
- package/dist/bpmn/utils.js +4 -0
- package/dist/bpmn/zeebe-extensions.d.ts +10 -0
- package/dist/bpmn/zeebe-extensions.js +7 -0
- package/dist/connectors/aliases.d.ts +21 -0
- package/dist/connectors/aliases.js +272 -0
- package/dist/connectors/api.d.ts +118 -0
- package/dist/connectors/api.js +280 -0
- package/dist/connectors/apply-element.d.ts +59 -0
- package/dist/connectors/apply-element.js +385 -0
- package/dist/connectors/apply.d.ts +136 -0
- package/dist/connectors/apply.js +352 -0
- package/dist/connectors/cards.d.ts +96 -0
- package/dist/connectors/cards.js +306 -0
- package/dist/connectors/catalog.d.ts +79 -0
- package/dist/connectors/catalog.js +209 -0
- package/dist/connectors/index.d.ts +33 -0
- package/dist/connectors/index.js +24 -0
- package/dist/connectors/lines.d.ts +108 -0
- package/dist/connectors/lines.js +568 -0
- package/dist/connectors/select.d.ts +85 -0
- package/dist/connectors/select.js +419 -0
- package/dist/connectors/template-types.d.ts +188 -0
- package/dist/connectors/template-types.js +6 -0
- package/dist/connectors/templates/bpmnkit.d.ts +12 -0
- package/dist/connectors/templates/bpmnkit.js +186 -0
- package/dist/connectors/templates/generated.d.ts +3 -0
- package/dist/connectors/templates/generated.js +95885 -0
- package/dist/connectors/validate.d.ts +66 -0
- package/dist/connectors/validate.js +271 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +5 -0
- package/package.json +5 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `with` lines: how a model configures a connector in the line format.
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* with post: slack chat.postMessage | data.channel=#ops | data.text== "Order " + orderId
|
|
6
|
+
* with fetch: http GET https://api.example.com/orders | result=order
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* A line names a node already written by its id, the connector by its alias,
|
|
10
|
+
* the operation when the connector has several, and the inputs as
|
|
11
|
+
* `key=value` (`key==expr` for FEEL). Path lines are unchanged, so a `with`
|
|
12
|
+
* line can follow anywhere and a diagram streams as before.
|
|
13
|
+
*
|
|
14
|
+
* This module only reads the line. Which connector an alias names, which keys
|
|
15
|
+
* it has and what it writes is `@bpmnkit/core/connectors`' part, so the parser
|
|
16
|
+
* stays free of the catalog's data.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
/** `with <id>:` at the start of a line. */
|
|
21
|
+
export const CONNECTOR_LINE = /^with\s+([A-Za-z_][\w.-]*)\s*:\s*(.*)$/i;
|
|
22
|
+
/** Splits on `|` outside quotes, brackets, braces and parentheses. */
|
|
23
|
+
function splitParts(text) {
|
|
24
|
+
const parts = [];
|
|
25
|
+
let depth = 0;
|
|
26
|
+
let quote;
|
|
27
|
+
let start = 0;
|
|
28
|
+
for (let i = 0; i < text.length; i++) {
|
|
29
|
+
const ch = text[i];
|
|
30
|
+
if (quote !== undefined) {
|
|
31
|
+
if (ch === "\\")
|
|
32
|
+
i++;
|
|
33
|
+
else if (ch === quote)
|
|
34
|
+
quote = undefined;
|
|
35
|
+
}
|
|
36
|
+
else if (ch === '"' || ch === "'")
|
|
37
|
+
quote = ch;
|
|
38
|
+
else if (ch === "(" || ch === "[" || ch === "{")
|
|
39
|
+
depth++;
|
|
40
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
41
|
+
depth = Math.max(0, depth - 1);
|
|
42
|
+
else if (ch === "|" && depth === 0) {
|
|
43
|
+
parts.push(text.slice(start, i));
|
|
44
|
+
start = i + 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
parts.push(text.slice(start));
|
|
48
|
+
return parts.map((p) => p.trim());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `a=1 b=2 c==x + 1`, several inputs in one part as the cards list them, split
|
|
52
|
+
* into one part each: at a space before `key=`, outside quotes and brackets.
|
|
53
|
+
* A FEEL value runs to the end of the part, as it may hold `=` itself.
|
|
54
|
+
*/
|
|
55
|
+
function splitPairs(part) {
|
|
56
|
+
const pairs = [];
|
|
57
|
+
let depth = 0;
|
|
58
|
+
let quote;
|
|
59
|
+
let start = 0;
|
|
60
|
+
for (let i = 0; i < part.length; i++) {
|
|
61
|
+
const ch = part[i];
|
|
62
|
+
if (quote !== undefined) {
|
|
63
|
+
if (ch === "\\")
|
|
64
|
+
i++;
|
|
65
|
+
else if (ch === quote)
|
|
66
|
+
quote = undefined;
|
|
67
|
+
}
|
|
68
|
+
else if (ch === '"' || ch === "'")
|
|
69
|
+
quote = ch;
|
|
70
|
+
else if (ch === "(" || ch === "[" || ch === "{")
|
|
71
|
+
depth++;
|
|
72
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
73
|
+
depth = Math.max(0, depth - 1);
|
|
74
|
+
else if (ch === "=" && part[i + 1] === "=" && depth === 0)
|
|
75
|
+
break;
|
|
76
|
+
else if (/\s/.test(ch ?? "") && depth === 0 && /^\s+[A-Za-z_][\w.]*\*?=/.test(part.slice(i))) {
|
|
77
|
+
pairs.push(part.slice(start, i));
|
|
78
|
+
start = i + 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
pairs.push(part.slice(start));
|
|
82
|
+
return pairs.map((p) => p.trim()).filter((p) => p !== "");
|
|
83
|
+
}
|
|
84
|
+
function headWords(head) {
|
|
85
|
+
const words = [];
|
|
86
|
+
let rest = head.trim();
|
|
87
|
+
while (rest !== "") {
|
|
88
|
+
if (rest.startsWith("=") || rest.startsWith('"') || rest.startsWith("'")) {
|
|
89
|
+
words.push(rest);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
const space = rest.search(/\s/);
|
|
93
|
+
words.push(space < 0 ? rest : rest.slice(0, space));
|
|
94
|
+
rest = space < 0 ? "" : rest.slice(space).trim();
|
|
95
|
+
}
|
|
96
|
+
return words;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads a `with` line, or answers `undefined` when the line is not one.
|
|
100
|
+
*
|
|
101
|
+
* Never throws: a line that starts like one but cannot be read becomes a
|
|
102
|
+
* problem, and the parts it could read are kept.
|
|
103
|
+
*/
|
|
104
|
+
export function parseConnectorLine(text, line, problems) {
|
|
105
|
+
const match = CONNECTOR_LINE.exec(text.trim());
|
|
106
|
+
if (!match)
|
|
107
|
+
return undefined;
|
|
108
|
+
const [, id = "", body = ""] = match;
|
|
109
|
+
const [head = "", ...rest] = splitParts(body);
|
|
110
|
+
const [alias, ...args] = headWords(head);
|
|
111
|
+
if (alias === undefined) {
|
|
112
|
+
problems.push({ line, message: `"with ${id}:" names no connector; ignored` });
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const values = {};
|
|
116
|
+
for (const part of rest.flatMap(splitPairs)) {
|
|
117
|
+
const eq = part.indexOf("=");
|
|
118
|
+
// `token*={{secrets.T}}`: the card's required mark copied with the key
|
|
119
|
+
const key = eq < 0 ? "" : part.slice(0, eq).trim().replace(/\*$/, "");
|
|
120
|
+
if (eq <= 0 || !/^[\w.:$-]+$/.test(key)) {
|
|
121
|
+
problems.push({ line, message: `expected "key=value" at "${part.slice(0, 30)}"; ignored` });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
values[key] = part.slice(eq + 1).trim();
|
|
125
|
+
}
|
|
126
|
+
// A URL where the alias goes keeps its case: paths are case-sensitive
|
|
127
|
+
return {
|
|
128
|
+
id,
|
|
129
|
+
alias: /^https?:\/\//i.test(alias) ? alias : alias.toLowerCase(),
|
|
130
|
+
args,
|
|
131
|
+
values,
|
|
132
|
+
line,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=connector-line.js.map
|
|
@@ -49,9 +49,7 @@ export function analyzePatterns(p) {
|
|
|
49
49
|
if (el.type !== "serviceTask")
|
|
50
50
|
continue;
|
|
51
51
|
const jobType = readZeebeTaskType(el.extensionElements) ?? "";
|
|
52
|
-
const isHttp = jobType.toLowerCase().includes("http") ||
|
|
53
|
-
jobType.toLowerCase().includes("rest") ||
|
|
54
|
-
jobType === "io.camunda.connector.HttpJson:1";
|
|
52
|
+
const isHttp = jobType.toLowerCase().includes("http") || jobType.toLowerCase().includes("rest");
|
|
55
53
|
if (!isHttp)
|
|
56
54
|
continue;
|
|
57
55
|
if (!hasBoundaryOf(el.id, "error", boundaryTypes)) {
|
|
@@ -227,6 +225,9 @@ export function analyzePatterns(p) {
|
|
|
227
225
|
if (el.type !== "exclusiveGateway")
|
|
228
226
|
continue;
|
|
229
227
|
const outflows = bySource.get(el.id) ?? [];
|
|
228
|
+
// Several ways in and one out is a join, which is what a join should look like.
|
|
229
|
+
if ((byTarget.get(el.id) ?? []).length > 1)
|
|
230
|
+
continue;
|
|
230
231
|
if (outflows.length === 1) {
|
|
231
232
|
findings.push({
|
|
232
233
|
id: "pattern/gateway-single-outgoing",
|
|
@@ -0,0 +1,91 @@
|
|
|
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 ConnectorLine } from "./connector-line.js";
|
|
21
|
+
import { type ProcessTextProblem } from "./process-text.js";
|
|
22
|
+
/**
|
|
23
|
+
* Kind words the writer uses for element types the line format cannot create.
|
|
24
|
+
* A script may restate them on an existing node; it cannot declare a new one.
|
|
25
|
+
*/
|
|
26
|
+
export declare const FIXED_KINDS: Readonly<Record<string, BpmnElementType>>;
|
|
27
|
+
/**
|
|
28
|
+
* How to write a change script — the part of a system prompt that teaches it,
|
|
29
|
+
* after {@link PROCESS_TEXT_GUIDE}. A test parses its example and expects no
|
|
30
|
+
* problems.
|
|
31
|
+
*/
|
|
32
|
+
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";
|
|
33
|
+
/** A node the script declares: a new one, or a change to an existing one. */
|
|
34
|
+
export interface DeltaNode {
|
|
35
|
+
/** The id as written. */
|
|
36
|
+
id: string;
|
|
37
|
+
/** The kind, when the declaration names one. Absent: a rename only. */
|
|
38
|
+
type?: BpmnElementType;
|
|
39
|
+
/** The event trigger after `kind:`. */
|
|
40
|
+
trigger?: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
/** Boundary host, from `on=`. */
|
|
43
|
+
on?: string;
|
|
44
|
+
/** Zeebe job type, from `job=`. */
|
|
45
|
+
jobType?: string;
|
|
46
|
+
/** `nonint`: a non-interrupting boundary or start event. */
|
|
47
|
+
interrupting?: false;
|
|
48
|
+
line: number;
|
|
49
|
+
}
|
|
50
|
+
/** A flow the script adds, or restates with a new label. */
|
|
51
|
+
export interface DeltaFlow extends Pick<CompactFlow, "from" | "to" | "name" | "condition"> {
|
|
52
|
+
isDefault?: true;
|
|
53
|
+
line: number;
|
|
54
|
+
}
|
|
55
|
+
/** What {@link parseProcessDelta} read. Nothing is resolved against a diagram yet. */
|
|
56
|
+
export interface ProcessDelta {
|
|
57
|
+
/** Declarations, in the order written. A node declared twice is kept once, first wins. */
|
|
58
|
+
nodes: DeltaNode[];
|
|
59
|
+
/** Flows, in the order written. */
|
|
60
|
+
flows: DeltaFlow[];
|
|
61
|
+
/** `- x` lines. */
|
|
62
|
+
removedNodes: {
|
|
63
|
+
id: string;
|
|
64
|
+
line: number;
|
|
65
|
+
}[];
|
|
66
|
+
/** `- a > b` lines, one entry per arrow. */
|
|
67
|
+
removedFlows: {
|
|
68
|
+
from: string;
|
|
69
|
+
to: string;
|
|
70
|
+
line: number;
|
|
71
|
+
}[];
|
|
72
|
+
/** `@n` lines: the feedback item, and the ids the script says answer it. */
|
|
73
|
+
addressed: {
|
|
74
|
+
item: number;
|
|
75
|
+
ids: string[];
|
|
76
|
+
line: number;
|
|
77
|
+
}[];
|
|
78
|
+
/** `with` lines: connector configuration for a node, existing or new. */
|
|
79
|
+
connectors: ConnectorLine[];
|
|
80
|
+
/** Lines, or parts of lines, that were left out. */
|
|
81
|
+
problems: ProcessTextProblem[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Reads a change script ({@link PROCESS_DELTA_GUIDE}).
|
|
85
|
+
*
|
|
86
|
+
* Never throws: what it cannot read is reported in `problems` and left out.
|
|
87
|
+
* Ids are taken as written; whether they name anything is for the caller to
|
|
88
|
+
* decide against the diagram the script was written for.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseProcessDelta(text: string): ProcessDelta;
|
|
91
|
+
//# sourceMappingURL=process-delta.d.ts.map
|
|
@@ -0,0 +1,259 @@
|
|
|
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 { CONNECTOR_LINE, parseConnectorLine } from "./connector-line.js";
|
|
19
|
+
import { ALIASES, KINDS, TRIGGERS, edgeLabel, tokenizePath, } from "./process-text.js";
|
|
20
|
+
/**
|
|
21
|
+
* Kind words the writer uses for element types the line format cannot create.
|
|
22
|
+
* A script may restate them on an existing node; it cannot declare a new one.
|
|
23
|
+
*/
|
|
24
|
+
export const FIXED_KINDS = {
|
|
25
|
+
sub: "subProcess",
|
|
26
|
+
adhoc: "adHocSubProcess",
|
|
27
|
+
transaction: "transaction",
|
|
28
|
+
complex: "complexGateway",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* How to write a change script — the part of a system prompt that teaches it,
|
|
32
|
+
* after {@link PROCESS_TEXT_GUIDE}. A test parses its example and expects no
|
|
33
|
+
* problems.
|
|
34
|
+
*/
|
|
35
|
+
export const PROCESS_DELTA_GUIDE = `Change script — write only what changes, one line each:
|
|
36
|
+
a > new[kind Name] > b add nodes and flows; an existing node is written by its id only
|
|
37
|
+
a >(Label: condition) b add a flow; restating an existing flow with a new label changes it
|
|
38
|
+
x[kind Name] an existing id declared again changes its kind or name
|
|
39
|
+
- a > b remove the flow from a to b
|
|
40
|
+
- x remove node x and its flows
|
|
41
|
+
@2 x y feedback item 2 is answered by the changes to x and y
|
|
42
|
+
Rules:
|
|
43
|
+
- Use the ids of the diagram you were given. Never repeat a line that changes nothing.
|
|
44
|
+
- A new node written between two connected nodes (a > new > b) replaces the flow a > b.
|
|
45
|
+
- Removing a node with one way in and one way out joins the two.
|
|
46
|
+
- End with one @ line for each feedback item you answered.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
check > second[user Second approval] > pay
|
|
50
|
+
review[user Review application]
|
|
51
|
+
- notify
|
|
52
|
+
@1 second
|
|
53
|
+
@2 review`;
|
|
54
|
+
/**
|
|
55
|
+
* One id, or several separated by commas. Not by spaces: a model's prose bullet
|
|
56
|
+
* ("- review is removed") would otherwise remove every word that is an id.
|
|
57
|
+
*/
|
|
58
|
+
const ID_LIST = /^[A-Za-z_][\w.-]*(\s*,\s*[A-Za-z_][\w.-]*)*$/;
|
|
59
|
+
/** A line that ends in an arrow: the path goes on below, as in the line format. */
|
|
60
|
+
const DANGLING = /\s*-{0,2}>\s*(\([^()]*\))?\s*$/;
|
|
61
|
+
/** Reads one declaration's bracket text. */
|
|
62
|
+
function readSpec(id, spec, line, problems) {
|
|
63
|
+
const node = { id, line };
|
|
64
|
+
const bar = spec.indexOf("|");
|
|
65
|
+
const head = (bar < 0 ? spec : spec.slice(0, bar)).trim();
|
|
66
|
+
const attrs = bar < 0 ? "" : spec.slice(bar + 1);
|
|
67
|
+
const space = head.search(/\s/);
|
|
68
|
+
const word = space < 0 ? head : head.slice(0, space);
|
|
69
|
+
const [kindWord = "", trigger] = word.toLowerCase().split(":");
|
|
70
|
+
const type = KINDS[kindWord] ?? ALIASES[kindWord] ?? FIXED_KINDS[kindWord];
|
|
71
|
+
if (type === undefined) {
|
|
72
|
+
// `review[Review application]`: no kind, so the whole head is the new name.
|
|
73
|
+
if (head)
|
|
74
|
+
node.name = head;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
node.type = type;
|
|
78
|
+
const name = space < 0 ? "" : head.slice(space + 1).trim();
|
|
79
|
+
if (name)
|
|
80
|
+
node.name = name;
|
|
81
|
+
if (trigger !== undefined) {
|
|
82
|
+
if (TRIGGERS.has(trigger))
|
|
83
|
+
node.trigger = trigger;
|
|
84
|
+
else
|
|
85
|
+
problems.push({ line, message: `unknown trigger "${trigger}" for "${id}"; ignored` });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const attr of attrs.split(/[\s,|]+/).filter(Boolean)) {
|
|
89
|
+
const [key, value] = attr.split("=", 2);
|
|
90
|
+
if (key === "on" && value)
|
|
91
|
+
node.on = value;
|
|
92
|
+
else if (key === "job" && value)
|
|
93
|
+
node.jobType = value;
|
|
94
|
+
else if (key === "nonint" && value === undefined)
|
|
95
|
+
node.interrupting = false;
|
|
96
|
+
else
|
|
97
|
+
problems.push({ line, message: `unknown attribute "${attr}" on "${id}"; ignored` });
|
|
98
|
+
}
|
|
99
|
+
return node;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Reads a change script ({@link PROCESS_DELTA_GUIDE}).
|
|
103
|
+
*
|
|
104
|
+
* Never throws: what it cannot read is reported in `problems` and left out.
|
|
105
|
+
* Ids are taken as written; whether they name anything is for the caller to
|
|
106
|
+
* decide against the diagram the script was written for.
|
|
107
|
+
*/
|
|
108
|
+
export function parseProcessDelta(text) {
|
|
109
|
+
const delta = {
|
|
110
|
+
nodes: [],
|
|
111
|
+
flows: [],
|
|
112
|
+
removedNodes: [],
|
|
113
|
+
removedFlows: [],
|
|
114
|
+
addressed: [],
|
|
115
|
+
connectors: [],
|
|
116
|
+
problems: [],
|
|
117
|
+
};
|
|
118
|
+
const declared = new Map();
|
|
119
|
+
let carry;
|
|
120
|
+
const path = (raw, n) => {
|
|
121
|
+
const tokens = tokenizePath(raw);
|
|
122
|
+
if ("error" in tokens) {
|
|
123
|
+
delta.problems.push({ line: n, message: tokens.error });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (tokens.note !== undefined) {
|
|
127
|
+
delta.problems.push({ line: n, message: `ignored the note "${tokens.note}"` });
|
|
128
|
+
}
|
|
129
|
+
for (const id of tokens.bracketless ?? []) {
|
|
130
|
+
delta.problems.push({
|
|
131
|
+
line: n,
|
|
132
|
+
message: `"${id} …" has no brackets; read it as declaring "${id}"`,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
for (const id of tokens.unclosed ?? []) {
|
|
136
|
+
delta.problems.push({
|
|
137
|
+
line: n,
|
|
138
|
+
message: `"${id}[" is not closed; closed it where its name ends`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
for (const { written, id } of tokens.joined ?? []) {
|
|
142
|
+
delta.problems.push({ line: n, message: `"${written}" is not an id; read as "${id}"` });
|
|
143
|
+
}
|
|
144
|
+
for (const ref of tokens.refs) {
|
|
145
|
+
if (ref.spec === undefined)
|
|
146
|
+
continue;
|
|
147
|
+
const node = readSpec(ref.id, ref.spec, n, delta.problems);
|
|
148
|
+
const earlier = declared.get(ref.id);
|
|
149
|
+
if (earlier) {
|
|
150
|
+
delta.problems.push({
|
|
151
|
+
line: n,
|
|
152
|
+
message: `"${ref.id}" is already declared on line ${earlier.line}; ignored "${ref.spec}"`,
|
|
153
|
+
});
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
declared.set(ref.id, node);
|
|
157
|
+
delta.nodes.push(node);
|
|
158
|
+
}
|
|
159
|
+
tokens.labels.forEach((raw, k) => {
|
|
160
|
+
const from = tokens.refs[k]?.id;
|
|
161
|
+
const to = tokens.refs[k + 1]?.id;
|
|
162
|
+
if (from === undefined || to === undefined)
|
|
163
|
+
return;
|
|
164
|
+
// The condition is kept as written, FEEL or not: restating a flow in another
|
|
165
|
+
// expression language must not change it. The applier checks a condition
|
|
166
|
+
// it is about to write.
|
|
167
|
+
const edge = edgeLabel(raw);
|
|
168
|
+
const flow = { from, to, line: n };
|
|
169
|
+
if (edge.name !== undefined)
|
|
170
|
+
flow.name = edge.name;
|
|
171
|
+
if (edge.condition !== undefined)
|
|
172
|
+
flow.condition = edge.condition;
|
|
173
|
+
if (edge.isDefault)
|
|
174
|
+
flow.isDefault = true;
|
|
175
|
+
delta.flows.push(flow);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
const removal = (rest, n) => {
|
|
179
|
+
if (ID_LIST.test(rest) && !rest.includes(">")) {
|
|
180
|
+
for (const id of rest.split(/[\s,]+/).filter(Boolean)) {
|
|
181
|
+
delta.removedNodes.push({ id, line: n });
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!rest.includes(">")) {
|
|
186
|
+
delta.problems.push({
|
|
187
|
+
line: n,
|
|
188
|
+
message: `expected "- <id>" or "- <id> > <id>" at "${rest.slice(0, 30)}"`,
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const tokens = tokenizePath(rest);
|
|
193
|
+
if ("error" in tokens) {
|
|
194
|
+
delta.problems.push({ line: n, message: tokens.error });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
for (let k = 0; k + 1 < tokens.refs.length; k++) {
|
|
198
|
+
const from = tokens.refs[k]?.id;
|
|
199
|
+
const to = tokens.refs[k + 1]?.id;
|
|
200
|
+
if (from !== undefined && to !== undefined)
|
|
201
|
+
delta.removedFlows.push({ from, to, line: n });
|
|
202
|
+
}
|
|
203
|
+
if (tokens.refs.some((ref) => ref.spec !== undefined)) {
|
|
204
|
+
delta.problems.push({ line: n, message: "a removal names ids only; ignored the brackets" });
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const lines = text.split(/\r?\n/);
|
|
208
|
+
lines.forEach((raw, index) => {
|
|
209
|
+
const n = index + 1;
|
|
210
|
+
let line = raw.trim();
|
|
211
|
+
if (carry !== undefined) {
|
|
212
|
+
if (line === "")
|
|
213
|
+
return;
|
|
214
|
+
line = `${carry.text} ${line}`;
|
|
215
|
+
carry = undefined;
|
|
216
|
+
}
|
|
217
|
+
if (line === "" || line.startsWith("```") || line.startsWith("//") || line.startsWith("#")) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (line.startsWith("@")) {
|
|
221
|
+
const match = /^@\s*(\d+)\s*:?\s*(.*)$/.exec(line);
|
|
222
|
+
const item = match ? Number.parseInt(match[1] ?? "", 10) : Number.NaN;
|
|
223
|
+
if (!match || !Number.isFinite(item)) {
|
|
224
|
+
delta.problems.push({ line: n, message: `expected "@<feedback number> <ids>"` });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const ids = (match[2] ?? "").split(/[\s,]+/).filter((id) => /^[A-Za-z_][\w.-]*$/.test(id));
|
|
228
|
+
delta.addressed.push({ item, ids, line: n });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (CONNECTOR_LINE.test(line)) {
|
|
232
|
+
const connector = parseConnectorLine(line, n, delta.problems);
|
|
233
|
+
if (connector)
|
|
234
|
+
delta.connectors.push(connector);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
// `- x` removes; `-> x` is an arrow a model wrote at the start of a line.
|
|
238
|
+
const removed = /^-(?![->])\s*(.*)$/.exec(line);
|
|
239
|
+
if (removed) {
|
|
240
|
+
removal((removed[1] ?? "").trim(), n);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (DANGLING.test(line)) {
|
|
244
|
+
carry = { text: line, line: n };
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
path(line, n);
|
|
248
|
+
});
|
|
249
|
+
if (carry !== undefined) {
|
|
250
|
+
const { text: rest, line } = carry;
|
|
251
|
+
delta.problems.push({
|
|
252
|
+
line,
|
|
253
|
+
message: 'the line ends with ">" and nothing follows; read without it',
|
|
254
|
+
});
|
|
255
|
+
path(rest.replace(DANGLING, ""), line);
|
|
256
|
+
}
|
|
257
|
+
return delta;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=process-delta.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
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, BpmnFlowElement } from "./bpmn-model.js";
|
|
19
|
+
/** Options for {@link writeProcessText}. */
|
|
20
|
+
export interface WriteProcessTextOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Writes an element's connector as a `with` line, after `with <id>: `, or
|
|
23
|
+
* answers `undefined` for an element without one. Pass `connectorLineFor`
|
|
24
|
+
* from `@bpmnkit/core/connectors`, so a model that changes the diagram keeps
|
|
25
|
+
* its connectors; without it no `with` lines are written.
|
|
26
|
+
*/
|
|
27
|
+
connectorLine?: (element: BpmnFlowElement, definitions: BpmnDefinitions) => string | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** What {@link writeProcessText} wrote. */
|
|
30
|
+
export interface WrittenProcessText {
|
|
31
|
+
/** The diagram in the line format. */
|
|
32
|
+
text: string;
|
|
33
|
+
/** Every written id, mapped to the element id it stands for. */
|
|
34
|
+
aliases: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A name as it can be written inside brackets: on one line, with no bracket
|
|
38
|
+
* or bar to end the declaration early. The change applier compares a restated
|
|
39
|
+
* name against this, so writing it back unchanged is no rename.
|
|
40
|
+
*/
|
|
41
|
+
export declare function writableName(name: string): string;
|
|
42
|
+
/** A flow name as it can be written in an arrow label, which a colon or parenthesis would end. */
|
|
43
|
+
export declare function writableLabel(name: string): string;
|
|
44
|
+
/** A FEEL condition without its leading `=`, on one line. */
|
|
45
|
+
export declare function writableCondition(condition: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Writes the first process of `definitions` in the line format.
|
|
48
|
+
*
|
|
49
|
+
* Paths start at the start events and follow the flows; each flow is written
|
|
50
|
+
* once and each node is declared where it first appears. A boundary event
|
|
51
|
+
* starts its own line once its host has been declared, and a node no path
|
|
52
|
+
* reaches is declared on a line of its own, so nothing the format can express
|
|
53
|
+
* is left out.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const { text, aliases } = writeProcessText(Bpmn.parse(xml))
|
|
58
|
+
* // text: "# Order\nstart[start Order placed] > check_order[service Check order] > …"
|
|
59
|
+
* // aliases: { start: "StartEvent_1", check_order: "Activity_0x9k2lm", … }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeProcessText(definitions: BpmnDefinitions, options?: WriteProcessTextOptions): WrittenProcessText;
|
|
63
|
+
//# sourceMappingURL=process-text-writer.d.ts.map
|