proto.io 0.0.198 → 0.0.200

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.
Files changed (48) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +26 -0
  2. package/dist/adapters/file/aliyun-oss.d.ts.map +1 -0
  3. package/dist/adapters/file/aliyun-oss.js +88 -0
  4. package/dist/adapters/file/aliyun-oss.js.map +1 -0
  5. package/dist/adapters/file/aliyun-oss.mjs +83 -0
  6. package/dist/adapters/file/aliyun-oss.mjs.map +1 -0
  7. package/dist/adapters/file/database.d.ts +1 -1
  8. package/dist/adapters/file/database.js +4 -4
  9. package/dist/adapters/file/database.js.map +1 -1
  10. package/dist/adapters/file/database.mjs +1 -1
  11. package/dist/adapters/file/filesystem.d.ts +7 -5
  12. package/dist/adapters/file/filesystem.js +11 -17
  13. package/dist/adapters/file/filesystem.js.map +1 -1
  14. package/dist/adapters/file/filesystem.mjs +11 -17
  15. package/dist/adapters/file/filesystem.mjs.map +1 -1
  16. package/dist/adapters/file/google-cloud-storage.d.ts +8 -6
  17. package/dist/adapters/file/google-cloud-storage.js +14 -22
  18. package/dist/adapters/file/google-cloud-storage.js.map +1 -1
  19. package/dist/adapters/file/google-cloud-storage.mjs +14 -22
  20. package/dist/adapters/file/google-cloud-storage.mjs.map +1 -1
  21. package/dist/adapters/storage/progres.js +1 -1
  22. package/dist/adapters/storage/progres.mjs +1 -1
  23. package/dist/index.js +7 -7
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +7 -7
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/internals/{index-BAFVUYCo.mjs → base-DYc1_peK.mjs} +2 -2
  28. package/dist/internals/base-DYc1_peK.mjs.map +1 -0
  29. package/dist/internals/{index-DvpJENaG.d.ts → base-DvpJENaG.d.ts} +1 -1
  30. package/dist/internals/base-DvpJENaG.d.ts.map +1 -0
  31. package/dist/internals/{index-DfPY7Xbb.js → base-NsJYo2MG.js} +2 -2
  32. package/dist/internals/base-NsJYo2MG.js.map +1 -0
  33. package/dist/internals/chunk-3nNdftWC.mjs +47 -0
  34. package/dist/internals/chunk-3nNdftWC.mjs.map +1 -0
  35. package/dist/internals/chunk-BZdO1nZ9.d.ts +17 -0
  36. package/dist/internals/chunk-BZdO1nZ9.d.ts.map +1 -0
  37. package/dist/internals/chunk-CdEGTub2.js +49 -0
  38. package/dist/internals/chunk-CdEGTub2.js.map +1 -0
  39. package/dist/internals/{random-Cuj4jIuw.js → random-CM_i1mxR.js} +3 -2
  40. package/dist/internals/random-CM_i1mxR.js.map +1 -0
  41. package/dist/internals/{random-CalKTKvO.mjs → random-l5S7hC1z.mjs} +3 -2
  42. package/dist/internals/random-l5S7hC1z.mjs.map +1 -0
  43. package/package.json +3 -1
  44. package/dist/internals/index-BAFVUYCo.mjs.map +0 -1
  45. package/dist/internals/index-DfPY7Xbb.js.map +0 -1
  46. package/dist/internals/index-DvpJENaG.d.ts.map +0 -1
  47. package/dist/internals/random-CalKTKvO.mjs.map +0 -1
  48. package/dist/internals/random-Cuj4jIuw.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"google-cloud-storage.js","sources":["../../../../src/adapters/file/google-cloud-storage/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { Storage } from '@google-cloud/storage';\nimport FileStorageBase, { FileStorageOptions } from '../base';\n\nexport class GoogleCloudStorage extends FileStorageBase {\n\n private _storage: Storage;\n private _bucket: string;\n\n constructor(storage: Storage, bucket: string, options: FileStorageOptions = {}) {\n super(options);\n this._storage = storage;\n this._bucket = bucket;\n }\n\n get bucket() {\n return this._storage.bucket(this._bucket);\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n await this.bucket.file(`${token}/${start}.chunk`).save(compressed);\n }\n\n async* readChunks<E>(proto: ProtoService<E>, token: string, start?: number | undefined, end?: number | undefined) {\n const [response] = await this.bucket.getFiles({\n prefix: `${token}/`,\n delimiter: '/',\n });\n const _files = _.filter(_.map(response, x => ({\n file: x,\n name: _.last(_.split(x.name, '/')),\n })), x => !!x.name?.match(/^\\d+\\.chunk$/));\n const files = _.orderBy(_.map(_files, x => ({\n file: x.file,\n start: parseInt(x.name!.slice(0, -6)),\n })), x => x.start);\n for (const [chunk, endBytes] of _.zip(files, _.slice(_.map(files, x => x.start), 1))) {\n if (_.isNumber(start) && _.isNumber(endBytes) && start >= endBytes) continue;\n if (_.isNumber(end) && end <= chunk!.start) continue;\n yield {\n start: chunk!.start,\n data: (async () => {\n const [buffer] = await chunk?.file.download() ?? [];\n if (!buffer) throw Error('Unable to connect cloud storage');\n return buffer;\n })(),\n };\n }\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n await this.bucket.deleteFiles({ prefix: `${token}/` });\n }\n};\n\nexport default Goog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AAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA,EAAE,CAAC;;AAEzD;;;;;"}
