proto.io 0.0.212 → 0.0.214

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 (44) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +2 -2
  4. package/dist/adapters/file/database.js.map +1 -1
  5. package/dist/adapters/file/database.mjs +1 -1
  6. package/dist/adapters/file/filesystem.d.ts +3 -3
  7. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  8. package/dist/adapters/storage/progres.d.ts +1 -1
  9. package/dist/adapters/storage/progres.js +117 -84
  10. package/dist/adapters/storage/progres.js.map +1 -1
  11. package/dist/adapters/storage/progres.mjs +79 -46
  12. package/dist/adapters/storage/progres.mjs.map +1 -1
  13. package/dist/client.d.ts +3 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +42 -42
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +2 -2
  18. package/dist/internals/{base-CZGalGrd.d.ts → base-E1b8J-Fs.d.ts} +2 -2
  19. package/dist/internals/base-E1b8J-Fs.d.ts.map +1 -0
  20. package/dist/internals/{chunk-BsT9SYny.d.ts → chunk-D1bD7otk.d.ts} +3 -3
  21. package/dist/internals/chunk-D1bD7otk.d.ts.map +1 -0
  22. package/dist/internals/{index-Boxwkqe0.d.ts → index-CbjY-gJ7.d.ts} +6 -8
  23. package/dist/internals/index-CbjY-gJ7.d.ts.map +1 -0
  24. package/dist/internals/{index-NF-U_3zG.d.ts → index-SSEdPyhp.d.ts} +2 -2
  25. package/dist/internals/index-SSEdPyhp.d.ts.map +1 -0
  26. package/dist/internals/random-CYjWDvex.mjs +37 -0
  27. package/dist/internals/random-CYjWDvex.mjs.map +1 -0
  28. package/dist/internals/random-nkOQ9U6S.js +39 -0
  29. package/dist/internals/random-nkOQ9U6S.js.map +1 -0
  30. package/dist/internals/{index-D8O7SinR.js → validator-DoRPoIs2.js} +586 -2
  31. package/dist/internals/validator-DoRPoIs2.js.map +1 -0
  32. package/dist/internals/{index-DG9HHO_U.mjs → validator-Dxmbwa3P.mjs} +583 -3
  33. package/dist/internals/validator-Dxmbwa3P.mjs.map +1 -0
  34. package/package.json +1 -1
  35. package/dist/internals/base-CZGalGrd.d.ts.map +0 -1
  36. package/dist/internals/chunk-BsT9SYny.d.ts.map +0 -1
  37. package/dist/internals/index-Boxwkqe0.d.ts.map +0 -1
  38. package/dist/internals/index-D8O7SinR.js.map +0 -1
  39. package/dist/internals/index-DG9HHO_U.mjs.map +0 -1
  40. package/dist/internals/index-NF-U_3zG.d.ts.map +0 -1
  41. package/dist/internals/random-CufRbivU.mjs +0 -526
  42. package/dist/internals/random-CufRbivU.mjs.map +0 -1
  43. package/dist/internals/random-DzvxbWAc.js +0 -532
  44. package/dist/internals/random-DzvxbWAc.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { P as ProtoService } from '../../internals/index-Boxwkqe0.js';
1
+ import { P as ProtoService } from '../../internals/index-CbjY-gJ7.js';
2
2
  import OSS from 'ali-oss';
3
- import { a as FileStorageOptions } from '../../internals/base-CZGalGrd.js';
4
- import { F as FileChunkStorageBase } from '../../internals/chunk-BsT9SYny.js';
3
+ import { a as FileStorageOptions } from '../../internals/base-E1b8J-Fs.js';
4
+ import { F as FileChunkStorageBase } from '../../internals/chunk-D1bD7otk.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'jsonwebtoken';
7
7
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-Boxwkqe0.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-CZGalGrd.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-CbjY-gJ7.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-E1b8J-Fs.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _ = require('lodash');
6
6
  var base = require('../../internals/base-NsJYo2MG.js');
7
7
  var utilsJs = require('@o2ter/utils-js');
8
- var index = require('../../internals/index-D8O7SinR.js');
8
+ var validator = require('../../internals/validator-DoRPoIs2.js');
9
9
  require('util');
10
10
  require('zlib');
11
11
  require('../../internals/private-Ciddhure.js');
