@uipath/data-fabric-tool 1.0.4 → 1.195.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.json +3 -0
- package/dist/index.js +20 -43167
- package/dist/tool.js +29174 -28399
- package/package.json +16 -32
- package/src/commands/choice-sets.spec.ts +849 -0
- package/src/commands/choice-sets.ts +690 -0
- package/src/commands/entities.spec.ts +411 -137
- package/src/commands/entities.ts +189 -368
- package/src/commands/files.spec.ts +18 -32
- package/src/commands/files.ts +43 -92
- package/src/commands/records.spec.ts +171 -207
- package/src/commands/records.ts +150 -342
- package/src/index.ts +5 -10
- package/src/tool.ts +6 -0
- package/src/utils/output.spec.ts +78 -0
- package/src/utils/output.ts +51 -0
- package/src/utils/sdk-client.spec.ts +59 -0
- package/src/utils/sdk-client.ts +23 -0
|
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
3
3
|
|
|
4
4
|
vi.mock("../utils/sdk-client", () => ({
|
|
5
5
|
createDataFabricClient: vi.fn(),
|
|
6
|
+
connectOrFail: vi.fn(),
|
|
6
7
|
}));
|
|
7
8
|
|
|
8
9
|
vi.mock("@uipath/common", async (importOriginal) => {
|
|
@@ -27,7 +28,7 @@ vi.mock("@uipath/filesystem", () => ({
|
|
|
27
28
|
}));
|
|
28
29
|
|
|
29
30
|
import { OutputFormatter } from "@uipath/common";
|
|
30
|
-
import {
|
|
31
|
+
import { connectOrFail } from "../utils/sdk-client";
|
|
31
32
|
import { registerFilesCommand } from "./files";
|
|
32
33
|
|
|
33
34
|
function mockSdk(overrides: Record<string, unknown> = {}) {
|
|
@@ -39,7 +40,7 @@ function mockSdk(overrides: Record<string, unknown> = {}) {
|
|
|
39
40
|
...overrides,
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
|
-
vi.mocked(
|
|
43
|
+
vi.mocked(connectOrFail).mockResolvedValue(sdk as never);
|
|
43
44
|
return sdk;
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -134,22 +135,17 @@ describe("files upload", () => {
|
|
|
134
135
|
);
|
|
135
136
|
});
|
|
136
137
|
|
|
137
|
-
it("should
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
138
|
+
it("should bail when SDK connection fails on upload", async () => {
|
|
139
|
+
const sdk = mockSdk();
|
|
140
|
+
vi.mocked(connectOrFail).mockResolvedValue(undefined);
|
|
141
141
|
mockFs.readFile.mockResolvedValue(new Uint8Array([1, 2, 3]));
|
|
142
142
|
const program = buildProgram();
|
|
143
143
|
await runCommand(
|
|
144
144
|
program,
|
|
145
145
|
"files upload entity-1 record-1 attachment --file /tmp/report.pdf",
|
|
146
146
|
);
|
|
147
|
-
expect(
|
|
148
|
-
|
|
149
|
-
Result: "Failure",
|
|
150
|
-
Message: "Error connecting to Data Fabric",
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
147
|
+
expect(sdk.entities.uploadAttachment).not.toHaveBeenCalled();
|
|
148
|
+
expect(OutputFormatter.success).not.toHaveBeenCalled();
|
|
153
149
|
});
|
|
154
150
|
|
|
155
151
|
it("should error when upload API fails", async () => {
|
|
@@ -218,21 +214,16 @@ describe("files download", () => {
|
|
|
218
214
|
);
|
|
219
215
|
});
|
|
220
216
|
|
|
221
|
-
it("should
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
);
|
|
217
|
+
it("should bail when SDK connection fails", async () => {
|
|
218
|
+
const sdk = mockSdk();
|
|
219
|
+
vi.mocked(connectOrFail).mockResolvedValue(undefined);
|
|
225
220
|
const program = buildProgram();
|
|
226
221
|
await runCommand(
|
|
227
222
|
program,
|
|
228
223
|
"files download entity-1 record-1 attachment",
|
|
229
224
|
);
|
|
230
|
-
expect(
|
|
231
|
-
|
|
232
|
-
Result: "Failure",
|
|
233
|
-
Message: "Error connecting to Data Fabric",
|
|
234
|
-
}),
|
|
235
|
-
);
|
|
225
|
+
expect(sdk.entities.downloadAttachment).not.toHaveBeenCalled();
|
|
226
|
+
expect(OutputFormatter.success).not.toHaveBeenCalled();
|
|
236
227
|
});
|
|
237
228
|
});
|
|
238
229
|
|
|
@@ -270,18 +261,13 @@ describe("files delete", () => {
|
|
|
270
261
|
);
|
|
271
262
|
});
|
|
272
263
|
|
|
273
|
-
it("should
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
);
|
|
264
|
+
it("should bail when SDK connection fails on delete", async () => {
|
|
265
|
+
const sdk = mockSdk();
|
|
266
|
+
vi.mocked(connectOrFail).mockResolvedValue(undefined);
|
|
277
267
|
const program = buildProgram();
|
|
278
268
|
await runCommand(program, "files delete entity-1 record-1 attachment");
|
|
279
|
-
expect(
|
|
280
|
-
|
|
281
|
-
Result: "Failure",
|
|
282
|
-
Message: "Error connecting to Data Fabric",
|
|
283
|
-
}),
|
|
284
|
-
);
|
|
269
|
+
expect(sdk.entities.deleteAttachment).not.toHaveBeenCalled();
|
|
270
|
+
expect(OutputFormatter.success).not.toHaveBeenCalled();
|
|
285
271
|
});
|
|
286
272
|
});
|
|
287
273
|
|
package/src/commands/files.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type CommandExample,
|
|
3
3
|
catchError,
|
|
4
|
+
createHiddenDeprecatedTenantOption,
|
|
4
5
|
extractErrorMessage,
|
|
5
6
|
OutputFormatter,
|
|
6
7
|
processContext,
|
|
@@ -9,7 +10,8 @@ import {
|
|
|
9
10
|
import { getFileSystem } from "@uipath/filesystem";
|
|
10
11
|
import type { Command } from "commander";
|
|
11
12
|
import { readFileBinary } from "../utils/input";
|
|
12
|
-
import {
|
|
13
|
+
import { fail } from "../utils/output";
|
|
14
|
+
import { connectOrFail } from "../utils/sdk-client";
|
|
13
15
|
|
|
14
16
|
interface UploadOptions {
|
|
15
17
|
tenant?: string;
|
|
@@ -86,7 +88,9 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
86
88
|
.argument("<entity-id>", "Entity ID")
|
|
87
89
|
.argument("<record-id>", "Record ID")
|
|
88
90
|
.argument("<field-name>", "Name of the file field (case-sensitive)")
|
|
89
|
-
.
|
|
91
|
+
.addOption(
|
|
92
|
+
createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>"),
|
|
93
|
+
)
|
|
90
94
|
.option("-f, --file <path>", "Path to the file to upload")
|
|
91
95
|
.examples(FILES_UPLOAD_EXAMPLES)
|
|
92
96
|
.trackedAction(
|
|
@@ -98,41 +102,21 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
98
102
|
options: UploadOptions,
|
|
99
103
|
) => {
|
|
100
104
|
if (!options.file) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
processContext.exit(1);
|
|
107
|
-
return;
|
|
105
|
+
return fail(
|
|
106
|
+
"A file path is required",
|
|
107
|
+
"Provide a file path via --file.",
|
|
108
|
+
);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (clientError) {
|
|
115
|
-
OutputFormatter.error({
|
|
116
|
-
Result: RESULTS.Failure,
|
|
117
|
-
Message: "Error connecting to Data Fabric",
|
|
118
|
-
Instructions: await extractErrorMessage(clientError),
|
|
119
|
-
});
|
|
120
|
-
processContext.exit(1);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
111
|
+
const sdk = await connectOrFail(options.tenant);
|
|
112
|
+
if (!sdk) return;
|
|
123
113
|
|
|
124
114
|
const [readError, fileContent] = await catchError(
|
|
125
115
|
readFileBinary(options.file),
|
|
126
116
|
);
|
|
127
117
|
|
|
128
118
|
if (readError) {
|
|
129
|
-
|
|
130
|
-
Result: RESULTS.Failure,
|
|
131
|
-
Message: "Error reading file",
|
|
132
|
-
Instructions: readError.message,
|
|
133
|
-
});
|
|
134
|
-
processContext.exit(1);
|
|
135
|
-
return;
|
|
119
|
+
return fail("Error reading file", readError.message);
|
|
136
120
|
}
|
|
137
121
|
|
|
138
122
|
const fsInst = getFileSystem();
|
|
@@ -151,13 +135,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
151
135
|
);
|
|
152
136
|
|
|
153
137
|
if (uploadError) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
processContext.exit(1);
|
|
160
|
-
return;
|
|
138
|
+
return fail(
|
|
139
|
+
`Error uploading file to field '${fieldName}'`,
|
|
140
|
+
await extractErrorMessage(uploadError),
|
|
141
|
+
);
|
|
161
142
|
}
|
|
162
143
|
|
|
163
144
|
OutputFormatter.success({
|
|
@@ -179,7 +160,9 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
179
160
|
.argument("<entity-id>", "Entity ID")
|
|
180
161
|
.argument("<record-id>", "Record ID")
|
|
181
162
|
.argument("<field-name>", "Name of the file field (case-sensitive)")
|
|
182
|
-
.
|
|
163
|
+
.addOption(
|
|
164
|
+
createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>"),
|
|
165
|
+
)
|
|
183
166
|
.option(
|
|
184
167
|
"--destination <path>",
|
|
185
168
|
"Output file path (defaults to <record-id>_<field-name>.bin)",
|
|
@@ -193,19 +176,8 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
193
176
|
fieldName: string,
|
|
194
177
|
options: DownloadOptions,
|
|
195
178
|
) => {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
if (clientError) {
|
|
201
|
-
OutputFormatter.error({
|
|
202
|
-
Result: RESULTS.Failure,
|
|
203
|
-
Message: "Error connecting to Data Fabric",
|
|
204
|
-
Instructions: await extractErrorMessage(clientError),
|
|
205
|
-
});
|
|
206
|
-
processContext.exit(1);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
179
|
+
const sdk = await connectOrFail(options.tenant);
|
|
180
|
+
if (!sdk) return;
|
|
209
181
|
|
|
210
182
|
const [downloadError, blob] = await catchError(
|
|
211
183
|
sdk.entities.downloadAttachment(
|
|
@@ -216,13 +188,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
216
188
|
);
|
|
217
189
|
|
|
218
190
|
if (downloadError) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
});
|
|
224
|
-
processContext.exit(1);
|
|
225
|
-
return;
|
|
191
|
+
return fail(
|
|
192
|
+
`Error downloading file from field '${fieldName}'`,
|
|
193
|
+
await extractErrorMessage(downloadError),
|
|
194
|
+
);
|
|
226
195
|
}
|
|
227
196
|
|
|
228
197
|
const outputPath =
|
|
@@ -233,13 +202,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
233
202
|
);
|
|
234
203
|
|
|
235
204
|
if (bufferError) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
});
|
|
241
|
-
processContext.exit(1);
|
|
242
|
-
return;
|
|
205
|
+
return fail(
|
|
206
|
+
"Error reading downloaded file content",
|
|
207
|
+
bufferError.message,
|
|
208
|
+
);
|
|
243
209
|
}
|
|
244
210
|
|
|
245
211
|
const [writeError] = await catchError(
|
|
@@ -247,13 +213,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
247
213
|
);
|
|
248
214
|
|
|
249
215
|
if (writeError) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
255
|
-
processContext.exit(1);
|
|
256
|
-
return;
|
|
216
|
+
return fail(
|
|
217
|
+
"Error writing downloaded file",
|
|
218
|
+
writeError.message,
|
|
219
|
+
);
|
|
257
220
|
}
|
|
258
221
|
|
|
259
222
|
OutputFormatter.success({
|
|
@@ -275,7 +238,9 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
275
238
|
.argument("<entity-id>", "Entity ID")
|
|
276
239
|
.argument("<record-id>", "Record ID")
|
|
277
240
|
.argument("<field-name>", "Name of the file field (case-sensitive)")
|
|
278
|
-
.
|
|
241
|
+
.addOption(
|
|
242
|
+
createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>"),
|
|
243
|
+
)
|
|
279
244
|
.examples(FILES_DELETE_EXAMPLES)
|
|
280
245
|
.trackedAction(
|
|
281
246
|
processContext,
|
|
@@ -285,19 +250,8 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
285
250
|
fieldName: string,
|
|
286
251
|
options: DeleteOptions,
|
|
287
252
|
) => {
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
if (clientError) {
|
|
293
|
-
OutputFormatter.error({
|
|
294
|
-
Result: RESULTS.Failure,
|
|
295
|
-
Message: "Error connecting to Data Fabric",
|
|
296
|
-
Instructions: await extractErrorMessage(clientError),
|
|
297
|
-
});
|
|
298
|
-
processContext.exit(1);
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
253
|
+
const sdk = await connectOrFail(options.tenant);
|
|
254
|
+
if (!sdk) return;
|
|
301
255
|
|
|
302
256
|
const [deleteError] = await catchError(
|
|
303
257
|
sdk.entities.deleteAttachment(
|
|
@@ -308,13 +262,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
308
262
|
);
|
|
309
263
|
|
|
310
264
|
if (deleteError) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
});
|
|
316
|
-
processContext.exit(1);
|
|
317
|
-
return;
|
|
265
|
+
return fail(
|
|
266
|
+
`Error deleting file from field '${fieldName}'`,
|
|
267
|
+
await extractErrorMessage(deleteError),
|
|
268
|
+
);
|
|
318
269
|
}
|
|
319
270
|
|
|
320
271
|
OutputFormatter.success({
|