@uipath/maestro-builder-sdk 6.86.26 → 6.87.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.
@@ -1,3 +1,4 @@
1
+ import { type BpmnPlacementReport } from './merge-placement.js';
1
2
  export interface BpmnMergeOptions {
2
3
  /**
3
4
  * `compile(decompile(original))` captured BEFORE the author's edits — what a faithful
@@ -15,5 +16,11 @@ export interface BpmnMergeResult {
15
16
  authored: string[];
16
17
  /** Element ids present in the original but gone from the edited process. */
17
18
  removed: string[];
19
+ /**
20
+ * What the merge drew: the edit's new flow nodes and sequence flows get diagram
21
+ * geometry in the original's diagram, and every existing shape keeps its bounds unless
22
+ * a full container had to grow (merge-placement.ts). Empty when the original has no diagram.
23
+ */
24
+ layout: BpmnPlacementReport;
18
25
  }
19
26
  export declare function mergeBpmn(originalXml: string, editedXml: string, options?: BpmnMergeOptions): BpmnMergeResult;
@@ -28,6 +28,9 @@
28
28
  * children of its sub-process. The document root is merged the same way, so a
29
29
  * definition the edit needs (a new `bpmn:error`) lands beside the process.
30
30
  *
31
+ * The diagram is the original's. What the edit added is drawn into it, and nothing that
32
+ * was there moves (merge-placement.ts), so a brownfield edit needs no `format`.
33
+ *
31
34
  * Without a `baseline` the merge is two-way: take the edited process, re-attach the
32
35
  * original diagram by element id. Correct whenever decompile was faithful for every
33
36
  * element, and still much better than a bare recompile, which drops layout entirely.
@@ -65,6 +68,7 @@
65
68
  * edits that row: the merge changes what the edit changed and nothing else.
66
69
  */
67
70
  import { ownEntry } from '../core/own-entry.js';
71
+ import { placeAddedElements } from './merge-placement.js';
68
72
  import { findByLocal, parseXmlRanges } from './xml-ranges.js';
69
73
  const WIRING = new Set(['incoming', 'outgoing']);
70
74
  const isWiring = (range) => WIRING.has(range.local);
@@ -637,7 +641,45 @@ function twoWay(originalXml, editedXml) {
637
641
  let merged = originalXml.slice(0, originalProcess.innerStart) + body + originalXml.slice(originalProcess.innerEnd);
638
642
  if (removed.length > 0)
639
643
  merged = withoutDiagramFor(merged, kept, new Set(removed));
640
- return { xml: withDeclarations(merged, editedXml), preserved: [], authored, removed };
644
+ return { ...withPlacement(originalXml, withDeclarations(merged, editedXml)), preserved: [], authored, removed };
645
+ }
646
+ /** Each sequence flow's `sourceRef -> targetRef`, by id, anywhere in the document's processes. */
647
+ function flowEnds(xml) {
648
+ const ends = new Map();
649
+ for (const root of parseXmlRanges(xml))
650
+ for (const flow of allByLocal(root.children.filter((c) => c.local === 'process'), 'sequenceFlow'))
651
+ if (flow.id !== undefined)
652
+ ends.set(flow.id, `${flow.attributes.sourceRef ?? ''}->${flow.attributes.targetRef ?? ''}`);
653
+ return ends;
654
+ }
655
+ /** Each element's parent (its process or sub-process), by id, for every element under the document's processes. */
656
+ function scopes(xml) {
657
+ const parents = new Map();
658
+ const visit = (scope) => {
659
+ for (const child of scope.children) {
660
+ if (child.id === undefined)
661
+ continue;
662
+ parents.set(child.id, scope.id ?? '');
663
+ visit(child);
664
+ }
665
+ };
666
+ for (const root of parseXmlRanges(xml))
667
+ root.children.filter((c) => c.local === 'process').forEach(visit);
668
+ return parents;
669
+ }
670
+ /**
671
+ * Draw what the edit added into the original's diagram (merge-placement.ts): a shape for
672
+ * each new flow node, an edge for each new sequence flow, and a new route for a kept flow
673
+ * whose ends the edit moved.
674
+ */
675
+ function withPlacement(originalXml, merged) {
676
+ const originalIds = modelIds(originalXml);
677
+ const before = flowEnds(originalXml);
678
+ const rewired = new Set([...flowEnds(merged)].filter(([id, ends]) => before.has(id) && before.get(id) !== ends).map(([id]) => id));
679
+ const scopeBefore = scopes(originalXml);
680
+ const rescoped = new Set([...scopes(merged)].filter(([id, scope]) => scopeBefore.has(id) && scopeBefore.get(id) !== scope).map(([id]) => id));
681
+ const { xml, report } = placeAddedElements(merged, { isAdded: (id) => !originalIds.has(id), rewired, rescoped });
682
+ return { xml, layout: report };
641
683
  }
