proto.io 0.0.177 → 0.0.179

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
@@ -3,48 +3,22 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
- var index = require('../../internals/index-DXuW8UiB.js');
6
+ var index = require('../../internals/index-DRq6T_5w.js');
7
7
  var pg = require('pg');
8
8
  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-Dc3V_Bzw.js');
12
+ var index$1 = require('../../internals/index-DjrC854w.js');
13
13
  require('@o2ter/crypto-js');
14
- var random$1 = require('../../internals/random-CvVZek_8.js');
15
- var _private = require('../../internals/private-CSB1Ep4g.js');
16
-
17
- //
18
- // const.ts
19
- //
20
- // The MIT License
21
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
22
- //
23
- // Permission is hereby granted, free of charge, to any person obtaining a copy
24
- // of this software and associated documentation files (the "Software"), to deal
25
- // in the Software without restriction, including without limitation the rights
26
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
- // copies of the Software, and to permit persons to whom the Software is
28
- // furnished to do so, subject to the following conditions:
29
- //
30
- // The above copyright notice and this permission notice shall be included in
31
- // all copies or substantial portions of the Software.
32
- //
33
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39
- // THE SOFTWARE.
40
- //
41
- const PROTO_POSTGRES_MSG = 'PROTO_POSTGRES_MSG';
14
+ var random$1 = require('../../internals/random-CDtFUuES.js');
15
+ var _private = require('../../internals/private-Ciddhure.js');
42
16
 
43
17
  //
44
18
  // sql.ts
45
19
  //
46
20
  // The MIT License
47
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
21
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
48
22
  //
49
23
  // Permission is hereby granted, free of charge, to any person obtaining a copy
50
24
  // of this software and associated documentation files (the "Software"), to deal
@@ -145,7 +119,7 @@ const sql = (templates, ...values) => new SQL(templates, values);
145
119
  // compiler.ts
146
120
  //
147
121
  // The MIT License
148
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
122
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
149
123
  //
150
124
  // Permission is hereby granted, free of charge, to any person obtaining a copy
151
125
  // of this software and associated documentation files (the "Software"), to deal
