@uipath/maestro-builder-sdk 6.120.2 → 6.120.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.
@@ -5,6 +5,17 @@ export interface PreservedConnectorRowSet {
5
5
  /** The element was saved with no such field at all. */
6
6
  absent?: true;
7
7
  }
8
+ /** How one saved extract row differs from the row compile writes for it. */
9
+ export interface PreservedExtractShape {
10
+ /** The `source` the row reads (`=response.CreatedBy.Id`). */
11
+ source: string;
12
+ /** The variable the row writes. */
13
+ var: string;
14
+ /** Saved fields compile does not write (`displayName`), verbatim. */
15
+ fields?: Record<string, unknown>;
16
+ /** The row was saved with no `target`. */
17
+ omit?: ['target'];
18
+ }
8
19
  /** One saved connector element's own rows, as `preserveCaseJson` carries them. */
9
20
  export interface PreservedConnectorRows {
10
21
  /** `trigger:<node id>`, `task:<task id>` or `rule:<stage id>:<rule id>`. */
@@ -13,6 +24,8 @@ export interface PreservedConnectorRows {
13
24
  operation: Record<string, string>;
14
25
  inputs?: PreservedConnectorRowSet;
15
26
  outputs?: PreservedConnectorRowSet;
27
+ /** The Designer's spelling of the author's extract rows. */
28
+ extracts?: PreservedExtractShape[];
16
29
  }
17
30
  /**
18
31
  * Every connector element and the bag that holds its rows: event triggers,
@@ -44,6 +44,15 @@
44
44
  *
45
45
  * An element whose rows are what compile writes anyway (an SDK-authored
46
46
  * plan's) records nothing for that half, so its source carries no copy.
47
+ *
48
+ * The author's extracts (`.outputs({ createdById: '=response.CreatedBy.Id' })`)
49
+ * are compile's to write, but the Designer saves them with a field compile
50
+ * does not write (`displayName: 'CreatedBy.Id'`) and without one it does
51
+ * (`target`). `extracts` records that difference per extract, keyed by the
52
+ * `source` it reads and the `var` it writes, and compile puts it back on the
53
+ * row that still reads that source into that variable, while the element calls
54
+ * the same operation. An extract the author edits (another source or
55
+ * variable) gets compile's row.
47
56
  */
48
57
  import { caseSubscriptionOwners } from './subscription.js';
49
58
  const CONNECTOR_ACTIVITY_TYPE = 'execute-connector-activity';
@@ -196,9 +205,60 @@ export function savedConnectorRows(owner, bag) {
196
205
  const activity = bag.serviceType !== 'Intsvc.EventTrigger' && bag.serviceType !== 'Intsvc.WaitForEvent';
197
206
  const outputs = savedOutputs(bag);
198
207
  const inputs = savedInputs(bag, activity);
199
- if (!outputs && !inputs)
208
+ const extracts = savedExtracts(bag);
209
+ if (!outputs && !inputs && !extracts)
200
210
  return undefined;
201
- return { owner, operation, ...(inputs ? { inputs } : {}), ...(outputs ? { outputs } : {}) };
211
+ return { owner, operation, ...(inputs ? { inputs } : {}), ...(outputs ? { outputs } : {}), ...(extracts ? { extracts } : {}) };
212
+ }
213
+ /** The fields compile writes on an extract row (`emitTaskOutput`). */
214
+ const EXTRACT_WRITTEN_FIELDS = new Set(['name', 'type', 'id', 'var', 'originalVar', 'value', 'source', 'target', 'elementId', 'custom']);
215
+ /**
216
+ * Whether `row` is an author's extract: a field of the response or the error
217
+ * (`=response.CreatedBy.Id`, `=Error.message`) read into a variable. Not an own
218
+ * row (`=response`, or `=response2` once a plan-wide suffix renamed it) and not
219
+ * a `{ assign }`.
220
+ */
221
+ function isExtract(row) {
222
+ return isObject(row) && row.custom !== true && typeof row.source === 'string' && /^=(?:response|Error)[.[]/.test(row.source) && typeof row.var === 'string';
223
+ }
224
+ const extractKey = (row) => `${row.source}\u0000${row.var}`;
225
+ /**
226
+ * Each saved extract's difference from the row compile writes: the fields it
227
+ * has that compile does not write, and a `target` it lacks. An extract that
228
+ * reads the same source into the same variable as another is left to compile:
229
+ * no one row would get the shape.
230
+ */
231
+ function savedExtracts(bag) {
232
+ const rows = (Array.isArray(bag.outputs) ? bag.outputs : []).filter(isExtract);
233
+ const count = new Map();
234
+ for (const row of rows)
235
+ count.set(extractKey(row), (count.get(extractKey(row)) ?? 0) + 1);
236
+ const out = [];
237
+ for (const row of rows) {
238
+ if (count.get(extractKey(row)) !== 1)
239
+ continue;
240
+ const fields = Object.fromEntries(Object.entries(row).filter(([key]) => !EXTRACT_WRITTEN_FIELDS.has(key)).map(([key, value]) => [key, structuredClone(value)]));
241
+ const omit = row.target === undefined;
242
+ if (!Object.keys(fields).length && !omit)
243
+ continue;
244
+ out.push({ source: row.source, var: row.var, ...(Object.keys(fields).length ? { fields } : {}), ...(omit ? { omit: ['target'] } : {}) });
245
+ }
246
+ return out.length ? out : undefined;
247
+ }
248
+ /** Put each saved extract's shape back on the one compiled extract that reads its source into its variable. */
249
+ function extractsBack(bag, shapes) {
250
+ const rows = (Array.isArray(bag.outputs) ? bag.outputs : []).filter(isExtract);
251
+ for (const shape of shapes) {
252
+ const holders = rows.filter((row) => row.source === shape.source && row.var === shape.var);
253
+ if (holders.length !== 1)
254
+ continue;
255
+ const [row] = holders;
256
+ for (const [key, value] of Object.entries(shape.fields ?? {}))
257
+ if (!Object.prototype.hasOwnProperty.call(row, key))
258
+ row[key] = structuredClone(value);
259
+ if (shape.omit?.includes('target'))
260
+ delete row.target;
261
+ }
202
262
  }
203
263
  /** Whether the element compile built calls the operation the rows were saved for. */
204
264
  function sameOperation(bag, entry) {
@@ -262,6 +322,8 @@ export function applyConnectorRows(result, entries) {
262
322
  const entry = byOwner.get(key);
263
323
  if (!entry || !sameOperation(bag, entry))
264
324
  continue;
325
+ if (entry.extracts)
326
+ extractsBack(bag, entry.extracts);
265
327
  for (const field of ['inputs', 'outputs']) {
266
328
  const set = entry[field];
267
329
  if (!set)
@@ -291,7 +353,7 @@ export function connectorRowErrors(entries) {
291
353
  continue;
292
354
  }
293
355
  for (const field of Object.keys(entry))
294
- if (!['owner', 'operation', 'inputs', 'outputs'].includes(field))
356
+ if (!['owner', 'operation', 'inputs', 'outputs', 'extracts'].includes(field))
295
357
  errors.push(`preserved connector rows "${owner}" field "${field}" is not allowed in the preservation channel`);
296
358
  const { operation, inputs, outputs } = entry;
297
359
  if (!isObject(operation) || typeof operation.connectorKey !== 'string' || !Object.values(operation).every((value) => typeof value === 'string'))
@@ -313,6 +375,17 @@ export function connectorRowErrors(entries) {
313
375
  };
314
376
  half(inputs, 'inputs', isInputRow, (row) => row.name);
315
377
  half(outputs, 'outputs', isOwnOutput, (row) => row.source);
378
+ const { extracts } = entry;
379
+ if (extracts !== undefined) {
380
+ const shapeOk = (shape) => isObject(shape) && typeof shape.source === 'string' && /^=(?:response|Error)[.[]/.test(shape.source)
381
+ && typeof shape.var === 'string' && Object.keys(shape).every((key) => ['source', 'var', 'fields', 'omit'].includes(key))
382
+ && (shape.fields === undefined || (isObject(shape.fields) && Object.keys(shape.fields).every((key) => !EXTRACT_WRITTEN_FIELDS.has(key))))
383
+ && (shape.omit === undefined || (Array.isArray(shape.omit) && shape.omit.length === 1 && shape.omit[0] === 'target'));
384
+ if (!Array.isArray(extracts) || !extracts.every(shapeOk))
385
+ errors.push(`preserved connector rows "${owner}" extracts must each name a source and a var, with only fields compile does not write and omit ["target"]`);
386
+ else if (new Set(extracts.map(extractKey)).size !== extracts.length)
387
+ errors.push(`preserved connector rows "${owner}" extracts name a source and var twice`);
388
+ }
316
389
  }
317
390
  return errors;
318
391
  }
@@ -1356,6 +1356,15 @@ function applyPreservedIdentities(result, preservation, warn) {
1356
1356
  for (const row of planOutputRows(result, stages))
1357
1357
  if (typeof row?.id === 'string')
1358
1358
  heldOutputIds.add(row.id);
1359
+ // A wait-for-connector rule's own output rows (`ruleOutputRows`), and the
1360
+ // carried ids they have taken. The one place two rows may share an output id:
1361
+ // the Designer copies a rule with its rows (`response2` on both copies, each
1362
+ // writing `response2`), and `case validate` checks only task outputs for a
1363
+ // repeat (CASE_MGMT_OUTPUT_ID_DUPLICATE), so the plan is valid as saved.
1364
+ // Giving the copy a fresh id would point it at another variable. A rule row
1365
+ // that carries an id another rule row took takes it too; a task row never does.
1366
+ const ruleRows = new WeakSet(planRuleOutputRows(result, stages));
1367
+ const ruleRowIds = new Set();
1359
1368
  // A resource task row's carried Designer fields (`fields`) and the `target`
1360
1369
  // it was saved without (`omit`), put back on the row of the same name after
1361
1370
  // the id renames. Example: `{ name: 'echoIn', fields: { displayName: 'echoIn',
@@ -1441,7 +1450,8 @@ function applyPreservedIdentities(result, preservation, warn) {
1441
1450
  heldOutputIds.add(row.id);
1442
1451
  return true;
1443
1452
  }
1444
- if (target && typeof row.id === 'string' && row.id !== currentId && heldOutputIds.has(row.id))
1453
+ const ruleRow = !!target && ruleRows.has(target);
1454
+ if (target && typeof row.id === 'string' && row.id !== currentId && heldOutputIds.has(row.id) && !(ruleRow && ruleRowIds.has(row.id)))
1445
1455
  return false;
1446
1456
  // A reassigned row (slot id, `originalVar` the slot) whose carried id IS
1447
1457
  // its variable was saved in the own-name shape; see `ownNameRestored`.
@@ -1470,6 +1480,8 @@ function applyPreservedIdentities(result, preservation, warn) {
1470
1480
  heldOutputIds.delete(currentId);
1471
1481
  heldOutputIds.add(row.id);
1472
1482
  }
1483
+ if (ruleRow && typeof row.id === 'string' && target.id === row.id)
1484
+ ruleRowIds.add(row.id);
1473
1485
  return true;
1474
1486
  };
1475
1487
  // Rows whose carried id another row held when they were reached. Example: a
@@ -2811,6 +2823,17 @@ function ruleOutputRows(conditions) {
2811
2823
  return (conditions ?? []).flatMap((condition) => (condition?.rules ?? []).flat().flatMap((rule) => rule?.[bag]?.outputs ?? []));
2812
2824
  }
2813
2825
  /** Every output row in the plan: stage and task rule rows, task rows, and case-exit rule rows. */
2826
+ /** Every wait-for-connector rule's own output row in the plan: stage and task conditions, and the case exit rules. */
2827
+ function planRuleOutputRows(result, stages) {
2828
+ return [
2829
+ ...stages.flatMap((stage) => [
2830
+ ...ruleOutputRows(stage.data?.entryConditions),
2831
+ ...ruleOutputRows(stage.data?.exitConditions),
2832
+ ...(stage.data?.tasks ?? []).flat().flatMap((task) => ruleOutputRows(task?.entryConditions)),
2833
+ ]),
2834
+ ...ruleOutputRows(result.metadata?.caseExitRules),
2835
+ ].filter((row) => row && typeof row === 'object');
2836
+ }
2814
2837
  function planOutputRows(result, stages) {
2815
2838
  return [
2816
2839
  ...stages.flatMap((stage) => [
@@ -2849,7 +2872,10 @@ const OWN_NAME_OUTPUT_ROWS = new WeakSet();
2849
2872
  * - **own name** — the output keeps its field's name (the `var` is the source's
2850
2873
  * last segment, or the Designer's camelCase of it, either one optionally
2851
2874
  * with a numeric suffix: `=APIOutput1` into `APIOutput1`, `aPIOutput1` or
2852
- * `aPIOutput12`, and `=response.app_id` into `app_id`; see `keepsOwnName`).
2875
+ * `aPIOutput12`, and `=response.app_id` into `app_id`; for a nested
2876
+ * response field the camelCase of its whole path, `=response.CreatedBy.Id`
2877
+ * into `createdById`; see `keepsOwnSourceName`). The row's `name` is the
2878
+ * field's path under `response`, else its last segment (`outputRowName`).
2853
2879
  * The row's `id` IS the `var`, with no `originalVar`:
2854
2880
  * `{ id: 'APIOutput1', var: 'APIOutput1', target: '=APIOutput1' }`. This is
2855
2881
  * the task-scoped output: it writes no case variable, and a later task reads
@@ -2867,8 +2893,7 @@ const OWN_NAME_OUTPUT_ROWS = new WeakSet();
2867
2893
  function emitTaskOutput(o, elementId, ids, seed, resolver) {
2868
2894
  if (o.custom)
2869
2895
  return emitCustomOutput(o, resolver);
2870
- const path = o.source.replace(/^=/, '');
2871
- const field = path.split('.').pop() || o.source;
2896
+ const field = outputRowName(o.source);
2872
2897
  // A reassigned row registers the readable companion once (declared vars take
2873
2898
  // precedence in the merge); an own-name row is the variable and registers none.
2874
2899
  const companion = () => {
@@ -3544,8 +3569,7 @@ function isCarriedNestedReassignment(row, carriedId) {
3544
3569
  return false;
3545
3570
  if (carriedId === row.id || typeof row.source !== 'string')
3546
3571
  return false;
3547
- const path = row.source.replace(/^=/, '');
3548
- return path.includes('.') && keepsOwnName(row.var, path.split('.').pop() ?? '');
3572
+ return row.source.replace(/^=/, '').includes('.') && keepsOwnSourceName(row.var, row.source);
3549
3573
  }
3550
3574
  /** Whether a task output is written in the own-name shape (see `emitTaskOutput`). */
3551
3575
  function isOwnNameOutput(o) {
@@ -3557,8 +3581,43 @@ function isOwnNameOutput(o) {
3557
3581
  // that bare row (`outputFor`: `{ id: 'app_id', var: 'app_id', source:
3558
3582
  // '=response.app_id' }`), so it stays on the task with no root companion
3559
3583
  // (builder-sdk#1241).
3560
- const field = o.source.replace(/^=/, '').split('.').pop() ?? '';
3561
- return keepsOwnName(o.var, field);
3584
+ return keepsOwnSourceName(o.var, o.source);
3585
+ }
3586
+ /**
3587
+ * The `name` of the row that reads `source`: a connector result field's path
3588
+ * under `response` (`=response.CreatedBy.Id` is `CreatedBy.Id`), else the
3589
+ * path's last segment (`=Decision.output` is `output`, `=APIOutput1` is
3590
+ * `APIOutput1`).
3591
+ *
3592
+ * The Case Designer names a connector task's extract after the field's path
3593
+ * in the response, so one task that reads `CreatedBy.Id`, `Id` and
3594
+ * `UpdatedBy.Id` has three rows with three names. The last segment would name
3595
+ * all three `Id`.
3596
+ */
3597
+ function outputRowName(source) {
3598
+ const path = source.replace(/^=/, '');
3599
+ if (path.startsWith('response.') && path.length > 'response.'.length)
3600
+ return path.slice('response.'.length);
3601
+ return path.split('.').pop() || source;
3602
+ }
3603
+ /**
3604
+ * Whether variable `name` is the own name of the field `source` reads: the
3605
+ * path's last segment (`keepsOwnName`, `=response.app_id` into `app_id`), or,
3606
+ * for a nested connector result field, the Designer's camelCase of its whole
3607
+ * path under `response`, with its optional counter: `=response.CreatedBy.Id`
3608
+ * into `createdById` or `createdById4`.
3609
+ */
3610
+ function keepsOwnSourceName(name, source) {
3611
+ const path = source.replace(/^=/, '');
3612
+ if (keepsOwnName(name, path.split('.').pop() ?? ''))
3613
+ return true;
3614
+ if (!path.startsWith('response.'))
3615
+ return false;
3616
+ const segments = path.slice('response.'.length).split('.');
3617
+ if (segments.length < 2 || !segments.every((segment) => /^[A-Za-z_]\w*$/.test(segment)))
3618
+ return false;
3619
+ const base = camelizeName(segments.join(''));
3620
+ return name === base || (name.startsWith(base) && /^(?:[2-9]|[1-9]\d+)$/.test(name.slice(base.length)));
3562
3621
  }
3563
3622
  /** The ids of the carried document-extraction tasks' saved output rows. */
3564
3623
  function savedOutputIds(entries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.120.2",
3
+ "version": "6.120.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",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "53cda99a37bbc03af9ea7b89bc2a0c60d231ac28"
127
+ "gitref": "9f740b0bf276c4e815615529144164b9af6f1f08"
128
128
  }