642
684
  export function mergeBpmn(originalXml, editedXml, options = {}) {
643
685
  processOf(originalXml, 'original');
@@ -657,5 +699,5 @@ export function mergeBpmn(originalXml, editedXml, options = {}) {
657
699
  const removed = [...originalIds].filter((id) => !kept.has(id));
658
700
  if (removed.length > 0)
659
701
  merged = withoutDiagramFor(merged, kept, originalIds);
660
- return { xml: withDeclarations(merged, editedXml), preserved: ctx.preserved, authored: ctx.authored, removed };
702
+ return { ...withPlacement(originalXml, withDeclarations(merged, editedXml)), preserved: ctx.preserved, authored: ctx.authored, removed };
661
703
  }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * bpmn/refresh-connections — what `uip maestro bpmn refresh` refuses about a
3
+ * process's Integration Service connections, judged on the model `compile`
4
+ * writes (`collectSerializerModel`), so the bindings a label synthesizes and
5
+ * bindings.json resolves are the ones judged (#1809).
6
+ *
7
+ * Sources (uipcli, `@uipath/maestro-sdk`): `bpmn-packaging/connection-resources.ts`
8
+ * (`buildConnectionResources`, which refresh runs before it validates) and
9
+ * `bpmn-validation/project-validator.ts`. Rule → code:
10
+ *
11
+ * - a root `Connection` / `ConnectionId` binding other than `ImplicitConnection`
12
+ * has a `resourceKey` and a GUID `default` — CONNECTION_BINDING_NOT_GUID (warning);
13
+ * - a connector node that names a connection names it as `=bindings.<id>`
14
+ * — INTSVC_CONNECTION_NOT_BINDING;
15
+ * - a bound node names its connector (`connectorKey`; an HTTP request's
16
+ * `body.targetConnector`) — INTSVC_CONNECTOR_KEY_MISSING;
17
+ * - the id is a root binding spelled exactly `Connection` / `ConnectionId`,
18
+ * except on an HTTP request — INTSVC_CONNECTION_BINDING_MISSING;
19
+ * - one connection resource serves one connector and one connection id
20
+ * — INTSVC_CONNECTION_RESOURCE_CONFLICT;
21
+ * - an `Intsvc.WaitForEvent` / `Intsvc.EventTrigger` names a connection
22
+ * — INTSVC_EVENT_NO_CONNECTION;
23
+ * - an activity's connection and folder bindings carry the same resourceKey
24
+ * (refresh on a V1 activity; `validate`'s MISSING_BINDING on any version)
25
+ * — INTSVC_CONNECTION_FOLDER_MISMATCH;
26
+ * - an activity names a connection (`connection`, else `connectionId`,
27
+ * non-blank) — INTSVC_CONNECTION_MISSING, an error on V1, which refresh
28
+ * refuses, and a warning otherwise.
29
+ *
30
+ * "V1" is refresh's reading (`isIntsvcActivityExecutionV1`): the row absent or
31
+ * `v1`; an explicitly empty row is not V1 there.
32
+ */
33
+ import type { ModdleElement } from 'bpmn-moddle';
34
+ type El = ModdleElement;
35
+ /** A finding, in `check`'s `Diagnostic` shape (placed on the element it is about). */
36
+ export interface RefreshConnectionDiagnostic {
37
+ level: 'error' | 'warning';
38
+ code: 'CONNECTION_BINDING_NOT_GUID' | 'INTSVC_CONNECTION_NOT_BINDING' | 'INTSVC_CONNECTION_BINDING_MISSING' | 'INTSVC_CONNECTION_RESOURCE_CONFLICT' | 'INTSVC_EVENT_NO_CONNECTION' | 'INTSVC_CONNECTION_FOLDER_MISMATCH' | 'INTSVC_CONNECTION_MISSING' | 'INTSVC_CONNECTOR_KEY_MISSING';
39
+ message: string;
40
+ where?: string;
41
+ nodeId?: string;
42
+ /** The binding a INTSVC_CONNECTION_BINDING_MISSING finding names. */
43
+ bindingId?: string;
44
+ /** The node row a finding is about, for `check` to match it against the authored-task rules. */
45
+ field?: 'connection' | 'connectionId' | 'connectorKey' | 'body';
46
+ }
47
+ /**
48
+ * Every condition `uip maestro bpmn refresh` refuses about the connections of
49
+ * `definitions` (the model `compile` writes), each placed on its element.
50
+ *
51
+ * @param definitions - The `bpmn:Definitions` the serializer built.
52
+ * @returns The diagnostics, in document order.
53
+ */
54
+ export declare function refreshConnectionDiagnostics(definitions: El): RefreshConnectionDiagnostic[];
55
+ export {};
@@ -0,0 +1,258 @@
1
+ import { GUID_RE } from '../core/binding-messages.js';
2
+ import { placeholder, prepareCommand } from '../core/cli-spelling.js';
3
+ /** The connector node types refresh binds a connection for (`BINDING_NODE_TYPES`). */
4
+ const BINDING_NODE_TYPES = new Set([
5
+ 'Intsvc.ActivityExecution',
6
+ 'Intsvc.EventTrigger',
7
+ 'Intsvc.WaitForEvent',
8
+ 'Intsvc.AsyncExecution',
9
+ 'Intsvc.SyncAgentExecution',
10
+ 'Intsvc.AsyncAgentExecution',
11
+ 'Intsvc.AsyncWorkflowExecution',
12
+ 'Intsvc.SyncWorkflowExecution',
13
+ 'Intsvc.UnifiedHttpRequest',
14
+ ]);
15
+ /** A manual HTTP request's placeholder connection: refresh packages no resource for it. */
16
+ const IMPLICIT_CONNECTION = 'ImplicitConnection';
17
+ /** refresh's `bindingIdOf`: the id in a `=bindings.<id>` reference, or `undefined`. */
18
+ const BINDING_REF = /^=bindings\.([A-Za-z_][\w.-]*)$/;
19
+ const extensionValues = (el) => (el?.extensionElements?.values ?? []);
20
+ /** Every flow element under `scope`, sub-process contents included (refresh's `allFlowElements`). */
21
+ function allFlowElements(scope) {
22
+ const out = [];
23
+ for (const child of (scope.flowElements ?? []))
24
+ out.push(child, ...allFlowElements(child));
25
+ return out;
26
+ }
27
+ /**
28
+ * The process's connector nodes, with every named input from the `uipath:context`
29
+ * and the payload's direct inputs (refresh reads both, the context first).
30
+ */
31
+ function connectorNodes(process) {
32
+ return allFlowElements(process).flatMap((element) => {
33
+ const payload = extensionValues(element).find((v) => v.$type === 'uipath:Activity' || v.$type === 'uipath:Event');
34
+ const type = payload?.type?.value;
35
+ if (!payload || type === undefined || !BINDING_NODE_TYPES.has(type))
36
+ return [];
37
+ const rows = [...(payload.context?.input ?? []), ...(payload.input ?? [])];
38
+ const values = new Map();
39
+ for (const row of rows)
40
+ if (row.name)
41
+ values.set(row.name, (row.value ?? row.body));
42
+ return [{ element, type, values }];
43
+ });
44
+ }
45
+ /** refresh's `connectionReference`: `connection`, else `connectionId`, the first non-blank. */
46
+ const connectionReference = (values) => [values.get('connection'), values.get('connectionId')].find((v) => v?.trim());
47
+ /** How refresh names the node in its messages. */
48
+ const nodeLabel = (type) => type === 'Intsvc.EventTrigger' ? 'Trigger' : type === 'Intsvc.WaitForEvent' ? 'Wait' : 'Activity';
49
+ /** The connector an HTTP request authenticates with: its body's `targetConnector`. */
50
+ function targetConnector(body) {
51
+ if (!body?.trim())
52
+ return undefined;
53
+ try {
54
+ const parsed = JSON.parse(body);
55
+ return typeof parsed.targetConnector === 'string' ? parsed.targetConnector : undefined;
56
+ }
57
+ catch {
58
+ return undefined;
59
+ }
60
+ }
61
+ /** A V1 `Intsvc.ActivityExecution`: no `activityConfigurationVersion`, or `v1`. */
62
+ const isV1Activity = (n) => {
63
+ if (n.type !== 'Intsvc.ActivityExecution')
64
+ return false;
65
+ const version = n.values.get('activityConfigurationVersion');
66
+ return version === undefined || version === 'v1';
67
+ };
68
+ /**
69
+ * Every condition `uip maestro bpmn refresh` refuses about the connections of
70
+ * `definitions` (the model `compile` writes), each placed on its element.
71
+ *
72
+ * @param definitions - The `bpmn:Definitions` the serializer built.
73
+ * @returns The diagnostics, in document order.
74
+ */
75
+ export function refreshConnectionDiagnostics(definitions) {
76
+ const out = [];
77
+ const processes = (definitions.rootElements ?? []).filter((e) => e.$type === 'bpmn:Process');
78
+ for (const process of processes) {
79
+ const rootBindings = (extensionValues(process).find((v) => v.$type === 'uipath:Bindings')?.binding ?? []);
80
+ const byId = new Map(rootBindings.map((b) => [b.id, b]));
81
+ const connections = new Map(rootBindings
82
+ .filter((b) => b.resource === 'Connection' && b.propertyAttribute === 'ConnectionId' && b.resourceKey !== IMPLICIT_CONNECTION)
83
+ .map((b) => [b.id, b]));
84
+ const nodes = connectorNodes(process);
85
+ // The connector each binding serves, for the command that binds it.
86
+ const connectorOf = new Map();
87
+ for (const n of nodes) {
88
+ const bindingId = BINDING_REF.exec(connectionReference(n.values) ?? '')?.[1];
89
+ const key = n.values.get('connectorKey')?.trim();
90
+ if (bindingId !== undefined && key && !connectorOf.has(bindingId))
91
+ connectorOf.set(bindingId, key);
92
+ }
93
+ // 1. The binding's default is the connection id the package declares.
94
+ for (const b of connections.values()) {
95
+ const value = typeof b.default === 'string' ? b.default.trim() : '';
96
+ if (GUID_RE.test(value))
97
+ continue;
98
+ const key = connectorOf.get(b.id);
99
+ // refresh's `toConnectionBinding` requires resourceKey, then default, then a GUID.
100
+ const keyed = typeof b.resourceKey === 'string' && b.resourceKey.trim() !== '';
101
+ const refusal = !keyed ? 'resourceKey is required' : value ? 'default must be a GUID' : 'default is required';
102
+ out.push({
103
+ level: 'warning',
104
+ code: 'CONNECTION_BINDING_NOT_GUID',
105
+ message: `Connection binding "${b.id}" ${value ? `has the value "${value}", which is not a GUID` : 'has no value'}; ` +
106
+ `\`uip maestro bpmn refresh\` refuses it ("Connection binding "${b.id}" ${refusal}."), so the ` +
107
+ `process cannot be packaged until it carries the connection's id. Bind the real connection: ` +
108
+ `\`${prepareCommand(key ?? placeholder('<connector-key>'), placeholder('<action>'))}\` writes it into bindings.json under this label, ` +
109
+ `or read its Id from \`uip is connections list ${key ?? '<connector-key>'} --all-folders --output json\` and declare ` +
110
+ `\`.binding('${b.id}', { resource: 'Connection', propertyAttribute: 'ConnectionId', value: '<connection id>' })\`. ` +
111
+ `A symbolic label checks and compiles offline; refresh is the first rung that needs the id.`,
112
+ where: b.id,
113
+ });
114
+ }
115
+ // 2–6. Each connector node's connection, as refresh reads it.
116
+ const resources = new Map();
117
+ for (const n of nodes) {
118
+ const id = n.element.id;
119
+ const name = n.element.name?.trim() || id;
120
+ const label = nodeLabel(n.type);
121
+ const at = { where: id, nodeId: id };
122
+ const ref = connectionReference(n.values);
123
+ if (ref === undefined) {
124
+ // refresh skips an unconnected trigger or wait; its validator refuses it.
125
+ if (n.type === 'Intsvc.WaitForEvent' || n.type === 'Intsvc.EventTrigger') {
126
+ out.push({
127
+ level: 'error',
128
+ code: 'INTSVC_EVENT_NO_CONNECTION',
129
+ message: `"${id}" (${n.type}) names no connection; \`uip maestro bpmn refresh\` and \`validate\` refuse it ` +
130
+ `("${n.type} has no connection. The runtime faults with "Value cannot be null. (Parameter 'Connection')"."). ` +
131
+ `Declare the connection at the root — \`.binding('conn', { resource: 'Connection', propertyAttribute: 'ConnectionId', value: '<connection id>' })\` — ` +
132
+ `and read it as connectionId: '=bindings.conn', or author the node with \`.${n.type === 'Intsvc.EventTrigger' ? 'eventTrigger' : 'waitForEvent'}()\` ` +
133
+ `and its \`connection\` / \`folder\` labels.`,
134
+ ...at,
135
+ field: 'connectionId',
136
+ });
137
+ }
138
+ else if (n.type === 'Intsvc.ActivityExecution') {
139
+ const v1 = isV1Activity(n);
140
+ const key = n.values.get('connectorKey')?.trim() || '<connector-key>';
141
+ out.push({
142
+ level: v1 ? 'error' : 'warning',
143
+ code: 'INTSVC_CONNECTION_MISSING',
144
+ message: `"${id}" (Intsvc.ActivityExecution) names no connection (no non-blank \`connection\` or \`connectionId\`). ` +
145
+ (v1
146
+ ? `\`uip maestro bpmn refresh\` refuses a V1 task without one ("${label} "${name}" connection must reference a root binding as "=bindings.<id>"."). `
147
+ : `The registry says to omit \`connection\` and \`folderKey\` only when the activity uses none; a connector activity almost always does. `) +
148
+ `Declare a Connection binding and read it as connection: '=bindings.<id>' ` +
149
+ `(\`uip is connections list ${key} --all-folders --output json\` lists the ids).`,
150
+ ...at,
151
+ });
152
+ }
153
+ continue;
154
+ }
155
+ const field = n.values.get('connection')?.trim() ? 'connection' : 'connectionId';
156
+ const bindingId = BINDING_REF.exec(ref)?.[1];
157
+ if (bindingId === undefined) {
158
+ out.push({
159
+ level: 'error',
160
+ code: 'INTSVC_CONNECTION_NOT_BINDING',
161
+ message: `"${id}" (${n.type}) has ${field}="${ref}"; ` +
162
+ `\`uip maestro bpmn refresh\` refuses it ("${label} "${name}" connection must reference a root binding as "=bindings.<id>"."). ` +
163
+ `A connection is resolved from a root binding, never written inline or computed: declare ` +
164
+ `\`.binding('conn', { resource: 'Connection', propertyAttribute: 'ConnectionId', value: '<connection id>' })\` ` +
165
+ `and read it as '=bindings.conn'.`,
166
+ ...at,
167
+ field,
168
+ });
169
+ continue;
170
+ }
171
+ const binding = connections.get(bindingId);
172
+ // A manual HTTP request without its binding packages no resource.
173
+ if (!binding && n.type === 'Intsvc.UnifiedHttpRequest')
174
+ continue;
175
+ // 3. refresh names the resource's connector before it looks the binding up.
176
+ const http = n.type === 'Intsvc.UnifiedHttpRequest';
177
+ const connector = http ? targetConnector(n.values.get('body')) : n.values.get('connectorKey')?.trim();
178
+ if (!connector) {
179
+ out.push({
180
+ level: 'error',
181
+ code: 'INTSVC_CONNECTOR_KEY_MISSING',
182
+ message: http
183
+ ? `"${id}" (${n.type}) is bound to "=bindings.${bindingId}" but its \`body\` names no \`targetConnector\`; ` +
184
+ `\`uip maestro bpmn refresh\` refuses it ("HTTP request "${name}" body.targetConnector is required."). ` +
185
+ `Set \`targetConnector\` in the request body to the connector key the connection belongs to.`
186
+ : `"${id}" (${n.type}) is bound to "=bindings.${bindingId}" but has no \`connectorKey\`; ` +
187
+ `\`uip maestro bpmn refresh\` refuses it ("${label} "${name}" connectorKey is required."): the connection resource ` +
188
+ `is declared for a connector. Add a \`connectorKey\` row naming the connector the connection belongs to.`,
189
+ ...at,
190
+ field: http ? 'body' : 'connectorKey',
191
+ });
192
+ }
193
+ if (!binding) {
194
+ const declared = byId.get(bindingId);
195
+ out.push({
196
+ level: 'error',
197
+ code: 'INTSVC_CONNECTION_BINDING_MISSING',
198
+ message: `"${id}" (${n.type}) reads its connection from "=bindings.${bindingId}", but ` +
199
+ (declared
200
+ ? `binding "${bindingId}" is resource "${declared.resource ?? ''}" / propertyAttribute "${declared.propertyAttribute ?? ''}"` +
201
+ (declared.resourceKey === IMPLICIT_CONNECTION ? ` keyed "${IMPLICIT_CONNECTION}"` : '') +
202
+ `, not a Connection / ConnectionId binding (both spelled exactly so)`
203
+ : `the process declares no root binding "${bindingId}"`) +
204
+ `; \`uip maestro bpmn refresh\` refuses it ("${label} "${name}" references missing Connection binding "${bindingId}"."). ` +
205
+ `Declare it at the root: \`.binding('${bindingId}', { resource: 'Connection', propertyAttribute: 'ConnectionId', value: '<connection id>' })\`.`,
206
+ ...at,
207
+ bindingId,
208
+ field,
209
+ });
210
+ continue;
211
+ }
212
+ // One resource, one connector and one connection id.
213
+ const resourceKey = typeof binding.resourceKey === 'string' ? binding.resourceKey.trim() : '';
214
+ const connectionId = typeof binding.default === 'string' ? binding.default.trim() : '';
215
+ if (connector && resourceKey) {
216
+ const prior = resources.get(resourceKey);
217
+ if (!prior)
218
+ resources.set(resourceKey, { connector, connectionId, node: id });
219
+ else if (prior.connector !== connector || prior.connectionId !== connectionId) {
220
+ out.push({
221
+ level: 'error',
222
+ code: 'INTSVC_CONNECTION_RESOURCE_CONFLICT',
223
+ message: `"${id}" (${connector}) and "${prior.node}" (${prior.connector}) both use connection resource "${resourceKey}"` +
224
+ (prior.connector === connector ? ` with different connection ids` : '') +
225
+ `; \`uip maestro bpmn refresh\` refuses it ("Connection resource "${resourceKey}" is used by Integration Service nodes with ` +
226
+ `different connectors or connections."). An Integration Service connection belongs to one connector: give each ` +
227
+ `connector its own Connection binding, with its own resourceKey.`,
228
+ ...at,
229
+ });
230
+ }
231
+ }
232
+ // An activity's folder binding is keyed by the same connection resource.
233
+ if (n.type === 'Intsvc.ActivityExecution') {
234
+ const folderRef = n.values.get('folderKey')?.trim();
235
+ const folderId = folderRef?.startsWith('=bindings.') ? folderRef.slice('=bindings.'.length) : undefined;
236
+ const folder = folderId === undefined ? undefined : byId.get(folderId);
237
+ const folderKey = typeof folder?.resourceKey === 'string' ? folder.resourceKey.trim() : '';
238
+ if (folder && folder.resource === 'Connection' && folder.propertyAttribute === 'folderKey' && resourceKey && folderKey && folderKey !== resourceKey) {
239
+ out.push({
240
+ level: 'error',
241
+ code: 'INTSVC_CONNECTION_FOLDER_MISMATCH',
242
+ message: `"${id}" (Intsvc.ActivityExecution) reads connection binding "${bindingId}" (resourceKey "${resourceKey}") and folder ` +
243
+ `binding "${folderId}" (resourceKey "${folderKey}"); ` +
244
+ (isV1Activity(n)
245
+ ? `\`uip maestro bpmn refresh\` and \`validate\` refuse it ("Integration Service activity connection and folder bindings ` +
246
+ `refer to different connection resources."). `
247
+ : `\`uip maestro bpmn validate\` refuses it as MISSING_BINDING ("incorrectly configured"). `) +
248
+ `A folder binding is keyed ` +
249
+ `by its connection: drop the folder binding's \`resourceKey\` (the builder pairs it with the connection this task reads) ` +
250
+ `or set it to "${resourceKey}".`,
251
+ ...at,
252
+ });
253
+ }
254
+ }
255
+ }
256
+ }
257
+ return out;
258
+ }
@@ -1,7 +1,9 @@
1
+ import type { ModdleElement } from 'bpmn-moddle';
1
2
  import { type BuiltBpmn, type BpmnNode, type BpmnVarDecl } from './bpmn-sdk.js';
2
3
  import type { Library } from '../core/library.js';
3
4
  import type { BindingsView } from '../core/binding-messages.js';
4
5
  import type { ResourceResolutions } from '../core/resource-resolution.js';
6
+ type El = ModdleElement;
5
7
  /** A refusal a collect-mode serialize reported instead of throwing (see {@link BpmnSerializeOpts.collect}). */
6
8
  export interface BpmnCollectedRefusal {
7
9
  code: string;
@@ -54,6 +56,18 @@ export declare function serialize(built: BuiltBpmn, opts?: BpmnSerializeOpts): P
54
56
  * under its own catch, and the XML is not written. Synchronous, for `check`.
55
57
  */
56
58
  export declare function collectSerializerRefusals(built: BuiltBpmn, opts?: Omit<BpmnSerializeOpts, 'collect'>): BpmnCollectedRefusal[];
59
+ /**
60
+ * {@link collectSerializerRefusals}, and the model it built: the
61
+ * `bpmn:Definitions` `compile` would write, with each refused element stood
62
+ * in. `definitions` is absent when collection stopped at a scope-level
63
+ * refusal, which leaves no model to judge. `check` reads it for the rules
64
+ * `uip maestro bpmn refresh` applies to the emitted bindings
65
+ * (`refresh-connections.ts`).
66
+ */
67
+ export declare function collectSerializerModel(built: BuiltBpmn, opts?: Omit<BpmnSerializeOpts, 'collect'>): {
68
+ refusals: BpmnCollectedRefusal[];
69
+ definitions?: El;
70
+ };
57
71
  /**
58
72
  * Make schema-default attributes explicit for canvas fidelity. bpmn-moddle omits
59
73
  * an attribute whose value equals the BPMN default, but Studio Web (and the
@@ -195,3 +209,4 @@ export declare function folderCompanionKeys(built: BuiltBpmn, sink: Map<string,
195
209
  export declare function publicDeclarationScope(nodes: BpmnNode[], processId: string): (v: BpmnVarDecl) => string;
196
210
  /** Flatten a scope's nodes (recursing sub-processes) for global scans. */
197
211
  export declare function allNodes(nodes: BpmnNode[]): BpmnNode[];
212
+ export {};
@@ -11,7 +11,8 @@
11
11
  *
12
12
  * **Semantic-only, no diagram.** BPMN validation is layout-independent, so no
13
13
  * `bpmndi:BPMNDiagram` is emitted here; `uip maestro bpmn format` adds geometry
14
- * when a visual diagram is needed.
14
+ * to a greenfield file, and a brownfield merge keeps the original's and draws what
15
+ * the edit added (merge-placement.ts).
15
16
  */
16
17
  import BpmnModdle from 'bpmn-moddle';
17
18
  import { createRequire } from 'node:module';
@@ -66,23 +67,34 @@ export async function serialize(built, opts = {}) {
66
67
  * under its own catch, and the XML is not written. Synchronous, for `check`.
67
68
  */
68
69
  export function collectSerializerRefusals(built, opts = {}) {
70
+ return collectSerializerModel(built, opts).refusals;
71
+ }
72
+ /**
73
+ * {@link collectSerializerRefusals}, and the model it built: the
74
+ * `bpmn:Definitions` `compile` would write, with each refused element stood
75
+ * in. `definitions` is absent when collection stopped at a scope-level
76
+ * refusal, which leaves no model to judge. `check` reads it for the rules
77
+ * `uip maestro bpmn refresh` applies to the emitted bindings
78
+ * (`refresh-connections.ts`).
79
+ */
80
+ export function collectSerializerModel(built, opts = {}) {
69
81
  const refusals = [];
70
82
  const collect = (r) => {
71
83
  refusals.push(r);
72
84
  };
73
85
  try {
74
- buildDefinitions(built, { ...opts, collect });
86
+ return { refusals, definitions: buildDefinitions(built, { ...opts, collect }).definitions };
75
87
  }
76
88
  catch (error) {
77
89
  if (error === COLLECTION_STOPPED)
78
- return refusals;
90
+ return { refusals };
79
91
  // An element's own refusal was taken by its catch (`createNodeCollected`),
80
92
  // so one that gets here was thrown outside any one element: scope-level,
81
93
  // and collection stops. An internal SDK error is passed on.
82
94
  const refusal = refusalOf(error);
83
95
  collect({ code: refusal.code, message: refusal.message, ...(refusal.suggestion !== undefined ? { suggestion: refusal.suggestion } : {}) });
84
96
  }
85
- return refusals;
97
+ return { refusals };
86
98
  }
87
99
  /** Thrown in collect mode once the scope-level refusals are reported, to stop collection. */
88
100
  const COLLECTION_STOPPED = Symbol('collection stopped');
package/dist/check.js CHANGED
@@ -7,7 +7,6 @@ import { checkCookedEscapes, checkFlowExpressions } from './flow-expr-check.js';
7
7
  import { FLOW_EXPR_DIALECT, checkBindingLabels, checkConnectorLookups as coreCheckConnectorLookups, checkConnectorResources as coreCheckConnectorResources, checkConnectorSchema as coreCheckConnectorSchema, } from './core/connector-checks.js';
8
8
  import { nearestName } from './core/edit-distance.js';
9
9
  import { escapeRegExp } from './core/escape-regexp.js';
10
- import { hitlDerivesOutcomeHandles, hitlExitModel, hitlRoutesPerOutcome, outcomeIdOf } from './core/hitl-routing.js';
11
10
  import { hasExits } from './core/step-ports.js';
12
11
  import { actionTails, armReachesJoin } from './flow-parallel-hitl.js';
13
12
  import { FLOW_SCHEMA_VERSIONS } from './format-profile.js';
@@ -17,7 +16,7 @@ import { VARS_READ_RE } from './core/vars-read.js';
17
16
  import { FLOW_METADATA_KEYS, unknownMetadataKeys } from './core/flow-metadata.js';
18
17
  import { endContentKey } from './flow-end-content.js';
19
18
  import { FLOW_NODE_TYPES, FLOW_TRIGGER_TYPES } from './flow-node-registry.js';
20
- import { stepExits } from './flow-step-exits.js';
19
+ import { stepExits, stepRouting } from './flow-step-exits.js';
21
20
  import { stepDeclaredVariables } from './flow-step-variables.js';
22
21
  import { plainHttpOnErrorMessage } from './nodes/http/flow/family.js';
23
22
  import { resolveVersion, resolveVersionCarried } from './core/nodes/versioned.js';
@@ -383,10 +382,10 @@ function checkFlow(built, ancestors, opts = {}) {
383
382
  // the next step with no incoming edge. A `.return()` is an End already, so
384
383
  // the outcomes join it. Side exits attach to the task and do not count.
385
384
  for (const [i, st] of steps.entries()) {
386
- if (st.kind !== 'action' || st.spec.kind !== 'hitl')
385
+ if (st.kind !== 'action')
387
386
  continue;
388
- const model = hitlExitModel(st.spec.inputs, st.options?.version);
389
- if (model.shape !== 'every-outcome' || !model.exits.every((e) => e.endsProcess))
387
+ const routing = stepRouting(st.spec, st.options?.version);
388
+ if (routing?.shape !== 'every' || !routing.exits.every((e) => e.endsProcess))
390
389
  continue;
391
390
  const after = steps.slice(i + 1).find((x) => x.kind !== 'stepToList' && x.kind !== 'stepToRef');
392
391
  if (after === undefined || after.kind === 'return')
@@ -395,7 +394,7 @@ function checkFlow(built, ancestors, opts = {}) {
395
394
  level: 'error',
396
395
  code: 'HITL_UNREACHABLE_AFTER',
397
396
  message: `Every outcome of human task "${st.name}" is action: 'End' `
398
- + `(${model.exits.map((e) => e.value).join(', ')}), so each one ends the run at its own End node, and `
397
+ + `(${routing.exits.map((e) => e.value).join(', ')}), so each one ends the run at its own End node, and `
399
398
  + `"${'name' in after ? after.name : after.kind}" after it can never run. Drop action: 'End' from the `
400
399
  + 'outcomes that should continue, or end the path here with .return().',
401
400
  step: st.name,
@@ -458,8 +457,9 @@ function checkFlow(built, ancestors, opts = {}) {
458
457
  if ((s.kind === 'stepToList' || s.kind === 'stepToRef') && s.port.startsWith('outcome-')) {
459
458
  const want = s.port.slice('outcome-'.length);
460
459
  const prevSpec = prevAction?.spec;
461
- const isHitl = !!prevSpec && 'kind' in prevSpec && prevSpec.kind === 'hitl';
462
- if (!isHitl) {
460
+ // Only a type whose exits are outcomes declares how they leave it.
461
+ const routing = prevSpec && 'kind' in prevSpec ? stepRouting(prevSpec, prevAction?.options?.version) : undefined;
462
+ if (!routing) {
463
463
  diags.push({
464
464
  level: 'error', code: 'HITL_OUTCOME_PORT_MISPLACED', step: prevAction?.name,
465
465
  message: `Port "${s.port}" is a human task's per-outcome exit, but the preceding step `
@@ -467,14 +467,12 @@ function checkFlow(built, ancestors, opts = {}) {
467
467
  });
468
468
  }
469
469
  else {
470
- const model = hitlExitModel(prevSpec.inputs, prevAction?.options?.version);
471
- const ids = (prevSpec.inputs.outcomes ?? []).map((o, i) => outcomeIdOf(o, i));
472
470
  // A task with no per-outcome exits, an id the task does not declare,
473
471
  // and a port a task that does not route per outcome already continues
474
472
  // on are the serializer's HITL_OUTCOME_PORTS_NONE /
475
473
  // HITL_OUTCOME_PORT_UNKNOWN / HITL_OUTCOME_PORTS_OFF (#741). A routed
476
474
  // port is recorded for the unrouted-outcome rule.
477
- if (model.shape === 'per-outcome' && ids.includes(want) && prevAction) {
475
+ if (routing.shape === 'routed' && routing.exits.some((e) => e.port === s.port) && prevAction) {
478
476
  let routed = hitlOutcomeRouted.get(prevAction.name);
479
477
  if (!routed)
480
478
  hitlOutcomeRouted.set(prevAction.name, routed = new Set());
@@ -511,38 +509,18 @@ function checkFlow(built, ancestors, opts = {}) {
511
509
  // `.stepSwitch` routes its exits as ARMS, so the `.stepToList` bookkeeping
512
510
  // would report every one of them unrouted. STEP_SWITCH_EXIT_UNROUTED is
513
511
  // that step's version of the same question.
514
- if (s0.kind !== 'stepSwitch'
515
- && s.spec.kind === 'hitl' && hitlRoutesPerOutcome(s.spec.inputs, s.options?.version)) {
516
- hitlOutcomeSteps.set(s.name, (s.spec.inputs.outcomes ?? []).map((o, i) => ({
517
- id: outcomeIdOf(o, i),
518
- endsProcess: typeof o !== 'string' && o?.action === 'End',
512
+ const routing = stepRouting(s.spec, s.options?.version);
513
+ if (s0.kind !== 'stepSwitch' && routing?.shape === 'routed') {
514
+ hitlOutcomeSteps.set(s.name, routing.exits.map((e) => ({
515
+ id: e.port.slice('outcome-'.length),
516
+ endsProcess: e.endsProcess === true,
519
517
  })));
520
518
  }
521
- if (s.spec.kind === 'hitl') {
522
- const outcomes = s.spec.inputs?.outcomes ?? [];
523
- // `action: 'End'` ends the PROCESS at the node, so a task whose every
524
- // outcome ends it has nothing downstream to distinguish — one exit is
525
- // the whole truth there, and the rule below would be a false positive.
526
- const allEnd = outcomes.length > 0
527
- && outcomes.every((o) => typeof o !== 'string' && o?.action === 'End');
528
- // `.stepSwitch` routes every outcome as an arm, so it never belongs here.
529
- // Nor does a `legacyCompleted` task: only its primary outcome continues,
530
- // so no downstream switch can reach the others, and HITL_LEGACY_COMPLETED
531
- // already says so.
532
- if (outcomes.length > 1 && !allEnd && s0.kind !== 'stepSwitch'
533
- && s.spec.inputs?.legacyCompleted !== true
534
- && !hitlRoutesPerOutcome(s.spec.inputs, s.options?.version)) {
535
- hitlChoiceNoPorts.set(s.name, {
536
- names: outcomes.map((o) => String((typeof o === 'string' ? o : o?.name) ?? '').trim()),
537
- ids: outcomes.map((o, i) => outcomeIdOf(o, i)),
538
- ends: outcomes.filter((o) => typeof o !== 'string' && o?.action === 'End')
539
- .map((o) => String(o.name ?? '').trim()),
540
- variant: s.spec.inputs?.variant,
541
- pinned: s.options?.version,
542
- portsOff: s.spec.inputs?.outcomePorts === false,
543
- });
544
- }
545
- }
519
+ // A choice the task's exits leave unsplit waits for the expressions
520
+ // (HITL_OUTCOMES_UNREACHABLE below); `.stepSwitch` routes every outcome
521
+ // as an arm, so it never belongs there.
522
+ if (routing?.unsplit && s0.kind !== 'stepSwitch')
523
+ hitlChoiceNoPorts.set(s.name, routing.unsplit);
546
524
  // The process family checks the step itself; the flow-level fire-and-forget
547
525
  // read rule below needs to know which steps dispatch without waiting.
548
526
  if (s.spec.kind === 'agenticProcess')
@@ -2207,14 +2185,13 @@ function reportUnreachableHitlOutcomes(choices, exprs, diags) {
2207
2185
  for (const m of js.matchAll(/\$vars\.([A-Za-z0-9_]+)\s*\[/g))
2208
2186
  readsOutcome.add(m[1]);
2209
2187
  }
2210
- for (const [step, { names, ids, ends, variant, pinned, portsOff }] of choices) {
2188
+ for (const [step, { names, ids, ends, canRoute, kept, portsOff }] of choices) {
2211
2189
  if (readsOutcome.has(step))
2212
2190
  continue;
2213
- // The base node and quick-form draw a handle per outcome, so both can route
2214
- // it — `.stepSwitch`, or `outcomePorts: true` (a pin keeps its version). An
2215
- // app-backed variant cannot: the Action read is its only remedy.
2216
- const canRoute = hitlDerivesOutcomeHandles(variant);
2217
- // On those two, an `action: 'End'` outcome gets its own End node, so the
2191
+ // A task that draws a handle per outcome can route it — `.stepSwitch`, or
2192
+ // `outcomePorts: true` (a pin keeps its version). An app-backed variant
2193
+ // cannot: the Action read is its only remedy (`canRoute`).
2194
+ // On a task that can, an `action: 'End'` outcome gets its own End node, so the
2218
2195
  // graph already tells it apart. Only the outcomes that CONTINUE share a step.
2219
2196
  const continuing = canRoute ? names.filter((n) => !ends.includes(n)) : names;
2220
2197
  if (continuing.length < 2)
@@ -2222,13 +2199,6 @@ function reportUnreachableHitlOutcomes(choices, exprs, diags) {
2222
2199
  const endNote = canRoute && ends.length > 0
2223
2200
  ? ` (${ends.join(', ')} ${ends.length === 1 ? 'is' : 'are'} action: 'End' and end${ends.length === 1 ? 's' : ''} the run instead)`
2224
2201
  : '';
2225
- const kept = !canRoute
2226
- ? `The "${variant}" variant reads its outcomes from its app and leaves on its single 'completed' exit`
2227
- : portsOff
2228
- ? `outcomePorts: false continues every outcome to the next step`
2229
- : variant === 'quick-form'
2230
- ? `A quick-form task continues every outcome to the next step unless it routes them`
2231
- : `{ version: '${pinned}' } without outcomePorts: true continues every outcome to the next step`;
2232
2202
  diags.push({
2233
2203
  level: 'warning', code: 'HITL_OUTCOMES_UNREACHABLE', step,
2234
2204
  message: `Human task "${step}" declares ${names.length} outcomes (${names.join(', ')}), but nothing `