proto.io 0.0.147 → 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))
@@ -928,31 +934,16 @@ class ProtoInternal {
928
934
  }
929
935
  }
930
936
  async saveFile(proto, object, options) {
931
- const beforeSave = this.triggers?.beforeSaveFile;
932
- const afterSave = this.triggers?.afterSaveFile;
933
- const context = options?.context ?? {};
934
- if (_.isFunction(beforeSave)) {
935
- await beforeSave(proxy(Object.setPrototypeOf({ object, context }, proto)));
936
- }
937
937
  if (object.objectId) {
938
938
  object = await this.updateFile(proto, object, options);
939
939
  }
940
940
  else {
941
941
  object = await this.createFile(proto, object, options);
942
942
  }
943
- if (_.isFunction(afterSave)) {
944
- await afterSave(proxy(Object.setPrototypeOf({ object, context }, proto)));
945
- }
946
943
  return object;
947
944
  }
948
945
  async deleteFile(proto, object, options) {
949
- const beforeDelete = this.triggers?.beforeDeleteFile;
950
- const afterDelete = this.triggers?.afterDeleteFile;
951
946
  object = await object.fetchIfNeeded(['token'], options);
952
- const context = options?.context ?? {};
953
- if (_.isFunction(beforeDelete)) {
954
- await beforeDelete(proxy(Object.setPrototypeOf({ object, context }, proto)));
955
- }
956
947
  const deleted = await proto.Query('File')
957
948
  .equalTo('_id', object.objectId)
958
949
  .deleteOne(options);
@@ -962,9 +953,6 @@ class ProtoInternal {
962
953
  object[_private.PVK].extra = {};
963
954
  }
964
955
  this.destroyFileData(proto, object.token);
965
- if (_.isFunction(afterDelete)) {
966
- await afterDelete(proxy(Object.setPrototypeOf({ object, context }, proto)));
967
- }
968
956
  return object;
969
957
  }
970
958
  fileData(proto, object, options) {
@@ -1412,18 +1400,6 @@ class ProtoService extends index.ProtoType {
1412
1400
  this[_private.PVK].triggers.afterDelete = {};
1413
1401
  this[_private.PVK].triggers.afterDelete[name] = callback;
1414
1402
  }
1415
- beforeSaveFile(callback) {
1416
- this[_private.PVK].triggers.beforeSaveFile = callback;
1417
- }
1418
- afterSaveFile(callback) {
1419
- this[_private.PVK].triggers.afterSaveFile = callback;
1420
- }
1421
- beforeDeleteFile(callback) {
1422
- this[_private.PVK].triggers.beforeDeleteFile = callback;
1423
- }
1424
- afterDeleteFile(callback) {
1425
- this[_private.PVK].triggers.afterDeleteFile = callback;
1426
- }
1427
1403
  lockTable(className, update) {
1428
1404
  return this.storage.lockTable(className, update);
1429
1405
  }
@@ -1590,11 +1566,11 @@ var classesRoute = (router, proto) => {
1590
1566
  if (!_.includes(classes, name))
1591
1567
  return res.sendStatus(404);
1592
1568
  await response(res, async () => {
1593
- 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);
1594
1570
  const payload = proto.connect(req);
1595
1571
  const query = payload.Query(name);
1596
1572
  query[_private.PVK].options = options;
1597
- const opts = { master: payload.isMaster, context };
1573
+ const opts = { master: payload.isMaster, context, silent };
1598
1574
  switch (operation) {
1599
1575
  case 'explain':
1600
1576
  if (!payload.isMaster)