proto.io 0.0.209 → 0.0.210

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 (56) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +1 -1
  4. package/dist/adapters/file/database.mjs +1 -1
  5. package/dist/adapters/file/filesystem.d.ts +3 -3
  6. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  7. package/dist/adapters/storage/progres.d.ts +1 -1
  8. package/dist/adapters/storage/progres.js +22 -28
  9. package/dist/adapters/storage/progres.js.map +1 -1
  10. package/dist/adapters/storage/progres.mjs +22 -28
  11. package/dist/adapters/storage/progres.mjs.map +1 -1
  12. package/dist/client.d.ts +3 -3
  13. package/dist/client.js +2 -1
  14. package/dist/client.js.map +1 -1
  15. package/dist/client.mjs +3 -2
  16. package/dist/client.mjs.map +1 -1
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +135 -23
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +128 -16
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/internals/{base-DbSaGX_u.d.ts → base-C1ndp06_.d.ts} +2 -2
  23. package/dist/internals/base-C1ndp06_.d.ts.map +1 -0
  24. package/dist/internals/{chunk-bYrnqXiI.d.ts → chunk-DF4KyvgB.d.ts} +3 -3
  25. package/dist/internals/chunk-DF4KyvgB.d.ts.map +1 -0
  26. package/dist/internals/const-C3I6cfav.js +42 -0
  27. package/dist/internals/const-C3I6cfav.js.map +1 -0
  28. package/dist/internals/const-Dkp7Nsv5.mjs +34 -0
  29. package/dist/internals/const-Dkp7Nsv5.mjs.map +1 -0
  30. package/dist/internals/index-B8TESzd9.js.map +1 -1
  31. package/dist/internals/{index-Eo70ZAdZ.mjs → index-BgSBzm-K.mjs} +94 -20
  32. package/dist/internals/index-BgSBzm-K.mjs.map +1 -0
  33. package/dist/internals/{index-CK1snZyh.js → index-Clo9hepf.js} +99 -29
  34. package/dist/internals/index-Clo9hepf.js.map +1 -0
  35. package/dist/internals/{index-CkAvNaAe.js → index-D8O7SinR.js} +50 -3
  36. package/dist/internals/index-D8O7SinR.js.map +1 -0
  37. package/dist/internals/{index-Dn1IkLDx.d.ts → index-DIRjiWPh.d.ts} +19 -1
  38. package/dist/internals/index-DIRjiWPh.d.ts.map +1 -0
  39. package/dist/internals/{index-DlY33lfO.mjs → index-DPPLcZx8.mjs} +51 -4
  40. package/dist/internals/index-DPPLcZx8.mjs.map +1 -0
  41. package/dist/internals/index-al1N-qi7.mjs.map +1 -1
  42. package/dist/internals/{index-Dx36qTUa.d.ts → index-l-Mk0lCc.d.ts} +2 -2
  43. package/dist/internals/index-l-Mk0lCc.d.ts.map +1 -0
  44. package/dist/internals/{random-B0V0EnjP.js → random-CyU_Y2Ay.js} +2 -2
  45. package/dist/internals/{random-B0V0EnjP.js.map → random-CyU_Y2Ay.js.map} +1 -1
  46. package/dist/internals/{random-ZgzzM5v_.mjs → random-ycCeBd0S.mjs} +2 -2
  47. package/dist/internals/{random-ZgzzM5v_.mjs.map → random-ycCeBd0S.mjs.map} +1 -1
  48. package/package.json +1 -1
  49. package/dist/internals/base-DbSaGX_u.d.ts.map +0 -1
  50. package/dist/internals/chunk-bYrnqXiI.d.ts.map +0 -1
  51. package/dist/internals/index-CK1snZyh.js.map +0 -1
  52. package/dist/internals/index-CkAvNaAe.js.map +0 -1
  53. package/dist/internals/index-DlY33lfO.mjs.map +0 -1
  54. package/dist/internals/index-Dn1IkLDx.d.ts.map +0 -1
  55. package/dist/internals/index-Dx36qTUa.d.ts.map +0 -1
  56. package/dist/internals/index-Eo70ZAdZ.mjs.map +0 -1
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
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';
1
+ import { P as ProtoClient } from './internals/index-l-Mk0lCc.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-l-Mk0lCc.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-Dn1IkLDx.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-DIRjiWPh.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,13 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./internals/index-CK1snZyh.js');
5
+ var index = require('./internals/index-Clo9hepf.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('@o2ter/utils-js');
8
8
  require('./internals/private-Ciddhure.js');
9
9
  require('lodash');
10
10
  require('./internals/index-B8TESzd9.js');
11
11
  require('axios');
12
+ require('./internals/const-C3I6cfav.js');
12
13
  require('@o2ter/server-js/dist/const');
13
14
  require('socket.io-client');
14
15
  require('@o2ter/crypto-js');
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sources":["../../src/client/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 { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"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;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"client.js","sources":["../../src/client/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 { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"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;;;;;;;;;;;;;;;;;;"}
package/dist/client.mjs CHANGED
@@ -1,11 +1,12 @@
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';
1
+ import { b as ProtoClient } from './internals/index-BgSBzm-K.mjs';
2
+ export { c as classExtends, d as deserialize, h as isFile, j as isJob, e as isObject, i as isQuery, g as isRole, f as isUser, s as serialize } from './internals/index-BgSBzm-K.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import '@o2ter/utils-js';
5
5
  import './internals/private-CNw40LZ7.mjs';
6
6
  import 'lodash';
7
7
  import './internals/index-al1N-qi7.mjs';
8
8
  import 'axios';
9
+ import './internals/const-Dkp7Nsv5.mjs';
9
10
  import '@o2ter/server-js/dist/const';
10
11
  import 'socket.io-client';
11
12
  import '@o2ter/crypto-js';
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","sources":["../../src/client/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 { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"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;;;;"}
1
+ {"version":3,"file":"client.mjs","sources":["../../src/client/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 { ProtoClient } from './proto';\n\nexport * from '../common';\n\nexport { ProtoClient };\n\nexport default ProtoClient;"],"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;;;;"}
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-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';
4
+ import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-DIRjiWPh.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-DIRjiWPh.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-Dx36qTUa.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-l-Mk0lCc.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ 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-B0V0EnjP.js');
7
+ var random = require('./internals/random-CyU_Y2Ay.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-CK1snZyh.js');
10
+ var index = require('./internals/index-Clo9hepf.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');
@@ -15,8 +15,9 @@ var node_stream = require('node:stream');
15
15
  var node_crypto = require('node:crypto');
16
16
  var util = require('util');
17
17
  var cryptoJs = require('@o2ter/crypto-js');
18
+ var _const = require('./internals/const-C3I6cfav.js');
19
+ var index$2 = require('./internals/index-D8O7SinR.js');
18
20
  var Decimal = require('decimal.js');
19
- var index$2 = require('./internals/index-CkAvNaAe.js');
20
21
  var queryType = require('query-types');
21
22
  var busboy = require('busboy');
22
23
  require('axios');
@@ -338,6 +339,17 @@ class _ProtoQuery extends index.TQuery {
338
339
  })();
339
340
  }
