@e-mc/cloud 0.8.5 → 0.8.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 +8 -4
- package/README.md +74 -2
- package/index.js +45 -45
- package/package.json +5 -5
- package/util.js +2 -2
package/LICENSE
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
Copyright 2024
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,7 +1,79 @@
|
|
|
1
1
|
# @e-mc/cloud
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
* NodeJS 14
|
|
4
|
+
* ES2020
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { IHost, IScopeOrigin } from "./index";
|
|
16
|
+
import type { ExternalAsset } from "./asset";
|
|
17
|
+
import type { BucketWebsiteOptions, CloudDatabase, CloudFeatures, CloudFunctions, CloudService, CloudStorage, CloudStorageDownload, CloudStorageUpload } from "./cloud";
|
|
18
|
+
import type { ClientDbConstructor, IClientDb } from "./core";
|
|
19
|
+
import type { BatchQueryResult, QueryResult } from "./db";
|
|
20
|
+
import type { LogMessageOptions } from "./logger";
|
|
21
|
+
import type { CloudModule, CloudServiceOptions, CloudSettings, DbCoerceSettings } from "./settings";
|
|
22
|
+
|
|
23
|
+
interface ICloud extends IClientDb<IHost, CloudModule, CloudDatabase, CloudServiceOptions, DbCoerceSettings> {
|
|
24
|
+
module: CloudModule;
|
|
25
|
+
readonly uploaded: string[];
|
|
26
|
+
readonly downloaded: string[];
|
|
27
|
+
createBucket(service: string, credential: unknown, bucket: string, acl?: unknown, options?: unknown): Promise<boolean>;
|
|
28
|
+
createBucket(service: string, credential: unknown, bucket: string, publicRead?: boolean): Promise<boolean>;
|
|
29
|
+
setBucketPolicy(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
|
|
30
|
+
setBucketWebsite(service: string, credential: unknown, bucket: string, options: BucketWebsiteOptions): Promise<boolean>;
|
|
31
|
+
deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean): Promise<void>;
|
|
32
|
+
uploadObject(service: string, credential: unknown, bucket: string, upload: CloudStorageUpload, localUri: string, beforeResolve?: (value: string) => Promise<void> | void): Promise<string>;
|
|
33
|
+
downloadObject(service: string, credential: unknown, bucket: string, download: CloudStorageDownload, beforeResolve?: (value: Buffer | string | null) => Promise<string | undefined> | void): Promise<Buffer | string>;
|
|
34
|
+
getStorage(action: CloudFunctions, data: CloudStorage[] | undefined): CloudStorage | undefined;
|
|
35
|
+
hasStorage(action: CloudFunctions, storage: CloudStorage): CloudStorageUpload | false;
|
|
36
|
+
getDatabaseRows(item: CloudDatabase, ignoreErrors: boolean, sessionKey?: string): Promise<QueryResult>;
|
|
37
|
+
getDatabaseRows(item: CloudDatabase, sessionKey?: string): Promise<QueryResult>;
|
|
38
|
+
getDatabaseBatchRows(batch: CloudDatabase[], ignoreErrors: boolean, sessionKey?: string): Promise<BatchQueryResult>;
|
|
39
|
+
getDatabaseBatchRows(batch: CloudDatabase[], sessionKey?: string): Promise<BatchQueryResult>;
|
|
40
|
+
hasCredential(feature: CloudFeatures, data: CloudService, credential?: unknown): boolean;
|
|
41
|
+
getCredential(item: CloudService, unused?: boolean): Record<string | number | symbol, unknown>;
|
|
42
|
+
getSettings(service: string): Record<string, unknown> | undefined;
|
|
43
|
+
settingsOf(service: string, name: "cache"): unknown;
|
|
44
|
+
settingsOf(service: string, name: "coerce", component: keyof DbCoerceSettings): unknown;
|
|
45
|
+
getUploadHandler(service: string, credential: unknown): (...args: unknown[]) => void;
|
|
46
|
+
getDownloadHandler(service: string, credential: unknown): (...args: unknown[]) => void;
|
|
47
|
+
resolveService(service: string, folder?: string): string;
|
|
48
|
+
get settings(): CloudSettings;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface CloudConstructor extends ClientDbConstructor<IHost> {
|
|
52
|
+
LOG_CLOUD_FAIL: LogMessageOptions;
|
|
53
|
+
LOG_CLOUD_COMMAND: LogMessageOptions;
|
|
54
|
+
LOG_CLOUD_WARN: LogMessageOptions;
|
|
55
|
+
LOG_CLOUD_UPLOAD: LogMessageOptions;
|
|
56
|
+
LOG_CLOUD_DOWNLOAD: LogMessageOptions;
|
|
57
|
+
LOG_CLOUD_DELETE: LogMessageOptions;
|
|
58
|
+
LOG_CLOUD_DELAYED: LogMessageOptions;
|
|
59
|
+
finalize(this: IHost, instance: ICloud): Promise<unknown>;
|
|
60
|
+
uploadAsset(state: IScopeOrigin<IFileManager, ICloud<IFileManager>>, file: ExternalAsset, ignoreProcess: boolean): Promise<unknown>[];
|
|
61
|
+
uploadAsset(state: IScopeOrigin<IFileManager, ICloud<IFileManager>>, file: ExternalAsset, contentType?: string, ignoreProcess?: boolean): Promise<unknown>[];
|
|
62
|
+
sanitizeAssets(assets: ExternalAsset[]): ExternalAsset[];
|
|
63
|
+
readonly prototype: ICloud;
|
|
64
|
+
new(module?: CloudModule, database?: CloudDatabase[], ...args: unknown[]): ICloud;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## References
|
|
69
|
+
|
|
70
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/asset.d.ts
|
|
71
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/cloud.d.ts
|
|
72
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/core.d.ts
|
|
73
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/db.d.ts
|
|
74
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/logger.d.ts
|
|
75
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
|
|
4
76
|
|
|
5
77
|
## LICENSE
|
|
6
78
|
|
|
7
|
-
|
|
79
|
+
BSD 3-Clause
|
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 = new Map();
|
|
9
9
|
const SERVICE_UPLOAD = {};
|
|
10
10
|
const SERVICE_DOWNLOAD = {};
|
|
@@ -64,7 +64,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
64
64
|
const startTime = process.hrtime();
|
|
65
65
|
let tasks = [], downloadMap;
|
|
66
66
|
if (await instance.commit()) {
|
|
67
|
-
instance.writeTimeElapsed(instance.moduleName, "Transactions were committed"
|
|
67
|
+
instance.writeTimeElapsed(instance.moduleName, "Transactions were committed", startTime, { type: 64, ...Cloud.LOG_STYLE_SUCCESS });
|
|
68
68
|
}
|
|
69
69
|
for (const { instance: document } of this.Document) {
|
|
70
70
|
document.cloudInit?.(state);
|
|
@@ -73,7 +73,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
73
73
|
const cloudStorage = item.cloudStorage;
|
|
74
74
|
if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item.flags)) {
|
|
75
75
|
if (item.invalid) {
|
|
76
|
-
cloudStorage.forEach(storage => instance.formatMessage(64
|
|
76
|
+
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 }));
|
|
77
77
|
continue;
|
|
78
78
|
}
|
|
79
79
|
ignore: {
|
|
@@ -122,7 +122,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
122
122
|
const map = bucketDelete[service];
|
|
123
123
|
for (const bucket in map) {
|
|
124
124
|
const [credential, recursive] = map[bucket];
|
|
125
|
-
tasks.push(instance.deleteObjects(service, credential, bucket, recursive).catch(err => instance.writeFail(["Unable to empty bucket"
|
|
125
|
+
tasks.push(instance.deleteObjects(service, credential, bucket, recursive).catch(err => instance.writeFail(["Unable to empty bucket", service + ': ' + bucket], err, { type: 64, startTime })));
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
if (tasks.length) {
|
|
@@ -144,7 +144,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
144
144
|
const map = bucketPolicy[service];
|
|
145
145
|
for (const bucket in map) {
|
|
146
146
|
const params = map[bucket];
|
|
147
|
-
tasks.push(instance.setBucketPolicy(...params).catch(err => instance.writeFail(["Unable to update bucket policy"
|
|
147
|
+
tasks.push(instance.setBucketPolicy(...params).catch(err => instance.writeFail(["Unable to update bucket policy", params[0] + ': ' + params[2]], err, { type: 64, startTime })));
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
if (tasks.length) {
|
|
@@ -156,7 +156,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
156
156
|
}
|
|
157
157
|
for (const { instance: document } of this.Document) {
|
|
158
158
|
if (document.cloudFinalize) {
|
|
159
|
-
await document.cloudFinalize(state).catch(err => document.writeFail(["Handled rejection"
|
|
159
|
+
await document.cloudFinalize(state).catch(err => document.writeFail(["Handled rejection", document.moduleName], err, { type: 64, startTime }));
|
|
160
160
|
if (document.aborted) {
|
|
161
161
|
return Promise.reject((0, types_1.createAbortError)());
|
|
162
162
|
}
|
|
@@ -182,7 +182,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
182
182
|
if (pathname && path.isAbsolute(pathname)) {
|
|
183
183
|
downloadUri = path.join(pathname, filename);
|
|
184
184
|
if (!Cloud.isPath(downloadUri) && !this.canWrite(pathname)) {
|
|
185
|
-
instance.writeFail(["Unable to download file"
|
|
185
|
+
instance.writeFail(["Unable to download file", filename], (0, types_1.errorValue)("Unsupported access", pathname), { type: 64, fatal: !!active, startTime });
|
|
186
186
|
continue;
|
|
187
187
|
}
|
|
188
188
|
}
|
|
@@ -197,7 +197,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
197
197
|
active = true;
|
|
198
198
|
}
|
|
199
199
|
else if (!Cloud.createDir(destDir)) {
|
|
200
|
-
instance.writeFail(["Unable to create directory"
|
|
200
|
+
instance.writeFail(["Unable to create directory", filename], (0, types_1.errorValue)("Path is not a directory", destDir), { type: 64, fatal: !!active, startTime });
|
|
201
201
|
continue;
|
|
202
202
|
}
|
|
203
203
|
else if (active) {
|
|
@@ -237,7 +237,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
237
237
|
this.addDownload(size = value.length);
|
|
238
238
|
}
|
|
239
239
|
this.add(destUri);
|
|
240
|
-
this.formatMessage(64
|
|
240
|
+
this.formatMessage(64, data.service, ["Download success", (0, types_1.formatSize)(size)], destUri, { ...Cloud.LOG_CLOUD_DOWNLOAD });
|
|
241
241
|
result || (result = destUri);
|
|
242
242
|
}
|
|
243
243
|
catch (err) {
|
|
@@ -246,14 +246,14 @@ class Cloud extends core_1.ClientDb {
|
|
|
246
246
|
--i;
|
|
247
247
|
}
|
|
248
248
|
else {
|
|
249
|
-
instance.writeFail(["Unable to write file"
|
|
249
|
+
instance.writeFail(["Unable to write file", path.basename(destUri)], err, { type: 32, fatal: !!active, startTime });
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
return result;
|
|
255
255
|
})
|
|
256
|
-
.catch(err => instance.writeFail(["Download failed"
|
|
256
|
+
.catch(err => instance.writeFail(["Download failed", path.basename(downloadUri)], err, { type: 64, startTime }));
|
|
257
257
|
if (active || waitStatus || this.incremental === 'staging') {
|
|
258
258
|
tasks.push(task);
|
|
259
259
|
}
|
|
@@ -306,7 +306,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
306
306
|
let fileGroup;
|
|
307
307
|
if (index === 0) {
|
|
308
308
|
if (!group[0]) {
|
|
309
|
-
instance.writeFail("Unable to read file"
|
|
309
|
+
instance.writeFail("Unable to read file", (0, types_1.errorValue)("File not found", service), { type: 64, fatal: true });
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
312
|
if (group.length > 1) {
|
|
@@ -322,7 +322,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
322
322
|
fileGroup.push([typeof minStreamSize === 'number' ? await this.streamFile(value, { minStreamSize, cache: false, signal: instance.signal }) : fs.readFileSync(value), path.extname(value), value]);
|
|
323
323
|
}
|
|
324
324
|
catch (err) {
|
|
325
|
-
instance.writeFail(["Unable to read file"
|
|
325
|
+
instance.writeFail(["Unable to read file", path.basename(value)], err, { type: 32, fatal: false });
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
}
|
|
@@ -334,7 +334,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
334
334
|
const localUri = group[i];
|
|
335
335
|
const exists = index === 0 || this.isPath(localUri, true);
|
|
336
336
|
if (!exists || !instance.canRead(localUri, { ownPermissionOnly: true })) {
|
|
337
|
-
instance.writeFail(["Unable to read file"
|
|
337
|
+
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: i === 0 && index === 0 });
|
|
338
338
|
continue;
|
|
339
339
|
}
|
|
340
340
|
let buffer, filename;
|
|
@@ -358,10 +358,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
358
358
|
options.contentType = contentType;
|
|
359
359
|
}
|
|
360
360
|
uploading.push(instance.uploadObject(service, { ...credential }, bucket, options, localUri, callback)
|
|
361
|
-
.catch(err => instance.writeFail(["Upload failed"
|
|
361
|
+
.catch(err => instance.writeFail(["Upload failed", path.basename(localUri)], err, { type: 64, fatal: i === 0 && index === 0 })));
|
|
362
362
|
}
|
|
363
363
|
});
|
|
364
|
-
instance.allSettled(uploading, [`Upload file "${contentType || "Unknown"
|
|
364
|
+
instance.allSettled(uploading, [`Upload file "${contentType || "Unknown"}"`, storage.service + ': ' + path.basename(file.localUri)]).then(() => resolve());
|
|
365
365
|
});
|
|
366
366
|
if (active) {
|
|
367
367
|
tasks.push(task);
|
|
@@ -466,10 +466,10 @@ class Cloud extends core_1.ClientDb {
|
|
|
466
466
|
return handler.call(this, credential, bucket, publicRead, options);
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Create bucket not supported"
|
|
469
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Create bucket not supported"));
|
|
470
470
|
}
|
|
471
471
|
catch (err) {
|
|
472
|
-
this.formatMessage(64
|
|
472
|
+
this.formatMessage(64, service, ["Unable to create bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
473
473
|
return Promise.reject(err);
|
|
474
474
|
}
|
|
475
475
|
}
|
|
@@ -488,11 +488,11 @@ class Cloud extends core_1.ClientDb {
|
|
|
488
488
|
return handler.call(this, credential, bucket, options);
|
|
489
489
|
}
|
|
490
490
|
catch (err) {
|
|
491
|
-
this.formatMessage(64
|
|
491
|
+
this.formatMessage(64, service, ["Unable to update bucket policy", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
492
492
|
return Promise.reject(err);
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Bucket policy not supported"
|
|
495
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Bucket policy not supported"));
|
|
496
496
|
}
|
|
497
497
|
catch (err) {
|
|
498
498
|
return Promise.reject(err);
|
|
@@ -509,11 +509,11 @@ class Cloud extends core_1.ClientDb {
|
|
|
509
509
|
return handler.call(this, credential, bucket, options);
|
|
510
510
|
}
|
|
511
511
|
catch (err) {
|
|
512
|
-
this.formatMessage(64
|
|
512
|
+
this.formatMessage(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
513
513
|
return Promise.reject(err);
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Set bucket website not supported"
|
|
516
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Set bucket website not supported"));
|
|
517
517
|
}
|
|
518
518
|
catch (err) {
|
|
519
519
|
return Promise.reject(err);
|
|
@@ -524,7 +524,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
524
524
|
return Promise.reject((0, types_1.createAbortError)());
|
|
525
525
|
}
|
|
526
526
|
try {
|
|
527
|
-
const errorResponse = (err) => this.formatMessage(64
|
|
527
|
+
const errorResponse = (err) => this.formatMessage(64, service, ["Unable to empty bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
528
528
|
const client = this.getClient(service);
|
|
529
529
|
const handlerV2 = client.deleteObjectsV2?.bind(this);
|
|
530
530
|
if (handlerV2) {
|
|
@@ -534,7 +534,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
534
534
|
if (handlerV1) {
|
|
535
535
|
return handlerV1.call(this, credential, bucket, service, undefined, recursive).catch(err => errorResponse(err));
|
|
536
536
|
}
|
|
537
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Delete objects not supported"
|
|
537
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Delete objects not supported"));
|
|
538
538
|
}
|
|
539
539
|
catch (err) {
|
|
540
540
|
return Promise.reject(err);
|
|
@@ -549,14 +549,14 @@ class Cloud extends core_1.ClientDb {
|
|
|
549
549
|
handler = this.getUploadHandler(service, credential).bind(this);
|
|
550
550
|
}
|
|
551
551
|
catch (err) {
|
|
552
|
-
this.formatMessage(64
|
|
552
|
+
this.formatMessage(64, service, ["Upload function not supported", bucket], localUri, { ...Cloud.LOG_CLOUD_WARN });
|
|
553
553
|
return Promise.reject(err);
|
|
554
554
|
}
|
|
555
555
|
return new Promise((resolve, reject) => {
|
|
556
556
|
try {
|
|
557
557
|
handler({ bucket, upload, buffer: upload.buffer || fs.readFileSync(localUri), localUri }, async (err, value) => {
|
|
558
558
|
if (err) {
|
|
559
|
-
reject(errorObject(err, service, "Upload failed"
|
|
559
|
+
reject(errorObject(err, service, "Upload failed"));
|
|
560
560
|
}
|
|
561
561
|
else if (value) {
|
|
562
562
|
if (beforeResolve) {
|
|
@@ -566,7 +566,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
566
566
|
resolve(value);
|
|
567
567
|
}
|
|
568
568
|
else {
|
|
569
|
-
reject((0, types_1.errorMessage)(service, "Upload failed"
|
|
569
|
+
reject((0, types_1.errorMessage)(service, "Upload failed"));
|
|
570
570
|
}
|
|
571
571
|
});
|
|
572
572
|
}
|
|
@@ -587,14 +587,14 @@ class Cloud extends core_1.ClientDb {
|
|
|
587
587
|
handler = this.getDownloadHandler(service, credential).bind(this);
|
|
588
588
|
}
|
|
589
589
|
catch (err) {
|
|
590
|
-
this.formatMessage(64
|
|
590
|
+
this.formatMessage(64, service, ["Download function not supported", bucket], Cloud.joinPath(download.pathname, download.filename), { ...Cloud.LOG_CLOUD_WARN });
|
|
591
591
|
return Promise.reject(err);
|
|
592
592
|
}
|
|
593
593
|
return new Promise((resolve, reject) => {
|
|
594
594
|
try {
|
|
595
595
|
handler({ bucket, download }, async (err, value) => {
|
|
596
596
|
if (err) {
|
|
597
|
-
reject(errorObject(err, service, "Download failed"
|
|
597
|
+
reject(errorObject(err, service, "Download failed"));
|
|
598
598
|
}
|
|
599
599
|
else if (value) {
|
|
600
600
|
if (beforeResolve) {
|
|
@@ -610,7 +610,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
610
610
|
resolve(value);
|
|
611
611
|
}
|
|
612
612
|
else {
|
|
613
|
-
reject((0, types_1.errorMessage)(service, "Download failed"
|
|
613
|
+
reject((0, types_1.errorMessage)(service, "Download failed"));
|
|
614
614
|
}
|
|
615
615
|
});
|
|
616
616
|
}
|
|
@@ -642,13 +642,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
642
642
|
return await client.executeQuery.call(this, credential, item, sessionKey);
|
|
643
643
|
}
|
|
644
644
|
catch (err) {
|
|
645
|
-
this.formatFail(64
|
|
645
|
+
this.formatFail(64, service, "Unable to execute query", err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
646
646
|
return Promise.reject(err);
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported"
|
|
649
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported"));
|
|
650
650
|
}
|
|
651
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials"
|
|
651
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials"));
|
|
652
652
|
}
|
|
653
653
|
async getDatabaseBatchRows(batch, ignoreErrors, sessionKey) {
|
|
654
654
|
if (this.aborted) {
|
|
@@ -674,13 +674,13 @@ class Cloud extends core_1.ClientDb {
|
|
|
674
674
|
return await client.executeBatchQuery.call(this, credential, batch, sessionKey);
|
|
675
675
|
}
|
|
676
676
|
catch (err) {
|
|
677
|
-
this.formatFail(64
|
|
677
|
+
this.formatFail(64, service, "Unable to execute query", err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
678
678
|
return Promise.reject(err);
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported"
|
|
681
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported"));
|
|
682
682
|
}
|
|
683
|
-
return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials"
|
|
683
|
+
return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials"));
|
|
684
684
|
}
|
|
685
685
|
getCredential(item, unused) {
|
|
686
686
|
const service = item.service;
|
|
@@ -708,7 +708,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
708
708
|
if ((0, types_1.isArray)(data)) {
|
|
709
709
|
for (const item of data) {
|
|
710
710
|
const service = this.hasStorage(action, item);
|
|
711
|
-
if (service && service.active) {
|
|
711
|
+
if (service && service.active) {
|
|
712
712
|
return item;
|
|
713
713
|
}
|
|
714
714
|
}
|
|
@@ -740,7 +740,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
740
740
|
}
|
|
741
741
|
}
|
|
742
742
|
catch (err) {
|
|
743
|
-
this.formatFail(64
|
|
743
|
+
this.formatFail(64, data.service, "Cloud provider not found", err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
744
744
|
}
|
|
745
745
|
return false;
|
|
746
746
|
}
|
|
@@ -755,7 +755,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
755
755
|
if (!service.startsWith('@')) {
|
|
756
756
|
result = this.settings.imports?.[service] || util_1.IMPORTS[service];
|
|
757
757
|
}
|
|
758
|
-
else if (!folder && !service.startsWith("@squared-functions/"
|
|
758
|
+
else if (!folder && !service.startsWith("@squared-functions/")) {
|
|
759
759
|
folder = 'client';
|
|
760
760
|
}
|
|
761
761
|
return (result || service) + (folder ? '/' + folder : '');
|
|
@@ -772,7 +772,7 @@ class Cloud extends core_1.ClientDb {
|
|
|
772
772
|
data.ignoreCache ?? (data.ignoreCache = true);
|
|
773
773
|
return this.getDatabaseRows(data, true);
|
|
774
774
|
});
|
|
775
|
-
return items.length === 0 ? false : this.allSettled(items, ["Execute unassigned queries"
|
|
775
|
+
return items.length === 0 ? false : this.allSettled(items, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
|
|
776
776
|
}
|
|
777
777
|
getClient(service) {
|
|
778
778
|
let client = SERVICE_CLIENT.get(service);
|
|
@@ -788,11 +788,11 @@ class Cloud extends core_1.ClientDb {
|
|
|
788
788
|
}
|
|
789
789
|
catch {
|
|
790
790
|
}
|
|
791
|
-
throw (0, types_1.errorMessage)(service, "Cloud provider not found"
|
|
791
|
+
throw (0, types_1.errorMessage)(service, "Cloud provider not found");
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
|
-
Cloud.STORE_RESULT_PARTITION_SIZE = 16
|
|
795
|
-
Cloud.STORE_RESULT_PARTITION_MULT = 2
|
|
794
|
+
Cloud.STORE_RESULT_PARTITION_SIZE = 16;
|
|
795
|
+
Cloud.STORE_RESULT_PARTITION_MULT = 2;
|
|
796
796
|
Cloud.LOG_CLOUD_FAIL = core_1.ClientDb.LOG_STYLE_FAIL;
|
|
797
797
|
Cloud.LOG_CLOUD_COMMAND = Object.freeze({ titleColor: 'blue' });
|
|
798
798
|
Cloud.LOG_CLOUD_WARN = Object.freeze({ titleColor: 'yellow' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/cloud",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
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": "BSD 3-Clause",
|
|
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.6",
|
|
24
|
+
"@e-mc/db": "0.8.6",
|
|
25
|
+
"@e-mc/types": "0.8.6",
|
|
26
26
|
"mime-types": "^2.1.35"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/util.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.hasBasicAuth = exports.getBasicAuth = exports.formatError = exports.gene
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const mime = require("mime-types");
|
|
7
|
-
const types_1 = require("
|
|
8
|
-
const util_1 = require("
|
|
7
|
+
const types_1 = require("@e-mc/types");
|
|
8
|
+
const util_1 = require("@e-mc/db/util");
|
|
9
9
|
Object.defineProperty(exports, "getBasicAuth", { enumerable: true, get: function () { return util_1.getBasicAuth; } });
|
|
10
10
|
Object.defineProperty(exports, "hasBasicAuth", { enumerable: true, get: function () { return util_1.hasBasicAuth; } });
|
|
11
11
|
exports.IMPORTS = {
|