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
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-YpB-hXxf.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BZupzq1Y.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-CvKCWBvj.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CWGYv9An.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
- import { P as ProtoService } from '../../internals/index-YpB-hXxf.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BZupzq1Y.js';
1
+ import { P as ProtoService } from '../../internals/index-CvKCWBvj.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CWGYv9An.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -1,7 +1,7 @@
1
1
  import * as _google_cloud_storage from '@google-cloud/storage';
2
2
  import { Storage } from '@google-cloud/storage';
3
- import { P as ProtoService } from '../../internals/index-YpB-hXxf.js';
4
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BZupzq1Y.js';
3
+ import { P as ProtoService } from '../../internals/index-CvKCWBvj.js';
4
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CWGYv9An.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'jsonwebtoken';
7
7
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
1
  import { Pool, PoolClient, PoolConfig } from 'pg';
2
- import { _ as _TValue, T as TSchema, Q as QuerySelector, p as DecodedQuery, F as FindOptions, R as RelationOptions, q as DecodedSortOption, I as InsertOptions, r as TValue, t as FindOneOptions, u as TUpdateOp, v as FieldSelectorExpression, w as QueryExpression, x as TStorage, y as TransactionOptions, h as TObject, z as TQueryRandomOptions, A as TPubSub } from '../../internals/index-YpB-hXxf.js';
2
+ import { _ as _TValue, T as TSchema, Q as QuerySelector, p as DecodedQuery, F as FindOptions, R as RelationOptions, q as DecodedSortOption, I as InsertOptions, r as TValue, t as FindOneOptions, u as TUpdateOp, v as FieldSelectorExpression, w as QueryExpression, x as TStorage, y as TransactionOptions, h as TObject, z as TQueryRandomOptions, A as TPubSub } from '../../internals/index-CvKCWBvj.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
@@ -11,7 +11,7 @@ var Decimal = require('decimal.js');
11
11
  var utils = require('pg/lib/utils');
12
12
  var index$1 = require('../../internals/index-DjrC854w.js');
13
13
  require('@o2ter/crypto-js');
14
- var random$1 = require('../../internals/random-CDtFUuES.js');
14
+ var random$1 = require('../../internals/random-80Vpxbxh.js');
15
15
  var _private = require('../../internals/private-Ciddhure.js');
16
16
 
17
17
  //
@@ -7,7 +7,7 @@ import Decimal from 'decimal.js';
7
7
  import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
8
8
  import { a as QueryCoditionalSelector, b as QueryFieldSelector, c as QueryExpressionSelector, d as QueryDistanceExpression, e as QueryCoditionalExpression, f as QueryComparisonExpression, g as QueryNotExpression, h as QueryArrayExpression, i as QueryValueExpression, j as QueryKeyExpression, Q as QuerySelector, F as FieldSelectorExpression } from '../../internals/index-D9AowvHp.mjs';
9
9
  import '@o2ter/crypto-js';
10
- import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-BSyWEK8G.mjs';
10
+ import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-BtYyzHJD.mjs';
11
11
  import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
12
12
 
