proto.io 0.0.205 → 0.0.207

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 (54) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +2 -2
  4. package/dist/adapters/file/database.js.map +1 -1
  5. package/dist/adapters/file/database.mjs +2 -2
  6. package/dist/adapters/file/database.mjs.map +1 -1
  7. package/dist/adapters/file/filesystem.d.ts +3 -3
  8. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  9. package/dist/adapters/storage/progres.d.ts +9 -20
  10. package/dist/adapters/storage/progres.js +28 -109
  11. package/dist/adapters/storage/progres.js.map +1 -1
  12. package/dist/adapters/storage/progres.mjs +28 -109
  13. package/dist/adapters/storage/progres.mjs.map +1 -1
  14. package/dist/client.d.ts +3 -3
  15. package/dist/client.js +2 -1
  16. package/dist/client.js.map +1 -1
  17. package/dist/client.mjs +3 -2
  18. package/dist/client.mjs.map +1 -1
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +45 -109
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +46 -110
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/internals/{base-Cf7WkDhO.d.ts → base-DHkvlTFy.d.ts} +2 -2
  25. package/dist/internals/base-DHkvlTFy.d.ts.map +1 -0
  26. package/dist/internals/{chunk-ONaLyXL0.d.ts → chunk-C7kDLOLD.d.ts} +3 -3
  27. package/dist/internals/chunk-C7kDLOLD.d.ts.map +1 -0
  28. package/dist/internals/{index-DByHjIHI.js → index-BRzKDwPs.js} +64 -22
  29. package/dist/internals/index-BRzKDwPs.js.map +1 -0
  30. package/dist/internals/{index-DI-jPA6f.d.ts → index-CKcESGqE.d.ts} +3 -3
  31. package/dist/internals/index-CKcESGqE.d.ts.map +1 -0
  32. package/dist/internals/{index-C4vwSN74.js → index-CkAvNaAe.js} +240 -1
  33. package/dist/internals/index-CkAvNaAe.js.map +1 -0
  34. package/dist/internals/{index-DtCgllhg.mjs → index-DAkcqabS.mjs} +64 -22
  35. package/dist/internals/index-DAkcqabS.mjs.map +1 -0
  36. package/dist/internals/{index-Blw7vAq5.mjs → index-DlY33lfO.mjs} +240 -1
  37. package/dist/internals/index-DlY33lfO.mjs.map +1 -0
  38. package/dist/internals/{index-JdEs5VLY.d.ts → index-PLz89AWF.d.ts} +23 -31
  39. package/dist/internals/index-PLz89AWF.d.ts.map +1 -0
  40. package/dist/internals/{random-Dk3OhDNU.js → random-B0V0EnjP.js} +2 -2
  41. package/dist/internals/random-B0V0EnjP.js.map +1 -0
  42. package/dist/internals/{random-6nHcBOxn.mjs → random-ZgzzM5v_.mjs} +2 -2
  43. package/dist/internals/random-ZgzzM5v_.mjs.map +1 -0
  44. package/package.json +1 -1
  45. package/dist/internals/base-Cf7WkDhO.d.ts.map +0 -1
  46. package/dist/internals/chunk-ONaLyXL0.d.ts.map +0 -1
  47. package/dist/internals/index-Blw7vAq5.mjs.map +0 -1
  48. package/dist/internals/index-C4vwSN74.js.map +0 -1
  49. package/dist/internals/index-DByHjIHI.js.map +0 -1
  50. package/dist/internals/index-DI-jPA6f.d.ts.map +0 -1
  51. package/dist/internals/index-DtCgllhg.mjs.map +0 -1
  52. package/dist/internals/index-JdEs5VLY.d.ts.map +0 -1
  53. package/dist/internals/random-6nHcBOxn.mjs.map +0 -1
  54. package/dist/internals/random-Dk3OhDNU.js.map +0 -1
@@ -5,9 +5,9 @@ import QueryStream from 'pg-query-stream';
5
5
  import { asyncStream, IteratorPool } from '@o2ter/utils-js';
6
6
  import Decimal from 'decimal.js';
7
7
  import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
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-Blw7vAq5.mjs';
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-DlY33lfO.mjs';
9
9
  import '@o2ter/crypto-js';
10
- import { r as resolveColumn, a as resolveDataType$1, g as generateId, Q as QueryValidator } from '../../internals/random-6nHcBOxn.mjs';
10
+ import { r as resolveColumn, a as resolveDataType$1, g as generateId, Q as QueryValidator } from '../../internals/random-ZgzzM5v_.mjs';
11
11
  import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
12
12
 
13
13
  //
@@ -96,7 +96,7 @@ class SQL {
96
96
  query += `${dialect.placeholder(nextIdx())}::DOUBLE PRECISION`;
97
97
  values.push(value.value);
98
98
  }