340
341
  }
342
+ if (this._proto.schema[this.className]?.liveQuery) {
343
+ (async () => {
344
+ try {
345
+ await this._proto[_private.PVK].publishLiveQuery(this._proto, 'create', _.filter(objects, x => x.__v === 0));
346
+ await this._proto[_private.PVK].publishLiveQuery(this._proto, 'update', _.filter(objects, x => x.__v !== 0));
347
+ }
348
+ catch (e) {
349
+ this._proto.logger.error(e);
350
+ }
351
+ })();
352
+ }
341
353
  }
342
354
  _on_delete(objects) {
343
355
  const traggers = this._proto[_private.PVK].triggers[this.className]?.delete ?? [];
@@ -353,6 +365,16 @@ class _ProtoQuery extends index.TQuery {
353
365
  })();
354
366
  }
355
367
  }
368
+ if (this._proto.schema[this.className]?.liveQuery) {
369
+ (async () => {
370
+ try {
371
+ await this._proto[_private.PVK].publishLiveQuery(this._proto, 'delete', objects);
372
+ }
373
+ catch (e) {
374
+ this._proto.logger.error(e);
375
+ }
376
+ })();
377
+ }
356
378
  }
357
379
  async insertMany(values, options) {
358
380
  const objs = this._objectMethods(await this._dispatcher(options).insert({
@@ -398,6 +420,9 @@ class ProtoQuery extends _ProtoQuery {
398
420
  clone[_private.PVK].options = options ?? { ...this[_private.PVK].options };
399
421
  return clone;
400
422
  }
423
+ subscribe() {
424
+ return new index.LiveQuerySubscription(this.className, this._proto, this[_private.PVK].options.filter ?? []);
425
+ }
401
426
  }
402
427
  class ProtoRelationQuery extends _ProtoQuery {
403
428
  constructor(proto, opts) {
@@ -415,6 +440,9 @@ class ProtoRelationQuery extends _ProtoQuery {
415
440
  clone[_private.PVK].options = options ?? { ...this[_private.PVK].options };
416
441
  return clone;
417
442
  }
443
+ subscribe() {
444
+ throw Error('Unable to subscribe to relationship query');
445
+ }
418
446
  }
419
447
 
420
448
  //
@@ -755,6 +783,7 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
755
783
  ]),
756
784
  ...(s.indexes ?? []),
757
785
  ],
786
+ liveQuery: acc[className]?.liveQuery || s.liveQuery,
758
787
  })),
