@e-mc/cloud 0.10.0 → 0.10.2

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.10.0/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<void>;
61
- uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, options: UploadAssetOptions): Promise<void>[];
62
- uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, ignoreProcess: boolean): Promise<void>[];
63
- uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, contentType?: string, ignoreProcess?: boolean): Promise<void>[];
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.10.0/lib/asset.d.ts
178
- - https://www.unpkg.com/@e-mc/types@0.10.0/lib/cloud.d.ts
179
- - https://www.unpkg.com/@e-mc/types@0.10.0/lib/core.d.ts
180
- - https://www.unpkg.com/@e-mc/types@0.10.0/lib/db.d.ts
181
- - https://www.unpkg.com/@e-mc/types@0.10.0/lib/logger.d.ts
182
- - https://www.unpkg.com/@e-mc/types@0.10.0/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.10.2/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<void>;
61
+ uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, options: UploadAssetOptions): Promise<void>[];
62
+ uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, ignoreProcess: boolean): Promise<void>[];
63
+ uploadAsset(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, contentType?: string, ignoreProcess?: boolean): Promise<void>[];
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.10.2/lib/asset.d.ts
178
+ - https://www.unpkg.com/@e-mc/types@0.10.2/lib/cloud.d.ts
179
+ - https://www.unpkg.com/@e-mc/types@0.10.2/lib/core.d.ts
180
+ - https://www.unpkg.com/@e-mc/types@0.10.2/lib/db.d.ts
181
+ - https://www.unpkg.com/@e-mc/types@0.10.2/lib/logger.d.ts
182
+ - https://www.unpkg.com/@e-mc/types@0.10.2/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 '../types/lib';
2
+ import type { CloudAsset } from '../types/lib/cloud';
3
+
4
+ declare const Cloud: CloudConstructor<IFileManager<CloudAsset>>;
5
+
6
6
  export = Cloud;
package/index.js CHANGED
@@ -51,7 +51,7 @@ function createUploadCallback(state, file, active) {
51
51
  }
52
52
  function renameTrailing(map, item, folder, value) {
53
53
  const location = folder + value;
54
- map[location] || (map[location] = 1);
54
+ map[location] ||= 1;
55
55
  const index = value.indexOf('.');
56
56
  item.filename = (index !== -1 ? value.substring(0, index) : value) + '_' + map[location]++ + (index !== -1 ? value.substring(index) : '');
57
57
  }
