@e-mc/cloud 0.12.14 → 0.12.16

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/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.14/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.16/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,12 +175,12 @@ 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.14/lib/asset.d.ts
179
- - https://www.unpkg.com/@e-mc/types@0.12.14/lib/cloud.d.ts
180
- - https://www.unpkg.com/@e-mc/types@0.12.14/lib/core.d.ts
181
- - https://www.unpkg.com/@e-mc/types@0.12.14/lib/db.d.ts
182
- - https://www.unpkg.com/@e-mc/types@0.12.14/lib/logger.d.ts
183
- - https://www.unpkg.com/@e-mc/types@0.12.14/lib/settings.d.ts
178
+ - https://www.unpkg.com/@e-mc/types@0.12.16/lib/asset.d.ts
179
+ - https://www.unpkg.com/@e-mc/types@0.12.16/lib/cloud.d.ts
180
+ - https://www.unpkg.com/@e-mc/types@0.12.16/lib/core.d.ts
181
+ - https://www.unpkg.com/@e-mc/types@0.12.16/lib/db.d.ts
182
+ - https://www.unpkg.com/@e-mc/types@0.12.16/lib/logger.d.ts
183
+ - https://www.unpkg.com/@e-mc/types@0.12.16/lib/settings.d.ts
184
184
 
185
185
  ## LICENSE
186
186
 
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/cloud",
3
- "version": "0.12.14",
3
+ "version": "0.12.16",
4
4
  "description": "Cloud constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/core": "0.12.14",
23
- "@e-mc/db": "0.12.14",
24
- "@e-mc/types": "0.12.14",
22
+ "@e-mc/core": "0.12.16",
23
+ "@e-mc/db": "0.12.16",
24
+ "@e-mc/types": "0.12.16",
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) {