@uipath/maestro-builder-sdk 6.118.1 → 6.119.1

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,207 @@
1
+ /**
2
+ * `check`'s rules for an Extract document taxonomy (builder-sdk#1986): the
3
+ * refusals of `uip maestro flow nodes schema set`, which `flow validate`
4
+ * reports too, one code per rule.
5
+ *
6
+ * They run on the document as compile writes it (config scaffolded, ids
7
+ * settled, objects closed, `taxonomy.ts`), so nothing compile fills in is
8
+ * reported; for that reason the CLI validator's warnings for a missing id are
9
+ * left out.
10
+ *
11
+ * Copied from uipath-cli `flow-tool/src/services/extract-schema/validate-schema-document.ts`
12
+ * and flow-schema's `ixp-schema-limits` rule. Pure (FB015).
13
+ */
14
+ import { GROUP_PATH_SEPARATOR, PARENT_FIELD_GROUP_ID_EXTENSION, hasType, isRecord, quoteKey, readOutputSchema, } from './taxonomy.js';
15
+ /** A `$defs` key becomes a `$ref` token; one needing escaping is rejected downstream. */
16
+ const DEFS_KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
17
+ const DEFS_REFERENCE_PREFIX = '#/$defs/';
18
+ /**
19
+ * The extraction API's limits, flow-schema's `IXP_MAX_*` (`ixp-schema/constants.ts`).
20
+ * The names are 128 since flow-workbench #5603 (flow-schema 0.138.0-develop,
21
+ * 2026-11-06), which matches IXP; the 0.135.x line still says 64. The
22
+ * newest line is copied, so `check` refuses nothing the platform accepts.
23
+ * tests/taxonomy-limits-drift.test.ts holds each one to the flow-schema the
24
+ * repo pins for it.
25
+ */
26
+ export const TAXONOMY_LIMITS = {
27
+ fieldGroupName: 128,
28
+ fieldName: 128,
29
+ fieldTypeName: 128,
30
+ instructions: 4096,
31
+ };
32
+ function referenceFindings(node, path, keys, out) {
33
+ if (!isRecord(node))
34
+ return;
35
+ const reference = node.$ref;
36
+ if (typeof reference === 'string') {
37
+ const key = reference.startsWith(DEFS_REFERENCE_PREFIX) ? reference.slice(DEFS_REFERENCE_PREFIX.length) : undefined;
38
+ if (key === undefined || !keys.has(key)) {
39
+ out.push({ code: 'EXTRACT_TAXONOMY_REF', path: `${path}.$ref`, message: `$ref "${reference}" does not name a field type in outputSchema.$defs.` });
40
+ }
41
+ }
42
+ for (const member of ['properties', '$defs']) {
43
+ const children = node[member];
44
+ if (!isRecord(children))
45
+ continue;
46
+ for (const [key, child] of Object.entries(children))
47
+ referenceFindings(child, `${path}.${member}${quoteKey(key)}`, keys, out);
48
+ }
49
+ referenceFindings(node.items, `${path}.items`, keys, out);
50
+ if (Array.isArray(node.anyOf))
51
+ node.anyOf.forEach((child, i) => referenceFindings(child, `${path}.anyOf[${i}]`, keys, out));
52
+ }
53
+ function measure(out, value, limit, subject, path) {
54
+ if (typeof value !== 'string' || value.length <= limit)
55
+ return;
56
+ out.push({ code: 'EXTRACT_TAXONOMY_LIMIT', path, message: `${subject} is ${value.length} characters; the maximum is ${limit}.` });
57
+ }
58
+ /** The limits flow-schema's `ixp-schema-limits` rule applies, with its subjects. */
59
+ function limitFindings(document, out) {
60
+ measure(out, document.prompt, TAXONOMY_LIMITS.instructions, 'Overall instructions', 'prompt');
61
+ const outputSchema = isRecord(document.outputSchema) ? document.outputSchema : {};
62
+ const groups = isRecord(outputSchema.properties) ? outputSchema.properties : {};
63
+ for (const [name, raw] of Object.entries(groups)) {
64
+ const group = isRecord(raw) ? raw : undefined;
65
+ const path = `outputSchema.properties${quoteKey(name)}`;
66
+ const where = name ? `field group "${name}"` : 'an unnamed field group';
67
+ measure(out, name, TAXONOMY_LIMITS.fieldGroupName, `Field group "${name}"`, path);
68
+ measure(out, group?.description, TAXONOMY_LIMITS.instructions, `Instructions on ${where}`, `${path}.description`);
69
+ const items = isRecord(group?.items) ? group.items : undefined;
70
+ const fields = (isRecord(items?.properties) ? items.properties : undefined) ?? (isRecord(group?.properties) ? group.properties : {});
71
+ for (const [fieldName, rawField] of Object.entries(fields)) {
72
+ const which = fieldName ? `field "${fieldName}"` : 'an unnamed field';
73
+ const fieldPath = `${path}.${items ? 'items.' : ''}properties${quoteKey(fieldName)}`;
74
+ measure(out, fieldName, TAXONOMY_LIMITS.fieldName, `${which.charAt(0).toUpperCase()}${which.slice(1)} in ${where}`, fieldPath);
75
+ measure(out, isRecord(rawField) ? rawField.description : undefined, TAXONOMY_LIMITS.instructions, `Instructions on ${which} in ${where}`, `${fieldPath}.description`);
76
+ }
77
+ }
78
+ const defs = isRecord(outputSchema.$defs) ? outputSchema.$defs : {};
79
+ for (const [key, raw] of Object.entries(defs)) {
80
+ const def = isRecord(raw) ? raw : undefined;
81
+ const which = typeof def?.title === 'string' && def.title ? `field type "${def.title}"` : 'an unnamed field type';
82
+ const path = `outputSchema.$defs${quoteKey(key)}`;
83
+ measure(out, def?.title, TAXONOMY_LIMITS.fieldTypeName, `${which.charAt(0).toUpperCase()}${which.slice(1)}`, `${path}.title`);
84
+ measure(out, def?.description, TAXONOMY_LIMITS.instructions, `Instructions on ${which}`, `${path}.description`);
85
+ }
86
+ }
87
+ /**
88
+ * Every rule a `{ prompt, outputSchema }` document breaks, in the CLI
89
+ * validator's order, then the limits. Empty when `nodes schema set` would
90
+ * write it.
91
+ */
92
+ export function checkTaxonomy(document) {
93
+ const out = [];
94
+ const structure = (path, message) => { out.push({ code: 'EXTRACT_TAXONOMY_STRUCTURE', path, message }); };
95
+ if (typeof document.prompt !== 'string')
96
+ structure('prompt', 'prompt must be a string (the overall instructions).');
97
+ const outputSchema = document.outputSchema;
98
+ if (!isRecord(outputSchema)) {
99
+ structure('outputSchema', 'outputSchema must be an object.');
100
+ return out;
101
+ }
102
+ if (outputSchema.$defs !== undefined && !isRecord(outputSchema.$defs)) {
103
+ structure('outputSchema.$defs', '$defs must be an object of field types.');
104
+ }
105
+ else if (isRecord(outputSchema.$defs)) {
106
+ for (const [key, def] of Object.entries(outputSchema.$defs)) {
107
+ if (!isRecord(def))
108
+ structure(`outputSchema.$defs${quoteKey(key)}`, 'A field type must be an object.');
109
+ }
110
+ }
111
+ if (outputSchema.type !== undefined && !hasType(outputSchema, 'object'))
112
+ structure('outputSchema.type', 'outputSchema must be of type object.');
113
+ const definitions = isRecord(outputSchema.$defs) ? outputSchema.$defs : undefined;
114
+ referenceFindings(outputSchema, 'outputSchema', new Set(definitions ? Object.keys(definitions) : []), out);
115
+ const { groups, issues } = readOutputSchema(outputSchema);
116
+ for (const issue of issues)
117
+ structure(issue.path, issue.message);
118
+ const groupIdByPathKey = new Map();
119
+ const pathKeys = new Set();
120
+ for (const group of groups) {
121
+ pathKeys.add(group.pathKey);
122
+ if (group.groupId)
123
+ groupIdByPathKey.set(group.pathKey, group.groupId);
124
+ }
125
+ const groupIdOwners = new Map();
126
+ const fieldIdOwners = new Map();
127
+ for (const group of groups) {
128
+ if (!group.multiInstance && !hasType(group.node, 'object')) {
129
+ structure(group.path, 'A field group must be an array of objects (a repeating group) or an object (a single-instance group).');
130
+ }
131
+ if (group.groupId)
132
+ groupIdOwners.set(group.groupId, [...(groupIdOwners.get(group.groupId) ?? []), group.path]);
133
+ if (group.segments.length > 1) {
134
+ const parentPathKey = group.segments.slice(0, -1).join(GROUP_PATH_SEPARATOR);
135
+ const parentId = groupIdByPathKey.get(parentPathKey);
136
+ if (!pathKeys.has(parentPathKey)) {
137
+ out.push({
138
+ code: 'EXTRACT_TAXONOMY_NESTING',
139
+ path: group.path,
140
+ message: `Nested field group "${group.pathKey}" has no parent group "${parentPathKey}" in outputSchema.properties.`,
141
+ });
142
+ }
143
+ else if (parentId !== undefined && group.parentGroupId !== undefined && group.parentGroupId !== parentId) {
144
+ out.push({
145
+ code: 'EXTRACT_TAXONOMY_NESTING',
146
+ path: `${group.path}.${PARENT_FIELD_GROUP_ID_EXTENSION}`,
147
+ message: `${PARENT_FIELD_GROUP_ID_EXTENSION} must be the id of "${parentPathKey}" (${parentId}).`,
148
+ });
149
+ }
150
+ }
151
+ else if (group.parentGroupId !== undefined) {
152
+ out.push({
153
+ code: 'EXTRACT_TAXONOMY_NESTING',
154
+ path: `${group.path}.${PARENT_FIELD_GROUP_ID_EXTENSION}`,
155
+ message: 'A top-level field group must not name a parent group. '
156
+ + `Nest it by renaming it "<parent>${GROUP_PATH_SEPARATOR}${group.pathKey}", or drop its ${PARENT_FIELD_GROUP_ID_EXTENSION} to leave it at the top level.`,
157
+ });
158
+ }
159
+ for (const field of group.fields) {
160
+ if (typeof field.node.$ref !== 'string') {
161
+ out.push({ code: 'EXTRACT_TAXONOMY_REF', path: field.path, message: 'A field must name its field type with "$ref": "#/$defs/<key>".' });
162
+ }
163
+ if (field.fieldId)
164
+ fieldIdOwners.set(field.fieldId, [...(fieldIdOwners.get(field.fieldId) ?? []), field.path]);
165
+ }
166
+ }
167
+ for (const [id, owners] of groupIdOwners) {
168
+ if (owners.length > 1)
169
+ out.push({ code: 'EXTRACT_TAXONOMY_DUPLICATE_ID', path: owners[0], message: `Field group id "${id}" is used by more than one group: ${owners.join(', ')}.` });
170
+ }
171
+ for (const [id, owners] of fieldIdOwners) {
172
+ if (owners.length > 1)
173
+ out.push({ code: 'EXTRACT_TAXONOMY_DUPLICATE_ID', path: owners[0], message: `Field id "${id}" is used by more than one field: ${owners.join(', ')}.` });
174
+ }
175
+ if (definitions) {
176
+ for (const [key, def] of Object.entries(definitions)) {
177
+ const path = `outputSchema.$defs${quoteKey(key)}`;
178
+ if (!DEFS_KEY_PATTERN.test(key)) {
179
+ out.push({
180
+ code: 'EXTRACT_TAXONOMY_FIELD_TYPE',
181
+ path,
182
+ message: `Field type key "${key}" must use only letters, digits, '.', '_' or '-', so the $ref that names it needs no escaping.`,
183
+ });
184
+ }
185
+ const title = isRecord(def) ? def.title : undefined;
186
+ if (typeof title !== 'string' || title.length === 0) {
187
+ out.push({ code: 'EXTRACT_TAXONOMY_FIELD_TYPE', path: `${path}.title`, message: `Field type "${key}" needs a non-empty title.` });
188
+ }
189
+ }
190
+ }
191
+ limitFindings(document, out);
192
+ return out;
193
+ }
194
+ /** The superseded private `{ taxonomy, fieldTypes }` document. */
195
+ export function isLegacyTaxonomy(value) {
196
+ if (!isRecord(value) || isReadableTaxonomy(value))
197
+ return false;
198
+ return 'taxonomy' in value || 'fieldTypes' in value;
199
+ }
200
+ /** A `{ prompt, outputSchema }` document — the shape `schema set` takes. */
201
+ export function isReadableTaxonomy(value) {
202
+ return isRecord(value) && typeof value.prompt === 'string' && isRecord(value.outputSchema);
203
+ }
204
+ /** A bare JSON Schema — `{ type: 'object', properties }` with no `prompt` around it (flow-schema `readExtractionOutputSchema`). */
205
+ export function isBareJsonSchema(value) {
206
+ return isRecord(value) && !isRecord(value.outputSchema) && (isRecord(value.properties) || value.type === 'object');
207
+ }
@@ -0,0 +1,92 @@
1
+ import { isRecord } from '../../../core/node-envelope.js';
2
+ /** Vendor extension carrying a field group's stable id. */
3
+ export declare const FIELD_GROUP_ID_EXTENSION = "x-uipath-field-group-id";
4
+ /** Vendor extension carrying a field's stable id. */
5
+ export declare const FIELD_ID_EXTENSION = "x-uipath-field-id";
6
+ /** Vendor extension naming the group a nested group hangs under. */
7
+ export declare const PARENT_FIELD_GROUP_ID_EXTENSION = "x-uipath-parent-field-group-id";
8
+ /** Vendor extension holding business checks, which reference fields by id. */
9
+ export declare const BUSINESS_CHECKS_EXTENSION = "x-uipath-business-checks";
10
+ /** Joins the segments of a nested field group's flattened property key: `Invoice > Line items`. */
11
+ export declare const GROUP_PATH_SEPARATOR = " > ";
12
+ type Json = Record<string, unknown>;
13
+ export { isRecord };
14
+ /** One problem with the taxonomy's shape, at a path into the schema document. */
15
+ export interface TaxonomyIssue {
16
+ /** Dot/bracket path into the document, e.g. `outputSchema.properties["Invoice"]`. */
17
+ path: string;
18
+ message: string;
19
+ }
20
+ export interface TaxonomyField {
21
+ name: string;
22
+ node: Json;
23
+ fieldId?: string;
24
+ path: string;
25
+ }
26
+ export interface TaxonomyGroup {
27
+ /** The property key, which for a nested group is its full path. */
28
+ pathKey: string;
29
+ segments: string[];
30
+ node: Json;
31
+ groupId?: string;
32
+ parentGroupId?: string;
33
+ /** True when the group repeats, carrying its fields under `items`. */
34
+ multiInstance: boolean;
35
+ fields: TaxonomyField[];
36
+ path: string;
37
+ }
38
+ export declare function hasType(node: Json, wanted: string): boolean;
39
+ export declare const quoteKey: (key: string) => string;
40
+ /**
41
+ * The field groups of an output schema with their fields, and the containers
42
+ * that could not be read as either. Every entry of the root `properties` is a
43
+ * group; a repeating group (`type: 'array'`) holds its fields under
44
+ * `items.properties`, a single one directly under `properties`. Nesting is by
45
+ * name: a nested group is another root entry keyed by its full path.
46
+ */
47
+ export declare function readOutputSchema(outputSchema: Json): {
48
+ groups: TaxonomyGroup[];
49
+ issues: TaxonomyIssue[];
50
+ };
51
+ /** Where a new id comes from: a group by its key, a field by its group's id and its name. */
52
+ export interface TaxonomyMint {
53
+ group(pathKey: string): string;
54
+ field(groupId: string, name: string): string;
55
+ }
56
+ /** The ids compile mints for one node: deterministic, so a recompile mints the same. */
57
+ export declare function derivedTaxonomyMint(flowId: string, nodeId: string): TaxonomyMint;
58
+ /** What {@link settleTaxonomyIds} did, counted as `nodes schema set` reports it. */
59
+ export interface TaxonomyIdCounts {
60
+ groupIdsPreserved: number;
61
+ groupIdsMinted: number;
62
+ fieldIdsPreserved: number;
63
+ fieldIdsMinted: number;
64
+ businessChecksDropped: number;
65
+ }
66
+ /**
67
+ * `document` with every field group and field given an id: its own when it has
68
+ * one, else the one the entry of the same place had in `existing`, else a new
69
+ * one from `mint`; and every nested group's parent reference set to its
70
+ * parent's id. Business checks that name an id no longer in the document are
71
+ * dropped. A document with no `outputSchema` object is returned as given.
72
+ * Never mutates its arguments.
73
+ *
74
+ * A nested group is matched only under its parent's OLD path, and only while
75
+ * the parent itself survived; a field only within the group of the same id.
76
+ */
77
+ export declare function settleTaxonomyIds(document: Json, existing: Json | undefined, mint: TaxonomyMint): {
78
+ document: Json;
79
+ counts: TaxonomyIdCounts;
80
+ };
81
+ /**
82
+ * Fill in the keywords the Schema Editor needs to open the document, wherever
83
+ * they follow from what is there (uipath-cli `close-object-schemas.ts`, which
84
+ * `nodes schema set` runs): every object is closed (`additionalProperties:
85
+ * false`) and lists every property in `required` (optionality is the
86
+ * `[type, "null"]` union, not omission), and the root is an object with a
87
+ * `$defs`. For instance `{ type: ['object', 'null'], properties: { Total: … } }`
88
+ * gains `additionalProperties: false, required: ['Total']`. Without them the
89
+ * editor shows "Could not load schema". MUTATES `outputSchema`; a malformed
90
+ * container is left as it is, for `check` to report.
91
+ */
92
+ export declare function closeObjectSchemas(outputSchema: unknown): void;
@@ -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
+ }
@@ -262,7 +262,7 @@ export declare function rerunAgainstLine(label: string, field: string, connectio
262
262
  /** The terminal report's line for a candidate that resolved every requested lookup. */
263
263
  export declare function candidateResolvesAllLine(label: string, lookups: number): string;
264
264
  /** The terminal report's line for a candidate whose collection was read to the end. */
265
- export declare function candidateExhaustedLine(label: string, field: string, scanned: number): string;
265
+ export declare function candidateExhaustedLine(label: string, field: string, scanned: number, absentBy?: string): string;
266
266
  /** The terminal report's line for a candidate whose lookup failed for another reason: the error, verbatim. */
267
267
  export declare function candidateErrorLine(label: string, error: unknown): string;
268
268
  /**
@@ -285,7 +285,7 @@ export declare function collectionListingHint(connectorKey: string, collection:
285
285
  export declare function pinnedConnectionExhaustedMessage(first: string, connectorKey: string, othersCount: number, othersListing: string, hint: string): string;
286
286
  /** The listing of other connections itself failed; the original lookup failure is what the author asked about. */
287
287
  export declare function candidateListingFailedMessage(first: string, error: unknown): string;
288
- export declare function onlyConnectionMessage(first: string, connectorKey: string, hint: string): string;
288
+ export declare function onlyConnectionMessage(first: string, connectorKey: string, hint: string, byAbsent?: boolean): string;
289
289
  /** Two or more candidates resolve everything: reported, never chosen between. */
290
290
  export declare function severalConnectionsResolveMessage(count: number, connectorKey: string, listing: string): string;
291
291
  /**
@@ -299,7 +299,9 @@ export declare function noConnectionResolvesMessage(connectorKey: string, first:
299
299
  by: string;
300
300
  value: string;
301
301
  collection: string;
302
- }, lines: readonly string[], connectionId: string): string;
302
+ }, lines: readonly string[], connectionId: string, absent?: {
303
+ otherBys?: readonly string[];
304
+ }): string;
303
305
  export declare function eventParentFieldsMessage(): string;
304
306
  export declare function eventAllObjectsMessage(): string;
305
307
  /** A Generic event fires for ONE object; name it. `rows` is the `triggers objects` catalog. */