99
- else if (Decimal.isDecimal(value.value)) {
99
+ else if (value.value instanceof Decimal) {
100
100
  query += `${dialect.placeholder(nextIdx())}::DECIMAL`;
101
101
  values.push(value.value.toString());
102
102
  }
@@ -427,11 +427,12 @@ class QueryCompiler {
427
427
  _selectPopulateMap(context) {
428
428
  return _.map(context.populates, (populate, field) => this.dialect.selectPopulate(this, context, populate, field, _.includes(context.countMatches, field)));
429
429
  }
430
- insert(options, attrs) {
431
- const _attrs = _.toPairs({
430
+ insert(options, values) {
431
+ const _values = _.map(values, attr => ({
432
432
  ..._defaultInsertOpts(options),
433
- ...this._encodeObjectAttrs(options.className, attrs),
434
- });
433
+ ...this._encodeObjectAttrs(options.className, attr),
434
+ }));
435
+ const keys = _.uniq(_.flatMap(_values, x => _.keys(x)));
435
436
  const name = `_insert_$${options.className.toLowerCase()}`;
436
437
  const context = { ...this._encodeIncludes(options), name };
437
438
  const populates = _.mapValues(context.populates, (populate) => this.dialect.encodePopulate(this, populate));
@@ -441,8 +442,8 @@ class QueryCompiler {
441
442
  return sql `
442
443
  WITH ${{ identifier: name }} AS (
443
444
  INSERT INTO ${{ identifier: options.className }}
444
- (${_.map(_attrs, x => sql `${{ identifier: x[0] }}`)})
445
- VALUES (${_.map(_attrs, x => sql `${x[1]}`)})
445
+ (${_.map(keys, x => sql `${{ identifier: x }}`)})
446
+ VALUES ${_.map(_values, v => sql `(${_.map(keys, k => sql `${v[k]}`)})`)}
446
447
  RETURNING *
447
448
  )${!_.isEmpty(stages) ? sql `, ${_.map(stages, (q, n) => sql `${{ identifier: n }} AS (${q})`)}` : sql ``}
448
449
  SELECT ${{
@@ -455,21 +456,8 @@ class QueryCompiler {
455
456
  ${!_.isEmpty(joins) ? { literal: joins, separator: '\n' } : sql ``}
456
457
  `;
457
458
  }
458
- insertMany(options, values) {
459
- const _values = _.map(values, attr => ({
460
- ..._defaultInsertOpts(options),
461
- ...this._encodeObjectAttrs(options.className, attr),
462
- }));
463
- const keys = _.uniq(_.flatMap(_values, x => _.keys(x)));
464
- return sql `
465
- INSERT INTO ${{ identifier: options.className }}
466
- (${_.map(keys, x => sql `${{ identifier: x }}`)})
467
- VALUES ${_.map(_values, v => sql `(${_.map(keys, k => sql `${v[k]}`)})`)}
468
- RETURNING _id
469
- `;
470
- }
471
- updateOne(query, update) {
472
- return this._modifyQuery({ ...query, limit: 1 }, (fetchName) => {
459
+ update(query, update) {
460
+ return this._modifyQuery(query, (fetchName) => {
473
461
  const name = `_update_$${query.className.toLowerCase()}`;
474
462
  return sql `
475
463
  , ${{ identifier: name }} AS (
@@ -482,22 +470,12 @@ class QueryCompiler {
482
470
  `;
483
471
  });
484
472
  }
485
- updateMany(query, update) {
486
- return this._modifyQuery(query, (fetchName) => {
487
- return sql `
488
- UPDATE ${{ identifier: query.className }}
489
- SET ${this._encodeUpdateAttrs(query.className, update)}
490
- WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
491
- RETURNING _id
492
- `;
493
- });
494
- }
495
- upsertOne(query, update, setOnInsert) {
473
+ upsert(query, update, setOnInsert) {
496
474
  const _insert = _.toPairs({
497
475
  ..._defaultInsertOpts(query),
498
476
  ...this._encodeObjectAttrs(query.className, setOnInsert),
499
477
  });
500
- return this._modifyQuery({ ...query, limit: 1 }, (fetchName) => {
478
+ return this._modifyQuery(query, (fetchName) => {
501
479
  const updateName = `_update_$${query.className.toLowerCase()}`;
502
480
  const insertName = `_insert_$${query.className.toLowerCase()}`;
503
481
  const upsertName = `_upsert_$${query.className.toLowerCase()}`;
@@ -524,36 +502,8 @@ class QueryCompiler {
524
502
  `;
525
503
  });
526
504
  }
527
- upsertMany(query, update, setOnInsert) {
528
- const _insert = _.toPairs({
529
- ..._defaultInsertOpts(query),
530
- ...this._encodeObjectAttrs(query.className, setOnInsert),
531
- });
532
- return this._modifyQuery(query, (fetchName) => {
533
- const updateName = `_update_$${query.className.toLowerCase()}`;
534
- const insertName = `_insert_$${query.className.toLowerCase()}`;
535
- return sql `
536
- , ${{ identifier: updateName }} AS (
537
- UPDATE ${{ identifier: query.className }}
538
- SET ${this._encodeUpdateAttrs(query.className, update)}
539
- WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
540
- RETURNING _id, __v
541
- )
542
- , ${{ identifier: insertName }} AS (
543
- INSERT INTO ${{ identifier: query.className }}
544
- (${_.map(_insert, x => sql `${{ identifier: x[0] }}`)})
545
- SELECT ${_.map(_insert, x => sql `${x[1]} AS ${{ identifier: x[0] }}`)}
546
- WHERE NOT EXISTS(SELECT * FROM ${{ identifier: updateName }})
547
- RETURNING _id, __v
548
- )
549
- SELECT * FROM ${{ identifier: updateName }}
550
- UNION
551
- SELECT * FROM ${{ identifier: insertName }}
552
- `;
553
- });
554
- }
555
- deleteOne(query) {
556
- return this._modifyQuery({ ...query, limit: 1 }, (fetchName, context) => {
505
+ delete(query) {
506
+ return this._modifyQuery(query, (fetchName, context) => {
557
507
  const name = `_delete_$${query.className.toLowerCase()}`;
558
508
  const populates = this._selectPopulateMap({ ...context, name });
559
509
  const joins = _.compact(_.map(populates, ({ join }) => join));
@@ -574,13 +524,6 @@ class QueryCompiler {
574
524
  `;
575
525
  });
576
526
  }
577
- deleteMany(query) {
578
- return this._modifyQuery(query, (fetchName) => sql `
579
- DELETE FROM ${{ identifier: query.className }}
580
- WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
581
- RETURNING _id
582
- `);
583
- }
584
527
  }
585
528
 
586
529
  //
@@ -761,49 +704,25 @@ class SqlStorage {
761
704
  }
762
705
  })();
763
706
  }
764
- async insert(options, attrs) {
707
+ async insert(options, values) {
765
708
  const compiler = this._makeCompiler(true);
766
- const result = _.first(await this.query(compiler.insert(options, attrs)));
767
- return _.isNil(result) ? undefined : this._decodeObject(options.className, result);
768
- }
769
- async insertMany(options, values) {
770
- const compiler = this._makeCompiler(true);
771
- const result = await this.query(compiler.insertMany(options, values));
772
- return result.length;
773
- }
774
- async updateOne(query, update) {
775
- const compiler = this._makeCompiler(true, query.extraFilter);
776
- const updated = _.first(await this.query(compiler.updateOne(query, update)));
777
- return _.isNil(updated) ? undefined : this._decodeObject(query.className, updated);
709
+ const result = await this.query(compiler.insert(options, values));
710
+ return _.map(result, x => this._decodeObject(options.className, x));
778
711
  }
779
- async updateMany(query, update) {
712
+ async update(query, update) {
780
713
  const compiler = this._makeCompiler(true, query.extraFilter);
781
- const updated = await this.query(compiler.updateMany(query, update));
782
- return updated.length;
783
- }
784
- async upsertOne(query, update, setOnInsert) {
785
- const compiler = this._makeCompiler(true, query.extraFilter);
786
- const upserted = _.first(await this.query(compiler.upsertOne(query, update, setOnInsert)));
787
- return _.isNil(upserted) ? undefined : this._decodeObject(query.className, upserted);
788
- }
789
- async upsertMany(query, update, setOnInsert) {
790
- const compiler = this._makeCompiler(true, query.extraFilter);
791
- const upserted = await this.query(compiler.upsertMany(query, update, setOnInsert));
792
- const inserted = _.filter(upserted, x => x.__v === 0).length;
793
- return {
794
- updated: upserted.length - inserted,
795
- inserted: inserted,
796
- };
714
+ const updated = await this.query(compiler.update(query, update));
715
+ return _.map(updated, x => this._decodeObject(query.className, x));
797
716
  }
798
- async deleteOne(query) {
717
+ async upsert(query, update, setOnInsert) {
799
718
  const compiler = this._makeCompiler(true, query.extraFilter);
800
- const deleted = _.first(await this.query(compiler.deleteOne(query)));
801
- return _.isNil(deleted) ? undefined : this._decodeObject(query.className, deleted);
719
+ const upserted = await this.query(compiler.upsert(query, update, setOnInsert));
720
+ return _.map(upserted, x => this._decodeObject(query.className, x));
802
721
  }
803
- async deleteMany(query) {
722
+ async delete(query) {
804
723
  const compiler = this._makeCompiler(true, query.extraFilter);
805
- const deleted = await this.query(compiler.deleteMany(query));
806
- return deleted.length;
724
+ const deleted = await this.query(compiler.delete(query));
725
+ return _.map(deleted, x => this._decodeObject(query.className, x));
807
726
  }
808
727
  }
809
728