proto.io 0.0.172 → 0.0.174

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 (49) 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 +9 -2
  7. package/dist/adapters/storage/progres.js +58 -5
  8. package/dist/adapters/storage/progres.js.map +1 -1
  9. package/dist/adapters/storage/progres.mjs +58 -5
  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 +242 -12
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +243 -13
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/internals/{index-BYbMU-Ao.mjs → index--ifyu-GL.mjs} +139 -1
  20. package/dist/internals/index--ifyu-GL.mjs.map +1 -0
  21. package/dist/internals/{index-B1wqSio6.mjs → index-C3fbOqmn.mjs} +2 -2
  22. package/dist/internals/{index-B1wqSio6.mjs.map → index-C3fbOqmn.mjs.map} +1 -1
  23. package/dist/internals/index-CE5tdYK8.d.ts +1816 -0
  24. package/dist/internals/index-CE5tdYK8.d.ts.map +1 -0
  25. package/dist/internals/{index-K0jhERvZ.d.ts → index-CGX3qcjQ.d.ts} +2 -2
  26. package/dist/internals/index-CGX3qcjQ.d.ts.map +1 -0
  27. package/dist/internals/{index-CVutVPmd.js → index-DXuW8UiB.js} +139 -1
  28. package/dist/internals/index-DXuW8UiB.js.map +1 -0
  29. package/dist/internals/{index-CzfsyXvb.js → index-Dc3V_Bzw.js} +2 -2
  30. package/dist/internals/{index-CzfsyXvb.js.map → index-Dc3V_Bzw.js.map} +1 -1
  31. package/dist/internals/{index-D0hHgn2P.mjs → index-R0gbIGc-.mjs} +289 -2
  32. package/dist/internals/index-R0gbIGc-.mjs.map +1 -0
  33. package/dist/internals/{index-BJP46VGq.js → index-S_gTMQBh.js} +289 -2
  34. package/dist/internals/index-S_gTMQBh.js.map +1 -0
  35. package/dist/internals/{index-DchUjNEf.d.ts → index-uwXdnxqN.d.ts} +2 -2
  36. package/dist/internals/index-uwXdnxqN.d.ts.map +1 -0
  37. package/dist/internals/{random-BCpwYpyw.mjs → random-DPRG8oW6.mjs} +3 -3
  38. package/dist/internals/{random-BCpwYpyw.mjs.map → random-DPRG8oW6.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-BJP46VGq.js.map +0 -1
  43. package/dist/internals/index-BYbMU-Ao.mjs.map +0 -1
  44. package/dist/internals/index-BhWRmBiq.d.ts +0 -726
  45. package/dist/internals/index-BhWRmBiq.d.ts.map +0 -1
  46. package/dist/internals/index-CVutVPmd.js.map +0 -1
  47. package/dist/internals/index-D0hHgn2P.mjs.map +0 -1
  48. package/dist/internals/index-DchUjNEf.d.ts.map +0 -1
  49. package/dist/internals/index-K0jhERvZ.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-BhWRmBiq.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-K0jhERvZ.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-CE5tdYK8.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CGX3qcjQ.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -4,12 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
6
  var index = require('../../internals/index-BqFdBhFc.js');
7
- var index$1 = require('../../internals/index-CzfsyXvb.js');
7
+ var index$1 = require('../../internals/index-Dc3V_Bzw.js');
8
8
  var utilsJs = require('@o2ter/utils-js');
9
9
  require('util');
10
10
  require('zlib');
11
11
  require('../../internals/private-CSB1Ep4g.js');
12
- require('../../internals/index-CVutVPmd.js');
12
+ require('../../internals/index-DXuW8UiB.js');
13
13
  require('decimal.js');
14
14
 
15
15
  //
@@ -1,11 +1,11 @@
1
1
  import _ from 'lodash';
2
2
  import { F as FileStorageBase } from '../../internals/index-be1VYBY2.mjs';
3
- import { Q as QuerySelector } from '../../internals/index-B1wqSio6.mjs';
3
+ import { Q as QuerySelector } from '../../internals/index-C3fbOqmn.mjs';
4
4
  import { bufferToBase64, base64ToBuffer } from '@o2ter/utils-js';
5
5
  import 'util';
6
6
  import 'zlib';
7
7
  import '../../internals/private-BUpLAMZi.mjs';
8
- import '../../internals/index-BYbMU-Ao.mjs';
8
+ import '../../internals/index--ifyu-GL.mjs';
9
9
  import 'decimal.js';
10
10
 
11
11
  //
@@ -1,5 +1,5 @@
1
- import { P as ProtoService } from '../../internals/index-BhWRmBiq.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-K0jhERvZ.js';
1
+ import { P as ProtoService } from '../../internals/index-CE5tdYK8.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CGX3qcjQ.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-BhWRmBiq.js';
4
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-K0jhERvZ.js';
3
+ import { P as ProtoService } from '../../internals/index-CE5tdYK8.js';
4
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CGX3qcjQ.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 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-BhWRmBiq.js';
2
+ import { _ as _TValue, o as EventData, 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-CE5tdYK8.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
@@ -51,7 +51,7 @@ type Populate = {
51
51
  name: string;
52
52
  className: string;
53
53
  colname: string;
54
- type: TSchema.Relation;
54
+ type: 'pointer' | 'relation';
55
55
  foreignField?: string;
56
56
  subpaths: string[];
57
57
  filter?: QuerySelector;
@@ -106,7 +106,9 @@ declare class QueryCompiler {
106
106
  insert(options: InsertOptions, attrs: Record<string, TValue>): SQL;
107
107
  insertMany(options: InsertOptions, values: Record<string, TValue>[]): SQL;
108
108
  updateOne(query: DecodedQuery<FindOneOptions>, update: Record<string, TUpdateOp>): SQL;
109
+ updateMany(query: DecodedQuery<FindOneOptions>, update: Record<string, TUpdateOp>): SQL;
109
110
  upsertOne(query: DecodedQuery<FindOneOptions>, update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValue>): SQL;
111
+ upsertMany(query: DecodedQuery<FindOneOptions>, update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValue>): SQL;
110
112
  deleteOne(query: DecodedQuery<FindOneOptions>): SQL;
111
113
  deleteMany(query: DecodedQuery<FindOptions>): SQL;
112
114
  }
@@ -210,7 +212,12 @@ declare abstract class SqlStorage implements TStorage {
210
212
  insert(options: InsertOptions, attrs: Record<string, TValue>): Promise<TObject | undefined>;
211
213
  insertMany(options: InsertOptions, values: Record<string, TValue>[]): Promise<number>;
212
214
  updateOne(query: DecodedQuery<FindOneOptions>, update: Record<string, TUpdateOp>): Promise<TObject | undefined>;
215
+ updateMany(query: DecodedQuery<FindOptions>, update: Record<string, TUpdateOp>): Promise<number>;
213
216
  upsertOne(query: DecodedQuery<FindOneOptions>, update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValue>): Promise<TObject | undefined>;
217
+ upsertMany(query: DecodedQuery<FindOptions>, update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValue>): Promise<{
218
+ updated: number;
219
+ inserted: number;
220
+ }>;
214
221
  deleteOne(query: DecodedQuery<FindOneOptions>): Promise<TObject | undefined>;
215
222
  deleteMany(query: DecodedQuery<FindOptions>): Promise<number>;
216
223
  }
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
- var index = require('../../internals/index-CVutVPmd.js');
6
+ var index = require('../../internals/index-DXuW8UiB.js');
7
7
  var pg = require('pg');
8
8
  var QueryStream = require('pg-query-stream');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
10
  var Decimal = require('decimal.js');
11
11
  var utils = require('pg/lib/utils');
12
- var index$1 = require('../../internals/index-CzfsyXvb.js');
12
+ var index$1 = require('../../internals/index-Dc3V_Bzw.js');
13
13
  require('@o2ter/crypto-js');
14
- var random$1 = require('../../internals/random-Dytum6Nh.js');
14
+ var random$1 = require('../../internals/random-DVOUDDGg.js');
15
15
  var _private = require('../../internals/private-CSB1Ep4g.js');
16
16
 
17
17
  //
@@ -487,7 +487,7 @@ class QueryCompiler {
487
487
  INSERT INTO ${{ identifier: options.className }}
488
488
  (${_.map(keys, x => sql `${{ identifier: x }}`)})
489
489
  VALUES ${_.map(_values, v => sql `(${_.map(keys, k => sql `${v[k]}`)})`)}
490
- RETURNING 0
490
+ RETURNING _id
491
491
  `;
492
492
  }
493
493
  updateOne(query, update) {
@@ -505,6 +505,17 @@ class QueryCompiler {
505
505
  `;
506
506
  });
507
507
  }
508
+ updateMany(query, update) {
509
+ return this._modifyQuery(query, (fetchName) => {
510
+ return sql `
511
+ UPDATE ${{ identifier: query.className }}
512
+ SET __v = __v + 1, _updated_at = NOW()
513
+ ${!_.isEmpty(update) ? sql `, ${this._encodeUpdateAttrs(query.className, update)}` : sql ``}
514
+ WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
515
+ RETURNING _id
516
+ `;
517
+ });
518
+ }
508
519
  upsertOne(query, update, setOnInsert) {
509
520
  const _insert = _.toPairs({
510
521
  ..._defaultInsertOpts(query),
@@ -538,6 +549,35 @@ class QueryCompiler {
538
549
  `;
539
550
  });
540
551
  }
552
+ upsertMany(query, update, setOnInsert) {
553
+ const _insert = _.toPairs({
554
+ ..._defaultInsertOpts(query),
555
+ ...this._encodeObjectAttrs(query.className, setOnInsert),
556
+ });
557
+ return this._modifyQuery(query, (fetchName) => {
558
+ const updateName = `_update_$${query.className.toLowerCase()}`;
559
+ const insertName = `_insert_$${query.className.toLowerCase()}`;
560
+ return sql `
561
+ , ${{ identifier: updateName }} AS (
562
+ UPDATE ${{ identifier: query.className }}
563
+ SET __v = __v + 1, _updated_at = NOW()
564
+ ${!_.isEmpty(update) ? sql `, ${this._encodeUpdateAttrs(query.className, update)}` : sql ``}
565
+ WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
566
+ RETURNING _id, 0 AS ${{ identifier: 'result' }}
567
+ )
568
+ , ${{ identifier: insertName }} AS (
569
+ INSERT INTO ${{ identifier: query.className }}
570
+ (${_.map(_insert, x => sql `${{ identifier: x[0] }}`)})
571
+ SELECT ${_.map(_insert, x => sql `${x[1]} AS ${{ identifier: x[0] }}`)}
572
+ WHERE NOT EXISTS(SELECT * FROM ${{ identifier: updateName }})
573
+ RETURNING _id, 1 AS ${{ identifier: 'result' }}
574
+ )
575
+ SELECT * FROM ${{ identifier: updateName }}
576
+ UNION
577
+ SELECT * FROM ${{ identifier: insertName }}
578
+ `;
579
+ });
580
+ }
541
581
  deleteOne(query) {
542
582
  return this._modifyQuery({ ...query, limit: 1 }, (fetchName, context) => {
543
583
  const name = `_delete_$${query.className.toLowerCase()}`;
@@ -564,7 +604,7 @@ class QueryCompiler {
564
604
  return this._modifyQuery(query, (fetchName) => sql `
565
605
  DELETE FROM ${{ identifier: query.className }}
566
606
  WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
567
- RETURNING 0
607
+ RETURNING _id
568
608
  `);
569
609
  }
570
610
  }
@@ -758,11 +798,24 @@ class SqlStorage {
758
798
  const updated = _.first(await this.query(compiler.updateOne(query, update)));
759
799
  return _.isNil(updated) ? undefined : this._decodeObject(query.className, updated);
760
800
  }
801
+ async updateMany(query, update) {
802
+ const compiler = this._makeCompiler(true, query.extraFilter);
803
+ const updated = await this.query(compiler.updateMany(query, update));
804
+ return updated.length;
805
+ }
761
806
  async upsertOne(query, update, setOnInsert) {
762
807
  const compiler = this._makeCompiler(true, query.extraFilter);
763
808
  const upserted = _.first(await this.query(compiler.upsertOne(query, update, setOnInsert)));
764
809
  return _.isNil(upserted) ? undefined : this._decodeObject(query.className, upserted);
765
810
  }
811
+ async upsertMany(query, update, setOnInsert) {
812
+ const compiler = this._makeCompiler(true, query.extraFilter);
813
+ const upserted = await this.query(compiler.upsertMany(query, update, setOnInsert));
814
+ return {
815
+ updated: _.filter(upserted, x => x.result === 0).length,
816
+ inserted: _.filter(upserted, x => x.result === 1).length,
817
+ };
818
+ }
766
819
  async deleteOne(query) {
767
820
  const compiler = this._makeCompiler(true, query.extraFilter);
768
821
  const deleted = _.first(await this.query(compiler.deleteOne(query)));