proto.io 0.0.173 → 0.0.175

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 (48) hide show
  1. package/dist/adapters/file/database.d.ts +2 -2
  2. package/dist/adapters/file/database.js +2 -2
  3. package/dist/adapters/file/database.mjs +2 -2
  4. package/dist/adapters/file/filesystem.d.ts +2 -2
  5. package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
  6. package/dist/adapters/storage/progres.d.ts +2 -2
  7. package/dist/adapters/storage/progres.js +3 -3
  8. package/dist/adapters/storage/progres.js.map +1 -1
  9. package/dist/adapters/storage/progres.mjs +3 -3
  10. package/dist/adapters/storage/progres.mjs.map +1 -1
  11. package/dist/client.d.ts +3 -3
  12. package/dist/client.js +2 -2
  13. package/dist/client.mjs +3 -3
  14. package/dist/index.d.ts +75 -3
  15. package/dist/index.js +121 -261
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +123 -263
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/internals/{index-Cpv1DoEI.d.ts → index-B9CWU0y7.d.ts} +32 -2
  20. package/dist/internals/index-B9CWU0y7.d.ts.map +1 -0
  21. package/dist/internals/{index-BZNPlw1L.mjs → index-BPbXumUi.mjs} +286 -44
  22. package/dist/internals/index-BPbXumUi.mjs.map +1 -0
  23. package/dist/internals/{index-BJnQhKf3.d.ts → index-BQqYdjaH.d.ts} +2 -2
  24. package/dist/internals/index-BQqYdjaH.d.ts.map +1 -0
  25. package/dist/internals/{index-lX-M76Tn.d.ts → index-BYZpj31o.d.ts} +1062 -33
  26. package/dist/internals/index-BYZpj31o.d.ts.map +1 -0
  27. package/dist/internals/{index-BYbMU-Ao.mjs → index-CTsc042s.mjs} +140 -2
  28. package/dist/internals/index-CTsc042s.mjs.map +1 -0
  29. package/dist/internals/{index-CIecB6mS.js → index-CvA0tbwx.js} +286 -44
  30. package/dist/internals/index-CvA0tbwx.js.map +1 -0
  31. package/dist/internals/{index-B1wqSio6.mjs → index-DHQhYGsJ.mjs} +2 -2
  32. package/dist/internals/{index-B1wqSio6.mjs.map → index-DHQhYGsJ.mjs.map} +1 -1
  33. package/dist/internals/{index-CVutVPmd.js → index-DXuW8UiB.js} +139 -1
  34. package/dist/internals/index-DXuW8UiB.js.map +1 -0
  35. package/dist/internals/{index-CzfsyXvb.js → index-Dc3V_Bzw.js} +2 -2
  36. package/dist/internals/{index-CzfsyXvb.js.map → index-Dc3V_Bzw.js.map} +1 -1
  37. package/dist/internals/{random-BCpwYpyw.mjs → random-BMQpRlGH.mjs} +3 -3
  38. package/dist/internals/{random-BCpwYpyw.mjs.map → random-BMQpRlGH.mjs.map} +1 -1
  39. package/dist/internals/{random-Dytum6Nh.js → random-DVOUDDGg.js} +3 -3
  40. package/dist/internals/{random-Dytum6Nh.js.map → random-DVOUDDGg.js.map} +1 -1
  41. package/package.json +1 -1
  42. package/dist/internals/index-BJnQhKf3.d.ts.map +0 -1
  43. package/dist/internals/index-BYbMU-Ao.mjs.map +0 -1
  44. package/dist/internals/index-BZNPlw1L.mjs.map +0 -1
  45. package/dist/internals/index-CIecB6mS.js.map +0 -1
  46. package/dist/internals/index-CVutVPmd.js.map +0 -1
  47. package/dist/internals/index-Cpv1DoEI.d.ts.map +0 -1
  48. package/dist/internals/index-lX-M76Tn.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,18 +1,18 @@
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-BCpwYpyw.mjs';
3
+ import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-BMQpRlGH.mjs';
4
4
  import { P as PVK } from './internals/private-BUpLAMZi.mjs';