@@ -117,7 +117,7 @@ class Cloud extends core_1.ClientDb {
117
117
  const credential = instance.getCredential(storage, true);
118
118
  const configBucket = admin.configBucket;
119
119
  if (admin.emptyBucket) {
120
- const service = bucketDelete[name] || (bucketDelete[name] = {});
120
+ const service = bucketDelete[name] ||= {};
121
121
  const items = service[bucket];
122
122
  if (!items) {
123
123
  service[bucket] = [{ ...credential }, admin.recursive];
@@ -129,11 +129,11 @@ class Cloud extends core_1.ClientDb {
129
129
  if (configBucket) {
130
130
  const { policy, tags } = configBucket;
131
131
  if (policy) {
132
- const service = bucketPolicy[name] || (bucketPolicy[name] = {});
132
+ const service = bucketPolicy[name] ||= {};
133
133
  service[bucket] = [{ ...credential }, policy];
134
134
  }
135
135
  if (tags) {
136
- const service = bucketTagging[name] || (bucketTagging[name] = {});
136
+ const service = bucketTagging[name] ||= {};
137
137
  service[bucket] = [{ ...credential }, tags];
138
138
  }
139
139
  }
@@ -266,7 +266,7 @@ class Cloud extends core_1.ClientDb {
266
266
  }
267
267
  const service = data.service;
268
268
  const location = service + '_' + data.bucket + '_' + (download.keyname || filename);
269
- let pending = (downloadMap || (downloadMap = {}))[location];
269
+ let pending = (downloadMap ||= {})[location];
270
270
  if (pending) {
271
271
  pending.add(downloadUri);
272
272
  continue;
@@ -298,7 +298,7 @@ class Cloud extends core_1.ClientDb {
298
298
  }
299
299
  this.add(destUri);
300
300
  this.formatMessage(64, service, ["Download success", (0, types_1.formatSize)(size)], destUri, { ...Cloud.LOG_CLOUD_DOWNLOAD });
301
- result || (result = destUri);
301
+ result ||= destUri;
302
302
  }
303
303
  catch (err) {
304
304
  if (!copy && core_1.ClientDb.isErrorCode(err, 'EXDEV')) {
@@ -335,7 +335,7 @@ class Cloud extends core_1.ClientDb {
335
335
  ignoreProcess = contentType;
336
336
  contentType = undefined;
337
337
  }
338
- contentType || (contentType = file.mimeType);
338
+ contentType ||= file.mimeType;
339
339
  const { host, instance } = state;
340
340
  const cloudStorage = file.cloudStorage;
341
341
  if (instance.aborted || !Array.isArray(cloudStorage)) {
@@ -649,7 +649,7 @@ class Cloud extends core_1.ClientDb {
649
649
  return (0, types_1.createAbortError)(true);
650
650
  }
651
651
  if ((service === 'gcp' || service === 'gcloud') && (0, types_1.isPlainObject)(credential)) {
652
- credential.storageBucket || (credential.storageBucket = bucket);
652
+ credential.storageBucket ||= bucket;
653
653
  }
654
654
  let handler;
655
655
  try {
@@ -813,10 +813,10 @@ class Cloud extends core_1.ClientDb {
813
813
  return false;
814
814
  }
815
815
  getUploadHandler(service, credential) {
816
- return (SERVICE_UPLOAD[service] || (SERVICE_UPLOAD[service] = require(this.resolveService(service, 'upload')))).call(this, credential, service);
816
+ return (SERVICE_UPLOAD[service] ||= require(this.resolveService(service, 'upload'))).call(this, credential, service);
817
817
  }
818
818
  getDownloadHandler(service, credential) {
819
- return (SERVICE_DOWNLOAD[service] || (SERVICE_DOWNLOAD[service] = require(this.resolveService(service, 'download')))).call(this, credential, service);
819
+ return (SERVICE_DOWNLOAD[service] ||= require(this.resolveService(service, 'download'))).call(this, credential, service);
820
820
  }
821
821
  resolveService(service, folder) {
822
822
  let result;
@@ -824,7 +824,7 @@ class Cloud extends core_1.ClientDb {
824
824
  result = this.settings.imports?.[service] || types_1.IMPORT_MAP[service];
825
825
  }
826
826
  else {
827
- folder || (folder = 'client');
827
+ folder ||= 'client';
828
828
  }
829
829
  return (result || service) + (folder ? '/' + folder : '');
830
830
  }
@@ -837,7 +837,7 @@ class Cloud extends core_1.ClientDb {
837
837
  return (0, types_1.createAbortError)(true);
838
838
  }
839
839
  const items = this.pending.filter(item => !item.document).map(async (data) => {
840
- data.ignoreCache ?? (data.ignoreCache = true);
840
+ data.ignoreCache ??= true;
841
841
  return this.getDatabaseRows(data, true);
842
842
  });
843
843
  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.10.0",
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.10.0",
24
- "@e-mc/db": "0.10.0",
25
- "@e-mc/types": "0.10.0",
26
- "mime-types": "^2.1.35"
27
- }
28
- }
1
+ {
2
+ "name": "@e-mc/cloud",
3
+ "version": "0.10.2",
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.10.2",
24
+ "@e-mc/db": "0.10.2",
25
+ "@e-mc/types": "0.10.2",
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 '../../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
+ /** @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,18 +1,18 @@
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
- /** @deprecated Types.IMPORT_MAP */
8
- const IMPORTS: Record<string, string | undefined>;
9
- function readableAsBuffer(from: Readable): Promise<Buffer | null>;
10
- function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionType<void>, errorCallback?: FunctionType<void> | number, flags?: number): [string[], T[], string[]];
11
- function generateFilename(filename: string): (i: number) => [string, boolean];
12
- function getBasicAuth(auth: AuthValue): string;
13
- function getBasicAuth(username: unknown, password?: unknown): string;
14
- function hasBasicAuth(value: string): boolean;
15
- function formatError(title: string | { service: string }, message: string, hint?: string): Error;
16
- }
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
+ /** @deprecated Types.IMPORT_MAP */
8
+ const IMPORTS: Record<string, string | undefined>;
9
+ function readableAsBuffer(from: Readable): Promise<Buffer | null>;
10
+ function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionType<void>, errorCallback?: FunctionType<void> | number, flags?: number): [string[], T[], string[]];
11
+ function generateFilename(filename: string): (i: number) => [string, boolean];
12
+ function getBasicAuth(auth: AuthValue): string;
13
+ function getBasicAuth(username: unknown, password?: unknown): string;
14
+ function hasBasicAuth(value: string): boolean;
15
+ function formatError(title: string | { service: string }, message: string, hint?: string): Error;
16
+ }
17
+
18
18
  export = util;