@klapeks/micro-db-utils 0.0.9 → 0.0.11
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.
|
@@ -12,12 +12,29 @@ export declare class S3Connection {
|
|
|
12
12
|
private _config;
|
|
13
13
|
constructor(config: S3ConnectionConfig);
|
|
14
14
|
get bucketName(): string;
|
|
15
|
-
presignedUploadObjectUrl(path: string, mimeType: string): Promise<{
|
|
16
|
-
url: string;
|
|
17
|
-
mimeType: string;
|
|
18
|
-
}>;
|
|
19
15
|
uploadObject(path: string, buffer: Buffer, mimeType: string): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
20
16
|
listByPrefix(prefix: string): Promise<import("@aws-sdk/client-s3").ListObjectsCommandOutput>;
|
|
21
17
|
deleteFiles(keys: string[]): Promise<import("@aws-sdk/client-s3").DeleteObjectsCommandOutput | undefined>;
|
|
22
18
|
removeDirectory(directory: string): Promise<void>;
|
|
19
|
+
presignedUploadObjectUrl(path: string, mimeType: string): Promise<{
|
|
20
|
+
url: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
}>;
|
|
23
|
+
presignedMultipartUpload(path: string, mimeType: string, parts: number): Promise<{
|
|
24
|
+
pathKey: string;
|
|
25
|
+
uploadId: string;
|
|
26
|
+
urls: {
|
|
27
|
+
partNumber: number;
|
|
28
|
+
url: string;
|
|
29
|
+
isAdditional: boolean;
|
|
30
|
+
}[];
|
|
31
|
+
}>;
|
|
32
|
+
confirmMultipart(data: {
|
|
33
|
+
pathKey: string;
|
|
34
|
+
uploadId: string;
|
|
35
|
+
uploadResults: {
|
|
36
|
+
partNumber: number;
|
|
37
|
+
eTag: string;
|
|
38
|
+
}[];
|
|
39
|
+
}): Promise<void>;
|
|
23
40
|
}
|
|
@@ -71,26 +71,6 @@ var S3Connection = /** @class */ (function () {
|
|
|
71
71
|
enumerable: false,
|
|
72
72
|
configurable: true
|
|
73
73
|
});
|
|
74
|
-
S3Connection.prototype.presignedUploadObjectUrl = function (path, mimeType) {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var url;
|
|
77
|
-
return __generator(this, function (_a) {
|
|
78
|
-
switch (_a.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
if (!s3PresignerModule)
|
|
81
|
-
throw "No @aws-sdk/s3-request-presigner module";
|
|
82
|
-
return [4 /*yield*/, s3PresignerModule.getSignedUrl(this.client, new s3ClientModule.PutObjectCommand({
|
|
83
|
-
Bucket: this.bucketName,
|
|
84
|
-
Key: fixPath(path),
|
|
85
|
-
ContentType: mimeType,
|
|
86
|
-
}), { expiresIn: 3600 })];
|
|
87
|
-
case 1:
|
|
88
|
-
url = _a.sent();
|
|
89
|
-
return [2 /*return*/, { url: url, mimeType: mimeType }];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
74
|
S3Connection.prototype.uploadObject = function (path, buffer, mimeType) {
|
|
95
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
96
76
|
return __generator(this, function (_a) {
|
|
@@ -164,6 +144,102 @@ var S3Connection = /** @class */ (function () {
|
|
|
164
144
|
});
|
|
165
145
|
});
|
|
166
146
|
};
|
|
147
|
+
// ---- PRESIGNED URLS ----
|
|
148
|
+
S3Connection.prototype.presignedUploadObjectUrl = function (path, mimeType) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
var url;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
if (!s3PresignerModule)
|
|
155
|
+
throw "No @aws-sdk/s3-request-presigner module";
|
|
156
|
+
return [4 /*yield*/, s3PresignerModule.getSignedUrl(this.client, new s3ClientModule.PutObjectCommand({
|
|
157
|
+
Bucket: this.bucketName,
|
|
158
|
+
Key: fixPath(path),
|
|
159
|
+
ContentType: mimeType,
|
|
160
|
+
}), { expiresIn: 3600 })];
|
|
161
|
+
case 1:
|
|
162
|
+
url = _a.sent();
|
|
163
|
+
return [2 /*return*/, { url: url, mimeType: mimeType }];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
S3Connection.prototype.presignedMultipartUpload = function (path, mimeType, parts) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
+
var pathKey, createResult, urls, i, url;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
if (!s3ClientModule)
|
|
175
|
+
throw "No @aws-sdk/client-s3 module";
|
|
176
|
+
if (!s3PresignerModule)
|
|
177
|
+
throw "No @aws-sdk/s3-request-presigner module";
|
|
178
|
+
pathKey = fixPath(path);
|
|
179
|
+
return [4 /*yield*/, this.client.send(new s3ClientModule.CreateMultipartUploadCommand({
|
|
180
|
+
Bucket: this.bucketName,
|
|
181
|
+
Key: pathKey,
|
|
182
|
+
ContentType: mimeType
|
|
183
|
+
}))];
|
|
184
|
+
case 1:
|
|
185
|
+
createResult = _a.sent();
|
|
186
|
+
if (!createResult.UploadId)
|
|
187
|
+
throw "No uploadId";
|
|
188
|
+
urls = [];
|
|
189
|
+
i = 1;
|
|
190
|
+
_a.label = 2;
|
|
191
|
+
case 2:
|
|
192
|
+
if (!(i <= (parts + 5))) return [3 /*break*/, 5];
|
|
193
|
+
return [4 /*yield*/, s3PresignerModule.getSignedUrl(this.client, new s3ClientModule.UploadPartCommand({
|
|
194
|
+
Bucket: this.bucketName,
|
|
195
|
+
Key: pathKey,
|
|
196
|
+
UploadId: createResult.UploadId,
|
|
197
|
+
PartNumber: i
|
|
198
|
+
}), { expiresIn: 3600 })];
|
|
199
|
+
case 3:
|
|
200
|
+
url = _a.sent();
|
|
201
|
+
urls.push({
|
|
202
|
+
partNumber: i,
|
|
203
|
+
url: url,
|
|
204
|
+
isAdditional: i > parts
|
|
205
|
+
});
|
|
206
|
+
_a.label = 4;
|
|
207
|
+
case 4:
|
|
208
|
+
i++;
|
|
209
|
+
return [3 /*break*/, 2];
|
|
210
|
+
case 5: return [2 /*return*/, {
|
|
211
|
+
pathKey: pathKey,
|
|
212
|
+
uploadId: createResult.UploadId,
|
|
213
|
+
urls: urls
|
|
214
|
+
}];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
S3Connection.prototype.confirmMultipart = function (data) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
switch (_a.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
if (!s3ClientModule)
|
|
225
|
+
throw "No @aws-sdk/client-s3 module";
|
|
226
|
+
return [4 /*yield*/, this.client.send(new s3ClientModule.CompleteMultipartUploadCommand({
|
|
227
|
+
Bucket: this.bucketName,
|
|
228
|
+
Key: data.pathKey,
|
|
229
|
+
UploadId: data.uploadId,
|
|
230
|
+
MultipartUpload: {
|
|
231
|
+
Parts: data.uploadResults.map(function (r) { return ({
|
|
232
|
+
ETag: r.eTag, PartNumber: r.partNumber
|
|
233
|
+
}); })
|
|
234
|
+
}
|
|
235
|
+
}))];
|
|
236
|
+
case 1:
|
|
237
|
+
_a.sent();
|
|
238
|
+
return [2 /*return*/];
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
167
243
|
return S3Connection;
|
|
168
244
|
}());
|
|
169
245
|
exports.S3Connection = S3Connection;
|
|
@@ -152,7 +152,7 @@ var MongoDBConnection = /** @class */ (function () {
|
|
|
152
152
|
}
|
|
153
153
|
_a = this.getOptions(), host = _a.host, port = _a.port, password = _a.password, username = _a.username;
|
|
154
154
|
mongoURI = 'mongodb://' + host + ':' + port + '/' + databaseName
|
|
155
|
-
+ (replicaSet ? '?replicaSet=' + replicaSet :
|
|
155
|
+
+ (replicaSet ? ('?replicaSet=' + replicaSet) : '');
|
|
156
156
|
// logger.log(mongoURI);
|
|
157
157
|
if (!mongooseModule)
|
|
158
158
|
throw new Error("No mongoose module");
|