@e-mc/cloud 0.5.5 → 0.5.6
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 +1 -1
- package/index.js +33 -24
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
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
4
|
|
package/index.js
CHANGED
|
@@ -23,13 +23,14 @@ function hasSameBucket({ upload, service, bucket }, other) {
|
|
|
23
23
|
return (service && other.service || endpoint && endpoint === other.upload.endpoint) && bucket === other.bucket;
|
|
24
24
|
}
|
|
25
25
|
function getFiles(file, data) {
|
|
26
|
+
var _a, _b;
|
|
26
27
|
const grouped = file.localUri ? [file.localUri] : [];
|
|
27
28
|
if (data.all) {
|
|
28
29
|
const individual = new Set();
|
|
29
30
|
if (!file.cloudUrl) {
|
|
30
|
-
file.transforms
|
|
31
|
+
(_a = file.transforms) === null || _a === void 0 ? void 0 : _a.forEach(value => individual.add(value));
|
|
31
32
|
}
|
|
32
|
-
file.torrentFiles
|
|
33
|
+
(_b = file.torrentFiles) === null || _b === void 0 ? void 0 : _b.forEach(value => individual.add(value));
|
|
33
34
|
if (file.descendants) {
|
|
34
35
|
grouped.push(...file.descendants);
|
|
35
36
|
}
|
|
@@ -48,7 +49,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
48
49
|
this.downloaded = [];
|
|
49
50
|
}
|
|
50
51
|
static async finalize(instance) {
|
|
51
|
-
var _a, _b;
|
|
52
|
+
var _a, _b, _c, _d;
|
|
53
|
+
var _e, _f;
|
|
52
54
|
if (instance.aborted) {
|
|
53
55
|
return Promise.reject((0, types_1.createAbortError)());
|
|
54
56
|
}
|
|
@@ -65,7 +67,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
65
67
|
instance.writeTimeElapsed(instance.moduleName, "Transactions were committed", startTime, { type: 64, ...Cloud.LOG_STYLE_SUCCESS });
|
|
66
68
|
}
|
|
67
69
|
for (const { instance: document } of this.Document) {
|
|
68
|
-
document.cloudInit
|
|
70
|
+
(_a = document.cloudInit) === null || _a === void 0 ? void 0 : _a.call(document, state);
|
|
69
71
|
}
|
|
70
72
|
for (const item of this.assets) {
|
|
71
73
|
const cloudStorage = item.cloudStorage;
|
|
@@ -77,7 +79,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
77
79
|
ignore: {
|
|
78
80
|
if (item.localUri || item.torrentFiles) {
|
|
79
81
|
for (const { instance: document } of this.Document) {
|
|
80
|
-
if (document.cloudObject
|
|
82
|
+
if ((_b = document.cloudObject) === null || _b === void 0 ? void 0 : _b.call(document, state, item)) {
|
|
81
83
|
break ignore;
|
|
82
84
|
}
|
|
83
85
|
}
|
|
@@ -90,9 +92,9 @@ class Cloud extends core_1.ClientDb {
|
|
|
90
92
|
for (const storage of cloudStorage) {
|
|
91
93
|
const { admin, bucket } = storage;
|
|
92
94
|
if (admin && bucket && instance.hasCredential('storage', storage)) {
|
|
93
|
-
const policy = admin.configBucket
|
|
95
|
+
const policy = (_c = admin.configBucket) === null || _c === void 0 ? void 0 : _c.policy;
|
|
94
96
|
if (admin.emptyBucket) {
|
|
95
|
-
const service = bucketDelete[
|
|
97
|
+
const service = bucketDelete[_e = storage.service] || (bucketDelete[_e] = {});
|
|
96
98
|
const items = service[bucket];
|
|
97
99
|
if (!items) {
|
|
98
100
|
service[bucket] = [instance.getCredential(storage), admin.recursive];
|
|
@@ -102,7 +104,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
if (policy) {
|
|
105
|
-
const service = bucketPolicy[
|
|
107
|
+
const service = bucketPolicy[_f = storage.service] || (bucketPolicy[_f] = {});
|
|
106
108
|
service[bucket] = [storage.service, instance.getCredential(storage), bucket, policy];
|
|
107
109
|
}
|
|
108
110
|
}
|
|
@@ -186,7 +188,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
186
188
|
}
|
|
187
189
|
}
|
|
188
190
|
else {
|
|
189
|
-
downloadUri = pathname ? path.join(this.baseDirectory, pathname.replace(/^([A-Z]:)?[\\/]+/i, ''), filename) : path.join(data.admin
|
|
191
|
+
downloadUri = pathname ? path.join(this.baseDirectory, pathname.replace(/^([A-Z]:)?[\\/]+/i, ''), filename) : path.join(((_d = data.admin) === null || _d === void 0 ? void 0 : _d.preservePath) && localUri ? path.dirname(localUri) : this.baseDirectory, filename);
|
|
190
192
|
}
|
|
191
193
|
const destDir = path.dirname(downloadUri);
|
|
192
194
|
if (Cloud.isPath(downloadUri)) {
|
|
@@ -360,6 +362,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
360
362
|
return tasks;
|
|
361
363
|
}
|
|
362
364
|
static sanitizeAssets(assets) {
|
|
365
|
+
var _a;
|
|
363
366
|
const storage = [];
|
|
364
367
|
for (const item of assets) {
|
|
365
368
|
const cloudStorage = item.cloudStorage;
|
|
@@ -370,7 +373,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
370
373
|
if (upload.filename) {
|
|
371
374
|
setUploadFilename(upload, this.toPosix(upload.filename));
|
|
372
375
|
}
|
|
373
|
-
const pathname = upload.pathname || data.admin
|
|
376
|
+
const pathname = upload.pathname || ((_a = data.admin) === null || _a === void 0 ? void 0 : _a.preservePath) && item.pathname;
|
|
374
377
|
if (pathname) {
|
|
375
378
|
upload.pathname = this.toPosix(pathname).replace(/^\/+/, '') + '/';
|
|
376
379
|
}
|
|
@@ -438,6 +441,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
438
441
|
return super.setQueryResult(service, credential, queryString, result, sessionKey);
|
|
439
442
|
}
|
|
440
443
|
async createBucket(service, credential, bucket, publicRead, options) {
|
|
444
|
+
var _a, _b;
|
|
441
445
|
if (this.aborted) {
|
|
442
446
|
return Promise.reject((0, types_1.createAbortError)());
|
|
443
447
|
}
|
|
@@ -445,13 +449,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
445
449
|
const client = this.getClient(service);
|
|
446
450
|
try {
|
|
447
451
|
if (publicRead === undefined || typeof publicRead === 'boolean') {
|
|
448
|
-
const handler = client.createBucket
|
|
452
|
+
const handler = (_a = client.createBucket) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
449
453
|
if (handler) {
|
|
450
454
|
return handler.call(this, credential, bucket, publicRead);
|
|
451
455
|
}
|
|
452
456
|
}
|
|
453
457
|
else {
|
|
454
|
-
const handler = client.createBucketV2
|
|
458
|
+
const handler = (_b = client.createBucketV2) === null || _b === void 0 ? void 0 : _b.bind(this);
|
|
455
459
|
if (handler) {
|
|
456
460
|
return handler.call(this, credential, bucket, publicRead, options);
|
|
457
461
|
}
|
|
@@ -468,11 +472,12 @@ class Cloud extends core_1.ClientDb {
|
|
|
468
472
|
}
|
|
469
473
|
}
|
|
470
474
|
async setBucketPolicy(service, credential, bucket, options) {
|
|
475
|
+
var _a;
|
|
471
476
|
if (this.aborted) {
|
|
472
477
|
return Promise.reject((0, types_1.createAbortError)());
|
|
473
478
|
}
|
|
474
479
|
try {
|
|
475
|
-
const handler = this.getClient(service).setBucketPolicy
|
|
480
|
+
const handler = (_a = this.getClient(service).setBucketPolicy) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
476
481
|
if (handler) {
|
|
477
482
|
try {
|
|
478
483
|
return handler.call(this, credential, bucket, options);
|
|
@@ -489,11 +494,12 @@ class Cloud extends core_1.ClientDb {
|
|
|
489
494
|
}
|
|
490
495
|
}
|
|
491
496
|
async setBucketWebsite(service, credential, bucket, options) {
|
|
497
|
+
var _a;
|
|
492
498
|
if (this.aborted) {
|
|
493
499
|
return Promise.reject((0, types_1.createAbortError)());
|
|
494
500
|
}
|
|
495
501
|
try {
|
|
496
|
-
const handler = this.getClient(service).setBucketWebsite
|
|
502
|
+
const handler = (_a = this.getClient(service).setBucketWebsite) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
497
503
|
if (handler) {
|
|
498
504
|
try {
|
|
499
505
|
return handler.call(this, credential, bucket, options);
|
|
@@ -510,17 +516,18 @@ class Cloud extends core_1.ClientDb {
|
|
|
510
516
|
}
|
|
511
517
|
}
|
|
512
518
|
async deleteObjects(service, credential, bucket, recursive = true) {
|
|
519
|
+
var _a, _b;
|
|
513
520
|
if (this.aborted) {
|
|
514
521
|
return Promise.reject((0, types_1.createAbortError)());
|
|
515
522
|
}
|
|
516
523
|
try {
|
|
517
524
|
const errorResponse = (err) => this.formatMessage(64, service, ["Unable to empty bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
518
525
|
const client = this.getClient(service);
|
|
519
|
-
const handlerV2 = client.deleteObjectsV2
|
|
526
|
+
const handlerV2 = (_a = client.deleteObjectsV2) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
520
527
|
if (handlerV2) {
|
|
521
528
|
return handlerV2.call(this, credential, bucket, recursive, service).catch(err => errorResponse(err));
|
|
522
529
|
}
|
|
523
|
-
const handlerV1 = client.deleteObjects
|
|
530
|
+
const handlerV1 = (_b = client.deleteObjects) === null || _b === void 0 ? void 0 : _b.bind(this);
|
|
524
531
|
if (handlerV1) {
|
|
525
532
|
return handlerV1.call(this, credential, bucket, service, undefined, recursive).catch(err => errorResponse(err));
|
|
526
533
|
}
|
|
@@ -620,7 +627,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
620
627
|
const service = item.service;
|
|
621
628
|
if (this.hasCredential('database', item)) {
|
|
622
629
|
const host = SERVICE_CLIENT[service];
|
|
623
|
-
if (host
|
|
630
|
+
if (host === null || host === void 0 ? void 0 : host.executeQuery) {
|
|
624
631
|
const credential = this.getCredential(item);
|
|
625
632
|
if (item.options && this.hasCoerce(service, 'options', null, credential)) {
|
|
626
633
|
(0, types_1.coerceObject)(item.options);
|
|
@@ -652,7 +659,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
652
659
|
const service = data.service;
|
|
653
660
|
if (this.hasCredential('database', data)) {
|
|
654
661
|
const host = SERVICE_CLIENT[service];
|
|
655
|
-
if (host
|
|
662
|
+
if (host === null || host === void 0 ? void 0 : host.executeBatchQuery) {
|
|
656
663
|
const credential = this.getCredential(data);
|
|
657
664
|
if (this.hasCoerce(service, 'options', null, credential)) {
|
|
658
665
|
batch.forEach(item => item.options && (0, types_1.coerceObject)(item.options));
|
|
@@ -788,26 +795,27 @@ class Cloud extends core_1.ClientDb {
|
|
|
788
795
|
return result + (folder ? '/' + folder : '');
|
|
789
796
|
}
|
|
790
797
|
settingsOf(service, name, component) {
|
|
798
|
+
var _a, _b, _c, _d;
|
|
791
799
|
const settings = this.settings;
|
|
792
800
|
let options;
|
|
793
801
|
switch (service) {
|
|
794
802
|
case 'az':
|
|
795
|
-
options = settings.az
|
|
803
|
+
options = (_a = settings.az) !== null && _a !== void 0 ? _a : settings.azure;
|
|
796
804
|
break;
|
|
797
805
|
case 'azure':
|
|
798
|
-
options = settings.azure
|
|
806
|
+
options = (_b = settings.azure) !== null && _b !== void 0 ? _b : settings.az;
|
|
799
807
|
break;
|
|
800
808
|
case 'gcp':
|
|
801
|
-
options = settings.gcp
|
|
809
|
+
options = (_c = settings.gcp) !== null && _c !== void 0 ? _c : settings.gcloud;
|
|
802
810
|
break;
|
|
803
811
|
case 'gcloud':
|
|
804
|
-
options = settings.gcloud
|
|
812
|
+
options = (_d = settings.gcloud) !== null && _d !== void 0 ? _d : settings.gcp;
|
|
805
813
|
break;
|
|
806
814
|
default:
|
|
807
815
|
options = settings[service];
|
|
808
816
|
break;
|
|
809
817
|
}
|
|
810
|
-
const result = options
|
|
818
|
+
const result = options === null || options === void 0 ? void 0 : options[name];
|
|
811
819
|
return component ? (0, types_1.isObject)(result) ? result[component] : undefined : result;
|
|
812
820
|
}
|
|
813
821
|
commit() {
|
|
@@ -815,7 +823,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
815
823
|
return Promise.reject((0, types_1.createAbortError)());
|
|
816
824
|
}
|
|
817
825
|
const items = this.pending.filter(item => !item.document).map(async (data) => {
|
|
818
|
-
|
|
826
|
+
var _a;
|
|
827
|
+
(_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
|
|
819
828
|
return this.getDatabaseRows(data, true);
|
|
820
829
|
});
|
|
821
830
|
return items.length === 0 ? Promise.resolve(false) : this.allSettled(items, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/cloud",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "Cloud constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
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.6",
|
|
24
|
+
"@e-mc/db": "0.5.6",
|
|
25
|
+
"@e-mc/types": "0.5.6"
|
|
26
26
|
}
|
|
27
27
|
}
|