proto.io 0.0.207 → 0.0.209

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 (58) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +6 -6
  2. package/dist/adapters/file/aliyun-oss.js +16 -15
  3. package/dist/adapters/file/aliyun-oss.js.map +1 -1
  4. package/dist/adapters/file/aliyun-oss.mjs +16 -15
  5. package/dist/adapters/file/aliyun-oss.mjs.map +1 -1
  6. package/dist/adapters/file/database.d.ts +3 -3
  7. package/dist/adapters/file/database.js +2 -2
  8. package/dist/adapters/file/database.js.map +1 -1
  9. package/dist/adapters/file/database.mjs +2 -2
  10. package/dist/adapters/file/database.mjs.map +1 -1
  11. package/dist/adapters/file/filesystem.d.ts +5 -5
  12. package/dist/adapters/file/filesystem.js +11 -7
  13. package/dist/adapters/file/filesystem.js.map +1 -1
  14. package/dist/adapters/file/filesystem.mjs +11 -7
  15. package/dist/adapters/file/filesystem.mjs.map +1 -1
  16. package/dist/adapters/file/google-cloud-storage.d.ts +6 -6
  17. package/dist/adapters/file/google-cloud-storage.js +23 -13
  18. package/dist/adapters/file/google-cloud-storage.js.map +1 -1
  19. package/dist/adapters/file/google-cloud-storage.mjs +23 -13
  20. package/dist/adapters/file/google-cloud-storage.mjs.map +1 -1
  21. package/dist/adapters/storage/progres.d.ts +1 -1
  22. package/dist/client.d.ts +3 -3
  23. package/dist/client.js +1 -1
  24. package/dist/client.mjs +2 -2
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js +127 -49
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +129 -51
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/internals/{base-CfQi0T0I.mjs → base-DYc1_peK.mjs} +3 -3
  31. package/dist/internals/{base-CfQi0T0I.mjs.map → base-DYc1_peK.mjs.map} +1 -1
  32. package/dist/internals/{base-DHkvlTFy.d.ts → base-DbSaGX_u.d.ts} +2 -2
  33. package/dist/internals/base-DbSaGX_u.d.ts.map +1 -0
  34. package/dist/internals/{base-BFKQpiws.js → base-NsJYo2MG.js} +3 -3
  35. package/dist/internals/{base-BFKQpiws.js.map → base-NsJYo2MG.js.map} +1 -1
  36. package/dist/internals/{chunk-BuMQw4dz.js → chunk-BuKmyceG.js} +5 -3
  37. package/dist/internals/chunk-BuKmyceG.js.map +1 -0
  38. package/dist/internals/{chunk-C7kDLOLD.d.ts → chunk-bYrnqXiI.d.ts} +6 -6
  39. package/dist/internals/chunk-bYrnqXiI.d.ts.map +1 -0
  40. package/dist/internals/{chunk-DxYhYVky.mjs → chunk-bpt1C6W4.mjs} +5 -3
  41. package/dist/internals/chunk-bpt1C6W4.mjs.map +1 -0
  42. package/dist/internals/{index-BRzKDwPs.js → index-CK1snZyh.js} +19 -17
  43. package/dist/internals/index-CK1snZyh.js.map +1 -0
  44. package/dist/internals/{index-PLz89AWF.d.ts → index-Dn1IkLDx.d.ts} +48 -2
  45. package/dist/internals/index-Dn1IkLDx.d.ts.map +1 -0
  46. package/dist/internals/{index-CKcESGqE.d.ts → index-Dx36qTUa.d.ts} +2 -2
  47. package/dist/internals/index-Dx36qTUa.d.ts.map +1 -0
  48. package/dist/internals/{index-DAkcqabS.mjs → index-Eo70ZAdZ.mjs} +19 -18
  49. package/dist/internals/index-Eo70ZAdZ.mjs.map +1 -0
  50. package/package.json +1 -1
  51. package/dist/internals/base-DHkvlTFy.d.ts.map +0 -1
  52. package/dist/internals/chunk-BuMQw4dz.js.map +0 -1
  53. package/dist/internals/chunk-C7kDLOLD.d.ts.map +0 -1
  54. package/dist/internals/chunk-DxYhYVky.mjs.map +0 -1
  55. package/dist/internals/index-BRzKDwPs.js.map +0 -1
  56. package/dist/internals/index-CKcESGqE.d.ts.map +0 -1
  57. package/dist/internals/index-DAkcqabS.mjs.map +0 -1
  58. package/dist/internals/index-PLz89AWF.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash';
