@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,202 @@
|
|
|
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 { assertBpmnDefinitions } from "./argument-guards.js";
|
|
19
|
+
import { compactify } from "./compact.js";
|
|
20
|
+
import { FIXED_KINDS } from "./process-delta.js";
|
|
21
|
+
import { KINDS } from "./process-text.js";
|
|
22
|
+
const KIND_WORDS = new Map([...Object.entries(KINDS), ...Object.entries(FIXED_KINDS)].map(([word, type]) => [type, word]));
|
|
23
|
+
/** Ids kept as they are: short, lowercase, and readable. */
|
|
24
|
+
const READABLE_ID = /^[a-z][a-z0-9_]{0,23}$/;
|
|
25
|
+
/** Longest alias derived from a name, in words. */
|
|
26
|
+
const ALIAS_WORDS = 4;
|
|
27
|
+
/**
|
|
28
|
+
* A name as it can be written inside brackets: on one line, with no bracket
|
|
29
|
+
* or bar to end the declaration early. The change applier compares a restated
|
|
30
|
+
* name against this, so writing it back unchanged is no rename.
|
|
31
|
+
*/
|
|
32
|
+
export function writableName(name) {
|
|
33
|
+
return name
|
|
34
|
+
.replace(/\[/g, "(")
|
|
35
|
+
.replace(/\]/g, ")")
|
|
36
|
+
.replace(/\|/g, "/")
|
|
37
|
+
.replace(/\s+/g, " ")
|
|
38
|
+
.trim();
|
|
39
|
+
}
|
|
40
|
+
/** A flow name as it can be written in an arrow label, which a colon or parenthesis would end. */
|
|
41
|
+
export function writableLabel(name) {
|
|
42
|
+
return name.replace(/[():]/g, " ").replace(/\s+/g, " ").trim();
|
|
43
|
+
}
|
|
44
|
+
/** A FEEL condition without its leading `=`, on one line. */
|
|
45
|
+
export function writableCondition(condition) {
|
|
46
|
+
return condition.replace(/^\s*=/, "").replace(/\s+/g, " ").trim();
|
|
47
|
+
}
|
|
48
|
+
function aliasFor(element, taken) {
|
|
49
|
+
if (READABLE_ID.test(element.id) && !taken.has(element.id)) {
|
|
50
|
+
taken.add(element.id);
|
|
51
|
+
return element.id;
|
|
52
|
+
}
|
|
53
|
+
const words = (element.name ?? "")
|
|
54
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
55
|
+
.toLowerCase()
|
|
56
|
+
.split(/[^a-z0-9]+/)
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.slice(0, ALIAS_WORDS);
|
|
59
|
+
let base = words.join("_");
|
|
60
|
+
if (!/^[a-z]/.test(base))
|
|
61
|
+
base = (KIND_WORDS.get(element.type) ?? "node") + (base ? `_${base}` : "");
|
|
62
|
+
let alias = base;
|
|
63
|
+
for (let n = 2; taken.has(alias); n++)
|
|
64
|
+
alias = `${base}_${n}`;
|
|
65
|
+
taken.add(alias);
|
|
66
|
+
return alias;
|
|
67
|
+
}
|
|
68
|
+
function spec(element, host) {
|
|
69
|
+
const word = KIND_WORDS.get(element.type) ?? "task";
|
|
70
|
+
const trigger = element.eventType ? `:${element.eventType}` : "";
|
|
71
|
+
const name = element.name ? ` ${writableName(element.name)}` : "";
|
|
72
|
+
const attrs = [];
|
|
73
|
+
if (host !== undefined)
|
|
74
|
+
attrs.push(`on=${host}`);
|
|
75
|
+
if (element.interrupting === false)
|
|
76
|
+
attrs.push("nonint");
|
|
77
|
+
if (element.jobType)
|
|
78
|
+
attrs.push(`job=${element.jobType}`);
|
|
79
|
+
return `[${word}${trigger}${name}${attrs.length > 0 ? ` | ${attrs.join(" ")}` : ""}]`;
|
|
80
|
+
}
|
|
81
|
+
function label(flow) {
|
|
82
|
+
const name = flow.name ? writableLabel(flow.name) : "";
|
|
83
|
+
if (flow.isDefault)
|
|
84
|
+
return `>(${name ? `${name}: ` : ""}default) `;
|
|
85
|
+
if (flow.condition)
|
|
86
|
+
return `>(${name}: ${writableCondition(flow.condition)}) `;
|
|
87
|
+
return name ? `>(${name}) ` : "> ";
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Writes the first process of `definitions` in the line format.
|
|
91
|
+
*
|
|
92
|
+
* Paths start at the start events and follow the flows; each flow is written
|
|
93
|
+
* once and each node is declared where it first appears. A boundary event
|
|
94
|
+
* starts its own line once its host has been declared, and a node no path
|
|
95
|
+
* reaches is declared on a line of its own, so nothing the format can express
|
|
96
|
+
* is left out.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const { text, aliases } = writeProcessText(Bpmn.parse(xml))
|
|
101
|
+
* // text: "# Order\nstart[start Order placed] > check_order[service Check order] > …"
|
|
102
|
+
* // aliases: { start: "StartEvent_1", check_order: "Activity_0x9k2lm", … }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function writeProcessText(definitions, options = {}) {
|
|
106
|
+
assertBpmnDefinitions(definitions, "writeProcessText");
|
|
107
|
+
const process = compactify(definitions).processes[0];
|
|
108
|
+
if (!process)
|
|
109
|
+
return { text: "", aliases: {} };
|
|
110
|
+
// What the format can write: flow nodes with a kind word, outside any event sub-process.
|
|
111
|
+
const elements = process.elements.filter((el) => KIND_WORDS.has(el.type));
|
|
112
|
+
const byId = new Map(elements.map((el) => [el.id, el]));
|
|
113
|
+
const flows = process.flows.filter((f) => byId.has(f.from) && byId.has(f.to));
|
|
114
|
+
const outgoing = new Map();
|
|
115
|
+
for (const flow of flows)
|
|
116
|
+
outgoing.set(flow.from, [...(outgoing.get(flow.from) ?? []), flow]);
|
|
117
|
+
const taken = new Set();
|
|
118
|
+
const alias = new Map();
|
|
119
|
+
// Readable ids first, so a name-derived alias never takes one of them.
|
|
120
|
+
for (const el of elements)
|
|
121
|
+
if (READABLE_ID.test(el.id))
|
|
122
|
+
alias.set(el.id, aliasFor(el, taken));
|
|
123
|
+
for (const el of elements)
|
|
124
|
+
if (!alias.has(el.id))
|
|
125
|
+
alias.set(el.id, aliasFor(el, taken));
|
|
126
|
+
const declared = new Set();
|
|
127
|
+
const ref = (id) => {
|
|
128
|
+
const el = byId.get(id);
|
|
129
|
+
const written = alias.get(id) ?? id;
|
|
130
|
+
if (!el || declared.has(id))
|
|
131
|
+
return written;
|
|
132
|
+
declared.add(id);
|
|
133
|
+
return `${written}${spec(el, el.attachedTo === undefined ? undefined : alias.get(el.attachedTo))}`;
|
|
134
|
+
};
|
|
135
|
+
const lines = [];
|
|
136
|
+
if (process.name)
|
|
137
|
+
lines.push(`# ${writableName(process.name)}`);
|
|
138
|
+
const written = new Set();
|
|
139
|
+
const expanded = new Set();
|
|
140
|
+
const queue = [];
|
|
141
|
+
/** Writes every unwritten flow out of `id`, each as a path that runs on while it can. */
|
|
142
|
+
const expand = (id) => {
|
|
143
|
+
if (expanded.has(id))
|
|
144
|
+
return;
|
|
145
|
+
expanded.add(id);
|
|
146
|
+
for (const first of outgoing.get(id) ?? []) {
|
|
147
|
+
if (written.has(first))
|
|
148
|
+
continue;
|
|
149
|
+
let line = `${ref(id)} `;
|
|
150
|
+
let flow = first;
|
|
151
|
+
while (flow) {
|
|
152
|
+
written.add(flow);
|
|
153
|
+
line += `${label(flow)}${ref(flow.to)} `;
|
|
154
|
+
queue.push(flow.to);
|
|
155
|
+
const next = (outgoing.get(flow.to) ?? []).filter((f) => !written.has(f));
|
|
156
|
+
// Run on only through a node with one way out, and only once.
|
|
157
|
+
const only = next.length === 1 && !expanded.has(flow.to) ? next[0] : undefined;
|
|
158
|
+
if (only)
|
|
159
|
+
expanded.add(flow.to);
|
|
160
|
+
flow = only;
|
|
161
|
+
}
|
|
162
|
+
lines.push(line.trimEnd());
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const drain = () => {
|
|
166
|
+
for (let id = queue.shift(); id !== undefined; id = queue.shift()) {
|
|
167
|
+
// A boundary waits for its host; it is written after the main paths.
|
|
168
|
+
if (byId.get(id)?.type !== "boundaryEvent")
|
|
169
|
+
expand(id);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const starts = elements.filter((el) => el.type === "startEvent" || !flows.some((f) => f.to === el.id));
|
|
173
|
+
for (const el of starts) {
|
|
174
|
+
if (el.type === "boundaryEvent")
|
|
175
|
+
continue;
|
|
176
|
+
queue.push(el.id);
|
|
177
|
+
drain();
|
|
178
|
+
}
|
|
179
|
+
// Then boundaries, after their hosts, and whatever no path reached.
|
|
180
|
+
for (const el of elements) {
|
|
181
|
+
if (el.attachedTo !== undefined && !declared.has(el.attachedTo))
|
|
182
|
+
lines.push(ref(el.attachedTo));
|
|
183
|
+
expand(el.id);
|
|
184
|
+
drain();
|
|
185
|
+
if (!declared.has(el.id))
|
|
186
|
+
lines.push(ref(el.id));
|
|
187
|
+
}
|
|
188
|
+
if (options.connectorLine) {
|
|
189
|
+
const real = new Map((definitions.processes[0]?.flowElements ?? []).map((el) => [el.id, el]));
|
|
190
|
+
for (const el of elements) {
|
|
191
|
+
const element = real.get(el.id);
|
|
192
|
+
const line = element && options.connectorLine(element, definitions);
|
|
193
|
+
if (line)
|
|
194
|
+
lines.push(`with ${alias.get(el.id) ?? el.id}: ${line}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const aliases = {};
|
|
198
|
+
for (const [id, written] of alias)
|
|
199
|
+
aliases[written] = id;
|
|
200
|
+
return { text: lines.join("\n"), aliases };
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=process-text-writer.js.map
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A line format for a language model to write a process in.
|
|
3
|
+
*
|
|
4
|
+
* A model's time and cost are its output tokens, and a diagram as compact JSON
|
|
5
|
+
* spends most of them on keys, quotes and ids nobody reads: flow ids, `"type":`,
|
|
6
|
+
* `"from":`, the merge gateway every branch has to be routed into. This format
|
|
7
|
+
* writes a path as `a > b > c`, declares a node inline the first time it is
|
|
8
|
+
* used, and leaves ids, merges and the obvious gaps to {@link parseProcessText}
|
|
9
|
+
* — about a quarter of the tokens of minified compact JSON on the repo's own
|
|
10
|
+
* fixtures (`doc/drop-ai-generate-analysis.md` §2).
|
|
11
|
+
*
|
|
12
|
+
* Every line is a complete fact, so a diagram can be drawn while it is still
|
|
13
|
+
* being written: {@link createProcessTextStream} reads lines as they finish.
|
|
14
|
+
* JSON cannot do this without a brace scanner, and Workers AI's JSON mode cannot
|
|
15
|
+
* stream at all.
|
|
16
|
+
*
|
|
17
|
+
* The parser never throws on its input. Anything it cannot use is reported as a
|
|
18
|
+
* {@link ProcessTextProblem} and left out, and what it adds to complete the
|
|
19
|
+
* diagram is listed in `fixes` — so the result always expands.
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
import type { BpmnDefinitions, BpmnElementType } from "./bpmn-model.js";
|
|
24
|
+
import type { CompactDiagram, CompactFlow } from "./compact.js";
|
|
25
|
+
import { type ConnectorLine } from "./connector-line.js";
|
|
26
|
+
/**
|
|
27
|
+
* How to write the format — the part of a system prompt that teaches it.
|
|
28
|
+
*
|
|
29
|
+
* It lives beside the parser so the two cannot drift: a test parses its example
|
|
30
|
+
* and expects no problems.
|
|
31
|
+
*/
|
|
32
|
+
export declare const PROCESS_TEXT_GUIDE = "Format \u2014 one path per line, nothing else:\n# Process name (first line)\na > b > c sequence flow\nid[kind Name] declare a node the first time it appears; afterwards write only id\ngw >(Label: condition) x conditional branch, condition in FEEL (amount > 1000, status = \"ok\")\ngw >(Label: default) y branch taken when no condition holds\nKinds: start end task user service rule (DMN decision) send receive script manual call xor and or eventgw catch (wait for message or timer) throw boundary\nEvents take a trigger: start:message end:error catch:timer boundary:error (timer message signal error escalation terminate conditional compensate cancel)\nAttributes after |: on=<task id> (required on boundary), nonint (non-interrupting), job=<job type>, each=<list variable> (once per item), after=<ISO duration> (timer)\nRules:\n- One start event. Every node is on a path from it to an end event: never a node nothing leads to.\n- An xor has two or more branches: exactly one is (Label: default), each other has a FEEL condition.\n- A boundary starts its own line, on a task you declared, and leads to a task that handles it; never draw an arrow into a boundary.\n- Branches that meet again are joined automatically; join parallel branches with an and node.\n- Steps done at the same time start from an and node and meet at another. A deadline is a boundary:timer with after= on the task that may run late. A step done for every item of a list takes each=<list>; use it only when the description says every or each.\n\nExample:\n# Expense approval\nstart[start Expense submitted] > check[xor Amount over 1000?]\ncheck >(Yes: amount > 1000) review[user Review expense] > pay[service Pay expense] > done[end Expense paid]\ncheck >(No: default) auto[service Approve automatically] > pay\nfailed[boundary:error Payment failed | on=pay] > notify[send Notify submitter] > notice[end Payment failed]";
|
|
33
|
+
/** A line, or part of one, that {@link parseProcessText} could not use. */
|
|
34
|
+
export interface ProcessTextProblem {
|
|
35
|
+
/** 1-based line number in the text. */
|
|
36
|
+
line: number;
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A guess {@link parseProcessText} had to make, put as a question. Each answer
|
|
41
|
+
* is a change request, written for a model to apply to the diagram.
|
|
42
|
+
*/
|
|
43
|
+
export interface ProcessTextQuestion {
|
|
44
|
+
/** The element the guess is about. It may have been left out of the diagram. */
|
|
45
|
+
elementId: string;
|
|
46
|
+
/** What was guessed, then the question. */
|
|
47
|
+
text: string;
|
|
48
|
+
/** Ready answers. Empty when only the reader can say. */
|
|
49
|
+
options: {
|
|
50
|
+
label: string;
|
|
51
|
+
change: string;
|
|
52
|
+
}[];
|
|
53
|
+
/** The start of a change request for the reader to finish. */
|
|
54
|
+
draft: string;
|
|
55
|
+
}
|
|
56
|
+
/** What {@link parseProcessText} read. */
|
|
57
|
+
export interface ProcessTextResult {
|
|
58
|
+
/** One process. Always valid input for `expand`. */
|
|
59
|
+
diagram: CompactDiagram;
|
|
60
|
+
/** Text that was left out, with the line it came from. */
|
|
61
|
+
problems: ProcessTextProblem[];
|
|
62
|
+
/** What was added or changed to complete the diagram, e.g. a join gateway or a missing end event. */
|
|
63
|
+
fixes: string[];
|
|
64
|
+
/** The guesses behind the fixes that only the reader can confirm, in the order of the text. */
|
|
65
|
+
questions: ProcessTextQuestion[];
|
|
66
|
+
/**
|
|
67
|
+
* The `with` lines, each with the id of the element it configures. Not
|
|
68
|
+
* applied: `applyConnectorLines` from `@bpmnkit/core/connectors` writes them
|
|
69
|
+
* onto the expanded diagram.
|
|
70
|
+
*/
|
|
71
|
+
connectors: ConnectorRef[];
|
|
72
|
+
}
|
|
73
|
+
/** A `with` line, and the element it names in the diagram. */
|
|
74
|
+
export interface ConnectorRef extends ConnectorLine {
|
|
75
|
+
elementId: string;
|
|
76
|
+
}
|
|
77
|
+
export declare const KINDS: Record<string, BpmnElementType>;
|
|
78
|
+
/**
|
|
79
|
+
* Words models write for a kind instead of the one the guide teaches, taken
|
|
80
|
+
* from the Drop benchmark's recorded answers. Accepted without a problem: the
|
|
81
|
+
* meaning is plain, and teaching them would only lengthen the prompt.
|
|
82
|
+
*/
|
|
83
|
+
export declare const ALIASES: Record<string, BpmnElementType>;
|
|
84
|
+
export declare const TRIGGERS: Set<string>;
|
|
85
|
+
export declare const EVENTS: Set<BpmnElementType>;
|
|
86
|
+
/** A path line split into its parts. */
|
|
87
|
+
export interface PathTokens {
|
|
88
|
+
/** The nodes in the order written, each with the bracket text it was declared with, if any. */
|
|
89
|
+
refs: {
|
|
90
|
+
id: string;
|
|
91
|
+
spec?: string;
|
|
92
|
+
}[];
|
|
93
|
+
/** The label of each arrow, between `refs[k]` and `refs[k + 1]`. */
|
|
94
|
+
labels: (string | undefined)[];
|
|
95
|
+
/** A parenthesised note after the last node, which carries no meaning. */
|
|
96
|
+
note?: string;
|
|
97
|
+
/** Ids written with spaces (`call back[…]`), and the id each was read as. */
|
|
98
|
+
joined?: {
|
|
99
|
+
written: string;
|
|
100
|
+
id: string;
|
|
101
|
+
}[];
|
|
102
|
+
/** Ids whose bracket was never closed, read as closed where the name ends. */
|
|
103
|
+
unclosed?: string[];
|
|
104
|
+
/** Kinds written with a name but no brackets after an arrow (`> end Done`), read as declared. */
|
|
105
|
+
bracketless?: string[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Splits one complete path line (`a[kind Name] >(Label: cond) b > c`) into its
|
|
109
|
+
* node references and arrow labels, or says where it stops making sense.
|
|
110
|
+
*
|
|
111
|
+
* Shared by {@link parseProcessText} and the change-script parser, so the two
|
|
112
|
+
* read paths the same way.
|
|
113
|
+
*/
|
|
114
|
+
export declare function tokenizePath(text: string): PathTokens | {
|
|
115
|
+
error: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Keeps a condition only if it is FEEL.
|
|
119
|
+
*
|
|
120
|
+
* Models write the branch they mean in prose as often as in FEEL
|
|
121
|
+
* (`No: is not approved`). As an expression that fails at deploy time; as the
|
|
122
|
+
* branch's label it still says what was meant, and the missing condition is
|
|
123
|
+
* one the lint names and a reader can fill in.
|
|
124
|
+
*/
|
|
125
|
+
export declare function conditionOrLabel(edge: Pick<CompactFlow, "name" | "condition" | "isDefault">): {
|
|
126
|
+
edge: Pick<CompactFlow, "name" | "condition" | "isDefault">;
|
|
127
|
+
problem?: string;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* An ISO 8601 duration from what models write: `PT5M` as it is, `5m`, `5 min`,
|
|
131
|
+
* `5 minutes`, `2 hours` or `1 day`, also inside a name ("Wait 5 minutes").
|
|
132
|
+
*/
|
|
133
|
+
export declare function duration(text: string): string | undefined;
|
|
134
|
+
export declare function edgeLabel(label: string | undefined): Pick<CompactFlow, "name" | "condition" | "isDefault">;
|
|
135
|
+
/**
|
|
136
|
+
* Reads a process written in the line format ({@link PROCESS_TEXT_GUIDE}).
|
|
137
|
+
*
|
|
138
|
+
* Never throws. The returned diagram always expands, and keeps the structural
|
|
139
|
+
* rules `lintDiagram` checks; what could not be used is in `problems`, what was
|
|
140
|
+
* added or changed to complete the diagram is in `fixes`:
|
|
141
|
+
*
|
|
142
|
+
* - flow ids are generated, and a repeated edge is written once;
|
|
143
|
+
* - a missing start event is added before the first node without an incoming
|
|
144
|
+
* flow, and a start left unconnected leads there;
|
|
145
|
+
* - every node lies on a path from a start event: a task or gateway nothing
|
|
146
|
+
* leads to continues the latest path written before it that stops short of
|
|
147
|
+
* an end event, and a fragment that still cannot be reached is left out,
|
|
148
|
+
* never drawn loose;
|
|
149
|
+
* - an end event is added after every path that stops elsewhere;
|
|
150
|
+
* - a gateway with one way in and one way out is removed;
|
|
151
|
+
* - a task or event with several ways out gets a split gateway: xor when the
|
|
152
|
+
* branches are labelled, and otherwise parallel;
|
|
153
|
+
* - branches meeting at a task, an event or a splitting gateway are joined
|
|
154
|
+
* first, by a gateway of the type they were split with;
|
|
155
|
+
* - every decision has a default branch, and every other branch a FEEL
|
|
156
|
+
* condition — a prose one becomes a condition on a variable named for the
|
|
157
|
+
* gateway's question; flows out of anything else carry no condition or label;
|
|
158
|
+
* - an unnamed event, task or decision is named from its id;
|
|
159
|
+
* - a service or send task without `job=` uses its id as its job type, and a
|
|
160
|
+
* rule task its id as its decision id.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const { diagram, problems } = parseProcessText(modelOutput)
|
|
165
|
+
* const xml = Bpmn.export(expand(diagram))
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function parseProcessText(text: string): ProcessTextResult;
|
|
169
|
+
/** A process read line by line as it arrives. See {@link createProcessTextStream}. */
|
|
170
|
+
export interface ProcessTextStream {
|
|
171
|
+
/**
|
|
172
|
+
* Adds the next piece of text.
|
|
173
|
+
*
|
|
174
|
+
* @returns The diagram as it now stands, laid out, or `null` when the chunk
|
|
175
|
+
* completed no line that added anything.
|
|
176
|
+
*/
|
|
177
|
+
push(chunk: string): BpmnDefinitions | null;
|
|
178
|
+
/** Reads the last, unterminated line and returns the finished result, as {@link parseProcessText}. */
|
|
179
|
+
end(): ProcessTextResult;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reads the line format while it is being written, for a live preview.
|
|
183
|
+
*
|
|
184
|
+
* Only complete lines are read, so every frame is built from whole facts. A
|
|
185
|
+
* frame leaves out edges whose far end has not been declared yet and adds no
|
|
186
|
+
* start or end events; {@link ProcessTextStream.end} applies the full
|
|
187
|
+
* {@link parseProcessText} rules.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const stream = createProcessTextStream()
|
|
192
|
+
* for await (const chunk of tokens) {
|
|
193
|
+
* const defs = stream.push(chunk)
|
|
194
|
+
* if (defs) render(defs)
|
|
195
|
+
* }
|
|
196
|
+
* const { diagram, problems } = stream.end()
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare function createProcessTextStream(): ProcessTextStream;
|
|
200
|
+
//# sourceMappingURL=process-text.d.ts.map
|