@e-mc/cloud 0.5.3 → 0.5.5
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/LICENSE +7 -11
- package/README.md +5 -3
- package/index.d.ts +5 -5
- package/index.js +51 -51
- package/package.json +6 -6
- package/util.js +6 -5
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright 2023
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1
|
+
Copyright 2023 Anya Forger
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CloudConstructor, IFileManager } from '../types/lib';
|
|
2
|
-
import type { CloudAsset } from '../types/lib/cloud';
|
|
3
|
-
|
|
4
|
-
declare const Cloud: CloudConstructor<IFileManager<CloudAsset>>;
|
|
5
|
-
|
|
1
|
+
import type { CloudConstructor, IFileManager } from '../types/lib';
|
|
2
|
+
import type { CloudAsset } from '../types/lib/cloud';
|
|
3
|
+
|
|
4
|
+
declare const Cloud: CloudConstructor<IFileManager<CloudAsset>>;
|
|
5
|
+
|
|
6
6
|
export = Cloud;
|
package/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
|
-
const types_1 = require("
|
|
6
|
-
const core_1 = require("
|
|
7
|
-
const util_1 = require("
|
|
5
|
+
const types_1 = require("@e-mc/types");
|
|
6
|
+
const core_1 = require("@e-mc/core");
|
|
7
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
8
8
|
const SERVICE_CLIENT = {};
|
|
9
9
|
const SERVICE_UPLOAD = {};
|
|
10
10
|
const SERVICE_DOWNLOAD = {};
|
|
@@ -62,7 +62,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
62
62
|
const startTime = process.hrtime();
|
|
63
63
|
let tasks = [], downloadMap;
|
|
64
64
|
if (await instance.commit()) {
|
|
65
|
-
instance.writeTimeElapsed(instance.moduleName, "Transactions were committed"
|
|
65
|
+
instance.writeTimeElapsed(instance.moduleName, "Transactions were committed", startTime, { type: 64, ...Cloud.LOG_STYLE_SUCCESS });
|
|
66
66
|
}
|
|
67
67
|
for (const { instance: document } of this.Document) {
|
|
68
68
|
document.cloudInit?.(state);
|
|
@@ -71,7 +71,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
71
71
|
const cloudStorage = item.cloudStorage;
|
|
72
72
|
if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item.flags)) {
|
|
73
73
|
if (item.invalid) {
|
|
74
|
-
cloudStorage.forEach(storage => instance.formatMessage(64
|
|
74
|
+
cloudStorage.forEach(storage => instance.formatMessage(64, storage.service, ["Upload failed", storage.bucket], (0, types_1.errorValue)("File not found", item.uri || item.filename || "Unknown"), { ...Cloud.LOG_CLOUD_WARN }));
|
|
75
75
|
continue;
|
|
76
76
|
}
|
|
77
77
|
ignore: {
|
|
@@ -120,7 +120,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
120
120
|
const map = bucketDelete[service];
|
|
121
121
|
for (const bucket in map) {
|
|
122
122
|
const [credential, recursive] = map[bucket];
|
|
123
|
-
tasks.push(instance.deleteObjects(service, credential, bucket, recursive).catch(err => instance.writeFail(["Unable to empty bucket"
|
|
123
|
+
tasks.push(instance.deleteObjects(service, credential, bucket, recursive).catch(err => instance.writeFail(["Unable to empty bucket", service + ': ' + bucket], err, { type: 64, startTime })));
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
if (tasks.length) {
|
|
@@ -142,7 +142,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
142
142
|
const map = bucketPolicy[service];
|
|
143
143
|
for (const bucket in map) {
|
|
144
144
|
const params = map[bucket];
|
|
145
|
-
tasks.push(instance.setBucketPolicy(...params).catch(err => instance.writeFail(["Unable to update bucket policy"
|
|
145
|
+
tasks.push(instance.setBucketPolicy(...params).catch(err => instance.writeFail(["Unable to update bucket policy", params[0] + ': ' + params[2]], err, { type: 64, startTime })));
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
if (tasks.length) {
|
|
@@ -154,7 +154,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
154
154
|
}
|
|
155
155
|
for (const { instance: document } of this.Document) {
|
|
156
156
|
if (document.cloudFinalize) {
|
|
157
|
-
await document.cloudFinalize(state).catch(err => document.writeFail(["Handled rejection"
|
|
157
|
+
await document.cloudFinalize(state).catch(err => document.writeFail(["Handled rejection", document.moduleName], err, { type: 64, startTime }));
|
|
158
158
|
if (document.aborted) {
|
|
159
159
|
return Promise.reject((0, types_1.createAbortError)());
|
|
160
160
|
}
|
|
@@ -181,7 +181,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
181
181
|
if (pathname && path.isAbsolute(pathname)) {
|
|
182
182
|
downloadUri = path.join(pathname, filename);
|
|
183
183
|
if (!Cloud.isPath(downloadUri) && !this.canWrite(pathname)) {
|
|
184
|
-
instance.writeFail(["Unable to download file"
|
|
184
|
+
instance.writeFail(["Unable to download file", filename], (0, types_1.errorValue)("Unsupported access", pathname), { type: 64, fatal: !!active, startTime });
|
|
185
185
|
continue;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -214,7 +214,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
214
214
|
else {
|
|
215
215
|
pending = new Set([downloadUri]);
|
|
216
216
|
download.admin = data.admin;
|
|
217
|
-
const task = instance.downloadObject(data.service, instance.getCredential(data), data.bucket, download, (value) => {
|
|
217
|
+
const task = instance.downloadObject(data.service, instance.getCredential(data), data.bucket, download, async (value) => {
|
|
218
218
|
let result;
|
|
219
219
|
if (value && !instance.aborted) {
|
|
220
220
|
const items = Array.from(pending);
|
|
@@ -235,7 +235,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
235
235
|
this.addDownload(size = value.length);
|
|
236
236
|
}
|
|
237
237
|
this.add(destUri);
|
|
238
|
-
this.formatMessage(64
|
|
238
|
+
this.formatMessage(64, data.service, ["Download success", (0, types_1.formatSize)(size)], destUri, { ...Cloud.LOG_CLOUD_DOWNLOAD });
|
|
239
239
|
result || (result = destUri);
|
|
240
240
|
}
|
|
241
241
|
catch (err) {
|
|
@@ -244,14 +244,14 @@ class Cloud extends core_1.ClientDb {
|
|
|
244
244
|
--i;
|
|
245
245
|
}
|
|
246
246
|
else {
|
|
247
|
-
instance.writeFail(["Unable to write file"
|
|
247
|
+
instance.writeFail(["Unable to write file", path.basename(destUri)], err, { type: 32, fatal: !!active, startTime });
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
return Promise.resolve(result);
|
|
253
253
|
})
|
|
254
|
-
.catch(err => instance.writeFail(["Download failed"
|
|
254
|
+
.catch(err => instance.writeFail(["Download failed", path.basename(downloadUri)], err, { type: 64, startTime }));
|
|
255
255
|
if (active || waitStatus || this.incremental === 'staging') {
|
|
256
256
|
tasks.push(task);
|
|
257
257
|
}
|
|
@@ -314,7 +314,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
catch (err) {
|
|
317
|
-
instance.writeFail(["Unable to read file"
|
|
317
|
+
instance.writeFail(["Unable to read file", path.basename(value)], err, { type: 32, fatal: false });
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
break;
|
|
@@ -324,7 +324,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
324
324
|
for (const localUri of group) {
|
|
325
325
|
const exists = this.isPath(localUri);
|
|
326
326
|
if (!exists || !instance.canRead(localUri, { ownPermissionOnly: true })) {
|
|
327
|
-
instance.writeFail(["Unable to read file"
|
|
327
|
+
instance.writeFail(["Unable to read file", path.basename(localUri)], (0, types_1.errorValue)(exists ? "Not permitted to read file" : "File not found", localUri), { type: 64, fatal: index === 0 });
|
|
328
328
|
continue;
|
|
329
329
|
}
|
|
330
330
|
let buffer, filename;
|
|
@@ -348,10 +348,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
348
348
|
options.contentType = contentType;
|
|
349
349
|
}
|
|
350
350
|
uploading.push(instance.uploadObject(service, { ...credential }, bucket, options, localUri, callback)
|
|
351
|
-
.catch(err => instance.writeFail(["Upload failed"
|
|
351
|
+
.catch(err => instance.writeFail(["Upload failed", path.basename(localUri)], err, { type: 64, fatal: index === 0 })));
|
|
352
352
|
}
|
|
353
353
|
});
|
|
354
|
-
instance.allSettled(uploading, [`Upload file "${contentType || "Unknown"
|
|
354
|
+
instance.allSettled(uploading, [`Upload file "${contentType || "Unknown"}"`, storage.service + ': ' + path.basename(file.localUri)]).then(() => resolve());
|
|
355
355
|
});
|
|
356
356
|
if (active) {
|
|
357
357
|
tasks.push(task);
|
|
@@ -437,7 +437,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
437
437
|
}
|
|
438
438
|
return super.setQueryResult(service, credential, queryString, result, sessionKey);
|
|
439
439
|
}
|
|
440
|
-
createBucket(service, credential, bucket, publicRead, options) {
|
|
440
|
+
async createBucket(service, credential, bucket, publicRead, options) {
|
|
441
441
|
if (this.aborted) {
|
|
442
442
|
return Promise.reject((0, types_1.createAbortError)());
|
|
443
443
|
}
|
|
@@ -456,10 +456,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
456
456
|
return handler.call(this, credential, bucket, publicRead, options);
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
|
-
return Promise.reject((0, util_1.formatError)(service, "Create bucket not supported"
|
|
459
|
+
return Promise.reject((0, util_1.formatError)(service, "Create bucket not supported"));
|
|
460
460
|
}
|
|
461
461
|
catch (err) {
|
|
462
|
-
this.formatMessage(64
|
|
462
|
+
this.formatMessage(64, service, ["Unable to create bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
463
463
|
return Promise.reject(err);
|
|
464
464
|
}
|
|
465
465
|
}
|
|
@@ -467,7 +467,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
467
467
|
return Promise.reject(err);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
|
-
setBucketPolicy(service, credential, bucket, options) {
|
|
470
|
+
async setBucketPolicy(service, credential, bucket, options) {
|
|
471
471
|
if (this.aborted) {
|
|
472
472
|
return Promise.reject((0, types_1.createAbortError)());
|
|
473
473
|
}
|
|
@@ -478,17 +478,17 @@ class Cloud extends core_1.ClientDb {
|
|
|
478
478
|
return handler.call(this, credential, bucket, options);
|
|
479
479
|
}
|
|
480
480
|
catch (err) {
|
|
481
|
-
this.formatMessage(64
|
|
481
|
+
this.formatMessage(64, service, ["Unable to update bucket policy", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
482
482
|
return Promise.reject(err);
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
|
-
return Promise.reject((0, util_1.formatError)(service, "Bucket policy not supported"
|
|
485
|
+
return Promise.reject((0, util_1.formatError)(service, "Bucket policy not supported"));
|
|
486
486
|
}
|
|
487
487
|
catch (err) {
|
|
488
488
|
return Promise.reject(err);
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
|
-
setBucketWebsite(service, credential, bucket, options) {
|
|
491
|
+
async setBucketWebsite(service, credential, bucket, options) {
|
|
492
492
|
if (this.aborted) {
|
|
493
493
|
return Promise.reject((0, types_1.createAbortError)());
|
|
494
494
|
}
|
|
@@ -499,22 +499,22 @@ class Cloud extends core_1.ClientDb {
|
|
|
499
499
|
return handler.call(this, credential, bucket, options);
|
|
500
500
|
}
|
|
501
501
|
catch (err) {
|
|
502
|
-
this.formatMessage(64
|
|
502
|
+
this.formatMessage(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
503
503
|
return Promise.reject(err);
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
|
-
return Promise.reject((0, util_1.formatError)(service, "Set bucket website not supported"
|
|
506
|
+
return Promise.reject((0, util_1.formatError)(service, "Set bucket website not supported"));
|
|
507
507
|
}
|
|
508
508
|
catch (err) {
|
|
509
509
|
return Promise.reject(err);
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
|
-
deleteObjects(service, credential, bucket, recursive = true) {
|
|
512
|
+
async deleteObjects(service, credential, bucket, recursive = true) {
|
|
513
513
|
if (this.aborted) {
|
|
514
514
|
return Promise.reject((0, types_1.createAbortError)());
|
|
515
515
|
}
|
|
516
516
|
try {
|
|
517
|
-
const errorResponse = (err) => this.formatMessage(64
|
|
517
|
+
const errorResponse = (err) => this.formatMessage(64, service, ["Unable to empty bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
518
518
|
const client = this.getClient(service);
|
|
519
519
|
const handlerV2 = client.deleteObjectsV2?.bind(this);
|
|
520
520
|
if (handlerV2) {
|
|
@@ -524,13 +524,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
524
524
|
if (handlerV1) {
|
|
525
525
|
return handlerV1.call(this, credential, bucket, service, undefined, recursive).catch(err => errorResponse(err));
|
|
526
526
|
}
|
|
527
|
-
return Promise.reject((0, util_1.formatError)(service, "Delete objects not supported"
|
|
527
|
+
return Promise.reject((0, util_1.formatError)(service, "Delete objects not supported"));
|
|
528
528
|
}
|
|
529
529
|
catch (err) {
|
|
530
530
|
return Promise.reject(err);
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
|
-
uploadObject(service, credential, bucket, upload, localUri, beforeResolve) {
|
|
533
|
+
async uploadObject(service, credential, bucket, upload, localUri, beforeResolve) {
|
|
534
534
|
if (this.aborted) {
|
|
535
535
|
return Promise.reject((0, types_1.createAbortError)());
|
|
536
536
|
}
|
|
@@ -539,14 +539,14 @@ class Cloud extends core_1.ClientDb {
|
|
|
539
539
|
handler = this.getUploadHandler(service, credential).bind(this);
|
|
540
540
|
}
|
|
541
541
|
catch (err) {
|
|
542
|
-
this.formatMessage(64
|
|
542
|
+
this.formatMessage(64, service, ["Upload function not supported", bucket], localUri, { ...Cloud.LOG_CLOUD_WARN });
|
|
543
543
|
return Promise.reject(err);
|
|
544
544
|
}
|
|
545
545
|
return new Promise((resolve, reject) => {
|
|
546
546
|
try {
|
|
547
547
|
handler({ bucket, upload, buffer: upload.buffer || fs.readFileSync(localUri), localUri }, async (err, value) => {
|
|
548
548
|
if (err) {
|
|
549
|
-
reject(errorObject(err, service, "Upload failed"
|
|
549
|
+
reject(errorObject(err, service, "Upload failed"));
|
|
550
550
|
}
|
|
551
551
|
else if (value) {
|
|
552
552
|
if (beforeResolve) {
|
|
@@ -556,7 +556,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
556
556
|
resolve(value);
|
|
557
557
|
}
|
|
558
558
|
else {
|
|
559
|
-
reject((0, util_1.formatError)(service, "Upload failed"
|
|
559
|
+
reject((0, util_1.formatError)(service, "Upload failed"));
|
|
560
560
|
}
|
|
561
561
|
});
|
|
562
562
|
}
|
|
@@ -565,7 +565,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
565
565
|
}
|
|
566
566
|
});
|
|
567
567
|
}
|
|
568
|
-
downloadObject(service, credential, bucket, download, beforeResolve) {
|
|
568
|
+
async downloadObject(service, credential, bucket, download, beforeResolve) {
|
|
569
569
|
if (this.aborted) {
|
|
570
570
|
return Promise.reject((0, types_1.createAbortError)());
|
|
571
571
|
}
|
|
@@ -577,14 +577,14 @@ class Cloud extends core_1.ClientDb {
|
|
|
577
577
|
handler = this.getDownloadHandler(service, credential).bind(this);
|
|
578
578
|
}
|
|
579
579
|
catch (err) {
|
|
580
|
-
this.formatMessage(64
|
|
580
|
+
this.formatMessage(64, service, ["Download function not supported", bucket], Cloud.joinPath(download.pathname, download.filename), { ...Cloud.LOG_CLOUD_WARN });
|
|
581
581
|
return Promise.reject(err);
|
|
582
582
|
}
|
|
583
583
|
return new Promise((resolve, reject) => {
|
|
584
584
|
try {
|
|
585
585
|
handler({ bucket, download }, async (err, value) => {
|
|
586
586
|
if (err) {
|
|
587
|
-
reject(errorObject(err, service, "Download failed"
|
|
587
|
+
reject(errorObject(err, service, "Download failed"));
|
|
588
588
|
}
|
|
589
589
|
else if (value) {
|
|
590
590
|
if (beforeResolve) {
|
|
@@ -600,7 +600,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
600
600
|
resolve(value);
|
|
601
601
|
}
|
|
602
602
|
else {
|
|
603
|
-
reject((0, util_1.formatError)(service, "Download failed"
|
|
603
|
+
reject((0, util_1.formatError)(service, "Download failed"));
|
|
604
604
|
}
|
|
605
605
|
});
|
|
606
606
|
}
|
|
@@ -632,13 +632,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
632
632
|
return await host.executeQuery.call(this, credential, item, sessionKey);
|
|
633
633
|
}
|
|
634
634
|
catch (err) {
|
|
635
|
-
this.formatFail(64
|
|
635
|
+
this.formatFail(64, service, "Unable to execute query", err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
636
636
|
return Promise.reject(err);
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
|
-
return Promise.reject((0, util_1.formatError)(service, "Execute query not supported"
|
|
639
|
+
return Promise.reject((0, util_1.formatError)(service, "Execute query not supported"));
|
|
640
640
|
}
|
|
641
|
-
return Promise.reject((0, util_1.formatError)(service, "Invalid credentials"
|
|
641
|
+
return Promise.reject((0, util_1.formatError)(service, "Invalid credentials"));
|
|
642
642
|
}
|
|
643
643
|
async getDatabaseBatchRows(batch, ignoreErrors, sessionKey) {
|
|
644
644
|
if (this.aborted) {
|
|
@@ -664,13 +664,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
664
664
|
return await host.executeBatchQuery.call(this, credential, batch, sessionKey);
|
|
665
665
|
}
|
|
666
666
|
catch (err) {
|
|
667
|
-
this.formatFail(64
|
|
667
|
+
this.formatFail(64, service, "Unable to execute query", err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
668
668
|
return Promise.reject(err);
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
|
-
return Promise.reject((0, util_1.formatError)(service, "Execute query not supported"
|
|
671
|
+
return Promise.reject((0, util_1.formatError)(service, "Execute query not supported"));
|
|
672
672
|
}
|
|
673
|
-
return Promise.reject((0, util_1.formatError)(service, "Invalid credentials"
|
|
673
|
+
return Promise.reject((0, util_1.formatError)(service, "Invalid credentials"));
|
|
674
674
|
}
|
|
675
675
|
getCredential(item, unused) {
|
|
676
676
|
let credential = item.credential, stored;
|
|
@@ -709,7 +709,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
709
709
|
if ((0, types_1.isArray)(data)) {
|
|
710
710
|
for (const item of data) {
|
|
711
711
|
const service = this.hasStorage(action, item);
|
|
712
|
-
if (service && service.active) {
|
|
712
|
+
if (service && service.active) {
|
|
713
713
|
return item;
|
|
714
714
|
}
|
|
715
715
|
}
|
|
@@ -742,7 +742,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
catch (err) {
|
|
745
|
-
this.formatFail(64
|
|
745
|
+
this.formatFail(64, data.service, "Cloud provider not found", err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
746
746
|
}
|
|
747
747
|
return false;
|
|
748
748
|
}
|
|
@@ -754,9 +754,9 @@ class Cloud extends core_1.ClientDb {
|
|
|
754
754
|
}
|
|
755
755
|
resolveService(service, folder) {
|
|
756
756
|
let result;
|
|
757
|
-
if (service
|
|
757
|
+
if (service.startsWith('@')) {
|
|
758
758
|
result = service;
|
|
759
|
-
if (!folder && !service.startsWith("@squared-functions/"
|
|
759
|
+
if (!folder && !service.startsWith("@squared-functions/")) {
|
|
760
760
|
folder = 'client';
|
|
761
761
|
}
|
|
762
762
|
}
|
|
@@ -778,7 +778,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
778
778
|
case 'ibm':
|
|
779
779
|
case 'minio':
|
|
780
780
|
case 'oci':
|
|
781
|
-
result = "@pi-r/"
|
|
781
|
+
result = "@pi-r/" + service;
|
|
782
782
|
break;
|
|
783
783
|
default:
|
|
784
784
|
result = service;
|
|
@@ -814,18 +814,18 @@ class Cloud extends core_1.ClientDb {
|
|
|
814
814
|
if (this.aborted) {
|
|
815
815
|
return Promise.reject((0, types_1.createAbortError)());
|
|
816
816
|
}
|
|
817
|
-
const items = this.pending.filter(item => !item.document).map(data => {
|
|
817
|
+
const items = this.pending.filter(item => !item.document).map(async (data) => {
|
|
818
818
|
data.ignoreCache ?? (data.ignoreCache = true);
|
|
819
819
|
return this.getDatabaseRows(data, true);
|
|
820
820
|
});
|
|
821
|
-
return items.length === 0 ? Promise.resolve(false) : this.allSettled(items, ["Execute unassigned queries"
|
|
821
|
+
return items.length === 0 ? Promise.resolve(false) : this.allSettled(items, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
|
|
822
822
|
}
|
|
823
823
|
getClient(service) {
|
|
824
824
|
try {
|
|
825
825
|
return SERVICE_CLIENT[service] || (SERVICE_CLIENT[service] = require(this.resolveService(service)));
|
|
826
826
|
}
|
|
827
827
|
catch {
|
|
828
|
-
throw (0, util_1.formatError)(service, "Cloud provider not found"
|
|
828
|
+
throw (0, util_1.formatError)(service, "Cloud provider not found");
|
|
829
829
|
}
|
|
830
830
|
}
|
|
831
831
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/cloud",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Cloud constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/e-mc.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
13
|
"directory": "src/cloud"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.5.
|
|
24
|
-
"@e-mc/db": "0.5.
|
|
25
|
-
"@e-mc/types": "0.5.
|
|
23
|
+
"@e-mc/core": "0.5.5",
|
|
24
|
+
"@e-mc/db": "0.5.5",
|
|
25
|
+
"@e-mc/types": "0.5.5"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/util.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasBasicAuth = exports.getBasicAuth = exports.formatError = exports.generateFilename = exports.readableAsBuffer = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const types_1 = require("
|
|
6
|
-
const util_1 = require("
|
|
5
|
+
const types_1 = require("@e-mc/types");
|
|
6
|
+
const util_1 = require("@e-mc/db/util");
|
|
7
7
|
Object.defineProperty(exports, "getBasicAuth", { enumerable: true, get: function () { return util_1.getBasicAuth; } });
|
|
8
8
|
Object.defineProperty(exports, "hasBasicAuth", { enumerable: true, get: function () { return util_1.hasBasicAuth; } });
|
|
9
|
-
function readableAsBuffer(stream) {
|
|
9
|
+
async function readableAsBuffer(stream) {
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
11
|
let result = null;
|
|
12
12
|
stream
|
|
@@ -23,9 +23,10 @@ function generateFilename(filename) {
|
|
|
23
23
|
let basename, suffix;
|
|
24
24
|
return (i) => {
|
|
25
25
|
if (i === 1) {
|
|
26
|
-
const
|
|
26
|
+
const type = /\.[a-z0-9]+\.[a-z0-9]+$/i.exec(filename);
|
|
27
|
+
const j = type ? type.index : filename.lastIndexOf('.');
|
|
27
28
|
if (j !== -1) {
|
|
28
|
-
const match = /^(
|
|
29
|
+
const match = /^(.+)_(\d+)$/.exec(basename = filename.substring(0, j));
|
|
29
30
|
if (match) {
|
|
30
31
|
basename = match[1];
|
|
31
32
|
i = parseInt(match[2]) + 1;
|