@uipath/maestro-builder-sdk 6.102.0 → 6.103.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.
@@ -0,0 +1,135 @@
1
+ import { Refusal } from "../errors.js";
2
+ import { dfChoiceSetValues, dfEntityGet } from "../uip/commands.js";
3
+ import { failureReason, getCI, isSuccess, parseEnvelope } from "../uip/envelope.js";
4
+ /** The all-zero folder id Data Fabric gives everything at tenant level. */
5
+ const TENANT_FOLDER_ID = "00000000-0000-0000-0000-000000000000";
6
+ /** Choice-set values read a page at a time; a set longer than this many pages is left unread. */
7
+ const CHOICE_PAGE_SIZE = 500;
8
+ const CHOICE_MAX_PAGES = 10;
9
+ function text(value) {
10
+ return typeof value === "string" && value !== "" ? value : undefined;
11
+ }
12
+ /** A folder id worth passing on: not absent, and not the tenant's all-zero one. */
13
+ function folderOf(value) {
14
+ const id = text(value);
15
+ return id === undefined || id === TENANT_FOLDER_ID ? undefined : id;
16
+ }
17
+ /** One raw `Fields[]` entry as the recorded column, or `undefined` for one with no name. */
18
+ export function fieldSchema(raw) {
19
+ const name = text(getCI(raw, "Name"));
20
+ if (name === undefined)
21
+ return undefined;
22
+ const dataType = getCI(raw, "FieldDataType");
23
+ const type = (text(getCI(dataType, "Name")) ?? "UNKNOWN").toUpperCase();
24
+ const display = text(getCI(raw, "FieldDisplayType"));
25
+ const displayName = text(getCI(raw, "DisplayName"));
26
+ const lengthLimit = getCI(dataType, "LengthLimit");
27
+ const defaultValue = getCI(raw, "DefaultValue");
28
+ const field = {
29
+ name,
30
+ ...(displayName !== undefined && displayName !== name ? { displayName } : {}),
31
+ type,
32
+ required: getCI(raw, "IsRequired") === true,
33
+ };
34
+ if (getCI(raw, "IsSystemField") === true)
35
+ field.system = true;
36
+ if (defaultValue !== undefined && defaultValue !== null)
37
+ field.hasDefault = true;
38
+ if (getCI(raw, "IsUnique") === true || getCI(raw, "IsPrimaryKey") === true)
39
+ field.unique = true;
40
+ if (getCI(raw, "IsAttachment") === true || type === "FILE" || display === "File")
41
+ field.attachment = true;
42
+ if (type === "AUTO_NUMBER" || display === "AutoNumber")
43
+ field.autoNumber = true;
44
+ if (typeof lengthLimit === "number" && Number.isFinite(lengthLimit))
45
+ field.lengthLimit = lengthLimit;
46
+ if (type === "RELATIONSHIP") {
47
+ const entity = getCI(raw, "ReferenceEntity");
48
+ const entityName = text(getCI(entity, "Name"));
49
+ if (entityName !== undefined) {
50
+ const entityId = text(getCI(entity, "Id"));
51
+ const displayField = text(getCI(getCI(getCI(raw, "ReferenceField"), "Definition"), "Name"));
52
+ field.reference = {
53
+ entity: entityName,
54
+ ...(entityId !== undefined ? { entityId } : {}),
55
+ ...(displayField !== undefined ? { displayField } : {}),
56
+ };
57
+ }
58
+ }
59
+ const choiceSetId = text(getCI(raw, "ChoiceSetId"));
60
+ if (choiceSetId !== undefined) {
61
+ field.choiceSet = { name: text(getCI(getCI(raw, "ReferenceChoiceSet"), "Name")) ?? "", id: choiceSetId };
62
+ }
63
+ return field;
64
+ }
65
+ /** One `Data.Items[]` entry of `list-values` as a recorded value, or `undefined` for one with no number. */
66
+ function choiceValue(raw) {
67
+ const name = text(getCI(raw, "Name"));
68
+ const numberId = getCI(raw, "NumberId");
69
+ if (name === undefined || typeof numberId !== "number")
70
+ return undefined;
71
+ const displayName = text(getCI(raw, "DisplayName"));
72
+ return { name, ...(displayName !== undefined && displayName !== name ? { displayName } : {}), numberId };
73
+ }
74
+ /** Every value of one choice set, or a reason it could not be read. */
75
+ async function readChoiceValues(client, id, folderKey, cwd) {
76
+ const values = [];
77
+ for (let page = 0; page < CHOICE_MAX_PAGES; page++) {
78
+ const argv = dfChoiceSetValues(id, { ...(folderKey !== undefined ? { folderKey } : {}), limit: CHOICE_PAGE_SIZE, ...(page > 0 ? { offset: page * CHOICE_PAGE_SIZE } : {}) });
79
+ const result = await client.run(argv, { cwd });
80
+ const envelope = parseEnvelope(result.stdout);
81
+ if (result.code !== 0 || !isSuccess(envelope))
82
+ return failureReason(result);
83
+ const data = getCI(envelope, "Data");
84
+ const items = getCI(data, "Items");
85
+ for (const raw of Array.isArray(items) ? items : []) {
86
+ const value = choiceValue(raw);
87
+ if (value !== undefined)
88
+ values.push(value);
89
+ }
90
+ if (getCI(data, "HasNextPage") !== true)
91
+ return values;
92
+ }
93
+ return `more than ${CHOICE_MAX_PAGES * CHOICE_PAGE_SIZE} values`;
94
+ }
95
+ /**
96
+ * The entity's columns, with each choice set's values.
97
+ *
98
+ * A choice set that cannot be read leaves that column's `values` out, with a
99
+ * warning: its column is still checked by name and type, only not by value.
100
+ *
101
+ * @param client - The `uip` client every call goes through.
102
+ * @param target - The entity's id, and the folder key of a folder-scoped one.
103
+ * @param cwd - Where to run `uip`.
104
+ * @returns The columns, in the order the tenant lists them, and a warning per choice set left unread.
105
+ * @throws Refusal `ENTITY_SCHEMA_UNREAD` when `entities get` fails or returns no columns.
106
+ */
107
+ export async function readEntitySchema(client, target, cwd) {
108
+ const argv = dfEntityGet(target.id, target.folderKey);
109
+ const result = await client.run(argv, { cwd });
110
+ const envelope = parseEnvelope(result.stdout);
111
+ if (result.code !== 0 || !isSuccess(envelope)) {
112
+ throw new Refusal(`could not read the entity's columns (${failureReason(result)}).\n ${argv.slice(0, -2).join(" ")}`, "ENTITY_SCHEMA_UNREAD");
113
+ }
114
+ const raw = getCI(getCI(envelope, "Data"), "Fields");
115
+ const fields = (Array.isArray(raw) ? raw : []).map((f) => ({ raw: f, field: fieldSchema(f) }))
116
+ .filter((f) => f.field !== undefined);
117
+ if (fields.length === 0) {
118
+ throw new Refusal(`the entity's schema lists no columns.\n ${argv.slice(0, -2).join(" ")}`, "ENTITY_SCHEMA_UNREAD");
119
+ }
120
+ const warnings = [];
121
+ for (const { raw: rawField, field } of fields) {
122
+ if (field.choiceSet === undefined)
123
+ continue;
124
+ const folderKey = folderOf(getCI(getCI(rawField, "ReferenceChoiceSet"), "FolderId")) ?? target.folderKey;
125
+ const values = await readChoiceValues(client, field.choiceSet.id, folderKey, cwd);
126
+ if (typeof values === "string") {
127
+ warnings.push(`could not read the values of choice set ${JSON.stringify(field.choiceSet.name || field.choiceSet.id)} `
128
+ + `(column ${JSON.stringify(field.name)}): ${values}. check will not judge that column's values.`);
129
+ }
130
+ else {
131
+ field.choiceSet.values = values;
132
+ }
133
+ }
134
+ return { fields: fields.map((f) => f.field), warnings };
135
+ }
@@ -1,5 +1,6 @@
1
1
  import { type ResourceRef, type ResourceResolution, type ResourceResolutions } from "../../core/resource-resolution.js";
