proto.io 0.0.172 → 0.0.173
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.
- package/dist/adapters/file/database.d.ts +2 -2
- package/dist/adapters/file/filesystem.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/storage/progres.d.ts +8 -1
- package/dist/adapters/storage/progres.js +55 -2
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +55 -2
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.mjs +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +108 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-K0jhERvZ.d.ts → index-BJnQhKf3.d.ts} +2 -2
- package/dist/internals/index-BJnQhKf3.d.ts.map +1 -0
- package/dist/internals/{index-D0hHgn2P.mjs → index-BZNPlw1L.mjs} +20 -1
- package/dist/internals/index-BZNPlw1L.mjs.map +1 -0
- package/dist/internals/{index-BJP46VGq.js → index-CIecB6mS.js} +20 -1
- package/dist/internals/index-CIecB6mS.js.map +1 -0
- package/dist/internals/{index-DchUjNEf.d.ts → index-Cpv1DoEI.d.ts} +2 -2
- package/dist/internals/index-Cpv1DoEI.d.ts.map +1 -0
- package/dist/internals/{index-BhWRmBiq.d.ts → index-lX-M76Tn.d.ts} +11 -1
- package/dist/internals/index-lX-M76Tn.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/internals/index-BJP46VGq.js.map +0 -1
- package/dist/internals/index-BhWRmBiq.d.ts.map +0 -1
- package/dist/internals/index-D0hHgn2P.mjs.map +0 -1
- package/dist/internals/index-DchUjNEf.d.ts.map +0 -1
- 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-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { T as TSchema, P as ProtoService } from '../../internals/index-lX-M76Tn.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BJnQhKf3.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-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { P as ProtoService } from '../../internals/index-lX-M76Tn.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BJnQhKf3.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-
|
|
4
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
3
|
+
import { P as ProtoService } from '../../internals/index-lX-M76Tn.js';
|
|
4
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-BJnQhKf3.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-
|
|
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-lX-M76Tn.js';
|
|
3
3
|
import * as _o2ter_utils_js from '@o2ter/utils-js';
|
|
4
4
|
import { asyncStream } from '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
@@ -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
|
}
|
|
@@ -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
|
|
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
|
|
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)));
|