@e-mc/cloud 0.10.5 → 0.11.0

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
@@ -8,4 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,
8
8
 
9
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
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.
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,7 @@
1
1
  # @e-mc/cloud
2
2
 
3
- * NodeJS 16
4
- * ES2020
3
+ * NodeJS 16 LTS
4
+ * ES2021
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,12 +9,12 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.10.5/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.11.0/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IHost, IScopeOrigin } from "./index";
16
16
  import type { ExternalAsset } from "./asset";
17
- import type { BucketWebsiteOptions, CloudDatabase, CloudFeatures, CloudFunctions, CloudService, CloudStorage, CloudStorageDownload, CloudStorageUpload, UploadAssetOptions } from "./cloud";
17
+ import type { BucketWebsiteOptions, CloudDatabase, CloudFeatures, CloudFunctions, CloudService, CloudStorage, CloudStorageDownload, CloudStorageUpload, DeleteObjectsOptions, UploadAssetOptions } from "./cloud";
18
18
  import type { ClientDbConstructor, IClientDb } from "./core";
19
19
  import type { BatchQueryResult, QueryResult } from "./db";
20
20
  import type { LogMessageOptions } from "./logger";
@@ -29,7 +29,8 @@ interface ICloud extends IClientDb<IHost, CloudModule, CloudDatabase, CloudServi
29
29
  setBucketPolicy(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
30
30
  setBucketTagging(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
31
31
  setBucketWebsite(service: string, credential: unknown, bucket: string, options: BucketWebsiteOptions): Promise<boolean>;
32
- deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean): Promise<void>;
32
+ deleteObjects(service: string, credential: unknown, bucket: string, options: DeleteObjectsOptions): Promise<void>;
33
+ deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean | DeleteObjectsOptions): Promise<void>;
33
34
  uploadObject(service: string, credential: unknown, bucket: string, upload: CloudStorageUpload, localUri: string, beforeResolve?: ((value: string) => Promise<void> | void)): Promise<string>;
34
35
  downloadObject(service: string, credential: unknown, bucket: string, download: CloudStorageDownload, beforeResolve?: ((value: Buffer | string | null) => Promise<string | undefined> | void)): Promise<Buffer | string>;
35
36
  getStorage(action: CloudFunctions, data: CloudStorage[] | undefined): CloudStorage | undefined;
