@uipath/maestro-builder-sdk 6.124.1 → 6.124.3

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.
@@ -9,9 +9,10 @@
9
9
  * - the whole section: edited equals baseline → the original's, verbatim;
10
10
  * - a top-level key (`globals`, `nodes`, `variableUpdates`): edited equals
11
11
  * baseline → the original's (absent stays absent);
12
- * - an entry of an id-keyed list (`globals`, `nodes`) or a key of a map
13
- * (`variableUpdates`): the same, and inside an entry each field the same,
14
- * so an edited global's new `type` lands without the `name` compile adds.
12
+ * - an entry of an id-keyed list (`globals`, `nodes`), a key of a map
13
+ * (`variableUpdates`) and a row under that key (by `variableId`): the
14
+ * same, and inside an entry each field the same, so an edited global's new
15
+ * `type` lands without the `name` compile adds.
15
16
  *
16
17
  * Presence follows the same logic. An entry the edited file lacks was removed
17
18
  * by the author when the baseline has it, and lost by the round trip when it
@@ -79,7 +80,7 @@ export function mergeVariables(original, edited, baseline, goneNodeIds) {
79
80
  for (const key of keysInOrder(orig, edited)) {
80
81
  const updates = key === 'variableUpdates';
81
82
  const inner = updates
82
- ? (o, b, e) => (isObj(o) && isObj(e) ? mergeFields(o, isObj(b) ? b : undefined, e) : copy(e))
83
+ ? (o, b, e) => (isObj(o) && isObj(e) ? mergeUpdates(o, isObj(b) ? b : {}, e) : copy(e))
83
84
  : (o, b, e) => mergeList(o, b, e, goneNodeIds);
84
85
  // A section the original lacks but the round trip writes is merged as an
85
86
  // empty one, so its minted entries stay out and only the author's land.
@@ -92,7 +93,53 @@ export function mergeVariables(original, edited, baseline, goneNodeIds) {
92
93
  }
93
94
  if (original === undefined && entries.length === 0)
94
95
  return undefined;
95
- return withoutGoneUpdates(Object.fromEntries(entries), goneNodeIds);
96
+ return withoutGoneUpdates(withoutRowsForGoneGlobals(Object.fromEntries(entries), orig, edited), goneNodeIds);
97
+ }
98
+ /**
99
+ * `variables` without an update row kept from the original for a global the
100
+ * merged file no longer has. `mergeRows` keeps a row compile never writes (the
101
+ * edited file lacks it, and so does the baseline), so when the author renamed or
102
+ * deleted the global that row writes, it would outlive the variable.
103
+ *
104
+ * Example, the author renames global `x` to `y` on an End whose `x` row compile
105
+ * does not write:
106
+ *
107
+ * original end: [x = 1] merged globals [y] edited end: [y = 2]
108
+ * merged end: [y = 2] (not [x = 1, y = 2])
109
+ *
110
+ * Only a row the edited file lacks, for an id that was a global in the original
111
+ * and is not one now: any other row is left to the delta rule.
112
+ */
113
+ function withoutRowsForGoneGlobals(merged, orig, edited) {
114
+ const ids = (v) => new Set(Array.isArray(v) ? v.filter((g) => isObj(g) && typeof g.id === 'string').map((g) => g.id) : []);
115
+ const before = ids(orig.globals);
116
+ const now = ids(merged.globals);
117
+ const gone = [...before].filter((id) => !now.has(id));
118
+ if (gone.length === 0 || !isObj(merged.variableUpdates))
119
+ return merged;
120
+ const editedUpdates = isObj(edited.variableUpdates) ? edited.variableUpdates : {};
121
+ // Built from entries, not by assignment, so a node id `__proto__` stays a key.
122
+ const entries = [];
123
+ let changed = false;
124
+ for (const [nodeId, rows] of Object.entries(merged.variableUpdates)) {
125
+ if (!Array.isArray(rows)) {
126
+ entries.push([nodeId, rows]);
127
+ continue;
128
+ }
129
+ const editedOwn = own(editedUpdates, nodeId);
130
+ const editedRows = Array.isArray(editedOwn) ? editedOwn : [];
131
+ const inEdited = (vid) => editedRows.some((r) => isObj(r) && r.variableId === vid);
132
+ const kept = rows.filter((r) => !(isObj(r) && typeof r.variableId === 'string' && gone.includes(r.variableId) && !inEdited(r.variableId)));
133
+ if (kept.length === rows.length) {
134
+ entries.push([nodeId, rows]);
135
+ continue;
136
+ }
137
+ changed = true;
138
+ // A node left with no rows keeps no key, as the merge writes for a node the author emptied.
139
+ if (kept.length)
140
+ entries.push([nodeId, kept]);
141
+ }
142
+ return changed ? { ...merged, variableUpdates: Object.fromEntries(entries) } : merged;
96
143
  }
97
144
  /** `undefined` for an empty list or map, so an absent section stays absent. */
98
145
  function nonEmpty(v) {
@@ -188,9 +235,128 @@ function insertAt(out, edited, i) {
188
235
  return 0;
189
236
  }
190
237
  /**
191
- * An object the author changed — a list entry, or the `variableUpdates` map
192
- * (keyed by node id): each key under the delta rule, each value taken whole,
193
- * keys in the original's order.
238
+ * The `variableUpdates` map (node id -> rows) the author changed: each node's
239
+ * rows under the delta rule, one row at a time ({@link mergeRows}), node ids in
240
+ * the original's order.
241
+ *
242
+ * Taking a changed node's rows whole lost what the original wrote and kept what
243
+ * only compile writes. An End the original wrote with ten rows that compile
244
+ * does not write came back with just the one row the author added; an End the
245
+ * original wrote with none came back with the row compile mints for it too.
246
+ */
247
+ function mergeUpdates(o, b, e) {
248
+ const entries = [];
249
+ for (const key of keysInOrder(o, e)) {
250
+ const [inO, inB, inE] = [has(o, key), has(b, key), has(e, key)];
251
+ let v;
252
+ if (!inE)
253
+ v = inB || !inO ? undefined : copy(o[key]); // removed by the author / lost by the round trip
254
+ else if (inB && same(e[key], b[key]))
255
+ v = inO ? copy(o[key]) : undefined; // untouched
256
+ else {
257
+ const rows = mergeRows(inO ? o[key] : [], inB ? b[key] : [], e[key]);
258
+ // Every row compile minted, and none the author wrote: absent stays absent.
259
+ v = !inO && Array.isArray(rows) && rows.length === 0 ? undefined : rows;
260
+ }
261
+ if (v !== undefined)
262
+ entries.push([key, v]);
263
+ }
264
+ return Object.fromEntries(entries);
265
+ }
266
+ /** Rows (`{ variableId, expression }`), each variable at most once. */
267
+ function rowList(v) {
268
+ if (!Array.isArray(v) || !v.every((x) => isObj(x) && typeof x.variableId === 'string'))
269
+ return false;
270
+ return new Set(v.map((x) => x.variableId)).size === v.length;
271
+ }
272
+ /**
273
+ * One node's update rows, keyed by `variableId`, under the delta rule: a row
274
+ * the author did not change is the original's; one the edited file lacks was
275
+ * removed (the baseline has it) or lost by the round trip (kept); one the
276
+ * original lacks is the author's, unless the baseline has it unchanged (minted
277
+ * by the round trip, dropped).
278
+ *
279
+ * Order: rows are ordered BPMN output mappings, and the runtime writes each one
280
+ * before it evaluates the next, so order can change a value. When the author
281
+ * did not reorder (the rows edited and baseline share are in the same order in
282
+ * both), rows keep the original's order and an added row goes after the edited
283
+ * row before it, else before the edited row after it, else last. When the
284
+ * author did reorder, rows follow the edited order, and a row only the original
285
+ * has (one compile never writes) goes after the original row before it, else
286
+ * before the original row after it, else last.
287
+ *
288
+ * Example, the author adds `extra` to an End compile writes no rows for:
289
+ *
290
+ * original [a, b] baseline [] edited [extra]
291
+ * merged [a, b, extra]
292
+ *
293
+ * Example, the author swaps `a` and `b` on an End that also has `k`, a row
294
+ * compile never writes:
295
+ *
296
+ * original [a, k, b] baseline [a, b] edited [b, a]
297
+ * merged [b, a, k]
298
+ */
299
+ function mergeRows(o, b, e) {
300
+ if (!rowList(o) || !rowList(b) || !rowList(e))
301
+ return copy(e);
302
+ const id = (x) => x.variableId;
303
+ const base = new Map(b.map((x) => [id(x), x]));
304
+ const edits = new Map(e.map((x) => [id(x), x]));
305
+ /** The merged row for an edited one; `undefined` = minted by the round trip. */
306
+ const originals = new Map(o.map((x) => [id(x), x]));
307
+ const mergedRow = (ed) => {
308
+ const [row, bRow] = [originals.get(id(ed)), base.get(id(ed))];
309
+ const untouched = bRow !== undefined && same(ed, bRow);
310
+ if (!row)
311
+ return untouched ? undefined : copy(ed);
312
+ return untouched ? copy(row) : mergeFields(row, bRow, ed);
313
+ };
314
+ /** A row only the original has: compile never writes it, so it is kept. */
315
+ const originalOnly = (row) => !edits.has(id(row)) && !base.has(id(row));
316
+ const shared = (rows, other) => rows.map(id).filter((v) => other.has(v));
317
+ const reordered = shared(e, base).join('\0') !== shared(b, edits).join('\0');
318
+ const out = [];
319
+ if (reordered) {
320
+ for (const ed of e) {
321
+ const row = mergedRow(ed);
322
+ if (row)
323
+ out.push(row);
324
+ }
325
+ for (const [i, row] of o.entries())
326
+ if (originalOnly(row))
327
+ out.splice(rowInsertAt(out, o, i), 0, copy(row));
328
+ return out;
329
+ }
330
+ for (const row of o) {
331
+ const ed = edits.get(id(row));
332
+ if (ed)
333
+ out.push(mergedRow(ed));
334
+ else if (originalOnly(row))
335
+ out.push(copy(row));
336
+ }
337
+ for (const [i, ed] of e.entries()) {
338
+ if (originals.has(id(ed)))
339
+ continue; // placed above
340
+ const row = mergedRow(ed);
341
+ if (row)
342
+ out.splice(rowInsertAt(out, e, i), 0, row);
343
+ }
344
+ return out;
345
+ }
346
+ /** After the nearest earlier row of `rows` already in `out`, else before the nearest later one, else last. */
347
+ function rowInsertAt(out, rows, i) {
348
+ const at = (j) => out.findIndex((x) => x.variableId === rows[j].variableId);
349
+ for (let j = i - 1; j >= 0; j--)
350
+ if (at(j) >= 0)
351
+ return at(j) + 1;
352
+ for (let j = i + 1; j < rows.length; j++)
353
+ if (at(j) >= 0)
354
+ return at(j);
355
+ return out.length;
356
+ }
357
+ /**
358
+ * An object the author changed, a list entry or an update row: each key under
359
+ * the delta rule, each value taken whole, keys in the original's order.
194
360
  */
195
361
  function mergeFields(o, b, e) {
196
362
  return mergeObject(o, b ?? {}, e, (_o, _b, ev) => copy(ev));
package/dist/merge.js CHANGED
@@ -118,13 +118,20 @@ export { MergeRefusedError } from './merge-roundtrip.js';
118
118
  * `layout.nodes` entry, the merged file keeps that entry (it is carried over
119
119
  * with the original's `layout`) and the edited node's compile placeholder `ui`
120
120
  * is dropped, so the node has one position, not two.
121
+ *
122
+ * An original node with NO position (neither) keeps none: the edited node's
123
+ * `ui` is compile's placeholder (`isUnplaced`), an emission-index slot that
124
+ * moves whenever a step is added before the node, not a position the author
125
+ * gave it. Taking it wrote that slot, placeholder mark and all, onto a node the
126
+ * author never placed. A position the author set with `.layout()` is not a
127
+ * placeholder, so it is still taken.
121
128
  */
122
- function withOriginalLayout(edited, orig, originalLayout) {
129
+ function withOriginalLayout(edited, orig, originalLayout, isUnplaced) {
123
130
  if (!orig)
124
131
  return edited;
125
132
  if (orig.ui !== undefined)
126
133
  return { ...edited, ui: jsonClone(orig.ui) };
127
- if (originalLayout?.[orig.id] !== undefined) {
134
+ if (originalLayout?.[orig.id] !== undefined || (edited.ui !== undefined && isUnplaced(edited.ui))) {
128
135
  const { ui: _placeholder, ...rest } = edited;
129
136
  return rest;
130
137
  }
@@ -464,6 +471,9 @@ function mergeFlowFindings(original, edited, options) {
464
471
  const result = jsonClone(original);
465
472
  const origNodes = byId(original.nodes);
466
473
  const baseNodes = byId(options.baseline?.nodes);
474
+ // Which edited nodes sit where compile put them, not where an author did (node-placement.ts).
475
+ const editedNodes = [...(edited.nodes ?? []), ...Object.values(edited.subflows ?? {}).flatMap((sf) => sf?.nodes ?? [])];
476
+ const isUnplaced = unplacedRule(editedNodes);
467
477
  // ── Nodes: the edited graph decides which nodes exist and in what order; the
468
478
  // original decides their look (and, for untouched nodes, their content). ──
469
479
  const finalNodes = [];
@@ -499,7 +509,7 @@ function mergeFlowFindings(original, edited, options) {
499
509
  if (byField)
500
510
  fieldwise.set(e.id, changedFrom(orig, taken));
501
511
  const node = orig && base ? withDisplayEdits(taken, orig, e, base) : taken;
502
- const placed = withOriginalSource(withOriginalLayout(node, orig, layoutNodesOf(original)), orig, base);
512
+ const placed = withOriginalSource(withOriginalLayout(node, orig, layoutNodesOf(original), isUnplaced), orig, base);
503
513
  finalNodes.push(placed);
504
514
  // Without a baseline every node lands here; count one as edited only
505
515
  // when the merged node differs from the original.
@@ -596,8 +606,6 @@ function mergeFlowFindings(original, edited, options) {
596
606
  // room, and store every added node's position where the original stores
597
607
  // positions — see node-placement.ts. Root scope only: a
598
608
  // subflow is taken from `edited` whole, layout included. ──
599
- const editedNodes = [...(edited.nodes ?? []), ...Object.values(edited.subflows ?? {}).flatMap((sf) => sf?.nodes ?? [])];
600
- const isUnplaced = unplacedRule(editedNodes);
601
609
  // ── Layout edits: a `.layout()` entry the author changed (edited differs from
602
610
  // the baseline) is an edit like any other, so it lands on the original's node,
603
611
  // root and every subflow, before added nodes are placed around it (#1994). ──
package/dist/serialize.js CHANGED
@@ -3077,6 +3077,20 @@ function serializeFlow(built, opts, scopeLayout) {
3077
3077
  throw new Error(`internal SDK error: label on "${step.name}": emitted node not found.`);
3078
3078
  node.display = { ...(node.display ?? {}), label };
3079
3079
  };
3080
+ /**
3081
+ * `{ errorHandlingEnabled: true }` (StepOptions.errorHandlingEnabled): the
3082
+ * error handle shown with nothing wired, the flag `.onError(...)` sets with
3083
+ * its edge. Refused like a handler on a node with no error port.
3084
+ */
3085
+ const applyErrorHandle = (step, nodeId) => {
3086
+ if (step.options?.errorHandlingEnabled !== true)
3087
+ return;
3088
+ const node = nodeId ? scope.nodes.find((n) => n.id === nodeId) : undefined;
3089
+ if (!node)
3090
+ throw new Error(`internal SDK error: errorHandlingEnabled on "${step.name}": emitted node not found.`);
3091
+ refuseErrorEdgeWithoutPort(scope, node.id, step.name);
3092
+ node.inputs = { ...(node.inputs ?? {}), errorHandlingEnabled: true };
3093
+ };
3080
3094
  for (const [stepIndex, step] of steps.entries()) {
3081
3095
  // After a node whose exits are all templated, only its port lists may
3082
3096
  // follow: nothing continues from it, so a step here would hang off no edge.
@@ -3092,7 +3106,7 @@ function serializeFlow(built, opts, scopeLayout) {
3092
3106
  if (step.kind !== 'action')
3093
3107
  refuseUnknownStepOptions(scope, step);
3094
3108
  if (step.kind === 'action') {
3095
- tails = emitStep(step, tails, scope, parentId, () => { applyUpdates(step); applyLabel(step); });
3109
+ tails = emitStep(step, tails, scope, parentId, () => { applyUpdates(step); applyLabel(step); applyErrorHandle(step, scope.stepNodeId.get(step.name)); });
3096
3110
  refuseUnknownStepOptions(scope, step);
3097
3111
  lastAction = step.name;
3098
3112
  // A fan-out human task's `action: 'End'` outcomes end the run here: the
@@ -3419,6 +3433,7 @@ function serializeFlow(built, opts, scopeLayout) {
3419
3433
  ...(v24 || 'breakEnabled' in declared ? { breakEnabled: (o.breakEnabled ?? false) || usesBreak } : {}),
3420
3434
  };
3421
3435
  scope.nodes.push(node);
3436
+ applyErrorHandle(step, id);
3422
3437
  for (const t of tails)
3423
3438
  addEdge(scope, t, id);
3424
3439
  const bodyPort = v24 ? 'start' : 'output';
@@ -3440,6 +3455,7 @@ function serializeFlow(built, opts, scopeLayout) {
3440
3455
  breakEnabled: (o.breakEnabled ?? false) || usesBreak,
3441
3456
  };
3442
3457
  scope.nodes.push(node);
3458
+ applyErrorHandle(step, id);
3443
3459
  for (const t of tails)
3444
3460
  addEdge(scope, t, id);
3445
3461
  const bodyTails = emit(step.body, [{ node: id, port: 'start' }], scope, id, { node: id, break: 'break', continue: 'continue' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.124.1",
3
+ "version": "6.124.3",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -127,5 +127,5 @@
127
127
  "@types/node": "^22.7.0",
128
128
  "esbuild": "^0.28.1"
129
129
  },
130
- "gitref": "b369805f68a4f9c8dc72651bf7c53bb2a466d373"
130
+ "gitref": "5d3f82361ea40fb54a8397cac501a1e667934a78"
131
131
  }