2
- import { F as FileChunkStorageBase } from '../../internals/chunk-DxYhYVky.mjs';
3
- import '../../internals/base-CfQi0T0I.mjs';
2
+ import { F as FileChunkStorageBase } from '../../internals/chunk-bpt1C6W4.mjs';
3
+ import '../../internals/base-DYc1_peK.mjs';
4
4
  import 'util';
5
5
  import 'zlib';
6
6
  import '@o2ter/utils-js';
@@ -44,19 +44,29 @@ class GoogleCloudStorage extends FileChunkStorageBase {
44
44
  async createChunk(proto, token, start, end, compressed) {
45
45
  await this.bucket.file(`${token}/${start}.chunk`).save(compressed);
46
46
  }
47
- async listChunks(proto, token) {
48
- const [response] = await this.bucket.getFiles({
47
+ async *listChunks(proto, token, start, end) {
48
+ let query = {
49
+ autoPaginate: false,
49
50
  prefix: `${token}/`,
50
51
  delimiter: '/',
51
- });
52
- const files = _.map(response, x => ({
53
- file: x,
54
- name: _.last(_.split(x.name, '/')),
55
- }));
56
- return _.map(_.filter(files, x => !!x.name?.match(/^\d+\.chunk$/)), x => ({
57
- file: x.file,
58
- start: parseInt(x.name.slice(0, -6)),
59
- }));
52
+ };
53
+ do {
54
+ const [response, nextPage] = await this.bucket.getFiles(query);
55
+ if (_.isEmpty(response))
56
+ break;
57
+ for (const item of response) {
58
+ const name = _.last(_.split(item.name, '/'));
59
+ if (!name?.match(/^\d+\.chunk$/))
60
+ continue;
61
+ const pos = parseInt(name.slice(0, -6));
62
+ if (start && pos < start)
63
+ continue;
64
+ if (end && pos >= end)
65
+ continue;
66
+ yield { start: pos, file: item };
67
+ }
68
+ query = nextPage;
69
+ } while (query);
60
70
  }
61
71
  async readChunk(proto, file) {
62
72
  const [buffer] = await file.download() ?? [];
@@ -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, 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;;;;"}
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, GetFilesOptions } 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, start?: number, end?: number) {\n let query: any = {\n autoPaginate: false,\n prefix: `${token}/`,\n delimiter: '/',\n };\n do {\n const [response, nextPage] = await this.bucket.getFiles(query);\n if (_.isEmpty(response)) break;\n for (const item of response) {\n const name = _.last(_.split(item.name, '/'));\n if (!name?.match(/^\\d+\\.chunk$/)) continue;\n const pos = parseInt(name.slice(0, -6));\n if (start && pos < start) continue;\n if (end && pos >= end) continue;\n yield { start: pos, file: item };\n }\n query = nextPage;\n } while (query);\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;;IAGpE,OAAO,UAAU,CAAI,KAAsB,EAAE,KAAa,EAAE,KAAc,EAAE,GAAY,EAAA;AACtF,QAAA,IAAI,KAAK,GAAQ;AACf,YAAA,YAAY,EAAE,KAAK;YACnB,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA;AACnB,YAAA,SAAS,EAAE,GAAG;SACf;AACD,QAAA,GAAG;AACD,YAAA,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC9D,YAAA,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAAE;AACzB,YAAA,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE;AAC3B,gBAAA,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5C,gBAAA,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC;oBAAE;AAClC,gBAAA,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACvC,gBAAA,IAAI,KAAK,IAAI,GAAG,GAAG,KAAK;oBAAE;AAC1B,gBAAA,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;oBAAE;gBACvB,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE;;YAElC,KAAK,GAAG,QAAQ;SACjB,QAAQ,KAAK;;AAGhB,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;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { Pool, PoolClient, PoolConfig } from 'pg';
2
- import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QuerySelector, y as DecodedSortOption, z as DecodedQuery, A as FindOptions, I as InsertOptions, B as TStorage, C as TransactionOptions, j as TObject, G as TQueryRandomOptions, H as TPubSub } from '../../internals/index-PLz89AWF.js';
2
+ import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QuerySelector, y as DecodedSortOption, z as DecodedQuery, A as FindOptions, I as InsertOptions, B as TStorage, C as TransactionOptions, j as TObject, G as TQueryRandomOptions, H as TPubSub } from '../../internals/index-Dn1IkLDx.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-CKcESGqE.js';
2
- export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CKcESGqE.js';
1
+ import { P as ProtoClient } from './internals/index-Dx36qTUa.js';
2
+ export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-Dx36qTUa.js';
3
3
  export { Decimal } from 'decimal.js';
