@uipath/maestro-builder-sdk 6.118.0 → 6.119.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,301 @@
1
+ /**
2
+ * The Extract document node's taxonomy ids (builder-sdk#1985): every field
3
+ * group and field of `inputs.schemaDocument.outputSchema` carries a stable id
4
+ * (`x-uipath-field-group-id`, `x-uipath-field-id`) that annotations and
5
+ * evaluator settings are stored against.
6
+ *
7
+ * Invariant: an id the source carries is kept; a missing one is the id the
8
+ * overwritten `.flow` has for the entry of the same name (a group by its key,
9
+ * a field by its name within the group of the same id), else one minted from
10
+ * the flow, the node and that name, so a recompile mints the same one.
11
+ *
12
+ * Copied from uipath-cli `flow-tool/src/services/extract-schema/`
13
+ * (`merge-schema-ids.ts`, `close-object-schemas.ts`, and `readOutputSchema` from
14
+ * `validate-schema-document.ts`); only the source of new ids differs (the CLI
15
+ * mints random ones). Pure: the flow core is portable (FB015).
16
+ */
17
+ import { stableId } from '../../../core/stable-id.js';
18
+ import { isRecord } from '../../../core/node-envelope.js';
19
+ /** Vendor extension carrying a field group's stable id. */
20
+ export const FIELD_GROUP_ID_EXTENSION = 'x-uipath-field-group-id';
21
+ /** Vendor extension carrying a field's stable id. */
22
+ export const FIELD_ID_EXTENSION = 'x-uipath-field-id';
23
+ /** Vendor extension naming the group a nested group hangs under. */
24
+ export const PARENT_FIELD_GROUP_ID_EXTENSION = 'x-uipath-parent-field-group-id';
25
+ /** Vendor extension holding business checks, which reference fields by id. */
26
+ export const BUSINESS_CHECKS_EXTENSION = 'x-uipath-business-checks';
27
+ /** Joins the segments of a nested field group's flattened property key: `Invoice > Line items`. */
28
+ export const GROUP_PATH_SEPARATOR = ' > ';
29
+ export { isRecord };
30
+ export function hasType(node, wanted) {
31
+ const type = node.type;
32
+ if (typeof type === 'string')
33
+ return type === wanted;
34
+ if (Array.isArray(type))
35
+ return type.includes(wanted);
36
+ return false;
37
+ }
38
+ function readString(node, key) {
39
+ const value = node[key];
40
+ return typeof value === 'string' ? value : undefined;
41
+ }
42
+ export const quoteKey = (key) => `["${key}"]`;
43
+ /**
44
+ * The field groups of an output schema with their fields, and the containers
45
+ * that could not be read as either. Every entry of the root `properties` is a
46
+ * group; a repeating group (`type: 'array'`) holds its fields under
47
+ * `items.properties`, a single one directly under `properties`. Nesting is by
48
+ * name: a nested group is another root entry keyed by its full path.
49
+ */
50
+ export function readOutputSchema(outputSchema) {
51
+ const groups = [];
52
+ const issues = [];
53
+ const properties = outputSchema.properties;
54
+ if (!isRecord(properties)) {
55
+ issues.push({ path: 'outputSchema.properties', message: 'properties must be an object of field groups.' });
56
+ return { groups, issues };
57
+ }
58
+ for (const [pathKey, rawGroup] of Object.entries(properties)) {
59
+ const groupPath = `outputSchema.properties${quoteKey(pathKey)}`;
60
+ if (!isRecord(rawGroup)) {
61
+ issues.push({ path: groupPath, message: 'A field group must be an object.' });
62
+ continue;
63
+ }
64
+ const multiInstance = hasType(rawGroup, 'array');
65
+ const holder = multiInstance ? rawGroup.items : rawGroup;
66
+ const fieldsPath = multiInstance ? `${groupPath}.items.properties` : `${groupPath}.properties`;
67
+ if (multiInstance && !isRecord(holder)) {
68
+ issues.push({ path: `${groupPath}.items`, message: 'A repeating field group must declare its fields under an `items` object.' });
69
+ continue;
70
+ }
71
+ if (multiInstance && isRecord(holder) && holder.type !== undefined && !hasType(holder, 'object')) {
72
+ issues.push({ path: `${groupPath}.items.type`, message: "A repeating field group's `items` must be of type object." });
73
+ continue;
74
+ }
75
+ const fieldProperties = isRecord(holder) ? holder.properties : undefined;
76
+ if (fieldProperties !== undefined && !isRecord(fieldProperties)) {
77
+ issues.push({ path: fieldsPath, message: 'properties must be an object of fields.' });
78
+ continue;
79
+ }
80
+ const fields = [];
81
+ if (isRecord(fieldProperties)) {
82
+ for (const [name, rawField] of Object.entries(fieldProperties)) {
83
+ const fieldPath = `${fieldsPath}${quoteKey(name)}`;
84
+ if (!isRecord(rawField)) {
85
+ issues.push({ path: fieldPath, message: 'A field must be an object.' });
86
+ continue;
87
+ }
88
+ fields.push({ name, node: rawField, fieldId: readString(rawField, FIELD_ID_EXTENSION), path: fieldPath });
89
+ }
90
+ }
91
+ groups.push({
92
+ pathKey,
93
+ segments: pathKey.split(GROUP_PATH_SEPARATOR),
94
+ node: rawGroup,
95
+ groupId: readString(rawGroup, FIELD_GROUP_ID_EXTENSION),
96
+ parentGroupId: readString(rawGroup, PARENT_FIELD_GROUP_ID_EXTENSION),
97
+ multiInstance,
98
+ fields,
99
+ path: groupPath,
100
+ });
101
+ }
102
+ return { groups, issues };
103
+ }
104
+ /** Every object holding `x-uipath-business-checks`, wherever it sits. */
105
+ function businessCheckHolders(value, found = []) {
106
+ if (Array.isArray(value)) {
107
+ for (const entry of value)
108
+ businessCheckHolders(entry, found);
109
+ return found;
110
+ }
111
+ if (!isRecord(value))
112
+ return found;
113
+ if (Array.isArray(value[BUSINESS_CHECKS_EXTENSION]))
114
+ found.push(value);
115
+ for (const [key, child] of Object.entries(value)) {
116
+ if (key !== BUSINESS_CHECKS_EXTENSION)
117
+ businessCheckHolders(child, found);
118
+ }
119
+ return found;
120
+ }
121
+ /** The ids compile mints for one node: deterministic, so a recompile mints the same. */
122
+ export function derivedTaxonomyMint(flowId, nodeId) {
123
+ return {
124
+ group: (pathKey) => stableId(`${flowId}:${nodeId}:taxonomy-group:${pathKey}`),
125
+ field: (groupId, name) => stableId(`${flowId}:${nodeId}:taxonomy-field:${groupId}:${name}`),
126
+ };
127
+ }
128
+ /**
129
+ * `document` with every field group and field given an id: its own when it has
130
+ * one, else the one the entry of the same place had in `existing`, else a new
131
+ * one from `mint`; and every nested group's parent reference set to its
132
+ * parent's id. Business checks that name an id no longer in the document are
133
+ * dropped. A document with no `outputSchema` object is returned as given.
134
+ * Never mutates its arguments.
135
+ *
136
+ * A nested group is matched only under its parent's OLD path, and only while
137
+ * the parent itself survived; a field only within the group of the same id.
138
+ */
139
+ export function settleTaxonomyIds(document, existing, mint) {
140
+ const out = JSON.parse(JSON.stringify(document));
141
+ const counts = { groupIdsPreserved: 0, groupIdsMinted: 0, fieldIdsPreserved: 0, fieldIdsMinted: 0, businessChecksDropped: 0 };
142
+ if (!isRecord(out.outputSchema))
143
+ return { document: out, counts };
144
+ const groupIdByPath = new Map();
145
+ const pathByGroupId = new Map();
146
+ const fieldIdsByGroupId = new Map();
147
+ if (isRecord(existing?.outputSchema)) {
148
+ for (const group of readOutputSchema(existing.outputSchema).groups) {
149
+ if (group.groupId === undefined || group.groupId.length === 0)
150
+ continue;
151
+ const fieldIds = new Map();
152
+ for (const field of group.fields)
153
+ if (field.fieldId !== undefined && field.fieldId.length > 0)
154
+ fieldIds.set(field.name, field.fieldId);
155
+ groupIdByPath.set(group.pathKey, group.groupId);
156
+ pathByGroupId.set(group.groupId, group.pathKey);
157
+ fieldIdsByGroupId.set(group.groupId, fieldIds);
158
+ }
159
+ }
160
+ const groups = readOutputSchema(out.outputSchema).groups;
161
+ const claimedGroupIds = new Set();
162
+ const claimedFieldIds = new Set();
163
+ for (const group of groups) {
164
+ if (group.groupId !== undefined && group.groupId.length > 0)
165
+ claimedGroupIds.add(group.groupId);
166
+ for (const field of group.fields)
167
+ if (field.fieldId !== undefined && field.fieldId.length > 0)
168
+ claimedFieldIds.add(field.fieldId);
169
+ }
170
+ const finalGroupIdByPathKey = new Map();
171
+ const liveGroupIds = new Set();
172
+ const liveFieldIds = new Set();
173
+ const previousPathByPathKey = new Map();
174
+ const takenGroupIds = new Set(claimedGroupIds);
175
+ const fresh = (candidate, taken, again) => {
176
+ let id = candidate;
177
+ for (let n = 2; taken.has(id); n++)
178
+ id = again(n);
179
+ return id;
180
+ };
181
+ for (const group of [...groups].sort((a, b) => a.segments.length - b.segments.length)) {
182
+ const parentPath = group.segments.slice(0, -1).join(GROUP_PATH_SEPARATOR);
183
+ const leaf = group.segments[group.segments.length - 1];
184
+ const previousParentPath = previousPathByPathKey.get(parentPath);
185
+ const candidatePath = group.segments.length > 1
186
+ ? previousParentPath === undefined ? undefined : `${previousParentPath}${GROUP_PATH_SEPARATOR}${leaf}`
187
+ : group.pathKey;
188
+ let groupId = group.groupId;
189
+ if (groupId !== undefined && groupId.length > 0) {
190
+ counts.groupIdsPreserved++;
191
+ }
192
+ else {
193
+ const adopted = candidatePath === undefined ? undefined : groupIdByPath.get(candidatePath);
194
+ if (adopted !== undefined && !takenGroupIds.has(adopted)) {
195
+ groupId = adopted;
196
+ counts.groupIdsPreserved++;
197
+ }
198
+ else {
199
+ groupId = fresh(mint.group(group.pathKey), takenGroupIds, (n) => mint.group(`${group.pathKey}#${n}`));
200
+ counts.groupIdsMinted++;
201
+ }
202
+ group.node[FIELD_GROUP_ID_EXTENSION] = groupId;
203
+ }
204
+ finalGroupIdByPathKey.set(group.pathKey, groupId);
205
+ takenGroupIds.add(groupId);
206
+ liveGroupIds.add(groupId);
207
+ const previousPath = pathByGroupId.get(groupId);
208
+ if (previousPath !== undefined)
209
+ previousPathByPathKey.set(group.pathKey, previousPath);
210
+ }
211
+ const takenFieldIds = new Set(claimedFieldIds);
212
+ for (const group of groups) {
213
+ const groupId = finalGroupIdByPathKey.get(group.pathKey) ?? '';
214
+ const previousFieldIds = fieldIdsByGroupId.get(groupId);
215
+ for (const field of group.fields) {
216
+ if (field.fieldId !== undefined && field.fieldId.length > 0) {
217
+ counts.fieldIdsPreserved++;
218
+ liveFieldIds.add(field.fieldId);
219
+ continue;
220
+ }
221
+ const adopted = previousFieldIds?.get(field.name);
222
+ let fieldId;
223
+ if (adopted !== undefined && !takenFieldIds.has(adopted)) {
224
+ fieldId = adopted;
225
+ counts.fieldIdsPreserved++;
226
+ }
227
+ else {
228
+ fieldId = fresh(mint.field(groupId, field.name), takenFieldIds, (n) => mint.field(groupId, `${field.name}#${n}`));
229
+ counts.fieldIdsMinted++;
230
+ }
231
+ field.node[FIELD_ID_EXTENSION] = fieldId;
232
+ takenFieldIds.add(fieldId);
233
+ liveFieldIds.add(fieldId);
234
+ }
235
+ }
236
+ for (const group of groups) {
237
+ if (group.segments.length < 2)
238
+ continue;
239
+ const parentId = finalGroupIdByPathKey.get(group.segments.slice(0, -1).join(GROUP_PATH_SEPARATOR));
240
+ if (parentId !== undefined)
241
+ group.node[PARENT_FIELD_GROUP_ID_EXTENSION] = parentId;
242
+ }
243
+ for (const holder of businessCheckHolders(out)) {
244
+ const checks = holder[BUSINESS_CHECKS_EXTENSION];
245
+ const kept = checks.filter((check) => {
246
+ if (!isRecord(check))
247
+ return true;
248
+ if (typeof check.fieldId === 'string' && !liveFieldIds.has(check.fieldId))
249
+ return false;
250
+ if (typeof check.fieldGroupId === 'string' && !liveGroupIds.has(check.fieldGroupId))
251
+ return false;
252
+ return true;
253
+ });
254
+ counts.businessChecksDropped += checks.length - kept.length;
255
+ holder[BUSINESS_CHECKS_EXTENSION] = kept;
256
+ }
257
+ return { document: out, counts };
258
+ }
259
+ const declaresObject = (node) => hasType(node, 'object');
260
+ function closeNode(node) {
261
+ if (!isRecord(node))
262
+ return;
263
+ if (node.properties === undefined && declaresObject(node))
264
+ node.properties = {};
265
+ const properties = node.properties;
266
+ if (isRecord(properties)) {
267
+ if (node.type === undefined)
268
+ node.type = 'object';
269
+ node.additionalProperties = false;
270
+ node.required = Object.keys(properties);
271
+ for (const child of Object.values(properties))
272
+ closeNode(child);
273
+ }
274
+ if (isRecord(node.$defs))
275
+ for (const child of Object.values(node.$defs))
276
+ closeNode(child);
277
+ closeNode(node.items);
278
+ if (Array.isArray(node.anyOf))
279
+ for (const child of node.anyOf)
280
+ closeNode(child);
281
+ }
282
+ /**
283
+ * Fill in the keywords the Schema Editor needs to open the document, wherever
284
+ * they follow from what is there (uipath-cli `close-object-schemas.ts`, which
285
+ * `nodes schema set` runs): every object is closed (`additionalProperties:
286
+ * false`) and lists every property in `required` (optionality is the
287
+ * `[type, "null"]` union, not omission), and the root is an object with a
288
+ * `$defs`. For instance `{ type: ['object', 'null'], properties: { Total: … } }`
289
+ * gains `additionalProperties: false, required: ['Total']`. Without them the
290
+ * editor shows "Could not load schema". MUTATES `outputSchema`; a malformed
291
+ * container is left as it is, for `check` to report.
292
+ */
293
+ export function closeObjectSchemas(outputSchema) {
294
+ if (!isRecord(outputSchema))
295
+ return;
296
+ if (outputSchema.type === undefined)
297
+ outputSchema.type = 'object';
298
+ if (outputSchema.$defs === undefined)
299
+ outputSchema.$defs = {};
300
+ closeNode(outputSchema);
301
+ }
@@ -63,6 +63,23 @@ export interface CollectedRefusal {
63
63
  }
