proto.io 0.0.223 → 0.0.224

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 (46) 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 +3 -3
  9. package/dist/adapters/storage/progres.js.map +1 -1
  10. package/dist/adapters/storage/progres.mjs +3 -3
  11. package/dist/adapters/storage/progres.mjs.map +1 -1
  12. package/dist/client.d.ts +3 -3
  13. package/dist/client.js +1 -1
  14. package/dist/client.mjs +2 -2
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +53 -51
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +54 -52
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/internals/{base-D7eiLTdl.d.ts → base-NZIvB1zK.d.ts} +2 -2
  21. package/dist/internals/base-NZIvB1zK.d.ts.map +1 -0
  22. package/dist/internals/{chunk-B95QS-B7.d.ts → chunk-B9i8NMB_.d.ts} +3 -3
  23. package/dist/internals/chunk-B9i8NMB_.d.ts.map +1 -0
  24. package/dist/internals/{index-B9kyejqo.d.ts → index-BOboD1oK.d.ts} +84 -35
  25. package/dist/internals/index-BOboD1oK.d.ts.map +1 -0
  26. package/dist/internals/{index-BozJOOCD.mjs → index-BZ79Ljis.mjs} +12 -1
  27. package/dist/internals/index-BZ79Ljis.mjs.map +1 -0
  28. package/dist/internals/{index-DRgs8WkW.d.ts → index-BcNiVp-e.d.ts} +3 -2
  29. package/dist/internals/index-BcNiVp-e.d.ts.map +1 -0
  30. package/dist/internals/index-CLKTEIj0.js.map +1 -1
  31. package/dist/internals/index-gWcE22mf.mjs.map +1 -1
  32. package/dist/internals/{index-C01HL8O6.js → index-vOFh8pVc.js} +12 -1
  33. package/dist/internals/index-vOFh8pVc.js.map +1 -0
  34. package/dist/internals/{validator-DX2nXeQo.mjs → validator-0I1kvhsL.mjs} +42 -10
  35. package/dist/internals/validator-0I1kvhsL.mjs.map +1 -0
  36. package/dist/internals/{validator-B5yHpyvb.js → validator-Bc1jRJfA.js} +42 -10
  37. package/dist/internals/validator-Bc1jRJfA.js.map +1 -0
  38. package/package.json +1 -1
  39. package/dist/internals/base-D7eiLTdl.d.ts.map +0 -1
  40. package/dist/internals/chunk-B95QS-B7.d.ts.map +0 -1
  41. package/dist/internals/index-B9kyejqo.d.ts.map +0 -1
  42. package/dist/internals/index-BozJOOCD.mjs.map +0 -1
  43. package/dist/internals/index-C01HL8O6.js.map +0 -1
  44. package/dist/internals/index-DRgs8WkW.d.ts.map +0 -1
  45. package/dist/internals/validator-B5yHpyvb.js.map +0 -1
  46. package/dist/internals/validator-DX2nXeQo.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import _ from 'lodash';
2
2
  import { Server } from '@o2ter/server-js';
3
- import { Q as QueryValidator, a as QueryExpression, r as resolveColumn, b as resolveDataType, c as QuerySelector } from './internals/validator-DX2nXeQo.mjs';
3
+ import { Q as QueryValidator, a as QueryExpression, r as resolveColumn, b as resolveDataType, c as QuerySelector } from './internals/validator-0I1kvhsL.mjs';
4
4
  import { P as PVK } from './internals/private-CNw40LZ7.mjs';
5
5
  import { prototypes, asyncStream, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
6
- import { L as LiveQuerySubscription, T as TQuery, d as deserialize, s as serialize, a as TUser, P as ProtoType, _ as _logLevels } from './internals/index-BozJOOCD.mjs';
7
- export { b as ProtoClient, c as classExtends } from './internals/index-BozJOOCD.mjs';
6
+ import { L as LiveQuerySubscription, T as TQuery, d as deserialize, s as serialize, a as TUser, P as ProtoType, _ as _logLevels } from './internals/index-BZ79Ljis.mjs';
7
+ export { b as ProtoClient, c as classExtends } from './internals/index-BZ79Ljis.mjs';
8
8
  import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-gWcE22mf.mjs';
9
9
  import jwt from 'jsonwebtoken';
10
10
  import { Blob } from 'node:buffer';
@@ -324,7 +324,7 @@ class _ProtoQuery extends TQuery {
324
324
  yield self._objectMethods(object);
325
325
  });