@@ -76,13 +77,17 @@ interface ICloudServiceClient {
76
77
  validateDatabase?(credential: unknown, data?: CloudService): boolean;
77
78
  createStorageClient?(this: IModule, credential: unknown, service?: string): unknown;
78
79
  createDatabaseClient?(this: IModule, credential: unknown, data?: CloudService): unknown;
80
+ /** @deprecated */
79
81
  createBucket?(this: IModule, credential: unknown, bucket: string, publicRead?: boolean, service?: string, sdk?: string): Promise<boolean>;
80
82
  createBucketV2?(this: IModule, credential: unknown, bucket: string, acl?: unknown, options?: unknown, service?: string, sdk?: string): Promise<boolean>;
81
83
  setBucketPolicy?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
82
84
  setBucketTagging?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
83
85
  setBucketWebsite?(this: IModule, credential: unknown, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise<boolean>;
86
+ /** @deprecated */
84
87
  deleteObjects?(this: IModule, credential: unknown, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise<void>;
88
+ /** @deprecated */
85
89
  deleteObjectsV2?(this: IModule, credential: unknown, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise<void>;
90
+ deleteObjectsV3?(this: IModule, credential: U, bucket: string, options?: DeleteObjectsOptions, service?: string, sdk?: string): Promise<void>;
86
91
  executeQuery?(this: ICloud, credential: unknown, data: CloudDatabase, sessionKey?: string): Promise<QueryResult>;
87
92
  executeBatchQuery?(this: ICloud, credential: unknown, batch: CloudDatabase[], sessionKey?: string): Promise<BatchQueryResult>;
88
93
  }
@@ -102,9 +107,7 @@ interface CloudModule {
102
107
  "aws-v3"?: CloudStoredCredentials;
103
108
  azure?: CloudStoredCredentials; // az
104
109
  gcp?: CloudStoredCredentials; // gcloud
105
- ibm?: CloudStoredCredentials;
106
110
  oci?: CloudStoredCredentials;
107
- minio?: CloudStoredCredentials;
108
111
  settings?: {
109
112
  broadcast_id?: string | string[];
110
113
  users?: Record<string, Record<string, unknown>>;
@@ -118,9 +121,7 @@ interface CloudModule {
118
121
  "aws-v3"?: CloudServiceOptions;
119
122
  azure?: CloudServiceOptions;
120
123
  gcp?: CloudServiceOptions;
121
- ibm?: CloudServiceOptions;
122
124
  oci?: CloudServiceOptions;
123
- minio?: CloudServiceOptions;
124
125
  };
125
126
  permission?: PermittedDirectories;
126
127
  }
@@ -174,13 +175,13 @@ const rows = await instance.getDatabaseRows({ service: "aws-v3", credential: "ma
174
175
 
175
176
  ## References
176
177
 
177
- - https://www.unpkg.com/@e-mc/types@0.10.5/lib/asset.d.ts
178
- - https://www.unpkg.com/@e-mc/types@0.10.5/lib/cloud.d.ts
179
- - https://www.unpkg.com/@e-mc/types@0.10.5/lib/core.d.ts
180
- - https://www.unpkg.com/@e-mc/types@0.10.5/lib/db.d.ts
181
- - https://www.unpkg.com/@e-mc/types@0.10.5/lib/logger.d.ts
182
- - https://www.unpkg.com/@e-mc/types@0.10.5/lib/settings.d.ts
178
+ - https://www.unpkg.com/@e-mc/types@0.11.0/lib/asset.d.ts
179
+ - https://www.unpkg.com/@e-mc/types@0.11.0/lib/cloud.d.ts
180
+ - https://www.unpkg.com/@e-mc/types@0.11.0/lib/core.d.ts
181
+ - https://www.unpkg.com/@e-mc/types@0.11.0/lib/db.d.ts
182
+ - https://www.unpkg.com/@e-mc/types@0.11.0/lib/logger.d.ts
183
+ - https://www.unpkg.com/@e-mc/types@0.11.0/lib/settings.d.ts
183
184
 
184
185
  ## LICENSE
185
186
 
186
- BSD 3-Clause
187
+ BSD 3-Clause
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- const path = require("path");
3
- const fs = require("fs");
4
- const crypto = require("crypto");
2
+ const path = require("node:path");
3
+ const fs = require("node:fs");
4
+ const crypto = require("node:crypto");
5
5
  const types_1 = require("@e-mc/types");
6
6
  const core_1 = require("@e-mc/core");
7
7
  const SERVICE_CLIENT = new Map();
@@ -80,7 +80,7 @@ class Cloud extends core_1.ClientDb {
80
80
  const bucketPolicy = {};
81
81
  const bucketTagging = {};
82
82
  const rawFiles = [];
83
- const startTime = process.hrtime();
83
+ const startTime = process.hrtime.bigint();
84
84
  let tasks = [], downloadMap;
85
85
  if (await instance.commit()) {
86
86
  instance.writeTimeElapsed(instance.moduleName, "Transactions were committed", startTime, { type: 64, ...Cloud.LOG_STYLE_SUCCESS });
@@ -90,7 +90,7 @@ class Cloud extends core_1.ClientDb {
90
90
  }
91
91
  for (const item of this.assets) {
92
92
  const cloudStorage = item.cloudStorage;
93
- if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item.flags)) {
93
+ if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item)) {
94
94
  if (item.invalid) {
95
95
  cloudStorage.forEach(storage => {
96
96
  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 });
@@ -120,10 +120,14 @@ class Cloud extends core_1.ClientDb {
120
120
  const service = bucketDelete[name] ||= {};
121
121
  const items = service[bucket];
122
122
  if (!items) {
123
- service[bucket] = [{ ...credential }, admin.recursive];
123
+ let options = (0, types_1.isObject)(admin.emptyBucket) ? admin.emptyBucket : undefined;
124
+ if (typeof admin.recursive === 'boolean') {
125
+ (options ||= {}).recursive = admin.recursive;
126
+ }
127
+ service[bucket] = [{ ...credential }, options];
124
128
  }
125
129
  else if (admin.recursive === false) {
126
- items[1] = false;
130
+ (items[1] ||= {}).recursive = false;
127
131
  }
128
132
  }
129
133
  if (configBucket) {
@@ -151,8 +155,8 @@ class Cloud extends core_1.ClientDb {
151
155
  for (const service in bucketDelete) {
152
156
  const map = bucketDelete[service];
153
157
  for (const bucket in map) {
154
- const [credential, recursive] = map[bucket];
155
- tasks.push(instance.deleteObjects(service, credential, bucket, recursive).catch((err) => {
158
+ const [credential, options] = map[bucket];
159
+ tasks.push(instance.deleteObjects(service, credential, bucket, options).catch((err) => {
156
160
  instance.writeFail(["Unable to empty bucket", service + ': ' + bucket], err, { type: 64, startTime });
157
161
  }));
158
162
  }
@@ -223,7 +227,7 @@ class Cloud extends core_1.ClientDb {
223
227
  }
224
228
  for (const item of this.assets) {
225
229
  const cloudStorage = item.cloudStorage;
226
- if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item.flags)) {
230
+ if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item)) {
227
231
  for (const data of cloudStorage) {
228
232
  if (!instance.hasStorage('download', data)) {
229
233
  continue;
@@ -280,7 +284,7 @@ class Cloud extends core_1.ClientDb {
280
284
  }
281
285
  const items = Array.from(pending);
282
286
  let result;
283
- for (let i = 0, length = items.length, size, copy; i < length; ++i) {
287
+ for (let i = 0, length = items.length, size = 0, copy = false; i < length; ++i) {
284
288
  const destUri = items[i];
285
289
  try {
286
290
  if (typeof value === 'string') {
@@ -453,7 +457,7 @@ class Cloud extends core_1.ClientDb {
453
457
  const storage = [];
454
458
  for (const item of assets) {
455
459
  const cloudStorage = item.cloudStorage;
456
- if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item.flags)) {
460
+ if ((0, types_1.isArray)(cloudStorage) && !(0, types_1.ignoreFlag)(item)) {
457
461
  for (const data of cloudStorage) {
458
462
  const upload = data.upload;
459
463
  if (upload) {
@@ -594,14 +598,21 @@ class Cloud extends core_1.ClientDb {
594
598
  }
595
599
  throw (0, types_1.errorMessage)(service, "Set bucket website not supported");
596
600
  }
597
- async deleteObjects(service, credential, bucket, recursive = true) {
601
+ async deleteObjects(service, credential, bucket, options = true) {
598
602
  if (this.aborted) {
599
603
  return (0, types_1.createAbortError)(true);
600
604
  }
601
605
  const client = this.getClient(service);
606
+ const handlerV3 = client.deleteObjectsV3?.bind(this);
607
+ if (handlerV3) {
608
+ return handlerV3.call(this, credential, bucket, typeof options === 'boolean' ? { recursive: options } : options, service).catch((err) => {
609
+ errorResponse(this, service, bucket, err);
610
+ });
611
+ }
612
+ const recursive = (0, types_1.isObject)(options) ? options.recursive : options;
602
613
  const handlerV2 = client.deleteObjectsV2?.bind(this);
603
614
  if (handlerV2) {
604
- return handlerV2.call(this, credential, bucket, recursive, service).catch((err) => {
615
+ return handlerV2.call(this, credential, bucket, recursive ?? true, service).catch((err) => {
605
616
  errorResponse(this, service, bucket, err);
606
617
  });
607
618
  }
@@ -752,7 +763,7 @@ class Cloud extends core_1.ClientDb {
752
763
  }
753
764
  getCredential(item, unused) {
754
765
  const service = item.service;
755
- let credential = item.credential, stored;
766
+ let credential = item.credential, stored = false;
756
767
  if (typeof credential === 'string') {
757
768
  const settings = this.getSettings(service);
758
769
  if ((0, types_1.isPlainObject)(settings)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/cloud",
3
- "version": "0.10.5",
3
+ "version": "0.11.0",
4
4
  "description": "Cloud constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.10.5",
24
- "@e-mc/db": "0.10.5",
25
- "@e-mc/types": "0.10.5",
23
+ "@e-mc/core": "0.11.0",
24
+ "@e-mc/db": "0.11.0",
25
+ "@e-mc/types": "0.11.0",
26
26
  "mime-types": "^2.1.35"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ICloud, IFileManager, IModule, IScopeOrigin } from '@e-mc/types/lib';
2
- import type { BucketWebsiteOptions, CloudAsset, CloudDatabase, CloudService, CloudStorageUpload, DownloadData, UploadData } from '@e-mc/types/lib/cloud';
2
+ import type { BucketWebsiteOptions, CloudAsset, CloudDatabase, CloudService, CloudStorageUpload, DeleteObjectsOptions, DownloadData, UploadData } from '@e-mc/types/lib/cloud';
3
3
  import type { BatchQueryResult, QueryResult } from '@e-mc/types/lib/db';
4
4
 
5
5
  export interface ICloudServiceClient<T extends CloudDatabase = CloudDatabase, U = unknown, V = unknown> {
@@ -20,7 +20,9 @@ export interface ICloudServiceClient<T extends CloudDatabase = CloudDatabase, U
20
20
  setBucketWebsite?(this: IModule, credential: U, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise<boolean>;
21
21
  /** @deprecated */
22
22
  deleteObjects?(this: IModule, credential: U, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise<void>;
23
+ /** @deprecated */
23
24
  deleteObjectsV2?(this: IModule, credential: U, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise<void>;
25
+ deleteObjectsV3?(this: IModule, credential: U, bucket: string, options?: DeleteObjectsOptions, service?: string, sdk?: string): Promise<void>;
24
26
  executeQuery?(this: ICloud, credential: V, data: T, sessionKey?: string): Promise<QueryResult>;
25
27
  executeBatchQuery?(this: ICloud, credential: V, batch: T[], sessionKey?: string): Promise<BatchQueryResult>;
26
28
  }
@@ -32,6 +34,6 @@ export interface CloudScopeOrigin<T extends IFileManager<U>, U extends CloudAsse
32
34
 
33
35
  export type ServiceHost<T, U = unknown> = (this: IModule, credential: U, service?: string, sdk?: string) => T;
34
36
  export type UploadCallback = (data: UploadData, callback: (err: unknown, value?: string) => void) => void;
35
- export type DownloadCallback = (data: DownloadData, callback: (err: unknown, value?: Null<string | Buffer>) => void) => void;
37
+ export type DownloadCallback = (data: DownloadData, callback: (err: unknown, value?: string | Buffer | null) => void) => void;
36
38
  export type UploadHost = ServiceHost<UploadCallback>;
37
39
  export type DownloadHost = ServiceHost<DownloadCallback>;
package/util.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { UploadContent } from '@e-mc/types/lib/cloud';
2
2
  import type { AuthValue } from '@e-mc/types/lib/http';
3
3
 
4
- import type { Readable } from 'stream';
4
+ import type { Readable } from 'node:stream';
5
5
 
6
6
  declare namespace util {
7
7
  /** @deprecated Types.IMPORT_MAP */
package/util.js CHANGED
@@ -4,9 +4,9 @@ exports.readableAsBuffer = readableAsBuffer;
4
4
  exports.createKeyAndBody = createKeyAndBody;
5
5
  exports.generateFilename = generateFilename;
6
6
  exports.formatError = formatError;
7
- const path = require("path");
8
- const fs = require("fs");
9
- const stream = require("stream");
7
+ const path = require("node:path");
8
+ const fs = require("node:fs");
9
+ const stream = require("node:stream");
10
10
  const mime = require("mime-types");
11
11
  const types_1 = require("@e-mc/types");
12
12
  Object.defineProperty(exports, "IMPORTS", { enumerable: true, get: function () { return types_1.IMPORT_MAP; } });
@@ -25,9 +25,7 @@ async function readableAsBuffer(from) {
25
25
  .on('end', () => {
26
26
  resolve(result);
27
27
  })
28
- .on('error', err => {
29
- reject(err);
30
- })
28
+ .on('error', reject)
31
29
  .read();
32
30
  });
33
31
  }