@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/esm/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ var __spreadValues = (a, b) => {
|
|
|
30
30
|
return a;
|
|
31
31
|
};
|
|
32
32
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
33
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
33
34
|
var __objRest = (source, exclude) => {
|
|
34
35
|
var target = {};
|
|
35
36
|
for (var prop in source)
|
|
@@ -42,6 +43,10 @@ var __objRest = (source, exclude) => {
|
|
|
42
43
|
}
|
|
43
44
|
return target;
|
|
44
45
|
};
|
|
46
|
+
var __publicField = (obj, key, value) => {
|
|
47
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
45
50
|
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);
|
|
46
51
|
|
|
47
52
|
// src/shared/utils/errorHandler.ts
|
|
@@ -69,7 +74,7 @@ var errorMessages = {
|
|
|
69
74
|
ObjectNotFound: "ObjectNotFound - The specified key does not exist. (404)",
|
|
70
75
|
DEFAULT: "An unknown error occurred"
|
|
71
76
|
};
|
|
72
|
-
var
|
|
77
|
+
var _ErrorHandler = class _ErrorHandler {
|
|
73
78
|
static handleError(errorCode, errorMessage, errorObj) {
|
|
74
79
|
const errorResponse = {
|
|
75
80
|
code: errorCode,
|
|
@@ -84,6 +89,8 @@ var ErrorHandler = class {
|
|
|
84
89
|
return errorResponse;
|
|
85
90
|
}
|
|
86
91
|
};
|
|
92
|
+
__name(_ErrorHandler, "ErrorHandler");
|
|
93
|
+
var ErrorHandler = _ErrorHandler;
|
|
87
94
|
|
|
88
95
|
// src/services/storage/blob/blobHelpers.ts
|
|
89
96
|
function BlobPropertiesResponseToObjectResponse(blobProperties) {
|
|
@@ -99,11 +106,12 @@ function BlobPropertiesResponseToObjectResponse(blobProperties) {
|
|
|
99
106
|
contentLanguage: blobProperties.contentLanguage
|
|
100
107
|
};
|
|
101
108
|
}
|
|
109
|
+
__name(BlobPropertiesResponseToObjectResponse, "BlobPropertiesResponseToObjectResponse");
|
|
102
110
|
|
|
103
111
|
// src/services/storage/blob/blocIdStorage.ts
|
|
104
|
-
var
|
|
112
|
+
var _BlockIdStorage = class _BlockIdStorage {
|
|
105
113
|
constructor() {
|
|
106
|
-
this
|
|
114
|
+
__publicField(this, "blockIdMap", {});
|
|
107
115
|
}
|
|
108
116
|
static getInstance() {
|
|
109
117
|
if (!_BlockIdStorage.instance) {
|
|
@@ -124,9 +132,12 @@ var BlockIdStorage = class _BlockIdStorage {
|
|
|
124
132
|
delete this.blockIdMap[blobName];
|
|
125
133
|
}
|
|
126
134
|
};
|
|
135
|
+
__name(_BlockIdStorage, "BlockIdStorage");
|
|
136
|
+
__publicField(_BlockIdStorage, "instance");
|
|
137
|
+
var BlockIdStorage = _BlockIdStorage;
|
|
127
138
|
|
|
128
139
|
// src/services/storage/blob/blobStorage.service.ts
|
|
129
|
-
var
|
|
140
|
+
var _BlobStorageService = class _BlobStorageService {
|
|
130
141
|
/**
|
|
131
142
|
* Retrieves the properties of a blob from the container by its name.
|
|
132
143
|
*
|
|
@@ -134,17 +145,10 @@ var BlobStorageService = class {
|
|
|
134
145
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.
|
|
135
146
|
*/
|
|
136
147
|
constructor(containerName) {
|
|
148
|
+
__publicField(this, "blobServiceClient");
|
|
149
|
+
__publicField(this, "containerName");
|
|
137
150
|
this.containerName = containerName;
|
|
138
|
-
|
|
139
|
-
if (process.env.DATA_LAKE_BUCKET && process.env.DATA_LAKE_BUCKET === this.containerName) {
|
|
140
|
-
connectionString = process.env.AZURE_DATALAKE_CONNECTION_STRING;
|
|
141
|
-
}
|
|
142
|
-
if (!connectionString) {
|
|
143
|
-
connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
|
|
144
|
-
}
|
|
145
|
-
this.blobServiceClient = BlobServiceClient.fromConnectionString(
|
|
146
|
-
connectionString
|
|
147
|
-
);
|
|
151
|
+
this.blobServiceClient = BlobServiceClient.fromConnectionString(process.env.AZURE_STORAGE_CONNECTION_STRING);
|
|
148
152
|
}
|
|
149
153
|
/**
|
|
150
154
|
* Creates a writable stream for uploading a file to the Blob storage.
|
|
@@ -154,14 +158,15 @@ var BlobStorageService = class {
|
|
|
154
158
|
*/
|
|
155
159
|
createUploadWriteStream(blobName) {
|
|
156
160
|
const streamPassThrough = new stream.PassThrough();
|
|
157
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
158
|
-
this.containerName
|
|
159
|
-
);
|
|
161
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
160
162
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
161
163
|
const uploadPromise = blockBlobClient.uploadStream(streamPassThrough, void 0, void 0, {
|
|
162
164
|
onProgress: (ev) => console.log(ev)
|
|
163
165
|
}).then(() => {
|
|
164
|
-
return {
|
|
166
|
+
return {
|
|
167
|
+
Bucket: this.containerName,
|
|
168
|
+
Key: blobName
|
|
169
|
+
};
|
|
165
170
|
});
|
|
166
171
|
return {
|
|
167
172
|
key: blobName,
|
|
@@ -177,9 +182,7 @@ var BlobStorageService = class {
|
|
|
177
182
|
*/
|
|
178
183
|
async getHeadObject(blobName) {
|
|
179
184
|
try {
|
|
180
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
181
|
-
this.containerName
|
|
182
|
-
);
|
|
185
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
183
186
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
184
187
|
const blobProperties = await blockBlobClient.getProperties();
|
|
185
188
|
return BlobPropertiesResponseToObjectResponse(blobProperties);
|
|
@@ -198,18 +201,13 @@ var BlobStorageService = class {
|
|
|
198
201
|
var _a;
|
|
199
202
|
try {
|
|
200
203
|
let downloadBlockBlobResponse;
|
|
201
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
202
|
-
this.containerName
|
|
203
|
-
);
|
|
204
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
204
205
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
205
206
|
const expression = (options == null ? void 0 : options.range) || "";
|
|
206
207
|
const matches = expression.match(/\d+/g);
|
|
207
208
|
if (expression && (matches == null ? void 0 : matches.length)) {
|
|
208
209
|
const [start, end] = matches.map(Number);
|
|
209
|
-
downloadBlockBlobResponse = await blockBlobClient.download(
|
|
210
|
-
start,
|
|
211
|
-
end
|
|
212
|
-
);
|
|
210
|
+
downloadBlockBlobResponse = await blockBlobClient.download(start, end);
|
|
213
211
|
} else {
|
|
214
212
|
downloadBlockBlobResponse = await blockBlobClient.download(0);
|
|
215
213
|
}
|
|
@@ -229,9 +227,7 @@ var BlobStorageService = class {
|
|
|
229
227
|
}
|
|
230
228
|
async getSignatureUrl(blobName, expiresInMinutes, permissions) {
|
|
231
229
|
try {
|
|
232
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
233
|
-
this.containerName
|
|
234
|
-
);
|
|
230
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
235
231
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
236
232
|
const startDate = /* @__PURE__ */ new Date();
|
|
237
233
|
const expiryDate = new Date(startDate);
|
|
@@ -247,12 +243,11 @@ var BlobStorageService = class {
|
|
|
247
243
|
}
|
|
248
244
|
async getUploadUrl(blobName, expiresInMinutes) {
|
|
249
245
|
try {
|
|
250
|
-
const sasUrl = await this.getSignatureUrl(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return { key: blobName, signedUrl: sasUrl };
|
|
246
|
+
const sasUrl = await this.getSignatureUrl(blobName, expiresInMinutes, "w");
|
|
247
|
+
return {
|
|
248
|
+
key: blobName,
|
|
249
|
+
signedUrl: sasUrl
|
|
250
|
+
};
|
|
256
251
|
} catch (error) {
|
|
257
252
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
258
253
|
}
|
|
@@ -266,11 +261,7 @@ var BlobStorageService = class {
|
|
|
266
261
|
*/
|
|
267
262
|
async getDownloadUrl(blobName, expiresInMinutes) {
|
|
268
263
|
try {
|
|
269
|
-
const sasUrl = await this.getSignatureUrl(
|
|
270
|
-
blobName,
|
|
271
|
-
expiresInMinutes,
|
|
272
|
-
"r"
|
|
273
|
-
);
|
|
264
|
+
const sasUrl = await this.getSignatureUrl(blobName, expiresInMinutes, "r");
|
|
274
265
|
return sasUrl;
|
|
275
266
|
} catch (error) {
|
|
276
267
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
@@ -286,17 +277,16 @@ var BlobStorageService = class {
|
|
|
286
277
|
*/
|
|
287
278
|
async upload(blobName, body, metadata = {}) {
|
|
288
279
|
try {
|
|
289
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
290
|
-
this.containerName
|
|
291
|
-
);
|
|
280
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
292
281
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
|
293
|
-
Buffer.isBuffer(body) ? await blockBlobClient.upload(body, body.length, {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
282
|
+
Buffer.isBuffer(body) ? await blockBlobClient.upload(body, body.length, {
|
|
283
|
+
metadata
|
|
284
|
+
}) : await blockBlobClient.uploadStream(body, void 0, void 0, {
|
|
285
|
+
metadata
|
|
286
|
+
});
|
|
287
|
+
return {
|
|
288
|
+
key: blobName
|
|
289
|
+
};
|
|
300
290
|
} catch (error) {
|
|
301
291
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
302
292
|
}
|
|
@@ -309,9 +299,7 @@ var BlobStorageService = class {
|
|
|
309
299
|
*/
|
|
310
300
|
async delete(data) {
|
|
311
301
|
try {
|
|
312
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
313
|
-
this.containerName
|
|
314
|
-
);
|
|
302
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
315
303
|
return this.deleteObject(containerClient, data);
|
|
316
304
|
} catch (error) {
|
|
317
305
|
throw ErrorHandler.handleError("DEFAULT", "", error);
|
|
@@ -353,16 +341,9 @@ var BlobStorageService = class {
|
|
|
353
341
|
let continuationToken = options.pagination;
|
|
354
342
|
const limit = (_a = options.limit) != null ? _a : 1e3;
|
|
355
343
|
let continueListing = true;
|
|
356
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
357
|
-
this.containerName
|
|
358
|
-
);
|
|
344
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
359
345
|
while (continueListing) {
|
|
360
|
-
const response = await this.listChunk(
|
|
361
|
-
options,
|
|
362
|
-
continuationToken,
|
|
363
|
-
limit - responseContents.length,
|
|
364
|
-
containerClient
|
|
365
|
-
);
|
|
346
|
+
const response = await this.listChunk(options, continuationToken, limit - responseContents.length, containerClient);
|
|
366
347
|
continuationToken = response.continuationToken;
|
|
367
348
|
responseContents = responseContents.concat(response.items);
|
|
368
349
|
if (responseContents.length >= limit || !continuationToken) {
|
|
@@ -411,10 +392,16 @@ var BlobStorageService = class {
|
|
|
411
392
|
pagination
|
|
412
393
|
}));
|
|
413
394
|
if ((_a = response.items) == null ? void 0 : _a.length)
|
|
414
|
-
allItems = [
|
|
395
|
+
allItems = [
|
|
396
|
+
...allItems,
|
|
397
|
+
...response.items
|
|
398
|
+
];
|
|
415
399
|
pagination = (_b = response.pagination) != null ? _b : void 0;
|
|
416
400
|
} while (pagination);
|
|
417
|
-
return {
|
|
401
|
+
return {
|
|
402
|
+
items: allItems,
|
|
403
|
+
count: allItems.length
|
|
404
|
+
};
|
|
418
405
|
}
|
|
419
406
|
/**
|
|
420
407
|
* Deletes a blob from the blob storage service.
|
|
@@ -438,14 +425,15 @@ var BlobStorageService = class {
|
|
|
438
425
|
* @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.
|
|
439
426
|
*/
|
|
440
427
|
async deleteObjects(blobNames) {
|
|
441
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
442
|
-
this.containerName
|
|
443
|
-
);
|
|
428
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
444
429
|
const deleteBlobPromises = blobNames.map(async (blobName) => {
|
|
445
430
|
var _a;
|
|
446
431
|
try {
|
|
447
432
|
await this.deleteObject(containerClient, blobName);
|
|
448
|
-
return {
|
|
433
|
+
return {
|
|
434
|
+
key: blobName,
|
|
435
|
+
deleted: true
|
|
436
|
+
};
|
|
449
437
|
} catch (error) {
|
|
450
438
|
return {
|
|
451
439
|
key: blobName,
|
|
@@ -463,21 +451,15 @@ var BlobStorageService = class {
|
|
|
463
451
|
*/
|
|
464
452
|
async getHeadBucket() {
|
|
465
453
|
try {
|
|
466
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
467
|
-
this.containerName
|
|
468
|
-
);
|
|
454
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
469
455
|
const properties = await containerClient.getProperties();
|
|
470
456
|
return properties;
|
|
471
457
|
} catch (error) {
|
|
472
|
-
throw new Error(
|
|
473
|
-
"Error in Azure getHeadContainer. Container: " + this.containerName + " Error: " + error
|
|
474
|
-
);
|
|
458
|
+
throw new Error("Error in Azure getHeadContainer. Container: " + this.containerName + " Error: " + error);
|
|
475
459
|
}
|
|
476
460
|
}
|
|
477
461
|
async listMultipartUploadsForBucket() {
|
|
478
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
479
|
-
this.containerName
|
|
480
|
-
);
|
|
462
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
481
463
|
const blobList = containerClient.listBlobsFlat();
|
|
482
464
|
const uploads = [];
|
|
483
465
|
try {
|
|
@@ -512,15 +494,12 @@ var BlobStorageService = class {
|
|
|
512
494
|
*/
|
|
513
495
|
async listMultipartUploadsForKey(blobName) {
|
|
514
496
|
var _a;
|
|
515
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
516
|
-
this.containerName
|
|
517
|
-
);
|
|
497
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
518
498
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
519
499
|
const listResponse = await blobClient.getBlockList("all");
|
|
520
500
|
const parts = ((_a = listResponse == null ? void 0 : listResponse.uncommittedBlocks) == null ? void 0 : _a.map((block, index) => ({
|
|
521
501
|
PartNumber: index + 1,
|
|
522
502
|
LastModified: /* @__PURE__ */ new Date(),
|
|
523
|
-
// Azure Blob Storage doesn't provide the last modified date for individual parts
|
|
524
503
|
ETag: block.name,
|
|
525
504
|
Size: block.size
|
|
526
505
|
}))) || [];
|
|
@@ -549,9 +528,7 @@ var BlobStorageService = class {
|
|
|
549
528
|
* @return {Promise<string>} A Promise that resolves to a string representing the base64 encoded block ID of the uploaded part.
|
|
550
529
|
*/
|
|
551
530
|
async uploadMultipart(blobName, file, partNumber, uploadId) {
|
|
552
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
553
|
-
this.containerName
|
|
554
|
-
);
|
|
531
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
555
532
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
556
533
|
const blockIdBase = uploadId || await this.generateUploadIdMultipart();
|
|
557
534
|
const partId = partNumber.toString().padStart(6, "0");
|
|
@@ -569,9 +546,7 @@ var BlobStorageService = class {
|
|
|
569
546
|
*/
|
|
570
547
|
async completeMultipartUpload(blobName, uploadId) {
|
|
571
548
|
var _a;
|
|
572
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
573
|
-
this.containerName
|
|
574
|
-
);
|
|
549
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
575
550
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
576
551
|
const listMultipartUploads = await this.listMultipartUploadsForKey(blobName);
|
|
577
552
|
const blockIds = ((_a = listMultipartUploads == null ? void 0 : listMultipartUploads.Parts) == null ? void 0 : _a.map((part) => part.ETag)) || [];
|
|
@@ -588,9 +563,7 @@ var BlobStorageService = class {
|
|
|
588
563
|
* @return {Promise<void>} A promise that resolves when the multipart upload is successfully aborted.
|
|
589
564
|
*/
|
|
590
565
|
async abortMultipartUpload(blobName, uploadId) {
|
|
591
|
-
const containerClient = this.blobServiceClient.getContainerClient(
|
|
592
|
-
this.containerName
|
|
593
|
-
);
|
|
566
|
+
const containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
594
567
|
const blobClient = containerClient.getBlockBlobClient(blobName);
|
|
595
568
|
const blockIdStorage = BlockIdStorage.getInstance();
|
|
596
569
|
blockIdStorage.clearBlockIds(uploadId);
|
|
@@ -599,15 +572,13 @@ var BlobStorageService = class {
|
|
|
599
572
|
async getMultipartUploadPresignedUrl(blobName, uploadId, partNumber, expiresInMinutes = 2) {
|
|
600
573
|
const partId = partNumber.toString().padStart(6, "0");
|
|
601
574
|
const partIdBase64 = Buffer.from(partId).toString("base64");
|
|
602
|
-
const sasUrl = await this.getSignatureUrl(
|
|
603
|
-
blobName,
|
|
604
|
-
expiresInMinutes,
|
|
605
|
-
"w"
|
|
606
|
-
);
|
|
575
|
+
const sasUrl = await this.getSignatureUrl(blobName, expiresInMinutes, "w");
|
|
607
576
|
const url = `${sasUrl}&comp=block&blockid=${partIdBase64}`;
|
|
608
577
|
return url;
|
|
609
578
|
}
|
|
610
579
|
};
|
|
580
|
+
__name(_BlobStorageService, "BlobStorageService");
|
|
581
|
+
var BlobStorageService = _BlobStorageService;
|
|
611
582
|
|
|
612
583
|
// src/services/storage/s3/s3Helpers.ts
|
|
613
584
|
function listResponseContentsToListResponseItems(responseContents) {
|
|
@@ -620,6 +591,7 @@ function listResponseContentsToListResponseItems(responseContents) {
|
|
|
620
591
|
};
|
|
621
592
|
});
|
|
622
593
|
}
|
|
594
|
+
__name(listResponseContentsToListResponseItems, "listResponseContentsToListResponseItems");
|
|
623
595
|
function s3ObjectToObjectResponse(s3Object) {
|
|
624
596
|
return {
|
|
625
597
|
body: s3Object.Body,
|
|
@@ -634,21 +606,23 @@ function s3ObjectToObjectResponse(s3Object) {
|
|
|
634
606
|
lastModified: s3Object.LastModified
|
|
635
607
|
};
|
|
636
608
|
}
|
|
637
|
-
|
|
609
|
+
__name(s3ObjectToObjectResponse, "s3ObjectToObjectResponse");
|
|
610
|
+
var _S3StorageService = class _S3StorageService {
|
|
638
611
|
constructor(bucketName, options) {
|
|
639
|
-
this
|
|
612
|
+
__publicField(this, "httpHandler", new NodeHttpHandler({
|
|
640
613
|
socketTimeout: 6e5
|
|
641
|
-
});
|
|
642
|
-
this
|
|
614
|
+
}));
|
|
615
|
+
__publicField(this, "s3Client", new S3Client({
|
|
643
616
|
region: process.env.AWS_DEFAULT_REGION,
|
|
644
617
|
requestHandler: this.httpHandler,
|
|
645
618
|
credentials: defaultProvider()
|
|
646
|
-
});
|
|
647
|
-
this
|
|
619
|
+
}));
|
|
620
|
+
__publicField(this, "s3", new S3({
|
|
648
621
|
region: process.env.AWS_DEFAULT_REGION,
|
|
649
622
|
requestHandler: this.httpHandler,
|
|
650
623
|
credentials: defaultProvider()
|
|
651
|
-
});
|
|
624
|
+
}));
|
|
625
|
+
__publicField(this, "bucketName");
|
|
652
626
|
var _a, _b, _c, _d;
|
|
653
627
|
this.bucketName = bucketName;
|
|
654
628
|
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)) {
|
|
@@ -693,11 +667,7 @@ var S3StorageService = class {
|
|
|
693
667
|
let continueListing = true;
|
|
694
668
|
while (continueListing) {
|
|
695
669
|
const listChunkLimit = limit - responseContents.length;
|
|
696
|
-
const response = await this.listChunk(
|
|
697
|
-
options,
|
|
698
|
-
continuationToken,
|
|
699
|
-
listChunkLimit
|
|
700
|
-
);
|
|
670
|
+
const response = await this.listChunk(options, continuationToken, listChunkLimit);
|
|
701
671
|
continuationToken = response.NextContinuationToken;
|
|
702
672
|
responseContents = responseContents.concat((_b = response.Contents) != null ? _b : []);
|
|
703
673
|
if (responseContents.length >= limit || !continuationToken) {
|
|
@@ -739,10 +709,16 @@ var S3StorageService = class {
|
|
|
739
709
|
pagination
|
|
740
710
|
}));
|
|
741
711
|
if ((_a = response.items) == null ? void 0 : _a.length)
|
|
742
|
-
allItems = [
|
|
712
|
+
allItems = [
|
|
713
|
+
...allItems,
|
|
714
|
+
...response.items
|
|
715
|
+
];
|
|
743
716
|
pagination = response.pagination === null ? void 0 : response.pagination;
|
|
744
717
|
} while (pagination);
|
|
745
|
-
return {
|
|
718
|
+
return {
|
|
719
|
+
items: allItems,
|
|
720
|
+
count: allItems.length
|
|
721
|
+
};
|
|
746
722
|
}
|
|
747
723
|
/**
|
|
748
724
|
* Retrieves an object from the S3 bucket.
|
|
@@ -782,7 +758,9 @@ var S3StorageService = class {
|
|
|
782
758
|
Bucket: this.bucketName,
|
|
783
759
|
Key: key
|
|
784
760
|
});
|
|
785
|
-
return getSignedUrl(this.s3Client, command, {
|
|
761
|
+
return getSignedUrl(this.s3Client, command, {
|
|
762
|
+
expiresIn
|
|
763
|
+
});
|
|
786
764
|
}
|
|
787
765
|
/**
|
|
788
766
|
* Retrieves a signed URL for uploading an object to the S3 bucket.
|
|
@@ -822,7 +800,9 @@ var S3StorageService = class {
|
|
|
822
800
|
Metadata: metadata
|
|
823
801
|
});
|
|
824
802
|
await this.s3Client.send(command);
|
|
825
|
-
return {
|
|
803
|
+
return {
|
|
804
|
+
key
|
|
805
|
+
};
|
|
826
806
|
}
|
|
827
807
|
/**
|
|
828
808
|
* Creates a writable stream for uploading a file to the S3 bucket.
|
|
@@ -869,9 +849,7 @@ var S3StorageService = class {
|
|
|
869
849
|
});
|
|
870
850
|
return this.s3Client.send(command);
|
|
871
851
|
} catch (error) {
|
|
872
|
-
throw new Error(
|
|
873
|
-
"Error in S3 getHeadContainer. bucketName: " + this.bucketName + " Error: " + error
|
|
874
|
-
);
|
|
852
|
+
throw new Error("Error in S3 getHeadContainer. bucketName: " + this.bucketName + " Error: " + error);
|
|
875
853
|
}
|
|
876
854
|
}
|
|
877
855
|
/**
|
|
@@ -948,10 +926,7 @@ var S3StorageService = class {
|
|
|
948
926
|
return upId;
|
|
949
927
|
}
|
|
950
928
|
async completeMultipartUpload(key, uploadId) {
|
|
951
|
-
const partsResponse = await this.listMultipartUploadsForKey(
|
|
952
|
-
key,
|
|
953
|
-
uploadId
|
|
954
|
-
);
|
|
929
|
+
const partsResponse = await this.listMultipartUploadsForKey(key, uploadId);
|
|
955
930
|
const partsList = (partsResponse == null ? void 0 : partsResponse.Parts) && partsResponse.Parts.map(
|
|
956
931
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
957
932
|
(_a) => {
|
|
@@ -985,14 +960,14 @@ var S3StorageService = class {
|
|
|
985
960
|
PartNumber: parseInt(partNumber, 10)
|
|
986
961
|
};
|
|
987
962
|
const expiresIn = expiresInMinutes * 60;
|
|
988
|
-
const presignedUrl = await getSignedUrl(
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
{ expiresIn }
|
|
992
|
-
);
|
|
963
|
+
const presignedUrl = await getSignedUrl(this.s3Client, new UploadPartCommand(uploadPartParams), {
|
|
964
|
+
expiresIn
|
|
965
|
+
});
|
|
993
966
|
return presignedUrl;
|
|
994
967
|
}
|
|
995
968
|
};
|
|
969
|
+
__name(_S3StorageService, "S3StorageService");
|
|
970
|
+
var S3StorageService = _S3StorageService;
|
|
996
971
|
|
|
997
972
|
// src/shared/utils/constants.ts
|
|
998
973
|
var OBJECT_STORAGE_SERVICE_TYPES = {
|
|
@@ -1001,7 +976,7 @@ var OBJECT_STORAGE_SERVICE_TYPES = {
|
|
|
1001
976
|
};
|
|
1002
977
|
|
|
1003
978
|
// src/services/objectStorageFactory.service.ts
|
|
1004
|
-
var
|
|
979
|
+
var _ObjectStorageFactory = class _ObjectStorageFactory {
|
|
1005
980
|
static async instance(bucketName, options) {
|
|
1006
981
|
var _a, _b;
|
|
1007
982
|
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());
|
|
@@ -1011,15 +986,15 @@ var ObjectStorageFactory = class {
|
|
|
1011
986
|
case OBJECT_STORAGE_SERVICE_TYPES.AZURE_BLOB_STORAGE:
|
|
1012
987
|
return new BlobStorageService(bucketName);
|
|
1013
988
|
default:
|
|
1014
|
-
throw new Error(
|
|
1015
|
-
`Unsupported object storage provider: ${provider}`
|
|
1016
|
-
);
|
|
989
|
+
throw new Error(`Unsupported object storage provider: ${provider}`);
|
|
1017
990
|
}
|
|
1018
991
|
}
|
|
1019
992
|
};
|
|
993
|
+
__name(_ObjectStorageFactory, "ObjectStorageFactory");
|
|
994
|
+
var ObjectStorageFactory = _ObjectStorageFactory;
|
|
1020
995
|
|
|
1021
996
|
// src/services/objectStorage.service.ts
|
|
1022
|
-
var
|
|
997
|
+
var _ObjectStorageService = class _ObjectStorageService {
|
|
1023
998
|
constructor(bucketName, options) {
|
|
1024
999
|
_ObjectStorageService.bucketName = bucketName;
|
|
1025
1000
|
if (options)
|
|
@@ -1038,9 +1013,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1038
1013
|
* @return {Promise<ListResponse>} A promise that resolves to the list of objects.
|
|
1039
1014
|
*/
|
|
1040
1015
|
static async list(options, bucketName) {
|
|
1041
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1042
|
-
bucketName
|
|
1043
|
-
).then((instance) => instance.list(options));
|
|
1016
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.list(options));
|
|
1044
1017
|
}
|
|
1045
1018
|
/**
|
|
1046
1019
|
* Retrieves a list of all objects from the object storage service.
|
|
@@ -1050,9 +1023,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1050
1023
|
* @return {Promise<ListResponse>} A promise that resolves to the list of all objects.
|
|
1051
1024
|
*/
|
|
1052
1025
|
static async listAll(options, bucketName) {
|
|
1053
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1054
|
-
bucketName
|
|
1055
|
-
).then((instance) => instance.listAll(options));
|
|
1026
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listAll(options));
|
|
1056
1027
|
}
|
|
1057
1028
|
/**
|
|
1058
1029
|
* Retrieves an object from the object storage service.
|
|
@@ -1062,9 +1033,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1062
1033
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.
|
|
1063
1034
|
*/
|
|
1064
1035
|
static async getObject(key, bucketName, options) {
|
|
1065
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1066
|
-
bucketName
|
|
1067
|
-
).then((instance) => instance.getObject(key, options));
|
|
1036
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getObject(key, options));
|
|
1068
1037
|
}
|
|
1069
1038
|
/**
|
|
1070
1039
|
* Retrieves an object info (without file content) from the object storage service.
|
|
@@ -1072,9 +1041,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1072
1041
|
* @returns A promise that resolves to the info of the file.
|
|
1073
1042
|
*/
|
|
1074
1043
|
static async getHeadObject(key, bucketName) {
|
|
1075
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1076
|
-
bucketName
|
|
1077
|
-
).then((instance) => instance.getHeadObject(key));
|
|
1044
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getHeadObject(key));
|
|
1078
1045
|
}
|
|
1079
1046
|
/**
|
|
1080
1047
|
* Retrieves a signed URL for the specified object in the object storage service.
|
|
@@ -1085,9 +1052,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1085
1052
|
* @return {Promise<string>} A promise that resolves to the generated signed URL.
|
|
1086
1053
|
*/
|
|
1087
1054
|
static async getDownloadUrl(key, expiresInMinutes, bucketName) {
|
|
1088
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1089
|
-
bucketName
|
|
1090
|
-
).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1055
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));
|
|
1091
1056
|
}
|
|
1092
1057
|
/**
|
|
1093
1058
|
* Retrieves an upload URL for the specified object in the object storage service.
|
|
@@ -1098,9 +1063,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1098
1063
|
* @return {Promise<string>} A promise that resolves to the generated upload URL.
|
|
1099
1064
|
*/
|
|
1100
1065
|
static async getUploadUrl(key, expiresInMinutes, bucketName) {
|
|
1101
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1102
|
-
bucketName
|
|
1103
|
-
).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1066
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getUploadUrl(key, expiresInMinutes));
|
|
1104
1067
|
}
|
|
1105
1068
|
/**
|
|
1106
1069
|
* Uploads a file to the object storage service.
|
|
@@ -1112,9 +1075,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1112
1075
|
* @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.
|
|
1113
1076
|
*/
|
|
1114
1077
|
static async upload(key, body, metadata, bucketName) {
|
|
1115
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1116
|
-
bucketName
|
|
1117
|
-
).then((instance) => instance.upload(key, body, metadata));
|
|
1078
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.upload(key, body, metadata));
|
|
1118
1079
|
}
|
|
1119
1080
|
/**
|
|
1120
1081
|
* Creates an upload write stream for the specified key in the object storage service.
|
|
@@ -1124,9 +1085,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1124
1085
|
* @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.
|
|
1125
1086
|
*/
|
|
1126
1087
|
static async createUploadWriteStream(key, bucketName) {
|
|
1127
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1128
|
-
bucketName
|
|
1129
|
-
).then((instance) => instance.createUploadWriteStream(key));
|
|
1088
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.createUploadWriteStream(key));
|
|
1130
1089
|
}
|
|
1131
1090
|
/**
|
|
1132
1091
|
* Deletes an object or multiple objects from the object storage service.
|
|
@@ -1136,15 +1095,16 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1136
1095
|
* @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.
|
|
1137
1096
|
*/
|
|
1138
1097
|
static async delete(key, bucketName) {
|
|
1139
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1140
|
-
bucketName
|
|
1141
|
-
).then(async (instance) => {
|
|
1098
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then(async (instance) => {
|
|
1142
1099
|
if (Array.isArray(key)) {
|
|
1143
1100
|
const deleteBlobPromises = key.map(async (blobName) => {
|
|
1144
1101
|
var _a;
|
|
1145
1102
|
try {
|
|
1146
1103
|
await instance.delete(blobName);
|
|
1147
|
-
return {
|
|
1104
|
+
return {
|
|
1105
|
+
key: blobName,
|
|
1106
|
+
deleted: true
|
|
1107
|
+
};
|
|
1148
1108
|
} catch (error) {
|
|
1149
1109
|
return {
|
|
1150
1110
|
key: blobName,
|
|
@@ -1166,9 +1126,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1166
1126
|
* @return {Promise<HeadBucketResponse>} A promise that resolves to the head bucket response.
|
|
1167
1127
|
*/
|
|
1168
1128
|
static async getHeadBucket(bucketName) {
|
|
1169
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1170
|
-
bucketName
|
|
1171
|
-
).then((instance) => instance.getHeadBucket());
|
|
1129
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.getHeadBucket());
|
|
1172
1130
|
}
|
|
1173
1131
|
/**
|
|
1174
1132
|
* Generates a unique upload ID for a multipart upload.
|
|
@@ -1178,9 +1136,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1178
1136
|
* @return {Promise<string>} A promise that resolves to the generated upload ID.
|
|
1179
1137
|
*/
|
|
1180
1138
|
static async generateUploadIdMultipart(key, bucketName) {
|
|
1181
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1182
|
-
bucketName
|
|
1183
|
-
).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1139
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.generateUploadIdMultipart(key));
|
|
1184
1140
|
}
|
|
1185
1141
|
/**
|
|
1186
1142
|
* Retrieves a list of multipart uploads for a specified key in the object storage service.
|
|
@@ -1191,11 +1147,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1191
1147
|
* @return {Promise<ListPartsMultipartUploadResponse>} A promise that resolves to the list of multipart uploads for the specified key.
|
|
1192
1148
|
*/
|
|
1193
1149
|
static async listMultipartUploadsForKey(key, bucketName, uploadId) {
|
|
1194
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1195
|
-
bucketName
|
|
1196
|
-
).then(
|
|
1197
|
-
(instance) => instance.listMultipartUploadsForKey(key, uploadId)
|
|
1198
|
-
);
|
|
1150
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listMultipartUploadsForKey(key, uploadId));
|
|
1199
1151
|
}
|
|
1200
1152
|
/**
|
|
1201
1153
|
* Retrieves a list of all multipart uploads for a specified bucket in the object storage service.
|
|
@@ -1204,9 +1156,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1204
1156
|
* @return {Promise<ListMultipartUploadsResponse>} A promise that resolves to the list of multipart uploads for the specified bucket.
|
|
1205
1157
|
*/
|
|
1206
1158
|
static async listMultipartUploadsForBucket(bucketName) {
|
|
1207
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1208
|
-
bucketName
|
|
1209
|
-
).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1159
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.listMultipartUploadsForBucket());
|
|
1210
1160
|
}
|
|
1211
1161
|
/**
|
|
1212
1162
|
* Uploads a multipart file to the specified bucket in the object storage service.
|
|
@@ -1219,11 +1169,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1219
1169
|
* @return {Promise<string>} A Promise that resolves to the base64 encoded block ID of the uploaded part.
|
|
1220
1170
|
*/
|
|
1221
1171
|
static async uploadMultipart(key, file, partNumber, uploadId, bucketName) {
|
|
1222
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1223
|
-
bucketName
|
|
1224
|
-
).then(
|
|
1225
|
-
(instance) => instance.uploadMultipart(key, file, partNumber, uploadId)
|
|
1226
|
-
);
|
|
1172
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.uploadMultipart(key, file, partNumber, uploadId));
|
|
1227
1173
|
}
|
|
1228
1174
|
/**
|
|
1229
1175
|
* Completes a multipart upload for the specified object in the object storage service.
|
|
@@ -1234,9 +1180,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1234
1180
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is completed.
|
|
1235
1181
|
*/
|
|
1236
1182
|
static async completeMultipartUpload(key, uploadId, bucketName) {
|
|
1237
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1238
|
-
bucketName
|
|
1239
|
-
).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1183
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.completeMultipartUpload(key, uploadId));
|
|
1240
1184
|
}
|
|
1241
1185
|
/**
|
|
1242
1186
|
* Aborts a multipart upload for the specified object in the object storage service.
|
|
@@ -1247,9 +1191,7 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1247
1191
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is aborted.
|
|
1248
1192
|
*/
|
|
1249
1193
|
static async abortMultipartUpload(key, uploadId, bucketName) {
|
|
1250
|
-
return _ObjectStorageService.getObjectStorageServiceInstance(
|
|
1251
|
-
bucketName
|
|
1252
|
-
).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1194
|
+
return _ObjectStorageService.getObjectStorageServiceInstance(bucketName).then((instance) => instance.abortMultipartUpload(key, uploadId));
|
|
1253
1195
|
}
|
|
1254
1196
|
/**
|
|
1255
1197
|
* Retrieves a presigned URL for a specific part of a multipart upload.
|
|
@@ -1261,16 +1203,13 @@ var ObjectStorageService = class _ObjectStorageService {
|
|
|
1261
1203
|
* @return {Promise<string>} A Promise that resolves to the presigned URL for the specified part of the multipart upload.
|
|
1262
1204
|
*/
|
|
1263
1205
|
static async getMultipartUploadPresignedUrl(key, uploadId, partNumber, expiresInMinutes) {
|
|
1264
|
-
return _ObjectStorageService.getObjectStorageServiceInstance().then(
|
|
1265
|
-
(instance) => instance.getMultipartUploadPresignedUrl(
|
|
1266
|
-
key,
|
|
1267
|
-
uploadId,
|
|
1268
|
-
partNumber,
|
|
1269
|
-
expiresInMinutes
|
|
1270
|
-
)
|
|
1271
|
-
);
|
|
1206
|
+
return _ObjectStorageService.getObjectStorageServiceInstance().then((instance) => instance.getMultipartUploadPresignedUrl(key, uploadId, partNumber, expiresInMinutes));
|
|
1272
1207
|
}
|
|
1273
1208
|
};
|
|
1209
|
+
__name(_ObjectStorageService, "ObjectStorageService");
|
|
1210
|
+
__publicField(_ObjectStorageService, "bucketName");
|
|
1211
|
+
__publicField(_ObjectStorageService, "objectStorageOptions");
|
|
1212
|
+
var ObjectStorageService = _ObjectStorageService;
|
|
1274
1213
|
|
|
1275
1214
|
export { ObjectStorageService };
|
|
1276
1215
|
//# sourceMappingURL=out.js.map
|