@uipath/data-fabric-tool 1.204.0-preview.255 → 1.205.0-preview.256
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.
- package/dist/THIRD-PARTY-NOTICES.md +34 -3
- package/dist/entities-inline-9s390vev.js +2777 -0
- package/dist/federated-payload-nfjfj8v9.js +7333 -0
- package/dist/index.js +8 -4
- package/dist/packager-tool-2wp1xwz4.js +101 -0
- package/dist/packager-tool-m0btwdsf.js +884 -0
- package/dist/packager-tool-pz3g5mpk.js +2172 -0
- package/dist/packager-tool-r918t36v.js +2240 -0
- package/dist/{packager-tool-awbse7ws.js → packager-tool-w9r3qa12.js} +7226 -15066
- package/dist/packager-tool-xnrdmg37.js +6410 -0
- package/dist/packager-tool.js +5 -1724
- package/dist/tool.js +6 -3
- package/package.json +2 -2
- package/dist/packager-tool-wq4qexcc.js +0 -239
|
@@ -0,0 +1,2240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataFabricDirectoryEntityTypeName,
|
|
3
|
+
EntityClass,
|
|
4
|
+
EntityFieldDataType,
|
|
5
|
+
UiPath,
|
|
6
|
+
getLoginStatusAsync
|
|
7
|
+
} from "./packager-tool-w9r3qa12.js";
|
|
8
|
+
import {
|
|
9
|
+
fail,
|
|
10
|
+
failInvalidArgument,
|
|
11
|
+
readFileBinary,
|
|
12
|
+
readJsonInput,
|
|
13
|
+
requireDestructiveConfirmation
|
|
14
|
+
} from "./packager-tool-2wp1xwz4.js";
|
|
15
|
+
import {
|
|
16
|
+
Option,
|
|
17
|
+
OutputFormatter,
|
|
18
|
+
RESULTS,
|
|
19
|
+
createHiddenDeprecatedTenantOption,
|
|
20
|
+
extractErrorMessage,
|
|
21
|
+
findFilePayloadKeys,
|
|
22
|
+
findInvalidFieldMetadata,
|
|
23
|
+
findIsUniqueInUpdateFields,
|
|
24
|
+
getFileSystem,
|
|
25
|
+
logger,
|
|
26
|
+
processContext,
|
|
27
|
+
runChecks,
|
|
28
|
+
validateChoiceValueDisplayName,
|
|
29
|
+
validateChoiceValueName,
|
|
30
|
+
validateFieldsPayload,
|
|
31
|
+
validateQueryAggregates,
|
|
32
|
+
validateQueryFilter,
|
|
33
|
+
validateSchemaMetadata
|
|
34
|
+
} from "./packager-tool-xnrdmg37.js";
|
|
35
|
+
import {
|
|
36
|
+
catchError,
|
|
37
|
+
validateName
|
|
38
|
+
} from "./packager-tool-m0btwdsf.js";
|
|
39
|
+
import {
|
|
40
|
+
__require
|
|
41
|
+
} from "./packager-tool-1de529jm.js";
|
|
42
|
+
// package.json
|
|
43
|
+
var package_default = {
|
|
44
|
+
name: "@uipath/data-fabric-tool",
|
|
45
|
+
author: "UiPath",
|
|
46
|
+
license: "SEE LICENSE IN LICENSE.txt",
|
|
47
|
+
version: "1.205.0-preview.256",
|
|
48
|
+
description: "Manage Data Fabric entities and records.",
|
|
49
|
+
publishConfig: {
|
|
50
|
+
registry: "https://npm.pkg.github.com/"
|
|
51
|
+
},
|
|
52
|
+
type: "module",
|
|
53
|
+
main: "./dist/tool.js",
|
|
54
|
+
exports: {
|
|
55
|
+
".": "./dist/tool.js",
|
|
56
|
+
"./packager-tool": "./dist/packager-tool.js"
|
|
57
|
+
},
|
|
58
|
+
bin: {
|
|
59
|
+
"data-fabric-tool": "./dist/index.js"
|
|
60
|
+
},
|
|
61
|
+
files: [
|
|
62
|
+
"dist"
|
|
63
|
+
],
|
|
64
|
+
scripts: {
|
|
65
|
+
build: "bun ../../tools/build-tool.ts",
|
|
66
|
+
package: "bun run build && bun pm pack",
|
|
67
|
+
test: "vitest run",
|
|
68
|
+
"test:coverage": "vitest run --coverage",
|
|
69
|
+
lint: "biome check .",
|
|
70
|
+
"lint:fix": "biome check --write ."
|
|
71
|
+
},
|
|
72
|
+
devDependencies: {
|
|
73
|
+
commander: "^14.0.3",
|
|
74
|
+
"@uipath/common": "workspace:*",
|
|
75
|
+
"@uipath/auth": "workspace:*",
|
|
76
|
+
"@uipath/filesystem": "workspace:*",
|
|
77
|
+
"@uipath/uipath-typescript": "^1.8.0",
|
|
78
|
+
"@uipath/integrationservice-sdk": "workspace:*",
|
|
79
|
+
"@types/node": "^25.5.2",
|
|
80
|
+
"@uipath/packager-tool-datafabric": "workspace:*",
|
|
81
|
+
"@uipath/solutionpackager-tool-core": "workspace:*",
|
|
82
|
+
typescript: "^7.0.2"
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/utils/sdk-client.ts
|
|
87
|
+
var getAuthenticatedContext = async () => {
|
|
88
|
+
const status = await getLoginStatusAsync();
|
|
89
|
+
if (status.loginStatus !== "Logged in" || !status.accessToken || !status.baseUrl) {
|
|
90
|
+
throw new Error(status.hint ?? "Not logged in. Run 'uip login' first.");
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
accessToken: status.accessToken,
|
|
94
|
+
baseUrl: status.baseUrl,
|
|
95
|
+
organizationName: status.organizationName,
|
|
96
|
+
tenantName: status.tenantName
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
var createDataFabricClient = async (tenantOverride) => {
|
|
100
|
+
const ctx = await getAuthenticatedContext();
|
|
101
|
+
return new UiPath({
|
|
102
|
+
secret: ctx.accessToken,
|
|
103
|
+
baseUrl: ctx.baseUrl,
|
|
104
|
+
orgName: ctx.organizationName,
|
|
105
|
+
tenantName: tenantOverride ?? ctx.tenantName
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
var connectOrFail = async (tenantOverride) => {
|
|
109
|
+
const [clientError, sdk] = await catchError(createDataFabricClient(tenantOverride));
|
|
110
|
+
if (clientError) {
|
|
111
|
+
fail("Error connecting to Data Fabric", await extractErrorMessage(clientError));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
return sdk;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/commands/choice-sets.ts
|
|
118
|
+
var OUTPUT_CODES = {
|
|
119
|
+
ChoiceSetList: "ChoiceSetList",
|
|
120
|
+
ChoiceSetValues: "ChoiceSetValues",
|
|
121
|
+
ChoiceSetCreated: "ChoiceSetCreated",
|
|
122
|
+
ChoiceSetUpdated: "ChoiceSetUpdated",
|
|
123
|
+
ChoiceSetDeleted: "ChoiceSetDeleted",
|
|
124
|
+
ChoiceSetValueCreated: "ChoiceSetValueCreated",
|
|
125
|
+
ChoiceSetValueUpdated: "ChoiceSetValueUpdated",
|
|
126
|
+
ChoiceSetValuesDeleted: "ChoiceSetValuesDeleted"
|
|
127
|
+
};
|
|
128
|
+
var CHOICE_SETS_LIST_EXAMPLES = [
|
|
129
|
+
{
|
|
130
|
+
Description: "List all Data Fabric choice sets. The returned 'id' is the value to pass as 'choiceSetId' on a CHOICE_SET_SINGLE/CHOICE_SET_MULTIPLE entity field, or to 'df choice-sets list-values <id>'. " + "Scope modes: omit both flags to see only tenant-level choice sets (the default); pass '--folder-key <uuid>' to see only that folder's choice sets; pass '--include-folders' to see tenant + folder choice sets together. '--folder-key' and '--include-folders' are mutually exclusive.",
|
|
131
|
+
Command: "uip df choice-sets list",
|
|
132
|
+
Output: {
|
|
133
|
+
Code: OUTPUT_CODES.ChoiceSetList,
|
|
134
|
+
Data: [
|
|
135
|
+
{
|
|
136
|
+
id: "c1d2e3f4-0000-0000-0000-000000000001",
|
|
137
|
+
name: "ExpenseTypes",
|
|
138
|
+
displayName: "Expense Types",
|
|
139
|
+
description: "Categories of expenses",
|
|
140
|
+
folderId: "f1000000-0000-0000-0000-000000000001",
|
|
141
|
+
createdBy: "u1000000-0000-0000-0000-000000000001",
|
|
142
|
+
updatedBy: "u1000000-0000-0000-0000-000000000001",
|
|
143
|
+
createdTime: "2026-01-01T00:00:00Z",
|
|
144
|
+
updatedTime: "2026-01-02T00:00:00Z"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
];
|
|
150
|
+
var CHOICE_SETS_GET_EXAMPLES = [
|
|
151
|
+
{
|
|
152
|
+
Description: "List the values of a choice set. The 'numberId' on each value is the integer to pass when inserting or updating a record into a CHOICE_SET_SINGLE field (or in an array for CHOICE_SET_MULTIPLE).",
|
|
153
|
+
Command: "uip df choice-sets list-values c1d2e3f4-0000-0000-0000-000000000001 --limit 2",
|
|
154
|
+
Output: {
|
|
155
|
+
Code: OUTPUT_CODES.ChoiceSetValues,
|
|
156
|
+
Data: {
|
|
157
|
+
items: [
|
|
158
|
+
{
|
|
159
|
+
id: "v1000000-0000-0000-0000-000000000001",
|
|
160
|
+
name: "travel",
|
|
161
|
+
displayName: "Travel",
|
|
162
|
+
numberId: 0
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "v1000000-0000-0000-0000-000000000002",
|
|
166
|
+
name: "meals",
|
|
167
|
+
displayName: "Meals",
|
|
168
|
+
numberId: 1
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
totalCount: 2,
|
|
172
|
+
hasNextPage: false
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
var CHOICE_SETS_CREATE_EXAMPLES = [
|
|
178
|
+
{
|
|
179
|
+
Description: "Create a choice set. The returned 'ID' is used as 'choiceSetId' on CHOICE_SET_SINGLE/CHOICE_SET_MULTIPLE entity fields. Add values with 'df choice-set-values create'.",
|
|
180
|
+
Command: 'uip df choice-sets create ExpenseTypes --display-name "Expense Types" --description "Categories of expenses"',
|
|
181
|
+
Output: {
|
|
182
|
+
Code: OUTPUT_CODES.ChoiceSetCreated,
|
|
183
|
+
Data: { ID: "c1d2e3f4-0000-0000-0000-000000000001" }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
];
|
|
187
|
+
var CHOICE_SETS_UPDATE_EXAMPLES = [
|
|
188
|
+
{
|
|
189
|
+
Description: "Update a choice set's display name and/or description. At least one of --display-name or --description is required.",
|
|
190
|
+
Command: 'uip df choice-sets update c1d2e3f4-0000-0000-0000-000000000001 --display-name "Expense Categories"',
|
|
191
|
+
Output: {
|
|
192
|
+
Code: OUTPUT_CODES.ChoiceSetUpdated,
|
|
193
|
+
Data: { ID: "c1d2e3f4-0000-0000-0000-000000000001" }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
var CHOICE_SETS_DELETE_EXAMPLES = [
|
|
198
|
+
{
|
|
199
|
+
Description: "Delete a choice set (irreversible — requires --confirm and --reason).",
|
|
200
|
+
Command: 'uip df choice-sets delete c1d2e3f4-0000-0000-0000-000000000001 --confirm --reason "no longer used"',
|
|
201
|
+
Output: {
|
|
202
|
+
Code: OUTPUT_CODES.ChoiceSetDeleted,
|
|
203
|
+
Data: {
|
|
204
|
+
ID: "c1d2e3f4-0000-0000-0000-000000000001",
|
|
205
|
+
Reason: "no longer used"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
];
|
|
210
|
+
var registerChoiceSetsCommand = (program) => {
|
|
211
|
+
const choiceSets = program.command("choice-sets").description("Manage Data Fabric choice sets — the enumerated value lists referenced by CHOICE_SET_SINGLE/CHOICE_SET_MULTIPLE entity fields. " + "Use 'list'/'list-values' to inspect, and 'create'/'update'/'delete' to manage them. Manage individual values with 'df choice-set-values'.");
|
|
212
|
+
choiceSets.command("list").description("List all Data Fabric choice sets").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--folder-key <key>", "Folder key (GUID) to scope the listing to a specific folder").option("--include-folders", "List tenant-level choice sets together with choice sets from every folder you can see. Mutually exclusive with --folder-key.").examples(CHOICE_SETS_LIST_EXAMPLES).trackedAction(processContext, async (options) => {
|
|
213
|
+
if (options.folderKey !== undefined && options.includeFolders === true) {
|
|
214
|
+
return fail("--folder-key and --include-folders are mutually exclusive", "Use --folder-key to list a single folder, or --include-folders to list tenant + folder choice sets together.");
|
|
215
|
+
}
|
|
216
|
+
const sdk = await connectOrFail(options.tenant);
|
|
217
|
+
if (!sdk)
|
|
218
|
+
return;
|
|
219
|
+
const listOpts = {
|
|
220
|
+
...options.folderKey !== undefined && {
|
|
221
|
+
folderKey: options.folderKey
|
|
222
|
+
},
|
|
223
|
+
...options.includeFolders === true && {
|
|
224
|
+
includeFolderChoiceSets: true
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const [listError, result] = await catchError(sdk.entities.choicesets.getAll(Object.keys(listOpts).length > 0 ? listOpts : undefined));
|
|
228
|
+
if (listError) {
|
|
229
|
+
return fail("Error listing choice sets", await extractErrorMessage(listError));
|
|
230
|
+
}
|
|
231
|
+
OutputFormatter.success({
|
|
232
|
+
Result: RESULTS.Success,
|
|
233
|
+
Code: OUTPUT_CODES.ChoiceSetList,
|
|
234
|
+
Data: result ?? []
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
choiceSets.command("list-values").description("List the values of a Data Fabric choice set").argument("<choice-set-id>", "Choice set ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-l, --limit <number>", "Number of values to return per page", "50").option("-o, --offset <number>", "Start from the page containing this record index (rounded down to the nearest page boundary; mutually exclusive with --cursor)").option("--cursor <cursor>", "Pagination cursor from a previous response to fetch the next page").option("--folder-key <key>", "Folder key (GUID) of the folder containing the choice set (for folder-scoped choice sets)").examples(CHOICE_SETS_GET_EXAMPLES).trackedAction(processContext, async (choiceSetId, options) => {
|
|
238
|
+
const pageSize = Number(options.limit ?? "50");
|
|
239
|
+
if (Number.isNaN(pageSize) || pageSize < 1) {
|
|
240
|
+
return fail("Invalid --limit value", "Provide a positive integer for --limit.");
|
|
241
|
+
}
|
|
242
|
+
if (options.cursor !== undefined && options.offset !== undefined) {
|
|
243
|
+
return fail("--offset and --cursor are mutually exclusive", "Use --offset to jump to a position by record count, or --cursor to continue from a previous response.");
|
|
244
|
+
}
|
|
245
|
+
let jumpToPage;
|
|
246
|
+
if (options.offset !== undefined) {
|
|
247
|
+
const offsetValue = Number(options.offset);
|
|
248
|
+
if (Number.isNaN(offsetValue) || offsetValue < 0) {
|
|
249
|
+
return fail("Invalid --offset value", "Provide a non-negative integer for --offset.");
|
|
250
|
+
}
|
|
251
|
+
jumpToPage = Math.floor(offsetValue / pageSize) + 1;
|
|
252
|
+
}
|
|
253
|
+
const sdk = await connectOrFail(options.tenant);
|
|
254
|
+
if (!sdk)
|
|
255
|
+
return;
|
|
256
|
+
const paginationOptions = options.cursor !== undefined ? { pageSize, cursor: { value: options.cursor } } : jumpToPage !== undefined ? { pageSize, jumpToPage } : { pageSize };
|
|
257
|
+
if (options.folderKey !== undefined) {
|
|
258
|
+
paginationOptions.folderKey = options.folderKey;
|
|
259
|
+
}
|
|
260
|
+
const [getError, result] = await catchError(sdk.entities.choicesets.getById(choiceSetId, paginationOptions));
|
|
261
|
+
if (getError) {
|
|
262
|
+
return fail(`Error getting choice set '${choiceSetId}'`, await extractErrorMessage(getError));
|
|
263
|
+
}
|
|
264
|
+
OutputFormatter.success({
|
|
265
|
+
Result: RESULTS.Success,
|
|
266
|
+
Code: OUTPUT_CODES.ChoiceSetValues,
|
|
267
|
+
Data: result
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
choiceSets.command("create").description("Create a new Data Fabric choice set").argument("<name>", "Choice set name (must start with a letter; letters, numbers, and underscores only)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--display-name <name>", "Human-readable display name").option("--description <text>", "Choice set description").option("--folder-key <uuid>", "UUID of the folder to place the choice set in (defaults to the tenant-level folder)").examples(CHOICE_SETS_CREATE_EXAMPLES).trackedAction(processContext, async (name, options) => {
|
|
271
|
+
const nameErr = validateName(name, "choice set");
|
|
272
|
+
if (nameErr)
|
|
273
|
+
return fail(nameErr.message, nameErr.instructions);
|
|
274
|
+
const metadataErr = validateSchemaMetadata({
|
|
275
|
+
displayName: options.displayName,
|
|
276
|
+
description: options.description
|
|
277
|
+
}, "Choice set");
|
|
278
|
+
if (metadataErr)
|
|
279
|
+
return fail(metadataErr.message, metadataErr.instructions);
|
|
280
|
+
const sdk = await connectOrFail(options.tenant);
|
|
281
|
+
if (!sdk)
|
|
282
|
+
return;
|
|
283
|
+
const createOpts = {
|
|
284
|
+
...options.displayName !== undefined && {
|
|
285
|
+
displayName: options.displayName
|
|
286
|
+
},
|
|
287
|
+
...options.description !== undefined && {
|
|
288
|
+
description: options.description
|
|
289
|
+
},
|
|
290
|
+
...options.folderKey !== undefined && {
|
|
291
|
+
folderKey: options.folderKey
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const choiceSetService = sdk.entities.choicesets;
|
|
295
|
+
const [createError, choiceSetId] = await catchError(choiceSetService.create(name, Object.keys(createOpts).length > 0 ? createOpts : undefined));
|
|
296
|
+
if (createError) {
|
|
297
|
+
return fail("Error creating choice set", await extractErrorMessage(createError));
|
|
298
|
+
}
|
|
299
|
+
OutputFormatter.success({
|
|
300
|
+
Result: RESULTS.Success,
|
|
301
|
+
Code: OUTPUT_CODES.ChoiceSetCreated,
|
|
302
|
+
Data: { ID: choiceSetId }
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
choiceSets.command("update").description("Update the metadata of a Data Fabric choice set").argument("<choice-set-id>", "Choice set ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--display-name <name>", "New display name").option("--description <text>", "New description").option("--folder-key <key>", "Folder key (GUID) of the folder containing the choice set (for folder-scoped choice sets)").examples(CHOICE_SETS_UPDATE_EXAMPLES).trackedAction(processContext, async (choiceSetId, options) => {
|
|
306
|
+
if (options.displayName === undefined || options.description === undefined) {
|
|
307
|
+
return fail("choice-sets update requires both --display-name and --description", "The server rejects a partial update with 'DisplayName is required.' or Internal Server Error. To change one field, run 'uip df choice-sets list' first to read the current value of the other, then re-send both with --display-name and --description.");
|
|
308
|
+
}
|
|
309
|
+
const metadataErr = validateSchemaMetadata({
|
|
310
|
+
displayName: options.displayName,
|
|
311
|
+
description: options.description
|
|
312
|
+
}, "Choice set");
|
|
313
|
+
if (metadataErr)
|
|
314
|
+
return fail(metadataErr.message, metadataErr.instructions);
|
|
315
|
+
const sdk = await connectOrFail(options.tenant);
|
|
316
|
+
if (!sdk)
|
|
317
|
+
return;
|
|
318
|
+
const updateOpts = {
|
|
319
|
+
...options.displayName !== undefined && {
|
|
320
|
+
displayName: options.displayName
|
|
321
|
+
},
|
|
322
|
+
...options.description !== undefined && {
|
|
323
|
+
description: options.description
|
|
324
|
+
},
|
|
325
|
+
...options.folderKey !== undefined && {
|
|
326
|
+
folderKey: options.folderKey
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const choiceSetService = sdk.entities.choicesets;
|
|
330
|
+
const [updateError] = await catchError(choiceSetService.updateById(choiceSetId, updateOpts));
|
|
331
|
+
if (updateError) {
|
|
332
|
+
return fail(`Error updating choice set '${choiceSetId}'`, await extractErrorMessage(updateError));
|
|
333
|
+
}
|
|
334
|
+
OutputFormatter.success({
|
|
335
|
+
Result: RESULTS.Success,
|
|
336
|
+
Code: OUTPUT_CODES.ChoiceSetUpdated,
|
|
337
|
+
Data: { ID: choiceSetId }
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
choiceSets.command("delete").description("Delete a Data Fabric choice set (irreversible)").argument("<choice-set-id>", "Choice set ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-y, --yes", "Acknowledge this is an irreversible operation").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Reason for the deletion — echoed back in the response so the caller can log it").option("--folder-key <key>", "Folder key (GUID) of the folder containing the choice set (for folder-scoped choice sets)").examples(CHOICE_SETS_DELETE_EXAMPLES).trackedAction(processContext, async (choiceSetId, options) => {
|
|
341
|
+
const reason = requireDestructiveConfirmation(options, `delete choice set '${choiceSetId}'`, 'Pass --reason "<text>" to record why the choice set is being deleted.');
|
|
342
|
+
if (reason === null)
|
|
343
|
+
return;
|
|
344
|
+
const sdk = await connectOrFail(options.tenant);
|
|
345
|
+
if (!sdk)
|
|
346
|
+
return;
|
|
347
|
+
const deleteOpts = {
|
|
348
|
+
...options.folderKey !== undefined && {
|
|
349
|
+
folderKey: options.folderKey
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
const choiceSetService = sdk.entities.choicesets;
|
|
353
|
+
const [deleteError] = await catchError(choiceSetService.deleteById(choiceSetId, Object.keys(deleteOpts).length > 0 ? deleteOpts : undefined));
|
|
354
|
+
if (deleteError) {
|
|
355
|
+
return fail(`Error deleting choice set '${choiceSetId}'`, await extractErrorMessage(deleteError));
|
|
356
|
+
}
|
|
357
|
+
OutputFormatter.success({
|
|
358
|
+
Result: RESULTS.Success,
|
|
359
|
+
Code: OUTPUT_CODES.ChoiceSetDeleted,
|
|
360
|
+
Data: { ID: choiceSetId, Reason: reason }
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
var CHOICE_SET_VALUES_CREATE_EXAMPLES = [
|
|
365
|
+
{
|
|
366
|
+
Description: "Add a value to a choice set. The returned 'numberId' is the integer to pass when inserting or updating records into a CHOICE_SET_SINGLE field (or in an array for CHOICE_SET_MULTIPLE).",
|
|
367
|
+
Command: 'uip df choice-set-values create c1d2e3f4-0000-0000-0000-000000000001 travel --display-name "Travel"',
|
|
368
|
+
Output: {
|
|
369
|
+
Code: OUTPUT_CODES.ChoiceSetValueCreated,
|
|
370
|
+
Data: {
|
|
371
|
+
id: "v1000000-0000-0000-0000-000000000001",
|
|
372
|
+
name: "travel",
|
|
373
|
+
displayName: "Travel",
|
|
374
|
+
numberId: 0
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
];
|
|
379
|
+
var CHOICE_SET_VALUES_UPDATE_EXAMPLES = [
|
|
380
|
+
{
|
|
381
|
+
Description: "Update the display name of an existing choice set value. Find value IDs with 'df choice-sets list-values <choice-set-id>'.",
|
|
382
|
+
Command: 'uip df choice-set-values update c1d2e3f4-0000-0000-0000-000000000001 v1000000-0000-0000-0000-000000000001 "Business Travel"',
|
|
383
|
+
Output: {
|
|
384
|
+
Code: OUTPUT_CODES.ChoiceSetValueUpdated,
|
|
385
|
+
Data: {
|
|
386
|
+
id: "v1000000-0000-0000-0000-000000000001",
|
|
387
|
+
name: "travel",
|
|
388
|
+
displayName: "Business Travel",
|
|
389
|
+
numberId: 0
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
];
|
|
394
|
+
var CHOICE_SET_VALUES_DELETE_EXAMPLES = [
|
|
395
|
+
{
|
|
396
|
+
Description: "Delete one or more values from a choice set (irreversible — requires --confirm and --reason). Pass value IDs as a comma-separated list.",
|
|
397
|
+
Command: 'uip df choice-set-values delete c1d2e3f4-0000-0000-0000-000000000001 --ids v1000000-0000-0000-0000-000000000001,v1000000-0000-0000-0000-000000000002 --confirm --reason "deprecated categories"',
|
|
398
|
+
Output: {
|
|
399
|
+
Code: OUTPUT_CODES.ChoiceSetValuesDeleted,
|
|
400
|
+
Data: {
|
|
401
|
+
ChoiceSetId: "c1d2e3f4-0000-0000-0000-000000000001",
|
|
402
|
+
DeletedIds: [
|
|
403
|
+
"v1000000-0000-0000-0000-000000000001",
|
|
404
|
+
"v1000000-0000-0000-0000-000000000002"
|
|
405
|
+
],
|
|
406
|
+
Reason: "deprecated categories"
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
var registerChoiceSetValuesCommand = (program) => {
|
|
412
|
+
const values = program.command("choice-set-values").description("Manage the individual values of a Data Fabric choice set. " + "Use 'df choice-sets list-values <choice-set-id>' to list existing values and their IDs.");
|
|
413
|
+
values.command("create").description("Add a value to a Data Fabric choice set").argument("<choice-set-id>", "Choice set ID").argument("<name>", "Value name (must start with a letter; letters and numbers only)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--display-name <name>", "Human-readable display name").option("--folder-key <key>", "Folder key (GUID) of the folder containing the choice set (required for folder-scoped choice sets)").examples(CHOICE_SET_VALUES_CREATE_EXAMPLES).trackedAction(processContext, async (choiceSetId, name, options) => {
|
|
414
|
+
const nameErr = validateChoiceValueName(name);
|
|
415
|
+
if (nameErr)
|
|
416
|
+
return fail(nameErr.message, nameErr.instructions);
|
|
417
|
+
if (options.displayName !== undefined) {
|
|
418
|
+
const displayErr = validateChoiceValueDisplayName(options.displayName);
|
|
419
|
+
if (displayErr)
|
|
420
|
+
return fail(displayErr.message, displayErr.instructions);
|
|
421
|
+
}
|
|
422
|
+
const sdk = await connectOrFail(options.tenant);
|
|
423
|
+
if (!sdk)
|
|
424
|
+
return;
|
|
425
|
+
const insertOpts = {
|
|
426
|
+
...options.displayName !== undefined && {
|
|
427
|
+
displayName: options.displayName
|
|
428
|
+
},
|
|
429
|
+
...options.folderKey !== undefined && {
|
|
430
|
+
folderKey: options.folderKey
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const choiceSetService = sdk.entities.choicesets;
|
|
434
|
+
const [createError, result] = await catchError(choiceSetService.insertValueById(choiceSetId, name, Object.keys(insertOpts).length > 0 ? insertOpts : undefined));
|
|
435
|
+
if (createError) {
|
|
436
|
+
return fail(`Error creating value in choice set '${choiceSetId}'`, await extractErrorMessage(createError));
|
|
437
|
+
}
|
|
438
|
+
OutputFormatter.success({
|
|
439
|
+
Result: RESULTS.Success,
|
|
440
|
+
Code: OUTPUT_CODES.ChoiceSetValueCreated,
|
|
441
|
+
Data: result
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
values.command("update").description("Update the display name of a choice set value").argument("<choice-set-id>", "Choice set ID").argument("<value-id>", "Choice set value ID").argument("<display-name>", "New display name for the value").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--folder-key <key>", "Folder key (GUID) of the folder containing the choice set (required for folder-scoped choice sets)").examples(CHOICE_SET_VALUES_UPDATE_EXAMPLES).trackedAction(processContext, async (choiceSetId, valueId, displayName, options) => {
|
|
445
|
+
const displayErr = validateChoiceValueDisplayName(displayName);
|
|
446
|
+
if (displayErr)
|
|
447
|
+
return fail(displayErr.message, displayErr.instructions);
|
|
448
|
+
const sdk = await connectOrFail(options.tenant);
|
|
449
|
+
if (!sdk)
|
|
450
|
+
return;
|
|
451
|
+
const updateOpts = {
|
|
452
|
+
...options.folderKey !== undefined && {
|
|
453
|
+
folderKey: options.folderKey
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const choiceSetService = sdk.entities.choicesets;
|
|
457
|
+
const [updateError, result] = await catchError(choiceSetService.updateValueById(choiceSetId, valueId, displayName, Object.keys(updateOpts).length > 0 ? updateOpts : undefined));
|
|
458
|
+
if (updateError) {
|
|
459
|
+
return fail(`Error updating value '${valueId}' in choice set '${choiceSetId}'`, await extractErrorMessage(updateError));
|
|
460
|
+
}
|
|
461
|
+
OutputFormatter.success({
|
|
462
|
+
Result: RESULTS.Success,
|
|
463
|
+
Code: OUTPUT_CODES.ChoiceSetValueUpdated,
|
|
464
|
+
Data: result
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
values.command("delete").description("Delete values from a Data Fabric choice set (irreversible)").argument("<choice-set-id>", "Choice set ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--ids <ids>", "Comma-separated list of value IDs to delete").option("-y, --yes", "Acknowledge this is an irreversible operation").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Reason for the deletion — echoed back in the response so the caller can log it").option("--folder-key <key>", "Folder key (GUID) of the folder containing the choice set (required for folder-scoped choice sets)").examples(CHOICE_SET_VALUES_DELETE_EXAMPLES).trackedAction(processContext, async (choiceSetId, options) => {
|
|
468
|
+
const valueIds = (options.ids ?? "").split(",").map((id) => id.trim()).filter((id) => id.length > 0);
|
|
469
|
+
if (valueIds.length === 0) {
|
|
470
|
+
return fail("No value IDs provided", "Pass --ids <id,id,...> with at least one value ID to delete.");
|
|
471
|
+
}
|
|
472
|
+
const reason = requireDestructiveConfirmation(options, `delete ${valueIds.length} value(s) from choice set '${choiceSetId}'`, 'Pass --reason "<text>" to record why the values are being deleted.');
|
|
473
|
+
if (reason === null)
|
|
474
|
+
return;
|
|
475
|
+
const sdk = await connectOrFail(options.tenant);
|
|
476
|
+
if (!sdk)
|
|
477
|
+
return;
|
|
478
|
+
const deleteOpts = {
|
|
479
|
+
...options.folderKey !== undefined && {
|
|
480
|
+
folderKey: options.folderKey
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
const choiceSetService = sdk.entities.choicesets;
|
|
484
|
+
const [deleteError] = await catchError(choiceSetService.deleteValuesById(choiceSetId, valueIds, Object.keys(deleteOpts).length > 0 ? deleteOpts : undefined));
|
|
485
|
+
if (deleteError) {
|
|
486
|
+
return fail(`Error deleting values from choice set '${choiceSetId}'`, await extractErrorMessage(deleteError));
|
|
487
|
+
}
|
|
488
|
+
OutputFormatter.success({
|
|
489
|
+
Result: RESULTS.Success,
|
|
490
|
+
Code: OUTPUT_CODES.ChoiceSetValuesDeleted,
|
|
491
|
+
Data: {
|
|
492
|
+
ChoiceSetId: choiceSetId,
|
|
493
|
+
DeletedIds: valueIds,
|
|
494
|
+
Reason: reason
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// src/commands/connectors.ts
|
|
501
|
+
var CONNECTORS_LIST_EXAMPLES = [
|
|
502
|
+
{
|
|
503
|
+
Description: "List the Integration Service connectors supported as federated Data Fabric sources. " + "Backed by the tenant's 'fqs-connectors-list' feature flag — returns an empty list when the flag is unset.",
|
|
504
|
+
Command: "uip df connectors list",
|
|
505
|
+
Output: {
|
|
506
|
+
Code: "SupportedConnectorsList",
|
|
507
|
+
Data: [
|
|
508
|
+
{ ConnectorKey: "uipath-salesforce-sfdc" },
|
|
509
|
+
{ ConnectorKey: "uipath-hubspot" }
|
|
510
|
+
]
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
];
|
|
514
|
+
var registerConnectorsCommand = (program) => {
|
|
515
|
+
const connectors = program.command("connectors").description("Data Fabric federated-source connectors");
|
|
516
|
+
connectors.command("list").description("List Integration Service connectors supported as federated Data Fabric sources").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).examples(CONNECTORS_LIST_EXAMPLES).trackedAction(processContext, async (options) => {
|
|
517
|
+
const [authError, ctx] = await catchError(getAuthenticatedContext());
|
|
518
|
+
if (authError) {
|
|
519
|
+
return fail("Not logged in", await extractErrorMessage(authError));
|
|
520
|
+
}
|
|
521
|
+
const tenantName = options.tenant ?? ctx.tenantName;
|
|
522
|
+
if (!ctx.organizationName || !tenantName) {
|
|
523
|
+
return fail("Missing organization or tenant", "Run 'uip login' and select an organization and tenant, or pass --tenant.");
|
|
524
|
+
}
|
|
525
|
+
const base = ctx.baseUrl.replace(/\/+$/, "");
|
|
526
|
+
const url = `${base}/${encodeURIComponent(ctx.organizationName)}/${encodeURIComponent(tenantName)}/datafabric_/api/FeatureFlag/supportedConnectors`;
|
|
527
|
+
const [requestError, response] = await catchError(fetch(url, {
|
|
528
|
+
method: "GET",
|
|
529
|
+
headers: {
|
|
530
|
+
Authorization: `Bearer ${ctx.accessToken}`,
|
|
531
|
+
Accept: "application/json"
|
|
532
|
+
}
|
|
533
|
+
}));
|
|
534
|
+
if (requestError) {
|
|
535
|
+
return fail("Error listing supported connectors", await extractErrorMessage(requestError));
|
|
536
|
+
}
|
|
537
|
+
if (!response.ok) {
|
|
538
|
+
const [, body] = await catchError(response.text());
|
|
539
|
+
return fail("Error listing supported connectors", `Request failed with status ${response.status}${body ? `: ${body}` : ""}`);
|
|
540
|
+
}
|
|
541
|
+
const [parseError, data] = await catchError(response.json());
|
|
542
|
+
if (parseError) {
|
|
543
|
+
return fail("Error parsing supported connectors response", await extractErrorMessage(parseError));
|
|
544
|
+
}
|
|
545
|
+
OutputFormatter.success({
|
|
546
|
+
Result: RESULTS.Success,
|
|
547
|
+
Code: "SupportedConnectorsList",
|
|
548
|
+
Data: (data.connectors ?? []).map((connectorKey) => ({
|
|
549
|
+
connectorKey
|
|
550
|
+
}))
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// src/commands/directory.ts
|
|
556
|
+
var PRINCIPAL_TYPES = Object.values(DataFabricDirectoryEntityTypeName);
|
|
557
|
+
var DIRECTORY_LIST_EXAMPLES = [
|
|
558
|
+
{
|
|
559
|
+
Description: "List Data Fabric directory principals and their assigned roles.",
|
|
560
|
+
Command: "uip df directory list --limit 50",
|
|
561
|
+
Output: {
|
|
562
|
+
Code: "DirectoryList",
|
|
563
|
+
Data: {
|
|
564
|
+
TotalCount: 1,
|
|
565
|
+
Results: [
|
|
566
|
+
{
|
|
567
|
+
ExternalId: "d1e2f3a4-0000-0000-0000-000000000001",
|
|
568
|
+
Name: "Automation Users",
|
|
569
|
+
Type: "Group",
|
|
570
|
+
Roles: [
|
|
571
|
+
{
|
|
572
|
+
Id: "c1d2e3f4-0000-0000-0000-000000000001",
|
|
573
|
+
Name: "DataWriter"
|
|
574
|
+
}
|
|
575
|
+
],
|
|
576
|
+
IsUIEnabled: true
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
];
|
|
583
|
+
var DIRECTORY_ASSIGN_ROLES_EXAMPLES = [
|
|
584
|
+
{
|
|
585
|
+
Description: "Assign a Data Fabric role to an identity group.",
|
|
586
|
+
Command: "uip df directory assign-roles d1e2f3a4-0000-0000-0000-000000000001 --type Group --role-ids c1d2e3f4-0000-0000-0000-000000000001",
|
|
587
|
+
Output: {
|
|
588
|
+
Code: "DirectoryRolesAssigned",
|
|
589
|
+
Data: [
|
|
590
|
+
{
|
|
591
|
+
PrincipalId: "d1e2f3a4-0000-0000-0000-000000000001",
|
|
592
|
+
RoleIds: ["c1d2e3f4-0000-0000-0000-000000000001"]
|
|
593
|
+
}
|
|
594
|
+
]
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
];
|
|
598
|
+
var DIRECTORY_REVOKE_ROLES_EXAMPLES = [
|
|
599
|
+
{
|
|
600
|
+
Description: "Revoke all direct Data Fabric roles from a principal.",
|
|
601
|
+
Command: 'uip df directory revoke-roles d1e2f3a4-0000-0000-0000-000000000001 --yes --reason "Offboarding"',
|
|
602
|
+
Output: {
|
|
603
|
+
Code: "DirectoryRolesRevoked",
|
|
604
|
+
Data: {
|
|
605
|
+
PrincipalIds: ["d1e2f3a4-0000-0000-0000-000000000001"],
|
|
606
|
+
Reason: "Offboarding"
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
];
|
|
611
|
+
var parsePrincipalType = (value) => {
|
|
612
|
+
const match = PRINCIPAL_TYPES.find((t) => t.toLowerCase() === value.toLowerCase());
|
|
613
|
+
return match ?? null;
|
|
614
|
+
};
|
|
615
|
+
var parseRoleIds = (value) => value.split(",").map((id) => id.trim()).filter((id) => id !== "");
|
|
616
|
+
var parseIntegerOption = (value) => {
|
|
617
|
+
const trimmed = value.trim();
|
|
618
|
+
if (!/^-?\d+$/.test(trimmed)) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
const parsed = Number(trimmed);
|
|
622
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
623
|
+
};
|
|
624
|
+
var registerDirectoryCommand = (program) => {
|
|
625
|
+
const directory = program.command("directory", { hidden: true }).description("Manage Data Fabric directory principals and their role assignments");
|
|
626
|
+
directory.command("list").description("List Data Fabric directory principals and their assigned roles").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--limit <count>", "Maximum number of principals to return", "50").option("--offset <count>", "Number of principals to skip", "0").examples(DIRECTORY_LIST_EXAMPLES).trackedAction(processContext, async (options) => {
|
|
627
|
+
const top = parseIntegerOption(options.limit);
|
|
628
|
+
if (top === null || top <= 0) {
|
|
629
|
+
return fail(`Invalid --limit value '${options.limit}'`, "Provide a positive integer for --limit.");
|
|
630
|
+
}
|
|
631
|
+
const skip = parseIntegerOption(options.offset);
|
|
632
|
+
if (skip === null || skip < 0) {
|
|
633
|
+
return fail(`Invalid --offset value '${options.offset}'`, "Provide a non-negative integer for --offset.");
|
|
634
|
+
}
|
|
635
|
+
const sdk = await connectOrFail(options.tenant);
|
|
636
|
+
if (!sdk)
|
|
637
|
+
return;
|
|
638
|
+
const listOptions = { skip, top };
|
|
639
|
+
const [listError, result] = await catchError(sdk.entities.directory.list(listOptions));
|
|
640
|
+
if (listError) {
|
|
641
|
+
return fail("Error listing directory principals", await extractErrorMessage(listError));
|
|
642
|
+
}
|
|
643
|
+
OutputFormatter.success({
|
|
644
|
+
Result: RESULTS.Success,
|
|
645
|
+
Code: "DirectoryList",
|
|
646
|
+
Data: result
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
directory.command("assign-roles").description("Assign Data Fabric roles to one or more principals").argument("<principal-ids...>", "Principal external ID(s)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).requiredOption("--type <type>", "Principal type: User, Group, or Application").requiredOption("--role-ids <ids>", "Comma-separated Data Fabric role IDs to assign (see 'df roles list')").option("--replace", "Replace the principals' existing Data Fabric roles instead of preserving them").option("--no-ui-access", "Do not enable Data Fabric UI access for the assigned principals").examples(DIRECTORY_ASSIGN_ROLES_EXAMPLES).trackedAction(processContext, async (principalIds, options) => {
|
|
650
|
+
const principalType = parsePrincipalType(options.type);
|
|
651
|
+
if (principalType === null) {
|
|
652
|
+
return fail(`Invalid --type value '${options.type}'`, `Provide one of: ${PRINCIPAL_TYPES.join(", ")}.`);
|
|
653
|
+
}
|
|
654
|
+
const roleIds = parseRoleIds(options.roleIds);
|
|
655
|
+
if (roleIds.length === 0) {
|
|
656
|
+
return fail("No role IDs provided", "Provide at least one role ID via --role-ids. Use 'df roles list' to see available roles.");
|
|
657
|
+
}
|
|
658
|
+
const sdk = await connectOrFail(options.tenant);
|
|
659
|
+
if (!sdk)
|
|
660
|
+
return;
|
|
661
|
+
const assignOptions = {
|
|
662
|
+
...options.replace === true && {
|
|
663
|
+
preserveExisting: false
|
|
664
|
+
},
|
|
665
|
+
...options.uiAccess === false && {
|
|
666
|
+
uiEnabled: false
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
const [assignError, result] = await catchError(sdk.entities.directory.assignRoles(principalIds, principalType, roleIds, assignOptions));
|
|
670
|
+
if (assignError) {
|
|
671
|
+
return fail("Error assigning roles", await extractErrorMessage(assignError));
|
|
672
|
+
}
|
|
673
|
+
OutputFormatter.success({
|
|
674
|
+
Result: RESULTS.Success,
|
|
675
|
+
Code: "DirectoryRolesAssigned",
|
|
676
|
+
Data: result ?? []
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
directory.command("revoke-roles").description("Revoke all direct Data Fabric roles from one or more principals").argument("<principal-ids...>", "Principal external ID(s)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-y, --yes", "Acknowledge this is an irreversible operation").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Reason for the revocation — echoed back in the response so the caller can log it").examples(DIRECTORY_REVOKE_ROLES_EXAMPLES).trackedAction(processContext, async (principalIds, options) => {
|
|
680
|
+
const reason = requireDestructiveConfirmation(options, `revoke all Data Fabric roles from ${principalIds.length} principal(s)`, 'Pass --reason "<text>" to record why the roles are being revoked.');
|
|
681
|
+
if (reason === null)
|
|
682
|
+
return;
|
|
683
|
+
const sdk = await connectOrFail(options.tenant);
|
|
684
|
+
if (!sdk)
|
|
685
|
+
return;
|
|
686
|
+
const [revokeError] = await catchError(sdk.entities.directory.revokeRoles(principalIds));
|
|
687
|
+
if (revokeError) {
|
|
688
|
+
return fail("Error revoking roles", await extractErrorMessage(revokeError));
|
|
689
|
+
}
|
|
690
|
+
OutputFormatter.success({
|
|
691
|
+
Result: RESULTS.Success,
|
|
692
|
+
Code: "DirectoryRolesRevoked",
|
|
693
|
+
Data: {
|
|
694
|
+
PrincipalIds: principalIds,
|
|
695
|
+
Reason: reason
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// src/commands/entities.ts
|
|
702
|
+
var ENTITIES_LIST_EXAMPLES = [
|
|
703
|
+
{
|
|
704
|
+
Description: "List Data Fabric entities. Each entity includes the 'folderId' it lives in — pass that as '--folder-key' on follow-up commands targeting folder-scoped entities. " + "Scope modes: omit both flags to see only tenant-level entities (the default); pass '--folder-key <uuid>' to see only that folder's entities; pass '--include-folders' to see tenant + folder entities together. '--folder-key' and '--include-folders' are mutually exclusive.",
|
|
705
|
+
Command: "uip df entities list --native-only",
|
|
706
|
+
Output: {
|
|
707
|
+
Code: "EntityList",
|
|
708
|
+
Data: [
|
|
709
|
+
{
|
|
710
|
+
id: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
711
|
+
name: "Invoice",
|
|
712
|
+
displayName: "Invoice",
|
|
713
|
+
entityType: "Standard",
|
|
714
|
+
description: "Invoice records",
|
|
715
|
+
folderId: "f1000000-0000-0000-0000-000000000001",
|
|
716
|
+
isRbacEnabled: false,
|
|
717
|
+
fields: [
|
|
718
|
+
{
|
|
719
|
+
id: "f1000000-0000-0000-0000-000000000001",
|
|
720
|
+
name: "amount"
|
|
721
|
+
}
|
|
722
|
+
],
|
|
723
|
+
externalFields: []
|
|
724
|
+
}
|
|
725
|
+
]
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
var ENTITIES_GET_EXAMPLES = [
|
|
730
|
+
{
|
|
731
|
+
Description: "Get entity schema by ID.",
|
|
732
|
+
Command: "uip df entities get a1b2c3d4-0000-0000-0000-000000000001",
|
|
733
|
+
Output: {
|
|
734
|
+
Code: "EntitySchema",
|
|
735
|
+
Data: {
|
|
736
|
+
Id: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
737
|
+
Name: "Invoice",
|
|
738
|
+
DisplayName: "Invoice",
|
|
739
|
+
EntityType: "Standard",
|
|
740
|
+
Description: "Invoice records",
|
|
741
|
+
IsRbacEnabled: false,
|
|
742
|
+
Fields: [
|
|
743
|
+
{
|
|
744
|
+
Id: "f1000000-0000-0000-0000-000000000002",
|
|
745
|
+
Name: "amount",
|
|
746
|
+
DisplayName: "Amount",
|
|
747
|
+
FieldDataType: {
|
|
748
|
+
Name: "DECIMAL",
|
|
749
|
+
DecimalPrecision: 2,
|
|
750
|
+
MinValue: 0,
|
|
751
|
+
MaxValue: 999999
|
|
752
|
+
},
|
|
753
|
+
IsRequired: true,
|
|
754
|
+
IsUnique: false,
|
|
755
|
+
IsEncrypted: false,
|
|
756
|
+
IsRbacEnabled: false,
|
|
757
|
+
IsPrimaryKey: false,
|
|
758
|
+
IsSystemField: false
|
|
759
|
+
}
|
|
760
|
+
]
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
];
|
|
765
|
+
var ENTITIES_DELETE_EXAMPLES = [
|
|
766
|
+
{
|
|
767
|
+
Description: "Delete an entity (irreversible — requires --confirm and --reason)",
|
|
768
|
+
Command: 'uip df entities delete a1b2c3d4-0000-0000-0000-000000000001 --confirm --reason "test entity cleanup"',
|
|
769
|
+
Output: {
|
|
770
|
+
Code: "EntityDeleted",
|
|
771
|
+
Data: {
|
|
772
|
+
Id: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
773
|
+
Reason: "test entity cleanup"
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
];
|
|
778
|
+
var ENTITIES_CREATE_EXAMPLES = [
|
|
779
|
+
{
|
|
780
|
+
Description: "Create an entity with choice-set, relationship, file, and large-text fields. " + "CHOICE_SET_SINGLE/CHOICE_SET_MULTIPLE require 'choiceSetId' (from 'df choice-sets list'). " + "RELATIONSHIP requires 'referenceEntityId' (UUID of the target entity, from 'df entities list') and 'referenceFieldId' (UUID of the field on the target entity, from 'df entities get <target-id>'). " + "Note: a RELATIONSHIP column on a record always stores the target record's UUID 'Id' (regardless of which 'referenceFieldId' configured the join) — see 'df records insert' for how to write the value. " + "FILE fields take only 'name' and 'type' — the server auto-wires the internal attachment reference; populate them later with 'uip df files upload <entity-id> <record-id> <field-name> --file <path>'. " + "MULTILINE_MAX holds very large text ('lengthLimit' = UTF-16 byte budget, 1-131072; default max ~65,536 chars). Not filterable/sortable; 'records list'/'query' return only a preview (content truncated to 10,000 chars with a '...[Truncated]' suffix, or a 'HasValue=true Length=N' marker, depending on the tenant) — full content via 'records get'. Tenant-gated by the 'MultilineMax' feature flag.",
|
|
781
|
+
Command: `uip df entities create Expense --body '{"displayName":"Expense","fields":[{"name":"category","type":"CHOICE_SET_SINGLE","choiceSetId":"c1d2e3f4-0000-0000-0000-000000000001","isRequired":true},{"name":"tags","type":"CHOICE_SET_MULTIPLE","choiceSetId":"c1d2e3f4-0000-0000-0000-000000000002"},{"name":"submitter","type":"RELATIONSHIP","referenceEntityId":"a1b2c3d4-0000-0000-0000-000000000010","referenceFieldId":"f1000000-0000-0000-0000-000000000100","isRequired":true},{"name":"receipt","type":"FILE"},{"name":"notes","type":"MULTILINE_MAX"}]}'`,
|
|
782
|
+
Output: {
|
|
783
|
+
Code: "EntityCreated",
|
|
784
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000004" }
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
Description: "Create a folder-scoped entity with cross-folder references. " + "Pass '--folder-key' to place the new entity in a folder. " + "Per-field 'referenceFolderKey' points a RELATIONSHIP field at a target that lives in a different folder (or at the tenant level when omitted). " + "CHOICE_SET_* fields resolve scope from 'choiceSetId' and must not pass 'referenceFolderKey'. " + "Get target entity/field IDs from 'df entities list --folder-key <key>' and 'df entities get <id> --folder-key <key>'; get choice-set IDs from 'df choice-sets list --folder-key <key>' (omit '--folder-key' for tenant-level choice sets).",
|
|
789
|
+
Command: `uip df entities create OrderLine --folder-key f1000000-0000-0000-0000-000000000050 --body '{"displayName":"Order Line","fields":[{"name":"purchaseOrder","type":"RELATIONSHIP","referenceEntityId":"a1b2c3d4-0000-0000-0000-000000000010","referenceFieldId":"f1000000-0000-0000-0000-000000000100","referenceFolderKey":"f1000000-0000-0000-0000-000000000060","isRequired":true},{"name":"userType","type":"CHOICE_SET_SINGLE","choiceSetId":"c1d2e3f4-0000-0000-0000-000000000077"}]}'`,
|
|
790
|
+
Output: {
|
|
791
|
+
Code: "EntityCreated",
|
|
792
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000005" }
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
Description: `Create a FEDERATED entity (a read-only view over an Integration Service connector object). Per source provide 'connectionId', 'object', and the 'fields' to map. Get the connection id from 'uip is connections list <connector>' and object/field names from 'uip is resources describe <connector> <object> --operation List'. Omit '--folder-key' for a tenant-level entity. A field entry can be an object ('{"source":"priority","name":"prio","direction":"ReadAndWrite"}') to override its column name/type/direction.`,
|
|
797
|
+
Command: `uip df entities create SnIncidents --body '{"displayName":"SN Incidents","externalFields":[{"connectionId":"50689d14-0000-0000-0000-000000000001","object":"incident","fields":["sys_id","short_description","category","active"]}]}'`,
|
|
798
|
+
Output: {
|
|
799
|
+
Code: "EntityCreated",
|
|
800
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000007" }
|
|
801
|
+
}
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
Description: "Federated entity over a native source (another UiPath entity) — provide 'entityId' and 'fields'.",
|
|
805
|
+
Command: `uip df entities create AccountsView --body '{"externalFields":[{"entityId":"c8763252-0000-0000-0000-000000000001","fields":["Name","Email"]}]}'`,
|
|
806
|
+
Output: {
|
|
807
|
+
Code: "EntityCreated",
|
|
808
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000006" }
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
Description: "Federated entity joining two sources — one field pair per object pair (composite joins are not supported; chain joins across different pairs instead). A native source is referenced in a join by the source entity's name.",
|
|
813
|
+
Command: `uip df entities create OrdersWithAccount --body '{"externalFields":[{"connectionId":"e93c174b-0000-0000-0000-000000000001","object":"Order","fields":["Id","Amount","AccountId"]},{"connectionId":"e93c174b-0000-0000-0000-000000000001","object":"Account","fields":["Name"]}],"joins":[{"source":"Order","relatedSource":"Account","sourceField":"AccountId","relatedField":"Id","sourceConnectionId":"e93c174b-0000-0000-0000-000000000001","relatedConnectionId":"e93c174b-0000-0000-0000-000000000001"}]}'`,
|
|
814
|
+
Output: {
|
|
815
|
+
Code: "EntityCreated",
|
|
816
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000008" }
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
];
|
|
820
|
+
var ENTITIES_UPDATE_EXAMPLES = [
|
|
821
|
+
{
|
|
822
|
+
Description: "Add a field. addFields uses the flat write shape: name + type, plus optional lengthLimit, minValue, maxValue, decimalPrecision, displayName, description, isRequired, isUnique, choiceSetId, referenceEntityId, referenceFieldId, and referenceFolderKey. A field object copied from 'df entities get' is accepted in addFields and normalized, but do not replay a full 'entities get' entity object as the update body.",
|
|
823
|
+
Command: `uip df entities update a1b2c3d4-0000-0000-0000-000000000001 --body '{"addFields":[{"name":"note","type":"STRING","lengthLimit":200}]}'`,
|
|
824
|
+
Output: {
|
|
825
|
+
Code: "EntityUpdated",
|
|
826
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000001" }
|
|
827
|
+
}
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
Description: "Update field metadata. updateFields uses field IDs from 'df entities get <entity-id>' and accepts metadata such as displayName, description, isRequired, isRbacEnabled, isEncrypted, isHiddenField, defaultValue, and constraints. Do not paste a full copied field object here; pass 'id' plus only the flat write-shape properties being changed. It cannot change a field's type or isUnique setting.",
|
|
831
|
+
Command: `uip df entities update a1b2c3d4-0000-0000-0000-000000000001 --body '{"updateFields":[{"id":"f1000000-0000-0000-0000-000000000002","displayName":"Amount (USD)","isRequired":true}]}'`,
|
|
832
|
+
Output: {
|
|
833
|
+
Code: "EntityUpdated",
|
|
834
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000001" }
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
Description: "Remove fields. removeFields uses field names, not field IDs, and requires --yes with --reason because the field values are deleted.",
|
|
839
|
+
Command: `uip df entities update a1b2c3d4-0000-0000-0000-000000000001 --body '{"removeFields":[{"name":"oldColumn"}]}' --yes --reason "quarterly cleanup"`,
|
|
840
|
+
Output: {
|
|
841
|
+
Code: "EntityUpdated",
|
|
842
|
+
Data: {
|
|
843
|
+
Id: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
844
|
+
RemovedFields: ["oldColumn"],
|
|
845
|
+
Reason: "quarterly cleanup"
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
Description: "Add a source to a federated entity and join it in. 'addExternalSources' takes the same source shape as create ('connectionId'+'object'+'fields', or 'entityId'+'fields'); add 'joins' ('source'/'relatedSource'/'sourceField'/'relatedField'/'sourceConnectionId'/'relatedConnectionId') to connect it — every join names both sides' connection ids, including a source already on the entity. Removing structure ('removeExternalSources'/'removeExternalFields') needs --yes --reason.",
|
|
851
|
+
Command: `uip df entities update a1b2c3d4-0000-0000-0000-000000000006 --body '{"addExternalSources":[{"connectionId":"e93c174b-0000-0000-0000-000000000001","object":"Contact","fields":["Id","AccountId","Email"]}],"joins":[{"source":"Account","relatedSource":"Contact","sourceField":"Id","relatedField":"AccountId","sourceConnectionId":"e93c174b-0000-0000-0000-000000000002","relatedConnectionId":"e93c174b-0000-0000-0000-000000000001"}]}'`,
|
|
852
|
+
Output: {
|
|
853
|
+
Code: "EntityUpdated",
|
|
854
|
+
Data: { Id: "a1b2c3d4-0000-0000-0000-000000000006" }
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
];
|
|
858
|
+
var LOCAL_CREATE_EXAMPLES = [
|
|
859
|
+
{
|
|
860
|
+
Description: "Create an Entity project with its first entity, in the solution on disk. Run inside the solution directory; no login and no tenant involved. An existing --project-name must be a project of type Entity — pack only ships entities from those.",
|
|
861
|
+
Command: "uip df entities create PurchaseOrder --local --project-name MasterData",
|
|
862
|
+
Output: {
|
|
863
|
+
Code: "InlineEntityCreated",
|
|
864
|
+
Data: {
|
|
865
|
+
Project: "MasterData",
|
|
866
|
+
Entity: "PurchaseOrder",
|
|
867
|
+
EntityFile: "/workspace/Sol/MasterData/PurchaseOrder.entity",
|
|
868
|
+
ResourceFile: "/workspace/Sol/resources/solution_folder/entity/native/PurchaseOrder.json",
|
|
869
|
+
Created: "project"
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
];
|
|
874
|
+
var LOCAL_LIST_EXAMPLES = [
|
|
875
|
+
{
|
|
876
|
+
Description: "List every entity authored in the solution on disk. A row carrying 'Problem' is a stub/resource pair that does not verify, or a project directory the inline commands cannot read; 'entities delete <name> --local --force' clears a broken pair.",
|
|
877
|
+
Command: "uip df entities list --local",
|
|
878
|
+
Output: {
|
|
879
|
+
Code: "InlineEntityList",
|
|
880
|
+
Data: [
|
|
881
|
+
{
|
|
882
|
+
Project: "MasterData",
|
|
883
|
+
Entity: "PurchaseOrder",
|
|
884
|
+
EntityFile: "/workspace/Sol/MasterData/PurchaseOrder.entity",
|
|
885
|
+
ResourceFile: "/workspace/Sol/resources/solution_folder/entity/native/PurchaseOrder.json",
|
|
886
|
+
LocallyAuthored: true
|
|
887
|
+
}
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
];
|
|
892
|
+
var LOCAL_GET_EXAMPLES = [
|
|
893
|
+
{
|
|
894
|
+
Description: "Read the schema of an entity authored in the solution on disk. Unlike the tenant form this takes the entity NAME, not an id — nothing has an id until deploy. --project-name is optional: the owning project is found by name, since entity names are solution-wide unique. Data is the stored entity document as-is (abridged here: the system fields Id/CreateTime/CreatedBy/UpdateTime/UpdatedBy and the other document properties are omitted), so a field carries SqlType and FieldDisplayType, not the 'type' the create body takes.",
|
|
895
|
+
Command: "uip df entities get PurchaseOrder --local",
|
|
896
|
+
Output: {
|
|
897
|
+
Code: "InlineEntitySchema",
|
|
898
|
+
Data: {
|
|
899
|
+
Id: "bf667072-dea5-44fa-8e79-1858f70d517b",
|
|
900
|
+
Name: "PurchaseOrder",
|
|
901
|
+
DisplayName: "PurchaseOrder",
|
|
902
|
+
FolderId: "99999999-9999-9999-9999-999999999999",
|
|
903
|
+
Fields: [
|
|
904
|
+
{
|
|
905
|
+
Name: "OrderNumber",
|
|
906
|
+
DisplayName: "OrderNumber",
|
|
907
|
+
SqlType: { Name: "NVARCHAR", LengthLimit: 100 },
|
|
908
|
+
FieldDisplayType: "Basic",
|
|
909
|
+
IsRequired: false,
|
|
910
|
+
IsSystemField: false
|
|
911
|
+
}
|
|
912
|
+
]
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
];
|
|
917
|
+
var LOCAL_UPDATE_EXAMPLES = [
|
|
918
|
+
{
|
|
919
|
+
Description: `Add two fields to an entity authored on disk. Same body shape as the tenant update, applied to the local document; 'defaultValue' is text for every field type, so a DECIMAL default is "0".`,
|
|
920
|
+
Command: `uip df entities update PurchaseOrder --local --body '{"addFields":[{"name":"OrderNumber","type":"STRING","lengthLimit":100,"isRequired":true},{"name":"Amount","type":"DECIMAL","decimalPrecision":2,"defaultValue":"0"}]}'`,
|
|
921
|
+
Output: {
|
|
922
|
+
Code: "InlineEntityUpdated",
|
|
923
|
+
Data: {
|
|
924
|
+
Project: "MasterData",
|
|
925
|
+
Entity: "PurchaseOrder",
|
|
926
|
+
Fields: ["OrderNumber", "Amount"]
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
];
|
|
931
|
+
var LOCAL_DELETE_EXAMPLES = [
|
|
932
|
+
{
|
|
933
|
+
Description: "Delete an entity authored on disk — the .entity stub and its definition resource. Add --force for a pair that does not verify (anything 'entities list --local' shows with a Problem), which the ordinary path refuses because it cannot read it.",
|
|
934
|
+
Command: "uip df entities delete PurchaseOrder --local --yes",
|
|
935
|
+
Output: {
|
|
936
|
+
Code: "InlineEntityDeleted",
|
|
937
|
+
Data: {
|
|
938
|
+
Project: "MasterData",
|
|
939
|
+
Entity: "PurchaseOrder",
|
|
940
|
+
EntityFile: "/workspace/Sol/MasterData/PurchaseOrder.entity",
|
|
941
|
+
ResourceFile: "/workspace/Sol/resources/solution_folder/entity/native/PurchaseOrder.json"
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
];
|
|
946
|
+
var LOCAL_VALIDATE_EXAMPLES = [
|
|
947
|
+
{
|
|
948
|
+
Description: "Check every entity in a project — the same pair and schema checks 'uip solution pack' runs, without packing. Omit --project-name to gate the whole solution; that form exits non-zero on the first project it cannot read or validate.",
|
|
949
|
+
Command: "uip df entities validate --local --project-name MasterData",
|
|
950
|
+
Output: {
|
|
951
|
+
Code: "InlineEntityValidated",
|
|
952
|
+
Data: {
|
|
953
|
+
Project: "MasterData",
|
|
954
|
+
Valid: true,
|
|
955
|
+
Entities: [{ Entity: "PurchaseOrder", Diagnostics: [] }]
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
];
|
|
960
|
+
var VALID_FIELD_TYPES = new Set(Object.values(EntityFieldDataType));
|
|
961
|
+
var VALID_FIELD_TYPES_LIST = [...VALID_FIELD_TYPES].join(", ");
|
|
962
|
+
function hasInvalidFieldType(fields) {
|
|
963
|
+
return fields.some((f) => {
|
|
964
|
+
if (typeof f !== "object" || f === null)
|
|
965
|
+
return false;
|
|
966
|
+
const field = f;
|
|
967
|
+
return field.type !== undefined && !VALID_FIELD_TYPES.has(field.type);
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
var KNOWN_UPDATE_KEYS = [
|
|
971
|
+
"addFields",
|
|
972
|
+
"removeFields",
|
|
973
|
+
"updateFields",
|
|
974
|
+
"displayName",
|
|
975
|
+
"description",
|
|
976
|
+
"isRbacEnabled",
|
|
977
|
+
"addExternalSources",
|
|
978
|
+
"removeExternalSources",
|
|
979
|
+
"addExternalFields",
|
|
980
|
+
"removeExternalFields",
|
|
981
|
+
"addSourceJoins",
|
|
982
|
+
"updateSourceJoin",
|
|
983
|
+
"replaceSourceJoins",
|
|
984
|
+
"updateExternalConnection"
|
|
985
|
+
];
|
|
986
|
+
var FEDERATED_ARRAY_KEYS = [
|
|
987
|
+
"addExternalSources",
|
|
988
|
+
"removeExternalSources",
|
|
989
|
+
"addExternalFields",
|
|
990
|
+
"removeExternalFields",
|
|
991
|
+
"joins",
|
|
992
|
+
"replaceJoins",
|
|
993
|
+
"addSourceJoins",
|
|
994
|
+
"updateSourceJoin",
|
|
995
|
+
"updateExternalConnection"
|
|
996
|
+
];
|
|
997
|
+
var FEDERATED_REMOVE_KEYS = [
|
|
998
|
+
"removeExternalSources",
|
|
999
|
+
"removeExternalFields"
|
|
1000
|
+
];
|
|
1001
|
+
function pickKnownUpdateKeys(input) {
|
|
1002
|
+
const out = {};
|
|
1003
|
+
for (const key of KNOWN_UPDATE_KEYS) {
|
|
1004
|
+
if (input[key] !== undefined)
|
|
1005
|
+
out[key] = input[key];
|
|
1006
|
+
}
|
|
1007
|
+
return out;
|
|
1008
|
+
}
|
|
1009
|
+
var ADD_FIELDS_ARRAY_INSTRUCTIONS = 'Example: {"addFields":[{"name":"title","type":"STRING"}]}';
|
|
1010
|
+
var UPDATE_FIELDS_ARRAY_INSTRUCTIONS = 'Example: {"updateFields":[{"id":"<fieldId>","displayName":"New Name"}]}';
|
|
1011
|
+
var REMOVE_FIELDS_ARRAY_INSTRUCTIONS = 'Example: {"removeFields":[{"name":"oldField"}]}';
|
|
1012
|
+
var ADD_FIELDS_FIELD_NAME_INSTRUCTIONS = 'Use the flat write shape, for example {"name":"title","type":"STRING"}. A field copied from "df entities get" is also accepted inside addFields and normalized.';
|
|
1013
|
+
var UPDATE_FIELDS_ID_INSTRUCTIONS = 'Use "df entities get <entityId>" to find field IDs. Example: {"id":"<fieldId>","displayName":"Total Amount","isRequired":true}';
|
|
1014
|
+
var REMOVE_FIELDS_FIELD_NAME_INSTRUCTIONS = 'Example: {"removeFields":[{"name":"oldField"}]}';
|
|
1015
|
+
function isObjectRecord(value) {
|
|
1016
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1017
|
+
}
|
|
1018
|
+
function readKey(record, camelKey, pascalKey) {
|
|
1019
|
+
return record[camelKey] ?? record[pascalKey];
|
|
1020
|
+
}
|
|
1021
|
+
function readObjectKey(record, camelKey, pascalKey) {
|
|
1022
|
+
const value = readKey(record, camelKey, pascalKey);
|
|
1023
|
+
return isObjectRecord(value) ? value : undefined;
|
|
1024
|
+
}
|
|
1025
|
+
function setIfDefined(target, key, value) {
|
|
1026
|
+
if (value !== undefined)
|
|
1027
|
+
target[key] = value;
|
|
1028
|
+
}
|
|
1029
|
+
function readId(value) {
|
|
1030
|
+
if (!isObjectRecord(value))
|
|
1031
|
+
return;
|
|
1032
|
+
return value.id ?? value.Id ?? value.ID;
|
|
1033
|
+
}
|
|
1034
|
+
function readFieldTypeMetadata(field) {
|
|
1035
|
+
return readObjectKey(field, "fieldDataType", "FieldDataType");
|
|
1036
|
+
}
|
|
1037
|
+
function readConstraint(field, fieldTypeMetadata, camelKey, pascalKey) {
|
|
1038
|
+
return readKey(field, camelKey, pascalKey) ?? (fieldTypeMetadata === undefined ? undefined : readKey(fieldTypeMetadata, camelKey, pascalKey));
|
|
1039
|
+
}
|
|
1040
|
+
function normalizeAddFieldShape(field) {
|
|
1041
|
+
if (!isObjectRecord(field))
|
|
1042
|
+
return field;
|
|
1043
|
+
if (field.name !== undefined || field.type !== undefined)
|
|
1044
|
+
return field;
|
|
1045
|
+
const readName = readKey(field, "name", "Name");
|
|
1046
|
+
const fieldTypeMetadata = readFieldTypeMetadata(field);
|
|
1047
|
+
if (typeof readName !== "string" || fieldTypeMetadata === undefined) {
|
|
1048
|
+
return field;
|
|
1049
|
+
}
|
|
1050
|
+
const normalized = { name: readName };
|
|
1051
|
+
setIfDefined(normalized, "type", readKey(fieldTypeMetadata, "name", "Name"));
|
|
1052
|
+
for (const [writeKey, pascalKey] of [
|
|
1053
|
+
["displayName", "DisplayName"],
|
|
1054
|
+
["description", "Description"],
|
|
1055
|
+
["isRequired", "IsRequired"],
|
|
1056
|
+
["isUnique", "IsUnique"],
|
|
1057
|
+
["isRbacEnabled", "IsRbacEnabled"],
|
|
1058
|
+
["isEncrypted", "IsEncrypted"],
|
|
1059
|
+
["isHiddenField", "IsHiddenField"],
|
|
1060
|
+
["defaultValue", "DefaultValue"]
|
|
1061
|
+
]) {
|
|
1062
|
+
setIfDefined(normalized, writeKey, readKey(field, writeKey, pascalKey));
|
|
1063
|
+
}
|
|
1064
|
+
for (const [writeKey, pascalKey] of [
|
|
1065
|
+
["lengthLimit", "LengthLimit"],
|
|
1066
|
+
["maxValue", "MaxValue"],
|
|
1067
|
+
["minValue", "MinValue"],
|
|
1068
|
+
["decimalPrecision", "DecimalPrecision"]
|
|
1069
|
+
]) {
|
|
1070
|
+
setIfDefined(normalized, writeKey, readConstraint(field, fieldTypeMetadata, writeKey, pascalKey));
|
|
1071
|
+
}
|
|
1072
|
+
setIfDefined(normalized, "choiceSetId", readKey(field, "choiceSetId", "ChoiceSetId") ?? readId(readKey(field, "referenceChoiceSet", "ReferenceChoiceSet")));
|
|
1073
|
+
setIfDefined(normalized, "referenceEntityId", readKey(field, "referenceEntityId", "ReferenceEntityId") ?? readId(readKey(field, "referenceEntity", "ReferenceEntity")));
|
|
1074
|
+
setIfDefined(normalized, "referenceFieldId", readKey(field, "referenceFieldId", "ReferenceFieldId") ?? readId(readKey(field, "referenceField", "ReferenceField")));
|
|
1075
|
+
setIfDefined(normalized, "referenceFolderKey", readKey(field, "referenceFolderKey", "ReferenceFolderKey"));
|
|
1076
|
+
return normalized;
|
|
1077
|
+
}
|
|
1078
|
+
function normalizeAddFields(addFields) {
|
|
1079
|
+
return addFields.map((field) => normalizeAddFieldShape(field));
|
|
1080
|
+
}
|
|
1081
|
+
function hasMissingStringField(fields, key) {
|
|
1082
|
+
return fields.some((field) => {
|
|
1083
|
+
if (!isObjectRecord(field))
|
|
1084
|
+
return true;
|
|
1085
|
+
const value = field[key];
|
|
1086
|
+
return typeof value !== "string" || value.trim() === "";
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
function getUpdateArray(input, key, instructions, issues) {
|
|
1090
|
+
const value = input[key];
|
|
1091
|
+
if (value === undefined)
|
|
1092
|
+
return;
|
|
1093
|
+
if (Array.isArray(value))
|
|
1094
|
+
return value;
|
|
1095
|
+
issues.push({
|
|
1096
|
+
message: `'${key}' must be an array`,
|
|
1097
|
+
instructions
|
|
1098
|
+
});
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
function combineValidationIssues(issues) {
|
|
1102
|
+
if (issues.length === 0)
|
|
1103
|
+
return null;
|
|
1104
|
+
if (issues.length === 1)
|
|
1105
|
+
return issues[0];
|
|
1106
|
+
return {
|
|
1107
|
+
message: `Update body validation failed: ${issues.map((issue) => issue.message).join("; ")}`,
|
|
1108
|
+
instructions: issues.map((issue, index) => `${index + 1}. ${issue.instructions}`).join(`
|
|
1109
|
+
`)
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
function rejectMisplacedLocalOptions(options, tenantOnly, localOnly = []) {
|
|
1113
|
+
const flag = (name) => `--${name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
|
|
1114
|
+
if (options.local === true) {
|
|
1115
|
+
const offenders = tenantOnly.filter((name) => options[name] !== undefined && options[name] !== false);
|
|
1116
|
+
if (offenders.length > 0) {
|
|
1117
|
+
failInvalidArgument(`${offenders.map(flag).join(", ")} ${offenders.length === 1 ? "does" : "do"} not apply with --local`, "A locally authored entity has no tenant and no folder until the solution deploys, so there is nothing for these to address. Drop them, or drop --local to act on the tenant.");
|
|
1118
|
+
return true;
|
|
1119
|
+
}
|
|
1120
|
+
return false;
|
|
1121
|
+
}
|
|
1122
|
+
if (options.projectName !== undefined) {
|
|
1123
|
+
failInvalidArgument("--project-name requires --local", "It names an Entity project in the solution on disk. Without --local the command acts on the tenant, where projects do not exist.");
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
const localOffenders = localOnly.filter((name) => options[name] !== undefined && options[name] !== false);
|
|
1127
|
+
if (localOffenders.length > 0) {
|
|
1128
|
+
failInvalidArgument(`${localOffenders.map(flag).join(", ")} ${localOffenders.length === 1 ? "requires" : "require"} --local`, "These act on the entity files in the solution on disk. Without --local the command acts on the tenant, which never reads them. Add --local, or drop them.");
|
|
1129
|
+
return true;
|
|
1130
|
+
}
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1133
|
+
async function loadLocalHandlersAsync() {
|
|
1134
|
+
const {
|
|
1135
|
+
LOCAL_AUTHORING_AVAILABLE,
|
|
1136
|
+
runLocalCreate,
|
|
1137
|
+
runLocalDelete,
|
|
1138
|
+
runLocalGet,
|
|
1139
|
+
runLocalList,
|
|
1140
|
+
runLocalUpdate,
|
|
1141
|
+
runLocalValidate
|
|
1142
|
+
} = await import("./entities-inline-9s390vev.js");
|
|
1143
|
+
if (LOCAL_AUTHORING_AVAILABLE !== true) {
|
|
1144
|
+
failInvalidArgument("--local is not available in this environment", "Local authoring reads and writes the solution on disk, which this build cannot reach. Run the command with the uip CLI on a machine that has the solution checked out.");
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
return {
|
|
1148
|
+
runLocalCreate,
|
|
1149
|
+
runLocalDelete,
|
|
1150
|
+
runLocalGet,
|
|
1151
|
+
runLocalList,
|
|
1152
|
+
runLocalUpdate,
|
|
1153
|
+
runLocalValidate
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
var registerEntitiesCommand = (program) => {
|
|
1157
|
+
const entities = program.command("entities").description("Browse Data Fabric entity schemas. Pass --local to act on entities authored in the current solution instead of the tenant.");
|
|
1158
|
+
entities.command("validate").description("Validate entities authored in the local solution — the same stub/resource pairing and schema checks 'uip solution pack' runs, without packing.").argument("[name]", "Validate only this entity").option("--local", "Required. Validation applies to locally authored entities only.").option("--project-name <name>", "Scope to one Entity project. Omitted, the whole solution is checked.").examples(LOCAL_VALIDATE_EXAMPLES).trackedAction(processContext, async (name, options) => {
|
|
1159
|
+
if (!options.local) {
|
|
1160
|
+
return failInvalidArgument("'entities validate' requires --local", "Tenant entities are validated by the server on write. This checks entities authored in a solution on disk.");
|
|
1161
|
+
}
|
|
1162
|
+
const local = await loadLocalHandlersAsync();
|
|
1163
|
+
if (local === undefined)
|
|
1164
|
+
return;
|
|
1165
|
+
return local.runLocalValidate(name, options);
|
|
1166
|
+
});
|
|
1167
|
+
entities.command("list").description("List all Data Fabric entities").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--native-only", "Show only native entities (exclude federated entities with external connections)").option("--federated-only", "Show only federated entities (those backed by external connections). Mutually exclusive with --native-only; omit both to list all.").option("--folder-key <key>", "Folder key (GUID) to scope the listing to a specific folder").option("--include-folders", "List tenant-level entities together with entities from every folder you can see. Mutually exclusive with --folder-key.").option("--local", "Act on entities authored in the local solution instead of the tenant. No login required; nothing exists on a tenant until the solution deploys.").option("--project-name <name>", "With --local: list only this Entity project. Omitted, every Entity project in the solution is listed.").examples([...ENTITIES_LIST_EXAMPLES, ...LOCAL_LIST_EXAMPLES]).trackedAction(processContext, async (options) => {
|
|
1168
|
+
if (rejectMisplacedLocalOptions(options, [
|
|
1169
|
+
"folderKey",
|
|
1170
|
+
"includeFolders",
|
|
1171
|
+
"nativeOnly",
|
|
1172
|
+
"federatedOnly",
|
|
1173
|
+
"tenant"
|
|
1174
|
+
])) {
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
if (options.local) {
|
|
1178
|
+
const local = await loadLocalHandlersAsync();
|
|
1179
|
+
if (local === undefined)
|
|
1180
|
+
return;
|
|
1181
|
+
return local.runLocalList(options);
|
|
1182
|
+
}
|
|
1183
|
+
if (options.folderKey !== undefined && options.includeFolders === true) {
|
|
1184
|
+
return fail("--folder-key and --include-folders are mutually exclusive", "Use --folder-key to list a single folder, or --include-folders to list tenant + folder entities together.");
|
|
1185
|
+
}
|
|
1186
|
+
if (options.nativeOnly === true && options.federatedOnly === true) {
|
|
1187
|
+
return fail("--native-only and --federated-only are mutually exclusive", "Pass one to filter by class, or omit both to list all entities.");
|
|
1188
|
+
}
|
|
1189
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1190
|
+
if (!sdk)
|
|
1191
|
+
return;
|
|
1192
|
+
const listOpts = {
|
|
1193
|
+
...options.folderKey !== undefined && {
|
|
1194
|
+
folderKey: options.folderKey
|
|
1195
|
+
},
|
|
1196
|
+
...options.includeFolders === true && {
|
|
1197
|
+
includeFolderEntities: true
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
const [listError, result] = await catchError(sdk.entities.getAll(Object.keys(listOpts).length > 0 ? listOpts : undefined));
|
|
1201
|
+
if (listError) {
|
|
1202
|
+
return fail("Error listing entities", await extractErrorMessage(listError));
|
|
1203
|
+
}
|
|
1204
|
+
const entityList = (result ?? []).filter((e) => {
|
|
1205
|
+
if (!options.nativeOnly && !options.federatedOnly)
|
|
1206
|
+
return true;
|
|
1207
|
+
const entity = e;
|
|
1208
|
+
const externalFields = entity.externalFields ?? entity.ExternalFields ?? [];
|
|
1209
|
+
const isFederated = externalFields.length > 0;
|
|
1210
|
+
return options.federatedOnly ? isFederated : !isFederated;
|
|
1211
|
+
});
|
|
1212
|
+
OutputFormatter.success({
|
|
1213
|
+
Result: RESULTS.Success,
|
|
1214
|
+
Code: "EntityList",
|
|
1215
|
+
Data: entityList
|
|
1216
|
+
});
|
|
1217
|
+
});
|
|
1218
|
+
entities.command("get").description("Get schema details of a Data Fabric entity").argument("<id>", "Entity ID on the tenant; with --local, the entity name").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").option("--local", "Act on entities authored in the local solution instead of the tenant. No login required; nothing exists on a tenant until the solution deploys.").option("--project-name <name>", "With --local: the Entity project that owns the entity. Optional — omitted, the owner is found by name, since entity names are solution-wide unique.").examples([...ENTITIES_GET_EXAMPLES, ...LOCAL_GET_EXAMPLES]).trackedAction(processContext, async (id, options) => {
|
|
1219
|
+
if (rejectMisplacedLocalOptions(options, [
|
|
1220
|
+
"folderKey",
|
|
1221
|
+
"tenant"
|
|
1222
|
+
])) {
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
if (options.local) {
|
|
1226
|
+
const local = await loadLocalHandlersAsync();
|
|
1227
|
+
if (local === undefined)
|
|
1228
|
+
return;
|
|
1229
|
+
return local.runLocalGet(id, options);
|
|
1230
|
+
}
|
|
1231
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1232
|
+
if (!sdk)
|
|
1233
|
+
return;
|
|
1234
|
+
const [getError, entity] = await catchError(sdk.entities.getById(id, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
1235
|
+
if (getError) {
|
|
1236
|
+
return fail(`Error getting entity schema '${id}'`, await extractErrorMessage(getError));
|
|
1237
|
+
}
|
|
1238
|
+
const e = entity;
|
|
1239
|
+
if (!e?.fields) {
|
|
1240
|
+
return fail(`Entity '${id}' not found`, "Verify the entity ID exists. Use 'df entities list' to see available entities.");
|
|
1241
|
+
}
|
|
1242
|
+
OutputFormatter.success({
|
|
1243
|
+
Result: RESULTS.Success,
|
|
1244
|
+
Code: "EntitySchema",
|
|
1245
|
+
Data: e
|
|
1246
|
+
});
|
|
1247
|
+
});
|
|
1248
|
+
entities.command("create").description("Create a new Data Fabric entity").argument("<name>", "Entity name (must start with a letter; letters, numbers, and underscores only)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", `Path to JSON file with entity definition. Native entity: 'fields' array required. Federated entity: an 'externalFields' array where each source is either 'connectionId' + 'object' + 'fields' (a connector source) or 'entityId' + 'fields' (a native, entity-backed source). The primary source is derived from the joins (the source every join starts from). 'fields' entries are external field names, or objects to override a column: '{"source","name","type","direction","searchable","sortable"}' (only 'source' is required). Optional 'joins': '{"source","relatedSource","sourceField","relatedField","sourceConnectionId","relatedConnectionId"}' — 'sourceConnectionId'/'relatedConnectionId' are required on every join and identify each side (a connector 'connectionId', or the 'entityId' for a native source), since two sources can share an object name on different connections. Every join's 'source' must be the primary, every other source must be joined directly to it, one field pair per source pair. Optional: displayName, description, isRbacEnabled, isAnalyticsEnabled.`).option("--body <json>", "Inline JSON entity definition. A field object copied from 'df entities get' is also accepted and normalized to the write shape.").option("--folder-key <key>", "Folder key (GUID) of the target folder (for folder-scoped entities)").option("--local", "Act on entities authored in the local solution instead of the tenant. No login required; nothing exists on a tenant until the solution deploys.").option("--project-name <name>", "With --local: the Entity project to create the entity in, scaffolded and registered if it does not exist. Optional — omitted, the project is named after the entity.").examples([...ENTITIES_CREATE_EXAMPLES, ...LOCAL_CREATE_EXAMPLES]).trackedAction(processContext, async (name, options) => {
|
|
1249
|
+
if (rejectMisplacedLocalOptions(options, [
|
|
1250
|
+
"folderKey",
|
|
1251
|
+
"tenant"
|
|
1252
|
+
])) {
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (options.local) {
|
|
1256
|
+
const local = await loadLocalHandlersAsync();
|
|
1257
|
+
if (local === undefined)
|
|
1258
|
+
return;
|
|
1259
|
+
return local.runLocalCreate(name, options);
|
|
1260
|
+
}
|
|
1261
|
+
const [parseError, parsed] = await catchError(readJsonInput(options.file, options.body, "Provide entity definition via --file or --body."));
|
|
1262
|
+
if (parseError) {
|
|
1263
|
+
return fail("Error parsing entity definition", parseError.message);
|
|
1264
|
+
}
|
|
1265
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
1266
|
+
return fail("Entity definition must be a JSON object", "Provide a JSON object with a 'fields' array and optional displayName, description, isRbacEnabled, isAnalyticsEnabled.");
|
|
1267
|
+
}
|
|
1268
|
+
const definition = parsed;
|
|
1269
|
+
if (definition.externalFields !== undefined && !Array.isArray(definition.externalFields)) {
|
|
1270
|
+
return fail("'externalFields' must be an array", 'Provide an array of source objects. Each source is "connectionId" + "object" + "fields" or "entityId" + "fields".');
|
|
1271
|
+
}
|
|
1272
|
+
const isFederated = definition.entityClass === EntityClass.Federated || definition.externalFields !== undefined;
|
|
1273
|
+
if (isFederated && definition.entityClass !== undefined && definition.entityClass !== EntityClass.Federated) {
|
|
1274
|
+
return fail(`Entity has 'externalFields' but entityClass is '${String(definition.entityClass)}'`, "Remove 'entityClass' (it defaults to Federated when 'externalFields' is present) or set it to 'Federated'.");
|
|
1275
|
+
}
|
|
1276
|
+
if (!isFederated && !Array.isArray(definition.fields)) {
|
|
1277
|
+
return fail("Entity definition must include a 'fields' array", "Provide a JSON object with a 'fields' array containing field definitions.");
|
|
1278
|
+
}
|
|
1279
|
+
if (isFederated && (!Array.isArray(definition.externalFields) || definition.externalFields.length === 0)) {
|
|
1280
|
+
return fail("Federated entity requires a non-empty 'externalFields' array", 'Each source is "connectionId" + "object" + "fields" (a connector source) or "entityId" + "fields" (a native, entity-backed source). "fields" entries are external field names, or objects like {"source":"AccountId","name":"accountId"}.');
|
|
1281
|
+
}
|
|
1282
|
+
const nativeFields = Array.isArray(definition.fields) ? normalizeAddFields(definition.fields) : [];
|
|
1283
|
+
const hasInvalidField = nativeFields.some((f) => typeof f !== "object" || f === null || typeof f.name !== "string");
|
|
1284
|
+
if (hasInvalidField) {
|
|
1285
|
+
return fail("Each field must include a 'name' string", 'Example: {"name":"title","type":"STRING"}');
|
|
1286
|
+
}
|
|
1287
|
+
if (hasInvalidFieldType(nativeFields)) {
|
|
1288
|
+
return fail("Invalid field type in fields", `Valid types: ${VALID_FIELD_TYPES_LIST}`);
|
|
1289
|
+
}
|
|
1290
|
+
const err = runChecks([
|
|
1291
|
+
() => validateName(name, "entity"),
|
|
1292
|
+
() => validateSchemaMetadata(definition, "Entity"),
|
|
1293
|
+
() => validateFieldsPayload(nativeFields, name, true)
|
|
1294
|
+
]);
|
|
1295
|
+
if (err)
|
|
1296
|
+
return fail(err.message, err.instructions);
|
|
1297
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1298
|
+
if (!sdk)
|
|
1299
|
+
return;
|
|
1300
|
+
if (isFederated) {
|
|
1301
|
+
const {
|
|
1302
|
+
createFederatedMetadataProvider,
|
|
1303
|
+
expandFederatedCreate,
|
|
1304
|
+
validateFederatedTopology
|
|
1305
|
+
} = await import("./federated-payload-nfjfj8v9.js");
|
|
1306
|
+
try {
|
|
1307
|
+
validateFederatedTopology(definition.externalFields, definition.joins ?? []);
|
|
1308
|
+
} catch (err2) {
|
|
1309
|
+
return fail("Invalid federated entity topology", await extractErrorMessage(err2));
|
|
1310
|
+
}
|
|
1311
|
+
const [expandErr, expanded] = await catchError(expandFederatedCreate(definition, createFederatedMetadataProvider(options.tenant, (eid, fk) => sdk.entities.getById(eid, fk ? { folderKey: fk } : undefined)), name));
|
|
1312
|
+
if (expandErr) {
|
|
1313
|
+
return fail("Error building federated entity payload", await extractErrorMessage(expandErr));
|
|
1314
|
+
}
|
|
1315
|
+
definition.externalFields = expanded.externalFields;
|
|
1316
|
+
if (definition.joins !== undefined) {
|
|
1317
|
+
definition.sourceJoinConditionDetails = expanded.sourceJoinConditionDetails;
|
|
1318
|
+
delete definition.joins;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
const createOpts = {
|
|
1322
|
+
...definition.displayName !== undefined && {
|
|
1323
|
+
displayName: definition.displayName
|
|
1324
|
+
},
|
|
1325
|
+
...definition.description !== undefined && {
|
|
1326
|
+
description: definition.description
|
|
1327
|
+
},
|
|
1328
|
+
...definition.isRbacEnabled !== undefined && {
|
|
1329
|
+
isRbacEnabled: definition.isRbacEnabled
|
|
1330
|
+
},
|
|
1331
|
+
...(definition.entityClass !== undefined || isFederated) && {
|
|
1332
|
+
entityClass: definition.entityClass ?? EntityClass.Federated
|
|
1333
|
+
},
|
|
1334
|
+
...definition.externalFields !== undefined && {
|
|
1335
|
+
externalFields: definition.externalFields
|
|
1336
|
+
},
|
|
1337
|
+
...definition.sourceJoinConditionDetails !== undefined && {
|
|
1338
|
+
sourceJoinConditionDetails: definition.sourceJoinConditionDetails
|
|
1339
|
+
},
|
|
1340
|
+
...definition.isAnalyticsEnabled !== undefined && {
|
|
1341
|
+
isAnalyticsEnabled: definition.isAnalyticsEnabled
|
|
1342
|
+
},
|
|
1343
|
+
...options.folderKey !== undefined && {
|
|
1344
|
+
folderKey: options.folderKey
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
const entityService = sdk.entities;
|
|
1348
|
+
const [createError, entityId] = await catchError(entityService.create(name, nativeFields, Object.keys(createOpts).length > 0 ? createOpts : undefined));
|
|
1349
|
+
if (createError) {
|
|
1350
|
+
return fail("Error creating entity", await extractErrorMessage(createError));
|
|
1351
|
+
}
|
|
1352
|
+
OutputFormatter.success({
|
|
1353
|
+
Result: RESULTS.Success,
|
|
1354
|
+
Code: "EntityCreated",
|
|
1355
|
+
Data: { ID: entityId }
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
entities.command("update").description("Update schema or metadata of a Data Fabric entity").argument("<id>", "Entity ID on the tenant; with --local, the entity name").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", "Path to JSON file with update options. Field shapes: addFields [{name,type,...}], updateFields [{id,...}], removeFields [{name}]. Do not paste a full copied field object into updateFields; pass id plus only changed flat properties. Also accepts the entity metadata keys displayName, description and isRbacEnabled. Federated source/join deltas — every reference to an existing source needs both 'sourceObjectName' and 'sourceConnectionId' (a connector connectionId, or the entityId for a native source), since two sources can share an object name on different connections: 'addExternalSources' [{connectionId,object,fields}] or [{entityId,fields}] (same source shape as create); 'joins' [{source,relatedSource,sourceField,relatedField,sourceConnectionId,relatedConnectionId}] to connect an added source to the primary (all names + connection ids required); 'addExternalFields' [{sourceObjectName,sourceConnectionId,fields}] (fields as in create); 'removeExternalSources' [{sourceObjectName,sourceConnectionId},...]; 'removeExternalFields' [{sourceObjectName,sourceConnectionId,fieldNames}] (fieldNames are the entity's column names, not the external field names); 'updateSourceJoin' [{sourceObjectName,sourceConnectionId,relatedSourceObjectName,relatedSourceConnectionId,sourceJoinField,relatedSourceJoinField}] changes only the join fields of an existing join (not its sources, direction or type); 'replaceJoins' [same shape as 'joins'] is the complete new join set and is how you change the primary source (every join starts from the new primary, every other source is joined once; cannot be combined with 'joins' or 'updateSourceJoin'); 'updateExternalConnection' [{sourceObjectName,sourceConnectionId,newConnectionId}] swaps a connector source's connection (same connector only, connection must be enabled and expose the object; keeps its fields and joins; a mapped field the new connection lacks is dropped with a warning, along with any join that uses it, and needs --yes --reason). A join cannot be removed on its own: every source but the primary stays joined. Removing a source also removes its joins, and so does removing a join field, so pass 'replaceJoins' when that leaves a source unjoined. A source must keep at least one field. remove* and replaceJoins require --yes --reason.").option("--body <json>", "Inline JSON update options (use `-` to read from stdin). Field shapes: addFields [{name,type,...}], updateFields [{id,...}], removeFields [{name}]. Do not paste a full copied field object into updateFields; pass id plus only changed flat properties. Also accepts the entity metadata keys displayName, description and isRbacEnabled. Federated source/join deltas — every reference to an existing source needs both 'sourceObjectName' and 'sourceConnectionId' (a connector connectionId, or the entityId for a native source), since two sources can share an object name on different connections: 'addExternalSources' [{connectionId,object,fields}] or [{entityId,fields}] (same source shape as create); 'joins' [{source,relatedSource,sourceField,relatedField,sourceConnectionId,relatedConnectionId}] to connect an added source to the primary (all names + connection ids required); 'addExternalFields' [{sourceObjectName,sourceConnectionId,fields}] (fields as in create); 'removeExternalSources' [{sourceObjectName,sourceConnectionId},...]; 'removeExternalFields' [{sourceObjectName,sourceConnectionId,fieldNames}] (fieldNames are the entity's column names, not the external field names); 'updateSourceJoin' [{sourceObjectName,sourceConnectionId,relatedSourceObjectName,relatedSourceConnectionId,sourceJoinField,relatedSourceJoinField}] changes only the join fields of an existing join (not its sources, direction or type); 'replaceJoins' [same shape as 'joins'] is the complete new join set and is how you change the primary source (every join starts from the new primary, every other source is joined once; cannot be combined with 'joins' or 'updateSourceJoin'); 'updateExternalConnection' [{sourceObjectName,sourceConnectionId,newConnectionId}] swaps a connector source's connection (same connector only, connection must be enabled and expose the object; keeps its fields and joins; a mapped field the new connection lacks is dropped with a warning, along with any join that uses it, and needs --yes --reason). A join cannot be removed on its own: every source but the primary stays joined. Removing a source also removes its joins, and so does removing a join field, so pass 'replaceJoins' when that leaves a source unjoined. A source must keep at least one field. remove* and replaceJoins require --yes --reason.").option("-y, --yes", "Required when 'removeFields' is non-empty — acknowledges the field deletion is irreversible").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Required when 'removeFields' is non-empty — echoed back in the response so the caller can log it").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").option("--local", "Act on entities authored in the local solution instead of the tenant. No login required; nothing exists on a tenant until the solution deploys.").option("--project-name <name>", "With --local: the Entity project that owns the entity. Optional — omitted, the owner is found by name, since entity names are solution-wide unique.").examples([...ENTITIES_UPDATE_EXAMPLES, ...LOCAL_UPDATE_EXAMPLES]).trackedAction(processContext, async (id, options) => {
|
|
1359
|
+
if (rejectMisplacedLocalOptions(options, [
|
|
1360
|
+
"folderKey",
|
|
1361
|
+
"reason",
|
|
1362
|
+
"tenant"
|
|
1363
|
+
])) {
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
if (options.local) {
|
|
1367
|
+
const local = await loadLocalHandlersAsync();
|
|
1368
|
+
if (local === undefined)
|
|
1369
|
+
return;
|
|
1370
|
+
return local.runLocalUpdate(id, options);
|
|
1371
|
+
}
|
|
1372
|
+
const [parseError, parsed] = await catchError(readJsonInput(options.file, options.body, "Provide update options via --file or --body."));
|
|
1373
|
+
if (parseError) {
|
|
1374
|
+
return failInvalidArgument("Error parsing update options", parseError.message);
|
|
1375
|
+
}
|
|
1376
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
1377
|
+
return failInvalidArgument("Update options must be a JSON object", "Provide a JSON object. Native keys: addFields, updateFields, removeFields, displayName, description, isRbacEnabled. Federated source/join deltas: addExternalSources, addExternalFields, joins, replaceJoins, removeExternalSources, removeExternalFields, updateSourceJoin, updateExternalConnection.");
|
|
1378
|
+
}
|
|
1379
|
+
const input = parsed;
|
|
1380
|
+
if (Array.isArray(input.addFields)) {
|
|
1381
|
+
input.addFields = normalizeAddFields(input.addFields);
|
|
1382
|
+
}
|
|
1383
|
+
const validationIssues = [];
|
|
1384
|
+
if (input.name !== undefined) {
|
|
1385
|
+
validationIssues.push({
|
|
1386
|
+
message: "Entity name cannot be changed after creation",
|
|
1387
|
+
instructions: "Remove 'name' from the update body. The entity name is immutable — only 'displayName' and 'description' can be changed. To use a different name, create a new entity."
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
if (input.isAnalyticsEnabled !== undefined) {
|
|
1391
|
+
validationIssues.push({
|
|
1392
|
+
message: "Analytics cannot be changed after entity creation",
|
|
1393
|
+
instructions: "Remove 'isAnalyticsEnabled' from the update body. It is immutable — set it when creating the entity with 'df entities create'."
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
const hasMetadataUpdate = ["description", "isRbacEnabled"].some((key) => input[key] !== undefined);
|
|
1397
|
+
if (hasMetadataUpdate && input.displayName === undefined) {
|
|
1398
|
+
validationIssues.push({
|
|
1399
|
+
message: "'displayName' is required when updating entity metadata",
|
|
1400
|
+
instructions: `Include the current displayName in the body alongside description/isRbacEnabled — get it with 'df entities get <entityId>'. Example: {"displayName":"<current-display-name>","description":"<new-description>"}.`
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
const metadataErr = validateSchemaMetadata(input, "Entity");
|
|
1404
|
+
if (metadataErr)
|
|
1405
|
+
validationIssues.push(metadataErr);
|
|
1406
|
+
const addFields = getUpdateArray(input, "addFields", ADD_FIELDS_ARRAY_INSTRUCTIONS, validationIssues);
|
|
1407
|
+
const updateFields = getUpdateArray(input, "updateFields", UPDATE_FIELDS_ARRAY_INSTRUCTIONS, validationIssues);
|
|
1408
|
+
const removeFields = getUpdateArray(input, "removeFields", REMOVE_FIELDS_ARRAY_INSTRUCTIONS, validationIssues);
|
|
1409
|
+
for (const key of FEDERATED_ARRAY_KEYS) {
|
|
1410
|
+
if (input[key] !== undefined && !Array.isArray(input[key])) {
|
|
1411
|
+
validationIssues.push({
|
|
1412
|
+
message: `'${key}' must be an array`,
|
|
1413
|
+
instructions: "See 'uip df entities update --help' for the federated update body shape."
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
let addFieldNames = [];
|
|
1418
|
+
if (addFields !== undefined) {
|
|
1419
|
+
const hasInvalidAddFieldsShape = hasMissingStringField(addFields, "name");
|
|
1420
|
+
if (hasInvalidAddFieldsShape) {
|
|
1421
|
+
validationIssues.push({
|
|
1422
|
+
message: "Each field in addFields must include a non-empty 'name' string",
|
|
1423
|
+
instructions: ADD_FIELDS_FIELD_NAME_INSTRUCTIONS
|
|
1424
|
+
});
|
|
1425
|
+
} else {
|
|
1426
|
+
addFieldNames = addFields.map((field) => field.name);
|
|
1427
|
+
if (hasInvalidFieldType(addFields)) {
|
|
1428
|
+
validationIssues.push({
|
|
1429
|
+
message: "Invalid field type in addFields",
|
|
1430
|
+
instructions: `Valid types: ${VALID_FIELD_TYPES_LIST}`
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
const addErr = validateFieldsPayload(addFields);
|
|
1434
|
+
if (addErr)
|
|
1435
|
+
validationIssues.push(addErr);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
let removedFieldNames = [];
|
|
1439
|
+
if (removeFields !== undefined) {
|
|
1440
|
+
if (hasMissingStringField(removeFields, "name")) {
|
|
1441
|
+
validationIssues.push({
|
|
1442
|
+
message: "Each field in removeFields must include a non-empty 'name' string",
|
|
1443
|
+
instructions: REMOVE_FIELDS_FIELD_NAME_INSTRUCTIONS
|
|
1444
|
+
});
|
|
1445
|
+
} else {
|
|
1446
|
+
removedFieldNames = removeFields.map((field) => field.name);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
if (addFieldNames.length > 0 && removedFieldNames.length > 0) {
|
|
1450
|
+
const removedNamesLower = new Set(removedFieldNames.map((name) => name.toLowerCase()));
|
|
1451
|
+
const conflict = addFieldNames.find((name) => removedNamesLower.has(name.toLowerCase()));
|
|
1452
|
+
if (conflict !== undefined) {
|
|
1453
|
+
validationIssues.push({
|
|
1454
|
+
message: `Field '${conflict}' appears in both addFields and removeFields`,
|
|
1455
|
+
instructions: "A single update cannot add and remove the same field. Split into two calls if you need to recreate it."
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
if (updateFields !== undefined) {
|
|
1460
|
+
const hasInvalidUpdateFieldsShape = hasMissingStringField(updateFields, "id");
|
|
1461
|
+
if (hasInvalidUpdateFieldsShape) {
|
|
1462
|
+
validationIssues.push({
|
|
1463
|
+
message: "Each field in updateFields must include a non-empty 'id' string",
|
|
1464
|
+
instructions: UPDATE_FIELDS_ID_INSTRUCTIONS
|
|
1465
|
+
});
|
|
1466
|
+
} else {
|
|
1467
|
+
const updateErr = findIsUniqueInUpdateFields(updateFields);
|
|
1468
|
+
if (updateErr)
|
|
1469
|
+
validationIssues.push(updateErr);
|
|
1470
|
+
const updateMetadataErr = findInvalidFieldMetadata(updateFields);
|
|
1471
|
+
if (updateMetadataErr)
|
|
1472
|
+
validationIssues.push(updateMetadataErr);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const validationErr = combineValidationIssues(validationIssues);
|
|
1476
|
+
if (validationErr) {
|
|
1477
|
+
return failInvalidArgument(validationErr.message, validationErr.instructions);
|
|
1478
|
+
}
|
|
1479
|
+
let trimmedReason;
|
|
1480
|
+
const hasRemove = removedFieldNames.length > 0;
|
|
1481
|
+
if (hasRemove) {
|
|
1482
|
+
const reason = requireDestructiveConfirmation(options, `remove fields from entity '${id}'`, 'Pass --reason "<text>" to record why fields are being removed.');
|
|
1483
|
+
if (reason === null)
|
|
1484
|
+
return;
|
|
1485
|
+
trimmedReason = reason;
|
|
1486
|
+
}
|
|
1487
|
+
const hasFederatedRemove = FEDERATED_REMOVE_KEYS.some((key) => Array.isArray(input[key]) && input[key].length > 0) || Array.isArray(input.replaceJoins) || Array.isArray(input.replaceSourceJoins);
|
|
1488
|
+
if (hasFederatedRemove && trimmedReason === undefined) {
|
|
1489
|
+
const reason = requireDestructiveConfirmation(options, `remove or replace federated sources, fields or joins on entity '${id}'`, 'Pass --reason "<text>" to record why they are being removed or replaced.');
|
|
1490
|
+
if (reason === null)
|
|
1491
|
+
return;
|
|
1492
|
+
trimmedReason = reason;
|
|
1493
|
+
}
|
|
1494
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1495
|
+
if (!sdk)
|
|
1496
|
+
return;
|
|
1497
|
+
const warnings = [];
|
|
1498
|
+
if (input.addExternalSources !== undefined || input.addExternalFields !== undefined || input.joins !== undefined || input.replaceJoins !== undefined || input.updateExternalConnection !== undefined) {
|
|
1499
|
+
const {
|
|
1500
|
+
createFederatedMetadataProvider,
|
|
1501
|
+
existingColumnNames,
|
|
1502
|
+
existingDimensionObjects,
|
|
1503
|
+
existingSources,
|
|
1504
|
+
expandFederatedUpdate,
|
|
1505
|
+
sourceKey
|
|
1506
|
+
} = await import("./federated-payload-nfjfj8v9.js");
|
|
1507
|
+
const [entityErr, entity] = await catchError(sdk.entities.getById(id, options.folderKey ? { folderKey: options.folderKey } : undefined));
|
|
1508
|
+
if (entityErr || !entity) {
|
|
1509
|
+
return fail(`Could not read entity '${id}' to build the federated update`, "Check the entity id exists and you have access — 'df entities get <id>' (add --folder-key for a folder-scoped entity). If it exists, the service may be briefly unavailable; retry.");
|
|
1510
|
+
}
|
|
1511
|
+
const provider = createFederatedMetadataProvider(options.tenant, (eid, fk) => sdk.entities.getById(eid, fk ? { folderKey: fk } : undefined));
|
|
1512
|
+
const removed = new Set((Array.isArray(input.removeExternalSources) ? input.removeExternalSources : []).flatMap((r) => typeof r?.sourceObjectName === "string" && typeof r?.sourceConnectionId === "string" ? [
|
|
1513
|
+
sourceKey(r.sourceObjectName, r.sourceConnectionId)
|
|
1514
|
+
] : []));
|
|
1515
|
+
const current = existingSources(entity);
|
|
1516
|
+
const existingCols = existingColumnNames(entity, removed);
|
|
1517
|
+
const currentDimensions = existingDimensionObjects(entity);
|
|
1518
|
+
const entityRec = entity;
|
|
1519
|
+
const entityName = typeof entityRec.name === "string" ? entityRec.name : typeof entityRec.Name === "string" ? entityRec.Name : undefined;
|
|
1520
|
+
const [expandErr, expanded] = await catchError(expandFederatedUpdate(input, provider, current, existingCols, currentDimensions, entityName));
|
|
1521
|
+
if (expandErr) {
|
|
1522
|
+
return fail("Error building federated update payload", await extractErrorMessage(expandErr));
|
|
1523
|
+
}
|
|
1524
|
+
if (expanded.addExternalSources) {
|
|
1525
|
+
input.addExternalSources = expanded.addExternalSources;
|
|
1526
|
+
}
|
|
1527
|
+
if (expanded.addExternalFields) {
|
|
1528
|
+
input.addExternalFields = expanded.addExternalFields;
|
|
1529
|
+
}
|
|
1530
|
+
if (expanded.addSourceJoins) {
|
|
1531
|
+
const prior = Array.isArray(input.addSourceJoins) ? input.addSourceJoins : [];
|
|
1532
|
+
input.addSourceJoins = [
|
|
1533
|
+
...prior,
|
|
1534
|
+
...expanded.addSourceJoins
|
|
1535
|
+
];
|
|
1536
|
+
}
|
|
1537
|
+
if (expanded.replaceSourceJoins) {
|
|
1538
|
+
input.replaceSourceJoins = expanded.replaceSourceJoins;
|
|
1539
|
+
}
|
|
1540
|
+
if (expanded.updateExternalConnection) {
|
|
1541
|
+
input.updateExternalConnection = expanded.updateExternalConnection;
|
|
1542
|
+
}
|
|
1543
|
+
for (const warning of expanded.warnings ?? []) {
|
|
1544
|
+
logger.warn(warning);
|
|
1545
|
+
warnings.push(warning);
|
|
1546
|
+
}
|
|
1547
|
+
const droppedByExpansion = (expanded.removeExternalFields ?? []).flatMap((r) => Array.isArray(r.fieldNames) ? r.fieldNames : []);
|
|
1548
|
+
if (droppedByExpansion.length > 0 && trimmedReason === undefined) {
|
|
1549
|
+
const reason = requireDestructiveConfirmation(options, `drop ${droppedByExpansion.length} field(s) the new connection lacks from entity '${id}' (${droppedByExpansion.join(", ")}) — their mapping and any join that uses them are removed`, 'Pass --reason "<text>" to record why the fields are being dropped.');
|
|
1550
|
+
if (reason === null)
|
|
1551
|
+
return;
|
|
1552
|
+
trimmedReason = reason;
|
|
1553
|
+
}
|
|
1554
|
+
if (expanded.removeExternalFields) {
|
|
1555
|
+
input.removeExternalFields = [
|
|
1556
|
+
...Array.isArray(input.removeExternalFields) ? input.removeExternalFields : [],
|
|
1557
|
+
...expanded.removeExternalFields
|
|
1558
|
+
];
|
|
1559
|
+
}
|
|
1560
|
+
delete input.joins;
|
|
1561
|
+
delete input.replaceJoins;
|
|
1562
|
+
}
|
|
1563
|
+
const entityService = sdk.entities;
|
|
1564
|
+
const updatePayload = {
|
|
1565
|
+
...pickKnownUpdateKeys(input),
|
|
1566
|
+
...options.folderKey !== undefined && {
|
|
1567
|
+
folderKey: options.folderKey
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
const [updateError] = await catchError(entityService.updateById(id, updatePayload));
|
|
1571
|
+
if (updateError) {
|
|
1572
|
+
return fail("Error updating entity", await extractErrorMessage(updateError));
|
|
1573
|
+
}
|
|
1574
|
+
OutputFormatter.success({
|
|
1575
|
+
Result: RESULTS.Success,
|
|
1576
|
+
Code: "EntityUpdated",
|
|
1577
|
+
Data: {
|
|
1578
|
+
ID: id,
|
|
1579
|
+
...removedFieldNames.length > 0 && {
|
|
1580
|
+
RemovedFields: removedFieldNames
|
|
1581
|
+
},
|
|
1582
|
+
...trimmedReason !== undefined && {
|
|
1583
|
+
Reason: trimmedReason
|
|
1584
|
+
},
|
|
1585
|
+
...warnings.length > 0 && { Warnings: warnings }
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
entities.command("delete").description("Delete a Data Fabric entity (irreversible)").argument("<id>", "Entity ID on the tenant; with --local, the entity name").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-y, --yes", "Acknowledge this is an irreversible operation").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Reason for the deletion — echoed back in the response so the caller can log it").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").option("--local", "Act on entities authored in the local solution instead of the tenant. No login required; nothing exists on a tenant until the solution deploys.").option("--project-name <name>", "With --local: the Entity project that owns the entity. Optional — omitted, the owner is found by name; with --force and no owner at all, an orphaned definition resource is cleaned up.").option("--force", "With --local: delete a stub/resource pair that does not verify — anything 'entities list --local' reports with a Problem — or a definition resource no project declares any more (no --project-name needed for that). Every check runs before anything is removed: a resource another project still declares, or one describing a referenced platform entity, is refused and nothing changes.").examples([...ENTITIES_DELETE_EXAMPLES, ...LOCAL_DELETE_EXAMPLES]).trackedAction(processContext, async (id, options) => {
|
|
1590
|
+
if (rejectMisplacedLocalOptions(options, ["folderKey", "reason", "tenant"], ["force"])) {
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
if (options.local) {
|
|
1594
|
+
const local = await loadLocalHandlersAsync();
|
|
1595
|
+
if (local === undefined)
|
|
1596
|
+
return;
|
|
1597
|
+
return local.runLocalDelete(id, options);
|
|
1598
|
+
}
|
|
1599
|
+
const reason = requireDestructiveConfirmation(options, `delete entity '${id}'`, 'Pass --reason "<text>" to record why the entity is being deleted.');
|
|
1600
|
+
if (reason === null)
|
|
1601
|
+
return;
|
|
1602
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1603
|
+
if (!sdk)
|
|
1604
|
+
return;
|
|
1605
|
+
const entityService = sdk.entities;
|
|
1606
|
+
const [deleteError] = await catchError(entityService.deleteById(id, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
1607
|
+
if (deleteError) {
|
|
1608
|
+
return fail(`Error deleting entity '${id}'`, await extractErrorMessage(deleteError));
|
|
1609
|
+
}
|
|
1610
|
+
OutputFormatter.success({
|
|
1611
|
+
Result: RESULTS.Success,
|
|
1612
|
+
Code: "EntityDeleted",
|
|
1613
|
+
Data: { ID: id, Reason: reason }
|
|
1614
|
+
});
|
|
1615
|
+
});
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
// src/commands/files.ts
|
|
1619
|
+
var FILES_UPLOAD_EXAMPLES = [
|
|
1620
|
+
{
|
|
1621
|
+
Description: "Upload a file attachment to a record field",
|
|
1622
|
+
Command: "uip df files upload a1b2c3d4-0000-0000-0000-000000000001 b2c3d4e5-0000-0000-0000-000000000001 invoice --file ./invoice.pdf",
|
|
1623
|
+
Output: {
|
|
1624
|
+
Code: "FileUploaded",
|
|
1625
|
+
Data: {
|
|
1626
|
+
EntityId: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
1627
|
+
RecordId: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1628
|
+
FieldName: "invoice",
|
|
1629
|
+
FileName: "invoice.pdf"
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
];
|
|
1634
|
+
var FILES_DOWNLOAD_EXAMPLES = [
|
|
1635
|
+
{
|
|
1636
|
+
Description: "Download a file attachment from a record field",
|
|
1637
|
+
Command: "uip df files download a1b2c3d4-0000-0000-0000-000000000001 b2c3d4e5-0000-0000-0000-000000000001 invoice --destination ./invoice.pdf",
|
|
1638
|
+
Output: {
|
|
1639
|
+
Code: "FileDownloaded",
|
|
1640
|
+
Data: {
|
|
1641
|
+
EntityId: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
1642
|
+
RecordId: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1643
|
+
FieldName: "invoice",
|
|
1644
|
+
OutputPath: "./invoice.pdf"
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
];
|
|
1649
|
+
var FILES_DELETE_EXAMPLES = [
|
|
1650
|
+
{
|
|
1651
|
+
Description: "Delete a file attachment from a record field",
|
|
1652
|
+
Command: "uip df files delete a1b2c3d4-0000-0000-0000-000000000001 b2c3d4e5-0000-0000-0000-000000000001 invoice",
|
|
1653
|
+
Output: {
|
|
1654
|
+
Code: "FileDeleted",
|
|
1655
|
+
Data: {
|
|
1656
|
+
EntityId: "a1b2c3d4-0000-0000-0000-000000000001",
|
|
1657
|
+
RecordId: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1658
|
+
FieldName: "invoice"
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
];
|
|
1663
|
+
var registerFilesCommand = (program) => {
|
|
1664
|
+
const files = program.command("files").description("Manage file attachments on Data Fabric entity records");
|
|
1665
|
+
files.command("upload").description("Upload a file to a field on an entity record").argument("<entity-id>", "Entity ID").argument("<record-id>", "Record ID").argument("<field-name>", "Name of the file field (case-sensitive)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", "Path to the file to upload").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(FILES_UPLOAD_EXAMPLES).trackedAction(processContext, async (entityId, recordId, fieldName, options) => {
|
|
1666
|
+
if (!options.file) {
|
|
1667
|
+
return fail("A file path is required", "Provide a file path via --file.");
|
|
1668
|
+
}
|
|
1669
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1670
|
+
if (!sdk)
|
|
1671
|
+
return;
|
|
1672
|
+
const [readError, fileContent] = await catchError(readFileBinary(options.file));
|
|
1673
|
+
if (readError) {
|
|
1674
|
+
return fail("Error reading file", readError.message);
|
|
1675
|
+
}
|
|
1676
|
+
const fsInst = getFileSystem();
|
|
1677
|
+
const fileName = fsInst.path.basename(options.file) || "upload";
|
|
1678
|
+
const [uploadError] = await catchError(sdk.entities.uploadAttachment({ id: entityId }, recordId, fieldName, new File([fileContent], fileName), options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
1679
|
+
if (uploadError) {
|
|
1680
|
+
return fail(`Error uploading file to field '${fieldName}'`, await extractErrorMessage(uploadError));
|
|
1681
|
+
}
|
|
1682
|
+
OutputFormatter.success({
|
|
1683
|
+
Result: RESULTS.Success,
|
|
1684
|
+
Code: "FileUploaded",
|
|
1685
|
+
Data: {
|
|
1686
|
+
EntityId: entityId,
|
|
1687
|
+
RecordId: recordId,
|
|
1688
|
+
FieldName: fieldName,
|
|
1689
|
+
FileName: fileName
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
1692
|
+
});
|
|
1693
|
+
files.command("download").description("Download a file from a field on an entity record").argument("<entity-id>", "Entity ID").argument("<record-id>", "Record ID").argument("<field-name>", "Name of the file field (case-sensitive)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--destination <path>", "Output file path (defaults to <record-id>_<field-name>.bin)").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(FILES_DOWNLOAD_EXAMPLES).trackedAction(processContext, async (entityId, recordId, fieldName, options) => {
|
|
1694
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1695
|
+
if (!sdk)
|
|
1696
|
+
return;
|
|
1697
|
+
const [downloadError, blob] = await catchError(sdk.entities.downloadAttachment({ id: entityId }, recordId, fieldName, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
1698
|
+
if (downloadError) {
|
|
1699
|
+
return fail(`Error downloading file from field '${fieldName}'`, await extractErrorMessage(downloadError));
|
|
1700
|
+
}
|
|
1701
|
+
const outputPath = options.destination ?? `${recordId}_${fieldName}.bin`;
|
|
1702
|
+
const [bufferError, arrayBuffer] = await catchError(blob.arrayBuffer());
|
|
1703
|
+
if (bufferError) {
|
|
1704
|
+
return fail("Error reading downloaded file content", bufferError.message);
|
|
1705
|
+
}
|
|
1706
|
+
const [writeError] = await catchError(writeFileBinary(outputPath, new Uint8Array(arrayBuffer)));
|
|
1707
|
+
if (writeError) {
|
|
1708
|
+
return fail("Error writing downloaded file", writeError.message);
|
|
1709
|
+
}
|
|
1710
|
+
OutputFormatter.success({
|
|
1711
|
+
Result: RESULTS.Success,
|
|
1712
|
+
Code: "FileDownloaded",
|
|
1713
|
+
Data: {
|
|
1714
|
+
EntityId: entityId,
|
|
1715
|
+
RecordId: recordId,
|
|
1716
|
+
FieldName: fieldName,
|
|
1717
|
+
OutputPath: outputPath
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
});
|
|
1721
|
+
files.command("delete").description("Delete a file from a field on an entity record").argument("<entity-id>", "Entity ID").argument("<record-id>", "Record ID").argument("<field-name>", "Name of the file field (case-sensitive)").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-y, --yes", "Acknowledge this is an irreversible operation").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Reason for the deletion — echoed back in the response so the caller can log it").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(FILES_DELETE_EXAMPLES).trackedAction(processContext, async (entityId, recordId, fieldName, options) => {
|
|
1722
|
+
const reason = requireDestructiveConfirmation(options, `delete the file in field '${fieldName}'`, 'Pass --reason "<text>" to record why the file is being deleted.');
|
|
1723
|
+
if (reason === null)
|
|
1724
|
+
return;
|
|
1725
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1726
|
+
if (!sdk)
|
|
1727
|
+
return;
|
|
1728
|
+
const [deleteError] = await catchError(sdk.entities.deleteAttachment({ id: entityId }, recordId, fieldName, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
1729
|
+
if (deleteError) {
|
|
1730
|
+
return fail(`Error deleting file from field '${fieldName}'`, await extractErrorMessage(deleteError));
|
|
1731
|
+
}
|
|
1732
|
+
OutputFormatter.success({
|
|
1733
|
+
Result: RESULTS.Success,
|
|
1734
|
+
Code: "FileDeleted",
|
|
1735
|
+
Data: {
|
|
1736
|
+
EntityId: entityId,
|
|
1737
|
+
RecordId: recordId,
|
|
1738
|
+
FieldName: fieldName,
|
|
1739
|
+
Reason: reason
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
});
|
|
1743
|
+
};
|
|
1744
|
+
async function writeFileBinary(filePath, data) {
|
|
1745
|
+
const fs = getFileSystem();
|
|
1746
|
+
await fs.writeFile(filePath, data);
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// src/commands/records.ts
|
|
1750
|
+
async function loadFileFieldNames(sdk, entityId, folderKey) {
|
|
1751
|
+
const names = new Set;
|
|
1752
|
+
if (!sdk)
|
|
1753
|
+
return names;
|
|
1754
|
+
const [schemaErr, entity] = await catchError(sdk.entities.getById(entityId, folderKey !== undefined ? { folderKey } : undefined));
|
|
1755
|
+
if (schemaErr)
|
|
1756
|
+
return names;
|
|
1757
|
+
const rec = entity;
|
|
1758
|
+
const fieldList = rec.fields ?? rec.Fields ?? [];
|
|
1759
|
+
for (const f of fieldList) {
|
|
1760
|
+
const dataType = f.fieldDataType ?? f.FieldDataType;
|
|
1761
|
+
const typeName = dataType?.name ?? dataType?.Name;
|
|
1762
|
+
const fieldName = typeof f.name === "string" ? f.name : typeof f.Name === "string" ? f.Name : undefined;
|
|
1763
|
+
if (typeName === "FILE" && fieldName !== undefined) {
|
|
1764
|
+
names.add(fieldName);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
return names;
|
|
1768
|
+
}
|
|
1769
|
+
var RECORDS_LIST_EXAMPLES = [
|
|
1770
|
+
{
|
|
1771
|
+
Description: "List records in an entity. MULTILINE_MAX fields return only a preview (see 'notes' below): content truncated to 10,000 chars with a '...[Truncated]' suffix, or a 'HasValue=true Length=N' marker, depending on the tenant — full value via 'records get'.",
|
|
1772
|
+
Command: "uip df records list a1b2c3d4-0000-0000-0000-000000000001 --limit 2",
|
|
1773
|
+
Output: {
|
|
1774
|
+
Code: "RecordList",
|
|
1775
|
+
Data: {
|
|
1776
|
+
items: [
|
|
1777
|
+
{
|
|
1778
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1779
|
+
amount: 1500,
|
|
1780
|
+
notes: "Expense report for Q3 travel...[Truncated]"
|
|
1781
|
+
},
|
|
1782
|
+
{
|
|
1783
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000002",
|
|
1784
|
+
amount: 2750,
|
|
1785
|
+
notes: null
|
|
1786
|
+
}
|
|
1787
|
+
],
|
|
1788
|
+
totalCount: 2,
|
|
1789
|
+
hasNextPage: false
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
];
|
|
1794
|
+
var RECORDS_GET_EXAMPLES = [
|
|
1795
|
+
{
|
|
1796
|
+
Description: "Get a record by ID. Returns MULTILINE_MAX fields in full (see 'notes' below).",
|
|
1797
|
+
Command: "uip df records get a1b2c3d4-0000-0000-0000-000000000001 b2c3d4e5-0000-0000-0000-000000000001",
|
|
1798
|
+
Output: {
|
|
1799
|
+
Code: "RecordDetails",
|
|
1800
|
+
Data: {
|
|
1801
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1802
|
+
amount: 1500,
|
|
1803
|
+
status: "Paid",
|
|
1804
|
+
notes: "Customer disputed the Q1 late fee. Timeline of the case: … (the complete 20,000-character text, returned in full)"
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
];
|
|
1809
|
+
var RECORDS_INSERT_EXAMPLES = [
|
|
1810
|
+
{
|
|
1811
|
+
Description: "Insert a record",
|
|
1812
|
+
Command: `uip df records insert a1b2c3d4-0000-0000-0000-000000000001 --body '{"amount":1500,"status":"New"}'`,
|
|
1813
|
+
Output: {
|
|
1814
|
+
Code: "RecordInserted",
|
|
1815
|
+
Data: {
|
|
1816
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000010",
|
|
1817
|
+
amount: 1500,
|
|
1818
|
+
status: "New"
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
},
|
|
1822
|
+
{
|
|
1823
|
+
Description: "Insert a record into an entity that has choice-set and relationship fields. " + "CHOICE_SET_SINGLE → pass the choice value's 'numberId' (integer, NOT the name string — look it up via 'df choice-sets list-values <id>'). " + "CHOICE_SET_MULTIPLE → pass an array of numberId integers. " + "RELATIONSHIP → always pass the target record's Id (UUID), regardless of which 'referenceFieldId' the schema uses for the join (the referenceFieldId configures the join, not the stored value).",
|
|
1824
|
+
Command: `uip df records insert a1b2c3d4-0000-0000-0000-000000000004 --body '{"category":0,"tags":[1,3],"submitter":"e1f2a3b4-0000-0000-0000-000000000001","amount":250}'`,
|
|
1825
|
+
Output: {
|
|
1826
|
+
Code: "RecordInserted",
|
|
1827
|
+
Data: {
|
|
1828
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000020",
|
|
1829
|
+
category: 0,
|
|
1830
|
+
tags: [1, 3],
|
|
1831
|
+
submitter: "e1f2a3b4-0000-0000-0000-000000000001",
|
|
1832
|
+
amount: 250
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
];
|
|
1837
|
+
var RECORDS_UPDATE_EXAMPLES = [
|
|
1838
|
+
{
|
|
1839
|
+
Description: "Update a record",
|
|
1840
|
+
Command: `uip df records update a1b2c3d4-0000-0000-0000-000000000001 --body '{"Id":"b2c3d4e5-0000-0000-0000-000000000001","status":"Paid"}'`,
|
|
1841
|
+
Output: {
|
|
1842
|
+
Code: "RecordUpdated",
|
|
1843
|
+
Data: {
|
|
1844
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1845
|
+
status: "Paid"
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
];
|
|
1850
|
+
var RECORDS_QUERY_EXAMPLES = [
|
|
1851
|
+
{
|
|
1852
|
+
Description: "Filter records — exact keys: filterGroup / queryFilters / fieldName / operator / value. " + "Operators: = != > < >= <= contains 'not contains' startswith endswith in 'not in'. " + "Not accepted: 'filters', 'field', '==', 'Equals', 'eq', 'like'.",
|
|
1853
|
+
Command: "uip df records query a1b2c3d4-0000-0000-0000-000000000001 " + `--body '{"filterGroup":{"logicalOperator":0,"queryFilters":[{"fieldName":"status","operator":"=","value":"Paid"}]}}'`,
|
|
1854
|
+
Output: {
|
|
1855
|
+
Code: "RecordQuery",
|
|
1856
|
+
Data: {
|
|
1857
|
+
items: [
|
|
1858
|
+
{
|
|
1859
|
+
Id: "b2c3d4e5-0000-0000-0000-000000000001",
|
|
1860
|
+
status: "Paid"
|
|
1861
|
+
}
|
|
1862
|
+
],
|
|
1863
|
+
totalCount: 1,
|
|
1864
|
+
hasNextPage: false
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
},
|
|
1868
|
+
{
|
|
1869
|
+
Description: "Aggregate — COUNT grouped by a field.",
|
|
1870
|
+
Command: "uip df records query a1b2c3d4-0000-0000-0000-000000000001 " + `--body '{"aggregates":[{"function":"COUNT","field":"Id","alias":"total"}],"groupBy":["status"]}'`,
|
|
1871
|
+
Output: {
|
|
1872
|
+
Code: "RecordQuery",
|
|
1873
|
+
Data: {
|
|
1874
|
+
items: [
|
|
1875
|
+
{ status: "Paid", total: 12 },
|
|
1876
|
+
{ status: "Pending", total: 3 }
|
|
1877
|
+
]
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
];
|
|
1882
|
+
var RECORDS_DELETE_EXAMPLES = [
|
|
1883
|
+
{
|
|
1884
|
+
Description: "Delete records by ID",
|
|
1885
|
+
Command: "uip df records delete a1b2c3d4-0000-0000-0000-000000000001 b2c3d4e5-0000-0000-0000-000000000001",
|
|
1886
|
+
Output: {
|
|
1887
|
+
Code: "RecordsDeleted",
|
|
1888
|
+
Data: {
|
|
1889
|
+
SuccessCount: 1,
|
|
1890
|
+
FailureCount: 0,
|
|
1891
|
+
SuccessRecords: [
|
|
1892
|
+
{ Id: "b2c3d4e5-0000-0000-0000-000000000001" }
|
|
1893
|
+
],
|
|
1894
|
+
FailureRecords: []
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
];
|
|
1899
|
+
var registerRecordsCommand = (program) => {
|
|
1900
|
+
const records = program.command("records").description("Manage Data Fabric entity records");
|
|
1901
|
+
records.command("list").description("List records in a Data Fabric entity").argument("<id>", "Entity ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-l, --limit <number>", "Number of records to return per page", "50").option("-o, --offset <number>", "Start from the page containing this record index (rounded down to nearest page boundary; (mutually exclusive with --cursor)").option("--cursor <cursor>", "Pagination cursor from a previous response to fetch the next page").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(RECORDS_LIST_EXAMPLES).trackedAction(processContext, async (entityId, options) => {
|
|
1902
|
+
const pageSize = Number(options.limit);
|
|
1903
|
+
if (Number.isNaN(pageSize) || pageSize < 1) {
|
|
1904
|
+
return fail("Invalid --limit value", "Provide a positive integer for --limit.");
|
|
1905
|
+
}
|
|
1906
|
+
if (options.cursor !== undefined && options.offset !== undefined) {
|
|
1907
|
+
return fail("--offset and --cursor are mutually exclusive", "Use --offset to jump to a position by record count, or --cursor to continue from a previous response.");
|
|
1908
|
+
}
|
|
1909
|
+
let jumpToPage;
|
|
1910
|
+
if (options.offset !== undefined) {
|
|
1911
|
+
const offsetValue = Number(options.offset);
|
|
1912
|
+
if (Number.isNaN(offsetValue) || offsetValue < 0) {
|
|
1913
|
+
return fail("Invalid --offset value", "Provide a non-negative integer for --offset.");
|
|
1914
|
+
}
|
|
1915
|
+
jumpToPage = Math.floor(offsetValue / pageSize) + 1;
|
|
1916
|
+
}
|
|
1917
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1918
|
+
if (!sdk)
|
|
1919
|
+
return;
|
|
1920
|
+
const listPaginationOptions = options.cursor !== undefined ? { pageSize, cursor: { value: options.cursor } } : jumpToPage !== undefined ? { pageSize, jumpToPage } : { pageSize };
|
|
1921
|
+
const [listError, result] = await catchError(sdk.entities.getAllRecords(entityId, {
|
|
1922
|
+
...listPaginationOptions,
|
|
1923
|
+
...options.folderKey !== undefined && {
|
|
1924
|
+
folderKey: options.folderKey
|
|
1925
|
+
}
|
|
1926
|
+
}));
|
|
1927
|
+
if (listError) {
|
|
1928
|
+
return fail("Error listing records", await extractErrorMessage(listError));
|
|
1929
|
+
}
|
|
1930
|
+
OutputFormatter.success({
|
|
1931
|
+
Result: RESULTS.Success,
|
|
1932
|
+
Code: "RecordList",
|
|
1933
|
+
Data: result
|
|
1934
|
+
});
|
|
1935
|
+
});
|
|
1936
|
+
records.command("get").description("Get a single record by ID").argument("<id>", "Entity ID").argument("<key>", "Record ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(RECORDS_GET_EXAMPLES).trackedAction(processContext, async (entityId, recordId, options) => {
|
|
1937
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1938
|
+
if (!sdk)
|
|
1939
|
+
return;
|
|
1940
|
+
const [getError, record] = await catchError(sdk.entities.getRecordById(entityId, recordId, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
1941
|
+
if (getError) {
|
|
1942
|
+
return fail(`Error getting record '${recordId}'`, await extractErrorMessage(getError));
|
|
1943
|
+
}
|
|
1944
|
+
if (!record) {
|
|
1945
|
+
return fail(`Record '${recordId}' not found in entity '${entityId}'`, "Verify the record ID exists. Use 'df records list' to see available records.");
|
|
1946
|
+
}
|
|
1947
|
+
OutputFormatter.success({
|
|
1948
|
+
Result: RESULTS.Success,
|
|
1949
|
+
Code: "RecordDetails",
|
|
1950
|
+
Data: record
|
|
1951
|
+
});
|
|
1952
|
+
});
|
|
1953
|
+
records.command("insert").description("Insert records into a Data Fabric entity").argument("<id>", "Entity ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", "Path to JSON file with record data (object or array of objects)").option("--body <json>", "Inline JSON record data (object or array of objects; use `-` to read from stdin)").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(RECORDS_INSERT_EXAMPLES).trackedAction(processContext, async (entityId, options) => {
|
|
1954
|
+
const [parseError, rawData] = await catchError(resolveJsonInput(options.file, options.body));
|
|
1955
|
+
if (parseError) {
|
|
1956
|
+
return fail("Error parsing input data", parseError.message);
|
|
1957
|
+
}
|
|
1958
|
+
const sdk = await connectOrFail(options.tenant);
|
|
1959
|
+
if (!sdk)
|
|
1960
|
+
return;
|
|
1961
|
+
const data = rawData;
|
|
1962
|
+
const recordsList = Array.isArray(data) ? data : [data];
|
|
1963
|
+
const folderOptions = options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined;
|
|
1964
|
+
const fileNames = await loadFileFieldNames(sdk, entityId, options.folderKey);
|
|
1965
|
+
const fileErr = findFilePayloadKeys(recordsList, fileNames);
|
|
1966
|
+
if (fileErr)
|
|
1967
|
+
return fail(fileErr.message, fileErr.instructions);
|
|
1968
|
+
if (recordsList.length === 1) {
|
|
1969
|
+
const [insertError, result] = await catchError(sdk.entities.insertRecord({ id: entityId }, recordsList[0], folderOptions));
|
|
1970
|
+
if (insertError) {
|
|
1971
|
+
return fail("Error inserting record", await extractErrorMessage(insertError));
|
|
1972
|
+
}
|
|
1973
|
+
OutputFormatter.success({
|
|
1974
|
+
Result: RESULTS.Success,
|
|
1975
|
+
Code: "RecordInserted",
|
|
1976
|
+
Data: result
|
|
1977
|
+
});
|
|
1978
|
+
} else {
|
|
1979
|
+
const [insertError, result] = await catchError(sdk.entities.insertRecords({ id: entityId }, recordsList, folderOptions));
|
|
1980
|
+
if (insertError) {
|
|
1981
|
+
return fail("Error inserting records", await extractErrorMessage(insertError));
|
|
1982
|
+
}
|
|
1983
|
+
const r = result;
|
|
1984
|
+
const failureCount = r.failureRecords?.length ?? 0;
|
|
1985
|
+
OutputFormatter.success({
|
|
1986
|
+
Result: RESULTS.Success,
|
|
1987
|
+
Code: "RecordsBatchInserted",
|
|
1988
|
+
Data: {
|
|
1989
|
+
SuccessCount: r.successRecords?.length ?? 0,
|
|
1990
|
+
FailureCount: failureCount,
|
|
1991
|
+
SuccessRecords: r.successRecords ?? [],
|
|
1992
|
+
FailureRecords: r.failureRecords ?? []
|
|
1993
|
+
}
|
|
1994
|
+
});
|
|
1995
|
+
if (failureCount > 0) {
|
|
1996
|
+
processContext.exit(1);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
records.command("update").description("Update records in a Data Fabric entity").argument("<id>", "Entity ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", "Path to JSON file with record data (must include Id field)").option("--body <json>", "Inline JSON record data (must include Id field; use `-` to read from stdin)").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(RECORDS_UPDATE_EXAMPLES).trackedAction(processContext, async (entityId, options) => {
|
|
2001
|
+
const [parseError, rawData] = await catchError(resolveJsonInput(options.file, options.body));
|
|
2002
|
+
if (parseError) {
|
|
2003
|
+
return fail("Error parsing input data", parseError.message);
|
|
2004
|
+
}
|
|
2005
|
+
const sdk = await connectOrFail(options.tenant);
|
|
2006
|
+
if (!sdk)
|
|
2007
|
+
return;
|
|
2008
|
+
const data = rawData;
|
|
2009
|
+
const recordsList = Array.isArray(data) ? data : [data];
|
|
2010
|
+
const folderOptions = options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined;
|
|
2011
|
+
const fileNames = await loadFileFieldNames(sdk, entityId, options.folderKey);
|
|
2012
|
+
const fileErr = findFilePayloadKeys(recordsList, fileNames);
|
|
2013
|
+
if (fileErr)
|
|
2014
|
+
return fail(fileErr.message, fileErr.instructions);
|
|
2015
|
+
if (recordsList.length === 1) {
|
|
2016
|
+
const record = recordsList[0];
|
|
2017
|
+
const recordId = record.Id !== undefined ? record.Id : record.id;
|
|
2018
|
+
if (recordId === undefined || recordId === null) {
|
|
2019
|
+
return fail("Record must include an 'Id' field", "Provide the record ID in the JSON data.");
|
|
2020
|
+
}
|
|
2021
|
+
const [updateError, result] = await catchError(sdk.entities.updateRecord({ id: entityId }, String(recordId), record, folderOptions));
|
|
2022
|
+
if (updateError) {
|
|
2023
|
+
return fail("Error updating record", await extractErrorMessage(updateError));
|
|
2024
|
+
}
|
|
2025
|
+
OutputFormatter.success({
|
|
2026
|
+
Result: RESULTS.Success,
|
|
2027
|
+
Code: "RecordUpdated",
|
|
2028
|
+
Data: result
|
|
2029
|
+
});
|
|
2030
|
+
} else {
|
|
2031
|
+
const missingId = recordsList.find((r2) => r2.Id == null && r2.id == null);
|
|
2032
|
+
if (missingId) {
|
|
2033
|
+
return fail("All records must include an 'Id' field", "Provide the record ID in each JSON object.");
|
|
2034
|
+
}
|
|
2035
|
+
const [updateError, result] = await catchError(sdk.entities.updateRecords({ id: entityId }, recordsList, folderOptions));
|
|
2036
|
+
if (updateError) {
|
|
2037
|
+
return fail("Error updating records", await extractErrorMessage(updateError));
|
|
2038
|
+
}
|
|
2039
|
+
const r = result;
|
|
2040
|
+
const failureCount = r.failureRecords?.length ?? 0;
|
|
2041
|
+
OutputFormatter.success({
|
|
2042
|
+
Result: RESULTS.Success,
|
|
2043
|
+
Code: "RecordsBatchUpdated",
|
|
2044
|
+
Data: {
|
|
2045
|
+
SuccessCount: r.successRecords?.length ?? 0,
|
|
2046
|
+
FailureCount: failureCount,
|
|
2047
|
+
SuccessRecords: r.successRecords ?? [],
|
|
2048
|
+
FailureRecords: r.failureRecords ?? []
|
|
2049
|
+
}
|
|
2050
|
+
});
|
|
2051
|
+
if (failureCount > 0) {
|
|
2052
|
+
processContext.exit(1);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
records.command("query").description("Query records in a Data Fabric entity with filters, sorting, and aggregates. " + "Provide a JSON object via --body or --file with optional keys: " + "filterGroup, sortOptions (use isDescending: true/false), selectedFields, " + "aggregates (function: COUNT/SUM/AVG/MIN/MAX, field, alias?), groupBy, " + "joins (cross-entity, up to 3; native entities only). " + "Federated entities: filterGroup / sortOptions / selectedFields work, but do NOT use joins " + "(a federated entity already merges its own sources; to combine it with another entity, add that " + "as a source in the entity definition instead) and aggregates / groupBy are ignored.").argument("<id>", "Entity ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", "Path to JSON file with query options (filterGroup, selectedFields, sortOptions, aggregates, groupBy)").option("--body <json>", "Inline JSON query options (filterGroup, selectedFields, sortOptions, aggregates, groupBy; use `-` to read from stdin)").option("-l, --limit <number>", "Number of records to return per page", "50").option("-o, --offset <number>", "Start from the page containing this record index (rounded down to nearest page boundary;(mutually exclusive with --cursor)").option("--cursor <cursor>", "Pagination cursor from a previous response to fetch the next page").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(RECORDS_QUERY_EXAMPLES).trackedAction(processContext, async (entityId, options) => {
|
|
2057
|
+
const pageSize = Number(options.limit);
|
|
2058
|
+
if (Number.isNaN(pageSize) || pageSize < 1) {
|
|
2059
|
+
return fail("Invalid --limit value", "Provide a positive integer for --limit.");
|
|
2060
|
+
}
|
|
2061
|
+
if (options.cursor !== undefined && options.offset !== undefined) {
|
|
2062
|
+
return fail("--offset and --cursor are mutually exclusive", "Use --offset to jump to a position by record count, or --cursor to continue from a previous response.");
|
|
2063
|
+
}
|
|
2064
|
+
let jumpToPage;
|
|
2065
|
+
if (options.offset !== undefined) {
|
|
2066
|
+
const offsetValue = Number(options.offset);
|
|
2067
|
+
if (Number.isNaN(offsetValue) || offsetValue < 0) {
|
|
2068
|
+
return fail("Invalid --offset value", "Provide a non-negative integer for --offset.");
|
|
2069
|
+
}
|
|
2070
|
+
jumpToPage = Math.floor(offsetValue / pageSize) + 1;
|
|
2071
|
+
}
|
|
2072
|
+
let queryBody = null;
|
|
2073
|
+
if (options.file !== undefined || options.body !== undefined) {
|
|
2074
|
+
const [parseError, parsed] = await catchError(readJsonInput(options.file, options.body, "Provide a JSON object with query options via --file or --body."));
|
|
2075
|
+
if (parseError) {
|
|
2076
|
+
return fail("Error parsing query options", parseError.message);
|
|
2077
|
+
}
|
|
2078
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
2079
|
+
return fail("Query options must be a JSON object", "Provide a JSON object (not an array) with filterGroup, selectedFields, sortOptions, aggregates, or groupBy.");
|
|
2080
|
+
}
|
|
2081
|
+
queryBody = parsed;
|
|
2082
|
+
const filterErr = validateQueryFilter(queryBody.filterGroup);
|
|
2083
|
+
if (filterErr)
|
|
2084
|
+
return fail(filterErr.message, filterErr.instructions);
|
|
2085
|
+
const aggregateErr = validateQueryAggregates(queryBody);
|
|
2086
|
+
if (aggregateErr)
|
|
2087
|
+
return fail(aggregateErr.message, aggregateErr.instructions);
|
|
2088
|
+
}
|
|
2089
|
+
const sdk = await connectOrFail(options.tenant);
|
|
2090
|
+
if (!sdk)
|
|
2091
|
+
return;
|
|
2092
|
+
const queryPaginationOptions = options.cursor !== undefined ? { pageSize, cursor: { value: options.cursor } } : jumpToPage !== undefined ? { pageSize, jumpToPage } : { pageSize };
|
|
2093
|
+
const [queryError, result] = await catchError(sdk.entities.queryRecords({ id: entityId }, {
|
|
2094
|
+
...queryBody !== null && queryBody,
|
|
2095
|
+
...queryPaginationOptions,
|
|
2096
|
+
...options.folderKey !== undefined && {
|
|
2097
|
+
folderKey: options.folderKey
|
|
2098
|
+
}
|
|
2099
|
+
}));
|
|
2100
|
+
if (queryError) {
|
|
2101
|
+
return fail("Error querying records", await extractErrorMessage(queryError));
|
|
2102
|
+
}
|
|
2103
|
+
OutputFormatter.success({
|
|
2104
|
+
Result: RESULTS.Success,
|
|
2105
|
+
Code: "RecordQuery",
|
|
2106
|
+
Data: result
|
|
2107
|
+
});
|
|
2108
|
+
});
|
|
2109
|
+
records.command("import").description("Import records from a CSV file into a Data Fabric entity").argument("<id>", "Entity ID").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-f, --file <path>", "Path to the CSV file to import").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").trackedAction(processContext, async (entityId, options) => {
|
|
2110
|
+
if (options.file === undefined) {
|
|
2111
|
+
return fail("A CSV file path is required", "Provide a CSV file path via --file.");
|
|
2112
|
+
}
|
|
2113
|
+
const [readError, fileContent] = await catchError(readFileBinary(options.file));
|
|
2114
|
+
if (readError) {
|
|
2115
|
+
return fail("Error reading CSV file", readError.message);
|
|
2116
|
+
}
|
|
2117
|
+
const sdk = await connectOrFail(options.tenant);
|
|
2118
|
+
if (!sdk)
|
|
2119
|
+
return;
|
|
2120
|
+
const fs = getFileSystem();
|
|
2121
|
+
const fileName = fs.path.basename(options.file) || "import.csv";
|
|
2122
|
+
const csvFile = new File([fileContent], fileName, { type: "text/csv" });
|
|
2123
|
+
const [importError, result] = await catchError(sdk.entities.importRecords({ id: entityId }, csvFile, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
2124
|
+
if (importError) {
|
|
2125
|
+
return fail("Error importing records", await extractErrorMessage(importError));
|
|
2126
|
+
}
|
|
2127
|
+
const r = result;
|
|
2128
|
+
OutputFormatter.success({
|
|
2129
|
+
Result: RESULTS.Success,
|
|
2130
|
+
Code: "RecordsImported",
|
|
2131
|
+
Data: {
|
|
2132
|
+
InsertedRecords: r.insertedRecords ?? 0,
|
|
2133
|
+
TotalRecords: r.totalRecords ?? 0,
|
|
2134
|
+
...r.errorFileLink !== undefined && {
|
|
2135
|
+
ErrorFileLink: r.errorFileLink
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
});
|
|
2139
|
+
});
|
|
2140
|
+
records.command("delete").description("Delete records from a Data Fabric entity").argument("<id>", "Entity ID").argument("<key...>", "Record IDs to delete").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("-y, --yes", "Acknowledge this is an irreversible operation").addOption(new Option("--confirm", "Deprecated alias for --yes").hideHelp()).option("--reason <reason>", "Reason for the deletion — echoed back in the response so the caller can log it").option("--folder-key <key>", "Folder key (GUID) of the folder containing the entity (for folder-scoped entities)").examples(RECORDS_DELETE_EXAMPLES).trackedAction(processContext, async (entityId, recordIds, options) => {
|
|
2141
|
+
const reason = requireDestructiveConfirmation(options, `delete ${recordIds.length} record(s) from entity '${entityId}'`, 'Pass --reason "<text>" to record why the records are being deleted.');
|
|
2142
|
+
if (reason === null)
|
|
2143
|
+
return;
|
|
2144
|
+
const sdk = await connectOrFail(options.tenant);
|
|
2145
|
+
if (!sdk)
|
|
2146
|
+
return;
|
|
2147
|
+
const [deleteError, result] = await catchError(sdk.entities.deleteRecords({ id: entityId }, recordIds, options.folderKey !== undefined ? { folderKey: options.folderKey } : undefined));
|
|
2148
|
+
if (deleteError) {
|
|
2149
|
+
return fail("Error deleting records", await extractErrorMessage(deleteError));
|
|
2150
|
+
}
|
|
2151
|
+
const r = result;
|
|
2152
|
+
const failureCount = r.failureRecords?.length ?? 0;
|
|
2153
|
+
OutputFormatter.success({
|
|
2154
|
+
Result: RESULTS.Success,
|
|
2155
|
+
Code: "RecordsDeleted",
|
|
2156
|
+
Data: {
|
|
2157
|
+
SuccessCount: r.successRecords?.length ?? 0,
|
|
2158
|
+
FailureCount: failureCount,
|
|
2159
|
+
SuccessRecords: r.successRecords ?? [],
|
|
2160
|
+
FailureRecords: r.failureRecords ?? [],
|
|
2161
|
+
Reason: reason
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
if (failureCount > 0) {
|
|
2165
|
+
processContext.exit(1);
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
};
|
|
2169
|
+
var isRecordObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2170
|
+
async function resolveJsonInput(filePath, inlineBody) {
|
|
2171
|
+
const parsed = await readJsonInput(filePath, inlineBody, "Provide either --file <path> or --body <json> with record data.");
|
|
2172
|
+
if (!Array.isArray(parsed) && !isRecordObject(parsed) || Array.isArray(parsed) && parsed.some((item) => !isRecordObject(item))) {
|
|
2173
|
+
throw new Error("Input must be a JSON object or an array of JSON objects.");
|
|
2174
|
+
}
|
|
2175
|
+
return parsed;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// src/commands/roles.ts
|
|
2179
|
+
var ROLES_LIST_EXAMPLES = [
|
|
2180
|
+
{
|
|
2181
|
+
Description: "List Data Fabric access roles.",
|
|
2182
|
+
Command: "uip df roles list",
|
|
2183
|
+
Output: {
|
|
2184
|
+
Code: "RoleList",
|
|
2185
|
+
Data: [
|
|
2186
|
+
{
|
|
2187
|
+
Id: "c1d2e3f4-0000-0000-0000-000000000001",
|
|
2188
|
+
Name: "DataWriter",
|
|
2189
|
+
Type: "System",
|
|
2190
|
+
DirectoryEntityCount: 3
|
|
2191
|
+
}
|
|
2192
|
+
]
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
];
|
|
2196
|
+
var registerRolesCommand = (program) => {
|
|
2197
|
+
const roles = program.command("roles", { hidden: true }).description("Manage Data Fabric access roles");
|
|
2198
|
+
roles.command("list").description("List Data Fabric access roles").addOption(createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>")).option("--no-stats", "Skip role statistics (directory entity counts) in the response").option("--folder-key <key>", "Folder key (GUID) for folder-scoped role requests").examples(ROLES_LIST_EXAMPLES).trackedAction(processContext, async (options) => {
|
|
2199
|
+
const sdk = await connectOrFail(options.tenant);
|
|
2200
|
+
if (!sdk)
|
|
2201
|
+
return;
|
|
2202
|
+
const getAllOptions = {
|
|
2203
|
+
stats: options.stats,
|
|
2204
|
+
...options.folderKey !== undefined && {
|
|
2205
|
+
folderKey: options.folderKey
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
const [listError, result] = await catchError(sdk.entities.roles.getAll(getAllOptions));
|
|
2209
|
+
if (listError) {
|
|
2210
|
+
return fail("Error listing roles", await extractErrorMessage(listError));
|
|
2211
|
+
}
|
|
2212
|
+
OutputFormatter.success({
|
|
2213
|
+
Result: RESULTS.Success,
|
|
2214
|
+
Code: "RoleList",
|
|
2215
|
+
Data: result ?? []
|
|
2216
|
+
});
|
|
2217
|
+
});
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
// src/tool.ts
|
|
2221
|
+
var metadata = {
|
|
2222
|
+
name: "data-fabric-tool",
|
|
2223
|
+
version: package_default.version,
|
|
2224
|
+
description: "Manage Data Fabric entity schemas, records, and file attachments.",
|
|
2225
|
+
commandPrefix: "df"
|
|
2226
|
+
};
|
|
2227
|
+
var registerCommands = async (program) => {
|
|
2228
|
+
registerEntitiesCommand(program);
|
|
2229
|
+
registerRecordsCommand(program);
|
|
2230
|
+
registerFilesCommand(program);
|
|
2231
|
+
registerChoiceSetsCommand(program);
|
|
2232
|
+
registerChoiceSetValuesCommand(program);
|
|
2233
|
+
registerRolesCommand(program);
|
|
2234
|
+
registerDirectoryCommand(program);
|
|
2235
|
+
registerConnectorsCommand(program);
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
export { metadata, registerCommands };
|
|
2239
|
+
|
|
2240
|
+
//# debugId=B8B5C84A16365DEC64756E2164756E21
|