proto.io 0.0.154 → 0.0.156

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 (38) hide show
  1. package/dist/adapters/file/database.d.ts +2 -2
  2. package/dist/adapters/file/filesystem.d.ts +2 -2
  3. package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
  4. package/dist/adapters/storage/progres.d.ts +11 -7
  5. package/dist/adapters/storage/progres.js +55 -14
  6. package/dist/adapters/storage/progres.js.map +1 -1
  7. package/dist/adapters/storage/progres.mjs +55 -14
  8. package/dist/adapters/storage/progres.mjs.map +1 -1
  9. package/dist/client.d.ts +3 -3
  10. package/dist/client.js +1 -1
  11. package/dist/client.mjs +2 -2
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +39 -19
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +40 -20
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/internals/{index-c-CaNuVY.mjs → index-B01TqoO1.mjs} +19 -4
  18. package/dist/internals/index-B01TqoO1.mjs.map +1 -0
  19. package/dist/internals/{index-BeRyWUVp.d.ts → index-BLVOKfv3.d.ts} +15 -6
  20. package/dist/internals/index-BLVOKfv3.d.ts.map +1 -0
  21. package/dist/internals/{index-D1YGwuNK.js → index-Bs06MNCK.js} +19 -4
  22. package/dist/internals/index-Bs06MNCK.js.map +1 -0
  23. package/dist/internals/{index-rx1BTcvL.d.ts → index-DSU589g6.d.ts} +2 -2
  24. package/dist/internals/index-DSU589g6.d.ts.map +1 -0
  25. package/dist/internals/{index-DI0coKnM.d.ts → index-DmcvF1dx.d.ts} +3 -2
  26. package/dist/internals/index-DmcvF1dx.d.ts.map +1 -0
  27. package/dist/internals/{random-DBDmz54D.js → random-CPI-IjeV.js} +25 -3
  28. package/dist/internals/random-CPI-IjeV.js.map +1 -0
  29. package/dist/internals/{random-KZTFMK9-.mjs → random-DLFngtjg.mjs} +25 -3
  30. package/dist/internals/random-DLFngtjg.mjs.map +1 -0
  31. package/package.json +1 -1
  32. package/dist/internals/index-BeRyWUVp.d.ts.map +0 -1
  33. package/dist/internals/index-D1YGwuNK.js.map +0 -1
  34. package/dist/internals/index-DI0coKnM.d.ts.map +0 -1
  35. package/dist/internals/index-c-CaNuVY.mjs.map +0 -1
  36. package/dist/internals/index-rx1BTcvL.d.ts.map +0 -1
  37. package/dist/internals/random-DBDmz54D.js.map +0 -1
  38. package/dist/internals/random-KZTFMK9-.mjs.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-tU-lsQqj.mjs';
9
9
  import '@o2ter/crypto-js';
10
- import { _ as _resolveColumn, g as generateId, Q as QueryValidator } from '../../internals/random-KZTFMK9-.mjs';
10
+ import { _ as _resolveColumn, g as generateId, Q as QueryValidator } from '../../internals/random-DLFngtjg.mjs';
11
11
  import { P as PVK } from '../../internals/private-BUpLAMZi.mjs';
12
12
 
13
13
  //
@@ -282,35 +282,38 @@ class QueryCompiler {
282
282
  }
