@uipath/maestro-builder-sdk 6.120.5 → 6.120.6

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.
@@ -33,17 +33,24 @@ export interface PreservedConnectorRows {
33
33
  * `execute-connector-activity` task. A task is keyed by its own id, not its
34
34
  * stage's: a task moved to another stage keeps its element ids, and its rows
35
35
  * with them.
36
+ *
37
+ * `elementIds` are the spellings of the element's own id a row may carry:
38
+ * the one compile writes (the trigger's node id, else `<stage id>-<task or
39
+ * rule id>`), and an older SDK's bare task or rule id, which compile repairs
40
+ * (#1426).
36
41
  */
37
42
  export declare function caseConnectorRowOwners(plan: Record<string, any>): Array<{
38
43
  key: string;
39
44
  bag: Record<string, any>;
45
+ elementIds: string[];
40
46
  }>;
41
47
  /**
42
48
  * The saved own rows of a connector element, for each half compile would not
43
- * write as it is: a row in another shape, a row missing, or no such field.
44
- * Else `undefined`.
49
+ * write as it is: a row in another shape, a row missing, a row that names
50
+ * another element (not one of `elementIds`, its own id's spellings), or no such
51
+ * field. Else `undefined`.
45
52
  */
46
- export declare function savedConnectorRows(owner: string, bag: Record<string, any>): PreservedConnectorRows | undefined;
53
+ export declare function savedConnectorRows(owner: string, bag: Record<string, any>, elementIds?: readonly string[]): PreservedConnectorRows | undefined;
47
54
  /**
48
55
  * Write each element's saved own rows back over the ones compile built, half
49
56
  * by half, while they still describe the element. Runs after the ids are
@@ -69,17 +69,28 @@ const isObject = (value) => !!value && typeof value === 'object' && !Array.isArr
69
69
  * `execute-connector-activity` task. A task is keyed by its own id, not its
70
70
  * stage's: a task moved to another stage keeps its element ids, and its rows
71
71
  * with them.
72
+ *
73
+ * `elementIds` are the spellings of the element's own id a row may carry:
74
+ * the one compile writes (the trigger's node id, else `<stage id>-<task or
75
+ * rule id>`), and an older SDK's bare task or rule id, which compile repairs
76
+ * (#1426).
72
77
  */
73
78
  export function caseConnectorRowOwners(plan) {
74
- const out = caseSubscriptionOwners(plan)
75
- .map(({ key, bag }) => ({ key: key.startsWith('task:') ? `task:${key.split(':').slice(2).join(':')}` : key, bag }));
79
+ const out = caseSubscriptionOwners(plan).map(({ key, bag }) => {
80
+ const [kind, ...rest] = key.split(':');
81
+ if (kind === 'trigger')
82
+ return { key, bag, elementIds: [rest.join(':')] };
83
+ const [stageId, ...own] = rest;
84
+ const ownId = own.join(':');
85
+ return { key: kind === 'task' ? `task:${ownId}` : key, bag, elementIds: [`${stageId}-${ownId}`, ownId] };
86
+ });
76
87
  for (const node of Array.isArray(plan?.nodes) ? plan.nodes : []) {
77
88
  if (!String(node?.type ?? '').endsWith('Stage'))
78
89
  continue;
79
90
  for (const lane of Array.isArray(node.data?.tasks) ? node.data.tasks : [])
80
91
  for (const task of Array.isArray(lane) ? lane : [])
81
92
  if (task?.type === CONNECTOR_ACTIVITY_TYPE && isObject(task.data))
82
- out.push({ key: `task:${task.id}`, bag: task.data });
93
+ out.push({ key: `task:${task.id}`, bag: task.data, elementIds: [`${node.id}-${task.id}`, String(task.id)] });
83
94
  }
84
95
  return out;
85
96
  }
@@ -140,8 +151,10 @@ function sdkSchema(schema) {
140
151
  };
141
152
  return node(schema);
142
153
  }
143
- /** Whether compile could have written output `row` as it is (`connectorOutputs`). */
144
- function sdkShapedOutput(row) {
154
+ /** Whether a row's `elementId` names its own element (`elementIds`), when those are known. */
155
+ const ownElement = (row, elementIds) => typeof row.elementId === 'string' && (elementIds === undefined || elementIds.includes(row.elementId));
156
+ /** Whether compile could have written output `row` as it is (`connectorOutputs`) on its element (`elementIds`). */
157
+ function sdkShapedOutput(row, elementIds) {
145
158
  if (!Object.keys(row).every((key) => SDK_OUTPUT_FIELDS.has(key)))
146
159
  return false;
147
160
  const error = row.source === '=Error';
@@ -149,22 +162,27 @@ function sdkShapedOutput(row) {
149
162
  return false;
150
163
  if (typeof row.var !== 'string' || row.id !== row.var || row.value !== row.var || row.target !== `=${row.var}`)
151
164
  return false;
152
- if (typeof row.elementId !== 'string')
165
+ if (!ownElement(row, elementIds))
153
166
  return false;
154
167
  return error ? stable(row.body) === ERROR_SCHEMA : sdkSchema(row.body);
155
168
  }
156
- /** Whether compile could have written input `row` as it is (`ioSlot`, `fileSlot`, `eventInput`). */
157
- function sdkShapedInput(row) {
169
+ /**
170
+ * Whether compile could have written input `row` as it is (`ioSlot`, `fileSlot`,
171
+ * `eventInput`) on its element (`elementIds`). A row whose `elementId` names another
172
+ * element is the Designer's: a copied rule keeps the rows of the rule it was
173
+ * copied from, `elementId` and all, and compile would point them at the copy.
174
+ */
175
+ function sdkShapedInput(row, elementIds) {
158
176
  if (!Object.keys(row).every((key) => SDK_INPUT_FIELDS.has(key)))
159
177
  return false;
160
- if (typeof row.var !== 'string' || row.id !== row.var || typeof row.elementId !== 'string')
178
+ if (typeof row.var !== 'string' || row.id !== row.var || !ownElement(row, elementIds))
161
179
  return false;
162
180
  if (row.type === 'file')
163
181
  return row.target === 'file' && row.body === undefined;
164
182
  return row.type === 'json' && row.target === row.name && (row.body !== undefined) !== (row.value !== undefined);
165
183
  }
166
184
  /** The saved outputs half, when compile would not write it as it is. */
167
- function savedOutputs(bag) {
185
+ function savedOutputs(bag, elementIds) {
168
186
  if (bag.outputs !== undefined && !Array.isArray(bag.outputs))
169
187
  return undefined;
170
188
  const rows = (bag.outputs ?? []).filter(isOwnOutput);
@@ -174,12 +192,12 @@ function savedOutputs(bag) {
174
192
  if (sources.size !== rows.length)
175
193
  return undefined;
176
194
  const complete = rows.length === 2 && sources.size === 2;
177
- if (bag.outputs !== undefined && complete && rows.every(sdkShapedOutput))
195
+ if (bag.outputs !== undefined && complete && rows.every((row) => sdkShapedOutput(row, elementIds)))
178
196
  return undefined;
179
197
  return { rows: structuredClone(rows), ...(bag.outputs === undefined ? { absent: true } : {}) };
180
198
  }
181
199
  /** The saved inputs half, when compile would not write it as it is. */
182
- function savedInputs(bag, activity) {
200
+ function savedInputs(bag, activity, elementIds) {
183
201
  if (bag.inputs !== undefined && !Array.isArray(bag.inputs))
184
202
  return undefined;
185
203
  const rows = bag.inputs ?? [];
@@ -190,22 +208,23 @@ function savedInputs(bag, activity) {
190
208
  if (names.size !== rows.length)
191
209
  return undefined;
192
210
  const complete = activity ? ACTIVITY_CONTAINERS.every((name) => names.has(name)) : rows.length === 1;
193
- if (bag.inputs !== undefined && complete && rows.every(sdkShapedInput))
211
+ if (bag.inputs !== undefined && complete && rows.every((row) => sdkShapedInput(row, elementIds)))
194
212
  return undefined;
195
213
  return { rows: structuredClone(rows), ...(bag.inputs === undefined ? { absent: true } : {}) };
196
214
  }
197
215
  /**
198
216
  * The saved own rows of a connector element, for each half compile would not
199
- * write as it is: a row in another shape, a row missing, or no such field.
200
- * Else `undefined`.
217
+ * write as it is: a row in another shape, a row missing, a row that names
218
+ * another element (not one of `elementIds`, its own id's spellings), or no such
219
+ * field. Else `undefined`.
201
220
  */
202
- export function savedConnectorRows(owner, bag) {
221
+ export function savedConnectorRows(owner, bag, elementIds) {
203
222
  const operation = operationOf(bag);
204
223
  if (operation.connectorKey === undefined)
205
224
  return undefined;
206
225
  const activity = bag.serviceType !== 'Intsvc.EventTrigger' && bag.serviceType !== 'Intsvc.WaitForEvent';
207
- const outputs = savedOutputs(bag);
208
- const inputs = savedInputs(bag, activity);
226
+ const outputs = savedOutputs(bag, elementIds);
227
+ const inputs = savedInputs(bag, activity, elementIds);
209
228
  const extracts = savedExtracts(bag);
210
229
  if (!outputs && !inputs && !extracts)
211
230
  return undefined;
@@ -1057,6 +1057,14 @@ function connectorInputs(slots, resolved, owner, task) {
1057
1057
  if (!body || typeof body !== 'object' || Array.isArray(body)) {
1058
1058
  if (owner)
1059
1059
  throw new Error(`${owner} input container "${name}" must carry an object body.`);
1060
+ // A container saved as one value, not fields: a whole-body expression,
1061
+ // `{ name: 'body', body: '=js:({ "id": vars.x })' }`. The SDK names a
1062
+ // connector's inputs field by field, so it has nowhere to put it, and
1063
+ // compile would write the container empty: refuse, never drop.
1064
+ if (hasAuthoredValue(body))
1065
+ throw new Error(`${who} input container "${name}" is saved as one ${typeof body === 'string' ? 'expression' : 'value'}, ` +
1066
+ `not as fields; the SDK sets a connector's inputs field by field, so decompile cannot lift it and the value would be lost. ` +
1067
+ 'In Studio Web, set the fields one by one instead of the whole container, then decompile the saved plan.');
1060
1068
  continue;
1061
1069
  }