2
2
  import type { UipClient } from "../uip/client.js";
3
+ import type { EntitySchemaTarget } from "./entity-schema.js";
3
4
  /** The ledger's file name, under the SDK's work directory. */
4
5
  export declare const RESOURCE_LEDGER_FILENAME = "resources.json";
5
6
  /**
@@ -75,19 +76,25 @@ export interface ResolveResourceRequest extends ResourceRef {
75
76
  export declare function solutionRoot(cwd: string): string | undefined;
76
77
  /** True when `cwd` or a parent holds a solution file (`*.uipx`). */
77
78
  export declare function insideSolution(cwd: string): boolean;
79
+ /** {@link resolveResource}'s answer. */
80
+ export interface ResolvedResource {
81
+ /** The row to record. */
82
+ row: ResourceResolution;
83
+ /** A note for the author, when it was found without a folder. */
84
+ note?: string;
85
+ /** For an entity on the tenant: what `uip df entities get` reads its columns by. */
86
+ schema?: EntitySchemaTarget;
87
+ }
78
88
  /**
79
89
  * Resolve one reference against the solution and the tenant, or refuse with
80
90
  * what was searched.
81
91
  *
82
92
  * @param client - The `uip` client every call goes through.
83
93
  * @param request - The kind, the name, its folder path when the author gave one, and which listings to consult.
84
- * @returns The row to record, and a note for the author when it was found without a folder.
94
+ * @returns The row to record, a note for the author when it was found without a folder, and how to read an entity's columns.
85
95
  * @throws Refusal `RESOURCE_AMBIGUOUS`, `RESOURCE_NOT_IN_FOLDER`, `RESOURCE_NOT_FOUND` or `RESOURCE_LISTING_FAILED`.
86
96
  */
