proto.io 0.0.171 → 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 +66 -9
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +66 -9
- 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 +137 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-B5u7VXjz.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-D_GYwO8X.d.ts → index-Cpv1DoEI.d.ts} +2 -2
- package/dist/internals/index-Cpv1DoEI.d.ts.map +1 -0
- package/dist/internals/{index-BB2vDnq0.d.ts → index-lX-M76Tn.d.ts} +16 -3
- package/dist/internals/index-lX-M76Tn.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/internals/index-B5u7VXjz.d.ts.map +0 -1
- package/dist/internals/index-BB2vDnq0.d.ts.map +0 -1
- package/dist/internals/index-BJP46VGq.js.map +0 -1
- package/dist/internals/index-D0hHgn2P.mjs.map +0 -1
- package/dist/internals/index-D_GYwO8X.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)));
|
|
@@ -2108,7 +2161,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2108
2161
|
break;
|
|
2109
2162
|
if (_.isNil(expr.value))
|
|
2110
2163
|
return sql `${element} IS NULL`;
|
|
2111
|
-
if (!_.isString(dataType) && dataType?.type === 'pointer'
|
|
2164
|
+
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2165
|
+
if (!(expr.value instanceof index.TObject) || dataType.target !== expr.value.className || !expr.value.objectId)
|
|
2166
|
+
break;
|
|
2112
2167
|
return sql `${element} ${nullSafeEqual()} ${{ value: expr.value.objectId }}`;
|
|
2113
2168
|
}
|
|
2114
2169
|
return sql `${element} ${nullSafeEqual()} ${encodeValue(expr.value)}`;
|
|
@@ -2119,7 +2174,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2119
2174
|
break;
|
|
2120
2175
|
if (_.isNil(expr.value))
|
|
2121
2176
|
return sql `${element} IS NOT NULL`;
|
|
2122
|
-
if (!_.isString(dataType) && dataType?.type === 'pointer'
|
|
2177
|
+
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2178
|
+
if (!(expr.value instanceof index.TObject) || dataType.target !== expr.value.className || !expr.value.objectId)
|
|
2179
|
+
break;
|
|
2123
2180
|
return sql `${element} ${nullSafeNotEqual()} ${{ value: expr.value.objectId }}`;
|
|
2124
2181
|
}
|
|
2125
2182
|
return sql `${element} ${nullSafeNotEqual()} ${encodeValue(expr.value)}`;
|
|
@@ -2195,7 +2252,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2195
2252
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2196
2253
|
if (_.isNil(value))
|
|
2197
2254
|
return sql `${element} IS NULL`;
|
|
2198
|
-
if (!(value instanceof index.TObject) || !value.objectId)
|
|
2255
|
+
if (!(value instanceof index.TObject) || dataType.target !== value.className || !value.objectId)
|
|
2199
2256
|
break;
|
|
2200
2257
|
return sql `${element} ${nullSafeEqual()} ${{ value: value.objectId }}`;
|
|
2201
2258
|
}
|
|
@@ -2205,7 +2262,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2205
2262
|
const containsNil = _.some(expr.value, x => _.isNil(x));
|
|
2206
2263
|
const values = _.filter(expr.value, x => !_.isNil(x));
|
|
2207
2264
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2208
|
-
if (!_.every(values, x => x instanceof index.TObject && x.objectId))
|
|
2265
|
+
if (!_.every(values, x => x instanceof index.TObject && dataType.target === x.className && x.objectId))
|
|
2209
2266
|
break;
|
|
2210
2267
|
if (containsNil) {
|
|
2211
2268
|
return sql `${element} IS NULL OR ${element} IN (${_.map(values, (x) => sql `${{ value: x.objectId }}`)})`;
|
|
@@ -2231,7 +2288,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2231
2288
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2232
2289
|
if (_.isNil(value))
|
|
2233
2290
|
return sql `${element} IS NOT NULL`;
|
|
2234
|
-
if (!(value instanceof index.TObject) || !value.objectId)
|
|
2291
|
+
if (!(value instanceof index.TObject) || dataType.target !== value.className || !value.objectId)
|
|
2235
2292
|
break;
|
|
2236
2293
|
return sql `${element} ${nullSafeNotEqual()} ${{ value: value.objectId }}`;
|
|
2237
2294
|
}
|
|
@@ -2241,7 +2298,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2241
2298
|
const containsNil = _.some(expr.value, x => _.isNil(x));
|
|
2242
2299
|
const values = _.filter(expr.value, x => !_.isNil(x));
|
|
2243
2300
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2244
|
-
if (!_.every(values, x => x instanceof index.TObject && x.objectId))
|
|
2301
|
+
if (!_.every(values, x => x instanceof index.TObject && dataType.target === x.className && x.objectId))
|
|
2245
2302
|
break;
|
|
2246
2303
|
if (containsNil) {
|
|
2247
2304
|
return sql `${element} IS NOT NULL AND ${element} NOT IN (${_.map(values, (x) => sql `${{ value: x.objectId }}`)})`;
|
|
@@ -2276,7 +2333,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2276
2333
|
return sql `${element} ${{ literal: op }} ${{ value: index._encodeValue(expr.value) }}`;
|
|
2277
2334
|
}
|
|
2278
2335
|
if (relation && parent.className) {
|
|
2279
|
-
if (!_.every(expr.value, x => x instanceof index.TObject && x.objectId))
|
|
2336
|
+
if (!_.every(expr.value, x => x instanceof index.TObject && relation.target === x.className && x.objectId))
|
|
2280
2337
|
break;
|
|
2281
2338
|
const tempName = `_populate_expr_$${compiler.nextIdx()}`;
|
|
2282
2339
|
const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
|