5
- import { prototypes, asyncStream, asyncIterableToArray, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
6
- import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-BZNPlw1L.mjs';
7
- export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-BZNPlw1L.mjs';
8
- import { i as isPointer, a as isRelation, d as decodeUpdateOp, T as TObject, b as isShape, c as defaultObjectKeyTypes, e as isPrimitive } from './internals/index-BYbMU-Ao.mjs';
5
+ import { asyncStream, prototypes, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
6
+ import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-BPbXumUi.mjs';
7
+ export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-BPbXumUi.mjs';
8
+ import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-CTsc042s.mjs';
9
9
  import jwt from 'jsonwebtoken';
10
10
  import { Blob } from 'node:buffer';
11
11
  import { Readable } from 'node:stream';
12
12
  import { scrypt } from 'node:crypto';
13
13
  import { promisify } from 'util';
14
14
  import { randomBytes, randomUUID } from '@o2ter/crypto-js';
15
- import { Q as QuerySelector } from './internals/index-B1wqSio6.mjs';
15
+ import { Q as QuerySelector } from './internals/index-DHQhYGsJ.mjs';
16
16
  import queryType from 'query-types';
17
17
  import busboy from 'busboy';
18
18
  export { Decimal } from 'decimal.js';
@@ -245,46 +245,6 @@ const dispatcher = (proto, options, disableSecurity) => {
245
245
  };
246
246
  };
247
247
 
248
- //
249
- // proxy.ts
250
- //
251
- // The MIT License
252
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
253
- //
254
- // Permission is hereby granted, free of charge, to any person obtaining a copy
255
- // of this software and associated documentation files (the "Software"), to deal
256
- // in the Software without restriction, including without limitation the rights
257
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
258
- // copies of the Software, and to permit persons to whom the Software is
259
- // furnished to do so, subject to the following conditions:
260
- //
261
- // The above copyright notice and this permission notice shall be included in
262
- // all copies or substantial portions of the Software.
263
- //
264
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
265
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
266
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
267
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
268
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
269
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
270
- // THE SOFTWARE.
271
- //
272
- const proxy = (x) => {
273
- const self = x;
274
- const proxy = _.create(self);
275
- for (const name of _.uniq(_.flatMap(prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
276
- if (name === 'constructor')
277
- continue;
278
- if (_.isFunction(self[name])) {
279
- proxy[name] = self[name].bind(self);
280
- }
281
- else {
282
- Object.defineProperty(proxy, name, { get: () => self[name] });
283
- }
284
- }
285
- return proxy;
286
- };
287
-
288
248
  //
289
249
  // options.ts
290
250
  //
@@ -391,56 +351,16 @@ class _ProtoQuery extends TQuery {
391
351
  });
392
352
  }
393
353
  async insert(attrs, options) {
394
- const context = options?.context ?? {};
395
- const silent = _.castArray(options?.silent ?? []);
396
- const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
397
- const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
398
- const object = this._proto.Object(this.className);
399
- for (const [key, value] of _.toPairs(attrs)) {
400
- object[PVK].mutated[key] = { $set: value };
401
- }
402
- if (_.isFunction(beforeSave))
403
- await beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
404
354
  const result = this._objectMethods(await this._dispatcher(options).insert({
405
355
  className: this.className,
406
356
  includes: this[PVK].options.includes,
407
357
  matches: this[PVK].options.matches,
408
- }, _.fromPairs([...object._set_entries()])));
358
+ }, attrs));
409
359
  if (!result)
410
360
  throw Error('Unable to insert document');
411
- if (_.isFunction(afterSave)) {
412
- await afterSave(proxy(Object.setPrototypeOf({ object: result, context }, options?.session ?? this._proto)));
413
- }
414
361
  return result;
415
362
  }
