proto.io 0.0.206 → 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 +3 -3
  4. package/dist/adapters/file/database.js.map +1 -1
  5. package/dist/adapters/file/database.mjs +3 -3
  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 -17
  10. package/dist/adapters/storage/progres.js +24 -101
  11. package/dist/adapters/storage/progres.js.map +1 -1
  12. package/dist/adapters/storage/progres.mjs +24 -101
  13. package/dist/adapters/storage/progres.mjs.map +1 -1
  14. package/dist/client.d.ts +3 -3
  15. package/dist/client.js +2 -2
  16. package/dist/client.mjs +3 -3
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +24 -107
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +25 -108
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/internals/{base-Be7PFKEC.d.ts → base-DHkvlTFy.d.ts} +2 -2
  23. package/dist/internals/base-DHkvlTFy.d.ts.map +1 -0
  24. package/dist/internals/{chunk-CEQtSsWb.d.ts → chunk-C7kDLOLD.d.ts} +3 -3
  25. package/dist/internals/chunk-C7kDLOLD.d.ts.map +1 -0
  26. package/dist/internals/{index-CsmAYB_t.js → index-B8TESzd9.js} +1 -2
  27. package/dist/internals/{index-CsmAYB_t.js.map → index-B8TESzd9.js.map} +1 -1
  28. package/dist/internals/{index-BFZlY3IO.js → index-BRzKDwPs.js} +44 -2
  29. package/dist/internals/index-BRzKDwPs.js.map +1 -0
  30. package/dist/internals/{index-CURcwPBG.d.ts → index-CKcESGqE.d.ts} +2 -2
  31. package/dist/internals/index-CKcESGqE.d.ts.map +1 -0
  32. package/dist/internals/{index-CyPxh5dl.js → index-CkAvNaAe.js} +2 -2
  33. package/dist/internals/{index-CyPxh5dl.js.map → index-CkAvNaAe.js.map} +1 -1
  34. package/dist/internals/{index-CSnRU_KQ.mjs → index-DAkcqabS.mjs} +44 -2
  35. package/dist/internals/index-DAkcqabS.mjs.map +1 -0
  36. package/dist/internals/{index-iRVgw566.mjs → index-DlY33lfO.mjs} +2 -2
  37. package/dist/internals/{index-iRVgw566.mjs.map → index-DlY33lfO.mjs.map} +1 -1
  38. package/dist/internals/{index-DnbbpIaO.d.ts → index-PLz89AWF.d.ts} +14 -19
  39. package/dist/internals/index-PLz89AWF.d.ts.map +1 -0
  40. package/dist/internals/{index-DpN9tcbY.mjs → index-al1N-qi7.mjs} +2 -2
  41. package/dist/internals/{index-DpN9tcbY.mjs.map → index-al1N-qi7.mjs.map} +1 -1
  42. package/dist/internals/{random-D7S1XD7F.js → random-B0V0EnjP.js} +3 -3
  43. package/dist/internals/random-B0V0EnjP.js.map +1 -0
  44. package/dist/internals/{random-BnGB_bVS.mjs → random-ZgzzM5v_.mjs} +3 -3
  45. package/dist/internals/random-ZgzzM5v_.mjs.map +1 -0
  46. package/package.json +1 -1
  47. package/dist/internals/base-Be7PFKEC.d.ts.map +0 -1
  48. package/dist/internals/chunk-CEQtSsWb.d.ts.map +0 -1
  49. package/dist/internals/index-BFZlY3IO.js.map +0 -1
  50. package/dist/internals/index-CSnRU_KQ.mjs.map +0 -1
  51. package/dist/internals/index-CURcwPBG.d.ts.map +0 -1
  52. package/dist/internals/index-DnbbpIaO.d.ts.map +0 -1
  53. package/dist/internals/random-BnGB_bVS.mjs.map +0 -1
  54. package/dist/internals/random-D7S1XD7F.js.map +0 -1
@@ -1,13 +1,13 @@
1
1
  import _ from 'lodash';
2
- import { a as isRelation, i as isPointer, b as isShape, e as decodeUpdateOp, s as shapePaths, c as isPrimitive, f as defaultObjectKeys, T as TObject, _ as _isTypeof, g as isVector, h as _encodeValue, j as _decodeValue, k as dimensionOf, l as _typeof } from '../../internals/index-DpN9tcbY.mjs';
2
+ import { a as isRelation, i as isPointer, b as isShape, e as decodeUpdateOp, s as shapePaths, c as isPrimitive, T as TObject, _ as _isTypeof, f as isVector, g as _encodeValue, h as _decodeValue, j as dimensionOf, k as _typeof } from '../../internals/index-al1N-qi7.mjs';
3
3
  import { Pool, types } from 'pg';
4
4
  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-iRVgw566.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-BnGB_bVS.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
  //
@@ -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 ${_.map(defaultObjectKeys, k => sql `${{ identifier: k }}`)}
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 ${_.map(defaultObjectKeys, k => sql `${{ identifier: k }}`)}
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 ${_.map(defaultObjectKeys, k => sql `${{ identifier: k }}`)}
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 ${_.map(defaultObjectKeys, k => sql `${{ identifier: k }}`)}
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 ${_.map(defaultObjectKeys, k => sql `${{ identifier: k }}`)}
582
- `);
583
- }
584
527
  }
585
528
 
586
529
  //
@@ -761,44 +704,24 @@ class SqlStorage {
761
704
  }
762
705
  })();
763
706
  }
764
- async insert(options, attrs) {
765
- 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) {
707
+ async insert(options, values) {
770
708
  const compiler = this._makeCompiler(true);
771
- const result = await this.query(compiler.insertMany(options, values));
709
+ const result = await this.query(compiler.insert(options, values));
772
710
  return _.map(result, x => this._decodeObject(options.className, x));
773
711
  }
774
- async updateOne(query, update) {
712
+ async update(query, update) {
775
713
  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);
778
- }
779
- async updateMany(query, update) {
780
- const compiler = this._makeCompiler(true, query.extraFilter);
781
- const updated = await this.query(compiler.updateMany(query, update));
714
+ const updated = await this.query(compiler.update(query, update));
782
715
  return _.map(updated, x => this._decodeObject(query.className, x));
783
716
  }
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) {
717
+ async upsert(query, update, setOnInsert) {
790
718
  const compiler = this._makeCompiler(true, query.extraFilter);
791
- const upserted = await this.query(compiler.upsertMany(query, update, setOnInsert));
719
+ const upserted = await this.query(compiler.upsert(query, update, setOnInsert));
792
720
  return _.map(upserted, x => this._decodeObject(query.className, x));
793
721
  }
794
- async deleteOne(query) {
795
- const compiler = this._makeCompiler(true, query.extraFilter);
796
- const deleted = _.first(await this.query(compiler.deleteOne(query)));
797
- return _.isNil(deleted) ? undefined : this._decodeObject(query.className, deleted);
798
- }
799
- async deleteMany(query) {
722
+ async delete(query) {
800
723
  const compiler = this._makeCompiler(true, query.extraFilter);
801
- const deleted = await this.query(compiler.deleteMany(query));
724
+ const deleted = await this.query(compiler.delete(query));
802
725
  return _.map(deleted, x => this._decodeObject(query.className, x));
803
726
  }
804
727
  }