@e-mc/cloud 0.9.9 → 0.9.11

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,11 @@
1
- Copyright 2024 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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
-
1
+ Copyright 2024 An Pham
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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
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,186 +1,186 @@
1
- # @e-mc/cloud
2
-
3
- * NodeJS 16
4
- * ES2020
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.9/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, UploadAssetOptions } 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 { CloudAuthSettings, CloudModule, CloudServiceOptions, CloudSettings, DbCoerceSettings } from "./settings";
22
-
23
- interface ICloud extends IClientDb<IHost, CloudModule, CloudDatabase, CloudServiceOptions, DbCoerceSettings & CloudAuthSettings> {
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
- setBucketTagging(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
31
- setBucketWebsite(service: string, credential: unknown, bucket: string, options: BucketWebsiteOptions): Promise<boolean>;
32
- deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean): Promise<void>;
33
- uploadObject(service: string, credential: unknown, bucket: string, upload: CloudStorageUpload, localUri: string, beforeResolve?: ((value: string) => Promise<void> | void)): Promise<string>;
34
- downloadObject(service: string, credential: unknown, bucket: string, download: CloudStorageDownload, beforeResolve?: ((value: Buffer | string | null) => Promise<string | undefined> | void)): Promise<Buffer | string>;
35
- getStorage(action: CloudFunctions, data: CloudStorage[] | undefined): CloudStorage | undefined;
36
- hasStorage(action: CloudFunctions, storage: CloudStorage): CloudStorageUpload | false;
37
- getDatabaseRows(item: CloudDatabase, ignoreErrors: boolean, sessionKey?: string): Promise<QueryResult>;
38
- getDatabaseRows(item: CloudDatabase, sessionKey?: string): Promise<QueryResult>;
39
- getDatabaseBatchRows(batch: CloudDatabase[], ignoreErrors: boolean, sessionKey?: string): Promise<BatchQueryResult>;
40
- getDatabaseBatchRows(batch: CloudDatabase[], sessionKey?: string): Promise<BatchQueryResult>;
41
- hasCredential(feature: CloudFeatures, data: CloudService, credential?: unknown): boolean;
42
- getCredential(item: CloudService, unused?: boolean): Record<string | number | symbol, unknown>;
43
- getSettings(service: string): Record<string, unknown> | undefined;
44
- settingsOf(service: string, name: "coerce", component: keyof DbCoerceSettings): unknown;
45
- settingsOf(service: string, name: "auth", component: keyof CloudAuthSettings): unknown;
46
- getUploadHandler(service: string, credential: unknown): (...args: unknown[]) => void;
47
- getDownloadHandler(service: string, credential: unknown): (...args: unknown[]) => void;
48
- resolveService(service: string, folder?: string): string;
49
- get settings(): CloudSettings;
50
- }
51
-
52
- interface CloudConstructor extends ClientDbConstructor<IHost> {
53
- LOG_CLOUD_FAIL: LogMessageOptions;
54
- LOG_CLOUD_COMMAND: LogMessageOptions;
55
- LOG_CLOUD_WARN: LogMessageOptions;
56
- LOG_CLOUD_UPLOAD: LogMessageOptions;
57
- LOG_CLOUD_DOWNLOAD: LogMessageOptions;
58
- LOG_CLOUD_DELETE: LogMessageOptions;
59
- LOG_CLOUD_DELAYED: LogMessageOptions;
60
- finalize(this: IHost, instance: ICloud): Promise<unknown>;
61
- uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, options: UploadAssetOptions): Promise<unknown>[];
62
- uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, ignoreProcess: boolean): Promise<unknown>[];
63
- uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, contentType?: string, ignoreProcess?: boolean): Promise<unknown>[];
64
- sanitizeAssets(assets: ExternalAsset[]): ExternalAsset[];
65
- readonly prototype: ICloud;
66
- new(module?: CloudModule, database?: CloudDatabase[], ...args: unknown[]): ICloud;
67
- }
68
-
69
- interface ICloudServiceClient {
70
- CLOUD_SERVICE_NAME: string;
71
- CLOUD_UPLOAD_DISK?: boolean;
72
- CLOUD_UPLOAD_STREAM?: boolean;
73
- CLOUD_UPLOAD_CHUNK?: boolean;
74
- CLOUD_DOWNLOAD_CHUNK?: boolean;
75
- validateStorage?(credential: unknown, data?: CloudService): boolean;
76
- validateDatabase?(credential: unknown, data?: CloudService): boolean;
77
- createStorageClient?(this: IModule, credential: unknown, service?: string): unknown;
78
- createDatabaseClient?(this: IModule, credential: unknown, data?: CloudService): unknown;
79
- createBucket?(this: IModule, credential: unknown, bucket: string, publicRead?: boolean, service?: string, sdk?: string): Promise<boolean>;
80
- createBucketV2?(this: IModule, credential: unknown, bucket: string, acl?: unknown, options?: unknown, service?: string, sdk?: string): Promise<boolean>;
81
- setBucketPolicy?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
82
- setBucketTagging?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
83
- setBucketWebsite?(this: IModule, credential: unknown, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise<boolean>;
84
- deleteObjects?(this: IModule, credential: unknown, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise<void>;
85
- deleteObjectsV2?(this: IModule, credential: unknown, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise<void>;
86
- executeQuery?(this: ICloud, credential: unknown, data: CloudDatabase, sessionKey?: string): Promise<QueryResult>;
87
- executeBatchQuery?(this: ICloud, credential: unknown, batch: CloudDatabase[], sessionKey?: string): Promise<BatchQueryResult>;
88
- }
89
- ```
90
-
91
- ## Settings
92
-
93
- ```typescript
94
- import type { PermittedDirectories } from "./core";
95
- import type { CloudServiceOptions, DbSourceOptions, PurgeComponent } from "./settings";
96
-
97
- interface CloudModule {
98
- // handler: "@e-mc/cloud";
99
- extensions?: string[];
100
- atlas?: CloudStoredCredentials;
101
- aws?: CloudStoredCredentials;
102
- "aws-v3"?: CloudStoredCredentials;
103
- azure?: CloudStoredCredentials; // az
104
- gcp?: CloudStoredCredentials; // gcloud
105
- ibm?: CloudStoredCredentials;
106
- oci?: CloudStoredCredentials;
107
- minio?: CloudStoredCredentials;
108
- settings?: {
109
- broadcast_id?: string | string[];
110
- users?: Record<string, Record<string, unknown>>;
111
- cache_dir?: string;
112
- session_expires?: number;
113
- user_key?: Record<string, DbSourceOptions>;
114
- imports?: StringMap;
115
- purge?: PurgeComponent;
116
- atlas?: CloudServiceOptions;
117
- aws?: CloudServiceOptions;
118
- "aws-v3"?: CloudServiceOptions;
119
- azure?: CloudServiceOptions;
120
- gcp?: CloudServiceOptions;
121
- ibm?: CloudServiceOptions;
122
- oci?: CloudServiceOptions;
123
- minio?: CloudServiceOptions;
124
- };
125
- permission?: PermittedDirectories;
126
- }
127
-
128
- type CloudStoredCredentials = Record<string, Record<string, unknown>>;
129
- ```
130
-
131
- ### Example usage
132
-
133
- ```javascript
134
- const Cloud = require("@e-mc/cloud"); // Using @pi-r/aws
135
-
136
- const instance = new Cloud({
137
- aws: {
138
- main: {
139
- accessKeyId: "**********",
140
- secretAccessKey: "**********"
141
- }
142
- },
143
- "aws-v3": {
144
- main: {
145
- credentials: {
146
- accessKeyId: "**********",
147
- secretAccessKey: "**********",
148
- region: "ap-northeast-1"
149
- }
150
- }
151
- }
152
- });
153
- // instance.host = new Host();
154
- instance.init();
155
-
156
- const options = {
157
- contentType: "application/tar",
158
- acl: "authenticated-read",
159
- chunkSize: "8mb",
160
- overwrite: false, // Default
161
- tags: { key_1: "value", key_2: "value" }
162
- };
163
- Promise.all([
164
- // nodejs-001/archive.tar
165
- instance.uploadObject("aws", "main", "nodejs-001", options, "/tmp/archive.tar"),
166
- // nodejs-001/2024/01-01.tar
167
- instance.uploadObject("aws", "main", "nodejs-001", { ...options, publicRead: true, pathname: "2024", filename: "01-01.tar" }, "/tmp/archive.tar"),
168
- // nodejs-001/archive_1.tar
169
- instance.uploadObject("aws", { accessKeyId: "*****", secretAccessKey: "*****" }, "nodejs-001", { overwrite: false }, "/tmp/archive.tar")
170
- ]);
171
-
172
- const rows = await instance.getDatabaseRows({ service: "aws-v3", credential: "main", table: "demo", key: { id: 1 } });
173
- ```
174
-
175
- ## References
176
-
177
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/asset.d.ts
178
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/cloud.d.ts
179
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/core.d.ts
180
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/db.d.ts
181
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/logger.d.ts
182
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/settings.d.ts
183
-
184
- ## LICENSE
185
-
1
+ # @e-mc/cloud
2
+
3
+ * NodeJS 16
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.11/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, UploadAssetOptions } 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 { CloudAuthSettings, CloudModule, CloudServiceOptions, CloudSettings, DbCoerceSettings } from "./settings";
22
+
23
+ interface ICloud extends IClientDb<IHost, CloudModule, CloudDatabase, CloudServiceOptions, DbCoerceSettings & CloudAuthSettings> {
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
+ setBucketTagging(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
31
+ setBucketWebsite(service: string, credential: unknown, bucket: string, options: BucketWebsiteOptions): Promise<boolean>;
32
+ deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean): Promise<void>;
33
+ uploadObject(service: string, credential: unknown, bucket: string, upload: CloudStorageUpload, localUri: string, beforeResolve?: ((value: string) => Promise<void> | void)): Promise<string>;
34
+ downloadObject(service: string, credential: unknown, bucket: string, download: CloudStorageDownload, beforeResolve?: ((value: Buffer | string | null) => Promise<string | undefined> | void)): Promise<Buffer | string>;
35
+ getStorage(action: CloudFunctions, data: CloudStorage[] | undefined): CloudStorage | undefined;
36
+ hasStorage(action: CloudFunctions, storage: CloudStorage): CloudStorageUpload | false;
37
+ getDatabaseRows(item: CloudDatabase, ignoreErrors: boolean, sessionKey?: string): Promise<QueryResult>;
38
+ getDatabaseRows(item: CloudDatabase, sessionKey?: string): Promise<QueryResult>;
39
+ getDatabaseBatchRows(batch: CloudDatabase[], ignoreErrors: boolean, sessionKey?: string): Promise<BatchQueryResult>;
40
+ getDatabaseBatchRows(batch: CloudDatabase[], sessionKey?: string): Promise<BatchQueryResult>;
41
+ hasCredential(feature: CloudFeatures, data: CloudService, credential?: unknown): boolean;
42
+ getCredential(item: CloudService, unused?: boolean): Record<string | number | symbol, unknown>;
43
+ getSettings(service: string): Record<string, unknown> | undefined;
44
+ settingsOf(service: string, name: "coerce", component: keyof DbCoerceSettings): unknown;
45
+ settingsOf(service: string, name: "auth", component: keyof CloudAuthSettings): unknown;
46
+ getUploadHandler(service: string, credential: unknown): (...args: unknown[]) => void;
47
+ getDownloadHandler(service: string, credential: unknown): (...args: unknown[]) => void;
48
+ resolveService(service: string, folder?: string): string;
49
+ get settings(): CloudSettings;
50
+ }
51
+
52
+ interface CloudConstructor extends ClientDbConstructor<IHost> {
53
+ LOG_CLOUD_FAIL: LogMessageOptions;
54
+ LOG_CLOUD_COMMAND: LogMessageOptions;
55
+ LOG_CLOUD_WARN: LogMessageOptions;
56
+ LOG_CLOUD_UPLOAD: LogMessageOptions;
57
+ LOG_CLOUD_DOWNLOAD: LogMessageOptions;
58
+ LOG_CLOUD_DELETE: LogMessageOptions;
59
+ LOG_CLOUD_DELAYED: LogMessageOptions;
60
+ finalize(this: IHost, instance: ICloud): Promise<unknown>;
61
+ uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, options: UploadAssetOptions): Promise<unknown>[];
62
+ uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, ignoreProcess: boolean): Promise<unknown>[];
63
+ uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, contentType?: string, ignoreProcess?: boolean): Promise<unknown>[];
64
+ sanitizeAssets(assets: ExternalAsset[]): ExternalAsset[];
65
+ readonly prototype: ICloud;
66
+ new(module?: CloudModule, database?: CloudDatabase[], ...args: unknown[]): ICloud;
67
+ }
68
+
69
+ interface ICloudServiceClient {
70
+ CLOUD_SERVICE_NAME: string;
71
+ CLOUD_UPLOAD_DISK?: boolean;
72
+ CLOUD_UPLOAD_STREAM?: boolean;
73
+ CLOUD_UPLOAD_CHUNK?: boolean;
74
+ CLOUD_DOWNLOAD_CHUNK?: boolean;
75
+ validateStorage?(credential: unknown, data?: CloudService): boolean;
76
+ validateDatabase?(credential: unknown, data?: CloudService): boolean;
77
+ createStorageClient?(this: IModule, credential: unknown, service?: string): unknown;
78
+ createDatabaseClient?(this: IModule, credential: unknown, data?: CloudService): unknown;
79
+ createBucket?(this: IModule, credential: unknown, bucket: string, publicRead?: boolean, service?: string, sdk?: string): Promise<boolean>;
80
+ createBucketV2?(this: IModule, credential: unknown, bucket: string, acl?: unknown, options?: unknown, service?: string, sdk?: string): Promise<boolean>;
81
+ setBucketPolicy?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
82
+ setBucketTagging?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
83
+ setBucketWebsite?(this: IModule, credential: unknown, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise<boolean>;
84
+ deleteObjects?(this: IModule, credential: unknown, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise<void>;
85
+ deleteObjectsV2?(this: IModule, credential: unknown, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise<void>;
86
+ executeQuery?(this: ICloud, credential: unknown, data: CloudDatabase, sessionKey?: string): Promise<QueryResult>;
87
+ executeBatchQuery?(this: ICloud, credential: unknown, batch: CloudDatabase[], sessionKey?: string): Promise<BatchQueryResult>;
88
+ }
89
+ ```
90
+
91
+ ## Settings
92
+
93
+ ```typescript
94
+ import type { PermittedDirectories } from "./core";
95
+ import type { CloudServiceOptions, DbSourceOptions, PurgeComponent } from "./settings";
96
+
97
+ interface CloudModule {
98
+ // handler: "@e-mc/cloud";
99
+ extensions?: string[];
100
+ atlas?: CloudStoredCredentials;
101
+ aws?: CloudStoredCredentials;
102
+ "aws-v3"?: CloudStoredCredentials;
103
+ azure?: CloudStoredCredentials; // az
104
+ gcp?: CloudStoredCredentials; // gcloud
105
+ ibm?: CloudStoredCredentials;
106
+ oci?: CloudStoredCredentials;
107
+ minio?: CloudStoredCredentials;
108
+ settings?: {
109
+ broadcast_id?: string | string[];
110
+ users?: Record<string, Record<string, unknown>>;
111
+ cache_dir?: string;
112
+ session_expires?: number;
113
+ user_key?: Record<string, DbSourceOptions>;
114
+ imports?: StringMap;
115
+ purge?: PurgeComponent;
116
+ atlas?: CloudServiceOptions;
117
+ aws?: CloudServiceOptions;
118
+ "aws-v3"?: CloudServiceOptions;
119
+ azure?: CloudServiceOptions;
120
+ gcp?: CloudServiceOptions;
121
+ ibm?: CloudServiceOptions;
122
+ oci?: CloudServiceOptions;
123
+ minio?: CloudServiceOptions;
124
+ };
125
+ permission?: PermittedDirectories;
126
+ }
127
+
128
+ type CloudStoredCredentials = Record<string, Record<string, unknown>>;
129
+ ```
130
+
131
+ ### Example usage
132
+
133
+ ```javascript
134
+ const Cloud = require("@e-mc/cloud"); // Using @pi-r/aws
135
+
136
+ const instance = new Cloud({
137
+ aws: {
138
+ main: {
139
+ accessKeyId: "**********",
140
+ secretAccessKey: "**********"
141
+ }
142
+ },
143
+ "aws-v3": {
144
+ main: {
145
+ credentials: {
146
+ accessKeyId: "**********",
147
+ secretAccessKey: "**********",
148
+ region: "ap-northeast-1"
149
+ }
150
+ }
151
+ }
152
+ });
153
+ // instance.host = new Host();
154
+ instance.init();
155
+
156
+ const options = {
157
+ contentType: "application/tar",
158
+ acl: "authenticated-read",
159
+ chunkSize: "8mb",
160
+ overwrite: false, // Default
161
+ tags: { key_1: "value", key_2: "value" }
162
+ };
163
+ Promise.all([
164
+ // nodejs-001/archive.tar
165
+ instance.uploadObject("aws", "main", "nodejs-001", options, "/tmp/archive.tar"),
166
+ // nodejs-001/2024/01-01.tar
167
+ instance.uploadObject("aws", "main", "nodejs-001", { ...options, publicRead: true, pathname: "2024", filename: "01-01.tar" }, "/tmp/archive.tar"),
168
+ // nodejs-001/archive_1.tar
169
+ instance.uploadObject("aws", { accessKeyId: "*****", secretAccessKey: "*****" }, "nodejs-001", { overwrite: false }, "/tmp/archive.tar")
170
+ ]);
171
+
172
+ const rows = await instance.getDatabaseRows({ service: "aws-v3", credential: "main", table: "demo", key: { id: 1 } });
173
+ ```
174
+
175
+ ## References
176
+
177
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/asset.d.ts
178
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/cloud.d.ts
179
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/core.d.ts
180
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/db.d.ts
181
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/logger.d.ts
182
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/settings.d.ts
183
+
184
+ ## LICENSE
185
+
186
186
  BSD 3-Clause
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { CloudConstructor, IFileManager } from '../types/lib';
2
- import type { CloudAsset } from '../types/lib/cloud';
3
-
4
- declare const Cloud: CloudConstructor<IFileManager<CloudAsset>>;
5
-
1
+ import type { CloudConstructor, IFileManager } from '@e-mc/types/lib';
2
+ import type { CloudAsset } from '@e-mc/types/lib/cloud';
3
+
4
+ declare const Cloud: CloudConstructor<IFileManager<CloudAsset>>;
5
+
6
6
  export = Cloud;
package/index.js CHANGED
@@ -95,7 +95,7 @@ class Cloud extends core_1.ClientDb {
95
95
  const credential = instance.getCredential(storage, true);
96
96
  const configBucket = admin.configBucket;
97
97
  if (admin.emptyBucket) {
98
- const service = bucketDelete[name] || (bucketDelete[name] = {});
98
+ const service = bucketDelete[name] ||= {};
99
99
  const items = service[bucket];
100
100
  if (!items) {
101
101
  service[bucket] = [{ ...credential }, admin.recursive];
@@ -107,11 +107,11 @@ class Cloud extends core_1.ClientDb {
107
107
  if (configBucket) {
108
108
  const { policy, tags } = configBucket;
109
109
  if (policy) {
110
- const service = bucketPolicy[name] || (bucketPolicy[name] = {});
110
+ const service = bucketPolicy[name] ||= {};
111
111
  service[bucket] = [{ ...credential }, policy];
112
112
  }
113
113
  if (tags) {
114
- const service = bucketTagging[name] || (bucketTagging[name] = {});
114
+ const service = bucketTagging[name] ||= {};
115
115
  service[bucket] = [{ ...credential }, tags];
116
116
  }
117
117
  }
@@ -228,7 +228,7 @@ class Cloud extends core_1.ClientDb {
228
228
  }
229
229
  const service = data.service;
230
230
  const location = service + '_' + data.bucket + '_' + (download.keyname || filename);
231
- let pending = (downloadMap || (downloadMap = {}))[location];
231
+ let pending = (downloadMap ||= {})[location];
232
232
  if (pending) {
233
233
  pending.add(downloadUri);
234
234
  continue;
@@ -260,7 +260,7 @@ class Cloud extends core_1.ClientDb {
260
260
  }
261
261
  this.add(destUri);
262
262
  this.formatMessage(64, service, ["Download success", (0, types_1.formatSize)(size)], destUri, { ...Cloud.LOG_CLOUD_DOWNLOAD });
263
- result || (result = destUri);
263
+ result ||= destUri;
264
264
  }
265
265
  catch (err) {
266
266
  if (!copy && core_1.ClientDb.isErrorCode(err, 'EXDEV')) {
@@ -295,7 +295,7 @@ class Cloud extends core_1.ClientDb {
295
295
  ignoreProcess = contentType;
296
296
  contentType = undefined;
297
297
  }
298
- contentType || (contentType = file.mimeType);
298
+ contentType ||= file.mimeType;
299
299
  const { host, instance } = state;
300
300
  const cloudStorage = file.cloudStorage;
301
301
  if (instance.aborted || !Array.isArray(cloudStorage)) {
@@ -462,7 +462,7 @@ class Cloud extends core_1.ClientDb {
462
462
  const leadingFolder = leading.pathname || '';
463
463
  const renameTrailing = (value) => {
464
464
  const location = trailingFolder + value;
465
- nameIndex[location] || (nameIndex[location] = 1);
465
+ nameIndex[location] ||= 1;
466
466
  const index = value.indexOf('.');
467
467
  trailing.filename = (index !== -1 ? value.substring(0, index) : value) + '_' + nameIndex[location]++ + (index !== -1 ? value.substring(index) : '');
468
468
  };
@@ -645,7 +645,7 @@ class Cloud extends core_1.ClientDb {
645
645
  return (0, types_1.createAbortError)(true);
646
646
  }
647
647
  if ((service === 'gcp' || service === 'gcloud') && (0, types_1.isPlainObject)(credential)) {
648
- credential.storageBucket || (credential.storageBucket = bucket);
648
+ credential.storageBucket ||= bucket;
649
649
  }
650
650
  let handler;
651
651
  try {
@@ -805,10 +805,10 @@ class Cloud extends core_1.ClientDb {
805
805
  return false;
806
806
  }
807
807
  getUploadHandler(service, credential) {
808
- return (SERVICE_UPLOAD[service] || (SERVICE_UPLOAD[service] = require(this.resolveService(service, 'upload')))).call(this, credential, service);
808
+ return (SERVICE_UPLOAD[service] ||= require(this.resolveService(service, 'upload'))).call(this, credential, service);
809
809
  }
810
810
  getDownloadHandler(service, credential) {
811
- return (SERVICE_DOWNLOAD[service] || (SERVICE_DOWNLOAD[service] = require(this.resolveService(service, 'download')))).call(this, credential, service);
811
+ return (SERVICE_DOWNLOAD[service] ||= require(this.resolveService(service, 'download'))).call(this, credential, service);
812
812
  }
813
813
  resolveService(service, folder) {
814
814
  let result;
@@ -816,7 +816,7 @@ class Cloud extends core_1.ClientDb {
816
816
  result = this.settings.imports?.[service] || util_1.IMPORTS[service];
817
817
  }
818
818
  else {
819
- folder || (folder = 'client');
819
+ folder ||= 'client';
820
820
  }
821
821
  return (result || service) + (folder ? '/' + folder : '');
822
822
  }
@@ -829,7 +829,7 @@ class Cloud extends core_1.ClientDb {
829
829
  return (0, types_1.createAbortError)(true);
830
830
  }
831
831
  const items = this.pending.filter(item => !item.document).map(async (data) => {
832
- data.ignoreCache ?? (data.ignoreCache = true);
832
+ data.ignoreCache ??= true;
833
833
  return this.getDatabaseRows(data, true);
834
834
  });
835
835
  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,28 +1,28 @@
1
- {
2
- "name": "@e-mc/cloud",
3
- "version": "0.9.9",
4
- "description": "Cloud constructor for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/cloud"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/core": "0.9.9",
24
- "@e-mc/db": "0.9.9",
25
- "@e-mc/types": "0.9.9",
26
- "mime-types": "^2.1.35"
27
- }
28
- }
1
+ {
2
+ "name": "@e-mc/cloud",
3
+ "version": "0.9.11",
4
+ "description": "Cloud constructor for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/cloud"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "BSD 3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/core": "0.9.11",
24
+ "@e-mc/db": "0.9.11",
25
+ "@e-mc/types": "0.9.11",
26
+ "mime-types": "^2.1.35"
27
+ }
28
+ }
package/types/index.d.ts CHANGED
@@ -1,35 +1,37 @@
1
- import type { ICloud, IFileManager, IModule, IScopeOrigin } from '../../types/lib';
2
- import type { BucketWebsiteOptions, CloudAsset, CloudDatabase, CloudService, CloudStorageUpload, DownloadData, UploadData } from '../../types/lib/cloud';
3
- import type { BatchQueryResult, QueryResult } from '../../types/lib/db';
4
-
5
- export interface ICloudServiceClient<T extends CloudDatabase = CloudDatabase, U = unknown, V = unknown> {
6
- CLOUD_SERVICE_NAME: string;
7
- CLOUD_UPLOAD_DISK?: boolean;
8
- CLOUD_UPLOAD_STREAM?: boolean;
9
- CLOUD_UPLOAD_CHUNK?: boolean;
10
- CLOUD_DOWNLOAD_CHUNK?: boolean;
11
- validateStorage?(credential: U, data?: CloudService): boolean;
12
- validateDatabase?(credential: V, data?: CloudService): boolean;
13
- createStorageClient?<W>(this: IModule, credential: U, service?: string): W;
14
- createDatabaseClient?<W>(this: IModule, credential: V, data?: CloudService): W;
15
- createBucket?(this: IModule, credential: U, bucket: string, publicRead?: boolean, service?: string, sdk?: string): Promise<boolean>;
16
- createBucketV2?(this: IModule, credential: U, bucket: string, acl?: unknown, options?: unknown, service?: string, sdk?: string): Promise<boolean>;
17
- setBucketPolicy?(this: IModule, credential: U, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
18
- setBucketTagging?(this: IModule, credential: U, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
19
- setBucketWebsite?(this: IModule, credential: U, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise<boolean>;
20
- deleteObjects?(this: IModule, credential: U, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise<void>;
21
- deleteObjectsV2?(this: IModule, credential: U, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise<void>;
22
- executeQuery?(this: ICloud, credential: V, data: T, sessionKey?: string): Promise<QueryResult>;
23
- executeBatchQuery?(this: ICloud, credential: V, batch: T[], sessionKey?: string): Promise<BatchQueryResult>;
24
- }
25
-
26
- export interface CloudScopeOrigin<T extends IFileManager<U>, U extends CloudAsset = CloudAsset, V extends ICloud = ICloud<T>> extends Required<IScopeOrigin<T, V>> {
27
- bucketGroup: string;
28
- localStorage: Map<U, CloudStorageUpload>;
29
- }
30
-
31
- export type ServiceHost<T, U = unknown> = (this: IModule, credential: U, service?: string, sdk?: string) => T;
32
- export type UploadCallback = (data: UploadData, callback: (err: unknown, value?: string) => void) => void;
33
- export type DownloadCallback = (data: DownloadData, callback: (err: unknown, value?: Null<Bufferable>) => void) => void;
34
- export type UploadHost = ServiceHost<UploadCallback>;
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';
3
+ import type { BatchQueryResult, QueryResult } from '@e-mc/types/lib/db';
4
+
5
+ export interface ICloudServiceClient<T extends CloudDatabase = CloudDatabase, U = unknown, V = unknown> {
6
+ CLOUD_SERVICE_NAME: string;
7
+ CLOUD_UPLOAD_DISK?: boolean;
8
+ CLOUD_UPLOAD_STREAM?: boolean;
9
+ CLOUD_UPLOAD_CHUNK?: boolean;
10
+ CLOUD_DOWNLOAD_CHUNK?: boolean;
11
+ validateStorage?(credential: U, data?: CloudService): boolean;
12
+ validateDatabase?(credential: V, data?: CloudService): boolean;
13
+ createStorageClient?<W>(this: IModule, credential: U, service?: string): W;
14
+ createDatabaseClient?<W>(this: IModule, credential: V, data?: CloudService): W;
15
+ /** @deprecated */
16
+ createBucket?(this: IModule, credential: U, bucket: string, publicRead?: boolean, service?: string, sdk?: string): Promise<boolean>;
17
+ createBucketV2?(this: IModule, credential: U, bucket: string, acl?: unknown, options?: unknown, service?: string, sdk?: string): Promise<boolean>;
18
+ setBucketPolicy?(this: IModule, credential: U, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
19
+ setBucketTagging?(this: IModule, credential: U, bucket: string, options: unknown, service?: string, sdk?: string): Promise<boolean>;
20
+ setBucketWebsite?(this: IModule, credential: U, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise<boolean>;
21
+ /** @deprecated */
22
+ deleteObjects?(this: IModule, credential: U, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise<void>;
23
+ deleteObjectsV2?(this: IModule, credential: U, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise<void>;
24
+ executeQuery?(this: ICloud, credential: V, data: T, sessionKey?: string): Promise<QueryResult>;
25
+ executeBatchQuery?(this: ICloud, credential: V, batch: T[], sessionKey?: string): Promise<BatchQueryResult>;
26
+ }
27
+
28
+ export interface CloudScopeOrigin<T extends IFileManager<U>, U extends CloudAsset = CloudAsset, V extends ICloud = ICloud<T>> extends Required<IScopeOrigin<T, V>> {
29
+ bucketGroup: string;
30
+ localStorage: Map<U, CloudStorageUpload>;
31
+ }
32
+
33
+ export type ServiceHost<T, U = unknown> = (this: IModule, credential: U, service?: string, sdk?: string) => T;
34
+ export type UploadCallback = (data: UploadData, callback: (err: unknown, value?: string) => void) => void;
35
+ export type DownloadCallback = (data: DownloadData, callback: (err: unknown, value?: Null<Bufferable>) => void) => void;
36
+ export type UploadHost = ServiceHost<UploadCallback>;
35
37
  export type DownloadHost = ServiceHost<DownloadCallback>;
package/util.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- import type { UploadContent } from '../types/lib/cloud';
2
- import type { AuthValue } from '../types/lib/http';
3
-
4
- import type { Readable } from 'stream';
5
-
6
- declare namespace util {
7
- const IMPORTS: Record<string, string | undefined>;
8
- function readableAsBuffer(from: Readable): Promise<Buffer | null>;
9
- function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionType<void>, errorCallback?: FunctionType<void> | number, flags?: number): [string[], T[], string[]];
10
- function generateFilename(filename: string): (i: number) => [string, boolean];
11
- function getBasicAuth(auth: AuthValue): string;
12
- function getBasicAuth(username: unknown, password?: unknown): string;
13
- function hasBasicAuth(value: string): boolean;
14
- function formatError(title: string | { service: string }, message: string, hint?: string): Error;
15
- }
16
-
1
+ import type { UploadContent } from '@e-mc/types/lib/cloud';
2
+ import type { AuthValue } from '@e-mc/types/lib/http';
3
+
4
+ import type { Readable } from 'stream';
5
+
6
+ declare namespace util {
7
+ const IMPORTS: Record<string, string | undefined>;
8
+ function readableAsBuffer(from: Readable): Promise<Buffer | null>;
9
+ function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionType<void>, errorCallback?: FunctionType<void> | number, flags?: number): [string[], T[], string[]];
10
+ function generateFilename(filename: string): (i: number) => [string, boolean];
11
+ function getBasicAuth(auth: AuthValue): string;
12
+ function getBasicAuth(username: unknown, password?: unknown): string;
13
+ function hasBasicAuth(value: string): boolean;
14
+ function formatError(title: string | { service: string }, message: string, hint?: string): Error;
15
+ }
16
+
17
17
  export = util;