proto.io 0.0.182 → 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.
Files changed (36) hide show
  1. package/dist/adapters/file/database.d.ts +2 -2
  2. package/dist/adapters/file/filesystem.d.ts +2 -2
  3. package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
  4. package/dist/adapters/storage/progres.d.ts +1 -1
  5. package/dist/adapters/storage/progres.js +1 -1
  6. package/dist/adapters/storage/progres.mjs +1 -1
  7. package/dist/client.d.ts +3 -3
  8. package/dist/client.js +1 -1
  9. package/dist/client.mjs +2 -2
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +19 -6
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +20 -7
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/internals/{index-BnDahEvz.js → index-BEK58Z0z.js} +3 -3
  16. package/dist/internals/index-BEK58Z0z.js.map +1 -0
  17. package/dist/internals/{index-CmJh3t_k.mjs → index-CQdNVgOu.mjs} +3 -3
  18. package/dist/internals/index-CQdNVgOu.mjs.map +1 -0
  19. package/dist/internals/{index-cKx59cIc.d.ts → index-CT5PbMDJ.d.ts} +2 -2
  20. package/dist/internals/index-CT5PbMDJ.d.ts.map +1 -0
  21. package/dist/internals/{index-BZupzq1Y.d.ts → index-CWGYv9An.d.ts} +2 -2
  22. package/dist/internals/index-CWGYv9An.d.ts.map +1 -0
  23. package/dist/internals/{index-YpB-hXxf.d.ts → index-CvKCWBvj.d.ts} +16 -16
  24. package/dist/internals/index-CvKCWBvj.d.ts.map +1 -0
  25. package/dist/internals/{random-CDtFUuES.js → random-80Vpxbxh.js} +9 -11
  26. package/dist/internals/random-80Vpxbxh.js.map +1 -0
  27. package/dist/internals/{random-BSyWEK8G.mjs → random-BtYyzHJD.mjs} +9 -11
  28. package/dist/internals/random-BtYyzHJD.mjs.map +1 -0
  29. package/package.json +1 -1
  30. package/dist/internals/index-BZupzq1Y.d.ts.map +0 -1
  31. package/dist/internals/index-BnDahEvz.js.map +0 -1
  32. package/dist/internals/index-CmJh3t_k.mjs.map +0 -1
  33. package/dist/internals/index-YpB-hXxf.d.ts.map +0 -1
  34. package/dist/internals/index-cKx59cIc.d.ts.map +0 -1
  35. package/dist/internals/random-BSyWEK8G.mjs.map +0 -1
  36. package/dist/internals/random-CDtFUuES.js.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, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-BSyWEK8G.mjs';
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';
@@ -79,9 +79,12 @@ const normalize = (x) => {
79
79
  // THE SOFTWARE.
80
80
  //
81
81
  const fetchUserPerms = async (proto) => _.uniq(_.compact([..._.map(await proto.currentRoles(), x => `role:${x}`), (await proto.currentUser())?.objectId]));
82
- const dispatcher = (proto, options, disableSecurity) => {
82
+ const dispatcher = (proto, options) => {
83
83
  const acls = async () => options.master ? [] : await fetchUserPerms(proto);
84
- const validator = async () => new QueryValidator(proto, await acls(), options.master ?? false, disableSecurity);
84
+ const validator = async () => new QueryValidator(proto, await acls(), {
85
+ master: options.master ?? false,
86
+ disableSecurity: options.disableSecurity,
87
+ });
85
88
  return {
86
89
  async explain(query) {
87
90
  QueryValidator.recursiveCheck(query);
@@ -315,11 +318,17 @@ class _ProtoQuery extends TQuery {
315
318
  };
316
319
  }
317
320
  _dispatcher(options) {
321
+ const schema = this._proto.schema[this.className];
322
+ if (_.isNil(schema))
323
+ throw Error('Invalid className');
318
324
  if (this._opts.insecure) {
319
325
  if (options?.master !== true)
320
326
  throw Error('No permission');
321
327
  }
322
- return dispatcher(_serviceOf(options) ?? this._proto, options ?? {}, !!this._opts.insecure);
328
+ return dispatcher(_serviceOf(options) ?? this._proto, {
329
+ ...options ?? {},
330
+ disableSecurity: !!this._opts.insecure,
331
+ });
323
332
  }
324
333
  explain(options) {
325
334
  return this._dispatcher(options).explain(this._queryOptions);
@@ -725,6 +734,8 @@ const validateForeignField = (schema, key, dataType) => {
725
734
  throw Error(`Invalid foreign field: ${key}`);
726
735
  };
727
736
  const validateShapedObject = (schema, dataType) => {
737
+ if (_.isEmpty(dataType.shape))
738
+ throw Error('Invalid empty shape');
728
739
  for (const [key, type] of _.entries(dataType.shape)) {
729
740
  if (!key.match(QueryValidator.patterns.name))
730
741
  throw Error(`Invalid field name: ${key}`);
@@ -1299,7 +1310,8 @@ const fetchSessionInfo = async (proto, userId) => {
1299
1310
  const cache = userCacheMap.get(proto[PVK]);
1300
1311
  if (_.isNil(cache[userId]))
1301
1312
  cache[userId] = (async () => {
1302
- 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;
1303
1315
  const _roles = user instanceof TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
1304
1316
  cache[userId] = undefined;
1305
1317
  return { user, _roles };
@@ -1451,6 +1463,7 @@ class ProtoService extends ProtoType {
1451
1463
  constructor(options) {
1452
1464
  super();
1453
1465
  this[PVK] = new ProtoInternal({
1466
+ userResolver: (_req, user) => user,
1454
1467
  roleResolver: {},
1455
1468
  objectIdSize: 10,
1456
1469
  maxFetchLimit: 1000,