4
- export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-PLz89AWF.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-Dn1IkLDx.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
package/dist/client.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./internals/index-BRzKDwPs.js');
5
+ var index = require('./internals/index-CK1snZyh.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('@o2ter/utils-js');
8
8
  require('./internals/private-Ciddhure.js');
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { e as ProtoClient } from './internals/index-DAkcqabS.mjs';
2
- export { f as classExtends, d as deserialize, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-DAkcqabS.mjs';
1
+ import { e as ProtoClient } from './internals/index-Eo70ZAdZ.mjs';
2
+ export { f as classExtends, d as deserialize, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-Eo70ZAdZ.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import '@o2ter/utils-js';
5
5
  import './internals/private-CNw40LZ7.mjs';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as socket_io from 'socket.io';
2
2
  import { Router } from 'express';
3
3
  import { Server } from '@o2ter/server-js';
4
- import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-PLz89AWF.js';
5
- export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-PLz89AWF.js';
4
+ import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-Dn1IkLDx.js';
5
+ export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-Dn1IkLDx.js';
6
6
  import Decimal from 'decimal.js';
7
7
  export { Decimal } from 'decimal.js';
8
- export { P as ProtoClient, c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CKcESGqE.js';
8
+ export { P as ProtoClient, c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-Dx36qTUa.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var serverJs = require('@o2ter/server-js');
7
7
  var random = require('./internals/random-B0V0EnjP.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-BRzKDwPs.js');
10
+ var index = require('./internals/index-CK1snZyh.js');
11
11
  var index$1 = require('./internals/index-B8TESzd9.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
@@ -201,6 +201,42 @@ const dispatcher = (proto, options) => {
201
201
  };
202
202
  };
203
203
 
204
+ //
205
+ // proxy.ts
206
+ //
207
+ // The MIT License
208
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
209
+ //
210
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
211
+ // of this software and associated documentation files (the "Software"), to deal
212
+ // in the Software without restriction, including without limitation the rights
213
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
214
+ // copies of the Software, and to permit persons to whom the Software is
215
+ // furnished to do so, subject to the following conditions:
216
+ //
217
+ // The above copyright notice and this permission notice shall be included in
218
+ // all copies or substantial portions of the Software.
219
+ //
220
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
221
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
222
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
223
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
224
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
225
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
226
+ // THE SOFTWARE.
227
+ //
228
+ const proxy = (x) => {
229
+ const self = x;
230
+ const proxy = _.create(self);
231
+ for (const name of _.uniq(_.flatMap(utilsJs.prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
232
+ if (name === 'constructor')
233
+ continue;
234
+ const value = _.isFunction(self[name]) ? self[name].bind(self) : self[name];
235
+ Object.defineProperty(proxy, name, { get: () => value });
236
+ }
237
+ return proxy;
238
+ };
239
+
204
240
  //
205
241
  // methods.ts
206
242
  //
@@ -287,22 +323,65 @@ class _ProtoQuery extends index.TQuery {
287
323
  yield self._objectMethods(object);
288
324
  });
289
325
  }
326
+ _on_upsert(objects) {
327
+ const createTraggers = this._proto[_private.PVK].triggers[this.className]?.create ?? [];
328
+ const updateTraggers = this._proto[_private.PVK].triggers[this.className]?.update ?? [];
329
+ for (const obj of objects) {
330
+ for (const tragger of obj.__v === 0 ? createTraggers : updateTraggers) {
331
+ (async () => {
332
+ try {
333
+ await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
334
+ }
335
+ catch (e) {
336
+ this._proto.logger.error(e);
337
+ }
338
+ })();
339
+ }
340
+ }
341
+ }
342
+ _on_delete(objects) {
343
+ const traggers = this._proto[_private.PVK].triggers[this.className]?.delete ?? [];
344
+ for (const obj of objects) {
345
+ for (const tragger of traggers) {
346
+ (async () => {
347
+ try {
348
+ await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
349
+ }
350
+ catch (e) {
351
+ this._proto.logger.error(e);
352
+ }
353
+ })();
354
+ }
355
+ }
356
+ }
290
357
  async insertMany(values, options) {
291
- return this._objectMethods(await this._dispatcher(options).insert({
358
+ const objs = this._objectMethods(await this._dispatcher(options).insert({
292
359
  className: this.className,
293
360
  includes: this[_private.PVK].options.includes,
294
361
  matches: this[_private.PVK].options.matches,
295
362
  countMatches: this[_private.PVK].options.countMatches,
296
363
  }, values));
364
+ if (!options?.silent)
365
+ this._on_upsert(objs);
366
+ return objs;
297
367
  }
298
368
  async updateMany(update, options) {
299
- return this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
369
+ const objs = this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
370
+ if (!options?.silent)
371
+ this._on_upsert(objs);
372
+ return objs;
300
373
  }
301
374
  async upsertMany(update, setOnInsert, options) {
302
- return this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
375
+ const objs = this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
376
+ if (!options?.silent)
377
+ this._on_upsert(objs);
378
+ return objs;
303
379
  }
304
380
  async deleteMany(options) {
305
- return this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
381
+ const objs = this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
382
+ if (!options?.silent)
383
+ this._on_delete(objs);
384
+ return objs;
306
385
  }
307
386
  }
308
387
  class ProtoQuery extends _ProtoQuery {
@@ -557,42 +636,6 @@ const varifyPassword = async (alg, password, options) => {
557
636
  }
558
637
  };
559
638
 
560
- //
561
- // proxy.ts
562
- //
563
- // The MIT License
564
- // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
565
- //
566
- // Permission is hereby granted, free of charge, to any person obtaining a copy
567
- // of this software and associated documentation files (the "Software"), to deal
568
- // in the Software without restriction, including without limitation the rights
569
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
570
- // copies of the Software, and to permit persons to whom the Software is
571
- // furnished to do so, subject to the following conditions:
572
- //
573
- // The above copyright notice and this permission notice shall be included in
574
- // all copies or substantial portions of the Software.
575
- //
576
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
577
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
578
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
579
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
580
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
581
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
582
- // THE SOFTWARE.
583
- //
584
- const proxy = (x) => {
585
- const self = x;
586
- const proxy = _.create(self);
587
- for (const name of _.uniq(_.flatMap(utilsJs.prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
588
- if (name === 'constructor')
589
- continue;
590
- const value = _.isFunction(self[name]) ? self[name].bind(self) : self[name];
591
- Object.defineProperty(proxy, name, { get: () => value });
592
- }
593
- return proxy;
594
- };
595
-
596
639
  //
597
640
  // internal.ts
598
641
  //
@@ -717,6 +760,7 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
717
760
  class ProtoInternal {
718
761
  options;
719
762
  functions = {};
763
+ triggers = {};
720
764
  jobs = {};
721
765
  jobRunner = new JobRunner();
722
766
  constructor(options) {
@@ -931,7 +975,7 @@ class ProtoInternal {
931
975
  await proto.fileStorage.destroy(proto, id);
932
976
  }
933
977
  catch (e) {
934
- console.error(e);
978
+ proto.logger.error(e);
935
979
  }
936
980
  })();
937
981
  }
@@ -987,7 +1031,7 @@ class ProtoInternal {
987
1031
  }
988
1032
  }
989
1033
  catch (e) {
990
- console.error(e);
1034
+ proto.logger.error(e);
991
1035
  }
992
1036
  })();
993
1037
  }),
@@ -1317,7 +1361,7 @@ const schedule = (proto) => {
1317
1361
  await task(proto);
1318
1362
  }
1319
1363
  catch (e) {
1320
- console.error(`Errors on schedule ${op}: ${e}`);
1364
+ proto.logger.error(`Errors on schedule ${op}: ${e}`);
1321
1365
  }
1322
1366
  }
1323
1367
  running = false;
@@ -1387,6 +1431,7 @@ class ProtoService extends index.ProtoType {
1387
1431
  keySize: 64,
1388
1432
  saltSize: 64,
1389
1433
  },
1434
+ logger: {},
1390
1435
  ...options,
1391
1436
  });