13
13
  //
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-cKx59cIc.js';
2
- export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-cKx59cIc.js';
1
+ import { P as ProtoClient } from './internals/index-CT5PbMDJ.js';
2
+ export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CT5PbMDJ.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-YpB-hXxf.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-CvKCWBvj.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
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-BnDahEvz.js');
5
+ var index = require('./internals/index-BEK58Z0z.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('./internals/index-DRq6T_5w.js');
8
8
  require('lodash');
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { e as ProtoClient } from './internals/index-CmJh3t_k.mjs';
2
- export { f as classExtends, d as deserialize, k as isFile, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-CmJh3t_k.mjs';
1
+ import { e as ProtoClient } from './internals/index-CQdNVgOu.mjs';
2
+ export { f as classExtends, d as deserialize, k as isFile, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-CQdNVgOu.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import './internals/index-DyjcBbS1.mjs';
5
5
  import 'lodash';
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-YpB-hXxf.js';
5
- export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-YpB-hXxf.js';
4
+ import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-CvKCWBvj.js';
5
+ export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-CvKCWBvj.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-cKx59cIc.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-CT5PbMDJ.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
6
  var serverJs = require('@o2ter/server-js');
7
- var random = require('./internals/random-CDtFUuES.js');
7
+ var random = require('./internals/random-80Vpxbxh.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-BnDahEvz.js');
10
+ var index = require('./internals/index-BEK58Z0z.js');
11
11
  var index$1 = require('./internals/index-DRq6T_5w.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
@@ -82,9 +82,12 @@ const normalize = (x) => {
82
82
  // THE SOFTWARE.
83
83
  //
84
84
  const fetchUserPerms = async (proto) => _.uniq(_.compact([..._.map(await proto.currentRoles(), x => `role:${x}`), (await proto.currentUser())?.objectId]));
85
- const dispatcher = (proto, options, disableSecurity) => {
85
+ const dispatcher = (proto, options) => {
86
86
  const acls = async () => options.master ? [] : await fetchUserPerms(proto);
87
- const validator = async () => new random.QueryValidator(proto, await acls(), options.master ?? false, disableSecurity);
87
+ const validator = async () => new random.QueryValidator(proto, await acls(), {
88
+ master: options.master ?? false,
89
+ disableSecurity: options.disableSecurity,
90
+ });
88
91
  return {
89
92
  async explain(query) {
90
93
  random.QueryValidator.recursiveCheck(query);
@@ -318,11 +321,17 @@ class _ProtoQuery extends index.TQuery {
318
321
  };
319
322
  }
320
323
  _dispatcher(options) {
324
+ const schema = this._proto.schema[this.className];
325
+ if (_.isNil(schema))
326
+ throw Error('Invalid className');
321
327
  if (this._opts.insecure) {
322
328
  if (options?.master !== true)
323
329
  throw Error('No permission');
324
330
  }
325
- return dispatcher(_serviceOf(options) ?? this._proto, options ?? {}, !!this._opts.insecure);
331
+ return dispatcher(_serviceOf(options) ?? this._proto, {
332
+ ...options ?? {},
333
+ disableSecurity: !!this._opts.insecure,
334
+ });
326
335
  }
327
336
  explain(options) {
328
337
  return this._dispatcher(options).explain(this._queryOptions);
@@ -728,6 +737,8 @@ const validateForeignField = (schema, key, dataType) => {
728
737
  throw Error(`Invalid foreign field: ${key}`);
729
738
  };
730
739
  const validateShapedObject = (schema, dataType) => {
740
+ if (_.isEmpty(dataType.shape))
741
+ throw Error('Invalid empty shape');
731
742
  for (const [key, type] of _.entries(dataType.shape)) {
732
743
  if (!key.match(random.QueryValidator.patterns.name))
733
744
  throw Error(`Invalid field name: ${key}`);
@@ -1302,7 +1313,8 @@ const fetchSessionInfo = async (proto, userId) => {
1302
1313
  const cache = userCacheMap.get(proto[_private.PVK]);
1303
1314
  if (_.isNil(cache[userId]))
1304
1315
  cache[userId] = (async () => {
1305
- const user = _.isString(userId) ? await proto.Query('User').get(userId, { master: true }) : undefined;
1316
+ const _user = _.isString(userId) ? await proto.Query('User').get(userId, { master: true }) : undefined;
1317
+ const user = proto.req ? await proto[_private.PVK].options.userResolver(proto, _user) : _user;
1306
1318
  const _roles = user instanceof index.TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
1307
1319
  cache[userId] = undefined;
1308
1320
  return { user, _roles };
@@ -1454,6 +1466,7 @@ class ProtoService extends index.ProtoType {
1454
1466
  constructor(options) {
1455
1467
  super();
1456
1468
  this[_private.PVK] = new ProtoInternal({
1469
+ userResolver: (_req, user) => user,
1457
1470
  roleResolver: {},
1458
1471
  objectIdSize: 10,
1459
1472
  maxFetchLimit: 1000,