1062
1070
  for (const [wireName, value] of Object.entries(body)) {
@@ -3032,7 +3040,7 @@ export function collectPreservation(plan) {
3032
3040
  if (connectorConfigV2.length)
3033
3041
  preservation.connectorConfigV2 = connectorConfigV2;
3034
3042
  const connectorRows = caseConnectorRowOwners(plan)
3035
- .map(({ key, bag }) => savedConnectorRows(key, bag))
3043
+ .map(({ key, bag, elementIds }) => savedConnectorRows(key, bag, elementIds))
3036
3044
  .filter((entry) => entry !== undefined);
3037
3045
  if (connectorRows.length)
3038
3046
  preservation.connectorRows = connectorRows;
@@ -186,8 +186,7 @@ function collected(resolver, where, nodeId, emit, standIn) {
186
186
  /** The root companions a stand-in's authored outputs need, the way an emitted node registers them. */
187
187
  function standInCompanions(resolver, outputs) {
188
188
  for (const o of outputs ?? [])
189
- if (!resolver.varCompanions.has(o.var))
190
- resolver.varCompanions.set(o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
189
+ addVarCompanion(resolver, o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
191
190
  }
192
191
  /**
193
192
  * The value an author wrote, as plain JSON, for a stand-in. Deterministic, so
@@ -222,6 +221,7 @@ function serializeCase(built, opts) {
222
221
  offlineBindingIds: new Map(),
223
222
  varCompanions: new Map(),
224
223
  ownNameRows: new Map(),
224
+ firstWriters: new Map(),
225
225
  // A carried task's saved output rows keep their ids: no other row takes one.
226
226
  outputIds: new Set(savedOutputIds(caseJsonPreservation(built)?.documentExtractionData)),
227
227
  savedDocumentExtractions: pairSavedDocumentExtractions(carriedDocumentExtractionTasks(built), caseJsonPreservation(built)?.documentExtractionData),
@@ -392,8 +392,8 @@ function serializeCase(built, opts) {
392
392
  const variables = emitVariables(built.vars, ids, triggerNodeByRef, triggerNodes, built.triggers, resolver.collect);
393
393
  const inputOutputs = variables.inputOutputs;
394
394
  const declared = new Set(inputOutputs.map((e) => e.id));
395
- for (const [name, companion] of resolver.varCompanions)
396
- if (!declared.has(name))
395
+ for (const companion of orderedCompanions(resolver))
396
+ if (!declared.has(companion.id))
397
397
  inputOutputs.push(companion);
398
398
  // An own-name row that writes a variable which DOES have a root entry (a
399
399
  // declared `.var()`, or a companion another, reassigned, writer needed) is the
@@ -1952,6 +1952,7 @@ function applyPreservedIdentities(result, preservation, warn) {
1952
1952
  held.add(row.id);
1953
1953
  }
1954
1954
  }
1955
+ dropOwnVariableCompanions(result, stages, nodes, identities);
1955
1956
  }
1956
1957
  // An id hashed from a generated element id is re-minted from the preserved one,
1957
1958
  // wherever it is spelled, including inside a `=jsonString:` configuration.
@@ -2316,8 +2317,7 @@ function emitTrigger(t, i, triggerId, resolver) {
2316
2317
  if (t.eventOutputs?.length) {
2317
2318
  const outputs = t.eventOutputs.map((o) => {
2318
2319
  const field = o.source.replace(/^=/, '').split('.').pop() || o.source;
2319
- if (!resolver.varCompanions.has(o.var))
2320
- resolver.varCompanions.set(o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
2320
+ addVarCompanion(resolver, o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
2321
2321
  return { name: field, var: o.var, source: o.source, type: o.type, value: o.var };
2322
2322
  });
2323
2323
  bag.outputs = [...(bag.outputs ?? []), ...outputs];
@@ -2835,15 +2835,8 @@ function emitActionField(f, outputElementId, resolver) {
2835
2835
  // for it). Only a suffixed, reassigned row needs the readable companion.
2836
2836
  if (resolver && id === variable)
2837
2837
  addOwnNameRow(resolver, variable, row);
2838
- else if (resolver && !resolver.varCompanions.has(variable)) {
2839
- resolver.varCompanions.set(variable, {
2840
- id: variable,
2841
- name: variable,
2842
- type: f.type ?? 'string',
2843
- elementId: 'root',
2844
- custom: true,
2845
- });
2846
- }
2838
+ else if (resolver)
2839
+ addVarCompanion(resolver, variable, { id: variable, name: variable, type: f.type ?? 'string', elementId: 'root', custom: true });
2847
2840
  }
2848
2841
  if (f.required !== undefined)
2849
2842
  row.required = f.required;
@@ -2999,6 +2992,41 @@ function settleOwnNameRows(result, stages, restored, identities) {
2999
2992
  if (variables.inputOutputs)
3000
2993
  variables.inputOutputs = variables.inputOutputs.filter((entry) => !(names.has(entry?.id) && entry.custom === true && entry.elementId === 'root'));
3001
2994
  }
2995
+ /**
2996
+ * A custom (`{ assign }`) row Studio Web saved as its task's own output, with
2997
+ * an id that is its variable and the task's `elementId` (`{ custom: true, id:
2998
+ * 'region', var: 'region', elementId: '<stageId>-<taskId>' }`), declares that
2999
+ * variable itself: the platform reads every row on the task's `elementId` that
3000
+ * has an id as a task output variable. Compile writes a root companion for
3001
+ * every `{ assign }` row (`emitCustomOutput`), so such a row would come back
3002
+ * with a second, root declaration the plan never had. Once the saved shapes are
3003
+ * back, a companion is dropped when its variable has no root row in the source
3004
+ * (`identities.variables`) and every row that writes it is such an own row; a
3005
+ * row that writes it any other way (an edit can add one) keeps it.
3006
+ */
3007
+ function dropOwnVariableCompanions(result, stages, nodes, identities) {
3008
+ const variables = result.variables;
3009
+ if (!variables?.inputOutputs?.length)
3010
+ return;
3011
+ const declared = new Set(Object.values(identities.variables ?? {}).flatMap((rows) => (rows ?? []).map((row) => row.name)));
3012
+ const own = new Set();
3013
+ for (const stage of stages)
3014
+ for (const task of (stage.data?.tasks ?? []).flat())
3015
+ for (const row of task?.data?.outputs ?? [])
3016
+ if (row?.custom === true && typeof row.var === 'string' && row.id === row.var
3017
+ && typeof task.elementId === 'string' && row.elementId === task.elementId && row.elementId !== 'root')
3018
+ own.add(row.var);
3019
+ if (!own.size)
3020
+ return;
3021
+ const ownRow = (row) => row?.custom === true && row.id === row.var && row.elementId !== 'root';
3022
+ for (const row of [...planOutputRows(result, stages), ...triggerOutputRows(nodes)])
3023
+ if (own.has(row?.var) && !ownRow(row))
3024
+ own.delete(row.var);
3025
+ const gone = new Set([...own].filter((name) => !declared.has(name)));
3026
+ if (!gone.size)
3027
+ return;
3028
+ variables.inputOutputs = variables.inputOutputs.filter((entry) => !(gone.has(entry?.id) && entry.custom === true && entry.elementId === 'root'));
3029
+ }
3002
3030
  /** Every `outputs[]` row the plan's trigger nodes carry. */
3003
3031
  function triggerOutputRows(nodes) {
3004
3032
  return nodes.flatMap((node) => node.type === 'uipath.case.trigger' ? (node.data?.inputs?.outputs ?? [])
@@ -3102,8 +3130,7 @@ function emitTaskOutput(o, elementId, ids, seed, resolver) {
3102
3130
  // A reassigned row registers the readable companion once (declared vars take
3103
3131
  // precedence in the merge); an own-name row is the variable and registers none.
3104
3132
  const companion = () => {
3105
- if (!resolver.varCompanions.has(o.var))
3106
- resolver.varCompanions.set(o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
3133
+ addVarCompanion(resolver, o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
3107
3134
  };
3108
3135
  if (isOwnNameOutput(o)) {
3109
3136
  const id = claimOutputId(resolver, o.var);
@@ -3140,8 +3167,7 @@ function emitTaskOutput(o, elementId, ids, seed, resolver) {
3140
3167
  * Like an extract, it registers the root companion so `=vars.<var>` resolves.
3141
3168
  */
3142
3169
  function emitCustomOutput(o, resolver) {
3143
- if (!resolver.varCompanions.has(o.var))
3144
- resolver.varCompanions.set(o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
3170
+ addVarCompanion(resolver, o.var, { id: o.var, name: o.var, type: o.type, elementId: 'root', custom: true });
3145
3171
  return { name: o.var, type: o.type, custom: true, var: o.var, value: o.source, source: o.source, target: '', body: '', elementId: 'root' };
3146
3172
  }
3147
3173
  // ─── Business-rule task ───────────────────────────────────────────────────────
@@ -3432,8 +3458,7 @@ function scriptTaskData(task, resolver, elementId) {
3432
3458
  */
3433
3459
  function registerMappedCompanions(resolver, mappings) {
3434
3460
  for (const variable of mappings.values())
3435
- if (!resolver.varCompanions.has(variable))
3436
- resolver.varCompanions.set(variable, { id: variable, name: variable, type: 'object', elementId: 'root', custom: true });
3461
+ addVarCompanion(resolver, variable, { id: variable, name: variable, type: 'object', elementId: 'root', custom: true });
3437
3462
  }
3438
3463
  /**
3439
3464
  * An HTTP request task (`case/http-request.ts`): the generic HTTP connector's
@@ -3728,12 +3753,51 @@ function connectorOutputVar(resolver, base) {
3728
3753
  }
3729
3754
  /** Record an own-name row (`id == var`), the variable itself; see the variables merge in `serialize`. */
3730
3755
  function addOwnNameRow(resolver, name, row) {
3756
+ if (!resolver.firstWriters.has(name))
3757
+ resolver.firstWriters.set(name, { own: row });
3731
3758
  const rows = resolver.ownNameRows.get(name);
3732
3759
  if (rows)
3733
3760
  rows.push(row);
3734
3761
  else
3735
3762
  resolver.ownNameRows.set(name, [row]);
3736
3763
  }
3764
+ /**
3765
+ * Register the root companion a reassigned or custom row needs to write
3766
+ * `name` (`=vars.<name>` reads it), once per variable. See `orderedCompanions`
3767
+ * for where and with which type it is written.
3768
+ */
3769
+ function addVarCompanion(resolver, name, companion) {
3770
+ if (!resolver.firstWriters.has(name))
3771
+ resolver.firstWriters.set(name, {});
3772
+ if (!resolver.varCompanions.has(name))
3773
+ resolver.varCompanions.set(name, companion);
3774
+ }
3775
+ /**
3776
+ * The root companions, in the order their variables were first written, each
3777
+ * with its first writer's type when that writer is an own-name row.
3778
+ *
3779
+ * A companion belongs to the variable, and the variable is its first writer.
3780
+ * When an own-name row comes first (`{ id: 'status', var: 'status' }`) and a
3781
+ * later task writes the same variable, only the later row is reassigned and
3782
+ * registers the companion, but the companion still stands where `status` was
3783
+ * first written, typed as that row is. Example: task A saves
3784
+ * `{ id: 'status', var: 'status', type: 'string' }`, then task B's
3785
+ * `.outputs({ status: { source: '=Result', type: 'jsonSchema' } })` writes it
3786
+ * too: the root gets `{ id: 'status', type: 'string', ... }`, ahead of the
3787
+ * companion of any variable first written after task A. This is also how
3788
+ * compile repairs two tasks saved with one output id (validate's
3789
+ * CASE_MGMT_OUTPUT_ID_DUPLICATE): the first keeps the id and is the variable.
3790
+ */
3791
+ function orderedCompanions(resolver) {
3792
+ const order = [...resolver.firstWriters.keys()];
3793
+ const at = new Map(order.map((name, index) => [name, index]));
3794
+ return [...resolver.varCompanions]
3795
+ .sort(([a], [b]) => (at.get(a) ?? order.length) - (at.get(b) ?? order.length))
3796
+ .map(([name, companion]) => {
3797
+ const own = resolver.firstWriters.get(name)?.own;
3798
+ return own && typeof own.type === 'string' && own.type !== companion.type ? { ...companion, type: own.type } : companion;
3799
+ });
3800
+ }
3737
3801
  /**
3738
3802
  * Claim a task-output row id from the document-wide pool, the Designer's
3739
3803
  * uniqueness rule: the first claimant of `base` gets `base`, later ones get
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.120.5",
3
+ "version": "6.120.6",
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",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "100acc44efeb5f552ad50a399162c41d714be9ea"
127
+ "gitref": "596cf9e55591a9453fb651e8857bfc83b15e67b9"
128
128
  }