759
788
  }), {});
760
789
  class ProtoInternal {
@@ -1011,7 +1040,7 @@ class ProtoInternal {
1011
1040
  if (data._rperm && (!_.isArray(data._rperm) || !_.every(data._rperm, _.isString))) {
1012
1041
  throw Error('Invalid data type');
1013
1042
  }
1014
- return this.options.pubsub.publish(index.PROTO_NOTY_MSG, {
1043
+ return this.options.pubsub.publish(_const.PROTO_NOTY_MSG, {
1015
1044
  ...data,
1016
1045
  _id: this.generateId(),
1017
1046
  _created_at: new Date(),
@@ -1022,13 +1051,43 @@ class ProtoInternal {
1022
1051
  const isMaster = proto.isMaster;
1023
1052
  const roles = isMaster ? [] : this._perms(proto);
1024
1053
  return {
1025
- remove: this.options.pubsub.subscribe(index.PROTO_NOTY_MSG, payload => {
1054
+ remove: this.options.pubsub.subscribe(_const.PROTO_NOTY_MSG, payload => {
1026
1055
  const { _rperm } = payload;
1027
1056
  (async () => {
1028
1057
  try {
1029
- if (isMaster || _.some(await roles, x => _.includes(_rperm, x))) {
1030
- callback(payload);
1031
- }
1058
+ if (!isMaster && !_.some(await roles, x => _.includes(_rperm, x)))
1059
+ return;
1060
+ await callback(payload);
1061
+ }
1062
+ catch (e) {
1063
+ proto.logger.error(e);
1064
+ }
1065
+ })();
1066
+ }),
1067
+ };
1068
+ }
1069
+ async publishLiveQuery(proto, event, objects) {
1070
+ if (_.isEmpty(objects))
1071
+ return;
1072
+ return this.options.pubsub.publish(_const.PROTO_LIVEQUERY_MSG, JSON.parse(index.serialize({ event, objects }, { objAttrs: index$1.TObject.defaultKeys })));
1073
+ }
1074
+ _liveQuery(proto, callback) {
1075
+ const isMaster = proto.isMaster;
1076
+ const roles = isMaster ? [] : this._perms(proto);
1077
+ return {
1078
+ remove: this.options.pubsub.subscribe(_const.PROTO_LIVEQUERY_MSG, payload => {
1079
+ const { event, objects } = index.deserialize(JSON.stringify(payload));
1080
+ (async () => {
1081
+ try {
1082
+ const _roles = await roles;
1083
+ const payload = proto.rebind(_.filter(objects, object => {
1084
+ if (isMaster)
1085
+ return true;
1086
+ const acl = object.acl();
1087
+ const clp = proto.schema[object.className].classLevelPermissions?.get ?? ['*'];
1088
+ return _.some(_roles, x => _.includes(clp, x) && _.includes(acl.read, x));
1089
+ }));
1090
+ await callback(event, payload);
1032
1091
  }
1033
1092
  catch (e) {
1034
1093
  proto.logger.error(e);
@@ -1037,6 +1096,26 @@ class ProtoInternal {
1037
1096
  }),
1038
1097
  };
1039
1098
  }
1099
+ liveQuery(proto, event, className, filter, callback) {
1100
+ const _filter = _.isEmpty(filter) ? true : index$2.QuerySelector.decode(filter);
1101
+ return this._liveQuery(proto, (ev, objs) => {
1102
+ if (event !== ev)
1103
+ return;
1104
+ for (const object of objs) {
1105
+ if (className !== object.className)
1106
+ continue;
1107
+ (async () => {
1108
+ try {
1109
+ if (_filter === true || _filter.eval(object))
1110
+ await callback(object);
1111
+ }
1112
+ catch (e) {
1113
+ proto.logger.error(e);
1114
+ }
1115
+ })();
1116
+ }
1117
+ });
1118
+ }
1040
1119
  validateCLPs(className, acls, keys) {
1041
1120
  if (!_.has(this.options.schema, className))
1042
1121
  throw Error('No permission');
@@ -1232,8 +1311,8 @@ const _session = (proto, request) => {
1232
1311
  if (parts.length === 2 && parts[0] === 'Bearer')
1233
1312
  authorization = parts[1];
1234
1313
  }
1235
- else if (request.cookies[index.AUTH_COOKIE_KEY]) {
1236
- authorization = request.cookies[index.AUTH_COOKIE_KEY];
1314
+ else if (request.cookies[_const.AUTH_COOKIE_KEY]) {
1315
+ authorization = request.cookies[_const.AUTH_COOKIE_KEY];
1237
1316
  }
1238
1317
  if (_.isEmpty(authorization))
1239
1318
  return;
@@ -1294,8 +1373,8 @@ const session = async (proto, request) => {
1294
1373
  };
1295
1374
  };
1296
1375
  const sessionIsMaster = (proto, request) => {
1297
- const user = request.header(index.MASTER_USER_HEADER_NAME);
1298
- const pass = request.header(index.MASTER_PASS_HEADER_NAME);
1376
+ const user = request.header(_const.MASTER_USER_HEADER_NAME);
1377
+ const pass = request.header(_const.MASTER_PASS_HEADER_NAME);
1299
1378
  if (_.isEmpty(user) || _.isEmpty(pass))
1300
1379
  return false;
1301
1380
  return _.some(proto[_private.PVK].options.masterUsers, x => x.user === user && x.pass === pass) ? 'valid' : 'invalid';
@@ -1312,7 +1391,7 @@ const signUser = async (proto, res, user, options) => {
1312
1391
  user: user?.objectId,
1313
1392
  cookieOptions,
1314
1393
  }, options?.jwtSignOptions ?? 'login');
1315
- res.cookie(index.AUTH_COOKIE_KEY, token, cookieOptions);
1394
+ res.cookie(_const.AUTH_COOKIE_KEY, token, cookieOptions);
1316
1395
  sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.objectId) : {});
1317
1396
  };
1318
1397
 
@@ -1640,10 +1719,10 @@ class ProtoService extends index.ProtoType {
1640
1719
  }
1641
1720
  listen(callback, selector) {
1642
1721
  const _selector = !_.isNil(selector) ? index$2.QuerySelector.decode(selector) : undefined;
1643
- return this[_private.PVK].listen(this, data => {
1722
+ return this[_private.PVK].listen(this, async (data) => {
1644
1723
  if (_selector && !_selector.eval(data))
1645
1724
  return;
1646
- callback(data);
1725
+ await callback(data);
1647
1726
  });
1648
1727
  }
1649
1728
  refs(object, options) {
@@ -2129,7 +2208,7 @@ var filesRoute = (router, proto) => {
2129
2208
  res.setHeader('Cache-Control', ['no-cache', 'no-store']);
2130
2209
  await response(res, async () => {
2131
2210
  const payload = proto.connect(req);
2132
- const uploadToken = req.header(index.UPLOAD_TOKEN_HEADER_NAME);
2211
+ const uploadToken = req.header(_const.UPLOAD_TOKEN_HEADER_NAME);
2133
2212
  const { maxUploadSize } = payload[_private.PVK].varifyUploadToken(payload, uploadToken, payload.isMaster);
2134
2213
  const { attributes, file } = await decodeFormStream(req, (file, info) => proto.fileStorage.create(proto, file, info, maxUploadSize));
2135
2214
  try {
@@ -2514,15 +2593,34 @@ const ProtoRoute = async (options) => {
2514
2593
  const registerProtoSocket = (proto, server, endpoint) => {
2515
2594
  const io = endpoint ? server.socket().of(endpoint) : server.socket();
2516
2595
  io.on('connection', async (socket) => {
2517
- let listeners = {};
2596
+ let events = {};
2597
+ let queries = {};
2518
2598
  const connect = async (token) => {
2519
2599
  const payload = await proto.connectWithSessionToken(token);
2520
- const { remove } = payload.listen(data => {
2521
- const ids = _.keys(_.pickBy(listeners, v => v instanceof index$2.QuerySelector ? v.eval(data) : v));
2600
+ const { remove: remove_basic } = payload.listen(data => {
2601
+ const ids = _.keys(_.pickBy(events, v => v instanceof index$2.QuerySelector ? v.eval(data) : v));
2602
+ const payload = JSON.parse(index.serialize(data));
2522
2603
  if (!_.isEmpty(ids))
2523
- socket.emit('data', { ids, data });
2604
+ socket.emit('ON_EV_NOTIFY', { ids, data: payload });
2605
+ });
2606
+ const { remove: remove_livequery } = payload[_private.PVK]._liveQuery(payload, (ev, objs) => {
2607
+ const ids = {};
2608
+ for (const obj of objs) {
2609
+ ids[obj.objectId] = _.keys(_.pickBy(queries, v => {
2610
+ if (v.event !== ev || v.className !== obj.className)
2611
+ return false;
2612
+ return v.filter instanceof index$2.QuerySelector ? v.filter.eval(obj) : v.filter;
2613
+ }));
2614
+ }
2615
+ if (_.isEmpty(ids))
2616
+ return;
2617
+ const payload = JSON.parse(index.serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.objectId]))));
2618
+ socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
2524
2619
  });
2525
- return remove;
2620
+ return () => {
2621
+ remove_basic();
2622
+ remove_livequery();
2623
+ };
2526
2624
  };
2527
2625
  const { token } = socket.handshake.auth;
2528
2626
  let remove = connect(token);
@@ -2533,8 +2631,8 @@ const registerProtoSocket = (proto, server, endpoint) => {
2533
2631
  socket.on('disconnect', () => {
2534
2632
  remove.then(rm => rm());
2535
2633
  });
2536
- socket.on('register', (payload) => {
2537
- listeners = _.mapValues(payload, v => {
2634
+ socket.on('EV_NOTIFY', (payload) => {
2635
+ events = _.mapValues(payload, v => {
2538
2636
  if (_.isBoolean(v))
2539
2637
  return true;
2540
2638
  try {
@@ -2546,6 +2644,20 @@ const registerProtoSocket = (proto, server, endpoint) => {
2546
2644
  }
2547
2645
  });
2548
2646
  });
2647
+ socket.on('EV_LIVEQUERY', (payload) => {
2648
+ queries = _.mapValues(payload, v => {
2649
+ const { event = '', className = '', filter } = v ?? {};
2650
+ if (_.isBoolean(v))
2651
+ return { event, className, filter: true };
2652
+ try {
2653
+ return { event, className, filter: index$2.QuerySelector.decode(filter) };
2654
+ }
2655
+ catch (error) {
2656
+ proto.logger.error(error);
2657
+ return { event, className, filter: false };
2658
+ }
2659
+ });
2660
+ });
2549
2661
  });
2550
2662
  return io;
2551
2663
  };