@qrvey/object-storage 1.0.5-737 → 1.0.6-953
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/cjs/index.js +130 -191
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.mjs +130 -191
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/cjs/index.js
CHANGED
|
@@ -36,6 +36,7 @@ var __spreadValues = (a, b) => {
|
|
|
36
36
|
return a;
|
|
37
37
|
};
|
|
38
38
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
39
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
39
40
|
var __objRest = (source, exclude) => {
|
|
40
41
|
var target = {};
|
|
41
42
|
for (var prop in source)
|
|
@@ -48,6 +49,10 @@ var __objRest = (source, exclude) => {
|
|
|
48
49
|
}
|
|
49
50
|
return target;
|
|
50
51
|
};
|
|
52
|
+
var __publicField = (obj, key, value) => {
|
|
53
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
51
56
|
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
52
57
|
|
|
53
58
|
// src/shared/utils/errorHandler.ts
|
|
@@ -75,7 +80,7 @@ var errorMessages = {
|
|
|
75
80
|
ObjectNotFound: "ObjectNotFound - The specified key does not exist. (404)",
|
|
76
81
|
DEFAULT: "An unknown error occurred"
|
|
77
82
|
};
|
|
78
|
-
var
|
|
83
|
+
var _ErrorHandler = class _ErrorHandler {
|
|
79
84
|
static handleError(errorCode, errorMessage, errorObj) {
|
|
80
85
|
const errorResponse = {
|
|
81
86
|
code: errorCode,
|
|
@@ -90,6 +95,8 @@ var ErrorHandler = class {
|
|
|
90
95
|
return errorResponse;
|
|
91
96
|
}
|
|
92
97
|
};
|
|
98
|
+
__name(_ErrorHandler, "ErrorHandler");
|
|
99
|
+
var ErrorHandler = _ErrorHandler;
|
|
93
100
|
|
|
94
101
|
// src/services/storage/blob/blobHelpers.ts
|
|
95
102
|
function BlobPropertiesResponseToObjectResponse(blobProperties) {
|
|
@@ -105,11 +112,12 @@ function BlobPropertiesResponseToObjectResponse(blobProperties) {
|
|
|
105
112
|
contentLanguage: blobProperties.contentLanguage
|
|
106
113
|
};
|
|
107
114
|
}
|
|
115
|
+
__name(BlobPropertiesResponseToObjectResponse, "BlobPropertiesResponseToObjectResponse");
|
|
108
116
|
|
|
109
117
|
// src/services/storage/blob/blocIdStorage.ts
|
|
110
|
-
var
|
|
118
|
+
var _BlockIdStorage = class _BlockIdStorage {
|
|
111
119
|
constructor() {
|
|
112
|
-
this
|
|
120
|
+
__publicField(this, "blockIdMap", {});
|
|
113
121
|
}
|
|
114
122
|
static getInstance() {
|
|
115
123
|
if (!_BlockIdStorage.instance) {
|
|
@@ -130,9 +138,12 @@ var BlockIdStorage = class _BlockIdStorage {
|
|
|
130
138
|
delete this.blockIdMap[blobName];
|
|
131
139
|
}
|
|
132
140
|
};
|
|
141
|
+
__name(_BlockIdStorage, "BlockIdStorage");
|
|
142
|
+
__publicField(_BlockIdStorage, "instance");
|
|
143
|
+
var BlockIdStorage = _BlockIdStorage;
|
|
133
144
|
|
|
134
145
|
// src/services/storage/blob/blobStorage.service.ts
|
|
135
|
-
var
|
|
146
|
+
var _BlobStorageService = class _BlobStorageService {
|
|
136
147
|
/**
|
|
137
148
|
* Retrieves the properties of a blob from the container by its name.
|
|
138
149
|
*
|
|
@@ -140,17 +151,10 @@ var BlobStorageService = class {
|
|
|
140
151
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.
|
|
141
152
|
*/
|
|
142
153
|
constructor(containerName) {
|
|
154
|
+
__publicField(this, "blobServiceClient");
|
|
155
|
+
__publicField(this, "containerName");
|
|
143
156
|
this.containerName = containerName;
|
|
144
|
-
|
|
145
|
-
if (process.env.DATA_LAKE_BUCKET && process.env.DATA_LAKE_BUCKET === this.containerName) {
|
|
146
|
-
connectionString = process.env.AZURE_DATALAKE_CONNECTION_STRING;
|
|
147
|
-
}
|
|
148
|
-
if (!connectionString) {
|
|
149
|
-
connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
|
|
150
|
-
}
|
|
151
|
-
this.blobServiceClient = storageBlob.BlobServiceClient.fromConnectionString(
|
|
152
|
-
connectionString
|
|
153
|
-
);
|
|
157
|
+
this.blobServiceClient = storageBlob.BlobServiceClient.fromConnectionString(process.env.AZURE_STORAGE_CONNECTION_STRING);
|
|
154
158
|
}
|
|
155
159
|
/**
|
|
156
160
|
* Creates a writable stream for uploading a file to the Blob storage.
|
|
@@ -160,14 +164,15 @@ var BlobStorageService = class {
|
|
|
160
164
|
*/
|
|
161
165
|
createUploadWriteStream(blobName) {
|
|
162
166
|
const streamPassThrough = new stream__default.default.PassThrough();
|
|
163
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
164
|
-
this.containerName
|
|
165
|
-
);
|
|
167
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
166
168
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
167
169
|
const uploadPromise = blockBlobClient.uploadStream(streamPassThrough, void 0, void 0, {
|
|
168
170
|
onProgress: (ev) => console.log(ev)
|
|
169
171
|
}).then(() => {
|
|
170
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
Bucket: this.containerName,
|
|
174
|
+
Key: blobName
|
|
175
|
+
};
|
|
171
176
|
});
|
|
172
177
|
return {
|
|
173
178
|
key: blobName,
|
|
@@ -183,9 +188,7 @@ var BlobStorageService = class {
|
|
|
183
188
|
*/
|
|
184
189
|
async getHeadObject(blobName) {
|
|
185
190
|
try {
|
|
186
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
187
|
-
this.containerName
|
|
188
|
-
);
|
|
191
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
189
192
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
190
193
|
const blobProperties = await blockBlobClient.getProperties();
|
|
191
194
|
return BlobPropertiesResponseToObjectResponse(blobProperties);
|
|
@@ -204,18 +207,13 @@ var BlobStorageService = class {
|
|
|
204
207
|
var _a;
|
|
205
208
|
try {
|
|
206
209
|
let downloadBlockBlobResponse;
|
|
207
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
208
|
-
this.containerName
|
|
209
|
-
);
|
|
210
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
210
211
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
211
212
|
const expression = (options == null ? void 0 : options.range) || "";
|
|
212
213
|
const matches = expression.match(/\d+/g);
|
|
213
214
|
if (expression && (matches == null ? void 0 : matches.length)) {
|
|
214
215
|
const [start, end] = matches.map(Number);
|
|
215
|
-
downloadBlockBlobResponse = await blockBlobClient.download(
|
|
216
|
-
start,
|
|
217
|
-
end
|
|
218
|
-
);
|
|
216
|
+
downloadBlockBlobResponse = await blockBlobClient.download(start, end);
|
|
219
217
|
} else {
|
|
220
218
|
downloadBlockBlobResponse = await blockBlobClient.download(0);
|
|
221
219
|
}
|
|
@@ -235,9 +233,7 @@ var BlobStorageService = class {
|
|
|
235
233
|
}
|
|
236
234
|
async getSignatureUrl(blobName, expiresInMinutes, permissions) {
|
|
237
235
|
try {
|
|
238
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
239
|
-
this.containerName
|
|
240
|
-
);
|
|
236
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
241
237
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
242
238
|
const startDate = /* @__PURE__ */ new Date();
|
|
243
239
|
const expiryDate = new Date(startDate);
|
|
@@ -253,12 +249,11 @@ var BlobStorageService = class {
|
|
|
253
249
|
}
|
|
254
250
|
async getUploadUrl(blobName, expiresInMinutes) {
|
|
255
251
|
try {
|
|
256
|
-
const sasUrl = await this.getSignatureUrl(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return { key: blobName, signedUrl: sasUrl };
|
|
252
|
+
const sasUrl = await this.getSignatureUrl(blobName, expiresInMinutes, "w");
|
|
253
|
+
return {
|
|
254
|
+
key: blobName,
|
|
255
|
+
signedUrl: sasUrl
|
|
256
|
+
};
|
|
262
257
|
} catch (error) {
|
|
263
258
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
264
259
|
}
|
|
@@ -272,11 +267,7 @@ var BlobStorageService = class {
|
|
|
272
267
|
*/
|
|
273
268
|
async getDownloadUrl(blobName, expiresInMinutes) {
|
|
274
269
|
try {
|
|
275
|
-
const sasUrl = await this.getSignatureUrl(
|
|
276
|
-
blobName,
|
|
277
|
-
expiresInMinutes,
|
|
278
|
-
"r"
|
|
279
|
-
);
|
|
270
|
+
const sasUrl = await this.getSignatureUrl(blobName, expiresInMinutes, "r");
|
|
280
271
|
return sasUrl;
|
|
281
272
|
} catch (error) {
|
|
282
273
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
@@ -292,17 +283,16 @@ var BlobStorageService = class {
|
|
|
292
283
|
*/
|
|
293
284
|
async upload(blobName, body, metadata = {}) {
|
|
294
285
|
try {
|
|
295
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
296
|
-
this.containerName
|
|
297
|
-
);
|
|
286
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
298
287
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
299
|
-
Buffer.isBuffer(body) ? await blockBlobClient.upload(body, body.length, {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
288
|
+
Buffer.isBuffer(body) ? await blockBlobClient.upload(body, body.length, {
|
|
289
|
+
metadata
|
|
290
|
+
}) : await blockBlobClient.uploadStream(body, void 0, void 0, {
|
|
291
|
+
metadata
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
key: blobName
|
|
295
|
+
};
|
|
306
296
|
} catch (error) {
|
|
307
297
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
308
298
|
}
|
|
@@ -315,9 +305,7 @@ var BlobStorageService = class {
|
|
|
315
305
|
*/
|
|
316
306
|
async delete(data) {
|
|
317
307
|
try {
|
|
318
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
319
|
-
this.containerName
|
|
320
|
-
);
|
|
308
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
321
309
|
return this.deleteObject(containerClient, data);
|
|
322
310
|
} catch (error) {
|
|
323
311
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
@@ -359,16 +347,9 @@ var BlobStorageService = class {
|
|
|
359
347
|
let continuationToken = options.pagination;
|
|
360
348
|
const limit = (_a = options.limit) != null ? _a : 1e3;
|
|
361
349
|
let continueListing = true;
|
|
362
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
363
|
-
this.containerName
|
|
364
|
-
);
|
|
350
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
365
351
|
while (continueListing) {
|
|
366
|
-
const response = await this.listChunk(
|
|
367
|
-
options,
|
|
368
|
-
continuationToken,
|
|
369
|
-
limit - responseContents.length,
|
|
370
|
-
containerClient
|
|
371
|
-
);
|
|
352
|
+
const response = await this.listChunk(options, continuationToken, limit - responseContents.length, containerClient);
|
|
372
353
|
continuationToken = response.continuationToken;
|
|
373
354
|
responseContents = responseContents.concat(response.items);
|
|
374
355
|
if (responseContents.length >= limit || !continuationToken) {
|
|
@@ -417,10 +398,16 @@ var BlobStorageService = class {
|
|
|
417
398
|
pagination
|
|
418
399
|
}));
|
|
419
400
|
if ((_a = response.items) == null ? void 0 : _a.length)
|
|
420
|
-
allItems = [
|
|
401
|
+
allItems = [
|
|
402
|
+
...allItems,
|
|
403
|
+
...response.items
|
|
404
|
+
];
|
|
421
405
|
pagination = (_b = response.pagination) != null ? _b : void 0;
|
|
422
406
|
} while (pagination);
|
|
423
|
-
return {
|
|
407
|
+
return {
|
|
408
|
+
items: allItems,
|
|
409
|
+
count: allItems.length
|
|
410
|
+
};
|
|
424
411
|
}
|
|
425
412
|
/**
|
|
426
413
|
* Deletes a blob from the blob storage service.
|
|
@@ -444,14 +431,15 @@ var BlobStorageService = class {
|
|
|
444
431
|
* @return {Promise<{ key: string; deleted: boolean; error?: string }[]>} - A promise that resolves to an array of objects containing the key, deleted status, and an optional error message for each blob deleted.
|
|
445
432
|
*/
|
|
446
433
|
async deleteObjects(blobNames) {
|
|
447
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
448
|
-
this.containerName
|
|
449
|
-
);
|
|
434
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
450
435
|
const deleteBlobPromises = blobNames.map(async (blobName) => {
|
|
451
436
|
var _a;
|
|
452
437
|
try {
|
|
453
438
|
await this.deleteObject(containerClient, blobName);
|
|
454
|
-
return {
|
|
439
|
+
return {
|
|
440
|
+
key: blobName,
|
|
441
|
+
deleted: true
|
|
442
|
+
};
|
|
455
443
|
} catch (error) {
|
|
456
444
|
return {
|
|
457
445
|
key: blobName,
|
|
@@ -469,21 +457,15 @@ var BlobStorageService = class {
|
|
|
469
457
|
*/
|
|
470
458
|
async getHeadBucket() {
|
|
471
459
|
try {
|
|
472
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
473
|
-
this.containerName
|
|
474
|
-
);
|
|
460
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
475
461
|
const properties = await containerClient.getProperties();
|
|
476
462
|
return properties;
|
|
477
463
|
} catch (error) {
|
|
478
|
-
throw new Error(
|
|
479
|
-
"Error in Azure getHeadContainer. Container: " + this.containerName + " Error: " + error
|
|
480
|
-
);
|
|
464
|
+
throw new Error("Error in Azure getHeadContainer. Container: " + this.containerName + " Error: " + error);
|
|
481
465
|
}
|
|
482
466
|
}
|
|
483
467
|
async listMultipartUploadsForBucket() {
|
|
484
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
485
|
-
this.containerName
|
|
486
|
-
);
|
|
468
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
487
469
|
const blobList = containerClient.listBlobsFlat();
|
|
488
470
|
const uploads = [];
|
|
489
471
|
try {
|
|
@@ -518,15 +500,12 @@ var BlobStorageService = class {
|
|
|
518
500
|
*/
|
|
519
501
|
async listMultipartUploadsForKey(blobName) {
|
|
520
502
|
var _a;
|
|
521
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
522
|
-
this.containerName
|
|
523
|
-
);
|
|
503
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
524
504
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
525
505
|
const listResponse = await blobClient.getBlockList("all");
|
|
526
506
|
const parts = ((_a = listResponse == null ? void 0 : listResponse.uncommittedBlocks) == null ? void 0 : _a.map((block, index) => ({
|
|
527
507
|
PartNumber: index + 1,
|
|
528
508
|
LastModified: /* @__PURE__ */ new Date(),
|
|
529
|
-
// Azure Blob Storage doesn't provide the last modified date for individual parts
|
|
530
509
|
ETag: block.name,
|
|
531
510
|
Size: block.size
|
|
532
511
|
}))) || [];
|
|
@@ -555,9 +534,7 @@ var BlobStorageService = class {
|
|
|
555
534
|
* @return {Promise<string>} A Promise that resolves to a string representing the base64 encoded block ID of the uploaded part.
|
|
556
535
|
*/
|
|
557
536
|
async uploadMultipart(blobName, file, partNumber, uploadId) {
|
|
558
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
559
|
-
this.containerName
|
|
560
|
-
);
|
|
537
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
561
538
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
562
539
|
const blockIdBase = uploadId || await this.generateUploadIdMultipart();
|
|
563
540
|
const partId = partNumber.toString().padStart(6, "0");
|
|
@@ -575,9 +552,7 @@ var BlobStorageService = class {
|
|
|
575
552
|
*/
|
|
576
553
|
async completeMultipartUpload(blobName, uploadId) {
|
|
577
554
|
var _a;
|
|
578
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
579
|
-
this.containerName
|
|
580
|
-
);
|
|
555
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
581
556
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
582
557
|
const listMultipartUploads = await this.listMultipartUploadsForKey(blobName);
|
|
583
558
|
const blockIds = ((_a = listMultipartUploads == null ? void 0 : listMultipartUploads.Parts) == null ? void 0 : _a.map((part) => part.ETag)) || [];
|
|
@@ -594,9 +569,7 @@ var BlobStorageService = class {
|
|
|
594
569
|
* @return {Promise<void>} A promise that resolves when the multipart upload is successfully aborted.
|
|
595
570
|
*/
|
|
596
571
|
async abortMultipartUpload(blobName, uploadId) {
|
|
597
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
598
|
-
this.containerName
|
|
599
|
-
);
|
|
572
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
600
573
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
601
574
|
const blockIdStorage = BlockIdStorage.getInstance();
|
|
602
575
|
blockIdStorage.clearBlockIds(uploadId);
|
|
@@ -605,15 +578,13 @@ var BlobStorageService = class {
|
|
|
605
578
|
async getMultipartUploadPresignedUrl(blobName, uploadId, partNumber, expiresInMinutes = 2) {
|
|
606
579
|
const partId = partNumber.toString().padStart(6, "0");
|
|
607
580
|
const partIdBase64 = Buffer.from(partId).toString("base64");
|
|
608
|
-
const sasUrl = await this.getSignatureUrl(
|
|
609
|
-
blobName,
|
|
610
|
-
expiresInMinutes,
|
|
611
|
-
"w"
|
|
612
|
-
);
|
|
581
|
+
const sasUrl = await this.getSignatureUrl(blobName, expiresInMinutes, "w");
|
|
613
582
|
const url = `${sasUrl}&comp=block&blockid=${partIdBase64}`;
|
|
614
583
|
return url;
|
|
615
584
|
}
|
|
616
585
|
};
|
|
586
|
+
__name(_BlobStorageService, "BlobStorageService");
|
|
587
|
+
var BlobStorageService = _BlobStorageService;
|
|
617
588
|
|
|
618
589
|
// src/services/storage/s3/s3Helpers.ts
|
|
619
590
|
function listResponseContentsToListResponseItems(responseContents) {
|
|
@@ -626,6 +597,7 @@ function listResponseContentsToListResponseItems(responseContents) {
|
|
|
626
597
|
};
|
|
627
598
|
});
|
|
628
599
|
}
|
|
600
|
+
__name(listResponseContentsToListResponseItems, "listResponseContentsToListResponseItems");
|
|
629
601
|
function s3ObjectToObjectResponse(s3Object) {
|
|
630
602
|
return {
|
|
631
603
|
body: s3Object.Body,
|
|
@@ -640,21 +612,23 @@ function s3ObjectToObjectResponse(s3Object) {
|
|
|
640
612
|
lastModified: s3Object.LastModified
|
|
641
613
|
};
|
|
642
614
|
}
|
|
643
|
-
|
|
615
|
+
__name(s3ObjectToObjectResponse, "s3ObjectToObjectResponse");
|
|
616
|
+
var _S3StorageService = class _S3StorageService {
|
|
644
617
|
constructor(bucketName, options) {
|
|
645
|
-
this
|
|
618
|
+
__publicField(this, "httpHandler", new nodeHttpHandler.NodeHttpHandler({
|
|
646
619
|
socketTimeout: 6e5
|
|
647
|
-
});
|
|
648
|
-
this
|
|
620
|
+
}));
|
|
621
|
+
__publicField(this, "s3Client", new clientS3.S3Client({
|
|
649
622
|
region: process.env.AWS_DEFAULT_REGION,
|
|
650
623
|
requestHandler: this.httpHandler,
|
|
651
624
|
credentials: credentialProviderNode.defaultProvider()
|
|
652
|
-
});
|
|
653
|
-
this
|
|
625
|
+
}));
|
|
626
|
+
__publicField(this, "s3", new clientS3.S3({
|
|
654
627
|
region: process.env.AWS_DEFAULT_REGION,
|
|
655
628
|
requestHandler: this.httpHandler,
|
|
656
629
|
credentials: credentialProviderNode.defaultProvider()
|
|
657
|
-
});
|
|
630
|
+
}));
|
|
631
|
+
__publicField(this, "bucketName");
|
|
658
632
|
var _a, _b, _c, _d;
|
|
659
633
|
this.bucketName = bucketName;
|
|
660
634
|
if (((_a = options == null ? void 0 : options.credentials) == null ? void 0 : _a.accessKeyId) && ((_b = options == null ? void 0 : options.credentials) == null ? void 0 : _b.secretAccessKey)) {
|
|
@@ -699,11 +673,7 @@ var S3StorageService = class {
|
|
|
699
673
|
let continueListing = true;
|
|
700
674
|
while (continueListing) {
|
|
701
675
|
const listChunkLimit = limit - responseContents.length;
|
|
702
|
-
const response = await this.listChunk(
|
|
703
|
-
options,
|
|
704
|
-
continuationToken,
|
|
705
|
-
listChunkLimit
|
|
706
|
-
);
|
|
676
|
+
const response = await this.listChunk(options, continuationToken, listChunkLimit);
|
|
707
677
|
continuationToken = response.NextContinuationToken;
|
|
708
678
|
responseContents = responseContents.concat((_b = response.Contents) != null ? _b : []);
|
|
709
679
|
if (responseContents.length >= limit || !continuationToken) {
|
|
@@ -745,10 +715,16 @@ var S3StorageService = class {
|
|
|
745
715
|
pagination
|
|
746
716
|
}));
|
|
747
717
|
if ((_a = response.items) == null ? void 0 : _a.length)
|
|
748
|
-
allItems = [
|
|
718
|
+
allItems = [
|
|
719
|
+
...allItems,
|
|
720
|
+
...response.items
|
|
721
|
+
];
|
|
749
722
|
pagination = response.pagination === null ? void 0 : response.pagination;
|
|
750
723
|
} while (pagination);
|
|
751
|
-
return {
|
|
724
|
+
return {
|
|
725
|
+
items: allItems,
|
|
726
|
+
count: allItems.length
|
|
727
|
+
};
|
|
752
728
|
}
|
|
753
729
|
/**
|
|
754
730
|
* Retrieves an object from the S3 bucket.
|
|
@@ -788,7 +764,9 @@ var S3StorageService = class {
|
|
|
788
764
|
Bucket: this.bucketName,
|
|
789
765
|
Key: key
|
|
790
766
|
});
|
|
791
|
-
return s3RequestPresigner.getSignedUrl(this.s3Client, command, {
|
|
767
|
+
return s3RequestPresigner.getSignedUrl(this.s3Client, command, {
|
|
768
|
+
expiresIn
|
|
769
|
+
});
|
|
792
770
|
}
|
|
793
771
|
/**
|
|
794
772
|
* Retrieves a signed URL for uploading an object to the S3 bucket.
|
|
@@ -828,7 +806,9 @@ var S3StorageService = class {
|
|
|
828
806
|
Metadata: metadata
|
|
829
807
|
});
|
|
830
808
|
await this.s3Client.send(command);
|
|
831
|
-
return {
|
|
809
|
+
return {
|
|
810
|
+
key
|
|
811
|
+
};
|
|
832
812
|
}
|
|
833
813
|
/**
|
|
834
814
|
* Creates a writable stream for uploading a file to the S3 bucket.
|
|
@@ -875,9 +855,7 @@ var S3StorageService = class {
|
|
|
875
855
|
});
|
|
876
856
|
return this.s3Client.send(command);
|
|
877
857
|
} catch (error) {
|
|
878
|
-
throw new Error(
|
|
879
|
-
"Error in S3 getHeadContainer. bucketName: " + this.bucketName + " Error: " + error
|
|
880
|
-
);
|
|
858
|
+
throw new Error("Error in S3 getHeadContainer. bucketName: " + this.bucketName + " Error: " + error);
|
|
881
859
|
}
|
|
882
860
|
}
|
|
883
861
|
/**
|
|
@@ -954,10 +932,7 @@ var S3StorageService = class {
|
|
|
954
932
|
return upId;
|
|
955
933
|
}
|
|
956
934
|
async completeMultipartUpload(key, uploadId) {
|
|
957
|
-
const partsResponse = await this.listMultipartUploadsForKey(
|
|
958
|
-
key,
|
|
959
|
-
uploadId
|
|
960
|
-
);
|
|
935
|
+
const partsResponse = await this.listMultipartUploadsForKey(key, uploadId);
|
|
961
936
|
const partsList = (partsResponse == null ? void 0 : partsResponse.Parts) && partsResponse.Parts.map(
|
|
962
937
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
963
938
|
(_a) => {
|
|
@@ -991,14 +966,14 @@ var S3StorageService = class {
|
|
|
991
966
|
PartNumber: parseInt(partNumber, 10)
|
|
992
967
|
};
|
|
993
968
|
const expiresIn = expiresInMinutes * 60;
|
|
994
|
-
const presignedUrl = await s3RequestPresigner.getSignedUrl(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
{ expiresIn }
|
|
998
|
-
);
|
|
969
|
+
const presignedUrl = await s3RequestPresigner.getSignedUrl(this.s3Client, new clientS3.UploadPartCommand(uploadPartParams), {
|
|
970
|
+
expiresIn
|
|
971
|
+
});
|
|
999
972
|
return presignedUrl;
|
|
1000
973
|
}
|
|
1001
974
|
};
|
|
975
|
+
__name(_S3StorageService, "S3StorageService");
|
|
976
|
+
var S3StorageService = _S3StorageService;
|
|
1002
977
|
|
|
1003
978
|
// src/shared/utils/constants.ts
|
|
1004
979
|
var OBJECT_STORAGE_SERVICE_TYPES = {
|
|
@@ -1007,7 +982,7 @@ var OBJECT_STORAGE_SERVICE_TYPES = {
|
|
|
1007
982
|
};
|
|
1008
983
|
|
|
1009
984
|
// src/services/objectStorageFactory.service.ts
|
|
1010
|
-
var
|
|
985
|
+
var _ObjectStorageFactory = class _ObjectStorageFactory {
|
|
1011
986
|
static async instance(bucketName, options) {
|
|
1012
987
|
var _a, _b;
|
|
1013
988
|
const provider = ((_a = options == null ? void 0 : options.provider) == null ? void 0 : _a.toLowerCase()) || ((_b = process.env.OBJECT_STORAGE_SERVICE) == null ? void 0 : _b.toLowerCase());
|
|
@@ -1017,15 +992,15 @@ var ObjectStorageFactory = class {
|
|
|
1017
992
|
case OBJECT_STORAGE_SERVICE_TYPES.AZURE_BLOB_STORAGE:
|
|
1018
993
|
return new BlobStorageService(bucketName);
|
|
1019
994
|
default:
|
|
1020
|
-
throw new Error(
|
|
1021
|
-
`Unsupported object storage provider: ${provider}`
|
|
1022
|
-
);
|
|
995
|
+
throw new Error(`Unsupported object storage provider: ${provider}`);
|
|
1023
996
|
}
|
|
1024
997
|
}
|
|
1025
998
|
};
|
|
999
|
+
__name(_ObjectStorageFactory, "ObjectStorageFactory");
|
|
1000
|
+
var ObjectStorageFactory = _ObjectStorageFactory;
|
|
1026
1001
|
|
|
1027
1002
|
// src/services/objectStorage.service.ts
|
|
1028
|
-
var
|
|
1003
|
+
var _ObjectStorageService = class _ObjectStorageService {
|
|
1029
1004
|
constructor(bucketName, options) {
|
|
1030
1005
|
_ObjectStorageService.bucketName = bucketName;
|
|
1031
1006
|
if (options)
|
|
@@ -1044,9 +1019,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1044
1019
|
* @return {Promise<ListResponse>} A promise that resolves to the list of objects.
|
|
1045
1020
|
*/
|
|
1046
1021
|
static async list(options, bucketName) {
|
|
1047
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1048
|
-
bucketName
|
|
1049
|
-
).then((instance) => instance.list(options));
|
|
1022
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.list(options));
|
|
1050
1023
|
}
|
|
1051
1024
|
/**
|
|
1052
1025
|
* Retrieves a list of all objects from the object storage service.
|
|
@@ -1056,9 +1029,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1056
1029
|
* @return {Promise<ListResponse>} A promise that resolves to the list of all objects.
|
|
1057
1030
|
*/
|
|
1058
1031
|
static async listAll(options, bucketName) {
|
|
1059
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1060
|
-
bucketName
|
|
1061
|
-
).then((instance) => instance.listAll(options));
|
|
1032
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listAll(options));
|
|
1062
1033
|
}
|
|
1063
1034
|
/**
|
|
1064
1035
|
* Retrieves an object from the object storage service.
|
|
@@ -1068,9 +1039,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1068
1039
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.
|
|
1069
1040
|
*/
|
|
1070
1041
|
static async getObject(key, bucketName, options) {
|
|
1071
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1072
|
-
bucketName
|
|
1073
|
-
).then((instance) => instance.getObject(key, options));
|
|
1042
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getObject(key, options));
|
|
1074
1043
|
}
|
|
1075
1044
|
/**
|
|
1076
1045
|
* Retrieves an object info (without file content) from the object storage service.
|
|
@@ -1078,9 +1047,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1078
1047
|
* @returns A promise that resolves to the info of the file.
|
|
1079
1048
|
*/
|
|
1080
1049
|
static async getHeadObject(key, bucketName) {
|
|
1081
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1082
|
-
bucketName
|
|
1083
|
-
).then((instance) => instance.getHeadObject(key));
|
|
1050
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getHeadObject(key));
|
|
1084
1051
|
}
|
|
1085
1052
|
/**
|
|
1086
1053
|
* Retrieves a signed URL for the specified object in the object storage service.
|
|
@@ -1091,9 +1058,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1091
1058
|
* @return {Promise<string>} A promise that resolves to the generated signed URL.
|
|
1092
1059
|
*/
|
|
1093
1060
|
static async getDownloadUrl(key, expiresInMinutes, bucketName) {
|
|
1094
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1095
|
-
bucketName
|
|
1096
|
-
).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1061
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1097
1062
|
}
|
|
1098
1063
|
/**
|
|
1099
1064
|
* Retrieves an upload URL for the specified object in the object storage service.
|
|
@@ -1104,9 +1069,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1104
1069
|
* @return {Promise<string>} A promise that resolves to the generated upload URL.
|
|
1105
1070
|
*/
|
|
1106
1071
|
static async getUploadUrl(key, expiresInMinutes, bucketName) {
|
|
1107
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1108
|
-
bucketName
|
|
1109
|
-
).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1072
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1110
1073
|
}
|
|
1111
1074
|
/**
|
|
1112
1075
|
* Uploads a file to the object storage service.
|
|
@@ -1118,9 +1081,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1118
1081
|
* @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.
|
|
1119
1082
|
*/
|
|
1120
1083
|
static async upload(key, body, metadata, bucketName) {
|
|
1121
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1122
|
-
bucketName
|
|
1123
|
-
).then((instance) => instance.upload(key, body, metadata));
|
|
1084
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.upload(key, body, metadata));
|
|
1124
1085
|
}
|
|
1125
1086
|
/**
|
|
1126
1087
|
* Creates an upload write stream for the specified key in the object storage service.
|
|
@@ -1130,9 +1091,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1130
1091
|
* @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.
|
|
1131
1092
|
*/
|
|
1132
1093
|
static async createUploadWriteStream(key, bucketName) {
|
|
1133
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1134
|
-
bucketName
|
|
1135
|
-
).then((instance) => instance.createUploadWriteStream(key));
|
|
1094
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.createUploadWriteStream(key));
|
|
1136
1095
|
}
|
|
1137
1096
|
/**
|
|
1138
1097
|
* Deletes an object or multiple objects from the object storage service.
|
|
@@ -1142,15 +1101,16 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1142
1101
|
* @return {Promise<{ key: string; deleted: boolean; error?: string }[] | boolean>} A promise that resolves to an array of objects containing the key, deleted status, and an optional error message for each object deleted, or a boolean value indicating the success of the deletion.
|
|
1143
1102
|
*/
|
|
1144
1103
|
static async delete(key, bucketName) {
|
|
1145
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1146
|
-
bucketName
|
|
1147
|
-
).then(async (instance) => {
|
|
1104
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then(async (instance) => {
|
|
1148
1105
|
if (Array.isArray(key)) {
|
|
1149
1106
|
const deleteBlobPromises = key.map(async (blobName) => {
|
|
1150
1107
|
var _a;
|
|
1151
1108
|
try {
|
|
1152
1109
|
await instance.delete(blobName);
|
|
1153
|
-
return {
|
|
1110
|
+
return {
|
|
1111
|
+
key: blobName,
|
|
1112
|
+
deleted: true
|
|
1113
|
+
};
|
|
1154
1114
|
} catch (error) {
|
|
1155
1115
|
return {
|
|
1156
1116
|
key: blobName,
|
|
@@ -1172,9 +1132,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1172
1132
|
* @return {Promise<HeadBucketResponse>} A promise that resolves to the head bucket response.
|
|
1173
1133
|
*/
|
|
1174
1134
|
static async getHeadBucket(bucketName) {
|
|
1175
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1176
|
-
bucketName
|
|
1177
|
-
).then((instance) => instance.getHeadBucket());
|
|
1135
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getHeadBucket());
|
|
1178
1136
|
}
|
|
1179
1137
|
/**
|
|
1180
1138
|
* Generates a unique upload ID for a multipart upload.
|
|
@@ -1184,9 +1142,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1184
1142
|
* @return {Promise<string>} A promise that resolves to the generated upload ID.
|
|
1185
1143
|
*/
|
|
1186
1144
|
static async generateUploadIdMultipart(key, bucketName) {
|
|
1187
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1188
|
-
bucketName
|
|
1189
|
-
).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1145
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1190
1146
|
}
|
|
1191
1147
|
/**
|
|
1192
1148
|
* Retrieves a list of multipart uploads for a specified key in the object storage service.
|
|
@@ -1197,11 +1153,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1197
1153
|
* @return {Promise<ListPartsMultipartUploadResponse>} A promise that resolves to the list of multipart uploads for the specified key.
|
|
1198
1154
|
*/
|
|
1199
1155
|
static async listMultipartUploadsForKey(key, bucketName, uploadId) {
|
|
1200
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1201
|
-
bucketName
|
|
1202
|
-
).then(
|
|
1203
|
-
(instance) => instance.listMultipartUploadsForKey(key, uploadId)
|
|
1204
|
-
);
|
|
1156
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listMultipartUploadsForKey(key, uploadId));
|
|
1205
1157
|
}
|
|
1206
1158
|
/**
|
|
1207
1159
|
* Retrieves a list of all multipart uploads for a specified bucket in the object storage service.
|
|
@@ -1210,9 +1162,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1210
1162
|
* @return {Promise<ListMultipartUploadsResponse>} A promise that resolves to the list of multipart uploads for the specified bucket.
|
|
1211
1163
|
*/
|
|
1212
1164
|
static async listMultipartUploadsForBucket(bucketName) {
|
|
1213
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1214
|
-
bucketName
|
|
1215
|
-
).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1165
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1216
1166
|
}
|
|
1217
1167
|
/**
|
|
1218
1168
|
* Uploads a multipart file to the specified bucket in the object storage service.
|
|
@@ -1225,11 +1175,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1225
1175
|
* @return {Promise<string>} A Promise that resolves to the base64 encoded block ID of the uploaded part.
|
|
1226
1176
|
*/
|
|
1227
1177
|
static async uploadMultipart(key, file, partNumber, uploadId, bucketName) {
|
|
1228
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1229
|
-
bucketName
|
|
1230
|
-
).then(
|
|
1231
|
-
(instance) => instance.uploadMultipart(key, file, partNumber, uploadId)
|
|
1232
|
-
);
|
|
1178
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.uploadMultipart(key, file, partNumber, uploadId));
|
|
1233
1179
|
}
|
|
1234
1180
|
/**
|
|
1235
1181
|
* Completes a multipart upload for the specified object in the object storage service.
|
|
@@ -1240,9 +1186,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1240
1186
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is completed.
|
|
1241
1187
|
*/
|
|
1242
1188
|
static async completeMultipartUpload(key, uploadId, bucketName) {
|
|
1243
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1244
|
-
bucketName
|
|
1245
|
-
).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1189
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1246
1190
|
}
|
|
1247
1191
|
/**
|
|
1248
1192
|
* Aborts a multipart upload for the specified object in the object storage service.
|
|
@@ -1253,9 +1197,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1253
1197
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is aborted.
|
|
1254
1198
|
*/
|
|
1255
1199
|
static async abortMultipartUpload(key, uploadId, bucketName) {
|
|
1256
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1257
|
-
bucketName
|
|
1258
|
-
).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1200
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1259
1201
|
}
|
|
1260
1202
|
/**
|
|
1261
1203
|
* Retrieves a presigned URL for a specific part of a multipart upload.
|
|
@@ -1267,16 +1209,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1267
1209
|
* @return {Promise<string>} A Promise that resolves to the presigned URL for the specified part of the multipart upload.
|
|
1268
1210
|
*/
|
|
1269
1211
|
static async getMultipartUploadPresignedUrl(key, uploadId, partNumber, expiresInMinutes) {
|
|
1270
|
-
return _ObjectStorageService.getObjectStorageServiceInstance().then(
|
|
1271
|
-
(instance) => instance.getMultipartUploadPresignedUrl(
|
|
1272
|
-
key,
|
|
1273
|
-
uploadId,
|
|
1274
|
-
partNumber,
|
|
1275
|
-
expiresInMinutes
|
|
1276
|
-
)
|
|
1277
|
-
);
|
|
1212
|
+
return _ObjectStorageService.getObjectStorageServiceInstance().then((instance) => instance.getMultipartUploadPresignedUrl(key, uploadId, partNumber, expiresInMinutes));
|
|
1278
1213
|
}
|
|
1279
1214
|
};
|
|
1215
|
+
__name(_ObjectStorageService, "ObjectStorageService");
|
|
1216
|
+
__publicField(_ObjectStorageService, "bucketName");
|
|
1217
|
+
__publicField(_ObjectStorageService, "objectStorageOptions");
|
|
1218
|
+
var ObjectStorageService = _ObjectStorageService;
|
|
1280
1219
|
|
|
1281
1220
|
exports.ObjectStorageService = ObjectStorageService;
|
|
1282
1221
|
//# sourceMappingURL=out.js.map
|