proto.io 0.0.177 → 0.0.178

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 (71) hide show
  1. package/LICENSE +1 -1
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +5 -5
  4. package/dist/adapters/file/database.js.map +1 -1
  5. package/dist/adapters/file/database.mjs +5 -5
  6. package/dist/adapters/file/database.mjs.map +1 -1
  7. package/dist/adapters/file/filesystem.d.ts +2 -2
  8. package/dist/adapters/file/filesystem.js +3 -3
  9. package/dist/adapters/file/filesystem.js.map +1 -1
  10. package/dist/adapters/file/filesystem.mjs +3 -3
  11. package/dist/adapters/file/filesystem.mjs.map +1 -1
  12. package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
  13. package/dist/adapters/file/google-cloud-storage.js +3 -3
  14. package/dist/adapters/file/google-cloud-storage.js.map +1 -1
  15. package/dist/adapters/file/google-cloud-storage.mjs +3 -3
  16. package/dist/adapters/file/google-cloud-storage.mjs.map +1 -1
  17. package/dist/adapters/storage/progres.d.ts +5 -6
  18. package/dist/adapters/storage/progres.js +108 -80
  19. package/dist/adapters/storage/progres.js.map +1 -1
  20. package/dist/adapters/storage/progres.mjs +108 -80
  21. package/dist/adapters/storage/progres.mjs.map +1 -1
  22. package/dist/client.d.ts +3 -3
  23. package/dist/client.js +4 -4
  24. package/dist/client.js.map +1 -1
  25. package/dist/client.mjs +5 -5
  26. package/dist/client.mjs.map +1 -1
  27. package/dist/index.d.ts +12 -3
  28. package/dist/index.js +42 -31
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +43 -32
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/internals/{index-CZShhrIu.d.ts → index-B7qz_VeO.d.ts} +2 -2
  33. package/dist/internals/index-B7qz_VeO.d.ts.map +1 -0
  34. package/dist/internals/{index-be1VYBY2.mjs → index-BAFVUYCo.mjs} +3 -3
  35. package/dist/internals/{index-be1VYBY2.mjs.map → index-BAFVUYCo.mjs.map} +1 -1
  36. package/dist/internals/{index-Dz0pmKCD.d.ts → index-BgZqiNxF.d.ts} +13 -11
  37. package/dist/internals/index-BgZqiNxF.d.ts.map +1 -0
  38. package/dist/internals/{index-A2Ulsntq.mjs → index-CPodB1P0.mjs} +21 -20
  39. package/dist/internals/index-CPodB1P0.mjs.map +1 -0
  40. package/dist/internals/{index-BL2gpGny.d.ts → index-CyXddWjz.d.ts} +2 -2
  41. package/dist/internals/index-CyXddWjz.d.ts.map +1 -0
  42. package/dist/internals/{index-DHQhYGsJ.mjs → index-D9AowvHp.mjs} +6 -6
  43. package/dist/internals/{index-DHQhYGsJ.mjs.map → index-D9AowvHp.mjs.map} +1 -1
  44. package/dist/internals/{index-DXuW8UiB.js → index-DRq6T_5w.js} +12 -6
  45. package/dist/internals/index-DRq6T_5w.js.map +1 -0
  46. package/dist/internals/{index-BqFdBhFc.js → index-DfPY7Xbb.js} +3 -3
  47. package/dist/internals/{index-BqFdBhFc.js.map → index-DfPY7Xbb.js.map} +1 -1
  48. package/dist/internals/{index-Dc3V_Bzw.js → index-DjrC854w.js} +6 -6
  49. package/dist/internals/{index-Dc3V_Bzw.js.map → index-DjrC854w.js.map} +1 -1
  50. package/dist/internals/{index-DvjHa8S2.js → index-DwCNTJb5.js} +21 -19
  51. package/dist/internals/index-DwCNTJb5.js.map +1 -0
  52. package/dist/internals/{index-CTsc042s.mjs → index-DyjcBbS1.mjs} +12 -7
  53. package/dist/internals/index-DyjcBbS1.mjs.map +1 -0
  54. package/dist/internals/{private-BUpLAMZi.mjs → private-CNw40LZ7.mjs} +2 -2
  55. package/dist/internals/{private-BUpLAMZi.mjs.map → private-CNw40LZ7.mjs.map} +1 -1
  56. package/dist/internals/{private-CSB1Ep4g.js → private-Ciddhure.js} +2 -2
  57. package/dist/internals/{private-CSB1Ep4g.js.map → private-Ciddhure.js.map} +1 -1
  58. package/dist/internals/{random-DGiu1IIq.mjs → random-BSyWEK8G.mjs} +7 -7
  59. package/dist/internals/random-BSyWEK8G.mjs.map +1 -0
  60. package/dist/internals/{random-CvVZek_8.js → random-CDtFUuES.js} +7 -7
  61. package/dist/internals/random-CDtFUuES.js.map +1 -0
  62. package/package.json +1 -1
  63. package/dist/internals/index-A2Ulsntq.mjs.map +0 -1
  64. package/dist/internals/index-BL2gpGny.d.ts.map +0 -1
  65. package/dist/internals/index-CTsc042s.mjs.map +0 -1
  66. package/dist/internals/index-CZShhrIu.d.ts.map +0 -1
  67. package/dist/internals/index-DXuW8UiB.js.map +0 -1
  68. package/dist/internals/index-DvjHa8S2.js.map +0 -1
  69. package/dist/internals/index-Dz0pmKCD.d.ts.map +0 -1
  70. package/dist/internals/random-CvVZek_8.js.map +0 -1
  71. package/dist/internals/random-DGiu1IIq.mjs.map +0 -1
