proto.io 0.0.222 → 0.0.223

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 (34) 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/filesystem.d.ts +3 -3
  4. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  5. package/dist/adapters/storage/progres.d.ts +1 -1
  6. package/dist/client.d.ts +3 -3
  7. package/dist/client.js +1 -1
  8. package/dist/client.mjs +2 -2
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +126 -87
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +127 -88
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/internals/{base-C1uAg1dD.d.ts → base-D7eiLTdl.d.ts} +2 -2
  15. package/dist/internals/base-D7eiLTdl.d.ts.map +1 -0
  16. package/dist/internals/{chunk-CpgqvFNO.d.ts → chunk-B95QS-B7.d.ts} +3 -3
  17. package/dist/internals/chunk-B95QS-B7.d.ts.map +1 -0
  18. package/dist/internals/{index-82GLvDiN.d.ts → index-B9kyejqo.d.ts} +38 -27
  19. package/dist/internals/index-B9kyejqo.d.ts.map +1 -0
  20. package/dist/internals/{index-CsclRNTO.mjs → index-BozJOOCD.mjs} +49 -1
  21. package/dist/internals/index-BozJOOCD.mjs.map +1 -0
  22. package/dist/internals/{index-dk8iIkyr.js → index-C01HL8O6.js} +49 -1
  23. package/dist/internals/index-C01HL8O6.js.map +1 -0
  24. package/dist/internals/index-CLKTEIj0.js.map +1 -1
  25. package/dist/internals/{index-Cc-yXi8f.d.ts → index-DRgs8WkW.d.ts} +2 -2
  26. package/dist/internals/index-DRgs8WkW.d.ts.map +1 -0
  27. package/dist/internals/index-gWcE22mf.mjs.map +1 -1
  28. package/package.json +1 -1
  29. package/dist/internals/base-C1uAg1dD.d.ts.map +0 -1
  30. package/dist/internals/chunk-CpgqvFNO.d.ts.map +0 -1
  31. package/dist/internals/index-82GLvDiN.d.ts.map +0 -1
  32. package/dist/internals/index-Cc-yXi8f.d.ts.map +0 -1
  33. package/dist/internals/index-CsclRNTO.mjs.map +0 -1
  34. package/dist/internals/index-dk8iIkyr.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { P as ProtoService } from '../../internals/index-82GLvDiN.js';
1
+ import { P as ProtoService } from '../../internals/index-B9kyejqo.js';
2
2
  import OSS from 'ali-oss';
3
- import { a as FileStorageOptions } from '../../internals/base-C1uAg1dD.js';
4
- import { F as FileChunkStorageBase } from '../../internals/chunk-CpgqvFNO.js';
3
+ import { a as FileStorageOptions } from '../../internals/base-D7eiLTdl.js';
4
+ import { F as FileChunkStorageBase } from '../../internals/chunk-B95QS-B7.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'jsonwebtoken';
7
7
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-82GLvDiN.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-C1uAg1dD.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-B9kyejqo.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-D7eiLTdl.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -1,6 +1,6 @@
1
- import { P as ProtoService } from '../../internals/index-82GLvDiN.js';
2
- import { a as FileStorageOptions } from '../../internals/base-C1uAg1dD.js';
3
- import { F as FileChunkStorageBase } from '../../internals/chunk-CpgqvFNO.js';
1
+ import { P as ProtoService } from '../../internals/index-B9kyejqo.js';
2
+ import { a as FileStorageOptions } from '../../internals/base-D7eiLTdl.js';
3
+ import { F as FileChunkStorageBase } from '../../internals/chunk-B95QS-B7.js';
4
4
  import '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
6
6
  import '@o2ter/server-js';
@@ -1,8 +1,8 @@
1
1
  import * as _google_cloud_storage from '@google-cloud/storage';
2
2
  import { File, Storage } from '@google-cloud/storage';
3
- import { P as ProtoService } from '../../internals/index-82GLvDiN.js';
4
- import { a as FileStorageOptions } from '../../internals/base-C1uAg1dD.js';
5
- import { F as FileChunkStorageBase } from '../../internals/chunk-CpgqvFNO.js';
3
+ import { P as ProtoService } from '../../internals/index-B9kyejqo.js';
4
+ import { a as FileStorageOptions } from '../../internals/base-D7eiLTdl.js';
5
+ import { F as FileChunkStorageBase } from '../../internals/chunk-B95QS-B7.js';
6
6
  import '@o2ter/utils-js';