416
363
  async insertMany(values, options) {
417
- const context = options?.context ?? {};
418
- const silent = _.castArray(options?.silent ?? []);
419
- const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
420
- const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
421
- if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
422
- const objects = _.map(values, attr => {
423
- const object = this._proto.Object(this.className);
424
- for (const [key, value] of _.toPairs(attr)) {
425
- object[PVK].mutated[key] = { $set: value };
426
- }
427
- return object;
428
- });
429
- if (_.isEmpty(objects))
430
- return 0;
431
- if (_.isFunction(beforeSave)) {
432
- await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
433
- }
434
- await this._dispatcher(options).insertMany({
435
- className: this.className,
436
- includes: this[PVK].options.includes,
437
- matches: this[PVK].options.matches,
438
- }, _.map(objects, x => _.fromPairs([...x._set_entries()])));
439
- if (_.isFunction(afterSave)) {
440
- await Promise.all(_.map(objects, object => afterSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
441
- }
442
- return objects.length;
443
- }
444
364
  return this._dispatcher(options).insertMany({
445
365
  className: this.className,
446
366
  includes: this[PVK].options.includes,
@@ -448,175 +368,24 @@ class _ProtoQuery extends TQuery {
448
368
  }, values);
449
369
  }
450
370
  async updateOne(update, options) {
451
- const context = options?.context ?? {};
452
- const silent = _.castArray(options?.silent ?? []);
453
- const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
454
- const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
455
- if (_.isFunction(beforeSave)) {
456
- const object = this._objectMethods(_.first(await asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
457
- if (!object)
458
- return undefined;
459
- object[PVK].mutated = update;
460
- await beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
461
- update = object[PVK].mutated;
462
- }
463
- const result = this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
464
- if (result && _.isFunction(afterSave)) {
465
- await afterSave(proxy(Object.setPrototypeOf({ object: result, context }, options?.session ?? this._proto)));
466
- }
467
- return result;
371
+ return this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
468
372
  }
469
373
  async updateMany(update, options) {
470
- const context = options?.context ?? {};
471
- const silent = _.castArray(options?.silent ?? []);
472
- const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
473
- const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
474
- if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
475
- const objects = this._objectMethods(await asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
476
- if (_.isEmpty(objects))
477
- return 0;
478
- if (_.isFunction(beforeSave)) {
479
- await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
480
- }
481
- if (!_.isFunction(afterSave)) {
482
- return this._dispatcher(options).updateMany({
483
- ...this._queryOptions,
484
- filter: { _id: { $in: _.map(objects, x => x.objectId) } },
485
- }, update);
486
- }
487
- const updated = await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
488
- ...this._queryOptions,
489
- filter: { _id: { $eq: x.objectId } },
490
- }, update)));
491
- await Promise.all(_.map(updated, object => afterSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
492
- return updated.length;
493
- }
494
374
  return this._dispatcher(options).updateMany(this._queryOptions, update);
495
375
  }
496
376
  async upsertOne(update, setOnInsert, options) {
497
- const context = options?.context ?? {};
498
- const silent = _.castArray(options?.silent ?? []);
499
- const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
500
- const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
501
- if (_.isFunction(beforeSave)) {
502
- let object = this._objectMethods(_.first(await asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
503
- if (object) {
504
- object[PVK].mutated = update;
505
- }
506
- else {
507
- object = this._proto.Object(this.className);
508
- for (const [key, value] of _.toPairs(setOnInsert)) {
509
- object[PVK].mutated[key] = { $set: value };
510
- }
511
- }
512
- await beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
513
- if (object.objectId) {
514
- update = object[PVK].mutated;
515
- }
516
- else {
517
- setOnInsert = {};
518
- for (const [key, update] of _.toPairs(object[PVK].mutated)) {
519
- const [op, value] = decodeUpdateOp(update);
520
- if (op === '$set') {
521
- setOnInsert[key] = value;
522
- }
523
- }
524
- }
525
- }
526
377
  const result = this._objectMethods(await this._dispatcher(options).upsertOne(this._queryOptions, update, setOnInsert));
527
378
  if (!result)
528
379
  throw Error('Unable to upsert document');
529
- if (_.isFunction(afterSave)) {
530
- await afterSave(proxy(Object.setPrototypeOf({ object: result, context }, options?.session ?? this._proto)));
531
- }
532
380
  return result;
533
381
  }
534
382
  async upsertMany(update, setOnInsert, options) {
535
- const context = options?.context ?? {};
536
- const silent = _.castArray(options?.silent ?? []);
537
- const beforeSave = _.includes(silent, 'beforeSave') ? null : this._proto[PVK].triggers?.beforeSave?.[this.className];
538
- const afterSave = _.includes(silent, 'afterSave') ? null : this._proto[PVK].triggers?.afterSave?.[this.className];
539
- if (_.isFunction(beforeSave) || _.isFunction(afterSave)) {
540
- const objects = this._objectMethods(await asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
541
- if (!_.isEmpty(objects) && _.isFunction(beforeSave)) {
542
- await Promise.all(_.map(objects, object => beforeSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
543
- }
544
- if (_.isEmpty(objects)) {
545
- const result = await this._dispatcher(options).insert({
546
- className: this.className,
547
- includes: this[PVK].options.includes,
548
- matches: this[PVK].options.matches,
549
- }, setOnInsert);
550
- if (!result)
551
- throw Error('Unable to insert document');
552
- if (_.isFunction(afterSave)) {
553
- await afterSave(proxy(Object.setPrototypeOf({ object: result, context }, options?.session ?? this._proto)));
554
- }
555
- return { updated: 0, inserted: 1 };
556
- }
557
- if (!_.isFunction(afterSave)) {
558
- return {
559
- inserted: 0,
560
- updated: await this._dispatcher(options).updateMany({
561
- ...this._queryOptions,
562
- filter: { _id: { $in: _.map(objects, x => x.objectId) } },
563
- }, update),
564
- };
565
- }
566
- const updated = await Promise.all(_.map(objects, x => this._dispatcher(options).updateOne({
567
- ...this._queryOptions,
568
- filter: { _id: { $eq: x.objectId } },
569
- }, update)));
570
- await Promise.all(_.map(updated, object => afterSave(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
571
- return { updated: updated.length, inserted: 0 };
572
- }
573
383
  return this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert);
574
384
  }
575
385
  async deleteOne(options) {
576
- const context = options?.context ?? {};
577
- const silent = _.castArray(options?.silent ?? []);
578
- const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[PVK].triggers?.beforeDelete?.[this.className];
579
- const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[PVK].triggers?.afterDelete?.[this.className];
580
- let result;
581
- if (_.isFunction(beforeDelete)) {
582
- const object = this._objectMethods(_.first(await asyncIterableToArray(this._dispatcher(options).find({ ...this._queryOptions, limit: 1 }))));
583
- if (!object)
584
- return undefined;
585
- await beforeDelete(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)));
586
- result = this._objectMethods(await this._dispatcher(options).deleteOne({
587
- ...this._queryOptions,
588
- filter: { _id: { $eq: object.objectId } },
589
- }));
590
- }
591
- else {
592
- result = this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
593
- }
594
- if (result && _.isFunction(afterDelete)) {
595
- await afterDelete(proxy(Object.setPrototypeOf({ object: result, context }, options?.session ?? this._proto)));
596
- }
597
- return result;
386
+ return this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
598
387
  }
599
388
  async deleteMany(options) {
600
- const context = options?.context ?? {};
601
- const silent = _.castArray(options?.silent ?? []);
602
- const beforeDelete = _.includes(silent, 'beforeDelete') ? null : this._proto[PVK].triggers?.beforeDelete?.[this.className];
603
- const afterDelete = _.includes(silent, 'afterDelete') ? null : this._proto[PVK].triggers?.afterDelete?.[this.className];
604
- if (_.isFunction(beforeDelete) || _.isFunction(afterDelete)) {
605
- const objects = this._objectMethods(await asyncIterableToArray(this._dispatcher(options).find(this._queryOptions)));
606
- if (_.isEmpty(objects))
607
- return 0;
608
- if (_.isFunction(beforeDelete)) {
609
- await Promise.all(_.map(objects, object => beforeDelete(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
610
- }
611
- await this._dispatcher(options).deleteMany({
612
- ...this._queryOptions,
613
- filter: { _id: { $in: _.map(objects, x => x.objectId) } },
614
- });
615
- if (_.isFunction(afterDelete)) {
616
- await Promise.all(_.map(objects, object => afterDelete(proxy(Object.setPrototypeOf({ object, context }, options?.session ?? this._proto)))));
617
- }
618
- return objects.length;
619
- }
620
389
  return this._dispatcher(options).deleteMany(this._queryOptions);
621
390
  }
622
391
  }
@@ -817,6 +586,46 @@ const varifyPassword = async (alg, password, options) => {
817
586
  }
818
587
  };
819
588
 
589
+ //
590
+ // proxy.ts
591
+ //
592
+ // The MIT License
593
+ // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
594
+ //
595
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
596
+ // of this software and associated documentation files (the "Software"), to deal
597
+ // in the Software without restriction, including without limitation the rights
598
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
599
+ // copies of the Software, and to permit persons to whom the Software is
600
+ // furnished to do so, subject to the following conditions:
601
+ //
602
+ // The above copyright notice and this permission notice shall be included in
603
+ // all copies or substantial portions of the Software.
604
+ //
605
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
606
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
607
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
608
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
609
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
610
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
611
+ // THE SOFTWARE.
612
+ //
613
+ const proxy = (x) => {
614
+ const self = x;
615
+ const proxy = _.create(self);
616
+ for (const name of _.uniq(_.flatMap(prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
617
+ if (name === 'constructor')
618
+ continue;
619
+ if (_.isFunction(self[name])) {
620
+ proxy[name] = self[name].bind(self);
621
+ }
622
+ else {
623
+ Object.defineProperty(proxy, name, { get: () => self[name] });
624
+ }
625
+ }
626
+ return proxy;
627
+ };
628
+
820
629
  //
821
630
  // internal.ts
822
631
  //
@@ -937,7 +746,6 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
937
746
  class ProtoInternal {
938
747
  options;
939
748
  functions = {};
940
- triggers = {};
941
749
  constructor(options) {
942
750
  validateSchemaName(options.schema);
943
751
  const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
@@ -1614,26 +1422,6 @@ class ProtoService extends ProtoType {
1614
1422
  define(name, callback, options) {
1615
1423
  this[PVK].functions[name] = options ? { callback, ...options } : callback;
1616
1424
  }
1617
- beforeSave(name, callback) {
1618
- if (!this[PVK].triggers.beforeSave)
1619
- this[PVK].triggers.beforeSave = {};
1620
- this[PVK].triggers.beforeSave[name] = callback;
1621
- }
1622
- afterSave(name, callback) {
1623
- if (!this[PVK].triggers.afterSave)
1624
- this[PVK].triggers.afterSave = {};
1625
- this[PVK].triggers.afterSave[name] = callback;
1626
- }
1627
- beforeDelete(name, callback) {
1628
- if (!this[PVK].triggers.beforeDelete)
1629
- this[PVK].triggers.beforeDelete = {};
1630
- this[PVK].triggers.beforeDelete[name] = callback;
1631
- }
1632
- afterDelete(name, callback) {
1633
- if (!this[PVK].triggers.afterDelete)
1634
- this[PVK].triggers.afterDelete = {};
1635
- this[PVK].triggers.afterDelete[name] = callback;
1636
- }
1637
1425
  lockTable(className, update) {
1638
1426
  return this.storage.lockTable(className, update);
1639
1427
  }
@@ -1830,12 +1618,12 @@ const verifyRelatedBy = (relatedBy) => {
1830
1618
  var classesRoute = (router, proto) => {
1831
1619
  const defaultHandler = async (req) => {
1832
1620
  const { name } = req.params;
1833
- const { operation, context, silent, random, attributes, update, setOnInsert, relatedBy, ...options } = deserialize(req.body);
1621
+ const { operation, random, attributes, update, setOnInsert, relatedBy, ...options } = deserialize(req.body);
1834
1622
  verifyRelatedBy(relatedBy);
1835
1623
  const payload = proto.connect(req);
1836
1624
  const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.objectId), relatedBy.key) : payload.Query(name);
1837
1625
  query[PVK].options = options;
1838
- const opts = { master: payload.isMaster, context, silent };
1626
+ const opts = { master: payload.isMaster };
1839
1627
  switch (operation) {
1840
1628
  case 'explain':
1841
1629
  if (!payload.isMaster)
@@ -2376,19 +2164,84 @@ var configRoute = (router, proto) => {
2376
2164
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2377
2165
  // THE SOFTWARE.
2378
2166
  //
2167
+ /**
2168
+ * Schema definition utility functions.
2169
+ */
2379
2170
  const schema = _.assign((x) => x, {
2171
+ /**
2172
+ * Defines a boolean schema.
2173
+ * @param defaultValue - The default value for the boolean.
2174
+ * @returns The boolean schema.
2175
+ */
2380
2176
  boolean: (defaultValue) => ({ type: 'boolean', default: defaultValue }),
2177
+ /**
2178
+ * Defines a number schema.
2179
+ * @param defaultValue - The default value for the number.
2180
+ * @returns The number schema.
2181
+ */
2381
2182
  number: (defaultValue) => ({ type: 'number', default: defaultValue }),
2183
+ /**
2184
+ * Defines a decimal schema.
2185
+ * @param defaultValue - The default value for the decimal.
2186
+ * @returns The decimal schema.
2187
+ */
2382
2188
  decimal: (defaultValue) => ({ type: 'decimal', default: defaultValue }),
2189
+ /**
2190
+ * Defines a string schema.
2191
+ * @param defaultValue - The default value for the string.
2192
+ * @returns The string schema.
2193
+ */
2383
2194
  string: (defaultValue) => ({ type: 'string', default: defaultValue }),
2195
+ /**
2196
+ * Defines a date schema.
2197
+ * @param defaultValue - The default value for the date.
2198
+ * @returns The date schema.
2199
+ */
2384
2200
  date: (defaultValue) => ({ type: 'date', default: defaultValue }),
2201
+ /**
2202
+ * Defines an object schema.
2203
+ * @param defaultValue - The default value for the object.
2204
+ * @returns The object schema.
2205
+ */
2385
2206
  object: (defaultValue) => ({ type: 'object', default: defaultValue }),
2207
+ /**
2208
+ * Defines an array schema.
2209
+ * @param defaultValue - The default value for the array.
2210
+ * @returns The array schema.
2211
+ */
2386
2212
  array: (defaultValue) => ({ type: 'array', default: defaultValue }),
2213
+ /**
2214
+ * Defines a vector schema.
2215
+ * @param dimension - The dimension of the vector.
2216
+ * @param defaultValue - The default value for the vector.
2217
+ * @returns The vector schema.
2218
+ */
2387
2219
  vector: (dimension, defaultValue) => ({ type: 'vector', dimension, default: defaultValue }),
2220
+ /**
2221
+ * Defines a shape schema.
2222
+ * @param shape - The shape definition.
2223
+ * @returns The shape schema.
2224
+ */
2388
2225
  shape: (shape) => ({ type: 'shape', shape }),
2226
+ /**
2227
+ * Defines a pointer schema.
2228
+ * @param target - The target of the pointer.
2229
+ * @returns The pointer schema.
2230
+ */
2389
2231
  pointer: (target) => ({ type: 'pointer', target }),
2232
+ /**
2233
+ * Defines a relation schema.
2234
+ * @param target - The target of the relation.
2235
+ * @param foreignField - The foreign field of the relation.
2236
+ * @returns The relation schema.
2237
+ */
2390
2238
  relation: (target, foreignField) => ({ type: 'relation', target, foreignField }),
2391
2239
  });
2240
+ /**
2241
+ * Creates a ProtoRoute.
2242
+ * @param options - The options for the ProtoRoute.
2243
+ * @returns A promise that resolves to a Router.
2244
+ */
2392
2245
  const ProtoRoute = async (options) => {
2393
2246
  const proto = options.proto instanceof ProtoService ? options.proto : new ProtoService(options.proto);
2394
2247
  await proto[PVK].prepare();
@@ -2411,6 +2264,13 @@ const ProtoRoute = async (options) => {
2411
2264
  configRoute(router, proto);
2412
2265
  return router;
2413
2266
  };
2267
+ /**
2268
+ * Registers a ProtoSocket.
2269
+ * @param proto - The ProtoService instance.
2270
+ * @param server - The server instance.
2271
+ * @param endpoint - The optional endpoint.
2272
+ * @returns The socket.io instance.
2273
+ */
2414
2274
  const registerProtoSocket = (proto, server, endpoint) => {
2415
2275
  const io = endpoint ? server.socket().of(endpoint) : server.socket();
2416
2276
  io.on('connection', async (socket) => {