@@ -1,46 +1,20 @@
1
1
  import _ from 'lodash';
2
- import { a as isRelation, i as isPointer, b as isShape, e as decodeUpdateOp, s as shapePaths, c as isPrimitive, T as TObject, f as isVector, _ as _encodeValue, g as _decodeValue, h as dimensionOf, j as _typeof } from '../../internals/index-CTsc042s.mjs';
2
+ import { a as isRelation, i as isPointer, b as isShape, e as decodeUpdateOp, s as shapePaths, c as isPrimitive, T as TObject, _ as _isTypeof, f as isVector, g as _encodeValue, h as _decodeValue, j as dimensionOf, k as _typeof } from '../../internals/index-DyjcBbS1.mjs';
3
3
  import { Pool, types } from 'pg';
4
4
  import QueryStream from 'pg-query-stream';
5
5
  import { asyncStream } from '@o2ter/utils-js';
6
6
  import Decimal from 'decimal.js';
7
7
  import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
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-DHQhYGsJ.mjs';
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-DGiu1IIq.mjs';
11
- import { P as PVK } from '../../internals/private-BUpLAMZi.mjs';
12
-
13
- //
14
- // const.ts
15
- //
16
- // The MIT License
17
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
18
- //
19
- // Permission is hereby granted, free of charge, to any person obtaining a copy
20
- // of this software and associated documentation files (the "Software"), to deal
21
- // in the Software without restriction, including without limitation the rights
22
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
- // copies of the Software, and to permit persons to whom the Software is
24
- // furnished to do so, subject to the following conditions:
25
- //
26
- // The above copyright notice and this permission notice shall be included in
27
- // all copies or substantial portions of the Software.
28
- //
29
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35
- // THE SOFTWARE.
36
- //
37
- const PROTO_POSTGRES_MSG = 'PROTO_POSTGRES_MSG';
10
+ import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-BSyWEK8G.mjs';
11
+ import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
38
12
 
39
13
  //
40
14
  // sql.ts
41
15
  //
42
16
  // The MIT License
43
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
17
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
44
18
  //
45
19
  // Permission is hereby granted, free of charge, to any person obtaining a copy
46
20
  // of this software and associated documentation files (the "Software"), to deal
@@ -141,7 +115,7 @@ const sql = (templates, ...values) => new SQL(templates, values);
141
115
  // compiler.ts
142
116
  //
143
117
  // The MIT License
144
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
118
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
145
119
  //
146
120
  // Permission is hereby granted, free of charge, to any person obtaining a copy
147
121
  // of this software and associated documentation files (the "Software"), to deal