87
- export declare function resolveResource(client: UipClient, request: ResolveResourceRequest): Promise<{
88
- row: ResourceResolution;
89
- note?: string;
90
- }>;
97
+ export declare function resolveResource(client: UipClient, request: ResolveResourceRequest): Promise<ResolvedResource>;
91
98
  /** One line per recorded fact, for the console. */
92
99
  export declare function recordedLines(row: ResourceResolution, ledger: string): string[];
93
100
  /**
@@ -332,6 +332,17 @@ function nearMisses(name, pool) {
332
332
  function asRow(c) {
333
333
  return { kind: c.kind, name: c.name, scope: c.scope, folderPath: c.folderPath, folderKey: c.folderKey, key: c.key, source: c.source };
334
334
  }
335
+ /**
336
+ * What resolved, and how to read its columns: a remote folder entity by its
337
+ * resource key (the entity's id) and folder key, a tenant-level one by its
338
+ * `Id`. A resource authored in the solution has no tenant schema yet.
339
+ */
340
+ function resolved(c, note) {
341
+ const schema = c.kind !== ENTITY_KIND ? undefined
342
+ : c.scope === "tenant" ? (c.entityId !== undefined ? { id: c.entityId } : undefined)
343
+ : c.source === "remote" && c.key !== null && c.folderKey !== null ? { id: c.key, folderKey: c.folderKey } : undefined;
344
+ return { row: asRow(c), ...(note !== undefined ? { note } : {}), ...(schema !== undefined ? { schema } : {}) };
345
+ }
335
346
  /**
336
347
  * The solution's rows as candidates: a row whose `Key` a remote row has is that
337
348
  * remote resource (the remote row answers for it, with its real folder); one
@@ -350,7 +361,7 @@ function localCandidates(local, remote) {
350
361
  *
351
362
  * @param client - The `uip` client every call goes through.
352
363
  * @param request - The kind, the name, its folder path when the author gave one, and which listings to consult.
353
- * @returns The row to record, and a note for the author when it was found without a folder.
364
+ * @returns The row to record, a note for the author when it was found without a folder, and how to read an entity's columns.
354
365
  * @throws Refusal `RESOURCE_AMBIGUOUS`, `RESOURCE_NOT_IN_FOLDER`, `RESOURCE_NOT_FOUND` or `RESOURCE_LISTING_FAILED`.
355
366
  */