1
+ {"version":3,"file":"google-cloud-storage.js","sources":["../../../../src/adapters/file/google-cloud-storage/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { Storage, File } from '@google-cloud/storage';\nimport { FileStorageOptions } from '../base';\nimport { FileChunkStorageBase } from '../base/chunk';\n\nexport class GoogleCloudStorage extends FileChunkStorageBase<File> {\n\n private _storage: Storage;\n private _bucket: string;\n\n constructor(storage: Storage, bucket: string, options: FileStorageOptions = {}) {\n super(options);\n this._storage = storage;\n this._bucket = bucket;\n }\n\n get bucket() {\n return this._storage.bucket(this._bucket);\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n await this.bucket.file(`${token}/${start}.chunk`).save(compressed);\n }\n\n async listChunks<E>(proto: ProtoService<E>, token: string) {\n const [response] = await this.bucket.getFiles({\n prefix: `${token}/`,\n delimiter: '/',\n });\n const files = _.map(response, x => ({\n file: x,\n name: _.last(_.split(x.name, '/'))!,\n }));\n return _.map(_.filter(files, x => !!x.name?.match(/^\\d+\\.chunk$/)), x => ({\n file: x.file,\n start: parseInt(x.name.slice(0, -6)),\n }));\n }\n\n async readChunk<E>(proto: ProtoService<E>, file: File) {\n const [buffer] = await file.download() ?? [];\n if (!buffer) throw Error('Unable to connect cloud storage');\n return buffer;\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n await this.bucket.deleteFiles({ prefix: `${token}/` });\n }\n};\n\nexport default GoogleCloudStorage;"],"names":["FileChunkStorageBase"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQM,MAAO,kBAAmB,SAAQA,0BAA0B,CAAA;AAExD,IAAA,QAAQ;AACR,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,OAAgB,EAAE,MAAc,EAAE,UAA8B,EAAE,EAAA;QAC5E,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;;AAGvB,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;;IAG3C,MAAM,WAAW,CAAI,KAAsB,EAAE,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,UAAkB,EAAA;AACxG,QAAA,MAAM,IAAI,CAAC,MAAM,CA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AA,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA,EAAE,CAAC;;AAEzD;;;;;"}
@@ -1,5 +1,6 @@
1
1
  import _ from 'lodash';
2
- import { F as FileStorageBase } from '../../internals/index-BAFVUYCo.mjs';
2
+ import { F as FileChunkStorageBase } from '../../internals/chunk-3nNdftWC.mjs';
3
+ import '../../internals/base-DYc1_peK.mjs';
3
4
  import 'util';
4
5
  import 'zlib';
5
6
  import '@o2ter/utils-js';
@@ -29,7 +30,7 @@ import '../../internals/private-CNw40LZ7.mjs';
29
30
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
31
  // THE SOFTWARE.
31
32
  //
32
- class GoogleCloudStorage extends FileStorageBase {
33
+ class GoogleCloudStorage extends FileChunkStorageBase {
33
34
  _storage;
34
35
  _bucket;
35
36
  constructor(storage, bucket, options = {}) {
@@ -43,34 +44,25 @@ class GoogleCloudStorage extends FileStorageBase {
43
44
  async createChunk(proto, token, start, end, compressed) {
44
45
  await this.bucket.file(`${token}/${start}.chunk`).save(compressed);
45
46
  }
46
- async *readChunks(proto, token, start, end) {
47
+ async listChunks(proto, token) {
47
48
  const [response] = await this.bucket.getFiles({
48
49
  prefix: `${token}/`,
49
50
  delimiter: '/',
50
51
  });
51
- const _files = _.filter(_.map(response, x => ({
52
+ const files = _.map(response, x => ({
52
53
  file: x,
53
54
  name: _.last(_.split(x.name, '/')),
54
- })), x => !!x.name?.match(/^\d+\.chunk$/));
55
- const files = _.orderBy(_.map(_files, x => ({
55
+ }));
56
+ return _.map(_.filter(files, x => !!x.name?.match(/^\d+\.chunk$/)), x => ({
56
57
  file: x.file,
57
58
  start: parseInt(x.name.slice(0, -6)),
58
- })), x => x.start);
59
- for (const [chunk, endBytes] of _.zip(files, _.slice(_.map(files, x => x.start), 1))) {
60
- if (_.isNumber(start) && _.isNumber(endBytes) && start >= endBytes)
61
- continue;
62
- if (_.isNumber(end) && end <= chunk.start)
63
- continue;
64
- yield {
65
- start: chunk.start,
66
- data: (async () => {
67
- const [buffer] = await chunk?.file.download() ?? [];
68
- if (!buffer)
69
- throw Error('Unable to connect cloud storage');
70
- return buffer;
71
- })(),
72
- };
73
- }
59
+ }));
60
+ }
61
+ async readChunk(proto, file) {
62
+ const [buffer] = await file.download() ?? [];
63
+ if (!buffer)
64
+ throw Error('Unable to connect cloud storage');
65
+ return buffer;
74
66
  }
75
67
  async destroy(proto, token) {
76
68
  await this.bucket.deleteFiles({ prefix: `${token}/` });
@@ -1 +1 @@
1
- {"version":3,"file":"google-cloud-storage.mjs","sources":["../../../../src/adapters/file/google-cloud-storage/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { Storage } from '@google-cloud/storage';\nimport FileStorageBase, { FileStorageOptions } from '../base';\n\nexport class GoogleCloudStorage extends FileStorageBase {\n\n private _storage: Storage;\n private _bucket: string;\n\n constructor(storage: Storage, bucket: string, options: FileStorageOptions = {}) {\n super(options);\n this._storage = storage;\n this._bucket = bucket;\n }\n\n get bucket() {\n return this._storage.bucket(this._bucket);\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n await this.bucket.file(`${token}/${start}.chunk`).save(compressed);\n }\n\n async* readChunks<E>(proto: ProtoService<E>, token: string, start?: number | undefined, end?: number | undefined) {\n const [response] = await this.bucket.getFiles({\n prefix: `${token}/`,\n delimiter: '/',\n });\n const _files = _.filter(_.map(response, x => ({\n file: x,\n name: _.last(_.split(x.name, '/')),\n })), x => !!x.name?.match(/^\\d+\\.chunk$/));\n const files = _.orderBy(_.map(_files, x => ({\n file: x.file,\n start: parseInt(x.name!.slice(0, -6)),\n })), x => x.start);\n for (const [chunk, endBytes] of _.zip(files, _.slice(_.map(files, x => x.start), 1))) {\n if (_.isNumber(start) && _.isNumber(endBytes) && start >= endBytes) continue;\n if (_.isNumber(end) && end <= chunk!.start) continue;\n yield {\n start: chunk!.start,\n data: (async () => {\n const [buffer] = await chunk?.file.download() ?? [];\n if (!buffer) throw Error('Unable to connect cloud storage');\n return buffer;\n })(),\n };\n }\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n await this.bucket.deleteFiles({ prefix: `${token}/` });\n }\n};\n\nexport default GoogleCloudStorage;"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOM,MAAO,kBAAmB,SAAQ,eAAe,CAAA;AAE7C,IAAA,QAAQ;AACR,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,OAAgB,EAAE,MAAc,EAAE,UAA8B,EAAE,EAAA;QAC5E,KA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C,CAAC,CAAC,IAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SACtC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;AAClB,QAAA,KAAK,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;AACpF,YAAA,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,QAAQ;gBAAE;YACpE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,KAAM,CAAC,KAAK;gBAAE;YAC5C,MAAM;gBACJ,KAAK,EAAE,KAAM,CAAC,KAAK;AACnB,gBAAA,IAAI,EAAE,CAAC,YAAW;AAChB,oBAAA,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE;AACnD,oBAAA,IAAI,CAAC,MAAM;AAAE,wBAAA,MAAM,KAAK,CAAC,iCAAiC,CAAC;AAC3D,oBAAA,OAAO,MAAM;AACf,iBAAC,GAAG;aACL;;;AAIL,IAAA,MAAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA,EAAE,CAAC;;AAEzD;;;;"}
1
+ {"version":3,"file":"google-cloud-storage.mjs","sources":["../../../../src/adapters/file/google-cloud-storage/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { Storage, File } from '@google-cloud/storage';\nimport { FileStorageOptions } from '../base';\nimport { FileChunkStorageBase } from '../base/chunk';\n\nexport class GoogleCloudStorage extends FileChunkStorageBase<File> {\n\n private _storage: Storage;\n private _bucket: string;\n\n constructor(storage: Storage, bucket: string, options: FileStorageOptions = {}) {\n super(options);\n this._storage = storage;\n this._bucket = bucket;\n }\n\n get bucket() {\n return this._storage.bucket(this._bucket);\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n await this.bucket.file(`${token}/${start}.chunk`).save(compressed);\n }\n\n async listChunks<E>(proto: ProtoService<E>, token: string) {\n const [response] = await this.bucket.getFiles({\n prefix: `${token}/`,\n delimiter: '/',\n });\n const files = _.map(response, x => ({\n file: x,\n name: _.last(_.split(x.name, '/'))!,\n }));\n return _.map(_.filter(files, x => !!x.name?.match(/^\\d+\\.chunk$/)), x => ({\n file: x.file,\n start: parseInt(x.name.slice(0, -6)),\n }));\n }\n\n async readChunk<E>(proto: ProtoService<E>, file: File) {\n const [buffer] = await file.download() ?? [];\n if (!buffer) throw Error('Unable to connect cloud storage');\n return buffer;\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n await this.bucket.deleteFiles({ prefix: `${token}/` });\n }\n};\n\nexport default GoogleCloudStorage;"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQM,MAAO,kBAAmB,SAAQ,oBAA0B,CAAA;AAExD,IAAA,QAAQ;AACR,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,OAAgB,EAAE,MAAc,EAAE,UAA8B,EAAE,EAAA;QAC5E,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;;AAGvB,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;;IAG3C,MAAM,WAAW,CAAI,KAAsB,EAAE,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,UAAkB,EAAA;AACxG,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAG,EAAA,KAAK,CAAI,CAAA,EAAA,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;;AAGpE,IAAA,MAAM,UAAU,CAAI,KAAsB,EAAE,KAAa,EAAA;QACvD,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC5C,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA;AACnB,YAAA,SAAS,EAAE,GAAG;AACf,SAAA,CAAC;AACF,QAAA,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK;AAClC,YAAA,IAAI,EAAE,CAAC;AACP,YAAA,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAE;AACpC,SAAA,CAAC,CAAC;AACH,QAAA,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,KAAK;YACxE,IAAI,EAAE,CAAC,CAAC,IAAI;AACZ,YAAA,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACrC,SAAA,CAAC,CAAC;;AAGL,IAAA,MAAM,SAAS,CAAI,KAAsB,EAAE,IAAU,EAAA;QACnD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE;AAC5C,QAAA,IAAI,CAAC,MAAM;AAAE,YAAA,MAAM,KAAK,CAAC,iCAAiC,CAAC;AAC3D,QAAA,OAAO,MAAM;;AAGf,IAAA,MAAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA,EAAE,CAAC;;AAEzD;;;;"}
@@ -11,7 +11,7 @@ var Decimal = require('decimal.js');
11
11
  var utils = require('pg/lib/utils');
12
12
  var index$1 = require('../../internals/index-DIFr-lHN.js');
13
13
  require('@o2ter/crypto-js');
14
- var random$1 = require('../../internals/random-Cuj4jIuw.js');
14
+ var random$1 = require('../../internals/random-CM_i1mxR.js');
15
15
  var _private = require('../../internals/private-Ciddhure.js');
16
16
 
17
17
  //
@@ -7,7 +7,7 @@ import Decimal from 'decimal.js';
7
7
  import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
8
8
  import { a as QueryCoditionalSelector, b as QueryFieldSelector, c as QueryExpressionSelector, d as QueryDistanceExpression, e as QueryCoditionalExpression, f as QueryComparisonExpression, g as QueryNotExpression, h as QueryArrayExpression, i as QueryValueExpression, j as QueryKeyExpression, Q as QuerySelector, F as FieldSelectorExpression } from '../../internals/index-DAtoqvEN.mjs';
9
9
  import '@o2ter/crypto-js';
10
- import { r as resolveColumn, a as resolveDataType$1, g as generateId, Q as QueryValidator } from '../../internals/random-CalKTKvO.mjs';
10
+ import { r as resolveColumn, a as resolveDataType$1, g as generateId, Q as QueryValidator } from '../../internals/random-l5S7hC1z.mjs';
11
11
  import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
12
12
 
13
13
  //
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
6
  var serverJs = require('@o2ter/server-js');
7
- var random = require('./internals/random-Cuj4jIuw.js');
7
+ var random = require('./internals/random-CM_i1mxR.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
10
  var index = require('./internals/index-CGO-xORH.js');
@@ -130,7 +130,7 @@ const dispatcher = (proto, options) => {
130
130
  const isGet = _validator.isGetMethod(decoded.filter);
131
131
  if (!_validator.validateCLPs(query.className, isGet ? 'get' : 'find'))
132
132
  throw Error('No permission');
133
- if (opts?.weight && !_validator.validateKey(query.className, opts.weight, 'read', random.QueryValidator.patterns.name))
133
+ if (opts?.weight && !_validator.validateKey(query.className, opts.weight, 'read', random.QueryValidator.patterns.path))
134
134
  throw Error('No permission');
135
135
  return proto.storage.random(decoded, opts);
136
136
  },
@@ -211,7 +211,7 @@ const dispatcher = (proto, options) => {
211
211
  throw Error('No permission');
212
212
  const _query = _validator.decodeQuery(normalize(query), 'update');
213
213
  const _update = normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path));
214
- const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.name));
214
+ const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.path));
215
215
  while (true) {
216
216
  try {
217
217
  return await proto.storage.atomic((storage) => storage.upsertOne(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
@@ -232,7 +232,7 @@ const dispatcher = (proto, options) => {
232
232
  throw Error('No permission');
233
233
  const _query = _validator.decodeQuery(normalize(query), 'update');
234
234
  const _update = normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path));
235
- const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.name));
235
+ const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.path));
236
236
  while (true) {
237
237
  try {
238
238
  return await proto.storage.atomic((storage) => storage.upsertMany(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
@@ -716,7 +716,7 @@ const validateShapedObject = (schema, dataType) => {
716
716
  if (_.isEmpty(dataType.shape))
717
717
  throw Error('Invalid empty shape');
718
718
  for (const [key, type] of _.entries(dataType.shape)) {
719
- if (!key.match(random.QueryValidator.patterns.name))
719
+ if (!key.match(random.QueryValidator.patterns.fieldName))
720
720
  throw Error(`Invalid field name: ${key}`);
721
721
  if (index$1.isShape(type)) {
722
722
  validateShapedObject(schema, type);
@@ -740,10 +740,10 @@ const validateSchemaName = (schema) => {
740
740
  };
741
741
  const validateSchema = (schema) => {
742
742
  for (const [className, _schema] of _.toPairs(schema)) {
743
- if (!className.match(random.QueryValidator.patterns.name))
743
+ if (!className.match(random.QueryValidator.patterns.className))
744
744
  throw Error(`Invalid class name: ${className}`);
745
745
  for (const [key, dataType] of _.toPairs(_schema.fields)) {
746
- if (!key.match(random.QueryValidator.patterns.name))
746
+ if (!key.match(random.QueryValidator.patterns.fieldName))
747
747
  throw Error(`Invalid field name: ${key}`);
748
748
  if (index$1.isShape(dataType)) {
749
749
  validateShapedObject(schema, dataType);