@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
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applying an element template to an element of a parsed model.
|
|
3
|
+
*
|
|
4
|
+
* `applyElementTemplate` answers with builder options, which is enough for an
|
|
5
|
+
* outbound task built from scratch. An inbound connector is not: its message
|
|
6
|
+
* name and correlation key live on a root `bpmn:message` the event references,
|
|
7
|
+
* and an RPA task's scripts on `zeebe:linkedResources` — places no builder
|
|
8
|
+
* option reaches. This writes all of it onto an element that already exists.
|
|
9
|
+
*/
|
|
10
|
+
import { bpmnElementName, isZeebePlacementAllowed, retypeElement, sha256Hex, zeebeExtensionsToXmlElements, } from "../index.js";
|
|
11
|
+
import { resolveBindings } from "./apply.js";
|
|
12
|
+
/** The one `elementType.eventDefinition` this toolkit writes. */
|
|
13
|
+
export const APPLIED_EVENT_DEFINITION = "bpmn:MessageEventDefinition";
|
|
14
|
+
/** Every flow element type, so a template's `elementType` is checked rather than cast. */
|
|
15
|
+
const ELEMENT_TYPES = {
|
|
16
|
+
startEvent: true,
|
|
17
|
+
endEvent: true,
|
|
18
|
+
intermediateThrowEvent: true,
|
|
19
|
+
intermediateCatchEvent: true,
|
|
20
|
+
boundaryEvent: true,
|
|
21
|
+
task: true,
|
|
22
|
+
serviceTask: true,
|
|
23
|
+
scriptTask: true,
|
|
24
|
+
userTask: true,
|
|
25
|
+
sendTask: true,
|
|
26
|
+
receiveTask: true,
|
|
27
|
+
businessRuleTask: true,
|
|
28
|
+
manualTask: true,
|
|
29
|
+
callActivity: true,
|
|
30
|
+
exclusiveGateway: true,
|
|
31
|
+
parallelGateway: true,
|
|
32
|
+
inclusiveGateway: true,
|
|
33
|
+
eventBasedGateway: true,
|
|
34
|
+
complexGateway: true,
|
|
35
|
+
subProcess: true,
|
|
36
|
+
adHocSubProcess: true,
|
|
37
|
+
eventSubProcess: true,
|
|
38
|
+
transaction: true,
|
|
39
|
+
dataObject: true,
|
|
40
|
+
dataObjectReference: true,
|
|
41
|
+
dataStoreReference: true,
|
|
42
|
+
};
|
|
43
|
+
/** `"bpmn:ServiceTask"` → `"serviceTask"`, or undefined for a type the model has no element for. */
|
|
44
|
+
function toElementType(name) {
|
|
45
|
+
const local = name.startsWith("bpmn:") ? name.slice(5) : name;
|
|
46
|
+
const type = `${local.charAt(0).toLowerCase()}${local.slice(1)}`;
|
|
47
|
+
return Object.hasOwn(ELEMENT_TYPES, type) ? type : undefined;
|
|
48
|
+
}
|
|
49
|
+
function isEvent(type) {
|
|
50
|
+
return type.endsWith("Event");
|
|
51
|
+
}
|
|
52
|
+
/** `appliesTo` matches by type, and `bpmn:Task` covers every task, as it does in the Modeler. */
|
|
53
|
+
function appliesTo(template, type) {
|
|
54
|
+
const own = bpmnElementName({ type }).toLowerCase();
|
|
55
|
+
const isTask = type === "task" || type.endsWith("Task");
|
|
56
|
+
return template.appliesTo.some((entry) => entry.toLowerCase() === own || (entry === "bpmn:Task" && isTask));
|
|
57
|
+
}
|
|
58
|
+
function locateIn(elements, id) {
|
|
59
|
+
for (let index = 0; index < elements.length; index++) {
|
|
60
|
+
const element = elements[index];
|
|
61
|
+
if (element.id === id)
|
|
62
|
+
return { siblings: elements, index };
|
|
63
|
+
if ("flowElements" in element) {
|
|
64
|
+
const nested = locateIn(element.flowElements, id);
|
|
65
|
+
if (nested)
|
|
66
|
+
return nested;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
function locate(definitions, id) {
|
|
72
|
+
for (const process of definitions.processes) {
|
|
73
|
+
const found = locateIn(process.flowElements, id);
|
|
74
|
+
if (found)
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
function isMessageDefinition(definition) {
|
|
80
|
+
return definition.type === "message";
|
|
81
|
+
}
|
|
82
|
+
/** The id of the root message an element references, if any. */
|
|
83
|
+
export function messageRefOf(element) {
|
|
84
|
+
if (element.type === "receiveTask" || element.type === "sendTask")
|
|
85
|
+
return element.messageRef;
|
|
86
|
+
if ("eventDefinitions" in element) {
|
|
87
|
+
return element.eventDefinitions.find(isMessageDefinition)?.messageRef;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
function visitElements(definitions, visit) {
|
|
92
|
+
const walk = (elements) => {
|
|
93
|
+
for (const element of elements) {
|
|
94
|
+
visit(element);
|
|
95
|
+
if ("flowElements" in element)
|
|
96
|
+
walk(element.flowElements);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
for (const process of definitions.processes)
|
|
100
|
+
walk(process.flowElements);
|
|
101
|
+
}
|
|
102
|
+
/** How many elements and message flows reference a root message. */
|
|
103
|
+
function messageUses(definitions, messageId) {
|
|
104
|
+
let uses = 0;
|
|
105
|
+
visitElements(definitions, (element) => {
|
|
106
|
+
if (messageRefOf(element) === messageId)
|
|
107
|
+
uses++;
|
|
108
|
+
});
|
|
109
|
+
for (const collaboration of definitions.collaborations) {
|
|
110
|
+
for (const flow of collaboration.messageFlows)
|
|
111
|
+
if (flow.messageRef === messageId)
|
|
112
|
+
uses++;
|
|
113
|
+
}
|
|
114
|
+
return uses;
|
|
115
|
+
}
|
|
116
|
+
/** A message id derived from its name, like the builder's, deduped against every id in the model. */
|
|
117
|
+
function messageId(definitions, name) {
|
|
118
|
+
const taken = new Set();
|
|
119
|
+
for (const root of [
|
|
120
|
+
...definitions.messages,
|
|
121
|
+
...definitions.errors,
|
|
122
|
+
...definitions.signals,
|
|
123
|
+
...definitions.escalations,
|
|
124
|
+
]) {
|
|
125
|
+
taken.add(root.id);
|
|
126
|
+
}
|
|
127
|
+
visitElements(definitions, (element) => taken.add(element.id));
|
|
128
|
+
const base = `Message_${name.replace(/[^A-Za-z0-9_.-]/g, "_")}`;
|
|
129
|
+
let id = base;
|
|
130
|
+
for (let n = 2; taken.has(id); n++)
|
|
131
|
+
id = `${base}_${n}`;
|
|
132
|
+
return id;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The message an element should reference: one already named `name`, else the
|
|
136
|
+
* element's own message renamed when nothing else uses it, else a new one.
|
|
137
|
+
* Renaming in place keeps a re-applied template from leaving orphans behind.
|
|
138
|
+
*/
|
|
139
|
+
function resolveMessage(definitions, name, currentId) {
|
|
140
|
+
const named = definitions.messages.find((message) => message.name === name);
|
|
141
|
+
if (named)
|
|
142
|
+
return named;
|
|
143
|
+
const current = definitions.messages.find((message) => message.id === currentId);
|
|
144
|
+
if (current && messageUses(definitions, current.id) <= 1) {
|
|
145
|
+
current.name = name;
|
|
146
|
+
return current;
|
|
147
|
+
}
|
|
148
|
+
const created = { id: messageId(definitions, name), name, unknownAttributes: {} };
|
|
149
|
+
definitions.messages.push(created);
|
|
150
|
+
return created;
|
|
151
|
+
}
|
|
152
|
+
/** A UUID-shaped value (version 8, custom) from a SHA-256 — stable for the same seed. */
|
|
153
|
+
function derivedUuid(seed) {
|
|
154
|
+
const hex = sha256Hex(seed);
|
|
155
|
+
const variant = ((Number.parseInt(hex.charAt(16), 16) & 0x3) | 0x8).toString(16);
|
|
156
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-8${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Puts `replacement` where the first `name` extension sat, dropping any others;
|
|
160
|
+
* appends it when there was none, and removes it when `replacement` is undefined.
|
|
161
|
+
*/
|
|
162
|
+
function replaceExtension(extensions, name, replacement) {
|
|
163
|
+
const at = extensions.findIndex((extension) => extension.name === name);
|
|
164
|
+
const rest = extensions.filter((extension) => extension.name !== name);
|
|
165
|
+
if (!replacement)
|
|
166
|
+
return rest;
|
|
167
|
+
if (at === -1)
|
|
168
|
+
return [...rest, replacement];
|
|
169
|
+
rest.splice(at, 0, replacement);
|
|
170
|
+
return rest;
|
|
171
|
+
}
|
|
172
|
+
function zeebeElement(extensions) {
|
|
173
|
+
return zeebeExtensionsToXmlElements(extensions)[0];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The element-level extensions a template owns, each with what it now holds.
|
|
177
|
+
*
|
|
178
|
+
* Ownership follows the bindings the template *declares*, not the ones active
|
|
179
|
+
* for these values — so switching a dropdown off removes what it had written,
|
|
180
|
+
* and applying twice gives the same element.
|
|
181
|
+
*/
|
|
182
|
+
function ownedExtensions(declared, accum) {
|
|
183
|
+
const owned = [];
|
|
184
|
+
if (declared.has("zeebe:taskDefinition") || declared.has("zeebe:taskDefinition:type")) {
|
|
185
|
+
owned.push([
|
|
186
|
+
"zeebe:taskDefinition",
|
|
187
|
+
accum.taskType === undefined
|
|
188
|
+
? undefined
|
|
189
|
+
: zeebeElement({ taskDefinition: { type: accum.taskType, retries: accum.retries } }),
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
if (declared.has("zeebe:input") || declared.has("zeebe:output")) {
|
|
193
|
+
const { inputs, outputs } = accum;
|
|
194
|
+
owned.push([
|
|
195
|
+
"zeebe:ioMapping",
|
|
196
|
+
inputs.length + outputs.length === 0
|
|
197
|
+
? undefined
|
|
198
|
+
: zeebeElement({ ioMapping: { inputs, outputs } }),
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
if (declared.has("zeebe:taskHeader")) {
|
|
202
|
+
const headers = Object.entries(accum.taskHeaders).map(([key, value]) => ({ key, value }));
|
|
203
|
+
owned.push([
|
|
204
|
+
"zeebe:taskHeaders",
|
|
205
|
+
headers.length === 0 ? undefined : zeebeElement({ taskHeaders: { headers } }),
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
208
|
+
if (declared.has("zeebe:property")) {
|
|
209
|
+
const properties = accum.zeebeProperties;
|
|
210
|
+
owned.push([
|
|
211
|
+
"zeebe:properties",
|
|
212
|
+
properties.length === 0 ? undefined : zeebeElement({ properties: { properties } }),
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
if (declared.has("zeebe:adHoc")) {
|
|
216
|
+
const written = Object.values(accum.adHoc).some((value) => value !== undefined);
|
|
217
|
+
owned.push(["zeebe:adHoc", written ? zeebeElement({ adHoc: accum.adHoc }) : undefined]);
|
|
218
|
+
}
|
|
219
|
+
if (declared.has("zeebe:agentDefinition")) {
|
|
220
|
+
const { agentType } = accum.agentDefinition;
|
|
221
|
+
owned.push([
|
|
222
|
+
"zeebe:agentDefinition",
|
|
223
|
+
agentType === undefined ? undefined : zeebeElement({ agentDefinition: { agentType } }),
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
if (declared.has("zeebe:linkedResource")) {
|
|
227
|
+
const children = [...accum.linkedResources].map(([linkName, attributes]) => ({
|
|
228
|
+
name: "zeebe:linkedResource",
|
|
229
|
+
attributes: { linkName, ...attributes },
|
|
230
|
+
children: [],
|
|
231
|
+
}));
|
|
232
|
+
owned.push([
|
|
233
|
+
"zeebe:linkedResources",
|
|
234
|
+
children.length === 0
|
|
235
|
+
? undefined
|
|
236
|
+
: { name: "zeebe:linkedResources", attributes: {}, children },
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
return owned;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Applies an element template to one element of a parsed model — every binding
|
|
243
|
+
* kind, including the inbound ones builder options cannot carry.
|
|
244
|
+
*
|
|
245
|
+
* - **Element type.** `elementType` converts the element (keeping its id and
|
|
246
|
+
* wiring), and `elementType.eventDefinition` makes an event a message event.
|
|
247
|
+
* A template whose `appliesTo` does not cover the element is refused.
|
|
248
|
+
* - **Messages.** `bpmn:Message#property` names the root `bpmn:message` the
|
|
249
|
+
* event definition or receive task references — reusing one already carrying
|
|
250
|
+
* that name, renaming the element's own when nothing else uses it, creating
|
|
251
|
+
* one otherwise. `bpmn:Message#zeebe:subscription#property` writes that
|
|
252
|
+
* message's `zeebe:subscription`, which is where Camunda reads the
|
|
253
|
+
* correlation key; one left on the element itself is removed.
|
|
254
|
+
* - **Generated values.** A property with `generatedValue` and no value — the
|
|
255
|
+
* inbound message name — keeps the name of the message the element already
|
|
256
|
+
* references, and is otherwise derived from the template and element ids,
|
|
257
|
+
* never from a clock or random source.
|
|
258
|
+
* - **Extensions.** `zeebe:taskDefinition`, `ioMapping`, `taskHeaders`,
|
|
259
|
+
* `properties`, `adHoc` and `linkedResources` are replaced wholesale when the
|
|
260
|
+
* template declares a binding of that kind, in place, and left alone when it
|
|
261
|
+
* does not. `zeebe:modelerTemplate`, `…Version` and `…Icon` are stamped.
|
|
262
|
+
*
|
|
263
|
+
* Deterministic and idempotent: the same model, template and values give the
|
|
264
|
+
* same XML, and applying twice gives the same model as applying once.
|
|
265
|
+
*
|
|
266
|
+
* @param definitions - The model; not mutated.
|
|
267
|
+
* @param elementId - A flow element anywhere in its processes, sub-processes included.
|
|
268
|
+
* @param template - Any element template, bundled or a workspace's own.
|
|
269
|
+
* @param values - Keyed as in {@link applyElementTemplate}; `name` sets the element's name.
|
|
270
|
+
*/
|
|
271
|
+
export function applyTemplateToElement(definitions, elementId, template, values = {}) {
|
|
272
|
+
const refuse = (message) => ({
|
|
273
|
+
definitions,
|
|
274
|
+
problems: [{ message }],
|
|
275
|
+
});
|
|
276
|
+
const original = locate(definitions, elementId);
|
|
277
|
+
if (!original)
|
|
278
|
+
return refuse(`No flow element "${elementId}" in this model`);
|
|
279
|
+
const originalElement = original.siblings[original.index];
|
|
280
|
+
const targetType = template.elementType === undefined ? undefined : toElementType(template.elementType.value);
|
|
281
|
+
if (template.elementType !== undefined && targetType === undefined) {
|
|
282
|
+
return refuse(`Template "${template.id}" converts to "${template.elementType.value}", which is not a flow element type`);
|
|
283
|
+
}
|
|
284
|
+
if (originalElement.type !== targetType && !appliesTo(template, originalElement.type)) {
|
|
285
|
+
return refuse(`Template "${template.id}" applies to ${template.appliesTo.join(", ")}, not ${bpmnElementName(originalElement)} "${elementId}"`);
|
|
286
|
+
}
|
|
287
|
+
const next = structuredClone(definitions);
|
|
288
|
+
const location = locate(next, elementId);
|
|
289
|
+
const currentMessageId = messageRefOf(originalElement);
|
|
290
|
+
const currentMessage = next.messages.find((message) => message.id === currentMessageId);
|
|
291
|
+
const { accum, problems } = resolveBindings(template, values, (key, prop) => prop.binding.type === "bpmn:Message#property" &&
|
|
292
|
+
prop.binding.name === "name" &&
|
|
293
|
+
currentMessage?.name !== undefined
|
|
294
|
+
? currentMessage.name
|
|
295
|
+
: derivedUuid(`${template.id}\n${elementId}\n${key}`));
|
|
296
|
+
let element = location.siblings[location.index];
|
|
297
|
+
if (targetType !== undefined)
|
|
298
|
+
element = retypeElement(element, targetType);
|
|
299
|
+
if (values.name !== undefined)
|
|
300
|
+
element.name = values.name;
|
|
301
|
+
// Rebuilt rather than patched so a previous template's version or icon cannot survive.
|
|
302
|
+
const stamps = { "zeebe:modelerTemplate": template.id };
|
|
303
|
+
if (template.version !== undefined) {
|
|
304
|
+
stamps["zeebe:modelerTemplateVersion"] = String(template.version);
|
|
305
|
+
}
|
|
306
|
+
if (template.icon !== undefined)
|
|
307
|
+
stamps["zeebe:modelerTemplateIcon"] = template.icon.contents;
|
|
308
|
+
element.unknownAttributes = {
|
|
309
|
+
...Object.fromEntries(Object.entries(element.unknownAttributes).filter(([attribute]) => !attribute.startsWith("zeebe:modelerTemplate"))),
|
|
310
|
+
...stamps,
|
|
311
|
+
};
|
|
312
|
+
const declared = new Set(template.properties.map((prop) => prop.binding.type));
|
|
313
|
+
const owner = bpmnElementName(element);
|
|
314
|
+
for (const [name, extension] of ownedExtensions(declared, accum)) {
|
|
315
|
+
if (extension && !isZeebePlacementAllowed(owner, name)) {
|
|
316
|
+
problems.push({ message: `<${name}> is not allowed on <${owner}>; it was not written` });
|
|
317
|
+
element.extensionElements = replaceExtension(element.extensionElements, name, undefined);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
element.extensionElements = replaceExtension(element.extensionElements, name, extension);
|
|
321
|
+
}
|
|
322
|
+
const usesMessage = declared.has("bpmn:Message#property") ||
|
|
323
|
+
declared.has("bpmn:Message#zeebe:subscription#property");
|
|
324
|
+
const eventDefinition = template.elementType?.eventDefinition;
|
|
325
|
+
let messageDefinition;
|
|
326
|
+
if ("eventDefinitions" in element) {
|
|
327
|
+
if (eventDefinition !== undefined && eventDefinition !== APPLIED_EVENT_DEFINITION) {
|
|
328
|
+
problems.push({
|
|
329
|
+
message: `Event definition "${eventDefinition}" is not applied by this toolkit; the event's definitions were left as they were`,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
else if (eventDefinition !== undefined || usesMessage) {
|
|
333
|
+
messageDefinition = element.eventDefinitions.find(isMessageDefinition) ?? {
|
|
334
|
+
type: "message",
|
|
335
|
+
};
|
|
336
|
+
element.eventDefinitions = [messageDefinition];
|
|
337
|
+
}
|
|
338
|
+
else if (template.elementType !== undefined && isEvent(element.type)) {
|
|
339
|
+
element.eventDefinitions = [];
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (usesMessage) {
|
|
343
|
+
const name = accum.message.name ?? currentMessage?.name;
|
|
344
|
+
if (name === undefined) {
|
|
345
|
+
problems.push({
|
|
346
|
+
message: `Template "${template.id}" binds message properties but resolved no message name; the message was not written`,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
else if (messageDefinition === undefined &&
|
|
350
|
+
element.type !== "receiveTask" &&
|
|
351
|
+
element.type !== "sendTask") {
|
|
352
|
+
problems.push({
|
|
353
|
+
message: `${owner} "${elementId}" cannot reference a message; the message bindings were not written`,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
const message = resolveMessage(next, name, currentMessageId);
|
|
358
|
+
for (const [attribute, value] of Object.entries(accum.message)) {
|
|
359
|
+
if (attribute === "name")
|
|
360
|
+
continue;
|
|
361
|
+
message.unknownAttributes[attribute] = value;
|
|
362
|
+
}
|
|
363
|
+
if (declared.has("bpmn:Message#zeebe:subscription#property")) {
|
|
364
|
+
const subscription = Object.keys(accum.subscription).length
|
|
365
|
+
? {
|
|
366
|
+
name: "zeebe:subscription",
|
|
367
|
+
attributes: { ...accum.subscription },
|
|
368
|
+
children: [],
|
|
369
|
+
}
|
|
370
|
+
: undefined;
|
|
371
|
+
const extensions = replaceExtension(message.extensionElements ?? [], "zeebe:subscription", subscription);
|
|
372
|
+
message.extensionElements = extensions.length > 0 ? extensions : undefined;
|
|
373
|
+
}
|
|
374
|
+
if (messageDefinition)
|
|
375
|
+
messageDefinition.messageRef = message.id;
|
|
376
|
+
else if (element.type === "receiveTask" || element.type === "sendTask") {
|
|
377
|
+
element.messageRef = message.id;
|
|
378
|
+
}
|
|
379
|
+
element.extensionElements = replaceExtension(element.extensionElements, "zeebe:subscription", undefined);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
location.siblings[location.index] = element;
|
|
383
|
+
return { definitions: next, problems };
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=apply-element.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { AdHocSubProcessOptions, BoundaryEventOptions, IntermediateCatchEventOptions, ServiceTaskOptions, StartEventOptions } from "../index.js";
|
|
2
|
+
import type { ElementTemplate, TemplateCondition, TemplateProperty } from "./template-types.js";
|
|
3
|
+
export interface ApplyProblem {
|
|
4
|
+
/** The property key this problem is about, if any. */
|
|
5
|
+
key?: string;
|
|
6
|
+
message: string;
|
|
7
|
+
/**
|
|
8
|
+
* What kind of problem this is — distinguishes a genuinely unmet required
|
|
9
|
+
* field ("missing-required") from an unrecognized values key
|
|
10
|
+
* ("unknown-key"), a FEEL syntax error ("invalid-feel"), or a template
|
|
11
|
+
* with no resolvable task type ("no-task-type"). Callers that specifically
|
|
12
|
+
* want "what's still required" (e.g. the deploy-lint connector check)
|
|
13
|
+
* must filter on `kind === "missing-required"` — an unknown key is not
|
|
14
|
+
* evidence that some other field is missing.
|
|
15
|
+
*/
|
|
16
|
+
kind?: "missing-required" | "unknown-key" | "invalid-feel" | "no-task-type";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The result of applying a connector template — exactly one of `serviceTask`,
|
|
20
|
+
* `adHocSubProcess`, `startEvent`, `boundaryEvent`, or `intermediateEvent` is
|
|
21
|
+
* set, matching the template's direction. `problems` is always present and
|
|
22
|
+
* must be checked: a non-empty array means the template could not be fully
|
|
23
|
+
* applied (missing required value, unknown value key, or a FEEL parse error).
|
|
24
|
+
*/
|
|
25
|
+
export interface ApplyResult {
|
|
26
|
+
serviceTask?: ServiceTaskOptions;
|
|
27
|
+
adHocSubProcess?: Partial<AdHocSubProcessOptions>;
|
|
28
|
+
startEvent?: Partial<StartEventOptions>;
|
|
29
|
+
boundaryEvent?: Partial<BoundaryEventOptions>;
|
|
30
|
+
intermediateEvent?: Partial<IntermediateCatchEventOptions>;
|
|
31
|
+
problems: ApplyProblem[];
|
|
32
|
+
}
|
|
33
|
+
/** Everything a template's active properties resolve to, before it is written anywhere. */
|
|
34
|
+
export interface Accumulator {
|
|
35
|
+
inputs: Array<{
|
|
36
|
+
source: string;
|
|
37
|
+
target: string;
|
|
38
|
+
}>;
|
|
39
|
+
outputs: Array<{
|
|
40
|
+
source: string;
|
|
41
|
+
target: string;
|
|
42
|
+
}>;
|
|
43
|
+
taskHeaders: Record<string, string>;
|
|
44
|
+
zeebeProperties: Array<{
|
|
45
|
+
name: string;
|
|
46
|
+
value: string;
|
|
47
|
+
}>;
|
|
48
|
+
taskType?: string;
|
|
49
|
+
retries?: string;
|
|
50
|
+
adHoc: {
|
|
51
|
+
outputCollection?: string;
|
|
52
|
+
outputElement?: string;
|
|
53
|
+
activeElementsCollection?: string;
|
|
54
|
+
};
|
|
55
|
+
/** `zeebe:agentDefinition` bindings, e.g. `agentType`. */
|
|
56
|
+
agentDefinition: {
|
|
57
|
+
agentType?: string;
|
|
58
|
+
};
|
|
59
|
+
/** `bpmn:Message#property` bindings — attribute name to value, e.g. `name`. */
|
|
60
|
+
message: Record<string, string>;
|
|
61
|
+
/** `bpmn:Message#zeebe:subscription#property` bindings, e.g. `correlationKey`. */
|
|
62
|
+
subscription: Record<string, string>;
|
|
63
|
+
/** `zeebe:linkedResource` bindings, by `linkName` in template order. */
|
|
64
|
+
linkedResources: Map<string, Record<string, string>>;
|
|
65
|
+
}
|
|
66
|
+
export declare function evalCondition(cond: TemplateCondition, values: Record<string, string>): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The effective value of every active property: user override, else template
|
|
69
|
+
* default.
|
|
70
|
+
*
|
|
71
|
+
* Only an active property has a value, as in the Modeler. A dropdown hidden by
|
|
72
|
+
* its own condition does not keep its default, so it cannot switch on the
|
|
73
|
+
* properties that depend on it: GitHub's `labelOperationType` defaults to a
|
|
74
|
+
* label operation, but while `operationGroup` is "issue" it is hidden, and the
|
|
75
|
+
* label inputs stay off. Conditions can chain, so this repeats until nothing
|
|
76
|
+
* changes.
|
|
77
|
+
*/
|
|
78
|
+
export declare function resolveValues(template: ElementTemplate, values: Record<string, string>): Record<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* The binding types `applyBinding` below writes.
|
|
81
|
+
*
|
|
82
|
+
* Declared beside the switch so the two are edited together: anything the
|
|
83
|
+
* switch gains belongs here, and `validateElementTemplate` warns about every
|
|
84
|
+
* binding that is valid but absent from this set — otherwise a template using
|
|
85
|
+
* one would apply silently and do nothing.
|
|
86
|
+
*/
|
|
87
|
+
export declare const APPLIED_BINDING_TYPES: ReadonlySet<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Resolves a template and a set of values into the bindings its active
|
|
90
|
+
* properties write — the half of applying a template that does not depend on
|
|
91
|
+
* where the result goes, shared by {@link applyElementTemplate} and
|
|
92
|
+
* `applyTemplateToElement`.
|
|
93
|
+
*
|
|
94
|
+
* @param generate - Supplies a value for an active property that declares a
|
|
95
|
+
* `generatedValue` and was given none. Returning `undefined` leaves the
|
|
96
|
+
* binding unwritten; the callback reports that however suits its caller.
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolveBindings(template: ElementTemplate, values: Record<string, string>, generate: (key: string, prop: TemplateProperty) => string | undefined): {
|
|
99
|
+
accum: Accumulator;
|
|
100
|
+
problems: ApplyProblem[];
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Applies a Camunda 8 out-of-the-box connector element template deterministically.
|
|
104
|
+
*
|
|
105
|
+
* Unlike a naive apply that only handles `zeebe:input`, this resolves every
|
|
106
|
+
* binding kind (`zeebe:input`, `zeebe:output`, `zeebe:taskHeader`,
|
|
107
|
+
* `zeebe:taskDefinition(:type)`, `zeebe:property`, `zeebe:adHoc`,
|
|
108
|
+
* `zeebe:agentDefinition`), respects
|
|
109
|
+
* dropdown-gated `condition`s, validates required fields, and parse-validates
|
|
110
|
+
* any value that looks like a FEEL expression (leading "=").
|
|
111
|
+
*
|
|
112
|
+
* The result is builder options, which have no field for some bindings: a
|
|
113
|
+
* message start event's correlation key and `zeebe:linkedResource` come back
|
|
114
|
+
* as problems rather than being dropped, and a message name the template
|
|
115
|
+
* generates per element (`generatedValue`) must be passed in `values`. Inbound
|
|
116
|
+
* intermediate and boundary templates' `zeebe:property` bindings are returned
|
|
117
|
+
* but not written by `@bpmnkit/core`'s builder. {@link applyTemplateToElement}
|
|
118
|
+
* writes every binding onto an existing element of a parsed model instead.
|
|
119
|
+
*
|
|
120
|
+
* `values` keys match `ConnectorSummary.requiredInputs[].key` /
|
|
121
|
+
* `optionalInputs[].key` from `listConnectors()`/`searchConnectors()`.
|
|
122
|
+
*
|
|
123
|
+
* Operates on any {@link ElementTemplate} object — not just the bundled OOTB
|
|
124
|
+
* catalog — so custom/generated templates (e.g. from `@bpmnkit/connector-gen`)
|
|
125
|
+
* work the same way. Use {@link applyConnectorTemplate} to apply by bundled
|
|
126
|
+
* template id instead.
|
|
127
|
+
*/
|
|
128
|
+
export declare function applyElementTemplate(template: ElementTemplate, values?: Record<string, string>): ApplyResult;
|
|
129
|
+
/**
|
|
130
|
+
* Applies a bundled Camunda 8 out-of-the-box connector element template by
|
|
131
|
+
* id — see {@link applyElementTemplate} for the full binding-resolution
|
|
132
|
+
* behavior. Returns a single `problems` entry if `templateId` isn't in the
|
|
133
|
+
* bundled catalog (use `applyElementTemplate` directly for custom templates).
|
|
134
|
+
*/
|
|
135
|
+
export declare function applyConnectorTemplate(templateId: string, values?: Record<string, string>): ApplyResult;
|
|
136
|
+
//# sourceMappingURL=apply.d.ts.map
|