proto.io 0.0.183 → 0.0.184

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/index.mjs CHANGED
@@ -3,8 +3,8 @@ import { Server } from '@o2ter/server-js';
3
3
  import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-BtYyzHJD.mjs';
4
4
  import { P as PVK } from './internals/private-CNw40LZ7.mjs';
5
5
  import { asyncStream, prototypes, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
6
- import { T as TQuery, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-CmJh3t_k.mjs';
7
- export { e as ProtoClient, f as classExtends, k as isFile, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-CmJh3t_k.mjs';
6
+ import { T as TQuery, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-CQdNVgOu.mjs';
7
+ export { e as ProtoClient, f as classExtends, k as isFile, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-CQdNVgOu.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-DyjcBbS1.mjs';
9
9
  import jwt from 'jsonwebtoken';
10
10
  import { Blob } from 'node:buffer';
@@ -734,6 +734,8 @@ const validateForeignField = (schema, key, dataType) => {
734
734
  throw Error(`Invalid foreign field: ${key}`);
735
735
  };
736
736
  const validateShapedObject = (schema, dataType) => {
737
+ if (_.isEmpty(dataType.shape))
738
+ throw Error('Invalid empty shape');
737
739
  for (const [key, type] of _.entries(dataType.shape)) {
738
740
  if (!key.match(QueryValidator.patterns.name))
739
741
  throw Error(`Invalid field name: ${key}`);
@@ -1308,7 +1310,8 @@ const fetchSessionInfo = async (proto, userId) => {
1308
1310
  const cache = userCacheMap.get(proto[PVK]);
1309
1311
  if (_.isNil(cache[userId]))
1310
1312
  cache[userId] = (async () => {
1311
- const user = _.isString(userId) ? await proto.Query('User').get(userId, { master: true }) : undefined;
1313
+ const _user = _.isString(userId) ? await proto.Query('User').get(userId, { master: true }) : undefined;
1314
+ const user = proto.req ? await proto[PVK].options.userResolver(proto, _user) : _user;
1312
1315
  const _roles = user instanceof TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
1313
1316
  cache[userId] = undefined;
1314
1317
  return { user, _roles };
@@ -1460,6 +1463,7 @@ class ProtoService extends ProtoType {
1460
1463
  constructor(options) {
1461
1464
  super();
1462
1465
  this[PVK] = new ProtoInternal({
1466
+ userResolver: (_req, user) => user,
1463
1467
  roleResolver: {},
1464
1468
  objectIdSize: 10,
1465
1469
  maxFetchLimit: 1000,