@e-mc/cloud 0.7.3 → 0.7.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 +1 -1
- package/index.js +33 -22
- 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)) {
|
|
@@ -298,9 +300,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
298
300
|
const credential = instance.getCredential(storage, true);
|
|
299
301
|
const uploading = [];
|
|
300
302
|
getFiles(file, upload).forEach((group, index) => {
|
|
303
|
+
var _a;
|
|
301
304
|
let fileGroup;
|
|
302
305
|
if (index === 0 && group.length > 1) {
|
|
303
|
-
if (SERVICE_CLIENT.get(service)
|
|
306
|
+
if ((_a = SERVICE_CLIENT.get(service)) === null || _a === void 0 ? void 0 : _a.CLOUD_UPLOAD_FROMDISK) {
|
|
304
307
|
fileGroup = group.slice(1).filter(value => this.isPath(value)).map(value => [value, path.extname(value), value]);
|
|
305
308
|
}
|
|
306
309
|
else {
|
|
@@ -358,6 +361,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
358
361
|
return tasks;
|
|
359
362
|
}
|
|
360
363
|
static sanitizeAssets(assets) {
|
|
364
|
+
var _a;
|
|
361
365
|
const storage = [];
|
|
362
366
|
for (const item of assets) {
|
|
363
367
|
const cloudStorage = item.cloudStorage;
|
|
@@ -368,7 +372,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
368
372
|
if (upload.filename) {
|
|
369
373
|
setUploadFilename(upload, this.toPosix(upload.filename));
|
|
370
374
|
}
|
|
371
|
-
const pathname = upload.pathname || data.admin
|
|
375
|
+
const pathname = upload.pathname || ((_a = data.admin) === null || _a === void 0 ? void 0 : _a.preservePath) && item.pathname;
|
|
372
376
|
if (pathname) {
|
|
373
377
|
upload.pathname = this.toPosix(pathname).replace(/^\/+/, '') + '/';
|
|
374
378
|
}
|
|
@@ -436,6 +440,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
436
440
|
return super.setQueryResult(service, credential, queryString, result, sessionKey);
|
|
437
441
|
}
|
|
438
442
|
async createBucket(service, credential, bucket, publicRead, options) {
|
|
443
|
+
var _a, _b;
|
|
439
444
|
if (this.aborted) {
|
|
440
445
|
return Promise.reject((0, types_1.createAbortError)());
|
|
441
446
|
}
|
|
@@ -443,13 +448,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
443
448
|
const client = this.getClient(service);
|
|
444
449
|
try {
|
|
445
450
|
if (publicRead === undefined || typeof publicRead === 'boolean') {
|
|
446
|
-
const handler = client.createBucket
|
|
451
|
+
const handler = (_a = client.createBucket) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
447
452
|
if (handler) {
|
|
448
453
|
return handler.call(this, credential, bucket, publicRead);
|
|
449
454
|
}
|
|
450
455
|
}
|
|
451
456
|
else {
|
|
452
|
-
const handler = client.createBucketV2
|
|
457
|
+
const handler = (_b = client.createBucketV2) === null || _b === void 0 ? void 0 : _b.bind(this);
|
|
453
458
|
if (handler) {
|
|
454
459
|
return handler.call(this, credential, bucket, publicRead, options);
|
|
455
460
|
}
|
|
@@ -466,11 +471,12 @@ class Cloud extends core_1.ClientDb {
|
|
|
466
471
|
}
|
|
467
472
|
}
|
|
468
473
|
async setBucketPolicy(service, credential, bucket, options) {
|
|
474
|
+
var _a;
|
|
469
475
|
if (this.aborted) {
|
|
470
476
|
return Promise.reject((0, types_1.createAbortError)());
|
|
471
477
|
}
|
|
472
478
|
try {
|
|
473
|
-
const handler = this.getClient(service).setBucketPolicy
|
|
479
|
+
const handler = (_a = this.getClient(service).setBucketPolicy) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
474
480
|
if (handler) {
|
|
475
481
|
try {
|
|
476
482
|
return handler.call(this, credential, bucket, options);
|
|
@@ -487,11 +493,12 @@ class Cloud extends core_1.ClientDb {
|
|
|
487
493
|
}
|
|
488
494
|
}
|
|
489
495
|
async setBucketWebsite(service, credential, bucket, options) {
|
|
496
|
+
var _a;
|
|
490
497
|
if (this.aborted) {
|
|
491
498
|
return Promise.reject((0, types_1.createAbortError)());
|
|
492
499
|
}
|
|
493
500
|
try {
|
|
494
|
-
const handler = this.getClient(service).setBucketWebsite
|
|
501
|
+
const handler = (_a = this.getClient(service).setBucketWebsite) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
495
502
|
if (handler) {
|
|
496
503
|
try {
|
|
497
504
|
return handler.call(this, credential, bucket, options);
|
|
@@ -508,17 +515,18 @@ class Cloud extends core_1.ClientDb {
|
|
|
508
515
|
}
|
|
509
516
|
}
|
|
510
517
|
async deleteObjects(service, credential, bucket, recursive = true) {
|
|
518
|
+
var _a, _b;
|
|
511
519
|
if (this.aborted) {
|
|
512
520
|
return Promise.reject((0, types_1.createAbortError)());
|
|
513
521
|
}
|
|
514
522
|
try {
|
|
515
523
|
const errorResponse = (err) => this.formatMessage(64, service, ["Unable to empty bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
516
524
|
const client = this.getClient(service);
|
|
517
|
-
const handlerV2 = client.deleteObjectsV2
|
|
525
|
+
const handlerV2 = (_a = client.deleteObjectsV2) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
518
526
|
if (handlerV2) {
|
|
519
527
|
return handlerV2.call(this, credential, bucket, recursive, service).catch(err => errorResponse(err));
|
|
520
528
|
}
|
|
521
|
-
const handlerV1 = client.deleteObjects
|
|
529
|
+
const handlerV1 = (_b = client.deleteObjects) === null || _b === void 0 ? void 0 : _b.bind(this);
|
|
522
530
|
if (handlerV1) {
|
|
523
531
|
return handlerV1.call(this, credential, bucket, service, undefined, recursive).catch(err => errorResponse(err));
|
|
524
532
|
}
|
|
@@ -618,7 +626,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
618
626
|
const service = item.service;
|
|
619
627
|
let client;
|
|
620
628
|
if (this.hasCredential('database', item) && (client = this.getClient(item.service))) {
|
|
621
|
-
if (client
|
|
629
|
+
if (client === null || client === void 0 ? void 0 : client.executeQuery) {
|
|
622
630
|
const credential = this.getCredential(item);
|
|
623
631
|
if (item.options && this.hasCoerce(service, 'options', null, credential)) {
|
|
624
632
|
(0, types_1.coerceObject)(item.options);
|
|
@@ -650,7 +658,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
650
658
|
const service = data.service;
|
|
651
659
|
let client;
|
|
652
660
|
if (this.hasCredential('database', data) && (client = this.getClient(service))) {
|
|
653
|
-
if (client
|
|
661
|
+
if (client === null || client === void 0 ? void 0 : client.executeBatchQuery) {
|
|
654
662
|
const credential = this.getCredential(data);
|
|
655
663
|
if (this.hasCoerce(service, 'options', null, credential)) {
|
|
656
664
|
batch.forEach(item => item.options && (0, types_1.coerceObject)(item.options));
|
|
@@ -739,9 +747,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
739
747
|
return (SERVICE_DOWNLOAD[service] || (SERVICE_DOWNLOAD[service] = require(this.resolveService(service, 'download')))).call(this, credential, service);
|
|
740
748
|
}
|
|
741
749
|
resolveService(service, folder) {
|
|
750
|
+
var _a;
|
|
742
751
|
let result;
|
|
743
752
|
if (!service.startsWith('@')) {
|
|
744
|
-
result = this.settings.imports
|
|
753
|
+
result = ((_a = this.settings.imports) === null || _a === void 0 ? void 0 : _a[service]) || util_1.IMPORTS[service];
|
|
745
754
|
}
|
|
746
755
|
else if (!folder && !service.startsWith("@squared-functions/")) {
|
|
747
756
|
folder = 'client';
|
|
@@ -749,7 +758,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
749
758
|
return (result || service) + (folder ? '/' + folder : '');
|
|
750
759
|
}
|
|
751
760
|
settingsOf(service, name, component) {
|
|
752
|
-
|
|
761
|
+
var _a;
|
|
762
|
+
const result = (_a = this.settings[service]) === null || _a === void 0 ? void 0 : _a[name];
|
|
753
763
|
return component ? (0, types_1.isObject)(result) ? result[component] : undefined : result;
|
|
754
764
|
}
|
|
755
765
|
commit() {
|
|
@@ -757,7 +767,8 @@ class Cloud extends core_1.ClientDb {
|
|
|
757
767
|
return Promise.reject((0, types_1.createAbortError)());
|
|
758
768
|
}
|
|
759
769
|
const items = this.pending.filter(item => !item.document).map(async (data) => {
|
|
760
|
-
|
|
770
|
+
var _a;
|
|
771
|
+
(_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
|
|
761
772
|
return this.getDatabaseRows(data, true);
|
|
762
773
|
});
|
|
763
774
|
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.7.
|
|
3
|
+
"version": "0.7.5",
|
|
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.7.
|
|
24
|
-
"@e-mc/db": "0.7.
|
|
25
|
-
"@e-mc/types": "0.7.
|
|
23
|
+
"@e-mc/core": "0.7.5",
|
|
24
|
+
"@e-mc/db": "0.7.5",
|
|
25
|
+
"@e-mc/types": "0.7.5"
|
|
26
26
|
}
|
|
27
27
|
}
|