7
7
  import 'jsonwebtoken';
8
8
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
1
  import { Pool, PoolClient, PoolConfig } from 'pg';
2
- import { a as TValueWithoutObject, T as TSchema, q as TValueWithUndefined, r as TValue, t as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, u as QueryAccumulator, v as QuerySelector, w as DecodedSortOption, x as DecodedQuery, y as FindOptions, I as InsertOptions, z as TStorage, A as TransactionOptions, k as TObject, B as QueryRandomOptions, C as TPubSub } from '../../internals/index-82GLvDiN.js';
2
+ import { a as TValueWithoutObject, T as TSchema, q as TValueWithUndefined, r as TValue, t as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, u as QueryAccumulator, v as QuerySelector, w as DecodedSortOption, x as DecodedQuery, y as FindOptions, I as InsertOptions, z as TStorage, A as TransactionOptions, k as TObject, B as QueryRandomOptions, C as TPubSub } from '../../internals/index-B9kyejqo.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,6 +1,6 @@
1
- import { P as ProtoClient } from './internals/index-Cc-yXi8f.js';
2
- export { c as classExtends } from './internals/index-Cc-yXi8f.js';
3
- export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-82GLvDiN.js';
1
+ import { P as ProtoClient } from './internals/index-DRgs8WkW.js';
2
+ export { c as classExtends } from './internals/index-DRgs8WkW.js';
3
+ export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-B9kyejqo.js';
4
4
  export { Decimal } from 'decimal.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
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-dk8iIkyr.js');
5
+ var index = require('./internals/index-C01HL8O6.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 { b as ProtoClient } from './internals/index-CsclRNTO.mjs';
2
- export { c as classExtends, d as deserialize, s as serialize } from './internals/index-CsclRNTO.mjs';
1
+ import { b as ProtoClient } from './internals/index-BozJOOCD.mjs';
2
+ export { c as classExtends, d as deserialize, s as serialize } from './internals/index-BozJOOCD.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-82GLvDiN.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-82GLvDiN.js';
4
+ import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-B9kyejqo.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-B9kyejqo.js';
6
6
  import Decimal from 'decimal.js';
7
7
  export { Decimal } from 'decimal.js';
8
- export { P as ProtoClient, c as classExtends } from './internals/index-Cc-yXi8f.js';
8
+ export { P as ProtoClient, c as classExtends } from './internals/index-DRgs8WkW.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 validator = require('./internals/validator-B5yHpyvb.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-dk8iIkyr.js');
10
+ var index = require('./internals/index-C01HL8O6.js');
11
11
  var index$1 = require('./internals/index-CLKTEIj0.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
@@ -473,6 +473,30 @@ class ProtoRelationQuery extends _ProtoQuery {
473
473
  // THE SOFTWARE.
474
474
  //
475
475
  const defaultSchema = {
476
+ '_Session': {
477
+ fields: {
478
+ token: 'string',
479
+ user: { type: 'pointer', target: 'User' },
480
+ loginedAt: 'date',
481
+ },
482
+ classLevelPermissions: {
483
+ find: [],
484
+ count: [],
485
+ create: [],
486
+ update: [],
487
+ delete: [],
488
+ },
489
+ fieldLevelPermissions: {
490
+ token: { update: [] },
491
+ _expired_at: { create: [], update: [] },
492
+ },
493
+ indexes: [
494
+ {
495
+ keys: { token: 1 },
496
+ unique: true,
497
+ },
498
+ ],
499
+ },
476
500
  'User': {
477
501
  fields: {
478
502
  password: 'object',
@@ -1281,98 +1305,102 @@ class JobRunner {
1281
1305
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1282
1306
  // THE SOFTWARE.
1283
1307
  //
1284
- const sessionMap = new WeakMap();
1285
- const _sessionWithToken = (proto, token) => {
1308
+ const _sessionWithToken = async (proto, token) => {
1286
1309
  if (_.isEmpty(token))
1287
1310
  return;
1288
- const payload = proto[_private.PVK].jwtVarify(token, 'login');
1289
- if (!_.isObject(payload))
1311
+ const payload = proto[_private.PVK].jwtVarify(token, 'login') ?? {};
1312
+ if (!_.isString(payload.sessionId) || _.isEmpty(payload.sessionId))
1313
+ return;
1314
+ const session = await proto.Query('_Session')
1315
+ .equalTo('token', payload.sessionId)
1316
+ .includes('user')
1317
+ .first({ master: true });
1318
+ if (!session)
1290
1319
  return;
1320
+ return { payload, session };
1321
+ };
1322
+ const userCacheMap = new WeakMap();
1323
+ const fetchUserRole = async (proto, user) => {
1324
+ if (!userCacheMap.has(proto[_private.PVK]))
1325
+ userCacheMap.set(proto[_private.PVK], {});
1326
+ const cache = userCacheMap.get(proto[_private.PVK]);
1327
+ if (_.isNil(user?.id))
1328
+ return {};
1329
+ if (_.isNil(cache[user.id]))
1330
+ cache[user.id] = (async () => {
1331
+ const _roles = user instanceof index.TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
1332
+ cache[user.id] = undefined;
1333
+ return _roles;
1334
+ })();
1335
+ const _roles = await cache[user.id];
1291
1336
  return {
1292
- ...payload,
1293
- sessionId: payload.sessionId ?? cryptoJs.randomUUID(),
1294
- createdAt: payload.createdAt && _.isSafeInteger(payload.createdAt) ? new Date(payload.createdAt) : new Date,
1295
- loginedAt: payload.loginedAt && _.isSafeInteger(payload.loginedAt) ? new Date(payload.loginedAt) : new Date,
1337
+ user: user?.clone(),
1338
+ _roles: _.map(_roles, x => x.clone()),
1296
1339
  };
1297
1340
  };
1298
- const _session = (proto, request) => {
1341
+ const sessionMap = new WeakMap();
1342
+ const _session = async (proto, request) => {
1299
1343
  const cached = sessionMap.get(request);
1300
1344
  if (cached)
1301
- return cached;
1302
- sessionMap.set(request, {
1303
- sessionId: cryptoJs.randomUUID(),
1304
- createdAt: new Date,
1305
- loginedAt: new Date,
1306
- });
1307
- const jwtToken = proto[_private.PVK].options.jwtToken;
1308
- if (_.isEmpty(jwtToken))
1309
- throw Error('Invalid jwt token');
1345
+ return {
1346
+ sessionId: cached.session.sessionId,
1347
+ createdAt: cached.session.createdAt,
1348
+ updatedAt: cached.session.updatedAt,
1349
+ loginedAt: cached.session.loginedAt,
1350
+ user: cached.session.user,
1351
+ cookieOptions: cached.payload.cookieOptions,
1352
+ };
1310
1353
  const cookieKey = _.last(_.castArray(request.headers[_const.AUTH_ALT_COOKIE_KEY] || [])) || _const.AUTH_COOKIE_KEY;
1311
- let authorization = '';
1354
+ let sessionId = '';
1312
1355
  if (request.headers.authorization) {
1313
1356
  const parts = request.headers.authorization.split(' ');
1314
1357
  if (parts.length === 2 && parts[0] === 'Bearer')
1315
- authorization = parts[1];
1358
+ sessionId = parts[1];
1316
1359
  }
1317
1360
  else if (request.cookies[cookieKey]) {
1318
- authorization = request.cookies[cookieKey];
1361
+ sessionId = request.cookies[cookieKey];
1319
1362
  }
1320
- if (_.isEmpty(authorization))
1363
+ const { payload, session } = await _sessionWithToken(proto, sessionId) ?? {};
1364
+ if (!session)
1321
1365
  return;
1322
- const session = _sessionWithToken(proto, authorization);
1323
- if (!_.isObject(session))
1324
- return;
1325
- sessionMap.set(request, session);
1326
- return session;
1327
- };
1328
- const sessionId = (proto, request) => {
1329
- const session = _session(proto, request);
1330
- return sessionMap.get(request)?.sessionId ?? session?.sessionId;
1331
- };
1332
- const userCacheMap = new WeakMap;
1333
- const fetchSessionInfo = async (proto, userId = '') => {
1334
- if (!userCacheMap.has(proto[_private.PVK]))
1335
- userCacheMap.set(proto[_private.PVK], {});
1336
- const cache = userCacheMap.get(proto[_private.PVK]);
1337
- if (_.isNil(cache[userId]))
1338
- cache[userId] = (async () => {
1339
- const _user = userId ? await proto.Query('User').get(userId, { master: true }) : undefined;
1340
- const user = proto.req ? await proto[_private.PVK].options.userResolver(proto, _user) : _user;
1341
- const _roles = user instanceof index.TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
1342
- cache[userId] = undefined;
1343
- return { user, _roles };
1344
- })();
1345
- const { user, _roles } = await cache[userId];
1346
- return {
1347
- user: user?.clone(),
1348
- _roles: _.map(_roles, x => x.clone()),
1349
- };
1350
- };
1351
- const sessionWithToken = async (proto, token) => {
1352
- const session = _sessionWithToken(proto, token);
1353
- const info = await fetchSessionInfo(proto, session?.user);
1366
+ sessionMap.set(request, { payload, session });
1354
1367
  return {
1355
- ...session ?? {},
1356
- ...info,
1357
- loginedAt: info?.user ? session?.loginedAt : undefined,
1368
+ sessionId: session.sessionId,
1369
+ createdAt: session.createdAt,
1370
+ updatedAt: session.updatedAt,
1371
+ loginedAt: session.loginedAt,
1372
+ user: session.user,
1373
+ cookieOptions: payload.cookieOptions,
1358
1374
  };
1359
1375
  };
1360
- const sessionInfoMap = new WeakMap();
1376
+ const userRoleMap = new WeakMap();
1361
1377
  const session = async (proto, request) => {
1362
- const session = _session(proto, request);
1363
- const cached = sessionInfoMap.get(request);
1378
+ const session = await _session(proto, request);
1379
+ const cached = userRoleMap.get(request);
1364
1380
  if (cached)
1365
1381
  return {
1366
1382
  ...session ?? {},
1367
1383
  ...cached,
1368
- loginedAt: cached?.user ? session?.loginedAt : undefined,
1369
1384
  };
1370
- const info = await fetchSessionInfo(proto, session?.user);
1371
- sessionInfoMap.set(request, info);
1385
+ const info = await fetchUserRole(proto, session?.user);
1386
+ userRoleMap.set(request, info);
1372
1387
  return {
1373
1388
  ...session ?? {},
1374
1389
  ...info,
1375
- loginedAt: info?.user ? session?.loginedAt : undefined,
1390
+ };
1391
+ };
1392
+ const sessionWithToken = async (proto, token) => {
1393
+ const { payload, session } = await _sessionWithToken(proto, token) ?? {};
1394
+ if (!session)
1395
+ return;
1396
+ const info = await fetchUserRole(proto, session?.user);
1397
+ return {
1398
+ sessionId: session.sessionId,
1399
+ createdAt: session.createdAt,
1400
+ updatedAt: session.updatedAt,
1401
+ loginedAt: session.loginedAt,
1402
+ cookieOptions: payload.cookieOptions,
1403
+ ...info,
1376
1404
  };
1377
1405
  };
1378
1406
  const sessionIsMaster = (proto, request) => {
@@ -1385,18 +1413,30 @@ const sessionIsMaster = (proto, request) => {
1385
1413
  const signUser = async (proto, res, user, options) => {
1386
1414
  if (_.isNil(proto[_private.PVK].options.jwtToken))
1387
1415
  return;
1388
- const session = _session(proto, res.req);
1416
+ const session = await _session(proto, res.req);
1389
1417
  const cookieOptions = options?.cookieOptions ?? session?.cookieOptions ?? proto[_private.PVK].options.cookieOptions;
1418
+ const sessionId = session?.sessionId ?? cryptoJs.randomUUID();
1419
+ const expiredAt = cookieOptions?.expires ?? (cookieOptions?.maxAge ? new Date(Date.now() + cookieOptions.maxAge) : undefined);
1420
+ const loginedAt = user ? session?.loginedAt ?? new Date() : undefined;
1421
+ await proto.Query('_Session')
1422
+ .equalTo('token', sessionId)
1423
+ .upsertOne({
1424
+ loginedAt: { $set: loginedAt },
1425
+ user: { $set: user },
1426
+ _expired_at: { $set: expiredAt },
1427
+ }, {
1428
+ token: sessionId,
1429
+ loginedAt: loginedAt,
1430
+ user,
1431
+ _expired_at: expiredAt,
1432
+ }, { master: true });
1390
1433
  const token = proto[_private.PVK].jwtSign({
1391
- sessionId: session?.sessionId ?? cryptoJs.randomUUID(),
1392
- createdAt: session?.createdAt?.getTime() ?? Date.now(),
1393
- loginedAt: user ? session?.loginedAt?.getTime() ?? Date.now() : undefined,
1394
- user: user?.id,
1434
+ sessionId,
1395
1435
  cookieOptions,
1396
1436
  }, options?.jwtSignOptions ?? 'login');
1397
1437
  const cookieKey = _.last(_.castArray(res.req.headers[_const.AUTH_ALT_COOKIE_KEY] || [])) || _const.AUTH_COOKIE_KEY;
1398
1438
  res.cookie(cookieKey, token, cookieOptions);
1399
- sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.id) : {});
1439
+ userRoleMap.set(res.req, user ? await fetchUserRole(proto, user) : {});
1400
1440
  };
1401
1441
 
1402
1442
  //
@@ -1491,7 +1531,6 @@ class ProtoService extends index.ProtoType {
1491
1531
  constructor(options) {
1492
1532
  super();
1493
1533
  this[_private.PVK] = new ProtoInternal({
1494
- userResolver: (_req, user) => user,
1495
1534
  roleResolver: {},
1496
1535
  objectIdSize: 10,
1497
1536
  maxFetchLimit: 1000,
@@ -1558,11 +1597,6 @@ class ProtoService extends index.ProtoType {
1558
1597
  InsecureQuery(className) {
1559
1598
  return new ProtoQuery(className, this, { insecure: true });
1560
1599
  }
1561
- get sessionId() {
1562
- if (this.session)
1563
- return this.session.sessionId;
1564
- return this.req ? sessionId(this, this.req) : undefined;
1565
- }
1566
1600
  async sessionInfo() {
1567
1601
  if (this.session)
1568
1602
  return this.session;
@@ -1592,8 +1626,14 @@ class ProtoService extends index.ProtoType {
1592
1626
  }
1593
1627
  async connectWithSessionToken(token, attrs) {
1594
1628
  const session = _.isString(token) ? await sessionWithToken(this, token) : undefined;
1595
- const payload = _.create(this, { session });
1596
- return _.assign(payload, _.isFunction(attrs) ? attrs(payload) : attrs);
1629
+ if (Object.getPrototypeOf(this) instanceof ProtoService) {
1630
+ this.session = session;
1631
+ return _.assign(this, _.isFunction(attrs) ? attrs(this) : attrs);
1632
+ }
1633
+ else {
1634
+ const payload = _.create(this, { session });
1635
+ return _.assign(payload, _.isFunction(attrs) ? attrs(payload) : attrs);
1636
+ }
1597
1637
  }
1598
1638
  async userRoles(user) {
1599
1639
  const self = this;
@@ -2595,15 +2635,14 @@ const registerProtoSocket = (proto, server, endpoint) => {
2595
2635
  io.on('connection', async (socket) => {
2596
2636
  let events = {};
2597
2637
  let queries = {};
2598
- const connect = async (token) => {
2599
- const payload = await proto.connectWithSessionToken(token);
2600
- const { remove: remove_basic } = payload.listen(data => {
2638
+ const connect = (proto) => {
2639
+ const { remove: remove_basic } = proto.listen(data => {
2601
2640
  const ids = _.keys(_.pickBy(events, v => v instanceof validator.QuerySelector ? v.eval(data) : v));
2602
2641
  const payload = JSON.parse(index.serialize(data));
2603
2642
  if (!_.isEmpty(ids))
2604
2643
  socket.emit('ON_EV_NOTIFY', { ids, data: payload });
2605
2644
  });
2606
- const { remove: remove_livequery } = payload[_private.PVK]._liveQuery(payload, (ev, objs) => {
2645
+ const { remove: remove_livequery } = proto[_private.PVK]._liveQuery(proto, (ev, objs) => {
2607
2646
  const ids = {};
2608
2647
  for (const obj of objs) {
2609
2648
  ids[obj.id] = _.keys(_.pickBy(queries, v => {
@@ -2623,13 +2662,13 @@ const registerProtoSocket = (proto, server, endpoint) => {
2623
2662
  };
2624
2663
  };
2625
2664
  const { token } = socket.handshake.auth;
2626
- let remove = connect(token);
2665
+ const service = await proto.connectWithSessionToken(token);
2666
+ const remove = connect(service);
2627
2667
  socket.on('auth', (token) => {
2628
- remove.then(rm => rm());
2629
- remove = connect(token);
2668
+ service.connectWithSessionToken(token);
2630
2669
  });
2631
2670
  socket.on('disconnect', () => {
2632
- remove.then(rm => rm());
2671
+ remove();
2633
2672
  });
2634
2673
  socket.on('EV_NOTIFY', (payload) => {
2635
2674
  events = _.mapValues(payload, v => {