proto.io 0.0.146 → 0.0.148

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.
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-BWztjrw_.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BDB4idmt.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-CvfRsxEZ.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-D4VXQ1FB.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-BWztjrw_.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BDB4idmt.js';
1
+ import { P as ProtoService } from '../../internals/index-CvfRsxEZ.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-D4VXQ1FB.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-BWztjrw_.js';
4
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BDB4idmt.js';
3
+ import { P as ProtoService } from '../../internals/index-CvfRsxEZ.js';
4
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-D4VXQ1FB.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, o as EventData, T as TSchema, q as DecodedQuery, F as FindOptions, Q as QuerySelector, r as DecodedSortOption, I as InsertOptions, t as TValue, u as FindOneOptions, v as TUpdateOp, w as FieldSelectorExpression, x as QueryExpression, y as TStorage, z as TransactionOptions, h as TObject, A as TQueryRandomOptions, B as TPubSub } from '../../internals/index-BWztjrw_.js';
2
+ import { _ as _TValue, o as EventData, T as TSchema, q as DecodedQuery, F as FindOptions, Q as QuerySelector, r as DecodedSortOption, I as InsertOptions, t as TValue, u as FindOneOptions, v as TUpdateOp, w as FieldSelectorExpression, x as QueryExpression, y as TStorage, z as TransactionOptions, h as TObject, A as TQueryRandomOptions, B as TPubSub } from '../../internals/index-CvfRsxEZ.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-bbPCIbir.js';
2
- export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-bbPCIbir.js';
1
+ import { P as ProtoClient } from './internals/index-BAB_APmb.js';
2
+ export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-BAB_APmb.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-BWztjrw_.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-CvfRsxEZ.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-CT01T3qs.js');
5
+ var index = require('./internals/index-tNCIyuCp.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('./internals/index-C6zdNpc_.js');
8
8
  require('lodash');
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as ProtoClient } from './internals/index-Do-zNOpD.mjs';
2
- export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-Do-zNOpD.mjs';
1
+ import { c as ProtoClient } from './internals/index-DGau0Wqf.mjs';
2
+ export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-DGau0Wqf.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import './internals/index-EOtjV6U_.mjs';
5
5
  import 'lodash';
package/dist/index.d.ts CHANGED
@@ -2,11 +2,11 @@ import * as socket_io from 'socket.io';
2
2
  import * as socket_io_dist_typed_events from 'socket.io/dist/typed-events';
3
3
  import * as express_serve_static_core from 'express-serve-static-core';
4
4
  import { Server, RequestHandler } from '@o2ter/server-js';
5
- import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-BWztjrw_.js';
6
- export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BWztjrw_.js';
5
+ import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-CvfRsxEZ.js';
6
+ export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-CvfRsxEZ.js';
7
7
  import Decimal from 'decimal.js';
8
8
  export { Decimal } from 'decimal.js';
9
- 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-bbPCIbir.js';
9
+ 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-BAB_APmb.js';
10
10
  import '@o2ter/utils-js';
11
11
  import 'jsonwebtoken';
12
12
  import 'lodash';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var serverJs = require('@o2ter/server-js');
7
7
  var random = require('./internals/random-XGNkddOu.js');
8
8
  var _private = require('./internals/private-CSB1Ep4g.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-CT01T3qs.js');
10
+ var index = require('./internals/index-tNCIyuCp.js');
11
11
  var index$1 = require('./internals/index-C6zdNpc_.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
@@ -319,9 +319,10 @@ class ProtoQuery extends index.TQuery {
319
319
  });
320
320
  }