1392
1437
  }
@@ -1394,6 +1439,21 @@ class ProtoService extends index.ProtoType {
1394
1439
  this._schedule.destroy();
1395
1440
  this[_private.PVK].shutdown();
1396
1441
  }
1442
+ get logger() {
1443
+ const logger = this[_private.PVK].options.logger;
1444
+ const loggerLevel = logger.loggerLevel ?? 'warn';
1445
+ const callbacks = _.map(index._logLevels, (x, i) => [x, (...args) => {
1446
+ if (loggerLevel !== 'all' && _.indexOf(index._logLevels, loggerLevel) < i)
1447
+ return;
1448
+ const func = logger[x] ?? console[x];
1449
+ if (_.isFunction(func))
1450
+ func(...args);
1451
+ }]);
1452
+ return {
1453
+ loggerLevel,
1454
+ ..._.fromPairs(callbacks),
1455
+ };
1456
+ }
1397
1457
  classes() {
1398
1458
  return _.keys(this[_private.PVK].options.schema);
1399
1459
  }
@@ -1532,6 +1592,24 @@ class ProtoService extends index.ProtoType {
1532
1592
  define(name, callback, options) {
1533
1593
  this[_private.PVK].functions[name] = options ? { callback, ...options } : callback;
1534
1594
  }
1595
+ afterCreate(className, callback) {
1596
+ if (_.isNil(this[_private.PVK].triggers[className])) {
1597
+ this[_private.PVK].triggers[className] = { create: [], update: [], delete: [] };
1598
+ }
1599
+ this[_private.PVK].triggers[className].create.push(callback);
1600
+ }
1601
+ afterUpdate(className, callback) {
1602
+ if (_.isNil(this[_private.PVK].triggers[className])) {
1603
+ this[_private.PVK].triggers[className] = { create: [], update: [], delete: [] };
1604
+ }
1605
+ this[_private.PVK].triggers[className].update.push(callback);
1606
+ }
1607
+ afterDelete(className, callback) {
1608
+ if (_.isNil(this[_private.PVK].triggers[className])) {
1609
+ this[_private.PVK].triggers[className] = { create: [], update: [], delete: [] };
1610
+ }
1611
+ this[_private.PVK].triggers[className].delete.push(callback);
1612
+ }
1535
1613
  scheduleJob(name, params, options) {
1536
1614
  return this[_private.PVK].scheduleJob(this, name, params, options);
1537
1615
  }
@@ -1639,7 +1717,7 @@ var authHandler = (proto) => async (req, res, next) => {
1639
1717
  return next();
1640
1718
  }
1641
1719
  catch (e) {
1642
- console.error(e);
1720
+ proto.logger.error(e);
1643
1721
  return next(new Error('Internal server error'));
1644
1722
  }
1645
1723
  };
