@e-mc/cloud 0.7.1 → 0.7.3

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 CHANGED
@@ -1,11 +1,7 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2023 Sukina
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
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.
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,5 +1,7 @@
1
- ### @e-mc/cloud
1
+ # @e-mc/cloud
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever 2056
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
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("../types");
6
- const core_1 = require("../core");
7
- const util_1 = require("./util");
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 = {};
@@ -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" /* VAL_MESSAGE.COMMIT_TRANSACTION */, startTime, { type: 64 /* LOG_TYPE.CLOUD */, ...Cloud.LOG_STYLE_SUCCESS });
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 /* LOG_TYPE.CLOUD */, storage.service, ["Upload failed" /* ERR_CLOUD.UPLOAD_FAIL */, storage.bucket], (0, types_1.errorValue)("File not found" /* ERR_MESSAGE.NOTFOUND_FILE */, item.uri || item.filename || "Unknown" /* ERR_MESSAGE.UNKNOWN */), { ...Cloud.LOG_CLOUD_WARN }));
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" /* ERR_CLOUD.DELETE_BUCKET */, service + ': ' + bucket], err, { type: 64 /* LOG_TYPE.CLOUD */, startTime })));
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" /* ERR_CLOUD.POLICY_BUCKET */, params[0] + ': ' + params[2]], err, { type: 64 /* LOG_TYPE.CLOUD */, startTime })));
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" /* ERR_MESSAGE.HANDLED_REJECTION */, document.moduleName], err, { type: 64 /* LOG_TYPE.CLOUD */, startTime }));
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" /* ERR_MESSAGE.DOWNLOAD_FILE */, filename], (0, types_1.errorValue)("Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, pathname), { type: 64 /* LOG_TYPE.CLOUD */, fatal: !!active, startTime });
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 /* LOG_TYPE.CLOUD */, data.service, ["Download success" /* VAL_CLOUD.DOWNLOAD_FILE */, (0, types_1.formatSize)(size)], destUri, { ...Cloud.LOG_CLOUD_DOWNLOAD });
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" /* ERR_MESSAGE.WRITE_FILE */, path.basename(destUri)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: !!active, startTime });
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" /* ERR_CLOUD.DOWNLOAD_FAIL */, path.basename(downloadUri)], err, { type: 64 /* LOG_TYPE.CLOUD */, startTime }));
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
  }
@@ -313,7 +313,7 @@ class Cloud extends core_1.ClientDb {
313
313
  }
314
314
  }
315
315
  catch (err) {
316
- instance.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(value)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: false });
316
+ instance.writeFail(["Unable to read file", path.basename(value)], err, { type: 32, fatal: false });
317
317
  }
318
318
  }
319
319
  }
@@ -322,7 +322,7 @@ class Cloud extends core_1.ClientDb {
322
322
  for (const localUri of group) {
323
323
  const exists = this.isPath(localUri);
324
324
  if (!exists || !instance.canRead(localUri, { ownPermissionOnly: true })) {
325
- instance.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(localUri)], (0, types_1.errorValue)(exists ? "Not permitted to read file" /* ERR_MESSAGE.UNSUPPORTED_READ */ : "File not found" /* ERR_MESSAGE.NOTFOUND_FILE */, localUri), { type: 64 /* LOG_TYPE.CLOUD */, fatal: index === 0 });
325
+ 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 });
326
326
  continue;
327
327
  }
328
328
  let buffer, filename;
@@ -346,10 +346,10 @@ class Cloud extends core_1.ClientDb {
346
346
  options.contentType = contentType;
347
347
  }
348
348
  uploading.push(instance.uploadObject(service, { ...credential }, bucket, options, localUri, callback)
349
- .catch(err => instance.writeFail(["Upload failed" /* ERR_CLOUD.UPLOAD_FAIL */, path.basename(localUri)], err, { type: 64 /* LOG_TYPE.CLOUD */, fatal: index === 0 })));
349
+ .catch(err => instance.writeFail(["Upload failed", path.basename(localUri)], err, { type: 64, fatal: index === 0 })));
350
350
  }
351
351
  });
