@bpmnkit/core 1.2.0 → 1.4.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 +26 -0
- package/dist/bpmn/bpmn-builder.d.ts +8 -0
- package/dist/bpmn/bpmn-builder.js +6 -2
- package/dist/bpmn/compact.d.ts +39 -5
- package/dist/bpmn/compact.js +151 -29
- package/dist/bpmn/connector-line.d.ts +46 -0
- package/dist/bpmn/connector-line.js +135 -0
- package/dist/bpmn/full-operations.js +8 -1
- package/dist/bpmn/optimize/patterns.js +1 -3
- package/dist/bpmn/process-delta.d.ts +7 -0
- package/dist/bpmn/process-delta.js +34 -2
- package/dist/bpmn/process-text-writer.d.ts +12 -2
- package/dist/bpmn/process-text-writer.js +16 -1
- package/dist/bpmn/process-text.d.ts +36 -1
- package/dist/bpmn/process-text.js +412 -17
- 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 +7 -3
- package/dist/index.js +2 -0
- package/package.json +5 -1
|
@@ -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)) {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { BpmnElementType } from "./bpmn-model.js";
|
|
19
19
|
import type { CompactFlow } from "./compact.js";
|
|
20
|
+
import { type ConnectorLine } from "./connector-line.js";
|
|
20
21
|
import { type ProcessTextProblem } from "./process-text.js";
|
|
21
22
|
/**
|
|
22
23
|
* Kind words the writer uses for element types the line format cannot create.
|
|
@@ -42,6 +43,10 @@ export interface DeltaNode {
|
|
|
42
43
|
on?: string;
|
|
43
44
|
/** Zeebe job type, from `job=`. */
|
|
44
45
|
jobType?: string;
|
|
46
|
+
/** A script task's FEEL expression, with its leading `=`, from `feel=`. */
|
|
47
|
+
script?: string;
|
|
48
|
+
/** The variable a script task's or a job's result goes to, from `result=`. */
|
|
49
|
+
resultVariable?: string;
|
|
45
50
|
/** `nonint`: a non-interrupting boundary or start event. */
|
|
46
51
|
interrupting?: false;
|
|
47
52
|
line: number;
|
|
@@ -74,6 +79,8 @@ export interface ProcessDelta {
|
|
|
74
79
|
ids: string[];
|
|
75
80
|
line: number;
|
|
76
81
|
}[];
|
|
82
|
+
/** `with` lines: connector configuration for a node, existing or new. */
|
|
83
|
+
connectors: ConnectorLine[];
|
|
77
84
|
/** Lines, or parts of lines, that were left out. */
|
|
78
85
|
problems: ProcessTextProblem[];
|
|
79
86
|
}
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @packageDocumentation
|
|
17
17
|
*/
|
|
18
|
-
import {
|
|
18
|
+
import { CONNECTOR_LINE, parseConnectorLine } from "./connector-line.js";
|
|
19
|
+
import { ALIASES, KINDS, TRIGGERS, edgeLabel, splitFeel, tokenizePath, } from "./process-text.js";
|
|
19
20
|
/**
|
|
20
21
|
* Kind words the writer uses for element types the line format cannot create.
|
|
21
22
|
* A script may restate them on an existing node; it cannot declare a new one.
|
|
@@ -84,12 +85,21 @@ function readSpec(id, spec, line, problems) {
|
|
|
84
85
|
problems.push({ line, message: `unknown trigger "${trigger}" for "${id}"; ignored` });
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
+
const { plain, feel } = splitFeel(attrs);
|
|
89
|
+
if (feel !== undefined) {
|
|
90
|
+
// A step that evaluates FEEL is a script task
|
|
91
|
+
if (node.type === undefined || node.type === "task")
|
|
92
|
+
node.type = "scriptTask";
|
|
93
|
+
node.script = feel;
|
|
94
|
+
}
|
|
95
|
+
for (const attr of plain.split(/[\s,|]+/).filter(Boolean)) {
|
|
88
96
|
const [key, value] = attr.split("=", 2);
|
|
89
97
|
if (key === "on" && value)
|
|
90
98
|
node.on = value;
|
|
91
99
|
else if (key === "job" && value)
|
|
92
100
|
node.jobType = value;
|
|
101
|
+
else if (key === "result" && value)
|
|
102
|
+
node.resultVariable = value;
|
|
93
103
|
else if (key === "nonint" && value === undefined)
|
|
94
104
|
node.interrupting = false;
|
|
95
105
|
else
|
|
@@ -111,6 +121,7 @@ export function parseProcessDelta(text) {
|
|
|
111
121
|
removedNodes: [],
|
|
112
122
|
removedFlows: [],
|
|
113
123
|
addressed: [],
|
|
124
|
+
connectors: [],
|
|
114
125
|
problems: [],
|
|
115
126
|
};
|
|
116
127
|
const declared = new Map();
|
|
@@ -124,6 +135,21 @@ export function parseProcessDelta(text) {
|
|
|
124
135
|
if (tokens.note !== undefined) {
|
|
125
136
|
delta.problems.push({ line: n, message: `ignored the note "${tokens.note}"` });
|
|
126
137
|
}
|
|
138
|
+
for (const id of tokens.bracketless ?? []) {
|
|
139
|
+
delta.problems.push({
|
|
140
|
+
line: n,
|
|
141
|
+
message: `"${id} …" has no brackets; read it as declaring "${id}"`,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
for (const id of tokens.unclosed ?? []) {
|
|
145
|
+
delta.problems.push({
|
|
146
|
+
line: n,
|
|
147
|
+
message: `"${id}[" is not closed; closed it where its name ends`,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
for (const { written, id } of tokens.joined ?? []) {
|
|
151
|
+
delta.problems.push({ line: n, message: `"${written}" is not an id; read as "${id}"` });
|
|
152
|
+
}
|
|
127
153
|
for (const ref of tokens.refs) {
|
|
128
154
|
if (ref.spec === undefined)
|
|
129
155
|
continue;
|
|
@@ -211,6 +237,12 @@ export function parseProcessDelta(text) {
|
|
|
211
237
|
delta.addressed.push({ item, ids, line: n });
|
|
212
238
|
return;
|
|
213
239
|
}
|
|
240
|
+
if (CONNECTOR_LINE.test(line)) {
|
|
241
|
+
const connector = parseConnectorLine(line, n, delta.problems);
|
|
242
|
+
if (connector)
|
|
243
|
+
delta.connectors.push(connector);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
214
246
|
// `- x` removes; `-> x` is an arrow a model wrote at the start of a line.
|
|
215
247
|
const removed = /^-(?![->])\s*(.*)$/.exec(line);
|
|
216
248
|
if (removed) {
|
|
@@ -15,7 +15,17 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @packageDocumentation
|
|
17
17
|
*/
|
|
18
|
-
import type { BpmnDefinitions } from "./bpmn-model.js";
|
|
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
|
+
}
|
|
19
29
|
/** What {@link writeProcessText} wrote. */
|
|
20
30
|
export interface WrittenProcessText {
|
|
21
31
|
/** The diagram in the line format. */
|
|
@@ -49,5 +59,5 @@ export declare function writableCondition(condition: string): string;
|
|
|
49
59
|
* // aliases: { start: "StartEvent_1", check_order: "Activity_0x9k2lm", … }
|
|
50
60
|
* ```
|
|
51
61
|
*/
|
|
52
|
-
export declare function writeProcessText(definitions: BpmnDefinitions): WrittenProcessText;
|
|
62
|
+
export declare function writeProcessText(definitions: BpmnDefinitions, options?: WriteProcessTextOptions): WrittenProcessText;
|
|
53
63
|
//# sourceMappingURL=process-text-writer.d.ts.map
|
|
@@ -76,6 +76,12 @@ function spec(element, host) {
|
|
|
76
76
|
attrs.push("nonint");
|
|
77
77
|
if (element.jobType)
|
|
78
78
|
attrs.push(`job=${element.jobType}`);
|
|
79
|
+
if (element.script) {
|
|
80
|
+
// Last: feel= takes the rest of the attributes
|
|
81
|
+
if (element.resultVariable)
|
|
82
|
+
attrs.push(`result=${element.resultVariable}`);
|
|
83
|
+
attrs.push(`feel=${element.script.replace(/^=\s*/, "").replace(/\s+/g, " ")}`);
|
|
84
|
+
}
|
|
79
85
|
return `[${word}${trigger}${name}${attrs.length > 0 ? ` | ${attrs.join(" ")}` : ""}]`;
|
|
80
86
|
}
|
|
81
87
|
function label(flow) {
|
|
@@ -102,7 +108,7 @@ function label(flow) {
|
|
|
102
108
|
* // aliases: { start: "StartEvent_1", check_order: "Activity_0x9k2lm", … }
|
|
103
109
|
* ```
|
|
104
110
|
*/
|
|
105
|
-
export function writeProcessText(definitions) {
|
|
111
|
+
export function writeProcessText(definitions, options = {}) {
|
|
106
112
|
assertBpmnDefinitions(definitions, "writeProcessText");
|
|
107
113
|
const process = compactify(definitions).processes[0];
|
|
108
114
|
if (!process)
|
|
@@ -185,6 +191,15 @@ export function writeProcessText(definitions) {
|
|
|
185
191
|
if (!declared.has(el.id))
|
|
186
192
|
lines.push(ref(el.id));
|
|
187
193
|
}
|
|
194
|
+
if (options.connectorLine) {
|
|
195
|
+
const real = new Map((definitions.processes[0]?.flowElements ?? []).map((el) => [el.id, el]));
|
|
196
|
+
for (const el of elements) {
|
|
197
|
+
const element = real.get(el.id);
|
|
198
|
+
const line = element && options.connectorLine(element, definitions);
|
|
199
|
+
if (line)
|
|
200
|
+
lines.push(`with ${alias.get(el.id) ?? el.id}: ${line}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
188
203
|
const aliases = {};
|
|
189
204
|
for (const [id, written] of alias)
|
|
190
205
|
aliases[written] = id;
|
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import type { BpmnDefinitions, BpmnElementType } from "./bpmn-model.js";
|
|
24
24
|
import type { CompactDiagram, CompactFlow } from "./compact.js";
|
|
25
|
+
import { type ConnectorLine } from "./connector-line.js";
|
|
25
26
|
/**
|
|
26
27
|
* How to write the format — the part of a system prompt that teaches it.
|
|
27
28
|
*
|
|
28
29
|
* It lives beside the parser so the two cannot drift: a test parses its example
|
|
29
30
|
* and expects no problems.
|
|
30
31
|
*/
|
|
31
|
-
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
|
|
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), result=<variable>, feel=<FEEL expression> (last)\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- A boundary leads only to the handling. What happens next when nothing fails follows the task itself (read > count), never the boundary.\n- A step that only works on process data (count, sum, filter, compare, pick, format a message) is a script task, never a service or plain task: its FEEL reads the variables earlier steps set with result=. read[service Read issues | result=issues] > count[script Count open issues | result=openCount feel=count(issues[state = \"open\"])]\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]";
|
|
32
33
|
/** A line, or part of one, that {@link parseProcessText} could not use. */
|
|
33
34
|
export interface ProcessTextProblem {
|
|
34
35
|
/** 1-based line number in the text. */
|
|
@@ -62,6 +63,16 @@ export interface ProcessTextResult {
|
|
|
62
63
|
fixes: string[];
|
|
63
64
|
/** The guesses behind the fixes that only the reader can confirm, in the order of the text. */
|
|
64
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;
|
|
65
76
|
}
|
|
66
77
|
export declare const KINDS: Record<string, BpmnElementType>;
|
|
67
78
|
/**
|
|
@@ -72,6 +83,16 @@ export declare const KINDS: Record<string, BpmnElementType>;
|
|
|
72
83
|
export declare const ALIASES: Record<string, BpmnElementType>;
|
|
73
84
|
export declare const TRIGGERS: Set<string>;
|
|
74
85
|
export declare const EVENTS: Set<BpmnElementType>;
|
|
86
|
+
/**
|
|
87
|
+
* Splits `feel=` off a declaration's attributes. A FEEL expression has spaces and
|
|
88
|
+
* commas, so it takes the rest of them: `| result=open feel=count(issues[state = "open"])`.
|
|
89
|
+
*
|
|
90
|
+
* @returns The other attributes, and the expression with its leading `=`, if any.
|
|
91
|
+
*/
|
|
92
|
+
export declare function splitFeel(attrs: string): {
|
|
93
|
+
plain: string;
|
|
94
|
+
feel?: string;
|
|
95
|
+
};
|
|
75
96
|
/** A path line split into its parts. */
|
|
76
97
|
export interface PathTokens {
|
|
77
98
|
/** The nodes in the order written, each with the bracket text it was declared with, if any. */
|
|
@@ -83,6 +104,15 @@ export interface PathTokens {
|
|
|
83
104
|
labels: (string | undefined)[];
|
|
84
105
|
/** A parenthesised note after the last node, which carries no meaning. */
|
|
85
106
|
note?: string;
|
|
107
|
+
/** Ids written with spaces (`call back[…]`), and the id each was read as. */
|
|
108
|
+
joined?: {
|
|
109
|
+
written: string;
|
|
110
|
+
id: string;
|
|
111
|
+
}[];
|
|
112
|
+
/** Ids whose bracket was never closed, read as closed where the name ends. */
|
|
113
|
+
unclosed?: string[];
|
|
114
|
+
/** Kinds written with a name but no brackets after an arrow (`> end Done`), read as declared. */
|
|
115
|
+
bracketless?: string[];
|
|
86
116
|
}
|
|
87
117
|
/**
|
|
88
118
|
* Splits one complete path line (`a[kind Name] >(Label: cond) b > c`) into its
|
|
@@ -106,6 +136,11 @@ export declare function conditionOrLabel(edge: Pick<CompactFlow, "name" | "condi
|
|
|
106
136
|
edge: Pick<CompactFlow, "name" | "condition" | "isDefault">;
|
|
107
137
|
problem?: string;
|
|
108
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* An ISO 8601 duration from what models write: `PT5M` as it is, `5m`, `5 min`,
|
|
141
|
+
* `5 minutes`, `2 hours` or `1 day`, also inside a name ("Wait 5 minutes").
|
|
142
|
+
*/
|
|
143
|
+
export declare function duration(text: string): string | undefined;
|
|
109
144
|
export declare function edgeLabel(label: string | undefined): Pick<CompactFlow, "name" | "condition" | "isDefault">;
|
|
110
145
|
/**
|
|
111
146
|
* Reads a process written in the line format ({@link PROCESS_TEXT_GUIDE}).
|