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
|
@@ -483,7 +483,7 @@ class QueryCompiler {
|
|
|
483
483
|
INSERT INTO ${{ identifier: options.className }}
|
|
484
484
|
(${_.map(keys, x => sql `${{ identifier: x }}`)})
|
|
485
485
|
VALUES ${_.map(_values, v => sql `(${_.map(keys, k => sql `${v[k]}`)})`)}
|
|
486
|
-
RETURNING
|
|
486
|
+
RETURNING _id
|
|
487
487
|
`;
|
|
488
488
|
}
|
|
489
489
|
updateOne(query, update) {
|
|
@@ -501,6 +501,17 @@ class QueryCompiler {
|
|
|
501
501
|
`;
|
|
502
502
|
});
|
|
503
503
|
}
|
|
504
|
+
updateMany(query, update) {
|
|
505
|
+
return this._modifyQuery(query, (fetchName) => {
|
|
506
|
+
return sql `
|
|
507
|
+
UPDATE ${{ identifier: query.className }}
|
|
508
|
+
SET __v = __v + 1, _updated_at = NOW()
|
|
509
|
+
${!_.isEmpty(update) ? sql `, ${this._encodeUpdateAttrs(query.className, update)}` : sql ``}
|
|
510
|
+
WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
|
|
511
|
+
RETURNING _id
|
|
512
|
+
`;
|
|
513
|
+
});
|
|
514
|
+
}
|
|
504
515
|
upsertOne(query, update, setOnInsert) {
|
|
505
516
|
const _insert = _.toPairs({
|
|
506
517
|
..._defaultInsertOpts(query),
|
|
@@ -534,6 +545,35 @@ class QueryCompiler {
|
|
|
534
545
|
`;
|
|
535
546
|
});
|
|
536
547
|
}
|
|
548
|
+
upsertMany(query, update, setOnInsert) {
|
|
549
|
+
const _insert = _.toPairs({
|
|
550
|
+
..._defaultInsertOpts(query),
|
|
551
|
+
...this._encodeObjectAttrs(query.className, setOnInsert),
|
|
552
|
+
});
|
|
553
|
+
return this._modifyQuery(query, (fetchName) => {
|
|
554
|
+
const updateName = `_update_$${query.className.toLowerCase()}`;
|
|
555
|
+
const insertName = `_insert_$${query.className.toLowerCase()}`;
|
|
556
|
+
return sql `
|
|
557
|
+
, ${{ identifier: updateName }} AS (
|
|
558
|
+
UPDATE ${{ identifier: query.className }}
|
|
559
|
+
SET __v = __v + 1, _updated_at = NOW()
|
|
560
|
+
${!_.isEmpty(update) ? sql `, ${this._encodeUpdateAttrs(query.className, update)}` : sql ``}
|
|
561
|
+
WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
|
|
562
|
+
RETURNING _id, 0 AS ${{ identifier: 'result' }}
|
|
563
|
+
)
|
|
564
|
+
, ${{ identifier: insertName }} AS (
|
|
565
|
+
INSERT INTO ${{ identifier: query.className }}
|
|
566
|
+
(${_.map(_insert, x => sql `${{ identifier: x[0] }}`)})
|
|
567
|
+
SELECT ${_.map(_insert, x => sql `${x[1]} AS ${{ identifier: x[0] }}`)}
|
|
568
|
+
WHERE NOT EXISTS(SELECT * FROM ${{ identifier: updateName }})
|
|
569
|
+
RETURNING _id, 1 AS ${{ identifier: 'result' }}
|
|
570
|
+
)
|
|
571
|
+
SELECT * FROM ${{ identifier: updateName }}
|
|
572
|
+
UNION
|
|
573
|
+
SELECT * FROM ${{ identifier: insertName }}
|
|
574
|
+
`;
|
|
575
|
+
});
|
|
576
|
+
}
|
|
537
577
|
deleteOne(query) {
|
|
538
578
|
return this._modifyQuery({ ...query, limit: 1 }, (fetchName, context) => {
|
|
539
579
|
const name = `_delete_$${query.className.toLowerCase()}`;
|
|
@@ -560,7 +600,7 @@ class QueryCompiler {
|
|
|
560
600
|
return this._modifyQuery(query, (fetchName) => sql `
|
|
561
601
|
DELETE FROM ${{ identifier: query.className }}
|
|
562
602
|
WHERE ${{ identifier: query.className }}._id IN (SELECT ${{ identifier: fetchName }}._id FROM ${{ identifier: fetchName }})
|
|
563
|
-
RETURNING
|
|
603
|
+
RETURNING _id
|
|
564
604
|
`);
|
|
565
605
|
}
|
|
566
606
|
}
|
|
@@ -754,11 +794,24 @@ class SqlStorage {
|
|
|
754
794
|
const updated = _.first(await this.query(compiler.updateOne(query, update)));
|
|
755
795
|
return _.isNil(updated) ? undefined : this._decodeObject(query.className, updated);
|
|
756
796
|
}
|
|
797
|
+
async updateMany(query, update) {
|
|
798
|
+
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
799
|
+
const updated = await this.query(compiler.updateMany(query, update));
|
|
800
|
+
return updated.length;
|
|
801
|
+
}
|
|
757
802
|
async upsertOne(query, update, setOnInsert) {
|
|
758
803
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
759
804
|
const upserted = _.first(await this.query(compiler.upsertOne(query, update, setOnInsert)));
|
|
760
805
|
return _.isNil(upserted) ? undefined : this._decodeObject(query.className, upserted);
|
|
761
806
|
}
|
|
807
|
+
async upsertMany(query, update, setOnInsert) {
|
|
808
|
+
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
809
|
+
const upserted = await this.query(compiler.upsertMany(query, update, setOnInsert));
|
|
810
|
+
return {
|
|
811
|
+
updated: _.filter(upserted, x => x.result === 0).length,
|
|
812
|
+
inserted: _.filter(upserted, x => x.result === 1).length,
|
|
813
|
+
};
|
|
814
|
+
}
|
|
762
815
|
async deleteOne(query) {
|
|
763
816
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
764
817
|
const deleted = _.first(await this.query(compiler.deleteOne(query)));
|
|
@@ -2104,7 +2157,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2104
2157
|
break;
|
|
2105
2158
|
if (_.isNil(expr.value))
|
|
2106
2159
|
return sql `${element} IS NULL`;
|
|
2107
|
-
if (!_.isString(dataType) && dataType?.type === 'pointer'
|
|
2160
|
+
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2161
|
+
if (!(expr.value instanceof TObject) || dataType.target !== expr.value.className || !expr.value.objectId)
|
|
2162
|
+
break;
|
|
2108
2163
|
return sql `${element} ${nullSafeEqual()} ${{ value: expr.value.objectId }}`;
|
|
2109
2164
|
}
|
|
2110
2165
|
return sql `${element} ${nullSafeEqual()} ${encodeValue(expr.value)}`;
|
|
@@ -2115,7 +2170,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2115
2170
|
break;
|
|
2116
2171
|
if (_.isNil(expr.value))
|
|
2117
2172
|
return sql `${element} IS NOT NULL`;
|
|
2118
|
-
if (!_.isString(dataType) && dataType?.type === 'pointer'
|
|
2173
|
+
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2174
|
+
if (!(expr.value instanceof TObject) || dataType.target !== expr.value.className || !expr.value.objectId)
|
|
2175
|
+
break;
|
|
2119
2176
|
return sql `${element} ${nullSafeNotEqual()} ${{ value: expr.value.objectId }}`;
|
|
2120
2177
|
}
|
|
2121
2178
|
return sql `${element} ${nullSafeNotEqual()} ${encodeValue(expr.value)}`;
|
|
@@ -2191,7 +2248,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2191
2248
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2192
2249
|
if (_.isNil(value))
|
|
2193
2250
|
return sql `${element} IS NULL`;
|
|
2194
|
-
if (!(value instanceof TObject) || !value.objectId)
|
|
2251
|
+
if (!(value instanceof TObject) || dataType.target !== value.className || !value.objectId)
|
|
2195
2252
|
break;
|
|
2196
2253
|
return sql `${element} ${nullSafeEqual()} ${{ value: value.objectId }}`;
|
|
2197
2254
|
}
|
|
@@ -2201,7 +2258,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2201
2258
|
const containsNil = _.some(expr.value, x => _.isNil(x));
|
|
2202
2259
|
const values = _.filter(expr.value, x => !_.isNil(x));
|
|
2203
2260
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2204
|
-
if (!_.every(values, x => x instanceof TObject && x.objectId))
|
|
2261
|
+
if (!_.every(values, x => x instanceof TObject && dataType.target === x.className && x.objectId))
|
|
2205
2262
|
break;
|
|
2206
2263
|
if (containsNil) {
|
|
2207
2264
|
return sql `${element} IS NULL OR ${element} IN (${_.map(values, (x) => sql `${{ value: x.objectId }}`)})`;
|
|
@@ -2227,7 +2284,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2227
2284
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2228
2285
|
if (_.isNil(value))
|
|
2229
2286
|
return sql `${element} IS NOT NULL`;
|
|
2230
|
-
if (!(value instanceof TObject) || !value.objectId)
|
|
2287
|
+
if (!(value instanceof TObject) || dataType.target !== value.className || !value.objectId)
|
|
2231
2288
|
break;
|
|
2232
2289
|
return sql `${element} ${nullSafeNotEqual()} ${{ value: value.objectId }}`;
|
|
2233
2290
|
}
|
|
@@ -2237,7 +2294,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2237
2294
|
const containsNil = _.some(expr.value, x => _.isNil(x));
|
|
2238
2295
|
const values = _.filter(expr.value, x => !_.isNil(x));
|
|
2239
2296
|
if (!_.isString(dataType) && dataType?.type === 'pointer') {
|
|
2240
|
-
if (!_.every(values, x => x instanceof TObject && x.objectId))
|
|
2297
|
+
if (!_.every(values, x => x instanceof TObject && dataType.target === x.className && x.objectId))
|
|
2241
2298
|
break;
|
|
2242
2299
|
if (containsNil) {
|
|
2243
2300
|
return sql `${element} IS NOT NULL AND ${element} NOT IN (${_.map(values, (x) => sql `${{ value: x.objectId }}`)})`;
|
|
@@ -2272,7 +2329,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2272
2329
|
return sql `${element} ${{ literal: op }} ${{ value: _encodeValue(expr.value) }}`;
|
|
2273
2330
|
}
|
|
2274
2331
|
if (relation && parent.className) {
|
|
2275
|
-
if (!_.every(expr.value, x => x instanceof TObject && x.objectId))
|
|
2332
|
+
if (!_.every(expr.value, x => x instanceof TObject && relation.target === x.className && x.objectId))
|
|
2276
2333
|
break;
|
|
2277
2334
|
const tempName = `_populate_expr_$${compiler.nextIdx()}`;
|
|
2278
2335
|
const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
|