@@ -620,7 +594,7 @@ class QueryCompiler {
620
594
  // storage.ts
621
595
  //
622
596
  // The MIT License
623
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
597
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
624
598
  //
625
599
  // Permission is hereby granted, free of charge, to any person obtaining a copy
626
600
  // of this software and associated documentation files (the "Software"), to deal
@@ -844,7 +818,7 @@ class SqlStorage {
844
818
  // utils.ts
845
819
  //
846
820
  // The MIT License
847
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
821
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
848
822
  //
849
823
  // Permission is hereby granted, free of charge, to any person obtaining a copy
850
824
  // of this software and associated documentation files (the "Software"), to deal
@@ -882,7 +856,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
882
856
  }
883
857
  else if (!_.isEmpty(subpath)) {
884
858
  const _subpath = sql `${_.map(subpath, x => sql `${{ quote: x.startsWith('$') ? `$${x}` : x }}`)}`;
885
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'relation'))) {
859
+ if (dataType && _isTypeof(dataType, ['array', 'string[]', 'relation'])) {
886
860
  return {
887
861
  element: sql `jsonb_extract_path(to_jsonb(${element}), ${_subpath})`,
888
862
  json: true,
@@ -957,6 +931,21 @@ const fetchElement = (compiler, parent, field) => {
957
931
  },
958
932
  };
959
933
  }
934
+ if (field === '$') {
935
+ const mapping = {
936
+ 'number': '_doller_num_expr_$',
937
+ 'string': '_doller_str_expr_$',
938
+ };
939
+ for (const [key, value] of _.entries(mapping)) {
940
+ if (parent.name.startsWith(value)) {
941
+ return {
942
+ element: sql `${{ identifier: parent.name }}.${{ identifier: '$' }}`,
943
+ dataType: key,
944
+ relation: null,
945
+ };
946
+ }
947
+ }
948
+ }
960
949
  const [colname, ...subpath] = _.toPath(field);
961
950
  const { element } = _fetchElement(parent, colname, subpath);
962
951
  return { element, dataType: null, relation: null };
@@ -966,7 +955,7 @@ const fetchElement = (compiler, parent, field) => {
966
955
  // basic.ts
967
956
  //
968
957
  // The MIT License
969
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
958
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
970
959
  //
971
960
  // Permission is hereby granted, free of charge, to any person obtaining a copy
972
961
  // of this software and associated documentation files (the "Software"), to deal
@@ -986,7 +975,6 @@ const fetchElement = (compiler, parent, field) => {
986
975
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
987
976
  // THE SOFTWARE.
988
977
  //
989
- const stringArrayAttrs = ['_rperm', '_wperm'];
990
978
  const nullSafeEqual = () => sql `IS NOT DISTINCT FROM`;
991
979
  const nullSafeNotEqual = () => sql `IS DISTINCT FROM`;
992
980
  const quote = (str) => escapeLiteral(str);
@@ -1005,7 +993,7 @@ const random = (opts) => {
1005
993
  // index.ts
1006
994
  //
1007
995
  // The MIT License
1008
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
996
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1009
997
  //
1010
998
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1011
999
  // of this software and associated documentation files (the "Software"), to deal
@@ -1154,9 +1142,9 @@ class PostgresClientDriver {
1154
1142
  client.release();
1155
1143
  }
1156
1144
  }
1157
- async publish(payload) {
1145
+ async publish(channel, payload) {
1158
1146
  await this.withClient(async (db) => {
1159
- await db.query(`NOTIFY ${PROTO_POSTGRES_MSG}, ${quote(JSON.stringify(_encodeValue(payload)))}`);
1147
+ await db.query(`NOTIFY ${channel}, ${quote(JSON.stringify(_encodeValue(payload)))}`);
1160
1148
  });
1161
1149
  }
1162
1150
  }
@@ -1236,7 +1224,7 @@ class PostgresDriver extends PostgresClientDriver {
1236
1224
  this.pubsub = undefined;
1237
1225
  await pubsub?.shutdown();
1238
1226
  }
1239
- _subscribe(channel, callback) {
1227
+ subscribe(channel, callback) {
1240
1228
  this._init_pubsub();
1241
1229
  if (!_.includes(this.pubsub.channels, channel))
1242
1230
  this.pubsub.listen(channel);
@@ -1247,16 +1235,13 @@ class PostgresDriver extends PostgresClientDriver {
1247
1235
  this._release_pubsub();
1248
1236
  };
1249
1237
  }
1250
- subscribe(callback) {
1251
- return this._subscribe(PROTO_POSTGRES_MSG, callback);
1252
- }
1253
1238
  }
1254
1239
 
1255
1240
  //
1256
1241
  // encode.ts
1257
1242
  //
1258
1243
  // The MIT License
1259
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1244
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1260
1245
  //
1261
1246
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1262
1247
  // of this software and associated documentation files (the "Software"), to deal
@@ -1321,6 +1306,10 @@ const encodeType = (colname, dataType, value) => {
1321
1306
  if (_.isString(value))
1322
1307
  return sql `${{ value }}`;
1323
1308
  break;
1309
+ case 'string[]':
1310
+ if (_.isArray(value) && _.every(value, x => _.isString(x)))
1311
+ return sql `ARRAY[${_.map(value, x => sql `${{ value: x }}`)}]::TEXT[]`;
1312
+ break;
1324
1313
  case 'date':
1325
1314
  if (_.isDate(value))
1326
1315
  return sql `${{ value }}`;
@@ -1338,11 +1327,6 @@ const encodeType = (colname, dataType, value) => {
1338
1327
  case 'array':
1339
1328
  if (!_.isArray(value))
1340
1329
  break;
1341
- if (_.includes(stringArrayAttrs, colname)) {
1342
- if (!_.every(value, x => _.isString(x)))
1343
- break;
1344
- return sql `ARRAY[${_.map(value, x => sql `${{ value: x }}`)}]::TEXT[]`;
1345
- }
1346
1330
  return sql `ARRAY[${_.map(value, x => _encodeJsonValue(_encodeValue(x)))}]::JSONB[]`;
1347
1331
  case 'pointer':
1348
1332
  if (value instanceof TObject && value.objectId)
@@ -1386,6 +1370,10 @@ const decodeType = (type, value) => {
1386
1370
  if (_.isString(value))
1387
1371
  return value;
1388
1372
  break;
1373
+ case 'string[]':
1374
+ if (_.isArray(value) && _.every(value, x => _.isString(x)))
1375
+ return value;
1376
+ break;
1389
1377
  case 'date':
1390
1378
  if (_.isDate(value))
1391
1379
  return value;
@@ -1420,7 +1408,7 @@ const decodeType = (type, value) => {
1420
1408
  // update.ts
1421
1409
  //
1422
1410
  // The MIT License
1423
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1411
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1424
1412
  //
1425
1413
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1426
1414
  // of this software and associated documentation files (the "Software"), to deal
@@ -1445,6 +1433,8 @@ const updateOperation = (paths, dataType, operation) => {
1445
1433
  const [op, value] = decodeUpdateOp(operation);
1446
1434
  if (isVector(dataType)) {
1447
1435
  if (_.isEmpty(subpath)) {
1436
+ if (_.isNil(value) && op === '$set')
1437
+ return sql `${encodeType(column, dataType, value)}`;
1448
1438
  if (!_.isArray(value) || value.length !== dataType.dimension)
1449
1439
  throw Error('Invalid update operation');
1450
1440
  if (!_.every(value, x => _.isFinite(x)))
@@ -1479,7 +1469,7 @@ const updateOperation = (paths, dataType, operation) => {
1479
1469
  case '$max': return sql `GREATEST(${{ identifier: column }}, ${encodeType(column, dataType, value)})`;
1480
1470
  case '$min': return sql `LEAST(${{ identifier: column }}, ${encodeType(column, dataType, value)})`;
1481
1471
  }
1482
- if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
1472
+ if (dataType && _isTypeof(dataType, ['array', 'string[]'])) {
1483
1473
  switch (op) {
1484
1474
  case '$popFirst':
1485
1475
  if (!_.isNumber(value) || !_.isSafeInteger(value) || value < 0)
@@ -1491,7 +1481,7 @@ const updateOperation = (paths, dataType, operation) => {
1491
1481
  return sql `${{ identifier: column }}[:array_length(${{ identifier: column }}, 1) - ${{ literal: `${value}` }}]`;
1492
1482
  default:
1493
1483
  {
1494
- const isStringArray = _.includes(stringArrayAttrs, column);
1484
+ const isStringArray = dataType === 'string[]';
1495
1485
  if (!_.isArray(value))
1496
1486
  break;
1497
1487
  if (isStringArray && !_.every(value, x => _.isString(x)))
@@ -1554,7 +1544,7 @@ const updateOperation = (paths, dataType, operation) => {
1554
1544
  let element = sql `${{ identifier: column }}`;
1555
1545
  const _subpath = sql `${_.map(subpath, x => sql `${{ quote: x.startsWith('$') ? `$${x}` : x }}`)}`;
1556
1546
  let updateKey;
1557
- if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
1547
+ if (dataType && _isTypeof(dataType, ['array', 'string[]'])) {
1558
1548
  element = sql `jsonb_extract_path(to_jsonb(${element}), ${_subpath})`;
1559
1549
  updateKey = (value) => sql `ARRAY(SELECT * FROM jsonb_array_elements(
1560
1550
  jsonb_set(to_jsonb(${{ identifier: column }}), ARRAY[${_subpath}], ${value})
@@ -1704,7 +1694,7 @@ const updateOperation = (paths, dataType, operation) => {
1704
1694
  // expressions.ts
1705
1695
  //
1706
1696
  // The MIT License
1707
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1697
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1708
1698
  //
1709
1699
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1710
1700
  // of this software and associated documentation files (the "Software"), to deal
@@ -1793,6 +1783,7 @@ const encodeJsonQueryExpression = (compiler, parent, expr) => {
1793
1783
  case 'number': return sql `to_jsonb(${element})`;
1794
1784
  case 'decimal': return sql `jsonb_build_object('$decimal', CAST(${element} AS TEXT))`;
1795
1785
  case 'string': return sql `to_jsonb(${element})`;
1786
+ case 'string[]': return sql `to_jsonb(${element})`;
1796
1787
  case 'date': return sql `jsonb_build_object(
1797
1788
  '$date', to_char(${element} AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')
1798
1789
  )`;
@@ -1917,7 +1908,7 @@ const encodeQueryExpression = (compiler, parent, expr) => {
1917
1908
  // populate.ts
1918
1909
  //
1919
1910
  // The MIT License
1920
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1911
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1921
1912
  //
1922
1913
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1923
1914
  // of this software and associated documentation files (the "Software"), to deal
@@ -2148,7 +2139,7 @@ const encodePopulate = (compiler, parent, remix) => {
2148
2139
  // selectors.ts
2149
2140
  //
2150
2141
  // The MIT License
2151
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2142
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2152
2143
  //
2153
2144
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2154
2145
  // of this software and associated documentation files (the "Software"), to deal
@@ -2227,6 +2218,10 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2227
2218
  if (!_.isString(expr.value))
2228
2219
  break;
2229
2220
  return sql `${element} ${{ literal: op }} ${encodeValue(expr.value)}`;
2221
+ case 'string[]':
2222
+ if (!_.isArray(expr.value) || !_.every(expr.value, _.isString))
2223
+ break;
2224
+ return sql `${element} ${{ literal: op }} ${encodeValue(expr.value)}`;
2230
2225
  case 'date':
2231
2226
  if (!_.isDate(expr.value))
2232
2227
  break;
@@ -2347,7 +2342,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2347
2342
  case '$intersect': return sql `false`;
2348
2343
  }
2349
2344
  }
2350
- if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
2345
+ if (dataType && _isTypeof(dataType, ['array', 'string[]'])) {
2351
2346
  return sql `${element} ${{ literal: op }} ${{ value: _encodeValue(expr.value) }}`;
2352
2347
  }
2353
2348
  if (relation && parent.className) {
@@ -2373,7 +2368,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2373
2368
  }
2374
2369
  case '$pattern':
2375
2370
  {
2376
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2371
+ if (dataType && _isTypeof(dataType, 'string')) {
2377
2372
  if (_.isString(expr.value)) {
2378
2373
  return sql `${element} LIKE ${{ value: `%${expr.value.replace(/([\\_%])/g, '\\$1')}%` }}`;
2379
2374
  }
@@ -2399,7 +2394,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2399
2394
  {
2400
2395
  if (!_.isString(expr.value))
2401
2396
  break;
2402
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2397
+ if (dataType && _isTypeof(dataType, 'string')) {
2403
2398
  return sql `${element} LIKE ${{ value: `${expr.value.replace(/([\\_%])/g, '\\$1')}%` }}`;
2404
2399
  }
2405
2400
  if (!dataType) {
@@ -2411,7 +2406,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2411
2406
  {
2412
2407
  if (!_.isString(expr.value))
2413
2408
  break;
2414
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2409
+ if (dataType && _isTypeof(dataType, 'string')) {
2415
2410
  return sql `${element} LIKE ${{ value: `%${expr.value.replace(/([\\_%])/g, '\\$1')}` }}`;
2416
2411
  }
2417
2412
  if (!dataType) {
@@ -2423,10 +2418,10 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2423
2418
  {
2424
2419
  if (!_.isNumber(expr.value) || !_.isSafeInteger(expr.value))
2425
2420
  break;
2426
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2421
+ if (dataType && _isTypeof(dataType, 'string')) {
2427
2422
  return sql `COALESCE(length(${element}), 0) = ${{ value: expr.value }}`;
2428
2423
  }
2429
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector' || dataType?.type === 'relation'))) {
2424
+ if (dataType && _isTypeof(dataType, ['array', 'string[]', 'vector', 'relation'])) {
2430
2425
  return sql `COALESCE(array_length(${element}, 1), 0) = ${{ value: expr.value }}`;
2431
2426
  }
2432
2427
  if (!dataType) {
@@ -2444,10 +2439,10 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2444
2439
  {
2445
2440
  if (!_.isBoolean(expr.value))
2446
2441
  break;
2447
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2442
+ if (dataType && _isTypeof(dataType, 'string')) {
2448
2443
  return sql `COALESCE(length(${element}), 0) ${{ literal: expr.value ? '=' : '<>' }} 0`;
2449
2444
  }
2450
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector' || dataType?.type === 'relation'))) {
2445
+ if (dataType && _isTypeof(dataType, ['array', 'string[]', 'vector', 'relation'])) {
2451
2446
  return sql `COALESCE(array_length(${element}, 1), 0) ${{ literal: expr.value ? '=' : '<>' }} 0`;
2452
2447
  }
2453
2448
  if (!dataType) {
@@ -2473,18 +2468,34 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2473
2468
  populates: relation.populate.populates,
2474
2469
  }, expr.value);
2475
2470
  if (!filter)
2476
- break;
2471
+ throw Error('Invalid expression');
2477
2472
  const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
2478
2473
  return sql `NOT EXISTS(
2479
2474
  SELECT * FROM (${populate}) AS ${{ identifier: tempName }}
2480
2475
  WHERE NOT (${filter})
2481
2476
  )`;
2482
2477
  }
2478
+ const mapping = {
2479
+ 'vector': '_doller_num_expr_$',
2480
+ 'string[]': '_doller_str_expr_$',
2481
+ };
2482
+ for (const [key, value] of _.entries(mapping)) {
2483
+ if (dataType && _isTypeof(dataType, key)) {
2484
+ const tempName = `${value}${compiler.nextIdx()}`;
2485
+ const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2486
+ if (!filter)
2487
+ throw Error('Invalid expression');
2488
+ return sql `NOT EXISTS(
2489
+ SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2490
+ WHERE NOT (${filter})
2491
+ )`;
2492
+ }
2493
+ }
2483
2494
  const tempName = `_doller_expr_$${compiler.nextIdx()}`;
2484
2495
  const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2485
2496
  if (!filter)
2486
- break;
2487
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector'))) {
2497
+ throw Error('Invalid expression');
2498
+ if (dataType && _isTypeof(dataType, 'array')) {
2488
2499
  return sql `NOT EXISTS(
2489
2500
  SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2490
2501
  WHERE NOT (${filter})
@@ -2510,18 +2521,34 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2510
2521
  populates: relation.populate.populates,
2511
2522
  }, expr.value);
2512
2523
  if (!filter)
2513
- break;
2524
+ throw Error('Invalid expression');
2514
2525
  const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
2515
2526
  return sql `EXISTS(
2516
2527
  SELECT * FROM (${populate}) AS ${{ identifier: tempName }}
2517
2528
  WHERE ${filter}
2518
2529
  )`;
2519
2530
  }
2531
+ const mapping = {
2532
+ 'vector': '_doller_num_expr_$',
2533
+ 'string[]': '_doller_str_expr_$',
2534
+ };
2535
+ for (const [key, value] of _.entries(mapping)) {
2536
+ if (dataType && _isTypeof(dataType, key)) {
2537
+ const tempName = `${value}${compiler.nextIdx()}`;
2538
+ const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2539
+ if (!filter)
2540
+ throw Error('Invalid expression');
2541
+ return sql `EXISTS(
2542
+ SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2543
+ WHERE ${filter}
2544
+ )`;
2545
+ }
2546
+ }
2520
2547
  const tempName = `_doller_expr_$${compiler.nextIdx()}`;
2521
2548
  const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2522
2549
  if (!filter)
2523
- break;
2524
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector'))) {
2550
+ throw Error('Invalid expression');
2551
+ if (dataType && _isTypeof(dataType, 'array')) {
2525
2552
  return sql `EXISTS(
2526
2553
  SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2527
2554
  WHERE ${filter}
@@ -2543,7 +2570,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2543
2570
  // relation.ts
2544
2571
  //
2545
2572
  // The MIT License
2546
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2573
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2547
2574
  //
2548
2575
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2549
2576
  // of this software and associated documentation files (the "Software"), to deal
@@ -2580,7 +2607,7 @@ const encodeRelation = (compiler, parent, relatedBy) => {
2580
2607
  // index.ts
2581
2608
  //
2582
2609
  // The MIT License
2583
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2610
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2584
2611
  //
2585
2612
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2586
2613
  // of this software and associated documentation files (the "Software"), to deal
@@ -2621,7 +2648,7 @@ const PostgresDialect = {
2621
2648
  // base.ts
2622
2649
  //
2623
2650
  // The MIT License
2624
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2651
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2625
2652
  //
2626
2653
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2627
2654
  // of this software and associated documentation files (the "Software"), to deal
@@ -2779,14 +2806,14 @@ class PostgresStorageClient extends SqlStorage {
2779
2806
  throw e;
2780
2807
  }
2781
2808
  }
2782
- subscribe(callback) {
2809
+ subscribe(channel, callback) {
2783
2810
  const db = this._driver;
2784
2811
  if (!(db instanceof PostgresDriver))
2785
2812
  throw Error('Invalid pubsub instance');
2786
- return db.subscribe(callback);
2813
+ return db.subscribe(channel, callback);
2787
2814
  }
2788
- publish(payload) {
2789
- return this._driver.publish(payload);
2815
+ publish(channel, payload) {
2816
+ return this._driver.publish(channel, payload);
2790
2817
  }
2791
2818
  _refs(schema, className, keys, item) {
2792
2819
  const _schema = _.pickBy(_.mapValues(schema, s => _.pickBy(s.fields, f => (isPointer(f) || (isRelation(f) && _.isNil(f.foreignField))) && f.target === className)), s => !_.isEmpty(s));
@@ -2847,7 +2874,7 @@ class PostgresStorageTransaction extends PostgresStorageClient {
2847
2874
  // pool.ts
2848
2875
  //
2849
2876
  // The MIT License
2850
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2877
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2851
2878
  //
2852
2879
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2853
2880
  // of this software and associated documentation files (the "Software"), to deal
@@ -2892,6 +2919,7 @@ class PostgresStorage extends PostgresStorageClient {
2892
2919
  case 'number': return 'DOUBLE PRECISION';
2893
2920
  case 'decimal': return 'DECIMAL';
2894
2921
  case 'string': return 'TEXT';
2922
+ case 'string[]': return 'TEXT[]';
2895
2923
  case 'date': return 'TIMESTAMP(3) WITH TIME ZONE';
2896
2924
  case 'object': return 'JSONB';
2897
2925
  case 'array': return 'JSONB[]';
@@ -3119,7 +3147,7 @@ class PostgresStorage extends PostgresStorageClient {
3119
3147
  // index.ts
3120
3148
  //
3121
3149
  // The MIT License
3122
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
3150
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
3123
3151
  //
3124
3152
  // Permission is hereby granted, free of charge, to any person obtaining a copy
3125
3153
  // of this software and associated documentation files (the "Software"), to deal