352
- instance.allSettled(uploading, [`Upload file "${contentType || "Unknown" /* ERR_MESSAGE.UNKNOWN */}"`, storage.service + ': ' + path.basename(file.localUri)]).then(() => resolve());
352
+ instance.allSettled(uploading, [`Upload file "${contentType || "Unknown"}"`, storage.service + ': ' + path.basename(file.localUri)]).then(() => resolve());
353
353
  });
354
354
  if (active) {
355
355
  tasks.push(task);
@@ -435,7 +435,7 @@ class Cloud extends core_1.ClientDb {
435
435
  }
436
436
  return super.setQueryResult(service, credential, queryString, result, sessionKey);
437
437
  }
438
- createBucket(service, credential, bucket, publicRead, options) {
438
+ async createBucket(service, credential, bucket, publicRead, options) {
439
439
  if (this.aborted) {
440
440
  return Promise.reject((0, types_1.createAbortError)());
441
441
  }
@@ -454,10 +454,10 @@ class Cloud extends core_1.ClientDb {
454
454
  return handler.call(this, credential, bucket, publicRead, options);
455
455
  }
456
456
  }
457
- return Promise.reject((0, types_1.errorMessage)(service, "Create bucket not supported" /* ERR_CLOUD.CREATE_BUCKET_SUPPORT */));
457
+ return Promise.reject((0, types_1.errorMessage)(service, "Create bucket not supported"));
458
458
  }
459
459
  catch (err) {
460
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_WARN });
460
+ this.formatMessage(64, service, ["Unable to create bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
461
461
  return Promise.reject(err);
462
462
  }
463
463
  }
@@ -465,7 +465,7 @@ class Cloud extends core_1.ClientDb {
465
465
  return Promise.reject(err);
466
466
  }
467
467
  }
468
- setBucketPolicy(service, credential, bucket, options) {
468
+ async setBucketPolicy(service, credential, bucket, options) {
469
469
  if (this.aborted) {
470
470
  return Promise.reject((0, types_1.createAbortError)());
471
471
  }
@@ -476,17 +476,17 @@ class Cloud extends core_1.ClientDb {
476
476
  return handler.call(this, credential, bucket, options);
477
477
  }
478
478
  catch (err) {
479
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_WARN });
479
+ this.formatMessage(64, service, ["Unable to update bucket policy", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
480
480
  return Promise.reject(err);
481
481
  }
482
482
  }
483
- return Promise.reject((0, types_1.errorMessage)(service, "Bucket policy not supported" /* ERR_CLOUD.BUCKET_POLICY_SUPPORT */));
483
+ return Promise.reject((0, types_1.errorMessage)(service, "Bucket policy not supported"));
484
484
  }
485
485
  catch (err) {
486
486
  return Promise.reject(err);
487
487
  }
488
488
  }
489
- setBucketWebsite(service, credential, bucket, options) {
489
+ async setBucketWebsite(service, credential, bucket, options) {
490
490
  if (this.aborted) {
491
491
  return Promise.reject((0, types_1.createAbortError)());
492
492
  }
@@ -497,22 +497,22 @@ class Cloud extends core_1.ClientDb {
497
497
  return handler.call(this, credential, bucket, options);
498
498
  }
499
499
  catch (err) {
500
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_WARN });
500
+ this.formatMessage(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
501
501
  return Promise.reject(err);
502
502
  }
503
503
  }
504
- return Promise.reject((0, types_1.errorMessage)(service, "Set bucket website not supported" /* ERR_CLOUD.BUCKET_WEBSITE_SUPPORT */));
504
+ return Promise.reject((0, types_1.errorMessage)(service, "Set bucket website not supported"));
505
505
  }
506
506
  catch (err) {
507
507
  return Promise.reject(err);
508
508
  }
509
509
  }
