@uipath/data-fabric-tool 1.1.0 → 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/dist/tool.js +1638 -1164
- package/package.json +16 -24
- package/src/commands/choice-sets.spec.ts +538 -83
- package/src/commands/choice-sets.ts +550 -146
- package/src/commands/entities.spec.ts +58 -145
- package/src/commands/entities.ts +160 -367
- package/src/commands/files.spec.ts +18 -32
- package/src/commands/files.ts +33 -89
- package/src/commands/records.spec.ts +102 -207
- package/src/commands/records.ts +112 -328
- package/src/tool.ts +5 -1
- 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
- package/src/utils/pagination.ts +0 -10
|
@@ -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
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
import { getFileSystem } from "@uipath/filesystem";
|
|
11
11
|
import type { Command } from "commander";
|
|
12
12
|
import { readFileBinary } from "../utils/input";
|
|
13
|
-
import {
|
|
13
|
+
import { fail } from "../utils/output";
|
|
14
|
+
import { connectOrFail } from "../utils/sdk-client";
|
|
14
15
|
|
|
15
16
|
interface UploadOptions {
|
|
16
17
|
tenant?: string;
|
|
@@ -101,41 +102,21 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
101
102
|
options: UploadOptions,
|
|
102
103
|
) => {
|
|
103
104
|
if (!options.file) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
processContext.exit(1);
|
|
110
|
-
return;
|
|
105
|
+
return fail(
|
|
106
|
+
"A file path is required",
|
|
107
|
+
"Provide a file path via --file.",
|
|
108
|
+
);
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
if (clientError) {
|
|
118
|
-
OutputFormatter.error({
|
|
119
|
-
Result: RESULTS.Failure,
|
|
120
|
-
Message: "Error connecting to Data Fabric",
|
|
121
|
-
Instructions: await extractErrorMessage(clientError),
|
|
122
|
-
});
|
|
123
|
-
processContext.exit(1);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
111
|
+
const sdk = await connectOrFail(options.tenant);
|
|
112
|
+
if (!sdk) return;
|
|
126
113
|
|
|
127
114
|
const [readError, fileContent] = await catchError(
|
|
128
115
|
readFileBinary(options.file),
|
|
129
116
|
);
|
|
130
117
|
|
|
131
118
|
if (readError) {
|
|
132
|
-
|
|
133
|
-
Result: RESULTS.Failure,
|
|
134
|
-
Message: "Error reading file",
|
|
135
|
-
Instructions: readError.message,
|
|
136
|
-
});
|
|
137
|
-
processContext.exit(1);
|
|
138
|
-
return;
|
|
119
|
+
return fail("Error reading file", readError.message);
|
|
139
120
|
}
|
|
140
121
|
|
|
141
122
|
const fsInst = getFileSystem();
|
|
@@ -154,13 +135,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
154
135
|
);
|
|
155
136
|
|
|
156
137
|
if (uploadError) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
processContext.exit(1);
|
|
163
|
-
return;
|
|
138
|
+
return fail(
|
|
139
|
+
`Error uploading file to field '${fieldName}'`,
|
|
140
|
+
await extractErrorMessage(uploadError),
|
|
141
|
+
);
|
|
164
142
|
}
|
|
165
143
|
|
|
166
144
|
OutputFormatter.success({
|
|
@@ -198,19 +176,8 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
198
176
|
fieldName: string,
|
|
199
177
|
options: DownloadOptions,
|
|
200
178
|
) => {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
if (clientError) {
|
|
206
|
-
OutputFormatter.error({
|
|
207
|
-
Result: RESULTS.Failure,
|
|
208
|
-
Message: "Error connecting to Data Fabric",
|
|
209
|
-
Instructions: await extractErrorMessage(clientError),
|
|
210
|
-
});
|
|
211
|
-
processContext.exit(1);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
179
|
+
const sdk = await connectOrFail(options.tenant);
|
|
180
|
+
if (!sdk) return;
|
|
214
181
|
|
|
215
182
|
const [downloadError, blob] = await catchError(
|
|
216
183
|
sdk.entities.downloadAttachment(
|
|
@@ -221,13 +188,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
221
188
|
);
|
|
222
189
|
|
|
223
190
|
if (downloadError) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
});
|
|
229
|
-
processContext.exit(1);
|
|
230
|
-
return;
|
|
191
|
+
return fail(
|
|
192
|
+
`Error downloading file from field '${fieldName}'`,
|
|
193
|
+
await extractErrorMessage(downloadError),
|
|
194
|
+
);
|
|
231
195
|
}
|
|
232
196
|
|
|
233
197
|
const outputPath =
|
|
@@ -238,13 +202,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
238
202
|
);
|
|
239
203
|
|
|
240
204
|
if (bufferError) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
processContext.exit(1);
|
|
247
|
-
return;
|
|
205
|
+
return fail(
|
|
206
|
+
"Error reading downloaded file content",
|
|
207
|
+
bufferError.message,
|
|
208
|
+
);
|
|
248
209
|
}
|
|
249
210
|
|
|
250
211
|
const [writeError] = await catchError(
|
|
@@ -252,13 +213,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
252
213
|
);
|
|
253
214
|
|
|
254
215
|
if (writeError) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
});
|
|
260
|
-
processContext.exit(1);
|
|
261
|
-
return;
|
|
216
|
+
return fail(
|
|
217
|
+
"Error writing downloaded file",
|
|
218
|
+
writeError.message,
|
|
219
|
+
);
|
|
262
220
|
}
|
|
263
221
|
|
|
264
222
|
OutputFormatter.success({
|
|
@@ -292,19 +250,8 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
292
250
|
fieldName: string,
|
|
293
251
|
options: DeleteOptions,
|
|
294
252
|
) => {
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
if (clientError) {
|
|
300
|
-
OutputFormatter.error({
|
|
301
|
-
Result: RESULTS.Failure,
|
|
302
|
-
Message: "Error connecting to Data Fabric",
|
|
303
|
-
Instructions: await extractErrorMessage(clientError),
|
|
304
|
-
});
|
|
305
|
-
processContext.exit(1);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
253
|
+
const sdk = await connectOrFail(options.tenant);
|
|
254
|
+
if (!sdk) return;
|
|
308
255
|
|
|
309
256
|
const [deleteError] = await catchError(
|
|
310
257
|
sdk.entities.deleteAttachment(
|
|
@@ -315,13 +262,10 @@ export const registerFilesCommand = (program: Command) => {
|
|
|
315
262
|
);
|
|
316
263
|
|
|
317
264
|
if (deleteError) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
});
|
|
323
|
-
processContext.exit(1);
|
|
324
|
-
return;
|
|
265
|
+
return fail(
|
|
266
|
+
`Error deleting file from field '${fieldName}'`,
|
|
267
|
+
await extractErrorMessage(deleteError),
|
|
268
|
+
);
|
|
325
269
|
}
|
|
326
270
|
|
|
327
271
|
OutputFormatter.success({
|