proto.io 0.0.181 → 0.0.183
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 +16 -35
- package/dist/adapters/storage/progres.js +32 -27
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +32 -27
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internals/index-BnDahEvz.js.map +1 -1
- package/dist/internals/{index-BZupzq1Y.d.ts → index-C1pF5Xzm.d.ts} +2 -2
- package/dist/internals/index-C1pF5Xzm.d.ts.map +1 -0
- package/dist/internals/index-CmJh3t_k.mjs.map +1 -1
- package/dist/internals/{index-YpB-hXxf.d.ts → index-YJ0pBNzy.d.ts} +7 -11
- package/dist/internals/index-YJ0pBNzy.d.ts.map +1 -0
- package/dist/internals/{index-cKx59cIc.d.ts → index-Z57iS68O.d.ts} +2 -2
- package/dist/internals/index-Z57iS68O.d.ts.map +1 -0
- package/dist/internals/{random-CDtFUuES.js → random-80Vpxbxh.js} +9 -11
- package/dist/internals/random-80Vpxbxh.js.map +1 -0
- package/dist/internals/{random-BSyWEK8G.mjs → random-BtYyzHJD.mjs} +9 -11
- package/dist/internals/random-BtYyzHJD.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/internals/index-BZupzq1Y.d.ts.map +0 -1
- package/dist/internals/index-YpB-hXxf.d.ts.map +0 -1
- package/dist/internals/index-cKx59cIc.d.ts.map +0 -1
- package/dist/internals/random-BSyWEK8G.mjs.map +0 -1
- package/dist/internals/random-CDtFUuES.js.map +0 -1
|
@@ -7,7 +7,7 @@ import Decimal from 'decimal.js';
|
|
|
7
7
|
import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
|
|
8
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-D9AowvHp.mjs';
|
|
9
9
|
import '@o2ter/crypto-js';
|
|
10
|
-
import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-
|
|
10
|
+
import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-BtYyzHJD.mjs';
|
|
11
11
|
import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
|
|
12
12
|
|
|
13
13
|
//
|
|
@@ -206,13 +206,6 @@ class QueryCompiler {
|
|
|
206
206
|
nextIdx() {
|
|
207
207
|
return this.idx++;
|
|
208
208
|
}
|
|
209
|
-
_makeContext(query) {
|
|
210
|
-
const context = this._encodeIncludes(query);
|
|
211
|
-
return {
|
|
212
|
-
...context,
|
|
213
|
-
sorting: _encodeSorting(context.includes, context.populates, query.sort),
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
209
|
_encodeIncludes(query) {
|
|
217
210
|
const names = {};
|
|
218
211
|
const populates = {};
|
|
@@ -266,16 +259,15 @@ class QueryCompiler {
|
|
|
266
259
|
populate.populates = populates;
|
|
267
260
|
populate.countMatches = countMatches;
|
|
268
261
|
}
|
|
269
|
-
return { includes: names, populates, countMatches };
|
|
262
|
+
return { className: query.className, includes: names, populates, countMatches: _.uniq(countMatches) };
|
|
270
263
|
}
|
|
271
264
|
_baseSelectQuery(query, options) {
|
|
272
|
-
const
|
|
265
|
+
const fetchName = `_fetch_$${query.className.toLowerCase()}`;
|
|
266
|
+
const context = { ...this._encodeIncludes(query), name: fetchName };
|
|
273
267
|
const _stages = _.mapValues(context.populates, (populate) => this.dialect.encodePopulate(this, populate));
|
|
274
268
|
const stages = _.fromPairs(_.flatMap(_.values(_stages), (p) => _.toPairs(p)));
|
|
275
|
-
const
|
|
276
|
-
const
|
|
277
|
-
const baseFilter = this._encodeFilter(parent, query.filter);
|
|
278
|
-
const populates = this._selectPopulateMap(context, query.className, fetchName);
|
|
269
|
+
const baseFilter = this._encodeFilter(context, query.filter);
|
|
270
|
+
const populates = this._selectPopulateMap(context);
|
|
279
271
|
const joins = _.compact(_.map(populates, ({ join }) => join));
|
|
280
272
|
const includes = {
|
|
281
273
|
literal: [
|
|
@@ -288,12 +280,12 @@ class QueryCompiler {
|
|
|
288
280
|
const filter = _.compact([
|
|
289
281
|
baseFilter,
|
|
290
282
|
_options?.extraFilter,
|
|
291
|
-
query.relatedBy && this.dialect.encodeRelation(this,
|
|
283
|
+
query.relatedBy && this.dialect.encodeRelation(this, context, query.relatedBy),
|
|
292
284
|
]);
|
|
293
285
|
return {
|
|
294
286
|
stages,
|
|
295
287
|
fetchName,
|
|
296
|
-
context
|
|
288
|
+
context,
|
|
297
289
|
query: sql `
|
|
298
290
|
SELECT ${_options?.select ? _options?.select : sql `*`} FROM (
|
|
299
291
|
SELECT ${includes}
|
|
@@ -310,10 +302,10 @@ class QueryCompiler {
|
|
|
310
302
|
};
|
|
311
303
|
}
|
|
312
304
|
_refetch(name, query) {
|
|
313
|
-
const _context = this._encodeIncludes(query);
|
|
305
|
+
const _context = { ...this._encodeIncludes(query), name };
|
|
314
306
|
const populates = _.mapValues(_context.populates, (populate) => this.dialect.encodePopulate(this, populate, { className: query.className, name }));
|
|
315
307
|
const stages = _.fromPairs(_.flatMap(_.values(populates), (p) => _.toPairs(p)));
|
|
316
|
-
const _populates = this._selectPopulateMap(_context
|
|
308
|
+
const _populates = this._selectPopulateMap(_context);
|
|
317
309
|
const _joins = _.compact(_.map(_populates, ({ join }) => join));
|
|
318
310
|
const _includes = {
|
|
319
311
|
literal: [
|
|
@@ -428,11 +420,8 @@ class QueryCompiler {
|
|
|
428
420
|
${this.dialect.encodeSortKey(this, parent, key)} ${{ literal: order === 1 ? 'ASC' : 'DESC' }}
|
|
429
421
|
`)}`;
|
|
430
422
|
}
|
|
431
|
-
_selectPopulateMap(context
|
|
432
|
-
return _.map(context.populates, (populate, field) => this.dialect.selectPopulate(this,
|
|
433
|
-
className,
|
|
434
|
-
name,
|
|
435
|
-
}, populate, field, _.includes(context.countMatches, field)));
|
|
423
|
+
_selectPopulateMap(context) {
|
|
424
|
+
return _.map(context.populates, (populate, field) => this.dialect.selectPopulate(this, context, populate, field, _.includes(context.countMatches, field)));
|
|
436
425
|
}
|
|
437
426
|
insert(options, attrs) {
|
|
438
427
|
const _attrs = _.toPairs({
|
|
@@ -440,10 +429,10 @@ class QueryCompiler {
|
|
|
440
429
|
...this._encodeObjectAttrs(options.className, attrs),
|
|
441
430
|
});
|
|
442
431
|
const name = `_insert_$${options.className.toLowerCase()}`;
|
|
443
|
-
const context = this.
|
|
432
|
+
const context = { ...this._encodeIncludes(options), name };
|
|
444
433
|
const populates = _.mapValues(context.populates, (populate) => this.dialect.encodePopulate(this, populate));
|
|
445
434
|
const stages = _.fromPairs(_.flatMap(_.values(populates), (p) => _.toPairs(p)));
|
|
446
|
-
const _populates = this._selectPopulateMap(context
|
|
435
|
+
const _populates = this._selectPopulateMap(context);
|
|
447
436
|
const joins = _.compact(_.map(_populates, ({ join }) => join));
|
|
448
437
|
return sql `
|
|
449
438
|
WITH ${{ identifier: name }} AS (
|
|
@@ -562,7 +551,7 @@ class QueryCompiler {
|
|
|
562
551
|
deleteOne(query) {
|
|
563
552
|
return this._modifyQuery({ ...query, limit: 1 }, (fetchName, context) => {
|
|
564
553
|
const name = `_delete_$${query.className.toLowerCase()}`;
|
|
565
|
-
const populates = this._selectPopulateMap(context,
|
|
554
|
+
const populates = this._selectPopulateMap({ ...context, name });
|
|
566
555
|
const joins = _.compact(_.map(populates, ({ join }) => join));
|
|
567
556
|
return sql `
|
|
568
557
|
, ${{ identifier: name }} AS (
|
|
@@ -572,7 +561,7 @@ class QueryCompiler {
|
|
|
572
561
|
)
|
|
573
562
|
SELECT ${{
|
|
574
563
|
literal: [
|
|
575
|
-
...this._selectIncludes(name, context.includes),
|
|
564
|
+
...this._selectIncludes(name, context.includes ?? {}),
|
|
576
565
|
..._.flatMap(populates, ({ columns }) => columns),
|
|
577
566
|
], separator: ',\n'
|
|
578
567
|
}}
|
|
@@ -926,6 +915,7 @@ const fetchElement = (compiler, parent, field) => {
|
|
|
926
915
|
element,
|
|
927
916
|
dataType: json ? null : dataType,
|
|
928
917
|
relation: {
|
|
918
|
+
colname,
|
|
929
919
|
target: dataType.target,
|
|
930
920
|
populate,
|
|
931
921
|
},
|
|
@@ -2175,6 +2165,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2175
2165
|
break;
|
|
2176
2166
|
return sql `${element} ${nullSafeEqual()} ${{ value: expr.value.objectId }}`;
|
|
2177
2167
|
}
|
|
2168
|
+
if (relation && _.includes(parent.countMatches, relation.colname)) {
|
|
2169
|
+
return sql `${element} ${nullSafeEqual()} ${encodeType(colname, 'number', expr.value)}`;
|
|
2170
|
+
}
|
|
2178
2171
|
return sql `${element} ${nullSafeEqual()} ${encodeValue(expr.value)}`;
|
|
2179
2172
|
}
|
|
2180
2173
|
case '$ne':
|
|
@@ -2188,6 +2181,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2188
2181
|
break;
|
|
2189
2182
|
return sql `${element} ${nullSafeNotEqual()} ${{ value: expr.value.objectId }}`;
|
|
2190
2183
|
}
|
|
2184
|
+
if (relation && _.includes(parent.countMatches, relation.colname)) {
|
|
2185
|
+
return sql `${element} ${nullSafeNotEqual()} ${encodeType(colname, 'number', expr.value)}`;
|
|
2186
|
+
}
|
|
2191
2187
|
return sql `${element} ${nullSafeNotEqual()} ${encodeValue(expr.value)}`;
|
|
2192
2188
|
}
|
|
2193
2189
|
case '$gt':
|
|
@@ -2231,6 +2227,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2231
2227
|
else if (!_.isString(dataType) && dataType?.type === 'pointer' && expr.value instanceof TObject && expr.value.objectId) {
|
|
2232
2228
|
return sql `${element} ${{ literal: op }} ${{ value: expr.value.objectId }}`;
|
|
2233
2229
|
}
|
|
2230
|
+
else if (relation && _.includes(parent.countMatches, relation.colname)) {
|
|
2231
|
+
return sql `${element} ${{ literal: op }} ${encodeType(colname, 'number', expr.value)}`;
|
|
2232
|
+
}
|
|
2234
2233
|
else if (!dataType) {
|
|
2235
2234
|
if (expr.value instanceof Decimal || _.isNumber(expr.value)) {
|
|
2236
2235
|
return sql `(
|
|
@@ -2421,6 +2420,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2421
2420
|
if (dataType && _isTypeof(dataType, 'string')) {
|
|
2422
2421
|
return sql `COALESCE(length(${element}), 0) = ${{ value: expr.value }}`;
|
|
2423
2422
|
}
|
|
2423
|
+
if (relation && _.includes(parent.countMatches, relation.colname)) {
|
|
2424
|
+
return sql `${element} = ${{ value: expr.value }}`;
|
|
2425
|
+
}
|
|
2424
2426
|
if (dataType && _isTypeof(dataType, ['array', 'string[]', 'vector', 'relation'])) {
|
|
2425
2427
|
return sql `COALESCE(array_length(${element}, 1), 0) = ${{ value: expr.value }}`;
|
|
2426
2428
|
}
|
|
@@ -2442,6 +2444,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2442
2444
|
if (dataType && _isTypeof(dataType, 'string')) {
|
|
2443
2445
|
return sql `COALESCE(length(${element}), 0) ${{ literal: expr.value ? '=' : '<>' }} 0`;
|
|
2444
2446
|
}
|
|
2447
|
+
if (relation && _.includes(parent.countMatches, relation.colname)) {
|
|
2448
|
+
return sql `${element} ${{ literal: expr.value ? '=' : '<>' }} 0`;
|
|
2449
|
+
}
|
|
2445
2450
|
if (dataType && _isTypeof(dataType, ['array', 'string[]', 'vector', 'relation'])) {
|
|
2446
2451
|
return sql `COALESCE(array_length(${element}, 1), 0) ${{ literal: expr.value ? '=' : '<>' }} 0`;
|
|
2447
2452
|
}
|