283
283
  _baseSelectQuery(query, options) {
284
284
  const context = this._makeContext(query);
285
- const populates = _.mapValues(context.populates, (populate) => this.dialect.encodePopulate(this, context, populate));
286
- const stages = _.fromPairs(_.flatMap(_.values(populates), (p) => _.toPairs(p)));
285
+ const _stages = _.mapValues(context.populates, (populate) => this.dialect.encodePopulate(this, context, populate));
286
+ const stages = _.fromPairs(_.flatMap(_.values(_stages), (p) => _.toPairs(p)));
287
287
  const fetchName = `_fetch_$${query.className.toLowerCase()}`;
288
- const _filter = this._encodeFilter(context, { className: query.className, name: fetchName }, query.filter);
289
- const _populates = this._selectPopulateMap(context, query.className, fetchName);
290
- const _joins = _.compact(_.map(_populates, ({ join }) => join));
291
- const _includes = {
288
+ const parent = { className: query.className, name: fetchName };
289
+ const baseFilter = this._encodeFilter(context, parent, query.filter);
290
+ const populates = this._selectPopulateMap(context, query.className, fetchName);
291
+ const joins = _.compact(_.map(populates, ({ join }) => join));
292
+ const includes = {
292
293
  literal: [
293
294
  ...this._selectIncludes(fetchName, context.includes),
294
- ..._.flatMap(_populates, ({ columns }) => columns),
295
+ ..._.flatMap(populates, ({ columns }) => columns),
295
296
  ],
296
297
  separator: ',\n',
297
298
  };
298
299
  const _options = _.isFunction(options) ? options({ fetchName }) : options;
300
+ const filter = _.compact([
301
+ baseFilter,
302
+ _options?.extraFilter,
303
+ query.relatedBy && this.dialect.encodeRelation(this, context, parent, query.relatedBy),
304
+ ]);
299
305
  return {
300
306
  stages,
301
307
  fetchName,
302
308
  context: context,
303
309
  query: sql `
304
310
  SELECT ${_options?.select ? _options?.select : sql `*`} FROM (
305
- SELECT ${_includes}
311
+ SELECT ${includes}
306
312
  FROM ${{ identifier: query.className }} AS ${{ identifier: fetchName }}
307
- ${!_.isEmpty(_joins) ? { literal: _joins, separator: '\n' } : sql ``}
313
+ ${!_.isEmpty(joins) ? { literal: joins, separator: '\n' } : sql ``}
308
314
  ${this.selectLock ? this.isUpdate ? sql `FOR UPDATE NOWAIT` : sql `FOR SHARE NOWAIT` : sql ``}
309
315
  ) AS ${{ identifier: fetchName }}
310
- ${_filter || _options?.extraFilter ? sql `WHERE ${{
311
- literal: _.map(_.compact([_filter, _options?.extraFilter]), x => sql `(${x})`),
312
- separator: ' AND '
313
- }}` : sql ``}
316
+ ${!_.isEmpty(filter) ? sql `WHERE ${{ literal: _.map(filter, x => sql `(${x})`), separator: ' AND ' }}` : sql ``}
314
317
  ${_options?.sort ? _options?.sort : sql ``}
315
318
  ${!_.isEmpty(query.sort) ? sql `ORDER BY ${this._encodeSort(query.sort, { className: query.className, name: fetchName })}` : sql ``}
316
319
  ${query.limit ? sql `LIMIT ${{ literal: `${query.limit}` }}` : sql ``}
@@ -2289,6 +2292,43 @@ const encodePopulate = (compiler, context, parent, remix) => {
2289
2292
  });
2290
2293
  };
2291
2294
 
2295
+ //
2296
+ // relation.ts
2297
+ //
2298
+ // The MIT License
2299
+ // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2300
+ //
2301
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
2302
+ // of this software and associated documentation files (the "Software"), to deal
2303
+ // in the Software without restriction, including without limitation the rights
2304
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2305
+ // copies of the Software, and to permit persons to whom the Software is
2306
+ // furnished to do so, subject to the following conditions:
2307
+ //
2308
+ // The above copyright notice and this permission notice shall be included in
2309
+ // all copies or substantial portions of the Software.
2310
+ //
2311
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2312
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2313
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2314
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2315
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2316
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2317
+ // THE SOFTWARE.
2318
+ //
2319
+ const encodeRelation = (compiler, context, parent, relatedBy) => {
2320
+ const name = `_relation_$${relatedBy.className.toLowerCase()}`;
2321
+ const _local = (field) => sql `${{ identifier: parent.name }}.${{ identifier: field }}`;
2322
+ const _foreign = (field) => sql `${{ identifier: name }}.${{ identifier: field }}`;
2323
+ return sql `
2324
+ EXISTS (
2325
+ SELECT 1
2326
+ FROM ${{ identifier: relatedBy.className }} AS ${{ identifier: name }}
2327
+ WHERE ${_foreign('_id')} = ${{ value: relatedBy.objectId }} AND ${sql `(${{ quote: parent.className + '$' }} || ${_local('_id')})`} = ANY(${_foreign(relatedBy.key)})
2328
+ )
2329
+ `;
2330
+ };
2331
+
2292
2332
  //
2293
2333
  // index.ts
2294
2334
  //
@@ -2325,6 +2365,7 @@ const PostgresDialect = {
2325
2365
  encodeFieldExpression,
2326
2366
  encodeQueryExpression,
2327
2367
  encodePopulate,
2368
+ encodeRelation,
2328
2369
  encodeSortKey,
2329
2370
  random,
2330
2371
  };