@e-mc/cloud 0.12.15 → 0.12.17

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 2024 An Pham
1
+ Copyright 2025 An Pham
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
@@ -9,10 +9,10 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.15/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.17/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
- import type { IHost, IScopeOrigin } from "./index";
15
+ import type { IFileManager, IHost, IScopeOrigin } from "./index";
16
16
  import type { ExternalAsset } from "./asset";
17
17
  import type { BucketWebsiteOptions, CloudDatabase, CloudFeatures, CloudFunctions, CloudService, CloudStorage, CloudStorageDownload, CloudStorageUpload, DeleteObjectsOptions, UploadAssetOptions } from "./cloud";
18
18
  import type { ClientDbConstructor, IClientDb } from "./core";
@@ -175,13 +175,13 @@ const rows = await instance.getDatabaseRows({ service: "aws-v3", credential: "ma
175
175
 
176
176
  ## References
177
177
 
178
- - https://www.unpkg.com/@e-mc/types@0.12.15/lib/asset.d.ts
179
- - https://www.unpkg.com/@e-mc/types@0.12.15/lib/cloud.d.ts
180
- - https://www.unpkg.com/@e-mc/types@0.12.15/lib/core.d.ts
181
- - https://www.unpkg.com/@e-mc/types@0.12.15/lib/db.d.ts
182
- - https://www.unpkg.com/@e-mc/types@0.12.15/lib/logger.d.ts
183
- - https://www.unpkg.com/@e-mc/types@0.12.15/lib/settings.d.ts
178
+ - https://www.unpkg.com/@e-mc/types@0.12.17/lib/asset.d.ts
179
+ - https://www.unpkg.com/@e-mc/types@0.12.17/lib/cloud.d.ts
180
+ - https://www.unpkg.com/@e-mc/types@0.12.17/lib/core.d.ts
181
+ - https://www.unpkg.com/@e-mc/types@0.12.17/lib/db.d.ts
182
+ - https://www.unpkg.com/@e-mc/types@0.12.17/lib/logger.d.ts
183
+ - https://www.unpkg.com/@e-mc/types@0.12.17/lib/settings.d.ts
184
184
 
185
185
  ## LICENSE
186
186
 
187
- BSD 3-Clause
187
+ MIT
package/index.js CHANGED
@@ -483,34 +483,32 @@ class Cloud extends core_1.ClientDb {
483
483
  const current = storage[i];
484
484
  for (const data of current.cloudStorage) {
485
485
  const trailing = data.upload;
486
- if (!trailing) {
487
- continue;
488
- }
489
- renamed: {
486
+ if (trailing) {
490
487
  const basename = trailing.filename;
491
488
  const filename = basename || current.filename;
492
489
  const trailingFolder = trailing.pathname || '';
493
490
  const trailingName = this.joinPath(trailingFolder, filename);
494
- for (let j = 0; j < length - 1; ++j) {
495
- const previous = storage[j];
496
- if (current === previous) {
497
- continue;
498
- }
499
- for (const other of previous.cloudStorage) {
500
- const leading = other.upload;
501
- if (leading && hasSameBucket(data, other)) {
502
- const leadingFolder = leading.pathname || '';
503
- if (basename && basename === leading.filename && leadingFolder === trailingFolder) {
504
- renameTrailing(nameIndex, trailing, trailingFolder, basename);
505
- break renamed;
506
- }
507
- const leadingName = this.joinPath(leadingFolder, leading.filename || previous.filename);
508
- if (trailingName === leadingName) {
509
- if (!trailing.overwrite || leading.overwrite) {
510
- renameTrailing(nameIndex, trailing, trailingFolder, filename);
511
- break renamed;
491
+ renamed: {
492
+ for (let j = 0; j < length - 1; ++j) {
493
+ const previous = storage[j];
494
+ if (current !== previous) {
495
+ for (const other of previous.cloudStorage) {
496
+ const leading = other.upload;
497
+ if (leading && hasSameBucket(data, other)) {
498
+ const leadingFolder = leading.pathname || '';
499
+ if (basename && basename === leading.filename && leadingFolder === trailingFolder) {
500
+ renameTrailing(nameIndex, trailing, trailingFolder, basename);
501
+ break renamed;
502
+ }
503
+ const leadingName = this.joinPath(leadingFolder, leading.filename || previous.filename);
504
+ if (trailingName === leadingName) {
505
+ if (!trailing.overwrite || leading.overwrite) {
506
+ renameTrailing(nameIndex, trailing, trailingFolder, filename);
507
+ break renamed;
508
+ }
509
+ leading.filename = assignFilename(leading.filename || previous.filename);
510
+ }
512
511
  }
513
- leading.filename = assignFilename(leading.filename || previous.filename);
514
512
  }
515
513
  }
516
514
  }
@@ -874,7 +872,8 @@ class Cloud extends core_1.ClientDb {
874
872
  return client;
875
873
  }
876
874
  }
877
- catch {
875
+ catch (err) {
876
+ this.addLog(3, err, service);
878
877
  }
879
878
  throw service ? (0, types_1.errorMessage)(service, "Cloud provider not found") : (0, types_1.errorValue)("Cloud provider not found");
880
879
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/cloud",
3
- "version": "0.12.15",
3
+ "version": "0.12.17",
4
4
  "description": "Cloud constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,12 +16,12 @@
16
16
  "squared"
17
17
  ],
18
18
  "author": "An Pham <anpham6@gmail.com>",
19
- "license": "BSD-3-Clause",
19
+ "license": "MIT",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/core": "0.12.15",
23
- "@e-mc/db": "0.12.15",
24
- "@e-mc/types": "0.12.15",
22
+ "@e-mc/core": "0.12.17",
23
+ "@e-mc/db": "0.12.17",
24
+ "@e-mc/types": "0.12.17",
25
25
  "mime-types": "^2.1.35"
26
26
  }
27
27
  }
package/types/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface CloudScopeOrigin<T extends IFileManager<U>, U extends CloudAsse
33
33
  }
34
34
 
35
35
  export type ServiceHost<T, U = unknown> = (this: IModule, credential: U, service?: string, sdk?: string) => T;
36
- export type UploadCallback = (data: UploadData, callback: (err: unknown, value?: string) => void) => void;
37
- export type DownloadCallback = (data: DownloadData, callback: (err: unknown, value?: string | Buffer | null) => void) => void;
36
+ export type UploadCallback<T = any> = (data: UploadData<T, any, any, any, any, any, any>, callback: (err: unknown, value?: string) => void) => void;
37
+ export type DownloadCallback<T = any> = (data: DownloadData<T, any>, callback: (err: unknown, value?: string | Buffer | null) => void) => void;
38
38
  export type UploadHost = ServiceHost<UploadCallback>;
39
39
  export type DownloadHost = ServiceHost<DownloadCallback>;
package/util.d.ts CHANGED
@@ -4,8 +4,19 @@ import type { AuthValue } from '@e-mc/types/lib/http';
4
4
  import type { Readable } from 'node:stream';
5
5
 
6
6
  declare namespace util {
7
+ interface CreateKeyAndBodyOptions {
8
+ errorCallback?: FunctionType<void>;
9
+ descendantsGroup?: string[];
10
+ flags?: number;
11
+ chunkSize?: number;
12
+ mimeType?: string;
13
+ }
14
+
7
15
  function readableAsBuffer(from: Readable): Promise<Buffer | null>;
8
- function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionType<void>, errorCallback?: FunctionType<void> | number, flags?: number): [string[], T[], string[]];
16
+ function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], options: CreateKeyAndBodyOptions): [string[], T[], string[]];
17
+ function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], errorCallback: FunctionType<void>, flags?: number): [string[], T[], string[]];
18
+ /** @deprecated options */
19
+ function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionType<void>, errorCallback?: FunctionType<void> | number, flags?: number, descendantsGroup?: string[]): [string[], T[], string[]];
9
20
  function generateFilename(filename: string): (i: number) => [string, boolean];
10
21
  function getBasicAuth(auth: AuthValue): string;
11
22
  function getBasicAuth(username: unknown, password?: unknown): string;
package/util.js CHANGED
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "hasBasicAuth", { enumerable: true, get: function
15
15
  async function readableAsBuffer(from) {
16
16
  return new Promise((resolve, reject) => {
17
17
  let result = null;
18
- from.on('data', chunk => {
18
+ from.on('data', (chunk) => {
19
19
  if (!Buffer.isBuffer(chunk)) {
20
20
  chunk = Buffer.from(chunk);
21
21
  }
@@ -28,21 +28,26 @@ async function readableAsBuffer(from) {
28
28
  .read();
29
29
  });
30
30
  }
31
- function createKeyAndBody(filename, items, chunkSize = 0, errorCallback, flags = 0) {
31
+ function createKeyAndBody(filename, items, chunkSize = 0, errorCallback, flags = 0, descendantsGroup = ['.map']) {
32
32
  let mimeType;
33
- switch (typeof chunkSize) {
34
- case 'function':
35
- errorCallback = chunkSize;
36
- chunkSize = 0;
37
- break;
38
- case 'string':
39
- mimeType = chunkSize;
40
- chunkSize = 0;
41
- break;
33
+ if ((0, types_1.isPlainObject)(chunkSize)) {
34
+ ({ errorCallback, mimeType, chunkSize = 0, flags = 0, descendantsGroup } = chunkSize);
42
35
  }
43
- if (typeof errorCallback === 'number') {
44
- flags = errorCallback;
45
- errorCallback = undefined;
36
+ else {
37
+ switch (typeof chunkSize) {
38
+ case 'function':
39
+ errorCallback = chunkSize;
40
+ chunkSize = 0;
41
+ break;
42
+ case 'string':
43
+ mimeType = chunkSize;
44
+ chunkSize = 0;
45
+ break;
46
+ }
47
+ if (typeof errorCallback === 'number') {
48
+ flags = errorCallback;
49
+ errorCallback = undefined;
50
+ }
46
51
  }
47
52
  const key = [];
48
53
  const body = [];
@@ -103,9 +108,10 @@ function createKeyAndBody(filename, items, chunkSize = 0, errorCallback, flags =
103
108
  }
104
109
  if (target) {
105
110
  const output = filename + ext;
106
- key.push(ext === '.map' && localFile ? path.basename(localFile) : output);
111
+ const descendant = Array.isArray(descendantsGroup) && descendantsGroup.includes(ext);
112
+ key.push(descendant && localFile ? path.basename(localFile) : output);
107
113
  body.push(target);
108
- type.push(ext !== '.map' && mime.lookup(output) || mimeType || "application/octet-stream");
114
+ type.push(!descendant && mime.lookup(output) || mimeType || "application/octet-stream");
109
115
  }
110
116
  }
111
117
  catch (err) {