@@ -1741,12 +1819,12 @@ const verifyRelatedBy = (relatedBy) => {
1741
1819
  var classesRoute = (router, proto) => {
1742
1820
  const defaultHandler = async (req) => {
1743
1821
  const { name } = req.params;
1744
- const { operation, random, attributes, update, setOnInsert, relatedBy, ...options } = index.deserialize(req.body);
1822
+ const { operation, random, attributes, update, setOnInsert, relatedBy, silent, ...options } = index.deserialize(req.body);
1745
1823
  verifyRelatedBy(relatedBy);
1746
1824
  const payload = proto.connect(req);
1747
1825
  const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.objectId), relatedBy.key) : payload.Query(name);
1748
1826
  query[_private.PVK].options = options;
1749
- const opts = { master: payload.isMaster };
1827
+ const opts = { master: payload.isMaster, silent };
1750
1828
  if (_.includes(['File', '_Job', '_JobScope'], name) &&
1751
1829
  _.includes(['insert', 'insertMany', 'upsertOne', 'upsertMany'], operation))
1752
1830
  throw Error('Invaild operation');
@@ -2092,7 +2170,7 @@ var filesRoute = (router, proto) => {
2092
2170
  res.setHeader('Content-Length', endBytes - startBytes + 1);
2093
2171
  res.setHeader('Content-Range', `bytes ${startBytes}-${endBytes}/${file.size}`);
2094
2172
  res.status(206);
2095
- stream = payload.fileStorage.fileData(payload, file.token, startBytes, endBytes);
2173
+ stream = payload.fileStorage.fileData(payload, file.token, startBytes, endBytes + 1);
2096
2174
  }
2097
2175
  else {
2098
2176
  res.setHeader('Content-Length', file.size);
@@ -2463,7 +2541,7 @@ const registerProtoSocket = (proto, server, endpoint) => {
2463
2541
  return index$2.QuerySelector.decode(v);
2464
2542
  }
2465
2543
  catch (error) {
2466
- console.error(error);
2544
+ proto.logger.error(error);
2467
2545
  return false;
2468
2546
  }
2469
2547
  });