64
64
  export interface SerializeOpts {
65
65
  library?: Library;
66
+ /**
67
+ * The `.flow` this compile overwrites, parsed (`compile-cli` reads the output
68
+ * file before writing it). A type can read the node it had there through
69
+ * {@link FlowSerializeContext.overwrittenNode}: Extract document keeps the
70
+ * taxonomy ids that file has for entries the source names none for (#1985).
71
+ */
72
+ overwrites?: unknown;
73
+ /**
74
+ * Informational lines a type reports about what it wrote (`compile: <message>`),
75
+ * with the data behind them for `--json`. For instance Extract document's
76
+ * kept-vs-minted taxonomy id counts.
77
+ */
78
+ note?: (note: {
79
+ step: string;
80
+ message: string;
81
+ data?: unknown;
82
+ }) => void;
66
83
  /** The project's bindings.json (`Bindings`), or any view that answers the label rules. */
67
84
  bindings?: BindingsView;
68
85
  /**
package/dist/serialize.js CHANGED
@@ -196,6 +196,21 @@ export { CONNECTOR_INPUT_MISSING } from './core/connector-inputs.js';
196
196
  */
197
197
  const DRAFT_CODES_AGREE = true;
198
198
  void DRAFT_CODES_AGREE;
199
+ /** The node of `flow` emitted under `id`, when it is of type `typeName` (top level or a subflow). */
200
+ function overwrittenNodeOf(flow, id, typeName) {
201
+ if (flow === null || typeof flow !== 'object')
202
+ return undefined;
203
+ const f = flow;
204
+ const lists = [f.nodes, ...(f.subflows !== null && typeof f.subflows === 'object' ? Object.values(f.subflows).map((s) => s?.nodes) : [])];
205
+ for (const list of lists) {
206
+ if (!Array.isArray(list))
207
+ continue;
208
+ const node = list.find((n) => n !== null && typeof n === 'object' && n.id === id);
209
+ if (node !== undefined)
210
+ return node.type === typeName ? node : undefined;
211
+ }
212
+ return undefined;
213
+ }
199
214
  /**
200
215
  * `serialize`, plus the extra files the flow needs on disk beside it.
201
216
  *
@@ -2351,6 +2366,8 @@ function serializeFlow(built, opts) {
2351
2366
  ? resolved.carried
2352
2367
  : bundledDefinition(typeName, v) ?? carriedFor(typeName, v)),
2353
2368
  bindings: resourceBindings,
2369
+ overwrittenNode: () => overwrittenNodeOf(opts.overwrites, id, impl.typeName),
2370
+ note: (message, data) => opts.note?.({ step: step.name, message, ...(data !== undefined ? { data } : {}) }),
2354
2371
  resolveBinding: ((name, attribute, at, target) => resolveBinding(bindingOpts, name, attribute, at, target)),
2355
2372
  resolveBindingPair: (labels, at, target) => resolveBindingPair(bindingOpts, labels, at, target),
2356
2373
  bindConnection: (c) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.118.0",
3
+ "version": "6.119.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",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "9c219f2a52f548305c5576f25ed4266d23af9fdf"
127
+ "gitref": "737af3acc6d29c4b99c6e96e7c40d23dd3427b4b"
128
128
  }