@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
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ Parse → Modify → Validate → Export
|
|
|
33
33
|
- **Camunda Form Definitions** — type-safe form schema builder
|
|
34
34
|
- **Optimizer** — built-in rule engine to detect and auto-fix anti-patterns
|
|
35
35
|
- **Compact Format** — 70% smaller token-efficient JSON representation for AI/LLM workflows
|
|
36
|
+
- **Connector catalog** — all Camunda 8 out-of-the-box connector templates, applied deterministically (`@bpmnkit/core/connectors`)
|
|
36
37
|
- **Zero Dependencies** — runs in browsers, Node.js, Deno, Bun, and edge runtimes
|
|
37
38
|
|
|
38
39
|
## Installation
|
|
@@ -308,6 +309,31 @@ import { writeBpmn } from "@bpmnkit/core/node"
|
|
|
308
309
|
const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
|
|
309
310
|
```
|
|
310
311
|
|
|
312
|
+
### Connectors (`@bpmnkit/core/connectors`)
|
|
313
|
+
|
|
314
|
+
The Camunda 8 out-of-the-box connector catalog, behind its own subpath so its data is only
|
|
315
|
+
bundled by code that imports it. The templates leave out icons, groups, tooltips and
|
|
316
|
+
placeholders; [`@bpmnkit/connectors`](https://www.npmjs.com/package/@bpmnkit/connectors)
|
|
317
|
+
adds those back for a property panel.
|
|
318
|
+
|
|
319
|
+
| Export | Description |
|
|
320
|
+
|--------|-------------|
|
|
321
|
+
| `listConnectors()` / `searchConnectors(query)` | Summaries: task type, direction, required and optional inputs |
|
|
322
|
+
| `applyConnectorTemplate(id, values)` | Builder options for a bundled template, plus problems |
|
|
323
|
+
| `applyTemplateToElement(defs, id, template, values)` | Apply a template to an existing element |
|
|
324
|
+
| `validateElementTemplate(value)` | Structural check of an element template |
|
|
325
|
+
| `findConnectorCards(query)` / `formatConnectorCard(card)` | One card per operation, with only its inputs — for a model's prompt |
|
|
326
|
+
| `applyConnectorLines(defs, lines)` | Apply the `with` lines a model wrote in the line format |
|
|
327
|
+
| `selectConnectors({ text, tasks })` | Pick the cards a model sees for each task of a diagram |
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { applyConnectorTemplate } from "@bpmnkit/core/connectors"
|
|
331
|
+
|
|
332
|
+
const { serviceTask, problems } = applyConnectorTemplate("io.camunda.connectors.HttpJson.v2", {
|
|
333
|
+
url: "https://api.example.com/orders",
|
|
334
|
+
})
|
|
335
|
+
```
|
|
336
|
+
|
|
311
337
|
### DMN
|
|
312
338
|
|
|
313
339
|
| Export | Description |
|
|
@@ -67,6 +67,10 @@ export interface ServiceTaskOptions {
|
|
|
67
67
|
name: string;
|
|
68
68
|
value: string;
|
|
69
69
|
}>;
|
|
70
|
+
/** Marks the task as an AI agent the engine runs (`zeebe:agentDefinition`, Camunda 8.10+). */
|
|
71
|
+
agentDefinition?: {
|
|
72
|
+
agentType: string;
|
|
73
|
+
};
|
|
70
74
|
/** Zeebe modeler template ID. */
|
|
71
75
|
modelerTemplate?: string;
|
|
72
76
|
/** Zeebe modeler template version. */
|
|
@@ -293,6 +297,10 @@ export interface AdHocSubProcessOptions extends ElementOptions {
|
|
|
293
297
|
name: string;
|
|
294
298
|
value: string;
|
|
295
299
|
}>;
|
|
300
|
+
/** Marks the sub-process as an AI agent the engine runs (`zeebe:agentDefinition`, Camunda 8.10+). */
|
|
301
|
+
agentDefinition?: {
|
|
302
|
+
agentType: string;
|
|
303
|
+
};
|
|
296
304
|
/** Multi-instance loop configuration. */
|
|
297
305
|
loopCharacteristics?: {
|
|
298
306
|
inputCollection: string;
|
|
@@ -2,7 +2,7 @@ import { ValidationError } from "../errors.js";
|
|
|
2
2
|
import { generateId } from "../types/id-generator.js";
|
|
3
3
|
import { applyAutoLayout } from "./auto-layout.js";
|
|
4
4
|
import { createFlowElement } from "./element-shape.js";
|
|
5
|
-
import { restConnectorRetries, restConnectorTaskType, restConnectorToIoMappingInputs, restConnectorToTaskHeaders, } from "./rest-connector.js";
|
|
5
|
+
import { REST_CONNECTOR_TEMPLATE_VERSION, restConnectorRetries, restConnectorTaskType, restConnectorToIoMappingInputs, restConnectorToTaskHeaders, } from "./rest-connector.js";
|
|
6
6
|
import { assignStableFlowIds, rootDefinitionId } from "./stable-ids.js";
|
|
7
7
|
import { ensureZeebeExtension, zeebeExtensionsToXmlElements, } from "./zeebe-extensions.js";
|
|
8
8
|
// Keep in sync with packages/core/package.json version
|
|
@@ -266,6 +266,8 @@ function buildServiceTaskExtensions(options) {
|
|
|
266
266
|
if (options.zeebeProperties) {
|
|
267
267
|
extensions.properties = { properties: options.zeebeProperties };
|
|
268
268
|
}
|
|
269
|
+
if (options.agentDefinition)
|
|
270
|
+
extensions.agentDefinition = options.agentDefinition;
|
|
269
271
|
return zeebeExtensionsToXmlElements(extensions);
|
|
270
272
|
}
|
|
271
273
|
function makeConditionExpression(expression) {
|
|
@@ -294,6 +296,8 @@ function buildAdHocSubProcessExtensions(options) {
|
|
|
294
296
|
if (options?.zeebeProperties) {
|
|
295
297
|
zeebeExt.properties = { properties: options.zeebeProperties };
|
|
296
298
|
}
|
|
299
|
+
if (options?.agentDefinition)
|
|
300
|
+
zeebeExt.agentDefinition = options.agentDefinition;
|
|
297
301
|
const extensionElements = zeebeExtensionsToXmlElements(zeebeExt);
|
|
298
302
|
const adHocAttrs = {};
|
|
299
303
|
if (options?.activeElementsCollection) {
|
|
@@ -1914,7 +1918,7 @@ export class ProcessBuilder {
|
|
|
1914
1918
|
// Stamp the template identifier so editors recognise this as a REST connector
|
|
1915
1919
|
el.unknownAttributes = {
|
|
1916
1920
|
"zeebe:modelerTemplate": "io.camunda.connectors.HttpJson.v2",
|
|
1917
|
-
"zeebe:modelerTemplateVersion":
|
|
1921
|
+
"zeebe:modelerTemplateVersion": REST_CONNECTOR_TEMPLATE_VERSION,
|
|
1918
1922
|
};
|
|
1919
1923
|
this.addFlowElement(el);
|
|
1920
1924
|
return this;
|
package/dist/bpmn/compact.d.ts
CHANGED
|
@@ -19,22 +19,38 @@ export interface CompactElement {
|
|
|
19
19
|
dataStoreRef?: string;
|
|
20
20
|
/** dataObject / dataObjectReference: marks a collection. */
|
|
21
21
|
isCollection?: boolean;
|
|
22
|
+
/** Zeebe task headers (key→value). */
|
|
23
|
+
taskHeaders?: Record<string, string>;
|
|
22
24
|
/**
|
|
23
|
-
* Zeebe
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* Zeebe input mappings (target→source); a source starting with `=` is FEEL.
|
|
26
|
+
* A connector reads its configuration from these: for the Camunda HTTP
|
|
27
|
+
* connector (jobType "io.camunda:http-json:1") set `url`, `method`, and
|
|
28
|
+
* optionally `headers`, `queryParameters`, `body`, `authentication.type`.
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
inputs?: Record<string, string>;
|
|
31
|
+
/** The element template applied to this element (`zeebe:modelerTemplate`). */
|
|
32
|
+
modelerTemplate?: {
|
|
33
|
+
id: string;
|
|
34
|
+
version?: number;
|
|
35
|
+
};
|
|
28
36
|
/** Called process ID (callActivity: zeebe:calledElement.processId) */
|
|
29
37
|
calledProcess?: string;
|
|
30
38
|
/** Linked form ID (userTask: zeebe:formDefinition.formId) */
|
|
31
39
|
formId?: string;
|
|
32
40
|
/** Linked decision ID (businessRuleTask: zeebe:calledDecision.decisionId) */
|
|
33
41
|
decisionId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The FEEL expression a script task evaluates (`zeebe:script`), with its leading
|
|
44
|
+
* `=`. Its value goes to {@link resultVariable}.
|
|
45
|
+
*/
|
|
46
|
+
script?: string;
|
|
34
47
|
/**
|
|
35
48
|
* Primary output variable.
|
|
36
49
|
* - For businessRuleTask: stored in zeebe:calledDecision.resultVariable.
|
|
37
|
-
* - For
|
|
50
|
+
* - For a scriptTask with {@link script}: stored in zeebe:script.resultVariable.
|
|
51
|
+
* - For a Camunda connector job type (`io.camunda:…`): stored as the `resultVariable`
|
|
52
|
+
* task header, which is where the connector runtime reads it.
|
|
53
|
+
* - For any other serviceTask with jobType: stored as a zeebe:ioMapping output (source "= response").
|
|
38
54
|
*/
|
|
39
55
|
resultVariable?: string;
|
|
40
56
|
/** Event definition type (timer, error, message, signal, …) */
|
|
@@ -48,6 +64,18 @@ export interface CompactElement {
|
|
|
48
64
|
elements: CompactElement[];
|
|
49
65
|
flows: CompactFlow[];
|
|
50
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Runs the activity once per item of a list (`zeebe:loopCharacteristics`):
|
|
69
|
+
* `collection` is the FEEL expression of the list, `element` the variable each
|
|
70
|
+
* instance gets its item in. In parallel unless `sequential`.
|
|
71
|
+
*/
|
|
72
|
+
multiInstance?: {
|
|
73
|
+
collection: string;
|
|
74
|
+
element?: string;
|
|
75
|
+
sequential?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/** A timer event's ISO 8601 duration (`PT5M`): how long it waits once reached. */
|
|
78
|
+
timerDuration?: string;
|
|
51
79
|
}
|
|
52
80
|
/** A sequence flow in compact form. */
|
|
53
81
|
export interface CompactFlow {
|
|
@@ -126,6 +154,12 @@ export declare function defaultFlows(elements: readonly CompactElement[], flows:
|
|
|
126
154
|
*/
|
|
127
155
|
export declare function compactify(defs: BpmnDefinitions): CompactDiagram;
|
|
128
156
|
export declare function makeEventDef(eventType: string): BpmnEventDefinition | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Job types run by the Camunda connector runtime (`io.camunda:http-json:1`,
|
|
159
|
+
* `io.camunda.agenticai:aiagent:1`, …). The runtime reads `resultVariable` from
|
|
160
|
+
* a task header, not from an output mapping.
|
|
161
|
+
*/
|
|
162
|
+
export declare function isConnectorJobType(jobType: string): boolean;
|
|
129
163
|
export declare function makeExtensions(el: CompactElement): XmlElement[];
|
|
130
164
|
export declare function buildFlowElement(el: CompactElement, incoming: string[], outgoing: string[],
|
|
131
165
|
/** Id of the outgoing flow marked `isDefault`, for a gateway that has one. */
|
package/dist/bpmn/compact.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { layoutProcess } from "../layout/index.js";
|
|
2
2
|
import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
|
|
3
|
+
import { restConnectorTaskType } from "./rest-connector.js";
|
|
3
4
|
// ── Default flows ────────────────────────────────────────────────────────────
|
|
4
5
|
/**
|
|
5
6
|
* The gateway types that carry a `bpmn:default`. No other element in this model
|
|
@@ -49,14 +50,21 @@ function compactifyElement(el) {
|
|
|
49
50
|
const jobType = findAttr(ext, "zeebe:taskDefinition", "type");
|
|
50
51
|
if (jobType)
|
|
51
52
|
result.jobType = jobType;
|
|
52
|
-
// Extract task headers (key→value map from zeebe:taskHeaders children)
|
|
53
|
+
// Extract task headers (key→value map from zeebe:taskHeaders children). A connector's
|
|
54
|
+
// result variable is a header; it is kept apart to round-trip as `resultVariable`.
|
|
55
|
+
const connector = jobType !== undefined && isConnectorJobType(jobType);
|
|
56
|
+
let headerResult;
|
|
53
57
|
const taskHeadersEl = ext.find((e) => e.name === "zeebe:taskHeaders");
|
|
54
58
|
if (taskHeadersEl && taskHeadersEl.children.length > 0) {
|
|
55
59
|
const headers = {};
|
|
56
60
|
for (const child of taskHeadersEl.children) {
|
|
57
61
|
const key = child.attributes.key;
|
|
58
62
|
const value = child.attributes.value;
|
|
59
|
-
if (key
|
|
63
|
+
if (key === undefined || value === undefined)
|
|
64
|
+
continue;
|
|
65
|
+
if (connector && key === "resultVariable")
|
|
66
|
+
headerResult = value;
|
|
67
|
+
else
|
|
60
68
|
headers[key] = value;
|
|
61
69
|
}
|
|
62
70
|
if (Object.keys(headers).length > 0)
|
|
@@ -69,14 +77,25 @@ function compactifyElement(el) {
|
|
|
69
77
|
if (formId)
|
|
70
78
|
result.formId = formId;
|
|
71
79
|
const decisionId = findAttr(ext, "zeebe:calledDecision", "decisionId");
|
|
80
|
+
const script = findAttr(ext, "zeebe:script", "expression");
|
|
72
81
|
if (decisionId) {
|
|
73
82
|
result.decisionId = decisionId;
|
|
74
83
|
const rv = findAttr(ext, "zeebe:calledDecision", "resultVariable");
|
|
75
84
|
if (rv)
|
|
76
85
|
result.resultVariable = rv;
|
|
77
86
|
}
|
|
87
|
+
else if (script) {
|
|
88
|
+
result.script = script;
|
|
89
|
+
const rv = findAttr(ext, "zeebe:script", "resultVariable");
|
|
90
|
+
if (rv)
|
|
91
|
+
result.resultVariable = rv;
|
|
92
|
+
}
|
|
93
|
+
else if (connector) {
|
|
94
|
+
if (headerResult !== undefined)
|
|
95
|
+
result.resultVariable = headerResult;
|
|
96
|
+
}
|
|
78
97
|
else {
|
|
79
|
-
// For
|
|
98
|
+
// For job workers: extract the primary output variable from ioMapping
|
|
80
99
|
const ioMappingEl = ext.find((e) => e.name === "zeebe:ioMapping");
|
|
81
100
|
if (ioMappingEl) {
|
|
82
101
|
const outputs = ioMappingEl.children.filter((c) => c.name === "zeebe:output");
|
|
@@ -87,8 +106,35 @@ function compactifyElement(el) {
|
|
|
87
106
|
}
|
|
88
107
|
}
|
|
89
108
|
}
|
|
109
|
+
const inputs = {};
|
|
110
|
+
for (const input of ext.find((e) => e.name === "zeebe:ioMapping")?.children ?? []) {
|
|
111
|
+
const { source, target } = input.attributes;
|
|
112
|
+
if (input.name === "zeebe:input" && source !== undefined && target !== undefined) {
|
|
113
|
+
inputs[target] = source;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(inputs).length > 0)
|
|
117
|
+
result.inputs = inputs;
|
|
118
|
+
const template = el.unknownAttributes["zeebe:modelerTemplate"];
|
|
119
|
+
if (template) {
|
|
120
|
+
const version = Number.parseInt(el.unknownAttributes["zeebe:modelerTemplateVersion"] ?? "", 10);
|
|
121
|
+
result.modelerTemplate = Number.isNaN(version) ? { id: template } : { id: template, version };
|
|
122
|
+
}
|
|
90
123
|
if ("eventDefinitions" in el && el.eventDefinitions.length > 0) {
|
|
91
|
-
|
|
124
|
+
const def = el.eventDefinitions[0];
|
|
125
|
+
result.eventType = def?.type;
|
|
126
|
+
if (def?.type === "timer" && def.timeDuration)
|
|
127
|
+
result.timerDuration = def.timeDuration;
|
|
128
|
+
}
|
|
129
|
+
const loop = "loopCharacteristics" in el ? el.loopCharacteristics : undefined;
|
|
130
|
+
const zeebeLoop = loop?.extensionElements.find((x) => x.name === "zeebe:loopCharacteristics");
|
|
131
|
+
const collection = zeebeLoop?.attributes.inputCollection;
|
|
132
|
+
if (loop && collection) {
|
|
133
|
+
result.multiInstance = { collection };
|
|
134
|
+
if (zeebeLoop.attributes.inputElement)
|
|
135
|
+
result.multiInstance.element = zeebeLoop.attributes.inputElement;
|
|
136
|
+
if (loop.isSequential)
|
|
137
|
+
result.multiInstance.sequential = true;
|
|
92
138
|
}
|
|
93
139
|
if (el.type === "boundaryEvent") {
|
|
94
140
|
result.attachedTo = el.attachedToRef;
|
|
@@ -263,16 +309,59 @@ export function makeEventDef(eventType) {
|
|
|
263
309
|
return undefined;
|
|
264
310
|
}
|
|
265
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Job types run by the Camunda connector runtime (`io.camunda:http-json:1`,
|
|
314
|
+
* `io.camunda.agenticai:aiagent:1`, …). The runtime reads `resultVariable` from
|
|
315
|
+
* a task header, not from an output mapping.
|
|
316
|
+
*/
|
|
317
|
+
export function isConnectorJobType(jobType) {
|
|
318
|
+
return /^io\.camunda[.:]/.test(jobType);
|
|
319
|
+
}
|
|
320
|
+
/** Inputs of the HTTP connector that older compact answers wrote as task headers. */
|
|
321
|
+
function isRestInputKey(key) {
|
|
322
|
+
return (key === "url" ||
|
|
323
|
+
key === "method" ||
|
|
324
|
+
key === "headers" ||
|
|
325
|
+
key === "queryParameters" ||
|
|
326
|
+
key === "body" ||
|
|
327
|
+
key === "connectionTimeoutInSeconds" ||
|
|
328
|
+
key === "readTimeoutInSeconds" ||
|
|
329
|
+
key.startsWith("authentication."));
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Split an element's configuration into input mappings and task headers the
|
|
333
|
+
* way the engine reads them. The HTTP connector reads `url`, `method` and the
|
|
334
|
+
* rest from its inputs, so those keys move out of `taskHeaders`, where earlier
|
|
335
|
+
* prompts told models to put them and where the connector never looks.
|
|
336
|
+
*/
|
|
337
|
+
function zeebeConfig(el) {
|
|
338
|
+
const rest = el.jobType === restConnectorTaskType();
|
|
339
|
+
const inputs = { ...el.inputs };
|
|
340
|
+
const headers = {};
|
|
341
|
+
for (const [key, value] of Object.entries(el.taskHeaders ?? {})) {
|
|
342
|
+
if (rest && isRestInputKey(key))
|
|
343
|
+
inputs[key] ??= value;
|
|
344
|
+
else
|
|
345
|
+
headers[key] = value;
|
|
346
|
+
}
|
|
347
|
+
if (rest && inputs.url !== undefined)
|
|
348
|
+
inputs["authentication.type"] ??= "noAuth";
|
|
349
|
+
if (el.jobType && isConnectorJobType(el.jobType) && el.resultVariable && !el.decisionId) {
|
|
350
|
+
headers.resultVariable ??= el.resultVariable;
|
|
351
|
+
}
|
|
352
|
+
return { inputs, headers };
|
|
353
|
+
}
|
|
266
354
|
export function makeExtensions(el) {
|
|
267
355
|
const ext = [];
|
|
356
|
+
const { inputs, headers } = zeebeConfig(el);
|
|
268
357
|
if (el.jobType) {
|
|
269
358
|
ext.push({ name: "zeebe:taskDefinition", attributes: { type: el.jobType }, children: [] });
|
|
270
359
|
}
|
|
271
|
-
if (
|
|
360
|
+
if (Object.keys(headers).length > 0) {
|
|
272
361
|
ext.push({
|
|
273
362
|
name: "zeebe:taskHeaders",
|
|
274
363
|
attributes: {},
|
|
275
|
-
children: Object.entries(
|
|
364
|
+
children: Object.entries(headers).map(([key, value]) => ({
|
|
276
365
|
name: "zeebe:header",
|
|
277
366
|
attributes: { key, value },
|
|
278
367
|
children: [],
|
|
@@ -299,20 +388,29 @@ export function makeExtensions(el) {
|
|
|
299
388
|
children: [],
|
|
300
389
|
});
|
|
301
390
|
}
|
|
302
|
-
|
|
303
|
-
// Service task with a result variable: map the connector response to the variable
|
|
391
|
+
if (el.script) {
|
|
304
392
|
ext.push({
|
|
305
|
-
name: "zeebe:
|
|
306
|
-
attributes: {},
|
|
307
|
-
children: [
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
393
|
+
name: "zeebe:script",
|
|
394
|
+
attributes: { expression: el.script, resultVariable: el.resultVariable ?? "result" },
|
|
395
|
+
children: [],
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
const ioMapping = Object.entries(inputs).map(([target, source]) => ({
|
|
399
|
+
name: "zeebe:input",
|
|
400
|
+
attributes: { source, target },
|
|
401
|
+
children: [],
|
|
402
|
+
}));
|
|
403
|
+
if (el.resultVariable && el.jobType && !el.decisionId && !isConnectorJobType(el.jobType)) {
|
|
404
|
+
// A job worker's result: map its `response` variable to the result variable
|
|
405
|
+
ioMapping.push({
|
|
406
|
+
name: "zeebe:output",
|
|
407
|
+
attributes: { source: "= response", target: el.resultVariable },
|
|
408
|
+
children: [],
|
|
314
409
|
});
|
|
315
410
|
}
|
|
411
|
+
if (ioMapping.length > 0) {
|
|
412
|
+
ext.push({ name: "zeebe:ioMapping", attributes: {}, children: ioMapping });
|
|
413
|
+
}
|
|
316
414
|
return ext;
|
|
317
415
|
}
|
|
318
416
|
function buildSubContent(children) {
|
|
@@ -352,6 +450,14 @@ function buildSubContent(children) {
|
|
|
352
450
|
groups: [],
|
|
353
451
|
};
|
|
354
452
|
}
|
|
453
|
+
function templateAttributes(el) {
|
|
454
|
+
if (!el.modelerTemplate)
|
|
455
|
+
return {};
|
|
456
|
+
const { id, version } = el.modelerTemplate;
|
|
457
|
+
return version === undefined
|
|
458
|
+
? { "zeebe:modelerTemplate": id }
|
|
459
|
+
: { "zeebe:modelerTemplate": id, "zeebe:modelerTemplateVersion": String(version) };
|
|
460
|
+
}
|
|
355
461
|
export function buildFlowElement(el, incoming, outgoing,
|
|
356
462
|
/** Id of the outgoing flow marked `isDefault`, for a gateway that has one. */
|
|
357
463
|
defaultFlow) {
|
|
@@ -362,11 +468,27 @@ defaultFlow) {
|
|
|
362
468
|
incoming,
|
|
363
469
|
outgoing,
|
|
364
470
|
extensionElements: makeExtensions(el),
|
|
365
|
-
unknownAttributes:
|
|
471
|
+
unknownAttributes: templateAttributes(el),
|
|
366
472
|
};
|
|
367
|
-
const
|
|
473
|
+
const made = el.eventType ? makeEventDef(el.eventType) : undefined;
|
|
474
|
+
const eventDef = made?.type === "timer" && el.timerDuration ? { ...made, timeDuration: el.timerDuration } : made;
|
|
368
475
|
const eventDefs = eventDef ? [eventDef] : [];
|
|
369
476
|
const subContent = buildSubContent(el.children);
|
|
477
|
+
const loop = el.multiInstance && {
|
|
478
|
+
loopCharacteristics: {
|
|
479
|
+
isSequential: el.multiInstance.sequential || undefined,
|
|
480
|
+
extensionElements: [
|
|
481
|
+
{
|
|
482
|
+
name: "zeebe:loopCharacteristics",
|
|
483
|
+
attributes: {
|
|
484
|
+
inputCollection: el.multiInstance.collection,
|
|
485
|
+
...(el.multiInstance.element ? { inputElement: el.multiInstance.element } : {}),
|
|
486
|
+
},
|
|
487
|
+
children: [],
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
},
|
|
491
|
+
};
|
|
370
492
|
switch (el.type) {
|
|
371
493
|
case "startEvent":
|
|
372
494
|
return { ...base, type: "startEvent", eventDefinitions: eventDefs };
|
|
@@ -385,25 +507,25 @@ defaultFlow) {
|
|
|
385
507
|
eventDefinitions: eventDefs,
|
|
386
508
|
};
|
|
387
509
|
case "serviceTask":
|
|
388
|
-
return { ...base, type: "serviceTask" };
|
|
510
|
+
return { ...base, type: "serviceTask", ...loop };
|
|
389
511
|
case "scriptTask":
|
|
390
|
-
return { ...base, type: "scriptTask" };
|
|
512
|
+
return { ...base, type: "scriptTask", ...loop };
|
|
391
513
|
case "userTask":
|
|
392
|
-
return { ...base, type: "userTask" };
|
|
514
|
+
return { ...base, type: "userTask", ...loop };
|
|
393
515
|
case "businessRuleTask":
|
|
394
|
-
return { ...base, type: "businessRuleTask" };
|
|
516
|
+
return { ...base, type: "businessRuleTask", ...loop };
|
|
395
517
|
case "callActivity":
|
|
396
|
-
return { ...base, type: "callActivity" };
|
|
518
|
+
return { ...base, type: "callActivity", ...loop };
|
|
397
519
|
case "sendTask":
|
|
398
|
-
return { ...base, type: "sendTask" };
|
|
520
|
+
return { ...base, type: "sendTask", ...loop };
|
|
399
521
|
case "receiveTask":
|
|
400
|
-
return { ...base, type: "receiveTask" };
|
|
522
|
+
return { ...base, type: "receiveTask", ...loop };
|
|
401
523
|
case "manualTask":
|
|
402
|
-
return { ...base, type: "manualTask" };
|
|
524
|
+
return { ...base, type: "manualTask", ...loop };
|
|
403
525
|
case "task":
|
|
404
|
-
return { ...base, type: "task" };
|
|
526
|
+
return { ...base, type: "task", ...loop };
|
|
405
527
|
case "subProcess":
|
|
406
|
-
return { ...base, type: "subProcess", ...subContent };
|
|
528
|
+
return { ...base, type: "subProcess", ...subContent, ...loop };
|
|
407
529
|
case "adHocSubProcess":
|
|
408
530
|
return { ...base, type: "adHocSubProcess", ...subContent };
|
|
409
531
|
case "eventSubProcess":
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `with` lines: how a model configures a connector in the line format.
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* with post: slack chat.postMessage | data.channel=#ops | data.text== "Order " + orderId
|
|
6
|
+
* with fetch: http GET https://api.example.com/orders | result=order
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* A line names a node already written by its id, the connector by its alias,
|
|
10
|
+
* the operation when the connector has several, and the inputs as
|
|
11
|
+
* `key=value` (`key==expr` for FEEL). Path lines are unchanged, so a `with`
|
|
12
|
+
* line can follow anywhere and a diagram streams as before.
|
|
13
|
+
*
|
|
14
|
+
* This module only reads the line. Which connector an alias names, which keys
|
|
15
|
+
* it has and what it writes is `@bpmnkit/core/connectors`' part, so the parser
|
|
16
|
+
* stays free of the catalog's data.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
import type { ProcessTextProblem } from "./process-text.js";
|
|
21
|
+
/** One `with` line, as written. Nothing is resolved against the catalog yet. */
|
|
22
|
+
export interface ConnectorLine {
|
|
23
|
+
/** The node's id as written. */
|
|
24
|
+
id: string;
|
|
25
|
+
/** The connector alias, e.g. `slack`. */
|
|
26
|
+
alias: string;
|
|
27
|
+
/**
|
|
28
|
+
* The words after the alias, before the first `|`: the operation, and for
|
|
29
|
+
* some connectors values written without a key (`http GET <url>`). A word
|
|
30
|
+
* starting with `=` or a quote runs to the end of the head.
|
|
31
|
+
*/
|
|
32
|
+
args: string[];
|
|
33
|
+
/** `key=value` parts, in the order written; a later key wins. */
|
|
34
|
+
values: Record<string, string>;
|
|
35
|
+
line: number;
|
|
36
|
+
}
|
|
37
|
+
/** `with <id>:` at the start of a line. */
|
|
38
|
+
export declare const CONNECTOR_LINE: RegExp;
|
|
39
|
+
/**
|
|
40
|
+
* Reads a `with` line, or answers `undefined` when the line is not one.
|
|
41
|
+
*
|
|
42
|
+
* Never throws: a line that starts like one but cannot be read becomes a
|
|
43
|
+
* problem, and the parts it could read are kept.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseConnectorLine(text: string, line: number, problems: ProcessTextProblem[]): ConnectorLine | undefined;
|
|
46
|
+
//# sourceMappingURL=connector-line.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `with` lines: how a model configures a connector in the line format.
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* with post: slack chat.postMessage | data.channel=#ops | data.text== "Order " + orderId
|
|
6
|
+
* with fetch: http GET https://api.example.com/orders | result=order
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* A line names a node already written by its id, the connector by its alias,
|
|
10
|
+
* the operation when the connector has several, and the inputs as
|
|
11
|
+
* `key=value` (`key==expr` for FEEL). Path lines are unchanged, so a `with`
|
|
12
|
+
* line can follow anywhere and a diagram streams as before.
|
|
13
|
+
*
|
|
14
|
+
* This module only reads the line. Which connector an alias names, which keys
|
|
15
|
+
* it has and what it writes is `@bpmnkit/core/connectors`' part, so the parser
|
|
16
|
+
* stays free of the catalog's data.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
/** `with <id>:` at the start of a line. */
|
|
21
|
+
export const CONNECTOR_LINE = /^with\s+([A-Za-z_][\w.-]*)\s*:\s*(.*)$/i;
|
|
22
|
+
/** Splits on `|` outside quotes, brackets, braces and parentheses. */
|
|
23
|
+
function splitParts(text) {
|
|
24
|
+
const parts = [];
|
|
25
|
+
let depth = 0;
|
|
26
|
+
let quote;
|
|
27
|
+
let start = 0;
|
|
28
|
+
for (let i = 0; i < text.length; i++) {
|
|
29
|
+
const ch = text[i];
|
|
30
|
+
if (quote !== undefined) {
|
|
31
|
+
if (ch === "\\")
|
|
32
|
+
i++;
|
|
33
|
+
else if (ch === quote)
|
|
34
|
+
quote = undefined;
|
|
35
|
+
}
|
|
36
|
+
else if (ch === '"' || ch === "'")
|
|
37
|
+
quote = ch;
|
|
38
|
+
else if (ch === "(" || ch === "[" || ch === "{")
|
|
39
|
+
depth++;
|
|
40
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
41
|
+
depth = Math.max(0, depth - 1);
|
|
42
|
+
else if (ch === "|" && depth === 0) {
|
|
43
|
+
parts.push(text.slice(start, i));
|
|
44
|
+
start = i + 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
parts.push(text.slice(start));
|
|
48
|
+
return parts.map((p) => p.trim());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `a=1 b=2 c==x + 1`, several inputs in one part as the cards list them, split
|
|
52
|
+
* into one part each: at a space before `key=`, outside quotes and brackets.
|
|
53
|
+
* A FEEL value runs to the end of the part, as it may hold `=` itself.
|
|
54
|
+
*/
|
|
55
|
+
function splitPairs(part) {
|
|
56
|
+
const pairs = [];
|
|
57
|
+
let depth = 0;
|
|
58
|
+
let quote;
|
|
59
|
+
let start = 0;
|
|
60
|
+
for (let i = 0; i < part.length; i++) {
|
|
61
|
+
const ch = part[i];
|
|
62
|
+
if (quote !== undefined) {
|
|
63
|
+
if (ch === "\\")
|
|
64
|
+
i++;
|
|
65
|
+
else if (ch === quote)
|
|
66
|
+
quote = undefined;
|
|
67
|
+
}
|
|
68
|
+
else if (ch === '"' || ch === "'")
|
|
69
|
+
quote = ch;
|
|
70
|
+
else if (ch === "(" || ch === "[" || ch === "{")
|
|
71
|
+
depth++;
|
|
72
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
73
|
+
depth = Math.max(0, depth - 1);
|
|
74
|
+
else if (ch === "=" && part[i + 1] === "=" && depth === 0)
|
|
75
|
+
break;
|
|
76
|
+
else if (/\s/.test(ch ?? "") && depth === 0 && /^\s+[A-Za-z_][\w.]*\*?=/.test(part.slice(i))) {
|
|
77
|
+
pairs.push(part.slice(start, i));
|
|
78
|
+
start = i + 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
pairs.push(part.slice(start));
|
|
82
|
+
return pairs.map((p) => p.trim()).filter((p) => p !== "");
|
|
83
|
+
}
|
|
84
|
+
function headWords(head) {
|
|
85
|
+
const words = [];
|
|
86
|
+
let rest = head.trim();
|
|
87
|
+
while (rest !== "") {
|
|
88
|
+
if (rest.startsWith("=") || rest.startsWith('"') || rest.startsWith("'")) {
|
|
89
|
+
words.push(rest);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
const space = rest.search(/\s/);
|
|
93
|
+
words.push(space < 0 ? rest : rest.slice(0, space));
|
|
94
|
+
rest = space < 0 ? "" : rest.slice(space).trim();
|
|
95
|
+
}
|
|
96
|
+
return words;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads a `with` line, or answers `undefined` when the line is not one.
|
|
100
|
+
*
|
|
101
|
+
* Never throws: a line that starts like one but cannot be read becomes a
|
|
102
|
+
* problem, and the parts it could read are kept.
|
|
103
|
+
*/
|
|
104
|
+
export function parseConnectorLine(text, line, problems) {
|
|
105
|
+
const match = CONNECTOR_LINE.exec(text.trim());
|
|
106
|
+
if (!match)
|
|
107
|
+
return undefined;
|
|
108
|
+
const [, id = "", body = ""] = match;
|
|
109
|
+
const [head = "", ...rest] = splitParts(body);
|
|
110
|
+
const [alias, ...args] = headWords(head);
|
|
111
|
+
if (alias === undefined) {
|
|
112
|
+
problems.push({ line, message: `"with ${id}:" names no connector; ignored` });
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const values = {};
|
|
116
|
+
for (const part of rest.flatMap(splitPairs)) {
|
|
117
|
+
const eq = part.indexOf("=");
|
|
118
|
+
// `token*={{secrets.T}}`: the card's required mark copied with the key
|
|
119
|
+
const key = eq < 0 ? "" : part.slice(0, eq).trim().replace(/\*$/, "");
|
|
120
|
+
if (eq <= 0 || !/^[\w.:$-]+$/.test(key)) {
|
|
121
|
+
problems.push({ line, message: `expected "key=value" at "${part.slice(0, 30)}"; ignored` });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
values[key] = part.slice(eq + 1).trim();
|
|
125
|
+
}
|
|
126
|
+
// A URL where the alias goes keeps its case: paths are case-sensitive
|
|
127
|
+
return {
|
|
128
|
+
id,
|
|
129
|
+
alias: /^https?:\/\//i.test(alias) ? alias : alias.toLowerCase(),
|
|
130
|
+
args,
|
|
131
|
+
values,
|
|
132
|
+
line,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=connector-line.js.map
|
|
@@ -91,6 +91,7 @@ const PATCH_EXTENSIONS = [
|
|
|
91
91
|
["formId", "zeebe:formDefinition"],
|
|
92
92
|
["calledProcess", "zeebe:calledElement"],
|
|
93
93
|
["decisionId", "zeebe:calledDecision"],
|
|
94
|
+
["script", "zeebe:script"],
|
|
94
95
|
["taskHeaders", "zeebe:taskHeaders"],
|
|
95
96
|
];
|
|
96
97
|
/**
|
|
@@ -139,7 +140,7 @@ function setTaskHeaders(element, headers) {
|
|
|
139
140
|
* `zeebe:calledDecision` instead.
|
|
140
141
|
*/
|
|
141
142
|
function setResultVariable(element, resultVariable) {
|
|
142
|
-
const calledDecision = element.extensionElements.find((e) => e.name === "zeebe:calledDecision");
|
|
143
|
+
const calledDecision = element.extensionElements.find((e) => e.name === "zeebe:calledDecision" || e.name === "zeebe:script");
|
|
143
144
|
if (calledDecision) {
|
|
144
145
|
calledDecision.attributes.resultVariable = resultVariable;
|
|
145
146
|
return;
|
|
@@ -199,6 +200,12 @@ function patchElement(element, patch) {
|
|
|
199
200
|
if (patch.decisionId !== undefined) {
|
|
200
201
|
setExtensionAttribute(element, "zeebe:calledDecision", "decisionId", patch.decisionId);
|
|
201
202
|
}
|
|
203
|
+
if (patch.script !== undefined) {
|
|
204
|
+
const script = ensureExtension(element, "zeebe:script");
|
|
205
|
+
script.attributes.expression = patch.script;
|
|
206
|
+
// Camunda will not deploy a script without the variable its value goes to
|
|
207
|
+
script.attributes.resultVariable ??= patch.resultVariable ?? "result";
|
|
208
|
+
}
|
|
202
209
|
if (patch.resultVariable !== undefined)
|
|
203
210
|
setResultVariable(element, patch.resultVariable);
|
|
204
211
|
if (patch.taskHeaders !== undefined)
|