321
321
  async insert(attrs, options) {
322
- const beforeSave = this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
323
- const afterSave = this._proto[_private.PVK].triggers?.afterSave?.[this.className];
324
322
  const context = options?.context ?? {};
323
+ const silent = _.castArray(options?.silent ?? []);
324
+ const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
325
+ const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
325
326
  const object = this._proto.Object(this.className);
326
327
  for (const [key, value] of _.toPairs(attrs)) {
327
328
  object[_private.PVK].mutated[key] = { $set: value };
@@ -341,9 +342,10 @@ class ProtoQuery extends index.TQuery {
341
342
  return result;
342
343
  }
343
344
  async insertMany(values, options) {
344
- const beforeSave = this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
345
- const afterSave = this._proto[_private.PVK].triggers?.afterSave?.[this.className];
346
345
  const context = options?.context ?? {};
346
+ const silent = _.castArray(options?.silent ?? []);
347
+ const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
348
+ const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
347
349
  if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
348
350
  const objects = _.map(values, attr => {
349
351
  const object = this._proto.Object(this.className);
@@ -374,9 +376,10 @@ class ProtoQuery extends index.TQuery {
374
376
  }, values);
375
377
  }
376
378
  async updateOne(update, options) {
377
- const beforeSave = this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
378
- const afterSave = this._proto[_private.PVK].triggers?.afterSave?.[this.className];
379
379
  const context = options?.context ?? {};
380
+ const silent = _.castArray(options?.silent ?? []);
381
+ const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
382
+ const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
380
383
  if (_.isFunction(beforeSave)) {
381
384
  const object = this._objectMethods(_.first(await utilsJs.asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
382
385
  if (!object)
@@ -392,9 +395,10 @@ class ProtoQuery extends index.TQuery {
392
395
  return result;
393
396
  }
394
397
  async upsertOne(update, setOnInsert, options) {
395
- const beforeSave = this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
396
- const afterSave = this._proto[_private.PVK].triggers?.afterSave?.[this.className];
397
398
  const context = options?.context ?? {};
399
+ const silent = _.castArray(options?.silent ?? []);
400
+ const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[_private.PVK].triggers?.beforeSave?.[this.className];
401
+ const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[_private.PVK].triggers?.afterSave?.[this.className];
398
402
  if (_.isFunction(beforeSave)) {
399
403
  let object = this._objectMethods(_.first(await utilsJs.asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
400
404
  if (object) {
@@ -429,9 +433,10 @@ class ProtoQuery extends index.TQuery {
429
433
  return result;
430
434
  }
431
435
  async deleteOne(options) {
432
- const beforeDelete = this._proto[_private.PVK].triggers?.beforeDelete?.[this.className];
433
- const afterDelete = this._proto[_private.PVK].triggers?.afterDelete?.[this.className];
434
436
  const context = options?.context ?? {};
437
+ const silent = _.castArray(options?.silent ?? []);
438
+ const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[_private.PVK].triggers?.beforeDelete?.[this.className];
439
+ const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[_private.PVK].triggers?.afterDelete?.[this.className];
435
440
  let result;
436
441
  if (_.isFunction(beforeDelete)) {
437
442
  const object = this._objectMethods(_.first(await utilsJs.asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
@@ -452,9 +457,10 @@ class ProtoQuery extends index.TQuery {
452
457
  return result;
453
458
  }
454
459
  async deleteMany(options) {
455
- const beforeDelete = this._proto[_private.PVK].triggers?.beforeDelete?.[this.className];
456
- const afterDelete = this._proto[_private.PVK].triggers?.afterDelete?.[this.className];
457
460
  const context = options?.context ?? {};
461
+ const silent = _.castArray(options?.silent ?? []);
462
+ const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[_private.PVK].triggers?.beforeDelete?.[this.className];
463
+ const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[_private.PVK].triggers?.afterDelete?.[this.className];
458
464
  if (_.isFunction(beforeDelete) || _.isFunction(afterDelete)) {
459
465
  const objects = this._objectMethods(await utilsJs.asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
460
466
  if (_.isEmpty(objects))
@@ -800,14 +806,16 @@ class ProtoInternal {
800
806
  return func(proxy(payload ?? proto));
801
807
  const { callback, validator } = func;
802
808
  const roles = await proto.currentRoles();
803
- if (!!validator?.requireUser && !(await proto.currentUser()))
804
- throw Error('No permission');
805
- if (!!validator?.requireMaster && !options?.master)
806
- throw Error('No permission');
807
- if (_.isArray(validator?.requireAnyUserRoles) && !_.some(validator?.requireAnyUserRoles, x => _.includes(roles, x)))
808
- throw Error('No permission');
809
- if (_.isArray(validator?.requireAllUserRoles) && _.some(validator?.requireAllUserRoles, x => !_.includes(roles, x)))
810
- throw Error('No permission');
809
+ if (!options?.master) {
810
+ if (!!validator?.requireUser && !(await proto.currentUser()))
811
+ throw Error('No permission');
812
+ if (!!validator?.requireMaster)
813
+ throw Error('No permission');
814
+ if (_.isArray(validator?.requireAnyUserRoles) && !_.some(validator?.requireAnyUserRoles, x => _.includes(roles, x)))
815
+ throw Error('No permission');
816
+ if (_.isArray(validator?.requireAllUserRoles) && _.some(validator?.requireAllUserRoles, x => !_.includes(roles, x)))
817
+ throw Error('No permission');
818
+ }
811
819
  return callback(proxy(payload ?? proto));
812
820
  }
813
821
  async varifyPassword(proto, user, password, options) {
@@ -926,31 +934,16 @@ class ProtoInternal {
926
934
  }
927
935
  }
928
936
  async saveFile(proto, object, options) {
929
- const beforeSave = this.triggers?.beforeSaveFile;
930
- const afterSave = this.triggers?.afterSaveFile;
931
- const context = options?.context ?? {};
932
- if (_.isFunction(beforeSave)) {
933
- await beforeSave(proxy(Object.setPrototypeOf({ object, context }, proto)));
934
- }
935
937
  if (object.objectId) {
936
938
  object = await this.updateFile(proto, object, options);
937
939
  }
938
940
  else {
939
941
  object = await this.createFile(proto, object, options);
940
942
  }
941
- if (_.isFunction(afterSave)) {
942
- await afterSave(proxy(Object.setPrototypeOf({ object, context }, proto)));
943
- }
944
943
  return object;
945
944
  }
946
945
  async deleteFile(proto, object, options) {
947
- const beforeDelete = this.triggers?.beforeDeleteFile;
948
- const afterDelete = this.triggers?.afterDeleteFile;
949
946
  object = await object.fetchIfNeeded(['token'], options);
950
- const context = options?.context ?? {};
951
- if (_.isFunction(beforeDelete)) {
952
- await beforeDelete(proxy(Object.setPrototypeOf({ object, context }, proto)));
953
- }
954
947
  const deleted = await proto.Query('File')
955
948
  .equalTo('_id', object.objectId)
956
949
  .deleteOne(options);
@@ -960,9 +953,6 @@ class ProtoInternal {
960
953
  object[_private.PVK].extra = {};
961
954
  }
962
955
  this.destroyFileData(proto, object.token);
963
- if (_.isFunction(afterDelete)) {
964
- await afterDelete(proxy(Object.setPrototypeOf({ object, context }, proto)));
965
- }
966
956
  return object;
967
957
  }
968
958
  fileData(proto, object, options) {
@@ -1410,18 +1400,6 @@ class ProtoService extends index.ProtoType {
1410
1400
  this[_private.PVK].triggers.afterDelete = {};
1411
1401
  this[_private.PVK].triggers.afterDelete[name] = callback;
1412
1402
  }
1413
- beforeSaveFile(callback) {
1414
- this[_private.PVK].triggers.beforeSaveFile = callback;
1415
- }
1416
- afterSaveFile(callback) {
1417
- this[_private.PVK].triggers.afterSaveFile = callback;
1418
- }
1419
- beforeDeleteFile(callback) {
1420
- this[_private.PVK].triggers.beforeDeleteFile = callback;
1421
- }
1422
- afterDeleteFile(callback) {
1423
- this[_private.PVK].triggers.afterDeleteFile = callback;
1424
- }
1425
1403
  lockTable(className, update) {
1426
1404
  return this.storage.lockTable(className, update);
1427
1405
  }
@@ -1588,11 +1566,11 @@ var classesRoute = (router, proto) => {
1588
1566
  if (!_.includes(classes, name))
1589
1567
  return res.sendStatus(404);
1590
1568
  await response(res, async () => {
1591
- const { operation, context, random, attributes, update, setOnInsert, ...options } = index.deserialize(req.body);
1569
+ const { operation, context, silent, random, attributes, update, setOnInsert, ...options } = index.deserialize(req.body);
1592
1570
  const payload = proto.connect(req);
1593
1571
  const query = payload.Query(name);
1594
1572
  query[_private.PVK].options = options;
1595
- const opts = { master: payload.isMaster, context };
1573
+ const opts = { master: payload.isMaster, context, silent };
1596
1574
  switch (operation) {
1597
1575
  case 'explain':
1598
1576
  if (!payload.isMaster)