@@ -624,7 +598,7 @@ class QueryCompiler {
624
598
  // storage.ts
625
599
  //
626
600
  // The MIT License
627
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
601
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
628
602
  //
629
603
  // Permission is hereby granted, free of charge, to any person obtaining a copy
630
604
  // of this software and associated documentation files (the "Software"), to deal
@@ -848,7 +822,7 @@ class SqlStorage {
848
822
  // utils.ts
849
823
  //
850
824
  // The MIT License
851
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
825
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
852
826
  //
853
827
  // Permission is hereby granted, free of charge, to any person obtaining a copy
854
828
  // of this software and associated documentation files (the "Software"), to deal
@@ -886,7 +860,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
886
860
  }
887
861
  else if (!_.isEmpty(subpath)) {
888
862
  const _subpath = sql `${_.map(subpath, x => sql `${{ quote: x.startsWith('$') ? `$${x}` : x }}`)}`;
889
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'relation'))) {
863
+ if (dataType && index._isTypeof(dataType, ['array', 'string[]', 'relation'])) {
890
864
  return {
891
865
  element: sql `jsonb_extract_path(to_jsonb(${element}), ${_subpath})`,
892
866
  json: true,
@@ -961,6 +935,21 @@ const fetchElement = (compiler, parent, field) => {
961
935
  },
962
936
  };
963
937
  }
938
+ if (field === '$') {
939
+ const mapping = {
940
+ 'number': '_doller_num_expr_$',
941
+ 'string': '_doller_str_expr_$',
942
+ };
943
+ for (const [key, value] of _.entries(mapping)) {
944
+ if (parent.name.startsWith(value)) {
945
+ return {
946
+ element: sql `${{ identifier: parent.name }}.${{ identifier: '$' }}`,
947
+ dataType: key,
948
+ relation: null,
949
+ };
950
+ }
951
+ }
952
+ }
964
953
  const [colname, ...subpath] = _.toPath(field);
965
954
  const { element } = _fetchElement(parent, colname, subpath);
966
955
  return { element, dataType: null, relation: null };
@@ -970,7 +959,7 @@ const fetchElement = (compiler, parent, field) => {
970
959
  // basic.ts
971
960
  //
972
961
  // The MIT License
973
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
962
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
974
963
  //
975
964
  // Permission is hereby granted, free of charge, to any person obtaining a copy
976
965
  // of this software and associated documentation files (the "Software"), to deal
@@ -990,7 +979,6 @@ const fetchElement = (compiler, parent, field) => {
990
979
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
991
980
  // THE SOFTWARE.
992
981
  //
993
- const stringArrayAttrs = ['_rperm', '_wperm'];
994
982
  const nullSafeEqual = () => sql `IS NOT DISTINCT FROM`;
995
983
  const nullSafeNotEqual = () => sql `IS DISTINCT FROM`;
996
984
  const quote = (str) => utils.escapeLiteral(str);
@@ -1009,7 +997,7 @@ const random = (opts) => {
1009
997
  // index.ts
1010
998
  //
1011
999
  // The MIT License
1012
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1000
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1013
1001
  //
1014
1002
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1015
1003
  // of this software and associated documentation files (the "Software"), to deal
@@ -1158,9 +1146,9 @@ class PostgresClientDriver {
1158
1146
  client.release();
1159
1147
  }
1160
1148
  }
1161
- async publish(payload) {
1149
+ async publish(channel, payload) {
1162
1150
  await this.withClient(async (db) => {
1163
- await db.query(`NOTIFY ${PROTO_POSTGRES_MSG}, ${quote(JSON.stringify(index._encodeValue(payload)))}`);
1151
+ await db.query(`NOTIFY ${channel}, ${quote(JSON.stringify(index._encodeValue(payload)))}`);
1164
1152
  });
1165
1153
  }
1166
1154
  }
@@ -1240,7 +1228,7 @@ class PostgresDriver extends PostgresClientDriver {
1240
1228
  this.pubsub = undefined;
1241
1229
  await pubsub?.shutdown();
1242
1230
  }
1243
- _subscribe(channel, callback) {
1231
+ subscribe(channel, callback) {
1244
1232
  this._init_pubsub();
1245
1233
  if (!_.includes(this.pubsub.channels, channel))
1246
1234
  this.pubsub.listen(channel);
@@ -1251,16 +1239,13 @@ class PostgresDriver extends PostgresClientDriver {
1251
1239
  this._release_pubsub();
1252
1240
  };
1253
1241
  }
1254
- subscribe(callback) {
1255
- return this._subscribe(PROTO_POSTGRES_MSG, callback);
1256
- }
1257
1242
  }
1258
1243
 
1259
1244
  //
1260
1245
  // encode.ts
1261
1246
  //
1262
1247
  // The MIT License
1263
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1248
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1264
1249
  //
1265
1250
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1266
1251
  // of this software and associated documentation files (the "Software"), to deal
@@ -1325,6 +1310,10 @@ const encodeType = (colname, dataType, value) => {
1325
1310
  if (_.isString(value))
1326
1311
  return sql `${{ value }}`;
1327
1312
  break;
1313
+ case 'string[]':
1314
+ if (_.isArray(value) && _.every(value, x => _.isString(x)))
1315
+ return sql `ARRAY[${_.map(value, x => sql `${{ value: x }}`)}]::TEXT[]`;
1316
+ break;
1328
1317
  case 'date':
1329
1318
  if (_.isDate(value))
1330
1319
  return sql `${{ value }}`;
@@ -1342,11 +1331,6 @@ const encodeType = (colname, dataType, value) => {
1342
1331
  case 'array':
1343
1332
  if (!_.isArray(value))
1344
1333
  break;
1345
- if (_.includes(stringArrayAttrs, colname)) {
1346
- if (!_.every(value, x => _.isString(x)))
1347
- break;
1348
- return sql `ARRAY[${_.map(value, x => sql `${{ value: x }}`)}]::TEXT[]`;
1349
- }
1350
1334
  return sql `ARRAY[${_.map(value, x => _encodeJsonValue(index._encodeValue(x)))}]::JSONB[]`;
1351
1335
  case 'pointer':
1352
1336
  if (value instanceof index.TObject && value.objectId)
@@ -1390,6 +1374,10 @@ const decodeType = (type, value) => {
1390
1374
  if (_.isString(value))
1391
1375
  return value;
1392
1376
  break;
1377
+ case 'string[]':
1378
+ if (_.isArray(value) && _.every(value, x => _.isString(x)))
1379
+ return value;
1380
+ break;
1393
1381
  case 'date':
1394
1382
  if (_.isDate(value))
1395
1383
  return value;
@@ -1424,7 +1412,7 @@ const decodeType = (type, value) => {
1424
1412
  // update.ts
1425
1413
  //
1426
1414
  // The MIT License
1427
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1415
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1428
1416
  //
1429
1417
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1430
1418
  // of this software and associated documentation files (the "Software"), to deal
@@ -1449,6 +1437,8 @@ const updateOperation = (paths, dataType, operation) => {
1449
1437
  const [op, value] = index.decodeUpdateOp(operation);
1450
1438
  if (index.isVector(dataType)) {
1451
1439
  if (_.isEmpty(subpath)) {
1440
+ if (_.isNil(value) && op === '$set')
1441
+ return sql `${encodeType(column, dataType, value)}`;
1452
1442
  if (!_.isArray(value) || value.length !== dataType.dimension)
1453
1443
  throw Error('Invalid update operation');
1454
1444
  if (!_.every(value, x => _.isFinite(x)))
@@ -1483,7 +1473,7 @@ const updateOperation = (paths, dataType, operation) => {
1483
1473
  case '$max': return sql `GREATEST(${{ identifier: column }}, ${encodeType(column, dataType, value)})`;
1484
1474
  case '$min': return sql `LEAST(${{ identifier: column }}, ${encodeType(column, dataType, value)})`;
1485
1475
  }
1486
- if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
1476
+ if (dataType && index._isTypeof(dataType, ['array', 'string[]'])) {
1487
1477
  switch (op) {
1488
1478
  case '$popFirst':
1489
1479
  if (!_.isNumber(value) || !_.isSafeInteger(value) || value < 0)
@@ -1495,7 +1485,7 @@ const updateOperation = (paths, dataType, operation) => {
1495
1485
  return sql `${{ identifier: column }}[:array_length(${{ identifier: column }}, 1) - ${{ literal: `${value}` }}]`;
1496
1486
  default:
1497
1487
  {
1498
- const isStringArray = _.includes(stringArrayAttrs, column);
1488
+ const isStringArray = dataType === 'string[]';
1499
1489
  if (!_.isArray(value))
1500
1490
  break;
1501
1491
  if (isStringArray && !_.every(value, x => _.isString(x)))
@@ -1558,7 +1548,7 @@ const updateOperation = (paths, dataType, operation) => {
1558
1548
  let element = sql `${{ identifier: column }}`;
1559
1549
  const _subpath = sql `${_.map(subpath, x => sql `${{ quote: x.startsWith('$') ? `$${x}` : x }}`)}`;
1560
1550
  let updateKey;
1561
- if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
1551
+ if (dataType && index._isTypeof(dataType, ['array', 'string[]'])) {
1562
1552
  element = sql `jsonb_extract_path(to_jsonb(${element}), ${_subpath})`;
1563
1553
  updateKey = (value) => sql `ARRAY(SELECT * FROM jsonb_array_elements(
1564
1554
  jsonb_set(to_jsonb(${{ identifier: column }}), ARRAY[${_subpath}], ${value})
@@ -1708,7 +1698,7 @@ const updateOperation = (paths, dataType, operation) => {
1708
1698
  // expressions.ts
1709
1699
  //
1710
1700
  // The MIT License
1711
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1701
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1712
1702
  //
1713
1703
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1714
1704
  // of this software and associated documentation files (the "Software"), to deal
@@ -1797,6 +1787,7 @@ const encodeJsonQueryExpression = (compiler, parent, expr) => {
1797
1787
  case 'number': return sql `to_jsonb(${element})`;
1798
1788
  case 'decimal': return sql `jsonb_build_object('$decimal', CAST(${element} AS TEXT))`;
1799
1789
  case 'string': return sql `to_jsonb(${element})`;
1790
+ case 'string[]': return sql `to_jsonb(${element})`;
1800
1791
  case 'date': return sql `jsonb_build_object(
1801
1792
  '$date', to_char(${element} AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')
1802
1793
  )`;
@@ -1921,7 +1912,7 @@ const encodeQueryExpression = (compiler, parent, expr) => {
1921
1912
  // populate.ts
1922
1913
  //
1923
1914
  // The MIT License
1924
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
1915
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
1925
1916
  //
1926
1917
  // Permission is hereby granted, free of charge, to any person obtaining a copy
1927
1918
  // of this software and associated documentation files (the "Software"), to deal
@@ -2152,7 +2143,7 @@ const encodePopulate = (compiler, parent, remix) => {
2152
2143
  // selectors.ts
2153
2144
  //
2154
2145
  // The MIT License
2155
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2146
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2156
2147
  //
2157
2148
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2158
2149
  // of this software and associated documentation files (the "Software"), to deal
@@ -2231,6 +2222,10 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2231
2222
  if (!_.isString(expr.value))
2232
2223
  break;
2233
2224
  return sql `${element} ${{ literal: op }} ${encodeValue(expr.value)}`;
2225
+ case 'string[]':
2226
+ if (!_.isArray(expr.value) || !_.every(expr.value, _.isString))
2227
+ break;
2228
+ return sql `${element} ${{ literal: op }} ${encodeValue(expr.value)}`;
2234
2229
  case 'date':
2235
2230
  if (!_.isDate(expr.value))
2236
2231
  break;
@@ -2351,7 +2346,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2351
2346
  case '$intersect': return sql `false`;
2352
2347
  }
2353
2348
  }
2354
- if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
2349
+ if (dataType && index._isTypeof(dataType, ['array', 'string[]'])) {
2355
2350
  return sql `${element} ${{ literal: op }} ${{ value: index._encodeValue(expr.value) }}`;
2356
2351
  }
2357
2352
  if (relation && parent.className) {
@@ -2377,7 +2372,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2377
2372
  }
2378
2373
  case '$pattern':
2379
2374
  {
2380
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2375
+ if (dataType && index._isTypeof(dataType, 'string')) {
2381
2376
  if (_.isString(expr.value)) {
2382
2377
  return sql `${element} LIKE ${{ value: `%${expr.value.replace(/([\\_%])/g, '\\$1')}%` }}`;
2383
2378
  }
@@ -2403,7 +2398,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2403
2398
  {
2404
2399
  if (!_.isString(expr.value))
2405
2400
  break;
2406
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2401
+ if (dataType && index._isTypeof(dataType, 'string')) {
2407
2402
  return sql `${element} LIKE ${{ value: `${expr.value.replace(/([\\_%])/g, '\\$1')}%` }}`;
2408
2403
  }
2409
2404
  if (!dataType) {
@@ -2415,7 +2410,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2415
2410
  {
2416
2411
  if (!_.isString(expr.value))
2417
2412
  break;
2418
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2413
+ if (dataType && index._isTypeof(dataType, 'string')) {
2419
2414
  return sql `${element} LIKE ${{ value: `%${expr.value.replace(/([\\_%])/g, '\\$1')}` }}`;
2420
2415
  }
2421
2416
  if (!dataType) {
@@ -2427,10 +2422,10 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2427
2422
  {
2428
2423
  if (!_.isNumber(expr.value) || !_.isSafeInteger(expr.value))
2429
2424
  break;
2430
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2425
+ if (dataType && index._isTypeof(dataType, 'string')) {
2431
2426
  return sql `COALESCE(length(${element}), 0) = ${{ value: expr.value }}`;
2432
2427
  }
2433
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector' || dataType?.type === 'relation'))) {
2428
+ if (dataType && index._isTypeof(dataType, ['array', 'string[]', 'vector', 'relation'])) {
2434
2429
  return sql `COALESCE(array_length(${element}, 1), 0) = ${{ value: expr.value }}`;
2435
2430
  }
2436
2431
  if (!dataType) {
@@ -2448,10 +2443,10 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2448
2443
  {
2449
2444
  if (!_.isBoolean(expr.value))
2450
2445
  break;
2451
- if (dataType === 'string' || (!_.isString(dataType) && dataType?.type === 'string')) {
2446
+ if (dataType && index._isTypeof(dataType, 'string')) {
2452
2447
  return sql `COALESCE(length(${element}), 0) ${{ literal: expr.value ? '=' : '<>' }} 0`;
2453
2448
  }
2454
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector' || dataType?.type === 'relation'))) {
2449
+ if (dataType && index._isTypeof(dataType, ['array', 'string[]', 'vector', 'relation'])) {
2455
2450
  return sql `COALESCE(array_length(${element}, 1), 0) ${{ literal: expr.value ? '=' : '<>' }} 0`;
2456
2451
  }
2457
2452
  if (!dataType) {
@@ -2477,18 +2472,34 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2477
2472
  populates: relation.populate.populates,
2478
2473
  }, expr.value);
2479
2474
  if (!filter)
2480
- break;
2475
+ throw Error('Invalid expression');
2481
2476
  const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
2482
2477
  return sql `NOT EXISTS(
2483
2478
  SELECT * FROM (${populate}) AS ${{ identifier: tempName }}
2484
2479
  WHERE NOT (${filter})
2485
2480
  )`;
2486
2481
  }
2482
+ const mapping = {
2483
+ 'vector': '_doller_num_expr_$',
2484
+ 'string[]': '_doller_str_expr_$',
2485
+ };
2486
+ for (const [key, value] of _.entries(mapping)) {
2487
+ if (dataType && index._isTypeof(dataType, key)) {
2488
+ const tempName = `${value}${compiler.nextIdx()}`;
2489
+ const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2490
+ if (!filter)
2491
+ throw Error('Invalid expression');
2492
+ return sql `NOT EXISTS(
2493
+ SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2494
+ WHERE NOT (${filter})
2495
+ )`;
2496
+ }
2497
+ }
2487
2498
  const tempName = `_doller_expr_$${compiler.nextIdx()}`;
2488
2499
  const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2489
2500
  if (!filter)
2490
- break;
2491
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector'))) {
2501
+ throw Error('Invalid expression');
2502
+ if (dataType && index._isTypeof(dataType, 'array')) {
2492
2503
  return sql `NOT EXISTS(
2493
2504
  SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2494
2505
  WHERE NOT (${filter})
@@ -2514,18 +2525,34 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2514
2525
  populates: relation.populate.populates,
2515
2526
  }, expr.value);
2516
2527
  if (!filter)
2517
- break;
2528
+ throw Error('Invalid expression');
2518
2529
  const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
2519
2530
  return sql `EXISTS(
2520
2531
  SELECT * FROM (${populate}) AS ${{ identifier: tempName }}
2521
2532
  WHERE ${filter}
2522
2533
  )`;
2523
2534
  }
2535
+ const mapping = {
2536
+ 'vector': '_doller_num_expr_$',
2537
+ 'string[]': '_doller_str_expr_$',
2538
+ };
2539
+ for (const [key, value] of _.entries(mapping)) {
2540
+ if (dataType && index._isTypeof(dataType, key)) {
2541
+ const tempName = `${value}${compiler.nextIdx()}`;
2542
+ const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2543
+ if (!filter)
2544
+ throw Error('Invalid expression');
2545
+ return sql `EXISTS(
2546
+ SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2547
+ WHERE ${filter}
2548
+ )`;
2549
+ }
2550
+ }
2524
2551
  const tempName = `_doller_expr_$${compiler.nextIdx()}`;
2525
2552
  const filter = compiler._encodeFilter({ name: tempName, className: relation?.target }, expr.value);
2526
2553
  if (!filter)
2527
- break;
2528
- if (dataType === 'array' || (!_.isString(dataType) && (dataType?.type === 'array' || dataType?.type === 'vector'))) {
2554
+ throw Error('Invalid expression');
2555
+ if (dataType && index._isTypeof(dataType, 'array')) {
2529
2556
  return sql `EXISTS(
2530
2557
  SELECT * FROM (SELECT UNNEST AS "$" FROM UNNEST(${element})) AS ${{ identifier: tempName }}
2531
2558
  WHERE ${filter}
@@ -2547,7 +2574,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2547
2574
  // relation.ts
2548
2575
  //
2549
2576
  // The MIT License
2550
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2577
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2551
2578
  //
2552
2579
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2553
2580
  // of this software and associated documentation files (the "Software"), to deal
@@ -2584,7 +2611,7 @@ const encodeRelation = (compiler, parent, relatedBy) => {
2584
2611
  // index.ts
2585
2612
  //
2586
2613
  // The MIT License
2587
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2614
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2588
2615
  //
2589
2616
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2590
2617
  // of this software and associated documentation files (the "Software"), to deal
@@ -2625,7 +2652,7 @@ const PostgresDialect = {
2625
2652
  // base.ts
2626
2653
  //
2627
2654
  // The MIT License
2628
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2655
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2629
2656
  //
2630
2657
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2631
2658
  // of this software and associated documentation files (the "Software"), to deal
@@ -2783,14 +2810,14 @@ class PostgresStorageClient extends SqlStorage {
2783
2810
  throw e;
2784
2811
  }
2785
2812
  }
2786
- subscribe(callback) {
2813
+ subscribe(channel, callback) {
2787
2814
  const db = this._driver;
2788
2815
  if (!(db instanceof PostgresDriver))
2789
2816
  throw Error('Invalid pubsub instance');
2790
- return db.subscribe(callback);
2817
+ return db.subscribe(channel, callback);
2791
2818
  }
2792
- publish(payload) {
2793
- return this._driver.publish(payload);
2819
+ publish(channel, payload) {
2820
+ return this._driver.publish(channel, payload);
2794
2821
  }
2795
2822
  _refs(schema, className, keys, item) {
2796
2823
  const _schema = _.pickBy(_.mapValues(schema, s => _.pickBy(s.fields, f => (index.isPointer(f) || (index.isRelation(f) && _.isNil(f.foreignField))) && f.target === className)), s => !_.isEmpty(s));
@@ -2851,7 +2878,7 @@ class PostgresStorageTransaction extends PostgresStorageClient {
2851
2878
  // pool.ts
2852
2879
  //
2853
2880
  // The MIT License
2854
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
2881
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
2855
2882
  //
2856
2883
  // Permission is hereby granted, free of charge, to any person obtaining a copy
2857
2884
  // of this software and associated documentation files (the "Software"), to deal
@@ -2896,6 +2923,7 @@ class PostgresStorage extends PostgresStorageClient {
2896
2923
  case 'number': return 'DOUBLE PRECISION';
2897
2924
  case 'decimal': return 'DECIMAL';
2898
2925
  case 'string': return 'TEXT';
2926
+ case 'string[]': return 'TEXT[]';
2899
2927
  case 'date': return 'TIMESTAMP(3) WITH TIME ZONE';
2900
2928
  case 'object': return 'JSONB';
2901
2929
  case 'array': return 'JSONB[]';
@@ -3123,7 +3151,7 @@ class PostgresStorage extends PostgresStorageClient {
3123
3151
  // index.ts
3124
3152
  //
3125
3153
  // The MIT License
3126
- // Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
3154
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
3127
3155
  //
3128
3156
  // Permission is hereby granted, free of charge, to any person obtaining a copy
3129
3157
  // of this software and associated documentation files (the "Software"), to deal