@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
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { parseExpression } from "@bpmnkit/feel";
|
|
24
24
|
import { slugify, uniqueId } from "../plan/slug.js";
|
|
25
25
|
import { expand } from "./compact.js";
|
|
26
|
+
import { CONNECTOR_LINE, parseConnectorLine } from "./connector-line.js";
|
|
26
27
|
/**
|
|
27
28
|
* How to write the format — the part of a system prompt that teaches it.
|
|
28
29
|
*
|
|
@@ -37,12 +38,15 @@ gw >(Label: condition) x conditional branch, condition in FEEL (amount > 1000,
|
|
|
37
38
|
gw >(Label: default) y branch taken when no condition holds
|
|
38
39
|
Kinds: 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
|
|
39
40
|
Events take a trigger: start:message end:error catch:timer boundary:error (timer message signal error escalation terminate conditional compensate cancel)
|
|
40
|
-
Attributes after |: on=<task id> (required on boundary), nonint (non-interrupting), job=<job type>
|
|
41
|
+
Attributes 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)
|
|
41
42
|
Rules:
|
|
42
43
|
- One start event. Every node is on a path from it to an end event: never a node nothing leads to.
|
|
43
44
|
- An xor has two or more branches: exactly one is (Label: default), each other has a FEEL condition.
|
|
44
45
|
- 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.
|
|
46
|
+
- A boundary leads only to the handling. What happens next when nothing fails follows the task itself (read > count), never the boundary.
|
|
47
|
+
- 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"])]
|
|
45
48
|
- Branches that meet again are joined automatically; join parallel branches with an and node.
|
|
49
|
+
- 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.
|
|
46
50
|
|
|
47
51
|
Example:
|
|
48
52
|
# Expense approval
|
|
@@ -137,6 +141,29 @@ function matching(text, start, open, close) {
|
|
|
137
141
|
}
|
|
138
142
|
return -1;
|
|
139
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Splits `feel=` off a declaration's attributes. A FEEL expression has spaces and
|
|
146
|
+
* commas, so it takes the rest of them: `| result=open feel=count(issues[state = "open"])`.
|
|
147
|
+
*
|
|
148
|
+
* @returns The other attributes, and the expression with its leading `=`, if any.
|
|
149
|
+
*/
|
|
150
|
+
export function splitFeel(attrs) {
|
|
151
|
+
const at = /(?:^|[\s,|])feel=/.exec(attrs);
|
|
152
|
+
if (!at)
|
|
153
|
+
return { plain: attrs };
|
|
154
|
+
const feel = attrs.slice(at.index + at[0].length).trim();
|
|
155
|
+
if (feel === "")
|
|
156
|
+
return { plain: attrs.slice(0, at.index) };
|
|
157
|
+
return { plain: attrs.slice(0, at.index), feel: feel.startsWith("=") ? feel : `= ${feel}` };
|
|
158
|
+
}
|
|
159
|
+
/** Words that name the handling of a failure, a timeout or a cancellation. */
|
|
160
|
+
const HANDLING = /\b(?:fail\w*|error\w*|handle\w*|alert\w*|notify\w*|retr(?:y|ies)|escalat\w*|cancel\w*|reject\w*|abort\w*|roll\s?back|compensat\w*|timeout|timed out|late)\b/i;
|
|
161
|
+
/** Whether `element` reads as the handling of what a boundary catches. */
|
|
162
|
+
function handles(element) {
|
|
163
|
+
if (element === undefined)
|
|
164
|
+
return false;
|
|
165
|
+
return HANDLING.test(element.name ?? "") || HANDLING.test(element.id.replace(/[_.-]+/g, " "));
|
|
166
|
+
}
|
|
140
167
|
/** The type a bare id suggests, for a node written without a kind or never declared. */
|
|
141
168
|
function typeFromId(id) {
|
|
142
169
|
// `pick > and`, `and > dispatch`: the kind written as if it were an id.
|
|
@@ -168,24 +195,66 @@ function nameFromId(id) {
|
|
|
168
195
|
export function tokenizePath(text) {
|
|
169
196
|
const refs = [];
|
|
170
197
|
const labels = [];
|
|
198
|
+
const joined = [];
|
|
199
|
+
const unclosed = [];
|
|
200
|
+
const bracketless = [];
|
|
171
201
|
let note;
|
|
172
202
|
let i = 0;
|
|
173
203
|
for (;;) {
|
|
174
|
-
|
|
175
|
-
|
|
204
|
+
let id = ID.exec(text.slice(i))?.[0];
|
|
205
|
+
// `1[service List runs] > 2[xor …]`: numbers for ids, which BPMN ids cannot start with
|
|
206
|
+
const number = id === undefined ? /^\d[\w-]*(?=\s*(?:\[|-{0,2}>))/.exec(text.slice(i))?.[0] : undefined;
|
|
207
|
+
if (number !== undefined) {
|
|
208
|
+
id = `n${number}`;
|
|
209
|
+
if (!joined.some((j) => j.id === id))
|
|
210
|
+
joined.push({ written: number, id });
|
|
211
|
+
i += number.length;
|
|
212
|
+
}
|
|
213
|
+
else if (id === undefined) {
|
|
176
214
|
return { error: `expected a node id at "${text.slice(i, i + 20)}"` };
|
|
177
|
-
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
i += id.length;
|
|
218
|
+
}
|
|
219
|
+
// `call back[service …]`: words before a bracket are one id
|
|
220
|
+
const words = /^((?: +[A-Za-z_][\w.-]*)+)(?= *\[)/.exec(text.slice(i))?.[1];
|
|
221
|
+
if (words !== undefined) {
|
|
222
|
+
const written = `${id}${words}`;
|
|
223
|
+
id = written.split(/ +/).join("_");
|
|
224
|
+
joined.push({ written, id });
|
|
225
|
+
i += words.length;
|
|
226
|
+
}
|
|
178
227
|
let spec;
|
|
228
|
+
// `… > xor Notify sales? >(Yes: …)`: a kind and a name without brackets, after an
|
|
229
|
+
// arrow. At the start of a line it is more likely prose ("end of the answer").
|
|
230
|
+
const bare = refs.length > 0 && KINDS[id] !== undefined
|
|
231
|
+
? /^ +([^[\]()>|]+?)(?=\s*(?:-{0,2}>|$))/.exec(text.slice(i))
|
|
232
|
+
: null;
|
|
233
|
+
if (bare?.[1]) {
|
|
234
|
+
spec = `${id} ${bare[1].trim()}`;
|
|
235
|
+
bracketless.push(id);
|
|
236
|
+
i += bare[0].length;
|
|
237
|
+
}
|
|
179
238
|
// `done-end [end Done]`: a space before the bracket still declares.
|
|
180
239
|
const gap = /^ +\[/.exec(text.slice(i));
|
|
181
240
|
if (gap)
|
|
182
241
|
i += gap[0].length - 1;
|
|
183
242
|
if (text[i] === "[") {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
243
|
+
let end = matching(text, i, "[", "]");
|
|
244
|
+
let after = end + 1;
|
|
245
|
+
if (end < 0) {
|
|
246
|
+
// `start[start HR) > …` or `end[Page created` at the end of the line: the
|
|
247
|
+
// bracket closes where its name plainly ends, before the next arrow
|
|
248
|
+
const open = /^[^[\]]*?(?:\)(?=\s*-{0,2}>)|(?=\s+-{0,2}>)|$)/.exec(text.slice(i + 1))?.[0];
|
|
249
|
+
if (open === undefined || open.trim() === "")
|
|
250
|
+
return { error: `"${id}[" is not closed` };
|
|
251
|
+
const closer = open.endsWith(")") ? 1 : 0;
|
|
252
|
+
end = i + 1 + open.length - closer;
|
|
253
|
+
after = i + 1 + open.length;
|
|
254
|
+
unclosed.push(id);
|
|
255
|
+
}
|
|
187
256
|
spec = text.slice(i + 1, end).trim();
|
|
188
|
-
i =
|
|
257
|
+
i = after;
|
|
189
258
|
}
|
|
190
259
|
refs.push({ id, spec });
|
|
191
260
|
while (text[i] === " ")
|
|
@@ -205,6 +274,10 @@ export function tokenizePath(text) {
|
|
|
205
274
|
return { error: `expected ">" at "${text.slice(i, i + 20)}"` };
|
|
206
275
|
i += arrow.length;
|
|
207
276
|
let label;
|
|
277
|
+
// `credit > (No: default) decision`: a space before the label
|
|
278
|
+
const spaced = /^ +\(/.exec(text.slice(i));
|
|
279
|
+
if (spaced)
|
|
280
|
+
i += spaced[0].length - 1;
|
|
208
281
|
if (text[i] === "(") {
|
|
209
282
|
const end = matching(text, i, "(", ")");
|
|
210
283
|
if (end < 0)
|
|
@@ -222,7 +295,16 @@ export function tokenizePath(text) {
|
|
|
222
295
|
i++;
|
|
223
296
|
}
|
|
224
297
|
}
|
|
225
|
-
|
|
298
|
+
const tokens = { refs, labels };
|
|
299
|
+
if (note !== undefined)
|
|
300
|
+
tokens.note = note;
|
|
301
|
+
if (joined.length > 0)
|
|
302
|
+
tokens.joined = joined;
|
|
303
|
+
if (unclosed.length > 0)
|
|
304
|
+
tokens.unclosed = unclosed;
|
|
305
|
+
if (bracketless.length > 0)
|
|
306
|
+
tokens.bracketless = bracketless;
|
|
307
|
+
return tokens;
|
|
226
308
|
}
|
|
227
309
|
/**
|
|
228
310
|
* Keeps a condition only if it is FEEL.
|
|
@@ -257,11 +339,17 @@ class Reader {
|
|
|
257
339
|
taken = new Set();
|
|
258
340
|
edges = [];
|
|
259
341
|
problems = [];
|
|
342
|
+
/** What reading a declaration repaired, listed with the parser's other fixes. */
|
|
343
|
+
fixes = [];
|
|
344
|
+
/** `with` lines, with the written id resolved to the node it meant when read. */
|
|
345
|
+
connectors = [];
|
|
260
346
|
/** Catch and boundary events written without a trigger, and made message events. */
|
|
261
347
|
guessedMessage = new Set();
|
|
262
348
|
title;
|
|
263
349
|
/** A line that ended in an arrow, waiting for the line that continues it. */
|
|
264
350
|
carry;
|
|
351
|
+
/** The last node of the last path read, which a line starting with an arrow continues. */
|
|
352
|
+
tail;
|
|
265
353
|
/** Reads one line. Returns whether it added anything. */
|
|
266
354
|
line(raw, n) {
|
|
267
355
|
let text = raw.trim();
|
|
@@ -278,6 +366,24 @@ class Reader {
|
|
|
278
366
|
this.title = text.replace(/^#+/, "").trim() || undefined;
|
|
279
367
|
return false;
|
|
280
368
|
}
|
|
369
|
+
if (CONNECTOR_LINE.test(text)) {
|
|
370
|
+
const connector = parseConnectorLine(text, n, this.problems);
|
|
371
|
+
if (connector) {
|
|
372
|
+
this.connectors.push({
|
|
373
|
+
...connector,
|
|
374
|
+
elementId: this.current.get(connector.id) ?? connector.id,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
// `> stop[end Done]`: the path above wrapped before its arrow
|
|
380
|
+
if (/^-{0,2}>/.test(text) && this.tail !== undefined) {
|
|
381
|
+
this.problems.push({
|
|
382
|
+
line: n,
|
|
383
|
+
message: `the line starts with ">"; read it as continuing "${this.tail}"`,
|
|
384
|
+
});
|
|
385
|
+
text = `${this.tail} ${text}`;
|
|
386
|
+
}
|
|
281
387
|
// `engineer[user Fix issue] >` then the next step on the next line: models
|
|
282
388
|
// wrap a long path. The line is read once it is complete.
|
|
283
389
|
if (DANGLING.test(text)) {
|
|
@@ -307,6 +413,21 @@ class Reader {
|
|
|
307
413
|
if (path.note !== undefined) {
|
|
308
414
|
this.problems.push({ line: n, message: `ignored the note "${path.note}"` });
|
|
309
415
|
}
|
|
416
|
+
for (const id of path.bracketless ?? []) {
|
|
417
|
+
this.problems.push({
|
|
418
|
+
line: n,
|
|
419
|
+
message: `"${id} …" has no brackets; read it as declaring "${id}"`,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
for (const id of path.unclosed ?? []) {
|
|
423
|
+
this.problems.push({
|
|
424
|
+
line: n,
|
|
425
|
+
message: `"${id}[" is not closed; closed it where its name ends`,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
for (const { written, id } of path.joined ?? []) {
|
|
429
|
+
this.problems.push({ line: n, message: `"${written}" is not an id; read as "${id}"` });
|
|
430
|
+
}
|
|
310
431
|
const { refs, labels } = path;
|
|
311
432
|
// Declarations and references resolve left to right, so a chain that
|
|
312
433
|
// reuses an id (`task[A] > task[B]`) links the nodes in the order written.
|
|
@@ -320,6 +441,7 @@ class Reader {
|
|
|
320
441
|
this.edges.push({ from, to, line: n, ...this.feelOrLabel(edgeLabel(labels[k]), n) });
|
|
321
442
|
}
|
|
322
443
|
}
|
|
444
|
+
this.tail = ids.at(-1);
|
|
323
445
|
return true;
|
|
324
446
|
}
|
|
325
447
|
/** {@link conditionOrLabel}, with its problem recorded against line `n`. */
|
|
@@ -357,7 +479,10 @@ class Reader {
|
|
|
357
479
|
const word = spec.split(/[\s|]/, 1)[0]?.toLowerCase().split(":")[0] ?? "";
|
|
358
480
|
const kind = KINDS[word] ?? ALIASES[word];
|
|
359
481
|
// A boundary is always new: it cannot be a revision of the task it sits on.
|
|
360
|
-
|
|
482
|
+
// `send[…] > send[post Slack message to #support]`: a name of several words
|
|
483
|
+
// after an arrow is a second node, whatever its kind word
|
|
484
|
+
const named = afterArrow && !spec.includes("=") && spec.trim().split(/\s+/).length >= 3;
|
|
485
|
+
if ((kind === undefined && !named) || (!afterArrow && kind !== "boundaryEvent")) {
|
|
361
486
|
this.problems.push({
|
|
362
487
|
line: n,
|
|
363
488
|
message: `"${written}" is already declared on line ${earlier.line}; ignored "${spec}"`,
|
|
@@ -383,8 +508,12 @@ class Reader {
|
|
|
383
508
|
});
|
|
384
509
|
}
|
|
385
510
|
const bar = spec.indexOf("|");
|
|
386
|
-
|
|
387
|
-
const
|
|
511
|
+
// `boundary:timer on=poll`: an attribute written before the bar is one still
|
|
512
|
+
const loose = /\s+((?:on|job|each|after|result)=\S+|nonint)(?=\s|$)/g;
|
|
513
|
+
const beforeBar = bar < 0 ? spec : spec.slice(0, bar);
|
|
514
|
+
const head = beforeBar.replace(loose, "").trim();
|
|
515
|
+
const attrs = [...beforeBar.matchAll(loose)].map((m) => m[1]).join(" ") +
|
|
516
|
+
(bar < 0 ? "" : ` ${spec.slice(bar + 1)}`);
|
|
388
517
|
const space = head.search(/\s/);
|
|
389
518
|
const kindWord = space < 0 ? head : head.slice(0, space);
|
|
390
519
|
const name = space < 0 ? undefined : head.slice(space + 1).trim() || undefined;
|
|
@@ -436,7 +565,20 @@ class Reader {
|
|
|
436
565
|
element.name = label;
|
|
437
566
|
// A catch or boundary event waits for something, and cannot deploy without
|
|
438
567
|
// saying what. Unnamed, it is most often a message: "Payment confirmed".
|
|
439
|
-
|
|
568
|
+
// `queue[event catch Send to SQS]` is named for a call it makes, not for what it waits
|
|
569
|
+
// for: it is a service task, as every call to an outside system is
|
|
570
|
+
const call = element.type === "intermediateCatchEvent" && element.eventType === undefined
|
|
571
|
+
? /^(?:(?:catch|throw|event)\s+)?((?:send|post|publish|call|notify|invoke|push|upload|create|update|delete|run|trigger)\b.*)$/i.exec(label ?? "")?.[1]
|
|
572
|
+
: undefined;
|
|
573
|
+
if (call !== undefined) {
|
|
574
|
+
element.type = "serviceTask";
|
|
575
|
+
element.name = call;
|
|
576
|
+
this.problems.push({
|
|
577
|
+
line: n,
|
|
578
|
+
message: `"${id}" is named for a call it makes, "${call}"; made it a service task`,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
else if ((element.type === "intermediateCatchEvent" || element.type === "boundaryEvent") &&
|
|
440
582
|
element.eventType === undefined) {
|
|
441
583
|
element.eventType = "message";
|
|
442
584
|
this.guessedMessage.add(id);
|
|
@@ -446,8 +588,9 @@ class Reader {
|
|
|
446
588
|
});
|
|
447
589
|
}
|
|
448
590
|
const node = { element, line: n, spec };
|
|
591
|
+
const { plain, feel } = splitFeel(attrs);
|
|
449
592
|
// `| on=pay | nonint`: a second bar is only another separator.
|
|
450
|
-
for (const attr of
|
|
593
|
+
for (const attr of plain.split(/[\s,|]+/).filter(Boolean)) {
|
|
451
594
|
const [key, value] = attr.split("=", 2);
|
|
452
595
|
if (key === "on" && value)
|
|
453
596
|
node.on = hostOf.get(value) ?? value;
|
|
@@ -455,13 +598,149 @@ class Reader {
|
|
|
455
598
|
element.jobType = value;
|
|
456
599
|
else if (key === "nonint" && value === undefined)
|
|
457
600
|
element.interrupting = false;
|
|
601
|
+
else if (key === "each" && value && GATEWAYS.has(element.type) && element.name) {
|
|
602
|
+
// `and[and Process every recipient | each=recipients]`: a step, run per item
|
|
603
|
+
this.problems.push({
|
|
604
|
+
line: n,
|
|
605
|
+
message: `"${id}" is a gateway with each=, named like a step; made it a task run per item`,
|
|
606
|
+
});
|
|
607
|
+
element.type = "task";
|
|
608
|
+
element.multiInstance = {
|
|
609
|
+
collection: value.startsWith("=") ? value : `=${value}`,
|
|
610
|
+
element: itemOf(value.replace(/^=/, "")),
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
else if (key === "each" && value && ACTIVITIES.has(element.type)) {
|
|
614
|
+
element.multiInstance = {
|
|
615
|
+
collection: value.startsWith("=") ? value : `=${value}`,
|
|
616
|
+
element: itemOf(value.replace(/^=/, "")),
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
else if (key === "after" && value && EVENTS.has(element.type) && duration(value)) {
|
|
620
|
+
// `delay[boundary:error Timeout | after=P1D]`: only a timer waits for a time
|
|
621
|
+
if (element.eventType !== "timer" && element.type !== "endEvent") {
|
|
622
|
+
this.problems.push({
|
|
623
|
+
line: n,
|
|
624
|
+
message: `"${id}" waits ${value}, which only a timer does; made it a timer event`,
|
|
625
|
+
});
|
|
626
|
+
element.eventType = "timer";
|
|
627
|
+
}
|
|
628
|
+
element.timerDuration = duration(value);
|
|
629
|
+
}
|
|
630
|
+
else if (key === "result" && value && ACTIVITIES.has(element.type)) {
|
|
631
|
+
element.resultVariable = value;
|
|
632
|
+
}
|
|
458
633
|
else
|
|
459
634
|
this.problems.push({ line: n, message: `unknown attribute "${attr}" on "${id}"; ignored` });
|
|
460
635
|
}
|
|
636
|
+
if (feel !== undefined) {
|
|
637
|
+
// `calc[task Count open issues | feel=…]`: a step that evaluates FEEL is a script task
|
|
638
|
+
if (element.type === "task")
|
|
639
|
+
element.type = "scriptTask";
|
|
640
|
+
if (element.type === "scriptTask") {
|
|
641
|
+
element.script = feel;
|
|
642
|
+
element.resultVariable ??= id;
|
|
643
|
+
if (parseExpression(feel.slice(1)).errors.length > 0) {
|
|
644
|
+
this.problems.push({
|
|
645
|
+
line: n,
|
|
646
|
+
message: `feel= on "${id}" is not FEEL; kept for the reader to correct`,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
this.problems.push({
|
|
652
|
+
line: n,
|
|
653
|
+
message: `only a script task evaluates feel=; ignored on "${id}"`,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
// `late[catch:timer | on=poll after=PT5M]`: an event on a task is a boundary event
|
|
658
|
+
const host = node.on === undefined ? undefined : this.nodes.get(node.on)?.element;
|
|
659
|
+
if (element.type === "intermediateCatchEvent" && host && ACTIVITIES.has(host.type)) {
|
|
660
|
+
element.type = "boundaryEvent";
|
|
661
|
+
this.problems.push({
|
|
662
|
+
line: n,
|
|
663
|
+
message: `"${id}" is a catch event on "${node.on}"; made it a boundary event`,
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
// "Send email to each stakeholder": a step its name says is done per item runs once
|
|
667
|
+
// per item of the list of them, whose variable only the reader can name for sure
|
|
668
|
+
const per = /\b(?:each|every)\s+([a-z]{3,})\b/i.exec(label ?? "")?.[1]?.toLowerCase();
|
|
669
|
+
if (per &&
|
|
670
|
+
!TIME_WORDS.has(per) &&
|
|
671
|
+
ACTIVITIES.has(element.type) &&
|
|
672
|
+
element.multiInstance === undefined) {
|
|
673
|
+
const list = per.endsWith("y") && !/[aeiou]y$/.test(per) ? `${per.slice(0, -1)}ies` : `${per}s`;
|
|
674
|
+
element.multiInstance = { collection: `=${list}`, element: per };
|
|
675
|
+
this.fixes.push(`"${id}" runs once per ${per}, over the list "${list}"`);
|
|
676
|
+
}
|
|
677
|
+
// `late[boundary:timer 5 minutes | on=poll]`: a timer's name says how long it waits
|
|
678
|
+
if (element.eventType === "timer" && element.timerDuration === undefined && label) {
|
|
679
|
+
const said = duration(label);
|
|
680
|
+
if (said)
|
|
681
|
+
element.timerDuration = said;
|
|
682
|
+
}
|
|
461
683
|
this.nodes.set(id, node);
|
|
462
684
|
return id;
|
|
463
685
|
}
|
|
464
686
|
}
|
|
687
|
+
/** "Every day" is a schedule, not a list. */
|
|
688
|
+
const TIME_WORDS = new Set([
|
|
689
|
+
"second",
|
|
690
|
+
"minute",
|
|
691
|
+
"hour",
|
|
692
|
+
"day",
|
|
693
|
+
"week",
|
|
694
|
+
"month",
|
|
695
|
+
"quarter",
|
|
696
|
+
"year",
|
|
697
|
+
"morning",
|
|
698
|
+
"evening",
|
|
699
|
+
"night",
|
|
700
|
+
"time",
|
|
701
|
+
"other",
|
|
702
|
+
]);
|
|
703
|
+
/** Element types `each=` makes multi-instance. */
|
|
704
|
+
const ACTIVITIES = new Set([
|
|
705
|
+
"task",
|
|
706
|
+
"serviceTask",
|
|
707
|
+
"sendTask",
|
|
708
|
+
"receiveTask",
|
|
709
|
+
"userTask",
|
|
710
|
+
"manualTask",
|
|
711
|
+
"scriptTask",
|
|
712
|
+
"businessRuleTask",
|
|
713
|
+
"callActivity",
|
|
714
|
+
"subProcess",
|
|
715
|
+
]);
|
|
716
|
+
/** The variable one item of a list is in: `recipients` → `recipient`, else `item`. */
|
|
717
|
+
function itemOf(collection) {
|
|
718
|
+
if (!/^[A-Za-z_]\w*$/.test(collection))
|
|
719
|
+
return "item";
|
|
720
|
+
if (collection.endsWith("ies") && collection.length > 4)
|
|
721
|
+
return `${collection.slice(0, -3)}y`;
|
|
722
|
+
if (collection.endsWith("s") && !collection.endsWith("ss") && collection.length > 3)
|
|
723
|
+
return collection.slice(0, -1);
|
|
724
|
+
return "item";
|
|
725
|
+
}
|
|
726
|
+
const UNITS = { s: "S", m: "M", h: "H", d: "D", w: "W" };
|
|
727
|
+
/**
|
|
728
|
+
* An ISO 8601 duration from what models write: `PT5M` as it is, `5m`, `5 min`,
|
|
729
|
+
* `5 minutes`, `2 hours` or `1 day`, also inside a name ("Wait 5 minutes").
|
|
730
|
+
*/
|
|
731
|
+
export function duration(text) {
|
|
732
|
+
// `p1d` is P1D: models write ISO durations in lower case too
|
|
733
|
+
const iso = /\bP(?:\d+[YMWD])*(?:T(?:\d+[HMS])+)?\b/i.exec(text)?.[0]?.toUpperCase();
|
|
734
|
+
if (iso && iso !== "P" && iso !== "PT")
|
|
735
|
+
return iso;
|
|
736
|
+
const m = /(\d+)\s*(s|sec|secs|seconds?|m|min|mins|minutes?|h|hrs?|hours?|d|days?|w|weeks?)\b/i.exec(text);
|
|
737
|
+
if (!m?.[1] || !m[2])
|
|
738
|
+
return undefined;
|
|
739
|
+
const unit = UNITS[m[2][0]?.toLowerCase() ?? ""];
|
|
740
|
+
if (unit === undefined)
|
|
741
|
+
return undefined;
|
|
742
|
+
return unit === "D" || unit === "W" ? `P${m[1]}${unit}` : `PT${m[1]}${unit}`;
|
|
743
|
+
}
|
|
465
744
|
export function edgeLabel(label) {
|
|
466
745
|
if (label === undefined)
|
|
467
746
|
return {};
|
|
@@ -511,7 +790,7 @@ function variableFrom(text) {
|
|
|
511
790
|
*/
|
|
512
791
|
function assemble(reader, final) {
|
|
513
792
|
const problems = [...reader.problems];
|
|
514
|
-
const fixes = [];
|
|
793
|
+
const fixes = [...reader.fixes];
|
|
515
794
|
// Asked once the names are final, so a question uses the names the diagram shows.
|
|
516
795
|
const asks = [];
|
|
517
796
|
const nodes = new Map();
|
|
@@ -545,6 +824,14 @@ function assemble(reader, final) {
|
|
|
545
824
|
for (const [id, node] of nodes) {
|
|
546
825
|
if (node.element.type !== "boundaryEvent")
|
|
547
826
|
continue;
|
|
827
|
+
// `send > wait[boundary:timer …]` without on=: the one task drawn into it is its host
|
|
828
|
+
const drawn = node.on === undefined ? reader.edges.filter((edge) => edge.to === id) : [];
|
|
829
|
+
const from = drawn.length === 1 ? nodes.get(drawn[0]?.from ?? "") : undefined;
|
|
830
|
+
if (from && drawn[0] && !EVENTS.has(from.element.type) && !GATEWAYS.has(from.element.type)) {
|
|
831
|
+
node.on = from.element.id;
|
|
832
|
+
reader.edges.splice(reader.edges.indexOf(drawn[0]), 1);
|
|
833
|
+
fixes.push(`put boundary "${id}" on "${from.element.id}", the task drawn into it`);
|
|
834
|
+
}
|
|
548
835
|
const host = node.on === undefined ? undefined : nodes.get(node.on);
|
|
549
836
|
const hostType = host?.element.type;
|
|
550
837
|
if (hostType !== undefined && !EVENTS.has(hostType) && !GATEWAYS.has(hostType)) {
|
|
@@ -569,8 +856,12 @@ function assemble(reader, final) {
|
|
|
569
856
|
// on=pay] > notify`) means the path that boundary leads to. Nothing can flow
|
|
570
857
|
// into a boundary, so the branch goes to its handler instead of being lost.
|
|
571
858
|
const written = reader.edges.flatMap((edge) => {
|
|
572
|
-
|
|
859
|
+
const target = reader.nodes.get(edge.to);
|
|
860
|
+
if (target?.element.type !== "boundaryEvent")
|
|
573
861
|
return [edge];
|
|
862
|
+
// `poll > late[… | on=poll]`: the arrow from its own task only says where it sits
|
|
863
|
+
if (target.on === edge.from)
|
|
864
|
+
return [];
|
|
574
865
|
const next = reader.edges.filter((out) => out.from === edge.to);
|
|
575
866
|
if (next.length === 0)
|
|
576
867
|
return [edge];
|
|
@@ -639,6 +930,38 @@ function assemble(reader, final) {
|
|
|
639
930
|
const outOf = (id) => edges.filter((edge) => edge.from === id);
|
|
640
931
|
const into = (id) => edges.filter((edge) => edge.to === id);
|
|
641
932
|
if (final) {
|
|
933
|
+
// A boundary leads to the handling of what it catches, and to nothing else:
|
|
934
|
+
// the work that goes on when nothing goes wrong follows the task. A model
|
|
935
|
+
// often writes that work through the boundary instead (`read >
|
|
936
|
+
// err[boundary:error … | on=read] > handle`, then `err > count > post`),
|
|
937
|
+
// which would run it only when the task fails. The ways out named for
|
|
938
|
+
// handling it stay (the first, when none is), and the rest move to the task. A bare end the task led to goes: it only stood in for
|
|
939
|
+
// the work that now follows.
|
|
940
|
+
for (const node of [...nodes.values()]) {
|
|
941
|
+
const { id, type, attachedTo } = node.element;
|
|
942
|
+
if (type !== "boundaryEvent" || attachedTo === undefined)
|
|
943
|
+
continue;
|
|
944
|
+
const out = outOf(id);
|
|
945
|
+
if (out.length < 2)
|
|
946
|
+
continue;
|
|
947
|
+
const handling = out.filter((edge) => handles(nodes.get(edge.to)?.element));
|
|
948
|
+
const rest = handling.length > 0 ? out.filter((edge) => !handling.includes(edge)) : out.slice(1);
|
|
949
|
+
if (rest.length === 0)
|
|
950
|
+
continue;
|
|
951
|
+
for (const edge of outOf(attachedTo)) {
|
|
952
|
+
const end = nodes.get(edge.to)?.element;
|
|
953
|
+
if (end?.type !== "endEvent" || end.eventType !== undefined)
|
|
954
|
+
continue;
|
|
955
|
+
if (into(end.id).length > 1)
|
|
956
|
+
continue;
|
|
957
|
+
nodes.delete(end.id);
|
|
958
|
+
edges = edges.filter((other) => other !== edge);
|
|
959
|
+
fixes.push(`removed end event "${end.id}" after "${attachedTo}", whose work followed its boundary`);
|
|
960
|
+
}
|
|
961
|
+
for (const edge of rest)
|
|
962
|
+
edge.from = attachedTo;
|
|
963
|
+
fixes.push(`moved ${rest.map((edge) => `${id} > ${edge.to}`).join(", ")} onto "${attachedTo}": a boundary leads only to its handling`);
|
|
964
|
+
}
|
|
642
965
|
// One blank start: a process that starts twice with no trigger to tell the
|
|
643
966
|
// two apart is two processes. The later one goes, and what it led to is
|
|
644
967
|
// placed as any path nothing leads to is, below.
|
|
@@ -835,10 +1158,56 @@ function assemble(reader, final) {
|
|
|
835
1158
|
},
|
|
836
1159
|
});
|
|
837
1160
|
}
|
|
1161
|
+
// `fork[and] > pick > pack > label > joined[and]`: steps between an and split and an
|
|
1162
|
+
// and join with nothing beside them are the parallel branches, drawn in a row
|
|
1163
|
+
for (const [id, node] of nodes) {
|
|
1164
|
+
if (node.element.type !== "parallelGateway")
|
|
1165
|
+
continue;
|
|
1166
|
+
if (into(id).length !== 1 || outOf(id).length !== 1)
|
|
1167
|
+
continue;
|
|
1168
|
+
const chain = [];
|
|
1169
|
+
let at = outOf(id)[0]?.to;
|
|
1170
|
+
while (at !== undefined) {
|
|
1171
|
+
const next = nodes.get(at)?.element;
|
|
1172
|
+
if (!next || GATEWAYS.has(next.type) || EVENTS.has(next.type))
|
|
1173
|
+
break;
|
|
1174
|
+
if (into(at).length !== 1 || outOf(at).length !== 1)
|
|
1175
|
+
break;
|
|
1176
|
+
chain.push(at);
|
|
1177
|
+
at = outOf(at)[0]?.to;
|
|
1178
|
+
}
|
|
1179
|
+
const join = at === undefined ? undefined : nodes.get(at);
|
|
1180
|
+
if (chain.length < 2 ||
|
|
1181
|
+
!join ||
|
|
1182
|
+
at === undefined ||
|
|
1183
|
+
join.element.type !== "parallelGateway" ||
|
|
1184
|
+
into(at).length !== 1) {
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
const end = at;
|
|
1188
|
+
edges = edges.filter((edge) => edge.from !== id && !chain.includes(edge.from));
|
|
1189
|
+
for (const step of chain) {
|
|
1190
|
+
edges.push({ from: id, to: step, line: node.line });
|
|
1191
|
+
edges.push({ from: step, to: end, line: node.line });
|
|
1192
|
+
}
|
|
1193
|
+
fixes.push(`ran ${chain.map((c) => `"${c}"`).join(", ")} in parallel between "${id}" and "${end}", as their and nodes say`);
|
|
1194
|
+
}
|
|
838
1195
|
// Pass-through gateways: one way in and one way out decides nothing. Most
|
|
839
1196
|
// often a question the model asked and then answered only one way.
|
|
1197
|
+
const dedupe = () => {
|
|
1198
|
+
const once = new Set();
|
|
1199
|
+
edges = edges.filter((edge) => {
|
|
1200
|
+
const key = `${edge.from}>${edge.to}`;
|
|
1201
|
+
if (once.has(key))
|
|
1202
|
+
return false;
|
|
1203
|
+
once.add(key);
|
|
1204
|
+
return true;
|
|
1205
|
+
});
|
|
1206
|
+
};
|
|
840
1207
|
for (let removed = true; removed;) {
|
|
841
1208
|
removed = false;
|
|
1209
|
+
// Removing one gateway can leave two flows between the same nodes: one is enough
|
|
1210
|
+
dedupe();
|
|
842
1211
|
for (const [id, node] of nodes) {
|
|
843
1212
|
if (!GATEWAYS.has(node.element.type))
|
|
844
1213
|
continue;
|
|
@@ -848,6 +1217,16 @@ function assemble(reader, final) {
|
|
|
848
1217
|
continue;
|
|
849
1218
|
if (inEdge.from === outEdge.to)
|
|
850
1219
|
continue;
|
|
1220
|
+
// `pack[and Pack into box]`: a step written with a gateway's kind is that step
|
|
1221
|
+
if (node.element.name &&
|
|
1222
|
+
(node.element.type === "parallelGateway" || node.element.type === "inclusiveGateway")) {
|
|
1223
|
+
node.element.type = "task";
|
|
1224
|
+
problems.push({
|
|
1225
|
+
line: node.line,
|
|
1226
|
+
message: `"${id}" is a gateway with one way in and out, named like a step; made it a task`,
|
|
1227
|
+
});
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
851
1230
|
const target = typeOf(outEdge.to);
|
|
852
1231
|
if (node.element.type === "eventBasedGateway" &&
|
|
853
1232
|
target !== "intermediateCatchEvent" &&
|
|
@@ -899,7 +1278,9 @@ function assemble(reader, final) {
|
|
|
899
1278
|
const out = outOf(id);
|
|
900
1279
|
if (GATEWAYS.has(type) || out.length < 2)
|
|
901
1280
|
continue;
|
|
902
|
-
|
|
1281
|
+
// A DMN decision's outcomes are alternatives, labelled or not
|
|
1282
|
+
const decides = type === "businessRuleTask" ||
|
|
1283
|
+
out.some((edge) => edge.condition !== undefined || edge.name !== undefined);
|
|
903
1284
|
const targets = out.map((edge) => nodes.get(edge.to)?.element);
|
|
904
1285
|
const races = !decides &&
|
|
905
1286
|
targets.every((t) => t?.type === "intermediateCatchEvent" || t?.type === "receiveTask") &&
|
|
@@ -1153,6 +1534,19 @@ function assemble(reader, final) {
|
|
|
1153
1534
|
}
|
|
1154
1535
|
return flow;
|
|
1155
1536
|
});
|
|
1537
|
+
// A `with` line configures a node of the diagram; one whose node was left out, or
|
|
1538
|
+
// never written, has nothing to configure.
|
|
1539
|
+
const connectors = [];
|
|
1540
|
+
for (const ref of reader.connectors) {
|
|
1541
|
+
if (nodes.has(ref.elementId))
|
|
1542
|
+
connectors.push(ref);
|
|
1543
|
+
else if (final) {
|
|
1544
|
+
problems.push({
|
|
1545
|
+
line: ref.line,
|
|
1546
|
+
message: `"with ${ref.id}:" names no node of the diagram; ignored`,
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1156
1550
|
return {
|
|
1157
1551
|
diagram: {
|
|
1158
1552
|
id: "Definitions_1",
|
|
@@ -1168,6 +1562,7 @@ function assemble(reader, final) {
|
|
|
1168
1562
|
problems: problems.sort((a, b) => a.line - b.line),
|
|
1169
1563
|
fixes,
|
|
1170
1564
|
questions: asks.sort((a, b) => a.line - b.line).map(({ ask }) => ask()),
|
|
1565
|
+
connectors,
|
|
1171
1566
|
};
|
|
1172
1567
|
}
|
|
1173
1568
|
/**
|
|
@@ -37,6 +37,12 @@ export interface RestConnectorConfig {
|
|
|
37
37
|
/** Retry backoff duration (ISO 8601 duration, e.g. "PT0S"). */
|
|
38
38
|
retryBackoff?: string;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Version of the bundled `io.camunda.connectors.HttpJson.v2` template in
|
|
42
|
+
* `@bpmnkit/connectors`. An editor matches a stamped element to its template by
|
|
43
|
+
* id and version, so this must follow the bundled one; a test there checks it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const REST_CONNECTOR_TEMPLATE_VERSION = "18";
|
|
40
46
|
/** Convert a REST connector config into Zeebe IO mapping inputs. */
|
|
41
47
|
export declare function restConnectorToIoMappingInputs(config: RestConnectorConfig): ZeebeIoMappingEntry[];
|
|
42
48
|
/** Get the Zeebe task definition type for REST connectors. */
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
const REST_CONNECTOR_TYPE = "io.camunda:http-json:1";
|
|
2
|
+
/**
|
|
3
|
+
* Version of the bundled `io.camunda.connectors.HttpJson.v2` template in
|
|
4
|
+
* `@bpmnkit/connectors`. An editor matches a stamped element to its template by
|
|
5
|
+
* id and version, so this must follow the bundled one; a test there checks it.
|
|
6
|
+
*/
|
|
7
|
+
export const REST_CONNECTOR_TEMPLATE_VERSION = "18";
|
|
2
8
|
const DEFAULT_TIMEOUT = 20;
|
|
3
9
|
const DEFAULT_RETRIES = "3";
|
|
4
10
|
/** Convert a REST connector config into Zeebe IO mapping inputs. */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BpmnDefinitions } from "./bpmn-model.js";
|
|
2
|
+
/** A secret a diagram needs, and the elements that use it. */
|
|
3
|
+
export interface DiagramSecret {
|
|
4
|
+
/** The name to create in the cluster's secrets: `SLACK_TOKEN`. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Elements whose configuration reads it, in diagram order. */
|
|
7
|
+
elementIds: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The secrets a diagram's configuration reads — connector inputs, headers,
|
|
11
|
+
* properties and message subscriptions — so whoever deploys it knows what to
|
|
12
|
+
* create in the cluster first. Sorted by name.
|
|
13
|
+
*/
|
|
14
|
+
export declare function listSecrets(definitions: BpmnDefinitions): DiagramSecret[];
|
|
15
|
+
//# sourceMappingURL=secrets.d.ts.map
|