@e-mc/cloud 0.8.7 → 0.8.9
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 +3 -7
- package/README.md +9 -9
- package/index.js +30 -20
- package/package.json +5 -5
- package/util.js +1 -1
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
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
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
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.
|
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/cloud
|
|
2
2
|
|
|
3
3
|
* NodeJS 14
|
|
4
|
-
*
|
|
4
|
+
* ES2019
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IHost, IScopeOrigin } from "./index";
|
|
@@ -67,13 +67,13 @@ interface CloudConstructor extends ClientDbConstructor<IHost> {
|
|
|
67
67
|
|
|
68
68
|
## References
|
|
69
69
|
|
|
70
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
71
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
72
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
73
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
74
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
75
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
70
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/asset.d.ts
|
|
71
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/cloud.d.ts
|
|
72
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/core.d.ts
|
|
73
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/db.d.ts
|
|
74
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/logger.d.ts
|
|
75
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/settings.d.ts
|
|
76
76
|
|
|
77
77
|
## LICENSE
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
MIT
|
package/index.js
CHANGED
|
@@ -50,7 +50,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
50
50
|
this.downloaded = [];
|
|
51
51
|
}
|
|
52
52
|
static async finalize(instance) {
|
|
53
|
-
var _a, _b;
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
|
+
var _e, _f;
|
|
54
55
|
if (instance.aborted) {
|
|
55
56
|
return Promise.reject((0, types_1.createAbortError)());
|
|
56
57
|
}
|
|
@@ -67,7 +68,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
67
68
|
instance.writeTimeElapsed(instance.moduleName, "Transactions were committed", startTime, { type: 64, ...Cloud.LOG_STYLE_SUCCESS });
|
|
68
69
|
}
|
|
69
70
|
for (const { instance: document } of this.Document) {
|
|
70
|
-
document.cloudInit
|
|
71
|
+
(_a = document.cloudInit) === null || _a === void 0 ? void 0 : _a.call(document, state);
|
|
71
72
|
}
|
|
72
73
|
for (const item of this.assets) {
|
|
73
74
|
const cloudStorage = item.cloudStorage;
|
|
@@ -79,7 +80,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
79
80
|
ignore: {
|
|
80
81
|
if (item.localUri || item.torrentFiles) {
|
|
81
82
|
for (const { instance: document } of this.Document) {
|
|
82
|
-
if (document.cloudObject
|
|
83
|
+
if ((_b = document.cloudObject) === null || _b === void 0 ? void 0 : _b.call(document, state, item)) {
|
|
83
84
|
break ignore;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -92,9 +93,9 @@ class Cloud extends core_1.ClientDb {
|
|
|
92
93
|
for (const storage of cloudStorage) {
|
|
93
94
|
const { admin, bucket } = storage;
|
|
94
95
|
if (admin && bucket && instance.hasCredential('storage', storage)) {
|
|
95
|
-
const policy = admin.configBucket
|
|
96
|
+
const policy = (_c = admin.configBucket) === null || _c === void 0 ? void 0 : _c.policy;
|
|
96
97
|
if (admin.emptyBucket) {
|
|
97
|
-
const service = bucketDelete[
|
|
98
|
+
const service = bucketDelete[_e = storage.service] || (bucketDelete[_e] = {});
|
|
98
99
|
const items = service[bucket];
|
|
99
100
|
if (!items) {
|
|
100
101
|
service[bucket] = [instance.getCredential(storage), admin.recursive];
|
|
@@ -104,7 +105,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
if (policy) {
|
|
107
|
-
const service = bucketPolicy[
|
|
108
|
+
const service = bucketPolicy[_f = storage.service] || (bucketPolicy[_f] = {});
|
|
108
109
|
service[bucket] = [storage.service, instance.getCredential(storage), bucket, policy];
|
|
109
110
|
}
|
|
110
111
|
}
|
|
@@ -187,7 +188,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
else {
|
|
190
|
-
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);
|
|
191
192
|
}
|
|
192
193
|
const destDir = path.dirname(downloadUri);
|
|
193
194
|
if (Cloud.isPath(downloadUri)) {
|
|
@@ -303,6 +304,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
303
304
|
const credential = instance.getCredential(storage, true);
|
|
304
305
|
const uploading = [];
|
|
305
306
|
getFiles(file, upload).forEach(async (group, index) => {
|
|
307
|
+
var _a;
|
|
306
308
|
let fileGroup;
|
|
307
309
|
if (index === 0) {
|
|
308
310
|
if (!group[0]) {
|
|
@@ -310,7 +312,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
310
312
|
return;
|
|
311
313
|
}
|
|
312
314
|
if (group.length > 1) {
|
|
313
|
-
if (SERVICE_CLIENT.get(service)
|
|
315
|
+
if ((_a = SERVICE_CLIENT.get(service)) === null || _a === void 0 ? void 0 : _a.CLOUD_UPLOAD_FROMDISK) {
|
|
314
316
|
fileGroup = group.slice(1).filter(value => this.isPath(value, true)).map(value => [value, path.extname(value), value]);
|
|
315
317
|
}
|
|
316
318
|
else {
|
|
@@ -370,6 +372,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
370
372
|
return tasks;
|
|
371
373
|
}
|
|
372
374
|
static sanitizeAssets(assets) {
|
|
375
|
+
var _a;
|
|
373
376
|
const storage = [];
|
|
374
377
|
for (const item of assets) {
|
|
375
378
|
const cloudStorage = item.cloudStorage;
|
|
@@ -380,7 +383,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
380
383
|
if (upload.filename) {
|
|
381
384
|
setUploadFilename(upload, this.toPosix(upload.filename));
|
|
382
385
|
}
|
|
383
|
-
const pathname = upload.pathname || data.admin
|
|
386
|
+
const pathname = upload.pathname || ((_a = data.admin) === null || _a === void 0 ? void 0 : _a.preservePath) && item.pathname;
|
|
384
387
|
if (pathname) {
|
|
385
388
|
upload.pathname = this.toPosix(pathname).replace(/^\/+/, '') + '/';
|
|
386
389
|
}
|
|
@@ -448,6 +451,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
448
451
|
return super.setQueryResult(service, credential, queryString, result, sessionKey);
|
|
449
452
|
}
|
|
450
453
|
async createBucket(service, credential, bucket, publicRead, options) {
|
|
454
|
+
var _a, _b;
|
|
451
455
|
if (this.aborted) {
|
|
452
456
|
return Promise.reject((0, types_1.createAbortError)());
|
|
453
457
|
}
|
|
@@ -455,13 +459,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
455
459
|
const client = this.getClient(service);
|
|
456
460
|
try {
|
|
457
461
|
if (publicRead === undefined || typeof publicRead === 'boolean') {
|
|
458
|
-
const handler = client.createBucket
|
|
462
|
+
const handler = (_a = client.createBucket) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
459
463
|
if (handler) {
|
|
460
464
|
return handler.call(this, credential, bucket, publicRead);
|
|
461
465
|
}
|
|
462
466
|
}
|
|
463
467
|
else {
|
|
464
|
-
const handler = client.createBucketV2
|
|
468
|
+
const handler = (_b = client.createBucketV2) === null || _b === void 0 ? void 0 : _b.bind(this);
|
|
465
469
|
if (handler) {
|
|
466
470
|
return handler.call(this, credential, bucket, publicRead, options);
|
|
467
471
|
}
|
|
@@ -478,11 +482,12 @@ class Cloud extends core_1.ClientDb {
|
|
|
478
482
|
}
|
|
479
483
|
}
|
|
480
484
|
async setBucketPolicy(service, credential, bucket, options) {
|
|
485
|
+
var _a;
|
|
481
486
|
if (this.aborted) {
|
|
482
487
|
return Promise.reject((0, types_1.createAbortError)());
|
|
483
488
|
}
|
|
484
489
|
try {
|
|
485
|
-
const handler = this.getClient(service).setBucketPolicy
|
|
490
|
+
const handler = (_a = this.getClient(service).setBucketPolicy) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
486
491
|
if (handler) {
|
|
487
492
|
try {
|
|
488
493
|
return handler.call(this, credential, bucket, options);
|
|
@@ -499,11 +504,12 @@ class Cloud extends core_1.ClientDb {
|
|
|
499
504
|
}
|
|
500
505
|
}
|
|
501
506
|
async setBucketWebsite(service, credential, bucket, options) {
|
|
507
|
+
var _a;
|
|
502
508
|
if (this.aborted) {
|
|
503
509
|
return Promise.reject((0, types_1.createAbortError)());
|
|
504
510
|
}
|
|
505
511
|
try {
|
|
506
|
-
const handler = this.getClient(service).setBucketWebsite
|
|
512
|
+
const handler = (_a = this.getClient(service).setBucketWebsite) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
507
513
|
if (handler) {
|
|
508
514
|
try {
|
|
509
515
|
return handler.call(this, credential, bucket, options);
|
|
@@ -520,17 +526,18 @@ class Cloud extends core_1.ClientDb {
|
|
|
520
526
|
}
|
|
521
527
|
}
|
|
522
528
|
async deleteObjects(service, credential, bucket, recursive = true) {
|
|
529
|
+
var _a, _b;
|
|
523
530
|
if (this.aborted) {
|
|
524
531
|
return Promise.reject((0, types_1.createAbortError)());
|
|
525
532
|
}
|
|
526
533
|
try {
|
|
527
534
|
const errorResponse = (err) => this.formatMessage(64, service, ["Unable to empty bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
528
535
|
const client = this.getClient(service);
|
|
529
|
-
const handlerV2 = client.deleteObjectsV2
|
|
536
|
+
const handlerV2 = (_a = client.deleteObjectsV2) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
530
537
|
if (handlerV2) {
|
|
531
538
|
return handlerV2.call(this, credential, bucket, recursive, service).catch(err => errorResponse(err));
|
|
532
539
|
}
|
|
533
|
-
const handlerV1 = client.deleteObjects
|
|
540
|
+
const handlerV1 = (_b = client.deleteObjects) === null || _b === void 0 ? void 0 : _b.bind(this);
|
|
534
541
|
if (handlerV1) {
|
|
535
542
|
return handlerV1.call(this, credential, bucket, service, undefined, recursive).catch(err => errorResponse(err));
|
|
536
543
|
}
|
|
@@ -630,7 +637,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
630
637
|
const service = item.service;
|
|
631
638
|
let client;
|
|
632
639
|
if (this.hasCredential('database', item) && (client = this.getClient(item.service))) {
|
|
633
|
-
if (client
|
|
640
|
+
if (client === null || client === void 0 ? void 0 : client.executeQuery) {
|
|
634
641
|
const credential = this.getCredential(item);
|
|
635
642
|
if (item.options && this.hasCoerce(service, 'options', null, credential)) {
|
|
636
643
|
(0, types_1.coerceObject)(item.options);
|
|
@@ -662,7 +669,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
662
669
|
const service = data.service;
|
|
663
670
|
let client;
|
|
664
671
|
if (this.hasCredential('database', data) && (client = this.getClient(service))) {
|
|
665
|
-
if (client
|
|
672
|
+
if (client === null || client === void 0 ? void 0 : client.executeBatchQuery) {
|
|
666
673
|
const credential = this.getCredential(data);
|
|
667
674
|
if (this.hasCoerce(service, 'options', null, credential)) {
|
|
668
675
|
batch.forEach(item => item.options && (0, types_1.coerceObject)(item.options));
|
|
@@ -751,9 +758,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
751
758
|
return (SERVICE_DOWNLOAD[service] || (SERVICE_DOWNLOAD[service] = require(this.resolveService(service, 'download')))).call(this, credential, service);
|
|
752
759
|
}
|
|
753
760
|
resolveService(service, folder) {
|
|
761
|
+
var _a;
|
|
754
762
|
let result;
|
|
755
763
|
if (!service.startsWith('@')) {
|
|
756
|
-
result = this.settings.imports
|
|
764
|
+
result = ((_a = this.settings.imports) === null || _a === void 0 ? void 0 : _a[service]) || util_1.IMPORTS[service];
|
|
757
765
|
}
|
|
758
766
|
else if (!folder && !service.startsWith("@squared-functions/")) {
|
|
759
767
|
folder = 'client';
|
|
@@ -761,7 +769,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
761
769
|
return (result || service) + (folder ? '/' + folder : '');
|
|
762
770
|
}
|
|
763
771
|
settingsOf(service, name, component) {
|
|
764
|
-
|
|
772
|
+
var _a;
|
|
773
|
+
const result = (_a = this.settings[service]) === null || _a === void 0 ? void 0 : _a[name];
|
|
765
774
|
return component ? (0, types_1.isObject)(result) ? result[component] : undefined : result;
|
|
766
775
|
}
|
|
767
776
|
async commit() {
|
|
@@ -769,7 +778,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
769
778
|
return Promise.reject((0, types_1.createAbortError)());
|
|
770
779
|
}
|
|
771
780
|
const items = this.pending.filter(item => !item.document).map(async (data) => {
|
|
772
|
-
|
|
781
|
+
var _a;
|
|
782
|
+
(_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
|
|
773
783
|
return this.getDatabaseRows(data, true);
|
|
774
784
|
});
|
|
775
785
|
return items.length === 0 ? 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.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "Cloud constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,12 +17,12 @@
|
|
|
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.8.
|
|
24
|
-
"@e-mc/db": "0.8.
|
|
25
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/core": "0.8.9",
|
|
24
|
+
"@e-mc/db": "0.8.9",
|
|
25
|
+
"@e-mc/types": "0.8.9",
|
|
26
26
|
"mime-types": "^2.1.35"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/util.js
CHANGED