326
326
  }
327
- _on_upsert(objects) {
327
+ _on_upsert_traggers(objects) {
328
328
  const createTraggers = this._proto[PVK].triggers[this.className]?.create ?? [];
329
329
  const updateTraggers = this._proto[PVK].triggers[this.className]?.update ?? [];
330
330
  for (const obj of objects) {
@@ -339,6 +339,8 @@ class _ProtoQuery extends TQuery {
339
339
  })();
340
340
  }
341
341
  }
342
+ }
343
+ _on_upsert(objects) {
342
344
  if (this._proto.schema[this.className]?.liveQuery) {
343
345
  (async () => {
344
346
  try {
@@ -351,7 +353,7 @@ class _ProtoQuery extends TQuery {
351
353
  })();
352
354
  }
353
355
  }
354
- _on_delete(objects) {
356
+ _on_delete_traggers(objects) {
355
357
  const traggers = this._proto[PVK].triggers[this.className]?.delete ?? [];
356
358
  for (const obj of objects) {
357
359
  for (const tragger of traggers) {
@@ -365,6 +367,8 @@ class _ProtoQuery extends TQuery {
365
367
  })();
366
368
  }
367
369
  }
370
+ }
371
+ _on_delete(objects) {
368
372
  if (this._proto.schema[this.className]?.liveQuery) {
369
373
  (async () => {
370
374
  try {
@@ -383,26 +387,30 @@ class _ProtoQuery extends TQuery {
383
387
  matches: this[PVK].options.matches,
384
388
  groupMatches: this[PVK].options.groupMatches,
385
389
  }, values));
386
- if (!options?.silent)
387
- this._on_upsert(objs);
390
+ this._on_upsert(objs);
391
+ if (!options?.silent || !options.master)
392
+ this._on_upsert_traggers(objs);
388
393
  return objs;
389
394
  }
390
395
  async updateMany(update, options) {
391
396
  const objs = this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
392
- if (!options?.silent)
393
- this._on_upsert(objs);
397
+ this._on_upsert(objs);
398
+ if (!options?.silent || !options.master)
399
+ this._on_upsert_traggers(objs);
394
400
  return objs;
395
401
  }
396
402
  async upsertMany(update, setOnInsert, options) {
397
403
  const objs = this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
398
- if (!options?.silent)
399
- this._on_upsert(objs);
404
+ this._on_upsert(objs);
405
+ if (!options?.silent || !options.master)
406
+ this._on_upsert_traggers(objs);
400
407
  return objs;
401
408
  }
402
409
  async deleteMany(options) {
403
410
  const objs = this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
404
- if (!options?.silent)
405
- this._on_delete(objs);
411
+ this._on_delete(objs);
412
+ if (!options?.silent || !options.master)
413
+ this._on_delete_traggers(objs);
406
414
  return objs;
407
415
  }
408
416
  }
@@ -1072,14 +1080,14 @@ class ProtoInternal {
1072
1080
  });
1073
1081
  }
1074
1082
  listen(proto, callback) {
1075
- const isMaster = proto.isMaster;
1076
- const roles = isMaster ? [] : this._perms(proto);
1077
1083
  return {
1078
1084
  remove: this.options.pubsub.subscribe(PROTO_NOTY_MSG, payload => {
1079
1085
  const { _rperm } = payload;
1080
1086
  (async () => {
1081
1087
  try {
1082
- if (!isMaster && !_.some(await roles, x => _.includes(_rperm, x)))
1088
+ const isMaster = proto.isMaster;
1089
+ const roles = isMaster ? [] : await this._perms(proto);
1090
+ if (!isMaster && !_.some(roles, x => _.includes(_rperm, x)))
1083
1091
  return;
1084
1092
  await callback(payload);
1085
1093
  }
@@ -1096,18 +1104,17 @@ class ProtoInternal {
1096
1104
  return this.options.pubsub.publish(PROTO_LIVEQUERY_MSG, JSON.parse(serialize({ event, objects }, { objAttrs: TObject.defaultKeys })));
1097
1105
  }
1098
1106
  _liveQuery(proto, callback) {
1099
- const isMaster = proto.isMaster;
1100
- const roles = isMaster ? [] : this._perms(proto);
1101
1107
  return {
1102
1108
  remove: this.options.pubsub.subscribe(PROTO_LIVEQUERY_MSG, payload => {
1103
1109
  const { event, objects } = deserialize(JSON.stringify(payload));
1104
1110
  (async () => {
1105
1111
  try {
1106
- const _roles = await roles;
1112
+ const isMaster = proto.isMaster;
1113
+ const roles = isMaster ? [] : await this._perms(proto);
1107
1114
  const payload = proto.rebind(isMaster ? objects : _.filter(objects, object => {
1108
1115
  const acl = object.acl();
1109
1116
  const clp = proto.schema[object.className].classLevelPermissions?.get ?? ['*'];
1110
- return _.some(_roles, x => _.includes(clp, x) && _.includes(acl.read, x));
1117
+ return _.some(roles, x => _.includes(clp, x) && _.includes(acl.read, x));
1111
1118
  }));
1112
1119
  if (!_.isEmpty(payload))
1113
1120
  await callback(event, payload);
@@ -2630,42 +2637,37 @@ const ProtoRoute = async (options) => {
2630
2637
  const registerProtoSocket = (proto, server, endpoint) => {
2631
2638
  const io = endpoint ? server.socket().of(endpoint) : server.socket();
2632
2639
  io.on('connection', async (socket) => {
2640
+ let { token } = socket.handshake.auth;
2641
+ const service = await proto.connectWithSessionToken(token);
2642
+ socket.on('auth', (t) => {
2643
+ token = t;
2644
+ service.connectWithSessionToken(t);
2645
+ });
2633
2646
  let events = {};
2634
2647
  let queries = {};
2635
- const connect = (proto) => {
2636
- const { remove: remove_basic } = proto.listen(data => {
2637
- const ids = _.keys(_.pickBy(events, v => v instanceof QuerySelector ? v.eval(data) : v));
2638
- const payload = JSON.parse(serialize(data));
2639
- if (!_.isEmpty(ids))
2640
- socket.emit('ON_EV_NOTIFY', { ids, data: payload });
2641
- });
2642
- const { remove: remove_livequery } = proto[PVK]._liveQuery(proto, (ev, objs) => {
2643
- const ids = {};
2644
- for (const obj of objs) {
2645
- ids[obj.id] = _.keys(_.pickBy(queries, v => {
2646
- if (v.event !== ev || v.className !== obj.className)
2647
- return false;
2648
- return v.filter instanceof QuerySelector ? v.filter.eval(obj) : v.filter;
2649
- }));
2650
- }
2651
- if (_.isEmpty(ids))
2652
- return;
2653
- const payload = JSON.parse(serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.id]))));
2654
- socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
2655
- });
2656
- return () => {
2657
- remove_basic();
2658
- remove_livequery();
2659
- };
2660
- };
2661
- const { token } = socket.handshake.auth;
2662
- const service = await proto.connectWithSessionToken(token);
2663
- const remove = connect(service);
2664
- socket.on('auth', (token) => {
2665
- service.connectWithSessionToken(token);
2648
+ const { remove: remove_basic } = service.listen(data => {
2649
+ const ids = _.keys(_.pickBy(events, v => v instanceof QuerySelector ? v.eval(data) : v));
2650
+ const payload = JSON.parse(serialize(data));
2651
+ if (!_.isEmpty(ids))
2652
+ socket.emit('ON_EV_NOTIFY', { ids, data: payload });
2653
+ });
2654
+ const { remove: remove_livequery } = service[PVK]._liveQuery(service, (ev, objs) => {
2655
+ const ids = {};
2656
+ for (const obj of objs) {
2657
+ ids[obj.id] = _.keys(_.pickBy(queries, v => {
2658
+ if (v.event !== ev || v.className !== obj.className)
2659
+ return false;
2660
+ return v.filter instanceof QuerySelector ? v.filter.eval(obj) : v.filter;
2661
+ }));
2662
+ }
2663
+ if (_.isEmpty(ids))
2664
+ return;
2665
+ const payload = JSON.parse(serialize(_.filter(objs, obj => !_.isEmpty(ids[obj.id]))));
2666
+ socket.emit('ON_EV_LIVEQUERY', { ids, data: payload });
2666
2667
  });
2667
2668
  socket.on('disconnect', () => {
2668
- remove();
2669
+ remove_basic();
2670
+ remove_livequery();
2669
2671
  });
2670
2672
  socket.on('EV_NOTIFY', (payload) => {
2671
2673
  events = _.mapValues(payload, v => {