@bpmnkit/core 1.2.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 +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 +33 -5
- package/dist/bpmn/compact.js +138 -30
- package/dist/bpmn/connector-line.d.ts +46 -0
- package/dist/bpmn/connector-line.js +135 -0
- package/dist/bpmn/optimize/patterns.js +1 -3
- package/dist/bpmn/process-delta.d.ts +3 -0
- package/dist/bpmn/process-delta.js +23 -0
- package/dist/bpmn/process-text-writer.d.ts +12 -2
- package/dist/bpmn/process-text-writer.js +10 -1
- package/dist/bpmn/process-text.d.ts +26 -1
- package/dist/bpmn/process-text.js +329 -16
- 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,13 @@ 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)
|
|
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.
|
|
45
46
|
- Branches that meet again are joined automatically; join parallel branches with an and node.
|
|
47
|
+
- 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
48
|
|
|
47
49
|
Example:
|
|
48
50
|
# Expense approval
|
|
@@ -168,24 +170,66 @@ function nameFromId(id) {
|
|
|
168
170
|
export function tokenizePath(text) {
|
|
169
171
|
const refs = [];
|
|
170
172
|
const labels = [];
|
|
173
|
+
const joined = [];
|
|
174
|
+
const unclosed = [];
|
|
175
|
+
const bracketless = [];
|
|
171
176
|
let note;
|
|
172
177
|
let i = 0;
|
|
173
178
|
for (;;) {
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
let id = ID.exec(text.slice(i))?.[0];
|
|
180
|
+
// `1[service List runs] > 2[xor …]`: numbers for ids, which BPMN ids cannot start with
|
|
181
|
+
const number = id === undefined ? /^\d[\w-]*(?=\s*(?:\[|-{0,2}>))/.exec(text.slice(i))?.[0] : undefined;
|
|
182
|
+
if (number !== undefined) {
|
|
183
|
+
id = `n${number}`;
|
|
184
|
+
if (!joined.some((j) => j.id === id))
|
|
185
|
+
joined.push({ written: number, id });
|
|
186
|
+
i += number.length;
|
|
187
|
+
}
|
|
188
|
+
else if (id === undefined) {
|
|
176
189
|
return { error: `expected a node id at "${text.slice(i, i + 20)}"` };
|
|
177
|
-
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
i += id.length;
|
|
193
|
+
}
|
|
194
|
+
// `call back[service …]`: words before a bracket are one id
|
|
195
|
+
const words = /^((?: +[A-Za-z_][\w.-]*)+)(?= *\[)/.exec(text.slice(i))?.[1];
|
|
196
|
+
if (words !== undefined) {
|
|
197
|
+
const written = `${id}${words}`;
|
|
198
|
+
id = written.split(/ +/).join("_");
|
|
199
|
+
joined.push({ written, id });
|
|
200
|
+
i += words.length;
|
|
201
|
+
}
|
|
178
202
|
let spec;
|
|
203
|
+
// `… > xor Notify sales? >(Yes: …)`: a kind and a name without brackets, after an
|
|
204
|
+
// arrow. At the start of a line it is more likely prose ("end of the answer").
|
|
205
|
+
const bare = refs.length > 0 && KINDS[id] !== undefined
|
|
206
|
+
? /^ +([^[\]()>|]+?)(?=\s*(?:-{0,2}>|$))/.exec(text.slice(i))
|
|
207
|
+
: null;
|
|
208
|
+
if (bare?.[1]) {
|
|
209
|
+
spec = `${id} ${bare[1].trim()}`;
|
|
210
|
+
bracketless.push(id);
|
|
211
|
+
i += bare[0].length;
|
|
212
|
+
}
|
|
179
213
|
// `done-end [end Done]`: a space before the bracket still declares.
|
|
180
214
|
const gap = /^ +\[/.exec(text.slice(i));
|
|
181
215
|
if (gap)
|
|
182
216
|
i += gap[0].length - 1;
|
|
183
217
|
if (text[i] === "[") {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
218
|
+
let end = matching(text, i, "[", "]");
|
|
219
|
+
let after = end + 1;
|
|
220
|
+
if (end < 0) {
|
|
221
|
+
// `start[start HR) > …` or `end[Page created` at the end of the line: the
|
|
222
|
+
// bracket closes where its name plainly ends, before the next arrow
|
|
223
|
+
const open = /^[^[\]]*?(?:\)(?=\s*-{0,2}>)|(?=\s+-{0,2}>)|$)/.exec(text.slice(i + 1))?.[0];
|
|
224
|
+
if (open === undefined || open.trim() === "")
|
|
225
|
+
return { error: `"${id}[" is not closed` };
|
|
226
|
+
const closer = open.endsWith(")") ? 1 : 0;
|
|
227
|
+
end = i + 1 + open.length - closer;
|
|
228
|
+
after = i + 1 + open.length;
|
|
229
|
+
unclosed.push(id);
|
|
230
|
+
}
|
|
187
231
|
spec = text.slice(i + 1, end).trim();
|
|
188
|
-
i =
|
|
232
|
+
i = after;
|
|
189
233
|
}
|
|
190
234
|
refs.push({ id, spec });
|
|
191
235
|
while (text[i] === " ")
|
|
@@ -205,6 +249,10 @@ export function tokenizePath(text) {
|
|
|
205
249
|
return { error: `expected ">" at "${text.slice(i, i + 20)}"` };
|
|
206
250
|
i += arrow.length;
|
|
207
251
|
let label;
|
|
252
|
+
// `credit > (No: default) decision`: a space before the label
|
|
253
|
+
const spaced = /^ +\(/.exec(text.slice(i));
|
|
254
|
+
if (spaced)
|
|
255
|
+
i += spaced[0].length - 1;
|
|
208
256
|
if (text[i] === "(") {
|
|
209
257
|
const end = matching(text, i, "(", ")");
|
|
210
258
|
if (end < 0)
|
|
@@ -222,7 +270,16 @@ export function tokenizePath(text) {
|
|
|
222
270
|
i++;
|
|
223
271
|
}
|
|
224
272
|
}
|
|
225
|
-
|
|
273
|
+
const tokens = { refs, labels };
|
|
274
|
+
if (note !== undefined)
|
|
275
|
+
tokens.note = note;
|
|
276
|
+
if (joined.length > 0)
|
|
277
|
+
tokens.joined = joined;
|
|
278
|
+
if (unclosed.length > 0)
|
|
279
|
+
tokens.unclosed = unclosed;
|
|
280
|
+
if (bracketless.length > 0)
|
|
281
|
+
tokens.bracketless = bracketless;
|
|
282
|
+
return tokens;
|
|
226
283
|
}
|
|
227
284
|
/**
|
|
228
285
|
* Keeps a condition only if it is FEEL.
|
|
@@ -257,11 +314,17 @@ class Reader {
|
|
|
257
314
|
taken = new Set();
|
|
258
315
|
edges = [];
|
|
259
316
|
problems = [];
|
|
317
|
+
/** What reading a declaration repaired, listed with the parser's other fixes. */
|
|
318
|
+
fixes = [];
|
|
319
|
+
/** `with` lines, with the written id resolved to the node it meant when read. */
|
|
320
|
+
connectors = [];
|
|
260
321
|
/** Catch and boundary events written without a trigger, and made message events. */
|
|
261
322
|
guessedMessage = new Set();
|
|
262
323
|
title;
|
|
263
324
|
/** A line that ended in an arrow, waiting for the line that continues it. */
|
|
264
325
|
carry;
|
|
326
|
+
/** The last node of the last path read, which a line starting with an arrow continues. */
|
|
327
|
+
tail;
|
|
265
328
|
/** Reads one line. Returns whether it added anything. */
|
|
266
329
|
line(raw, n) {
|
|
267
330
|
let text = raw.trim();
|
|
@@ -278,6 +341,24 @@ class Reader {
|
|
|
278
341
|
this.title = text.replace(/^#+/, "").trim() || undefined;
|
|
279
342
|
return false;
|
|
280
343
|
}
|
|
344
|
+
if (CONNECTOR_LINE.test(text)) {
|
|
345
|
+
const connector = parseConnectorLine(text, n, this.problems);
|
|
346
|
+
if (connector) {
|
|
347
|
+
this.connectors.push({
|
|
348
|
+
...connector,
|
|
349
|
+
elementId: this.current.get(connector.id) ?? connector.id,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
// `> stop[end Done]`: the path above wrapped before its arrow
|
|
355
|
+
if (/^-{0,2}>/.test(text) && this.tail !== undefined) {
|
|
356
|
+
this.problems.push({
|
|
357
|
+
line: n,
|
|
358
|
+
message: `the line starts with ">"; read it as continuing "${this.tail}"`,
|
|
359
|
+
});
|
|
360
|
+
text = `${this.tail} ${text}`;
|
|
361
|
+
}
|
|
281
362
|
// `engineer[user Fix issue] >` then the next step on the next line: models
|
|
282
363
|
// wrap a long path. The line is read once it is complete.
|
|
283
364
|
if (DANGLING.test(text)) {
|
|
@@ -307,6 +388,21 @@ class Reader {
|
|
|
307
388
|
if (path.note !== undefined) {
|
|
308
389
|
this.problems.push({ line: n, message: `ignored the note "${path.note}"` });
|
|
309
390
|
}
|
|
391
|
+
for (const id of path.bracketless ?? []) {
|
|
392
|
+
this.problems.push({
|
|
393
|
+
line: n,
|
|
394
|
+
message: `"${id} …" has no brackets; read it as declaring "${id}"`,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
for (const id of path.unclosed ?? []) {
|
|
398
|
+
this.problems.push({
|
|
399
|
+
line: n,
|
|
400
|
+
message: `"${id}[" is not closed; closed it where its name ends`,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
for (const { written, id } of path.joined ?? []) {
|
|
404
|
+
this.problems.push({ line: n, message: `"${written}" is not an id; read as "${id}"` });
|
|
405
|
+
}
|
|
310
406
|
const { refs, labels } = path;
|
|
311
407
|
// Declarations and references resolve left to right, so a chain that
|
|
312
408
|
// reuses an id (`task[A] > task[B]`) links the nodes in the order written.
|
|
@@ -320,6 +416,7 @@ class Reader {
|
|
|
320
416
|
this.edges.push({ from, to, line: n, ...this.feelOrLabel(edgeLabel(labels[k]), n) });
|
|
321
417
|
}
|
|
322
418
|
}
|
|
419
|
+
this.tail = ids.at(-1);
|
|
323
420
|
return true;
|
|
324
421
|
}
|
|
325
422
|
/** {@link conditionOrLabel}, with its problem recorded against line `n`. */
|
|
@@ -357,7 +454,10 @@ class Reader {
|
|
|
357
454
|
const word = spec.split(/[\s|]/, 1)[0]?.toLowerCase().split(":")[0] ?? "";
|
|
358
455
|
const kind = KINDS[word] ?? ALIASES[word];
|
|
359
456
|
// A boundary is always new: it cannot be a revision of the task it sits on.
|
|
360
|
-
|
|
457
|
+
// `send[…] > send[post Slack message to #support]`: a name of several words
|
|
458
|
+
// after an arrow is a second node, whatever its kind word
|
|
459
|
+
const named = afterArrow && !spec.includes("=") && spec.trim().split(/\s+/).length >= 3;
|
|
460
|
+
if ((kind === undefined && !named) || (!afterArrow && kind !== "boundaryEvent")) {
|
|
361
461
|
this.problems.push({
|
|
362
462
|
line: n,
|
|
363
463
|
message: `"${written}" is already declared on line ${earlier.line}; ignored "${spec}"`,
|
|
@@ -383,8 +483,12 @@ class Reader {
|
|
|
383
483
|
});
|
|
384
484
|
}
|
|
385
485
|
const bar = spec.indexOf("|");
|
|
386
|
-
|
|
387
|
-
const
|
|
486
|
+
// `boundary:timer on=poll`: an attribute written before the bar is one still
|
|
487
|
+
const loose = /\s+((?:on|job|each|after)=\S+|nonint)(?=\s|$)/g;
|
|
488
|
+
const beforeBar = bar < 0 ? spec : spec.slice(0, bar);
|
|
489
|
+
const head = beforeBar.replace(loose, "").trim();
|
|
490
|
+
const attrs = [...beforeBar.matchAll(loose)].map((m) => m[1]).join(" ") +
|
|
491
|
+
(bar < 0 ? "" : ` ${spec.slice(bar + 1)}`);
|
|
388
492
|
const space = head.search(/\s/);
|
|
389
493
|
const kindWord = space < 0 ? head : head.slice(0, space);
|
|
390
494
|
const name = space < 0 ? undefined : head.slice(space + 1).trim() || undefined;
|
|
@@ -436,7 +540,20 @@ class Reader {
|
|
|
436
540
|
element.name = label;
|
|
437
541
|
// A catch or boundary event waits for something, and cannot deploy without
|
|
438
542
|
// saying what. Unnamed, it is most often a message: "Payment confirmed".
|
|
439
|
-
|
|
543
|
+
// `queue[event catch Send to SQS]` is named for a call it makes, not for what it waits
|
|
544
|
+
// for: it is a service task, as every call to an outside system is
|
|
545
|
+
const call = element.type === "intermediateCatchEvent" && element.eventType === undefined
|
|
546
|
+
? /^(?:(?:catch|throw|event)\s+)?((?:send|post|publish|call|notify|invoke|push|upload|create|update|delete|run|trigger)\b.*)$/i.exec(label ?? "")?.[1]
|
|
547
|
+
: undefined;
|
|
548
|
+
if (call !== undefined) {
|
|
549
|
+
element.type = "serviceTask";
|
|
550
|
+
element.name = call;
|
|
551
|
+
this.problems.push({
|
|
552
|
+
line: n,
|
|
553
|
+
message: `"${id}" is named for a call it makes, "${call}"; made it a service task`,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
else if ((element.type === "intermediateCatchEvent" || element.type === "boundaryEvent") &&
|
|
440
557
|
element.eventType === undefined) {
|
|
441
558
|
element.eventType = "message";
|
|
442
559
|
this.guessedMessage.add(id);
|
|
@@ -455,13 +572,125 @@ class Reader {
|
|
|
455
572
|
element.jobType = value;
|
|
456
573
|
else if (key === "nonint" && value === undefined)
|
|
457
574
|
element.interrupting = false;
|
|
575
|
+
else if (key === "each" && value && GATEWAYS.has(element.type) && element.name) {
|
|
576
|
+
// `and[and Process every recipient | each=recipients]`: a step, run per item
|
|
577
|
+
this.problems.push({
|
|
578
|
+
line: n,
|
|
579
|
+
message: `"${id}" is a gateway with each=, named like a step; made it a task run per item`,
|
|
580
|
+
});
|
|
581
|
+
element.type = "task";
|
|
582
|
+
element.multiInstance = {
|
|
583
|
+
collection: value.startsWith("=") ? value : `=${value}`,
|
|
584
|
+
element: itemOf(value.replace(/^=/, "")),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
else if (key === "each" && value && ACTIVITIES.has(element.type)) {
|
|
588
|
+
element.multiInstance = {
|
|
589
|
+
collection: value.startsWith("=") ? value : `=${value}`,
|
|
590
|
+
element: itemOf(value.replace(/^=/, "")),
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
else if (key === "after" && value && EVENTS.has(element.type) && duration(value)) {
|
|
594
|
+
// `delay[boundary:error Timeout | after=P1D]`: only a timer waits for a time
|
|
595
|
+
if (element.eventType !== "timer" && element.type !== "endEvent") {
|
|
596
|
+
this.problems.push({
|
|
597
|
+
line: n,
|
|
598
|
+
message: `"${id}" waits ${value}, which only a timer does; made it a timer event`,
|
|
599
|
+
});
|
|
600
|
+
element.eventType = "timer";
|
|
601
|
+
}
|
|
602
|
+
element.timerDuration = duration(value);
|
|
603
|
+
}
|
|
458
604
|
else
|
|
459
605
|
this.problems.push({ line: n, message: `unknown attribute "${attr}" on "${id}"; ignored` });
|
|
460
606
|
}
|
|
607
|
+
// `late[catch:timer | on=poll after=PT5M]`: an event on a task is a boundary event
|
|
608
|
+
const host = node.on === undefined ? undefined : this.nodes.get(node.on)?.element;
|
|
609
|
+
if (element.type === "intermediateCatchEvent" && host && ACTIVITIES.has(host.type)) {
|
|
610
|
+
element.type = "boundaryEvent";
|
|
611
|
+
this.problems.push({
|
|
612
|
+
line: n,
|
|
613
|
+
message: `"${id}" is a catch event on "${node.on}"; made it a boundary event`,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
// "Send email to each stakeholder": a step its name says is done per item runs once
|
|
617
|
+
// per item of the list of them, whose variable only the reader can name for sure
|
|
618
|
+
const per = /\b(?:each|every)\s+([a-z]{3,})\b/i.exec(label ?? "")?.[1]?.toLowerCase();
|
|
619
|
+
if (per &&
|
|
620
|
+
!TIME_WORDS.has(per) &&
|
|
621
|
+
ACTIVITIES.has(element.type) &&
|
|
622
|
+
element.multiInstance === undefined) {
|
|
623
|
+
const list = per.endsWith("y") && !/[aeiou]y$/.test(per) ? `${per.slice(0, -1)}ies` : `${per}s`;
|
|
624
|
+
element.multiInstance = { collection: `=${list}`, element: per };
|
|
625
|
+
this.fixes.push(`"${id}" runs once per ${per}, over the list "${list}"`);
|
|
626
|
+
}
|
|
627
|
+
// `late[boundary:timer 5 minutes | on=poll]`: a timer's name says how long it waits
|
|
628
|
+
if (element.eventType === "timer" && element.timerDuration === undefined && label) {
|
|
629
|
+
const said = duration(label);
|
|
630
|
+
if (said)
|
|
631
|
+
element.timerDuration = said;
|
|
632
|
+
}
|
|
461
633
|
this.nodes.set(id, node);
|
|
462
634
|
return id;
|
|
463
635
|
}
|
|
464
636
|
}
|
|
637
|
+
/** "Every day" is a schedule, not a list. */
|
|
638
|
+
const TIME_WORDS = new Set([
|
|
639
|
+
"second",
|
|
640
|
+
"minute",
|
|
641
|
+
"hour",
|
|
642
|
+
"day",
|
|
643
|
+
"week",
|
|
644
|
+
"month",
|
|
645
|
+
"quarter",
|
|
646
|
+
"year",
|
|
647
|
+
"morning",
|
|
648
|
+
"evening",
|
|
649
|
+
"night",
|
|
650
|
+
"time",
|
|
651
|
+
"other",
|
|
652
|
+
]);
|
|
653
|
+
/** Element types `each=` makes multi-instance. */
|
|
654
|
+
const ACTIVITIES = new Set([
|
|
655
|
+
"task",
|
|
656
|
+
"serviceTask",
|
|
657
|
+
"sendTask",
|
|
658
|
+
"receiveTask",
|
|
659
|
+
"userTask",
|
|
660
|
+
"manualTask",
|
|
661
|
+
"scriptTask",
|
|
662
|
+
"businessRuleTask",
|
|
663
|
+
"callActivity",
|
|
664
|
+
"subProcess",
|
|
665
|
+
]);
|
|
666
|
+
/** The variable one item of a list is in: `recipients` → `recipient`, else `item`. */
|
|
667
|
+
function itemOf(collection) {
|
|
668
|
+
if (!/^[A-Za-z_]\w*$/.test(collection))
|
|
669
|
+
return "item";
|
|
670
|
+
if (collection.endsWith("ies") && collection.length > 4)
|
|
671
|
+
return `${collection.slice(0, -3)}y`;
|
|
672
|
+
if (collection.endsWith("s") && !collection.endsWith("ss") && collection.length > 3)
|
|
673
|
+
return collection.slice(0, -1);
|
|
674
|
+
return "item";
|
|
675
|
+
}
|
|
676
|
+
const UNITS = { s: "S", m: "M", h: "H", d: "D", w: "W" };
|
|
677
|
+
/**
|
|
678
|
+
* An ISO 8601 duration from what models write: `PT5M` as it is, `5m`, `5 min`,
|
|
679
|
+
* `5 minutes`, `2 hours` or `1 day`, also inside a name ("Wait 5 minutes").
|
|
680
|
+
*/
|
|
681
|
+
export function duration(text) {
|
|
682
|
+
// `p1d` is P1D: models write ISO durations in lower case too
|
|
683
|
+
const iso = /\bP(?:\d+[YMWD])*(?:T(?:\d+[HMS])+)?\b/i.exec(text)?.[0]?.toUpperCase();
|
|
684
|
+
if (iso && iso !== "P" && iso !== "PT")
|
|
685
|
+
return iso;
|
|
686
|
+
const m = /(\d+)\s*(s|sec|secs|seconds?|m|min|mins|minutes?|h|hrs?|hours?|d|days?|w|weeks?)\b/i.exec(text);
|
|
687
|
+
if (!m?.[1] || !m[2])
|
|
688
|
+
return undefined;
|
|
689
|
+
const unit = UNITS[m[2][0]?.toLowerCase() ?? ""];
|
|
690
|
+
if (unit === undefined)
|
|
691
|
+
return undefined;
|
|
692
|
+
return unit === "D" || unit === "W" ? `P${m[1]}${unit}` : `PT${m[1]}${unit}`;
|
|
693
|
+
}
|
|
465
694
|
export function edgeLabel(label) {
|
|
466
695
|
if (label === undefined)
|
|
467
696
|
return {};
|
|
@@ -511,7 +740,7 @@ function variableFrom(text) {
|
|
|
511
740
|
*/
|
|
512
741
|
function assemble(reader, final) {
|
|
513
742
|
const problems = [...reader.problems];
|
|
514
|
-
const fixes = [];
|
|
743
|
+
const fixes = [...reader.fixes];
|
|
515
744
|
// Asked once the names are final, so a question uses the names the diagram shows.
|
|
516
745
|
const asks = [];
|
|
517
746
|
const nodes = new Map();
|
|
@@ -545,6 +774,14 @@ function assemble(reader, final) {
|
|
|
545
774
|
for (const [id, node] of nodes) {
|
|
546
775
|
if (node.element.type !== "boundaryEvent")
|
|
547
776
|
continue;
|
|
777
|
+
// `send > wait[boundary:timer …]` without on=: the one task drawn into it is its host
|
|
778
|
+
const drawn = node.on === undefined ? reader.edges.filter((edge) => edge.to === id) : [];
|
|
779
|
+
const from = drawn.length === 1 ? nodes.get(drawn[0]?.from ?? "") : undefined;
|
|
780
|
+
if (from && drawn[0] && !EVENTS.has(from.element.type) && !GATEWAYS.has(from.element.type)) {
|
|
781
|
+
node.on = from.element.id;
|
|
782
|
+
reader.edges.splice(reader.edges.indexOf(drawn[0]), 1);
|
|
783
|
+
fixes.push(`put boundary "${id}" on "${from.element.id}", the task drawn into it`);
|
|
784
|
+
}
|
|
548
785
|
const host = node.on === undefined ? undefined : nodes.get(node.on);
|
|
549
786
|
const hostType = host?.element.type;
|
|
550
787
|
if (hostType !== undefined && !EVENTS.has(hostType) && !GATEWAYS.has(hostType)) {
|
|
@@ -569,8 +806,12 @@ function assemble(reader, final) {
|
|
|
569
806
|
// on=pay] > notify`) means the path that boundary leads to. Nothing can flow
|
|
570
807
|
// into a boundary, so the branch goes to its handler instead of being lost.
|
|
571
808
|
const written = reader.edges.flatMap((edge) => {
|
|
572
|
-
|
|
809
|
+
const target = reader.nodes.get(edge.to);
|
|
810
|
+
if (target?.element.type !== "boundaryEvent")
|
|
573
811
|
return [edge];
|
|
812
|
+
// `poll > late[… | on=poll]`: the arrow from its own task only says where it sits
|
|
813
|
+
if (target.on === edge.from)
|
|
814
|
+
return [];
|
|
574
815
|
const next = reader.edges.filter((out) => out.from === edge.to);
|
|
575
816
|
if (next.length === 0)
|
|
576
817
|
return [edge];
|
|
@@ -835,10 +1076,56 @@ function assemble(reader, final) {
|
|
|
835
1076
|
},
|
|
836
1077
|
});
|
|
837
1078
|
}
|
|
1079
|
+
// `fork[and] > pick > pack > label > joined[and]`: steps between an and split and an
|
|
1080
|
+
// and join with nothing beside them are the parallel branches, drawn in a row
|
|
1081
|
+
for (const [id, node] of nodes) {
|
|
1082
|
+
if (node.element.type !== "parallelGateway")
|
|
1083
|
+
continue;
|
|
1084
|
+
if (into(id).length !== 1 || outOf(id).length !== 1)
|
|
1085
|
+
continue;
|
|
1086
|
+
const chain = [];
|
|
1087
|
+
let at = outOf(id)[0]?.to;
|
|
1088
|
+
while (at !== undefined) {
|
|
1089
|
+
const next = nodes.get(at)?.element;
|
|
1090
|
+
if (!next || GATEWAYS.has(next.type) || EVENTS.has(next.type))
|
|
1091
|
+
break;
|
|
1092
|
+
if (into(at).length !== 1 || outOf(at).length !== 1)
|
|
1093
|
+
break;
|
|
1094
|
+
chain.push(at);
|
|
1095
|
+
at = outOf(at)[0]?.to;
|
|
1096
|
+
}
|
|
1097
|
+
const join = at === undefined ? undefined : nodes.get(at);
|
|
1098
|
+
if (chain.length < 2 ||
|
|
1099
|
+
!join ||
|
|
1100
|
+
at === undefined ||
|
|
1101
|
+
join.element.type !== "parallelGateway" ||
|
|
1102
|
+
into(at).length !== 1) {
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
const end = at;
|
|
1106
|
+
edges = edges.filter((edge) => edge.from !== id && !chain.includes(edge.from));
|
|
1107
|
+
for (const step of chain) {
|
|
1108
|
+
edges.push({ from: id, to: step, line: node.line });
|
|
1109
|
+
edges.push({ from: step, to: end, line: node.line });
|
|
1110
|
+
}
|
|
1111
|
+
fixes.push(`ran ${chain.map((c) => `"${c}"`).join(", ")} in parallel between "${id}" and "${end}", as their and nodes say`);
|
|
1112
|
+
}
|
|
838
1113
|
// Pass-through gateways: one way in and one way out decides nothing. Most
|
|
839
1114
|
// often a question the model asked and then answered only one way.
|
|
1115
|
+
const dedupe = () => {
|
|
1116
|
+
const once = new Set();
|
|
1117
|
+
edges = edges.filter((edge) => {
|
|
1118
|
+
const key = `${edge.from}>${edge.to}`;
|
|
1119
|
+
if (once.has(key))
|
|
1120
|
+
return false;
|
|
1121
|
+
once.add(key);
|
|
1122
|
+
return true;
|
|
1123
|
+
});
|
|
1124
|
+
};
|
|
840
1125
|
for (let removed = true; removed;) {
|
|
841
1126
|
removed = false;
|
|
1127
|
+
// Removing one gateway can leave two flows between the same nodes: one is enough
|
|
1128
|
+
dedupe();
|
|
842
1129
|
for (const [id, node] of nodes) {
|
|
843
1130
|
if (!GATEWAYS.has(node.element.type))
|
|
844
1131
|
continue;
|
|
@@ -848,6 +1135,16 @@ function assemble(reader, final) {
|
|
|
848
1135
|
continue;
|
|
849
1136
|
if (inEdge.from === outEdge.to)
|
|
850
1137
|
continue;
|
|
1138
|
+
// `pack[and Pack into box]`: a step written with a gateway's kind is that step
|
|
1139
|
+
if (node.element.name &&
|
|
1140
|
+
(node.element.type === "parallelGateway" || node.element.type === "inclusiveGateway")) {
|
|
1141
|
+
node.element.type = "task";
|
|
1142
|
+
problems.push({
|
|
1143
|
+
line: node.line,
|
|
1144
|
+
message: `"${id}" is a gateway with one way in and out, named like a step; made it a task`,
|
|
1145
|
+
});
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
851
1148
|
const target = typeOf(outEdge.to);
|
|
852
1149
|
if (node.element.type === "eventBasedGateway" &&
|
|
853
1150
|
target !== "intermediateCatchEvent" &&
|
|
@@ -899,7 +1196,9 @@ function assemble(reader, final) {
|
|
|
899
1196
|
const out = outOf(id);
|
|
900
1197
|
if (GATEWAYS.has(type) || out.length < 2)
|
|
901
1198
|
continue;
|
|
902
|
-
|
|
1199
|
+
// A DMN decision's outcomes are alternatives, labelled or not
|
|
1200
|
+
const decides = type === "businessRuleTask" ||
|
|
1201
|
+
out.some((edge) => edge.condition !== undefined || edge.name !== undefined);
|
|
903
1202
|
const targets = out.map((edge) => nodes.get(edge.to)?.element);
|
|
904
1203
|
const races = !decides &&
|
|
905
1204
|
targets.every((t) => t?.type === "intermediateCatchEvent" || t?.type === "receiveTask") &&
|
|
@@ -1153,6 +1452,19 @@ function assemble(reader, final) {
|
|
|
1153
1452
|
}
|
|
1154
1453
|
return flow;
|
|
1155
1454
|
});
|
|
1455
|
+
// A `with` line configures a node of the diagram; one whose node was left out, or
|
|
1456
|
+
// never written, has nothing to configure.
|
|
1457
|
+
const connectors = [];
|
|
1458
|
+
for (const ref of reader.connectors) {
|
|
1459
|
+
if (nodes.has(ref.elementId))
|
|
1460
|
+
connectors.push(ref);
|
|
1461
|
+
else if (final) {
|
|
1462
|
+
problems.push({
|
|
1463
|
+
line: ref.line,
|
|
1464
|
+
message: `"with ${ref.id}:" names no node of the diagram; ignored`,
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1156
1468
|
return {
|
|
1157
1469
|
diagram: {
|
|
1158
1470
|
id: "Definitions_1",
|
|
@@ -1168,6 +1480,7 @@ function assemble(reader, final) {
|
|
|
1168
1480
|
problems: problems.sort((a, b) => a.line - b.line),
|
|
1169
1481
|
fixes,
|
|
1170
1482
|
questions: asks.sort((a, b) => a.line - b.line).map(({ ask }) => ask()),
|
|
1483
|
+
connectors,
|
|
1171
1484
|
};
|
|
1172
1485
|
}
|
|
1173
1486
|
/**
|
|
@@ -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
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** `{{secrets.NAME}}`, `camunda.secrets.NAME` and `` camunda.secrets.`NAME` ``. */
|
|
2
|
+
const SECRET = /\{\{\s*secrets\.([\w-]+)\s*\}\}|camunda\.secrets\.(?:([\w-]+)|`([^`]+)`)/g;
|
|
3
|
+
function scan(text, found) {
|
|
4
|
+
if (text === undefined || !text.includes("secrets."))
|
|
5
|
+
return;
|
|
6
|
+
for (const m of text.matchAll(SECRET)) {
|
|
7
|
+
const name = m[1] ?? m[2] ?? m[3];
|
|
8
|
+
if (name)
|
|
9
|
+
found(name);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function scanXml(elements, found) {
|
|
13
|
+
for (const x of elements) {
|
|
14
|
+
for (const value of Object.values(x.attributes))
|
|
15
|
+
scan(value, found);
|
|
16
|
+
scan(x.text, found);
|
|
17
|
+
scanXml(x.children, found);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The secrets a diagram's configuration reads — connector inputs, headers,
|
|
22
|
+
* properties and message subscriptions — so whoever deploys it knows what to
|
|
23
|
+
* create in the cluster first. Sorted by name.
|
|
24
|
+
*/
|
|
25
|
+
export function listSecrets(definitions) {
|
|
26
|
+
const byName = new Map();
|
|
27
|
+
const add = (elementId) => (name) => {
|
|
28
|
+
const ids = byName.get(name) ?? new Set();
|
|
29
|
+
ids.add(elementId);
|
|
30
|
+
byName.set(name, ids);
|
|
31
|
+
};
|
|
32
|
+
const messageUsers = new Map();
|
|
33
|
+
const walk = (elements) => {
|
|
34
|
+
for (const el of elements) {
|
|
35
|
+
scanXml(el.extensionElements, add(el.id));
|
|
36
|
+
const ref = "messageRef" in el && typeof el.messageRef === "string"
|
|
37
|
+
? el.messageRef
|
|
38
|
+
: "eventDefinitions" in el
|
|
39
|
+
? el.eventDefinitions.find((d) => d.type === "message")?.messageRef
|
|
40
|
+
: undefined;
|
|
41
|
+
if (ref !== undefined)
|
|
42
|
+
messageUsers.set(ref, [...(messageUsers.get(ref) ?? []), el.id]);
|
|
43
|
+
if ("flowElements" in el && Array.isArray(el.flowElements))
|
|
44
|
+
walk(el.flowElements);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
for (const process of definitions.processes)
|
|
48
|
+
walk(process.flowElements);
|
|
49
|
+
// A message's correlation key is configured on the message, used by the events that wait for it
|
|
50
|
+
for (const message of definitions.messages) {
|
|
51
|
+
for (const id of messageUsers.get(message.id) ?? [message.id]) {
|
|
52
|
+
scanXml(message.extensionElements ?? [], add(id));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [...byName.entries()]
|
|
56
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
57
|
+
.map(([name, ids]) => ({ name, elementIds: [...ids] }));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=secrets.js.map
|
package/dist/bpmn/utils.js
CHANGED
|
@@ -194,6 +194,10 @@ export function getZeebeExtensions(extensionElements) {
|
|
|
194
194
|
const formDefinition = { formId: formDefEl.attributes.formId ?? "" };
|
|
195
195
|
ext.formDefinition = formDefinition;
|
|
196
196
|
}
|
|
197
|
+
const agentDefEl = findChild(extensionElements, "agentDefinition");
|
|
198
|
+
if (agentDefEl) {
|
|
199
|
+
ext.agentDefinition = { agentType: agentDefEl.attributes.agentType ?? "" };
|
|
200
|
+
}
|
|
197
201
|
const calledDecEl = findChild(extensionElements, "calledDecision");
|
|
198
202
|
if (calledDecEl) {
|
|
199
203
|
const calledDecision = {
|
|
@@ -41,6 +41,14 @@ export interface ZeebeAdHoc {
|
|
|
41
41
|
/** FEEL expression selecting which child element IDs to activate (BPMN-native mode). */
|
|
42
42
|
activeElementsCollection?: string;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Zeebe agent definition (`zeebe:agentDefinition`, Camunda 8.10+): marks a
|
|
46
|
+
* service task or ad-hoc sub-process as an AI agent the engine runs, e.g.
|
|
47
|
+
* `aiAgentTask` or `aiAgentSubProcess`.
|
|
48
|
+
*/
|
|
49
|
+
export interface ZeebeAgentDefinition {
|
|
50
|
+
agentType: string;
|
|
51
|
+
}
|
|
44
52
|
/** Zeebe form definition extension for user tasks. */
|
|
45
53
|
export interface ZeebeFormDefinition {
|
|
46
54
|
/** ID of the Camunda Form linked to this user task. */
|
|
@@ -79,6 +87,8 @@ export interface ZeebeExtensions {
|
|
|
79
87
|
taskHeaders?: ZeebeTaskHeaders;
|
|
80
88
|
properties?: ZeebeProperties;
|
|
81
89
|
adHoc?: ZeebeAdHoc;
|
|
90
|
+
/** AI agent marker (zeebe:agentDefinition). */
|
|
91
|
+
agentDefinition?: ZeebeAgentDefinition;
|
|
82
92
|
/** Camunda Form linked to a user task (zeebe:formDefinition). */
|
|
83
93
|
formDefinition?: ZeebeFormDefinition;
|
|
84
94
|
/** DMN decision invoked by a business rule task (zeebe:calledDecision). */
|
|
@@ -72,6 +72,13 @@ export function zeebeExtensionsToXmlElements(extensions) {
|
|
|
72
72
|
attrs.activeElementsCollection = activeElementsCollection;
|
|
73
73
|
elements.push({ name: "zeebe:adHoc", attributes: attrs, children: [] });
|
|
74
74
|
}
|
|
75
|
+
if (extensions.agentDefinition) {
|
|
76
|
+
elements.push({
|
|
77
|
+
name: "zeebe:agentDefinition",
|
|
78
|
+
attributes: { agentType: extensions.agentDefinition.agentType },
|
|
79
|
+
children: [],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
75
82
|
if (extensions.userTask) {
|
|
76
83
|
elements.push({ name: "zeebe:userTask", attributes: {}, children: [] });
|
|
77
84
|
}
|