@@ -101,7 +101,7 @@ class DatabaseFileStorage extends base.FileStorageBase {
101
101
  async destroy(proto, token) {
102
102
  proto.storage.delete({
103
103
  className: '_FileChunk',
104
- filter: index.QuerySelector.decode({ token: { $eq: token } }),
104
+ filter: validator.QuerySelector.decode({ token: { $eq: token } }),
105
105
  includes: ['_id'],
106
106
  matches: {},
107
107
  groupMatches: {},
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sources":["../../../../src/adapters/file/database/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { TSchema } from '../../../internals/schema';\nimport FileStorageBase, { FileStorageOptions } from '../base';\nimport { QuerySelector } from '../../../server/query/dispatcher/parser';\nimport { base64ToBuffer, bufferToBase64 } from '@o2ter/utils-js';\n\nexport class DatabaseFileStorage extends FileStorageBase {\n\n constructor(options: FileStorageOptions = {}) {\n super(options);\n }\n\n get schema(): Record<string, TSchema> {\n return {\n '_FileChunk': {\n fields: {\n token: 'string',\n start: 'number',\n end: 'number',\n size: 'number',\n base64: 'string',\n },\n classLevelPermissions: {\n get: [],\n find: [],\n count: [],\n create: [],\n update: [],\n delete: [],\n },\n fieldLevelPermissions: {\n _expired_at: { create: [], update: [] },\n },\n indexes: [\n { keys: { token: 1, start: 1, end: 1 } },\n { keys: { token: 1, end: 1 } },\n ]\n },\n }\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n\n const created = await proto.Query('_FileChunk').insert({\n token,\n start: start,\n end: end,\n size: end - start,\n base64: bufferToBase64(compressed),\n }, { master: true });\n\n if (!created) throw Error('Unable to save file');\n\n }\n\n async* readChunks<E>(proto: ProtoService<E>, token: string, start?: number, end?: number) {\n const query = proto.Query('_FileChunk')\n .sort({ start: 1 })\n .filter({\n token: { $eq: token },\n ...start ? { end: { $gt: start } } : {},\n ...end ? { start: { $lt: end } } : {},\n });\n for await (const chunk of query.find({ master: true })) {\n const startBytes = chunk.get('start');\n const base64 = chunk.get('base64');\n if (!_.isNumber(startBytes) || !_.isString(base64)) throw Error('Corrupted data');\n yield {\n start: startBytes,\n data: base64ToBuffer(base64),\n };\n }\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n proto.storage.delete({\n className: '_FileChunk',\n filter: QuerySelector.decode({ token: { $eq: token } }),\n includes: ['_id'],\n matches: {},\n groupMatches: {},\n objectIdSize: 0\n });\n }\n};\n\nexport default DatabaseF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;YACjF,MAAM;AACJ,gBAAA,KAAK,EAAE,UAAU;AACjB,gBAAA,IAAI,EAAEC,sBAAc,CAAC,MAAM,CAAC;aAC7B;;;AAIL,IAAA,MAAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AACnB,YAAA,SAAS,EAAE,YAAY;AACvB,YAAA,MAAM,EAAEC,mBAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;YACvD,QAAQ,EAAE,CAAC,KAAK,CAAC;AACjB,YAAA,OAAO,EAAE,EAAE;AACX,YAAA,YAAY,EAAE,EAAE;AAChB,YAAA,YAAY,EAAE;AACf,SAAA,CAAC;;AAEL;;;;;"}
1
+ {"version":3,"file":"database.js","sources":["../../../../src/adapters/file/database/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { TSchema } from '../../../internals/schema';\nimport FileStorageBase, { FileStorageOptions } from '../base';\nimport { QuerySelector } from '../../../server/query/dispatcher/parser';\nimport { base64ToBuffer, bufferToBase64 } from '@o2ter/utils-js';\n\nexport class DatabaseFileStorage extends FileStorageBase {\n\n constructor(options: FileStorageOptions = {}) {\n super(options);\n }\n\n get schema(): Record<string, TSchema> {\n return {\n '_FileChunk': {\n fields: {\n token: 'string',\n start: 'number',\n end: 'number',\n size: 'number',\n base64: 'string',\n },\n classLevelPermissions: {\n get: [],\n find: [],\n count: [],\n create: [],\n update: [],\n delete: [],\n },\n fieldLevelPermissions: {\n _expired_at: { create: [], update: [] },\n },\n indexes: [\n { keys: { token: 1, start: 1, end: 1 } },\n { keys: { token: 1, end: 1 } },\n ]\n },\n }\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n\n const created = await proto.Query('_FileChunk').insert({\n token,\n start: start,\n end: end,\n size: end - start,\n base64: bufferToBase64(compressed),\n }, { master: true });\n\n if (!created) throw Error('Unable to save file');\n\n }\n\n async* readChunks<E>(proto: ProtoService<E>, token: string, start?: number, end?: number) {\n const query = proto.Query('_FileChunk')\n .sort({ start: 1 })\n .filter({\n token: { $eq: token },\n ...start ? { end: { $gt: start } } : {},\n ...end ? { start: { $lt: end } } : {},\n });\n for await (const chunk of query.find({ master: true })) {\n const startBytes = chunk.get('start');\n const base64 = chunk.get('base64');\n if (!_.isNumber(startBytes) || !_.isString(base64)) throw Error('Corrupted data');\n yield {\n start: startBytes,\n data: base64ToBuffer(base64),\n };\n }\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n proto.storage.delete({\n className: '_FileChunk',\n filter: QuerySelector.decode({ token: { $eq: token } }),\n includes: ['_id'],\n matches: {},\n groupMatches: {},\n objectIdSize: 0\n });\n }\n};\n\nexport default Database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C;YACjF,MAAM;AACJ,gBAAA,KAAK,EAAE,UAAU;AACjB,gBAAA,IAAI,EAAEC,sBAAc,CAAC,MAAM,CAAC;aAC7B;;;AAIL,IAAA,MAAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AACnB,YAAA,SAAS,EAAE,YAAY;AACvB,YAAA,MAAM,EAAEC,uBAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;YACvD,QAAQ,EAAE,CAAC,KAAK,CAAC;AACjB,YAAA,OAAO,EAAE,EAAE;AACX,YAAA,YAAY,EAAE,EAAE;AAChB,YAAA,YAAY,EAAE;AACf,SAAA,CAAC;;AAEL;;;;;"}
@@ -1,7 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import { F as FileStorageBase } from '../../internals/base-DYc1_peK.mjs';
3
3
  import { bufferToBase64, base64ToBuffer } from '@o2ter/utils-js';
4
- import { Q as QuerySelector } from '../../internals/index-DG9HHO_U.mjs';
4
+ import { b as QuerySelector } from '../../internals/validator-Dxmbwa3P.mjs';
5
5
  import 'util';
6
6
  import 'zlib';
7
7
  import '../../internals/private-CNw40LZ7.mjs';
@@ -1,6 +1,6 @@
1
- import { P as ProtoService } from '../../internals/index-Boxwkqe0.js';
2
- import { a as FileStorageOptions } from '../../internals/base-CZGalGrd.js';
3
- import { F as FileChunkStorageBase } from '../../internals/chunk-BsT9SYny.js';
1
+ import { P as ProtoService } from '../../internals/index-CbjY-gJ7.js';
2
+ import { a as FileStorageOptions } from '../../internals/base-E1b8J-Fs.js';
3
+ import { F as FileChunkStorageBase } from '../../internals/chunk-D1bD7otk.js';
4
4
  import '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
6
6
  import '@o2ter/server-js';
@@ -1,8 +1,8 @@
1
1
  import * as _google_cloud_storage from '@google-cloud/storage';
2
2
  import { File, Storage } from '@google-cloud/storage';
3
- import { P as ProtoService } from '../../internals/index-Boxwkqe0.js';
4
- import { a as FileStorageOptions } from '../../internals/base-CZGalGrd.js';
5
- import { F as FileChunkStorageBase } from '../../internals/chunk-BsT9SYny.js';
3
+ import { P as ProtoService } from '../../internals/index-CbjY-gJ7.js';
4
+ import { a as FileStorageOptions } from '../../internals/base-E1b8J-Fs.js';
5
+ import { F as FileChunkStorageBase } from '../../internals/chunk-D1bD7otk.js';
6
6
  import '@o2ter/utils-js';
7
7
  import 'jsonwebtoken';
8
8
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
1
  import { Pool, PoolClient, PoolConfig } from 'pg';
2
- import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QueryAccumulator, y as QuerySelector, z as DecodedSortOption, A as DecodedQuery, B as FindOptions, I as InsertOptions, C as TStorage, G as TransactionOptions, j as TObject, H as TQueryRandomOptions, J as TPubSub } from '../../internals/index-Boxwkqe0.js';
2
+ import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QueryAccumulator, y as QuerySelector, z as DecodedSortOption, A as DecodedQuery, B as FindOptions, I as InsertOptions, C as TStorage, G as TransactionOptions, j as TObject, H as TQueryRandomOptions, J as TPubSub } from '../../internals/index-CbjY-gJ7.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
@@ -9,10 +9,10 @@ var QueryStream = require('pg-query-stream');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
10
  var Decimal = require('decimal.js');
11
11
  var utils = require('pg/lib/utils');
12
- var index$1 = require('../../internals/index-D8O7SinR.js');
12
+ var validator = require('../../internals/validator-DoRPoIs2.js');
13
13
  require('@o2ter/crypto-js');
14
- var random$1 = require('../../internals/random-DzvxbWAc.js');
15
14
  var _const = require('../../internals/const-C3I6cfav.js');
15
+ var random$1 = require('../../internals/random-nkOQ9U6S.js');
16
16
  var _private = require('../../internals/private-Ciddhure.js');
17
17
 
18
18
  //
@@ -220,7 +220,7 @@ class QueryCompiler {
220
220
  const populates = {};
221
221
  const groupMatches = {};
222
222
  for (const include of query.includes) {
223
- const { paths: [colname, ...subpath], dataType } = random$1.resolveColumn(this.schema, query.className, include);
223
+ const { paths: [colname, ...subpath], dataType } = validator.resolveColumn(this.schema, query.className, include);
224
224
  names[colname] = dataType;
225
225
  if (index.isRelation(dataType) && !_.isNil(query.groupMatches[colname]))
226
226
  groupMatches[colname] = query.groupMatches[colname];
@@ -239,7 +239,7 @@ class QueryCompiler {
239
239
  colname,
240
240
  };
241
241
  if (index.isRelation(dataType) && dataType.foreignField) {
242
- const targetType = random$1.resolveDataType(this.schema, dataType.target, dataType.foreignField);
242
+ const targetType = validator.resolveDataType(this.schema, dataType.target, dataType.foreignField);
243
243
  if (_.isNil(targetType))
244
244
  throw Error(`Invalid path: ${include}`);
245
245
  if (!index.isPointer(targetType) && !index.isRelation(targetType))
@@ -309,7 +309,11 @@ class QueryCompiler {
309
309
  ) AS ${{ identifier: fetchName }}
310
310
  ${!_.isEmpty(filter) ? sql `WHERE ${{ literal: _.map(filter, x => sql `(${x})`), separator: ' AND ' }}` : sql ``}
311
311
  ${_options?.sort ? _options?.sort : sql ``}
312
- ${!_.isEmpty(query.sort) ? sql `ORDER BY ${this._encodeSort(query.sort, { className: query.className, name: fetchName })}` : sql ``}
312
+ ${!_.isEmpty(query.sort) ? sql `ORDER BY ${this._encodeSort(query.sort, {
313
+ name: fetchName,
314
+ className: query.className,
315
+ groupMatches: query.groupMatches,
316
+ })}` : sql ``}
313
317
  ${query.limit ? sql `LIMIT ${{ literal: `${query.limit}` }}` : sql ``}
314
318
  ${query.skip ? sql `OFFSET ${{ literal: `${query.skip}` }}` : sql ``}
315
319
  `,
@@ -355,7 +359,7 @@ class QueryCompiler {
355
359
  sql `_updated_at = NOW()`,
356
360
  ];
357
361
  for (const [path, op] of _.toPairs(attrs)) {
358
- const { paths: [column, ...subpath], dataType } = random$1.resolveColumn(this.schema, className, path);
362
+ const { paths: [column, ...subpath], dataType } = validator.resolveColumn(this.schema, className, path);
359
363
  if (index.isShape(dataType)) {
360
364
  const [_op, value] = index.decodeUpdateOp(op);
361
365
  if (_op !== '$set')
@@ -375,7 +379,7 @@ class QueryCompiler {
375
379
  _encodeObjectAttrs(className, attrs) {
376
380
  const result = {};
377
381
  for (const [key, value] of _.toPairs(attrs)) {
378
- const { paths: [column, ...subpath], dataType } = random$1.resolveColumn(this.schema, className, key);
382
+ const { paths: [column, ...subpath], dataType } = validator.resolveColumn(this.schema, className, key);
379
383
  if (!_.isEmpty(subpath))
380
384
  throw Error(`Invalid insert key: ${key}`);
381
385
  if (index.isShape(dataType)) {
@@ -402,13 +406,13 @@ class QueryCompiler {
402
406
  }
403
407
  }
404
408
  _encodeFilter(parent, filter) {
405
- if (filter instanceof index$1.QueryCoditionalSelector) {
409
+ if (filter instanceof validator.QueryCoditionalSelector) {
406
410
  return this._encodeCoditionalSelector(parent, filter);
407
411
  }
408
- if (filter instanceof index$1.QueryFieldSelector) {
412
+ if (filter instanceof validator.QueryFieldSelector) {
409
413
  return this.dialect.encodeFieldExpression(this, parent, filter.field, filter.expr);
410
414
  }
411
- if (filter instanceof index$1.QueryExpressionSelector) {
415
+ if (filter instanceof validator.QueryExpressionSelector) {
412
416
  return this.dialect.encodeQueryExpression(this, parent, filter.expr);
413
417
  }
414
418
  }
@@ -668,14 +672,19 @@ class SqlStorage {
668
672
  const count = parseInt(_count);
669
673
  return _.isFinite(count) ? count : 0;
670
674
  }
671
- _matchesType(options) {
675
+ _matchesType(compiler, options) {
672
676
  const types = {};
673
677
  for (const [key, match] of _.entries(options.matches)) {
674
- types[key] = this._matchesType(match);
678
+ const type = validator.resolveDataType(compiler.schema, options.className, key);
679
+ if (_.isNil(type))
680
+ continue;
681
+ if (index.isPointer(type) || index.isRelation(type)) {
682
+ types[key] = this._matchesType(compiler, { className: type.target, ...match });
683
+ }
675
684
  }
676
685
  for (const [key, group] of _.entries(options.groupMatches)) {
677
686
  for (const [field, expr] of _.entries(group)) {
678
- _.set(types, `${key}.${field}`, random$1.accumulatorKeyTypes[expr.type]);
687
+ _.set(types, `${key}.${field}`, expr.evalType(compiler.schema, options.className));
679
688
  }
680
689
  }
681
690
  return types;
@@ -683,24 +692,26 @@ class SqlStorage {
683
692
  find(query) {
684
693
  const self = this;
685
694
  const compiler = self._makeCompiler(false, query.extraFilter);
695
+ const _matchesType = self._matchesType(compiler, query);
686
696
  const _query = compiler._selectQuery(query);
687
697
  return (async function* () {
688
698
  const objects = self.query(_query);
689
699
  for await (const object of objects) {
690
- yield self._decodeObject(query.className, object, self._matchesType(query));
700
+ yield self._decodeObject(query.className, object, _matchesType);
691
701
  }
692
702
  })();
693
703
  }
694
704
  random(query, opts) {
695
705
  const self = this;
696
706
  const compiler = self._makeCompiler(false, query.extraFilter);
707
+ const _matchesType = self._matchesType(compiler, query);
697
708
  const _query = compiler._selectQuery({ ...query, sort: {} }, {
698
709
  sort: sql `ORDER BY ${self.dialect.random(opts ?? {})}`,
699
710
  });
700
711
  return (async function* () {
701
712
  const objects = self.query(_query);
702
713
  for await (const object of objects) {
703
- yield self._decodeObject(query.className, object, self._matchesType(query));
714
+ yield self._decodeObject(query.className, object, _matchesType);
704
715
  }
705
716
  })();
706
717
  }
@@ -721,6 +732,7 @@ class SqlStorage {
721
732
  nonrefs(query) {
722
733
  const self = this;
723
734
  const compiler = self._makeCompiler(false, query.extraFilter);
735
+ const _matchesType = self._matchesType(compiler, query);
724
736
  const _query = compiler._selectQuery(query, ({ fetchName }) => ({
725
737
  extraFilter: sql `
726
738
  NOT EXISTS (${this._refs(this.schema, query.className, ['_id'], sql `(${{ quote: query.className + '$' }} || ${{ identifier: fetchName }}.${{ identifier: '_id' }})`)})
@@ -729,29 +741,33 @@ class SqlStorage {
729
741
  return (async function* () {
730
742
  const objects = self.query(_query);
731
743
  for await (const object of objects) {
732
- yield self._decodeObject(query.className, object, self._matchesType(query));
744
+ yield self._decodeObject(query.className, object, _matchesType);
733
745
  }
734
746
  })();
735
747
  }
736
748
  async insert(options, values) {
737
749
  const compiler = this._makeCompiler(true);
750
+ const _matchesType = this._matchesType(compiler, options);
738
751
  const result = await this.query(compiler.insert(options, values));
739
- return _.map(result, x => this._decodeObject(options.className, x, this._matchesType(options)));
752
+ return _.map(result, x => this._decodeObject(options.className, x, _matchesType));
740
753
  }
741
754
  async update(query, update) {
742
755
  const compiler = this._makeCompiler(true, query.extraFilter);
756
+ const _matchesType = this._matchesType(compiler, query);
743
757
  const updated = await this.query(compiler.update(query, update));
744
- return _.map(updated, x => this._decodeObject(query.className, x, this._matchesType(query)));
758
+ return _.map(updated, x => this._decodeObject(query.className, x, _matchesType));
745
759
  }
746
760
  async upsert(query, update, setOnInsert) {
747
761
  const compiler = this._makeCompiler(true, query.extraFilter);
762
+ const _matchesType = this._matchesType(compiler, query);
748
763
  const upserted = await this.query(compiler.upsert(query, update, setOnInsert));
749
- return _.map(upserted, x => this._decodeObject(query.className, x, this._matchesType(query)));
764
+ return _.map(upserted, x => this._decodeObject(query.className, x, _matchesType));
750
765
  }
751
766
  async delete(query) {
752
767
  const compiler = this._makeCompiler(true, query.extraFilter);
768
+ const _matchesType = this._matchesType(compiler, query);
753
769
  const deleted = await this.query(compiler.delete(query));
754
- return _.map(deleted, x => this._decodeObject(query.className, x, this._matchesType(query)));
770
+ return _.map(deleted, x => this._decodeObject(query.className, x, _matchesType));
755
771
  }
756
772
  }
757
773
 
@@ -779,7 +795,7 @@ class SqlStorage {
779
795
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
780
796
  // THE SOFTWARE.
781
797
  //
782
- const _fetchElement = (parent, colname, subpath, dataType) => {
798
+ const _fetchElement = (compiler, parent, colname, subpath, dataType) => {
783
799
  const element = sql `${{ identifier: parent.name }}.${{ identifier: parent.name.startsWith('_doller_expr_$') ? '$' : colname }}`;
784
800
  if (!parent.className) {
785
801
  if (colname !== '$') {
@@ -802,7 +818,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
802
818
  return {
803
819
  element: sql `${{ identifier: parent.name }}.${{ identifier: `${colname}.${subpath[0]}` }}`,
804
820
  json: false,
805
- dataType: random$1.accumulatorKeyTypes[match.type],
821
+ dataType: match.evalType(compiler.schema, dataType.target),
806
822
  };
807
823
  }
808
824
  else if (dataType && index._isTypeof(dataType, ['array', 'string[]', 'relation'])) {
@@ -827,7 +843,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
827
843
  return { element, json: false };
828
844
  };
829
845
  const resolvePaths = (compiler, className, paths) => {
830
- const { paths: [colname, ...subpath], dataType } = random$1.resolveColumn(compiler.schema, className, paths.join('.'));
846
+ const { paths: [colname, ...subpath], dataType } = validator.resolveColumn(compiler.schema, className, paths.join('.'));
831
847
  if (!_.isEmpty(subpath) && index.isVector(dataType)) {
832
848
  if (subpath.length !== 1)
833
849
  throw Error(`Invalid key: ${paths.join('.')}`);
@@ -844,7 +860,7 @@ const resolvePaths = (compiler, className, paths) => {
844
860
  return { ...resolved, colname: `${colname}.${resolved.colname}` };
845
861
  }
846
862
  const digit = _.first(subpath);
847
- if (!_.isEmpty(subpath) && index.isRelation(dataType) && digit?.match(random$1.QueryValidator.patterns.digits)) {
863
+ if (!_.isEmpty(subpath) && index.isRelation(dataType) && digit?.match(validator.QueryValidator.patterns.digits)) {
848
864
  const resolved = resolvePaths(compiler, dataType.target, _.slice(subpath, 1));
849
865
  return { dataType, colname, subpath: [digit, resolved.colname, ...resolved.subpath] };
850
866
  }
@@ -865,7 +881,7 @@ const _resolvePopulate = (path, populates) => {
865
881
  const fetchElement = (compiler, parent, field) => {
866
882
  if (parent.className) {
867
883
  const { dataType, colname, subpath } = resolvePaths(compiler, parent.className, _.toPath(field));
868
- const { element, json, dataType: _dataType } = _fetchElement(parent, colname, subpath, dataType);
884
+ const { element, json, dataType: _dataType } = _fetchElement(compiler, parent, colname, subpath, dataType);
869
885
  if (index.isPointer(dataType))
870
886
  return { element: sql `${{ identifier: parent.name }}.${{ identifier: `${colname}._id` }}`, dataType };
871
887
  const populate = index.isRelation(dataType) && _resolvePopulate(_.toPath(colname), parent.populates);
@@ -897,7 +913,7 @@ const fetchElement = (compiler, parent, field) => {
897
913
  }
898
914
  }
899
915
  const [colname, ...subpath] = _.toPath(field);
900
- const { element } = _fetchElement(parent, colname, subpath);
916
+ const { element } = _fetchElement(compiler, parent, colname, subpath);
901
917
  return { element, dataType: null, relation: null };
902
918
  };
903
919
 
@@ -1660,36 +1676,48 @@ const updateOperation = (paths, dataType, operation) => {
1660
1676
  // THE SOFTWARE.
1661
1677
  //
1662
1678
  const isArrayExpression = (expr) => {
1663
- if (expr instanceof index$1.QueryArrayExpression)
1679
+ if (expr instanceof validator.QueryArrayExpression)
1664
1680
  return true;
1665
- if (expr instanceof index$1.QueryValueExpression)
1681
+ if (expr instanceof validator.QueryValueExpression)
1666
1682
  return _.isArray(expr.value);
1667
1683
  return false;
1668
1684
  };
1669
1685
  const arrayLength = (expr) => {
1670
- if (expr instanceof index$1.QueryArrayExpression)
1686
+ if (expr instanceof validator.QueryArrayExpression)
1671
1687
  return expr.exprs.length;
1672
- if (expr instanceof index$1.QueryValueExpression)
1688
+ if (expr instanceof validator.QueryValueExpression)
1673
1689
  return _.isArray(expr.value) ? expr.value.length : 0;
1674
1690
  return 0;
1675
1691
  };
1676
1692
  const mapExpression = (expr, callback) => {
1677
- if (expr instanceof index$1.QueryArrayExpression)
1693
+ if (expr instanceof validator.QueryArrayExpression)
1678
1694
  return _.map(expr.exprs, x => callback(x));
1679
- if (expr instanceof index$1.QueryValueExpression)
1680
- return _.isArray(expr.value) ? _.map(expr.value, x => callback(new index$1.QueryValueExpression(x))) : [];
1695
+ if (expr instanceof validator.QueryValueExpression)
1696
+ return _.isArray(expr.value) ? _.map(expr.value, x => callback(new validator.QueryValueExpression(x))) : [];
1681
1697
  return [];
1682
1698
  };
1683
1699
  const _PrimitiveValue = ['boolean', 'number', 'decimal', 'string', 'date'];
1684
1700
  const encodeTypedQueryExpression = (compiler, parent, expr) => {
1685
- if (expr instanceof index$1.QueryKeyExpression) {
1701
+ if (expr instanceof validator.QueryKeyExpression) {
1686
1702
  const { element, dataType } = fetchElement(compiler, parent, expr.key);
1687
1703
  const _dataType = dataType ? index._typeof(dataType) : null;
1688
- if (_dataType && _PrimitiveValue.includes(_dataType)) {
1704
+ if (_dataType === 'number') {
1705
+ return [
1706
+ { type: 'number', sql: element },
1707
+ { type: 'decimal', sql: sql `CAST((${element}) AS DECIMAL)` },
1708
+ ];
1709
+ }
1710
+ else if (_dataType === 'decimal') {
1711
+ return [
1712
+ { type: 'decimal', sql: element },
1713
+ { type: 'number', sql: element },
1714
+ ];
1715
+ }
1716
+ else if (_dataType && _PrimitiveValue.includes(_dataType)) {
1689
1717
  return [{ type: _dataType, sql: element }];
1690
1718
  }
1691
1719
  }
1692
- if (expr instanceof index$1.QueryValueExpression) {
1720
+ if (expr instanceof validator.QueryValueExpression) {
1693
1721
  if (_.isBoolean(expr.value))
1694
1722
  return [{ type: 'boolean', sql: sql `${{ value: expr.value }}` }];
1695
1723
  if (_.isNumber(expr.value))
@@ -1707,20 +1735,20 @@ const encodeTypedQueryExpression = (compiler, parent, expr) => {
1707
1735
  if (_.isDate(expr.value))
1708
1736
  return [{ type: 'date', sql: sql `${{ value: expr.value }}` }];
1709
1737
  }
1710
- if (expr instanceof index$1.QueryCoditionalExpression ||
1711
- expr instanceof index$1.QueryComparisonExpression ||
1712
- expr instanceof index$1.QueryNotExpression) {
1738
+ if (expr instanceof validator.QueryCoditionalExpression ||
1739
+ expr instanceof validator.QueryComparisonExpression ||
1740
+ expr instanceof validator.QueryNotExpression) {
1713
1741
  const value = encodeBooleanExpression(compiler, parent, expr);
1714
1742
  if (value)
1715
1743
  return [{ type: 'boolean', sql: value }];
1716
1744
  }
1717
- if (expr instanceof index$1.QueryDistanceExpression) {
1745
+ if (expr instanceof validator.QueryDistanceExpression) {
1718
1746
  const value = encodeDistanceQueryExpression(compiler, parent, expr);
1719
1747
  return [{ type: 'number', sql: value }];
1720
1748
  }
1721
1749
  };
1722
1750
  const encodeJsonQueryExpression = (compiler, parent, expr) => {
1723
- if (expr instanceof index$1.QueryKeyExpression) {
1751
+ if (expr instanceof validator.QueryKeyExpression) {
1724
1752
  const { element, dataType } = fetchElement(compiler, parent, expr.key);
1725
1753
  if (dataType && index.isPrimitive(dataType)) {
1726
1754
  switch (index._typeof(dataType)) {
@@ -1736,10 +1764,10 @@ const encodeJsonQueryExpression = (compiler, parent, expr) => {
1736
1764
  }
1737
1765
  return sql `${element}`;
1738
1766
  }
1739
- if (expr instanceof index$1.QueryValueExpression) {
1767
+ if (expr instanceof validator.QueryValueExpression) {
1740
1768
  return _encodeJsonValue(index._encodeValue(expr.value));
1741
1769
  }
1742
- if (expr instanceof index$1.QueryArrayExpression) {
1770
+ if (expr instanceof validator.QueryArrayExpression) {
1743
1771
  return sql `jsonb_build_array(${_.map(expr.exprs, x => encodeJsonQueryExpression(compiler, parent, x))})`;
1744
1772
  }
1745
1773
  const value = encodeQueryExpression(compiler, parent, expr);
@@ -1750,13 +1778,13 @@ const encodeJsonQueryExpression = (compiler, parent, expr) => {
1750
1778
  const encodeVectorExpression = (compiler, parent, exprs) => {
1751
1779
  if (exprs.length === 1) {
1752
1780
  const [expr] = exprs;
1753
- if (expr instanceof index$1.QueryKeyExpression) {
1781
+ if (expr instanceof validator.QueryKeyExpression) {
1754
1782
  const { element, dataType } = fetchElement(compiler, parent, expr.key);
1755
1783
  if (!dataType || !index.isVector(dataType))
1756
1784
  throw Error('Invalid expression');
1757
1785
  return { sql: element, dimension: dataType.dimension };
1758
1786
  }
1759
- if (expr instanceof index$1.QueryValueExpression) {
1787
+ if (expr instanceof validator.QueryValueExpression) {
1760
1788
  if (!_.isArray(expr.value) || !_.every(expr.value, x => _.isFinite(x)))
1761
1789
  throw Error('Invalid expression');
1762
1790
  return { sql: sql `${{ value: expr.value }}::DOUBLE PRECISION[]`, dimension: expr.value.length };
@@ -1795,7 +1823,7 @@ const matchType = (first, second) => {
1795
1823
  return found ? [found, _.find(second, r => r.type === found.type)] : undefined;
1796
1824
  };
1797
1825
  const encodeBooleanExpression = (compiler, parent, expr) => {
1798
- if (expr instanceof index$1.QueryCoditionalExpression) {
1826
+ if (expr instanceof validator.QueryCoditionalExpression) {
1799
1827
  const queries = _.compact(_.map(expr.exprs, x => encodeBooleanExpression(compiler, parent, x)));
1800
1828
  if (_.isEmpty(queries))
1801
1829
  return;
@@ -1805,7 +1833,7 @@ const encodeBooleanExpression = (compiler, parent, expr) => {
1805
1833
  case '$or': return sql `(${{ literal: _.map(queries, x => sql `(${x})`), separator: ' OR ' }})`;
1806
1834
  }
1807
1835
  }
1808
- if (expr instanceof index$1.QueryComparisonExpression) {
1836
+ if (expr instanceof validator.QueryComparisonExpression) {
1809
1837
  const operatorMap = {
1810
1838
  '$eq': nullSafeEqual(),
1811
1839
  '$ne': nullSafeNotEqual(),
@@ -1836,14 +1864,14 @@ const encodeBooleanExpression = (compiler, parent, expr) => {
1836
1864
  const _right2 = encodeJsonQueryExpression(compiler, parent, expr.right);
1837
1865
  return sql `${_left2} ${operatorMap[expr.type]} ${_right2}`;
1838
1866
  }
1839
- if (expr instanceof index$1.QueryNotExpression) {
1867
+ if (expr instanceof validator.QueryNotExpression) {
1840
1868
  const _expr = encodeBooleanExpression(compiler, parent, expr.expr);
1841
1869
  return _expr ? sql `NOT (${_expr})` : undefined;
1842
1870
  }
1843
1871
  throw Error('Invalid expression');
1844
1872
  };
1845
1873
  const encodeQueryExpression = (compiler, parent, expr) => {
1846
- if (expr instanceof index$1.QueryDistanceExpression) {
1874
+ if (expr instanceof validator.QueryDistanceExpression) {
1847
1875
  return encodeDistanceQueryExpression(compiler, parent, expr);
1848
1876
  }
1849
1877
  return encodeBooleanExpression(compiler, parent, expr);
@@ -1937,7 +1965,7 @@ const _selectRelationPopulate = (compiler, parent, populate, field, encode) => {
1937
1965
  index.isRelation(type) && sql `${{ identifier: populate.name }}.${{ identifier: `$${path}` }}`,
1938
1966
  ]))}
1939
1967
  FROM ${{ identifier: populate.name }} WHERE ${cond}
1940
- ${!_.isEmpty(populate.sort) ? sql `ORDER BY ${compiler._encodeSort(populate.sort, { className: populate.className, name: populate.name })}` : sql ``}
1968
+ ${!_.isEmpty(populate.sort) ? sql `ORDER BY ${compiler._encodeSort(populate.sort, populate)}` : sql ``}
1941
1969
  ${populate.limit ? sql `LIMIT ${{ literal: `${populate.limit}` }}` : sql ``}
1942
1970
  ${populate.skip ? sql `OFFSET ${{ literal: `${populate.skip}` }}` : sql ``}
1943
1971
  ${compiler.selectLock ? compiler.isUpdate ? sql `FOR UPDATE NOWAIT` : sql `FOR SHARE NOWAIT` : sql ``}
@@ -1950,39 +1978,44 @@ const selectPopulate = (compiler, parent, populate, field) => {
1950
1978
  sql `${{ identifier: parent.name }}.${{ identifier: field }} AS ${{ identifier: `$${field}` }}`,
1951
1979
  ];
1952
1980
  if (!_.isEmpty(groupMatches?.[field])) {
1953
- for (const [key, { type, expr }] of _.entries(groupMatches[field])) {
1954
- switch (type) {
1955
- case '$count':
1956
- columns.push(sql `
1957
- (
1958
- SELECT COUNT(*) FROM (
1959
- ${_selectRelationPopulate(compiler, parent, populate, field, false)}
1960
- ) ${{ identifier: populate.name }}
1961
- ) AS ${{ identifier: `${field}.${key}` }}
1962
- `);
1963
- break;
1964
- case '$avg':
1965
- case '$sum':
1966
- {
1967
- const op = {
1968
- '$avg': 'AVG',
1969
- '$sum': 'SUM',
1970
- }[type];
1971
- if (!expr)
1972
- throw Error('Invalid expression');
1973
- const exprs = encodeTypedQueryExpression(compiler, populate, expr);
1974
- const { sql: value } = (_.includes(['$avg'], type) ? _.find(exprs, e => e.type === 'number') : _.first(exprs)) ?? {};
1975
- if (!value)
1976
- throw Error('Invalid expression');
1981
+ for (const [key, expr] of _.entries(groupMatches[field])) {
1982
+ if (expr instanceof validator.QueryNoParamAccumulator) {
1983
+ switch (expr.type) {
1984
+ case '$count':
1977
1985
  columns.push(sql `
1978
1986
  (
1979
- SELECT ${{ literal: op }}(${value}) FROM (
1987
+ SELECT COUNT(*) FROM (
1980
1988
  ${_selectRelationPopulate(compiler, parent, populate, field, false)}
1981
1989
  ) ${{ identifier: populate.name }}
1982
1990
  ) AS ${{ identifier: `${field}.${key}` }}
1983
1991
  `);
1984
- }
1985
- break;
1992
+ break;
1993
+ }
1994
+ }
1995
+ else if (expr instanceof validator.QueryExprAccumulator) {
1996
+ const op = {
1997
+ '$max': 'MAX',
1998
+ '$min': 'MIN',
1999
+ '$avg': 'AVG',
2000
+ '$sum': 'SUM',
2001
+ '$stdDevPop': 'STDDEV_POP',
2002
+ '$stdDevSamp': 'STDDEV_SAMP',
2003
+ '$varPop': 'VAR_POP',
2004
+ '$varSamp': 'VAR_SAMP',
2005
+ }[expr.type];
2006
+ if (!expr.expr)
2007
+ throw Error('Invalid expression');
2008
+ const exprs = encodeTypedQueryExpression(compiler, populate, expr.expr);
2009
+ const value = _.first(exprs)?.sql;
2010
+ if (!value)
2011
+ throw Error('Invalid expression');
2012
+ columns.push(sql `
2013
+ (
2014
+ SELECT ${{ literal: op }}(${value}) FROM (
2015
+ ${_selectRelationPopulate(compiler, parent, populate, field, false)}
2016
+ ) ${{ identifier: populate.name }}
2017
+ ) AS ${{ identifier: `${field}.${key}` }}
2018
+ `);
1986
2019
  }
1987
2020
  }
1988
2021
  }
@@ -2017,7 +2050,7 @@ const encodeRemix = (parent, remix) => sql `${remix?.className === parent.classN
2017
2050
  (SELECT * FROM ${{ identifier: remix.name }} UNION SELECT * FROM ${{ identifier: parent.className }})
2018
2051
  ` : { identifier: parent.className }}`;
2019
2052
  const encodeForeignField = (compiler, parent, foreignField, remix) => {
2020
- const { paths: [colname, ...subpath], dataType } = random$1.resolveColumn(compiler.schema, parent.className, foreignField);
2053
+ const { paths: [colname, ...subpath], dataType } = validator.resolveColumn(compiler.schema, parent.className, foreignField);
2021
2054
  const tempName = `_populate_$${compiler.nextIdx()}`;
2022
2055
  const _local = (field) => sql `${{ identifier: parent.name }}.${{ identifier: field }}`;
2023
2056
  const _foreign = (field) => sql `${{ identifier: tempName }}.${{ identifier: field }}`;
@@ -2148,7 +2181,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2148
2181
  switch (expr.type) {
2149
2182
  case '$eq':
2150
2183
  {
2151
- if (_.isRegExp(expr.value) || expr.value instanceof index$1.QuerySelector || expr.value instanceof index$1.FieldSelectorExpression)
2184
+ if (_.isRegExp(expr.value) || expr.value instanceof validator.QuerySelector || expr.value instanceof validator.FieldSelectorExpression)
2152
2185
  break;
2153
2186
  if (_.isNil(expr.value))
2154
2187
  return sql `${element} IS NULL`;
@@ -2161,7 +2194,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2161
2194
  }
2162
2195
  case '$ne':
2163
2196
  {
2164
- if (_.isRegExp(expr.value) || expr.value instanceof index$1.QuerySelector || expr.value instanceof index$1.FieldSelectorExpression)
2197
+ if (_.isRegExp(expr.value) || expr.value instanceof validator.QuerySelector || expr.value instanceof validator.FieldSelectorExpression)
2165
2198
  break;
2166
2199
  if (_.isNil(expr.value))
2167
2200
  return sql `${element} IS NOT NULL`;
@@ -2183,7 +2216,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2183
2216
  '$lt': '<',
2184
2217
  '$lte': '<=',
2185
2218
  }[expr.type];
2186
- if (_.isRegExp(expr.value) || expr.value instanceof index$1.QuerySelector || expr.value instanceof index$1.FieldSelectorExpression)
2219
+ if (_.isRegExp(expr.value) || expr.value instanceof validator.QuerySelector || expr.value instanceof validator.FieldSelectorExpression)
2187
2220
  break;
2188
2221
  if (dataType && index.isPrimitive(dataType)) {
2189
2222
  switch (index._typeof(dataType)) {
@@ -2344,7 +2377,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2344
2377
  break;
2345
2378
  case '$not':
2346
2379
  {
2347
- if (!(expr.value instanceof index$1.FieldSelectorExpression))
2380
+ if (!(expr.value instanceof validator.FieldSelectorExpression))
2348
2381
  break;
2349
2382
  return sql `NOT (${encodeFieldExpression(compiler, parent, field, expr.value)})`;
2350
2383
  }
@@ -2450,7 +2483,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2450
2483
  break;
2451
2484
  case '$every':
2452
2485
  {
2453
- if (!(expr.value instanceof index$1.QuerySelector))
2486
+ if (!(expr.value instanceof validator.QuerySelector))
2454
2487
  break;
2455
2488
  if (relation && parent.className) {
2456
2489
  const tempName = `_populate_expr_$${compiler.nextIdx()}`;
@@ -2503,7 +2536,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2503
2536
  break;
2504
2537
  case '$some':
2505
2538
  {
2506
- if (!(expr.value instanceof index$1.QuerySelector))
2539
+ if (!(expr.value instanceof validator.QuerySelector))
2507
2540
  break;
2508
2541
  if (relation && parent.className) {
2509
2542
  const tempName = `_populate_expr_$${compiler.nextIdx()}`;