510
- deleteObjects(service, credential, bucket, recursive = true) {
510
+ async deleteObjects(service, credential, bucket, recursive = true) {
511
511
  if (this.aborted) {
512
512
  return Promise.reject((0, types_1.createAbortError)());
513
513
  }
514
514
  try {
515
- const errorResponse = (err) => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_WARN });
515
+ const errorResponse = (err) => this.formatMessage(64, service, ["Unable to empty bucket", bucket], err, { ...Cloud.LOG_CLOUD_WARN });
516
516
  const client = this.getClient(service);
517
517
  const handlerV2 = client.deleteObjectsV2?.bind(this);
518
518
  if (handlerV2) {
@@ -522,13 +522,13 @@ class Cloud extends core_1.ClientDb {
522
522
  if (handlerV1) {
523
523
  return handlerV1.call(this, credential, bucket, service, undefined, recursive).catch(err => errorResponse(err));
524
524
  }
525
- return Promise.reject((0, types_1.errorMessage)(service, "Delete objects not supported" /* ERR_CLOUD.DELETE_OBJECTS_SUPPORT */));
525
+ return Promise.reject((0, types_1.errorMessage)(service, "Delete objects not supported"));
526
526
  }
527
527
  catch (err) {
528
528
  return Promise.reject(err);
529
529
  }
530
530
  }
531
- uploadObject(service, credential, bucket, upload, localUri, beforeResolve) {
531
+ async uploadObject(service, credential, bucket, upload, localUri, beforeResolve) {
532
532
  if (this.aborted) {
533
533
  return Promise.reject((0, types_1.createAbortError)());
534
534
  }
@@ -537,14 +537,14 @@ class Cloud extends core_1.ClientDb {
537
537
  handler = this.getUploadHandler(service, credential).bind(this);
538
538
  }
539
539
  catch (err) {
540
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Upload function not supported" /* ERR_CLOUD.UPLOAD_SUPPORT */, bucket], localUri, { ...Cloud.LOG_CLOUD_WARN });
540
+ this.formatMessage(64, service, ["Upload function not supported", bucket], localUri, { ...Cloud.LOG_CLOUD_WARN });
541
541
  return Promise.reject(err);
542
542
  }
543
543
  return new Promise((resolve, reject) => {
544
544
  try {
545
545
  handler({ bucket, upload, buffer: upload.buffer || fs.readFileSync(localUri), localUri }, async (err, value) => {
546
546
  if (err) {
547
- reject(errorObject(err, service, "Upload failed" /* ERR_CLOUD.UPLOAD_FAIL */));
547
+ reject(errorObject(err, service, "Upload failed"));
548
548
  }
549
549
  else if (value) {
550
550
  if (beforeResolve) {
@@ -554,7 +554,7 @@ class Cloud extends core_1.ClientDb {
554
554
  resolve(value);
555
555
  }
556
556
  else {
557
- reject((0, types_1.errorMessage)(service, "Upload failed" /* ERR_CLOUD.UPLOAD_FAIL */));
557
+ reject((0, types_1.errorMessage)(service, "Upload failed"));
558
558
  }
559
559
  });
560
560
  }
@@ -563,7 +563,7 @@ class Cloud extends core_1.ClientDb {
563
563
  }
564
564
  });
565
565
  }
566
- downloadObject(service, credential, bucket, download, beforeResolve) {
566
+ async downloadObject(service, credential, bucket, download, beforeResolve) {
567
567
  if (this.aborted) {
568
568
  return Promise.reject((0, types_1.createAbortError)());
569
569
  }
@@ -575,14 +575,14 @@ class Cloud extends core_1.ClientDb {
575
575
  handler = this.getDownloadHandler(service, credential).bind(this);
576
576
  }
577
577
  catch (err) {
578
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Download function not supported" /* ERR_CLOUD.DOWNLOAD_SUPPORT */, bucket], Cloud.joinPath(download.pathname, download.filename), { ...Cloud.LOG_CLOUD_WARN });
578
+ this.formatMessage(64, service, ["Download function not supported", bucket], Cloud.joinPath(download.pathname, download.filename), { ...Cloud.LOG_CLOUD_WARN });
579
579
  return Promise.reject(err);
580
580
  }
581
581
  return new Promise((resolve, reject) => {
582
582
  try {
583
583
  handler({ bucket, download }, async (err, value) => {
584
584
  if (err) {
585
- reject(errorObject(err, service, "Download failed" /* ERR_CLOUD.DOWNLOAD_FAIL */));
585
+ reject(errorObject(err, service, "Download failed"));
586
586
  }
587
587
  else if (value) {
588
588
  if (beforeResolve) {
@@ -598,7 +598,7 @@ class Cloud extends core_1.ClientDb {
598
598
  resolve(value);
599
599
  }
600
600
  else {
601
- reject((0, types_1.errorMessage)(service, "Download failed" /* ERR_CLOUD.DOWNLOAD_FAIL */));
601
+ reject((0, types_1.errorMessage)(service, "Download failed"));
602
602
  }
603
603
  });
604
604
  }
@@ -630,13 +630,13 @@ class Cloud extends core_1.ClientDb {
630
630
  return await client.executeQuery.call(this, credential, item, sessionKey);
631
631
  }
632
632
  catch (err) {
633
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, "Unable to execute query" /* ERR_DB.EXEC_QUERY */, err, { ...Cloud.LOG_CLOUD_FAIL });
633
+ this.formatFail(64, service, "Unable to execute query", err, { ...Cloud.LOG_CLOUD_FAIL });
634
634
  return Promise.reject(err);
635
635
  }
636
636
  }
637
- return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported" /* ERR_CLOUD.EXECUTE_QUERY_SUPPORT */));
637
+ return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported"));
638
638
  }
639
- return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials" /* ERR_DB.CREDENTIALS */));
639
+ return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials"));
640
640
  }
641
641
  async getDatabaseBatchRows(batch, ignoreErrors, sessionKey) {
642
642
  if (this.aborted) {
@@ -662,13 +662,13 @@ class Cloud extends core_1.ClientDb {
662
662
  return await client.executeBatchQuery.call(this, credential, batch, sessionKey);
663
663
  }
664
664
  catch (err) {
665
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, "Unable to execute query" /* ERR_DB.EXEC_QUERY */, err, { ...Cloud.LOG_CLOUD_FAIL });
665
+ this.formatFail(64, service, "Unable to execute query", err, { ...Cloud.LOG_CLOUD_FAIL });
666
666
  return Promise.reject(err);
667
667
  }
668
668
  }
669
- return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported" /* ERR_CLOUD.EXECUTE_QUERY_SUPPORT */));
669
+ return Promise.reject((0, types_1.errorMessage)(service, "Execute query not supported"));
670
670
  }
671
- return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials" /* ERR_DB.CREDENTIALS */));
671
+ return Promise.reject((0, types_1.errorMessage)(service, "Invalid credentials"));
672
672
  }
673
673
  getCredential(item, unused) {
674
674
  const service = item.service;
@@ -696,7 +696,7 @@ class Cloud extends core_1.ClientDb {
696
696
  if ((0, types_1.isArray)(data)) {
697
697
  for (const item of data) {
698
698
  const service = this.hasStorage(action, item);
699
- if (service && service.active) { // eslint-disable-line @typescript-eslint/prefer-optional-chain
699
+ if (service && service.active) {
700
700
  return item;
701
701
  }
702
702
  }
@@ -728,7 +728,7 @@ class Cloud extends core_1.ClientDb {
728
728
  }
729
729
  }
730
730
  catch (err) {
731
- this.formatFail(64 /* LOG_TYPE.CLOUD */, data.service, "Cloud provider not found" /* ERR_CLOUD.PROVIDER_NOTFOUND */, err, { ...Cloud.LOG_CLOUD_FAIL });
731
+ this.formatFail(64, data.service, "Cloud provider not found", err, { ...Cloud.LOG_CLOUD_FAIL });
732
732
  }
733
733
  return false;
734
734
  }
@@ -740,10 +740,10 @@ class Cloud extends core_1.ClientDb {
740
740
  }
741
741
  resolveService(service, folder) {
742
742
  let result;
743
- if (service[0] !== '@') {
743
+ if (!service.startsWith('@')) {
744
744
  result = this.settings.imports?.[service] || util_1.IMPORTS[service];
745
745
  }
746
- else if (!folder && !service.startsWith("@squared-functions/" /* NAMESPACE.SQUARED_FUNCTIONS */)) {
746
+ else if (!folder && !service.startsWith("@squared-functions/")) {
747
747
  folder = 'client';
748
748
  }
749
749
  return (result || service) + (folder ? '/' + folder : '');
@@ -756,11 +756,11 @@ class Cloud extends core_1.ClientDb {
756
756
  if (this.aborted) {
757
757
  return Promise.reject((0, types_1.createAbortError)());
758
758
  }
759
- const items = this.pending.filter(item => !item.document).map(data => {
759
+ const items = this.pending.filter(item => !item.document).map(async (data) => {
760
760
  data.ignoreCache ?? (data.ignoreCache = true);
761
761
  return this.getDatabaseRows(data, true);
762
762
  });
763
- return items.length === 0 ? Promise.resolve(false) : this.allSettled(items, ["Execute unassigned queries" /* VAL_DB.EXEC_QUERYUNASSIGNED */, this.moduleName]).then(result => result.length > 0).catch(() => false);
763
+ return items.length === 0 ? Promise.resolve(false) : this.allSettled(items, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
764
764
  }
765
765
  getClient(service) {
766
766
  let client = SERVICE_CLIENT.get(service);
@@ -776,11 +776,11 @@ class Cloud extends core_1.ClientDb {
776
776
  }
777
777
  catch {
778
778
  }
779
- throw (0, types_1.errorMessage)(service, "Cloud provider not found" /* ERR_CLOUD.PROVIDER_NOTFOUND */);
779
+ throw (0, types_1.errorMessage)(service, "Cloud provider not found");
780
780
  }
781
781
  }
782
- Cloud.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.CLOUD_PARTITION_SIZE */;
783
- Cloud.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.CLOUD_PARTITION_MULT */;
782
+ Cloud.STORE_RESULT_PARTITION_SIZE = 16;
783
+ Cloud.STORE_RESULT_PARTITION_MULT = 2;
784
784
  Cloud.LOG_CLOUD_FAIL = core_1.ClientDb.LOG_STYLE_FAIL;
785
785
  Cloud.LOG_CLOUD_COMMAND = Object.freeze({ titleColor: 'blue' });
786
786
  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.7.1",
3
+ "version": "0.7.3",
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": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.7.1",
24
- "@e-mc/db": "0.7.1",
25
- "@e-mc/types": "0.7.1"
23
+ "@e-mc/core": "0.7.3",
24
+ "@e-mc/db": "0.7.3",
25
+ "@e-mc/types": "0.7.3"
26
26
  }
27
27
  }
package/util.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasBasicAuth = exports.getBasicAuth = exports.formatError = exports.generateFilename = exports.readableAsBuffer = exports.IMPORTS = void 0;
4
4
  const path = require("path");
5
- const types_1 = require("../types");
6
- const util_1 = require("../db/util");
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
9
  exports.IMPORTS = {
@@ -18,7 +18,7 @@ exports.IMPORTS = {
18
18
  "minio": "@pi-r/minio",
19
19
  "oci": "@pi-r/oci"
20
20
  };
21
- function readableAsBuffer(stream) {
21
+ async function readableAsBuffer(stream) {
22
22
  return new Promise((resolve, reject) => {
23
23
  let result = null;
24
24
  stream
@@ -35,9 +35,10 @@ function generateFilename(filename) {
35
35
  let basename, suffix;
36
36
  return (i) => {
37
37
  if (i === 1) {
38
- const j = filename.indexOf('.');
38
+ const type = /\.[a-z0-9]+\.[a-z0-9]+$/i.exec(filename);
39
+ const j = type ? type.index : filename.lastIndexOf('.');
39
40
  if (j !== -1) {
40
- const match = /^([\S\s]+?)_(\d+)$/.exec(basename = filename.substring(0, j));
41
+ const match = /^(.+)_(\d+)$/.exec(basename = filename.substring(0, j));
41
42
  if (match) {
42
43
  basename = match[1];
43
44
  i = parseInt(match[2]) + 1;