proto.io 0.0.171 → 0.0.172

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.
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-D_GYwO8X.js';
2
- export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-D_GYwO8X.js';
1
+ import { P as ProtoClient } from './internals/index-DchUjNEf.js';
2
+ export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-DchUjNEf.js';
3
3
  export { Decimal } from 'decimal.js';
4
- export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BB2vDnq0.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BhWRmBiq.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
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, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-BB2vDnq0.js';
5
- export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BB2vDnq0.js';
4
+ import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-BhWRmBiq.js';
5
+ export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BhWRmBiq.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, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-D_GYwO8X.js';
8
+ export { P as ProtoClient, c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-DchUjNEf.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -851,7 +851,7 @@ class ProtoInternal {
851
851
  validateSchemaName(options.schema);
852
852
  const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
853
853
  validateSchema(schema);
854
- if (!_.every(options.roleInheritKeys, k => {
854
+ if (!_.every(options.roleResolver?.inheritKeys, k => {
855
855
  const type = random.resolveDataType(schema, 'Role', k);
856
856
  return type && index$1.isRelation(type) && _.includes(['User', 'Role'], type.target);
857
857
  })) {
@@ -1357,7 +1357,7 @@ class ProtoService extends index.ProtoType {
1357
1357
  constructor(options) {
1358
1358
  super();
1359
1359
  this[_private.PVK] = new ProtoInternal({
1360
- roleInheritKeys: [],
1360
+ roleResolver: {},
1361
1361
  objectIdSize: 10,
1362
1362
  maxFetchLimit: 1000,
1363
1363
  maxUploadSize: 20 * 1024 * 1024,
@@ -1444,30 +1444,37 @@ class ProtoService extends index.ProtoType {
1444
1444
  return _.assign(payload, _.isFunction(attrs) ? attrs(payload) : attrs);
1445
1445
  }
1446
1446
  async userRoles(user) {
1447
- const roleInheritKeys = this[_private.PVK].options.roleInheritKeys;
1448
- const schema = this.schema;
1449
- const userKeys = _.filter(roleInheritKeys, k => {
1450
- const type = random.resolveDataType(schema, 'Role', k);
1451
- return !!type && index$1.isRelation(type) && type.target === 'User';
1452
- });
1453
- const roleKeys = _.filter(roleInheritKeys, k => {
1454
- const type = random.resolveDataType(schema, 'Role', k);
1455
- return !!type && index$1.isRelation(type) && type.target === 'Role';
1456
- });
1457
- let queue = await this.Query('Role')
1458
- .or(_.map(_.uniq(['users', ...userKeys]), k => q => q.isIntersect(k, [user])))
1459
- .includes('name')
1460
- .find({ master: true });
1461
- let roles = queue;
1462
- while (!_.isEmpty(queue)) {
1463
- queue = await this.Query('Role')
1464
- .or(_.map(_.uniq(['roles', ...roleKeys]), k => q => q.isIntersect(k, queue)))
1465
- .notContainsIn('_id', _.compact(_.map(roles, x => x.objectId)))
1447
+ const self = this;
1448
+ const defaultResolver = async () => {
1449
+ const inheritKeys = self[_private.PVK].options.roleResolver?.inheritKeys ?? [];
1450
+ const schema = self.schema;
1451
+ const userKeys = _.filter(inheritKeys, k => {
1452
+ const type = random.resolveDataType(schema, 'Role', k);
1453
+ return !!type && index$1.isRelation(type) && type.target === 'User';
1454
+ });
1455
+ const roleKeys = _.filter(inheritKeys, k => {
1456
+ const type = random.resolveDataType(schema, 'Role', k);
1457
+ return !!type && index$1.isRelation(type) && type.target === 'Role';
1458
+ });
1459
+ let queue = await self.Query('Role')
1460
+ .or(_.map(_.uniq(['users', ...userKeys]), k => q => q.isIntersect(k, [user])))
1466
1461
  .includes('name')
1467
1462
  .find({ master: true });
1468
- roles = _.uniqBy([...roles, ...queue], x => x.objectId);
1469
- }
1470
- return roles;
1463
+ let roles = queue;
1464
+ while (!_.isEmpty(queue)) {
1465
+ queue = await self.Query('Role')
1466
+ .or(_.map(_.uniq(['roles', ...roleKeys]), k => q => q.isIntersect(k, queue)))
1467
+ .notContainsIn('_id', _.compact(_.map(roles, x => x.objectId)))
1468
+ .includes('name')
1469
+ .find({ master: true });
1470
+ roles = _.uniqBy([...roles, ...queue], x => x.objectId);
1471
+ }
1472
+ return roles;
1473
+ };
1474
+ const resolver = self[_private.PVK].options.roleResolver?.resolver;
1475
+ if (resolver)
1476
+ return resolver(user, defaultResolver);
1477
+ return defaultResolver();
1471
1478
  }
1472
1479
  async becomeUser(req, user, options) {
1473
1480
  if (!user.objectId)