356
367
  export async function resolveResource(client, request) {
@@ -399,7 +410,10 @@ export async function resolveResource(client, request) {
399
410
  .filter((r) => text(getCI(r, "FolderId")) === TENANT_FOLDER_ID)
400
411
  .map((r) => {
401
412
  const name = text(getCI(r, "Name"));
402
- return name === null ? undefined : { kind, name, scope: "tenant", folderPath: null, folderKey: null, key: null, source: "tenant" };
413
+ const entityId = text(getCI(r, "Id"));
414
+ return name === null ? undefined : {
415
+ kind, name, scope: "tenant", folderPath: null, folderKey: null, key: null, source: "tenant", ...(entityId !== null ? { entityId } : {}),
416
+ };
403
417
  })
404
418
  .filter((c) => c !== undefined);
405
419
  tenantExact.push(...tenantRows.filter(exactName));
@@ -413,7 +427,7 @@ export async function resolveResource(client, request) {
413
427
  if (request.folder !== undefined) {
414
428
  const matches = exact.filter(inFolder);
415
429
  if (matches.length === 1)
416
- return { row: asRow(matches[0]) };
430
+ return resolved(matches[0]);
417
431
  if (matches.length > 1) {
418
432
  throw new Refusal(`${matches.length} ${resourcePlural(kind)} named ${JSON.stringify(request.name)} are in folder ${JSON.stringify(request.folder)}; refusing to pick one:\n` +
419
433
  matches.map(candidateLine).join("\n") + `\n${searchedBlock(searched)}`, "RESOURCE_AMBIGUOUS");
@@ -432,7 +446,7 @@ export async function resolveResource(client, request) {
432
446
  ? `Found at tenant level. A tenant-level entity needs no prepare; write it as entity: '${only.name}'`
433
447
  : `Found in folder ${JSON.stringify(only.folderPath)}${only.source === "local" ? " (authored in this solution)" : ""} with no folder given. `
434
448
  + `Pin it in the source: ${only.kind === ENTITY_KIND ? `entity: { name: '${only.name}', folder: '${only.folderPath ?? ""}' }` : `resource('${only.kind}', '${only.name}', { folder: '${only.folderPath ?? ""}' })`}`;
435
- return { row: asRow(only), note };
449
+ return resolved(only, note);
436
450
  }
437
451
  if (all.length > 1) {
438
452
  throw new Refusal(`${all.length} ${resourcePlural(kind)} are named ${JSON.stringify(request.name)}; refusing to pick one:\n` +
@@ -462,6 +476,13 @@ export async function resolveResource(client, request) {
462
476
  (near.length > 0 ? `Near misses:\n${near.map(candidateLine).join("\n")}\n` : "") +
463
477
  findBlock(kind), "RESOURCE_NOT_FOUND");
464
478
  }
479
+ /** `4: Name, Status, Total, Notes (and 5 system columns)`, the first dozen named. */
480
+ function columnSummary(fields) {
481
+ const own = fields.filter((f) => f.system !== true).map((f) => f.name);
482
+ const named = own.length > 12 ? `${own.slice(0, 12).join(", ")}, …` : own.join(", ");
483
+ const system = fields.length - own.length;
484
+ return `${own.length}: ${named}${system > 0 ? ` (and ${system} system columns)` : ""}`;
485
+ }
465
486
  /** One line per recorded fact, for the console. */
466
487
  export function recordedLines(row, ledger) {
467
488
  const label = row.kind.padEnd(9);
@@ -469,6 +490,7 @@ export function recordedLines(row, ledger) {
469
490
  `${label} ${row.name} (${row.scope === "tenant" ? "tenant level" : row.folderPath}, ${row.source})`,
470
491
  ...(row.key !== null ? [`Key ${row.key}`] : []),
471
492
  ...(row.folderKey !== null ? [`Folder ${row.folderKey}`] : []),
493
+ ...(row.fields !== undefined ? [`Columns ${columnSummary(row.fields)}`] : []),
472
494
  `Recorded ${ledger}`,
473
495
  ];
474
496
  }
@@ -10,6 +10,7 @@ import { consoleReporter } from "./reporter.js";
10
10
  import { relative } from "node:path";
11
11
  import { ENTITY_KIND } from "../core/resource-resolution.js";
12
12
  import { defaultResourceLedger, forgetResource, readResourceLedger, recordResource, recordedLines, recordedRefs, resolveResource, } from "./prepare/resources.js";
13
+ import { readEntitySchema } from "./prepare/entity-schema.js";
13
14
  import { Refusal, UsageError } from "./errors.js";
14
15
  import { defaultUipClient } from "./uip/client.js";
15
16
  // This mirrors the generator's own flags one for one, so a `--version` here is
@@ -292,6 +293,31 @@ function requestedRef(options) {
292
293
  return { kind: options.kind, name: options.name, ...folder };
293
294
  return undefined;
294
295
  }
296
+ /**
297
+ * `row` with the entity's columns, read from the tenant (#1980). A failed read
298
+ * is a warning, not a refusal: the keys are what `compile` needs, and they
299
+ * resolved. The row is then recorded without columns, so `check` judges none,
300
+ * and the warning says so.
301
+ *
302
+ * This differs on purpose from a published process's argument schema, which
303
+ * `prepare` refuses to record without (`PROCESS_SCHEMA_READ_FAILED`): compile
304
+ * writes that schema into the node, so a row without it would compile wrong.
305
+ * An entity's columns are read only by `check`, and compile never writes them.
306
+ */
307
+ async function withSchema(ports, row, target, cwd) {
308
+ try {
309
+ const { fields, warnings } = await readEntitySchema(ports.client, target, cwd);
310
+ for (const warning of warnings)
311
+ ports.reporter.warn(`[ENTITY_SCHEMA_UNREAD] ${warning}`);
312
+ return { ...row, fields };
313
+ }
314
+ catch (error) {
315
+ if (!(error instanceof Refusal))
316
+ throw error;
317
+ ports.reporter.warn(`[${error.code}] ${row.name}: ${error.message}\n The keys are recorded; check will not judge this entity's columns until prepare reads them.`);
318
+ return row;
319
+ }
320
+ }
295
321
  /**
296
322
  * `--entity` / `--kind --name` / `--refresh-resources`: resolve each reference
297
323
  * against the solution and the tenant and record it in the resource ledger. A
@@ -335,12 +361,21 @@ export async function prepareResources(options, ports) {
335
361
  refused.push({ ref, error });
336
362
  continue;
337
363
  }
338
- recordResource(ledger, ref, resolved.row);
339
- for (const line of recordedLines(resolved.row, shownLedger))
364
+ const row = resolved.schema !== undefined ? await withSchema(ports, resolved.row, resolved.schema, cwd) : resolved.row;
365
+ if (row.kind === ENTITY_KIND && resolved.schema === undefined) {
366
+ if (row.source === "local") {
367
+ ports.reporter.info(`${row.name} was authored in this solution and is not on the tenant yet, so its columns are not recorded; check will not judge them.`);
368
+ }
369
+ else {
370
+ ports.reporter.warn(`[ENTITY_SCHEMA_UNREAD] ${row.name}: the listing gave no entity id to read its columns by; check will not judge them.`);
371
+ }
372
+ }
373
+ recordResource(ledger, ref, row);
374
+ for (const line of recordedLines(row, shownLedger))
340
375
  ports.reporter.info(line);
341
376
  if (resolved.note !== undefined)
342
377
  ports.reporter.info(resolved.note);
343
- recorded.push(resolved.row);
378
+ recorded.push(row);
344
379
  }
345
380
  if (refused.length > 0) {
346
381
  throw new Refusal(`${refused.length} of ${refs.length} recorded reference(s) no longer resolve; their rows are removed, so check reports them:\n`
@@ -70,3 +70,22 @@ export declare function solutionResourceList(kind: string, source: "local" | "re
70
70
  * all-zero GUID). The one listing that knows an entity the catalogue omits.
71
71
  */
72
72
  export declare function dfEntitiesList(): string[];
73
+ /**
74
+ * `uip df entities get <id>`: one entity's schema, `Data.Fields[]` with each
75
+ * column's `Name`, `FieldDataType.Name`, `IsRequired`, `IsSystemField`,
76
+ * `ChoiceSetId` and `ReferenceEntity`. The id of a folder-scoped entity is its
77
+ * solution resource `Key`, read with its `--folder-key`; a tenant-level one's is
78
+ * the `Id` `uip df entities list` gives it. More complete than the listing's
79
+ * `Fields`, which leaves out `RecordOwner` (staging, 2026-11-13).
80
+ */
81
+ export declare function dfEntityGet(id: string, folderKey?: string): string[];
82
+ /**
83
+ * `uip df choice-sets list-values <id>`: one page of a choice set's values,
84
+ * `Data.Items[]` with each value's `Name`, `DisplayName` and `NumberId`, and
85
+ * `Data.HasNextPage`. A folder-scoped set is read with its `--folder-key`.
86
+ */
87
+ export declare function dfChoiceSetValues(id: string, opts?: {
88
+ folderKey?: string;
89
+ limit?: number;
90
+ offset?: number;
91
+ }): string[];
@@ -122,3 +122,28 @@ export function solutionResourceList(kind, source, opts = {}) {
122
122
  export function dfEntitiesList() {
123
123
  return [UIP, "df", "entities", "list", "--output", "json"];
124
124
  }
125
+ /**
126
+ * `uip df entities get <id>`: one entity's schema, `Data.Fields[]` with each
127
+ * column's `Name`, `FieldDataType.Name`, `IsRequired`, `IsSystemField`,
128
+ * `ChoiceSetId` and `ReferenceEntity`. The id of a folder-scoped entity is its
129
+ * solution resource `Key`, read with its `--folder-key`; a tenant-level one's is
130
+ * the `Id` `uip df entities list` gives it. More complete than the listing's
131
+ * `Fields`, which leaves out `RecordOwner` (staging, 2026-11-13).
132
+ */
133
+ export function dfEntityGet(id, folderKey) {
134
+ return [UIP, "df", "entities", "get", id, ...(folderKey !== undefined ? ["--folder-key", folderKey] : []), "--output", "json"];
135
+ }
136
+ /**
137
+ * `uip df choice-sets list-values <id>`: one page of a choice set's values,
138
+ * `Data.Items[]` with each value's `Name`, `DisplayName` and `NumberId`, and
139
+ * `Data.HasNextPage`. A folder-scoped set is read with its `--folder-key`.
140
+ */
141
+ export function dfChoiceSetValues(id, opts = {}) {
142
+ return [
143
+ UIP, "df", "choice-sets", "list-values", id,
144
+ ...(opts.folderKey !== undefined ? ["--folder-key", opts.folderKey] : []),
145
+ ...(opts.limit !== undefined ? ["--limit", String(opts.limit)] : []),
146
+ ...(opts.offset !== undefined ? ["--offset", String(opts.offset)] : []),
147
+ "--output", "json",
148
+ ];
149
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.102.0",
3
+ "version": "6.103.0",
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",
@@ -121,5 +121,5 @@
121
121
  "@types/node": "^22.7.0",
122
122
  "esbuild": "^0.28.1"
123
123
  },
124
- "gitref": "ff60f24d741fc03b591278aa1d56ae76e7e3c7d7"
124
+ "gitref": "a2b0c3e4c8d5532116ba89a1761d07300bd4c4bd"
125
125
  }