pqb 0.40.12 → 0.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -119,21 +119,21 @@ const sqlFn = (...args) => {
119
119
  return (...args2) => new RawSQL(args2, arg);
120
120
  };
121
121
 
122
- var __defProp$n = Object.defineProperty;
122
+ var __defProp$o = Object.defineProperty;
123
123
  var __defProps$e = Object.defineProperties;
124
124
  var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
125
- var __getOwnPropSymbols$o = Object.getOwnPropertySymbols;
126
- var __hasOwnProp$o = Object.prototype.hasOwnProperty;
127
- var __propIsEnum$o = Object.prototype.propertyIsEnumerable;
128
- var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
- var __spreadValues$n = (a, b) => {
125
+ var __getOwnPropSymbols$p = Object.getOwnPropertySymbols;
126
+ var __hasOwnProp$p = Object.prototype.hasOwnProperty;
127
+ var __propIsEnum$p = Object.prototype.propertyIsEnumerable;
128
+ var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
+ var __spreadValues$o = (a, b) => {
130
130
  for (var prop in b || (b = {}))
131
- if (__hasOwnProp$o.call(b, prop))
132
- __defNormalProp$n(a, prop, b[prop]);
133
- if (__getOwnPropSymbols$o)
134
- for (var prop of __getOwnPropSymbols$o(b)) {
135
- if (__propIsEnum$o.call(b, prop))
136
- __defNormalProp$n(a, prop, b[prop]);
131
+ if (__hasOwnProp$p.call(b, prop))
132
+ __defNormalProp$o(a, prop, b[prop]);
133
+ if (__getOwnPropSymbols$p)
134
+ for (var prop of __getOwnPropSymbols$p(b)) {
135
+ if (__propIsEnum$p.call(b, prop))
136
+ __defNormalProp$o(a, prop, b[prop]);
137
137
  }
138
138
  return a;
139
139
  };
@@ -336,13 +336,13 @@ class ColumnType extends orchidCore.ColumnTypeBase {
336
336
  */
337
337
  searchIndex(...args) {
338
338
  return orchidCore.pushColumnData(this, "indexes", {
339
- options: __spreadValues$n(__spreadValues$n({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
339
+ options: __spreadValues$o(__spreadValues$o({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
340
340
  name: typeof args[0] === "string" ? args[0] : void 0
341
341
  });
342
342
  }
343
343
  unique(...args) {
344
344
  return orchidCore.pushColumnData(this, "indexes", {
345
- options: __spreadProps$e(__spreadValues$n({}, typeof args[0] === "string" ? args[1] : args[0]), {
345
+ options: __spreadProps$e(__spreadValues$o({}, typeof args[0] === "string" ? args[1] : args[0]), {
346
346
  unique: true
347
347
  }),
348
348
  name: typeof args[0] === "string" ? args[0] : void 0
@@ -385,21 +385,21 @@ class ColumnType extends orchidCore.ColumnTypeBase {
385
385
  }
386
386
  }
387
387
 
388
- var __defProp$m = Object.defineProperty;
388
+ var __defProp$n = Object.defineProperty;
389
389
  var __defProps$d = Object.defineProperties;
390
390
  var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
391
- var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
392
- var __hasOwnProp$n = Object.prototype.hasOwnProperty;
393
- var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
394
- var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
- var __spreadValues$m = (a, b) => {
391
+ var __getOwnPropSymbols$o = Object.getOwnPropertySymbols;
392
+ var __hasOwnProp$o = Object.prototype.hasOwnProperty;
393
+ var __propIsEnum$o = Object.prototype.propertyIsEnumerable;
394
+ var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
+ var __spreadValues$n = (a, b) => {
396
396
  for (var prop in b || (b = {}))
397
- if (__hasOwnProp$n.call(b, prop))
398
- __defNormalProp$m(a, prop, b[prop]);
399
- if (__getOwnPropSymbols$n)
400
- for (var prop of __getOwnPropSymbols$n(b)) {
401
- if (__propIsEnum$n.call(b, prop))
402
- __defNormalProp$m(a, prop, b[prop]);
397
+ if (__hasOwnProp$o.call(b, prop))
398
+ __defNormalProp$n(a, prop, b[prop]);
399
+ if (__getOwnPropSymbols$o)
400
+ for (var prop of __getOwnPropSymbols$o(b)) {
401
+ if (__propIsEnum$o.call(b, prop))
402
+ __defNormalProp$n(a, prop, b[prop]);
403
403
  }
404
404
  return a;
405
405
  };
@@ -419,7 +419,7 @@ const simplifyColumnDefault = (value) => {
419
419
  const instantiateColumn = (typeFn, params) => {
420
420
  const column = typeFn();
421
421
  const { dateTimePrecision } = params;
422
- Object.assign(column.data, __spreadProps$d(__spreadValues$m({}, params), {
422
+ Object.assign(column.data, __spreadProps$d(__spreadValues$n({}, params), {
423
423
  dateTimePrecision: (
424
424
  // 0 is default for date, 6 is default for timestamp
425
425
  dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
@@ -777,8 +777,9 @@ const identityToCode = (identity, dataType) => {
777
777
  orchidCore.addCode(code, ")");
778
778
  return code;
779
779
  };
780
- const columnCode = (type, ctx, key, code, data = type.data, skip) => {
780
+ const columnCode = (type, ctx, key, code) => {
781
781
  var _a;
782
+ const { data } = type;
782
783
  code = orchidCore.toArray(code);
783
784
  let prepend = `${ctx.t}.`;
784
785
  const keyName = ctx.snakeCase ? orchidCore.toSnakeCase(key) : key;
@@ -809,13 +810,15 @@ const columnCode = (type, ctx, key, code, data = type.data, skip) => {
809
810
  orchidCore.addCode(code, ".select(false)");
810
811
  if (data.isNullable)
811
812
  orchidCore.addCode(code, ".nullable()");
812
- if (type.encodeFn && type.encodeFn !== (skip == null ? void 0 : skip.encodeFn))
813
- orchidCore.addCode(code, `.encode(${type.encodeFn.toString()})`);
814
- if (type.parseFn && type.parseFn !== (skip == null ? void 0 : skip.parseFn) && !("hideFromCode" in type.parseFn))
815
- orchidCore.addCode(code, `.parse(${type.parseFn.toString()})`);
813
+ if (data.encode && data.encode !== data.defaultEncode)
814
+ orchidCore.addCode(code, `.encode(${data.encode.toString()})`);
815
+ if (data.parse && data.parse !== data.defaultParse)
816
+ orchidCore.addCode(code, `.parse(${data.parse.toString()})`);
817
+ if (type.data.parseNull)
818
+ orchidCore.addCode(code, `.parseNull(${type.data.parseNull.toString()})`);
816
819
  if (data.as)
817
820
  orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
818
- if (data.default !== void 0 && (!ctx.migration || typeof data.default !== "function")) {
821
+ if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
819
822
  orchidCore.addCode(
820
823
  code,
821
824
  `.default(${orchidCore.columnDefaultArgumentToCode(ctx.t, data.default)})`
@@ -858,9 +861,61 @@ const getSqlText = (sql) => {
858
861
  throw new Error(`Batch SQL is not supported in this query`);
859
862
  };
860
863
 
861
- var __defProp$l = Object.defineProperty;
864
+ var __defProp$m = Object.defineProperty;
862
865
  var __defProps$c = Object.defineProperties;
863
866
  var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
867
+ var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
868
+ var __hasOwnProp$n = Object.prototype.hasOwnProperty;
869
+ var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
870
+ var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
871
+ var __spreadValues$m = (a, b) => {
872
+ for (var prop in b || (b = {}))
873
+ if (__hasOwnProp$n.call(b, prop))
874
+ __defNormalProp$m(a, prop, b[prop]);
875
+ if (__getOwnPropSymbols$n)
876
+ for (var prop of __getOwnPropSymbols$n(b)) {
877
+ if (__propIsEnum$n.call(b, prop))
878
+ __defNormalProp$m(a, prop, b[prop]);
879
+ }
880
+ return a;
881
+ };
882
+ var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
883
+ const addColumnParserToQuery = (q, key, column) => {
884
+ var _a;
885
+ if (column._parse) {
886
+ ((_a = q.parsers) != null ? _a : q.parsers = {})[key] = column._parse;
887
+ }
888
+ };
889
+ const setColumnDefaultParse = (column, parse) => {
890
+ column.data.parse = column.data.defaultParse = parse;
891
+ column._parse = (input) => input === null ? null : parse(input);
892
+ };
893
+ const setColumnParse = (column, fn, outputSchema) => {
894
+ const c = Object.create(column);
895
+ c.outputSchema = outputSchema;
896
+ c.data = __spreadProps$c(__spreadValues$m({}, column.data), { parse: fn });
897
+ const { parseNull } = column.data;
898
+ c._parse = parseNull ? (input) => input === null ? parseNull() : fn(input) : (input) => input === null ? null : fn(input);
899
+ return c;
900
+ };
901
+ const setColumnParseNull = (column, fn, nullSchema) => {
902
+ const c = Object.create(column);
903
+ c.nullSchema = nullSchema;
904
+ c.data = __spreadProps$c(__spreadValues$m({}, column.data), { parseNull: fn });
905
+ const { parse } = column.data;
906
+ c._parse = parse ? (input) => input === null ? fn() : parse(input) : (input) => input === null ? fn() : input;
907
+ return c;
908
+ };
909
+ const setColumnEncode = (column, fn, inputSchema) => {
910
+ const c = Object.create(column);
911
+ c.inputSchema = inputSchema;
912
+ c.data = __spreadProps$c(__spreadValues$m({}, column.data), { encode: fn });
913
+ return c;
914
+ };
915
+
916
+ var __defProp$l = Object.defineProperty;
917
+ var __defProps$b = Object.defineProperties;
918
+ var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
864
919
  var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
865
920
  var __hasOwnProp$m = Object.prototype.hasOwnProperty;
866
921
  var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
@@ -876,7 +931,7 @@ var __spreadValues$l = (a, b) => {
876
931
  }
877
932
  return a;
878
933
  };
879
- var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
934
+ var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
880
935
  function setQueryOperators(query, operators) {
881
936
  const q = query.q;
882
937
  if (q.operators !== operators) {
@@ -965,7 +1020,7 @@ const base = {
965
1020
  (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
966
1021
  )
967
1022
  };
968
- const boolean = __spreadProps$c(__spreadValues$l({}, base), {
1023
+ const boolean = __spreadProps$b(__spreadValues$l({}, base), {
969
1024
  and: make(
970
1025
  (key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
971
1026
  ),
@@ -973,7 +1028,7 @@ const boolean = __spreadProps$c(__spreadValues$l({}, base), {
973
1028
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
974
1029
  )
975
1030
  });
976
- const numeric = __spreadProps$c(__spreadValues$l({}, base), {
1031
+ const numeric = __spreadProps$b(__spreadValues$l({}, base), {
977
1032
  lt: make(
978
1033
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
979
1034
  ),
@@ -994,7 +1049,7 @@ const numeric = __spreadProps$c(__spreadValues$l({}, base), {
994
1049
  )}`
995
1050
  )
996
1051
  });
997
- const text = __spreadProps$c(__spreadValues$l({}, base), {
1052
+ const text = __spreadProps$b(__spreadValues$l({}, base), {
998
1053
  contains: make(
999
1054
  (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
1000
1055
  ),
@@ -1016,10 +1071,10 @@ const text = __spreadProps$c(__spreadValues$l({}, base), {
1016
1071
  });
1017
1072
  const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1018
1073
  const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${orchidCore.addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${orchidCore.addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
1019
- const json = __spreadProps$c(__spreadValues$l({}, base), {
1074
+ const json = __spreadProps$b(__spreadValues$l({}, base), {
1020
1075
  jsonPathQueryFirst: Object.assign(
1021
1076
  function(path, options) {
1022
- var _a, _b, _c, _d, _e;
1077
+ var _a, _b, _c;
1023
1078
  const chain = (_b = (_a = this.q).chain) != null ? _b : _a.chain = [];
1024
1079
  chain.push(jsonPathQueryOp, [path, options]);
1025
1080
  if ((_c = this.q.parsers) == null ? void 0 : _c[orchidCore.getValueKey]) {
@@ -1027,8 +1082,7 @@ const json = __spreadProps$c(__spreadValues$l({}, base), {
1027
1082
  }
1028
1083
  if (options == null ? void 0 : options.type) {
1029
1084
  const type = options.type(this.columnTypes);
1030
- if (type.parseFn)
1031
- ((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[orchidCore.getValueKey] = type.parseFn;
1085
+ addColumnParserToQuery(this.q, orchidCore.getValueKey, type);
1032
1086
  chain.push = (...args) => {
1033
1087
  chain.push = Array.prototype.push;
1034
1088
  chain.push((s) => `${s}::${type.dataType}`, orchidCore.emptyArray);
@@ -1080,8 +1134,6 @@ const Operators = {
1080
1134
  };
1081
1135
 
1082
1136
  var __defProp$k = Object.defineProperty;
1083
- var __defProps$b = Object.defineProperties;
1084
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
1085
1137
  var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
1086
1138
  var __hasOwnProp$l = Object.prototype.hasOwnProperty;
1087
1139
  var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
@@ -1097,7 +1149,6 @@ var __spreadValues$k = (a, b) => {
1097
1149
  }
1098
1150
  return a;
1099
1151
  };
1100
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
1101
1152
  class TextBaseColumn extends ColumnType {
1102
1153
  constructor(schema, schemaType = schema.stringSchema()) {
1103
1154
  super(schema, schemaType);
@@ -1267,19 +1318,20 @@ class MoneyColumn extends ColumnType {
1267
1318
  super(schema, schema.number());
1268
1319
  this.dataType = "money";
1269
1320
  this.operators = Operators.number;
1270
- this.parseFn = Object.assign(
1271
- function(input) {
1272
- return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
1273
- },
1274
- {
1275
- hideFromCode: true
1276
- }
1277
- );
1321
+ setColumnDefaultParse(this, moneyParse);
1278
1322
  }
1279
1323
  toCode(ctx, key) {
1280
1324
  return columnCode(this, ctx, key, `money()`);
1281
1325
  }
1282
1326
  }
1327
+ const moneyParse = Object.assign(
1328
+ function(input) {
1329
+ return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
1330
+ },
1331
+ {
1332
+ hideFromCode: true
1333
+ }
1334
+ );
1283
1335
  class CidrColumn extends ColumnType {
1284
1336
  constructor(schema) {
1285
1337
  super(schema, schema.stringSchema());
@@ -1438,6 +1490,7 @@ class UUIDColumn extends ColumnType {
1438
1490
  super(schema, schema.uuid());
1439
1491
  this.dataType = "uuid";
1440
1492
  this.operators = Operators.text;
1493
+ this.data.defaultDefault = uuidDefault;
1441
1494
  }
1442
1495
  /**
1443
1496
  * see {@link ColumnType.primaryKey}
@@ -1449,15 +1502,7 @@ class UUIDColumn extends ColumnType {
1449
1502
  return column;
1450
1503
  }
1451
1504
  toCode(ctx, key) {
1452
- const { data } = this;
1453
- return columnCode(
1454
- this,
1455
- ctx,
1456
- key,
1457
- `uuid()`,
1458
- // don't output the default default
1459
- data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$b(__spreadValues$k({}, data), { default: void 0 }) : data
1460
- );
1505
+ return columnCode(this, ctx, key, `uuid()`);
1461
1506
  }
1462
1507
  }
1463
1508
  class XMLColumn extends ColumnType {
@@ -1484,7 +1529,6 @@ class CitextColumn extends TextBaseColumn {
1484
1529
  const dateTimeEncode = (input) => {
1485
1530
  return typeof input === "number" ? new Date(input) : input;
1486
1531
  };
1487
- const skipDateMethodsFromToCode = { encodeFn: dateTimeEncode };
1488
1532
  class DateBaseColumn extends ColumnType {
1489
1533
  constructor(schema) {
1490
1534
  super(
@@ -1494,9 +1538,9 @@ class DateBaseColumn extends ColumnType {
1494
1538
  schema.stringNumberDate()
1495
1539
  );
1496
1540
  this.operators = Operators.date;
1497
- this.encodeFn = dateTimeEncode;
1498
1541
  this.asNumber = schema.dateAsNumber;
1499
1542
  this.asDate = schema.dateAsDate;
1543
+ this.data.encode = this.data.defaultEncode = dateTimeEncode;
1500
1544
  }
1501
1545
  }
1502
1546
  class DateColumn extends DateBaseColumn {
@@ -1509,9 +1553,7 @@ class DateColumn extends DateBaseColumn {
1509
1553
  this,
1510
1554
  ctx,
1511
1555
  key,
1512
- `date()${orchidCore.dateDataToCode(this.data, ctx.migration)}`,
1513
- this.data,
1514
- skipDateMethodsFromToCode
1556
+ `date()${orchidCore.dateDataToCode(this.data, ctx.migration)}`
1515
1557
  );
1516
1558
  }
1517
1559
  }
@@ -1549,9 +1591,7 @@ const timestampToCode = (self, ctx, key) => {
1549
1591
  self,
1550
1592
  ctx,
1551
1593
  key,
1552
- `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, ctx.migration)}`,
1553
- self.data,
1554
- skipDateMethodsFromToCode
1594
+ `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, ctx.migration)}`
1555
1595
  );
1556
1596
  self.data.default = def;
1557
1597
  self.data.modifyQuery = modifyQuery;
@@ -1561,9 +1601,7 @@ const timestampToCode = (self, ctx, key) => {
1561
1601
  self,
1562
1602
  ctx,
1563
1603
  key,
1564
- `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, ctx.migration)}`,
1565
- self.data,
1566
- skipDateMethodsFromToCode
1604
+ `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, ctx.migration)}`
1567
1605
  );
1568
1606
  }
1569
1607
  };
@@ -1602,9 +1640,7 @@ class TimeColumn extends ColumnType {
1602
1640
  `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(
1603
1641
  this.data,
1604
1642
  ctx.migration
1605
- )}`,
1606
- this.data,
1607
- skipDateMethodsFromToCode
1643
+ )}`
1608
1644
  );
1609
1645
  }
1610
1646
  }
@@ -1622,9 +1658,7 @@ class IntervalColumn extends ColumnType {
1622
1658
  this,
1623
1659
  ctx,
1624
1660
  key,
1625
- `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`,
1626
- this.data,
1627
- skipDateMethodsFromToCode
1661
+ `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`
1628
1662
  );
1629
1663
  }
1630
1664
  toSQL() {
@@ -1642,28 +1676,26 @@ class BooleanColumn extends ColumnType {
1642
1676
  this.dataType = "bool";
1643
1677
  this.operators = Operators.boolean;
1644
1678
  this.data.alias = "boolean";
1679
+ this.data.parseItem = parseItem;
1645
1680
  }
1646
1681
  toCode(ctx, key) {
1647
1682
  return columnCode(this, ctx, key, "boolean()");
1648
1683
  }
1649
- parseItem(input) {
1650
- return input[0] === "t";
1651
- }
1652
1684
  }
1685
+ const parseItem = (input) => input[0] === "t";
1653
1686
 
1654
- const encodeFn = (x) => x === null ? x : JSON.stringify(x);
1655
- const toCodeSkip = { encodeFn };
1687
+ const encode = (x) => x === null ? x : JSON.stringify(x);
1656
1688
  class JSONColumn extends ColumnType {
1657
- constructor() {
1658
- super(...arguments);
1689
+ constructor(schema, inputType) {
1690
+ super(schema, inputType);
1659
1691
  this.dataType = "jsonb";
1660
1692
  this.operators = Operators.json;
1693
+ this.data.encode = this.data.defaultEncode = encode;
1661
1694
  }
1662
1695
  toCode(ctx, key) {
1663
- return columnCode(this, ctx, key, `json()`, this.data, toCodeSkip);
1696
+ return columnCode(this, ctx, key, `json()`);
1664
1697
  }
1665
1698
  }
1666
- JSONColumn.prototype.encodeFn = encodeFn;
1667
1699
  class JSONTextColumn extends ColumnType {
1668
1700
  constructor(schema) {
1669
1701
  super(schema, schema.stringSchema());
@@ -1671,7 +1703,7 @@ class JSONTextColumn extends ColumnType {
1671
1703
  this.operators = Operators.text;
1672
1704
  }
1673
1705
  toCode(ctx, key) {
1674
- return columnCode(this, ctx, key, `jsonText()`, this.data, toCodeSkip);
1706
+ return columnCode(this, ctx, key, `jsonText()`);
1675
1707
  }
1676
1708
  }
1677
1709
 
@@ -1684,10 +1716,7 @@ const queryTypeWithLimitOne = {
1684
1716
  const isQueryReturnsAll = (q) => !q.q.returnType || q.q.returnType === "all";
1685
1717
 
1686
1718
  const applySqlComputed = (ctx, q, computed, as, quotedAs) => {
1687
- var _a;
1688
- const parser = computed.result.value.parseFn;
1689
- if (parser)
1690
- ((_a = q.parsers) != null ? _a : q.parsers = {})[as] = parser;
1719
+ addColumnParserToQuery(q, as, computed.result.value);
1691
1720
  return computed.toSQL(ctx, quotedAs);
1692
1721
  };
1693
1722
  function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
@@ -2711,12 +2740,9 @@ const _join = (query, require2, type, first, args) => {
2711
2740
  if (shape) {
2712
2741
  if (!require2)
2713
2742
  shape = __spreadValues$h({}, shape);
2714
- parsers = {};
2743
+ const arg = { parsers: {} };
2715
2744
  for (const key in shape) {
2716
- const parser = shape[key].parseFn;
2717
- if (parser) {
2718
- parsers[key] = parser;
2719
- }
2745
+ addColumnParserToQuery(arg, key, shape[key]);
2720
2746
  }
2721
2747
  }
2722
2748
  }
@@ -2872,19 +2898,8 @@ class ArrayColumn extends ColumnType {
2872
2898
  super(schema, inputType, outputType, queryType);
2873
2899
  this.dataType = "array";
2874
2900
  this.operators = Operators.array;
2875
- this.parseFn = Object.assign(
2876
- (source) => {
2877
- if (!source)
2878
- return source;
2879
- const entries = [];
2880
- parsePostgresArray(source, entries, this.data.item.parseItem);
2881
- return entries;
2882
- },
2883
- {
2884
- hideFromCode: true
2885
- }
2886
- );
2887
2901
  item.data.isNullable = true;
2902
+ setColumnDefaultParse(this, (input) => parse.call(this, input));
2888
2903
  this.data.item = item instanceof ArrayColumn ? item.data.item : item;
2889
2904
  this.data.name = item.data.name;
2890
2905
  this.data.arrayDims = item instanceof ArrayColumn ? item.data.arrayDims + 1 : 1;
@@ -2909,6 +2924,11 @@ class ArrayColumn extends ColumnType {
2909
2924
  return columnCode(this, ctx, key, code);
2910
2925
  }
2911
2926
  }
2927
+ const parse = function(source) {
2928
+ const entries = [];
2929
+ parsePostgresArray(source, entries, this.data.item.data.parseItem);
2930
+ return entries;
2931
+ };
2912
2932
  const parsePostgresArray = (source, entries, transform) => {
2913
2933
  let pos = 0;
2914
2934
  if (source[0] === "[") {
@@ -3026,8 +3046,8 @@ class SmallIntColumn extends IntegerBaseColumn {
3026
3046
  constructor(schema) {
3027
3047
  super(schema);
3028
3048
  this.dataType = "int2";
3029
- this.parseItem = parseInt;
3030
3049
  this.data.alias = "smallint";
3050
+ this.data.parseItem = parseInt;
3031
3051
  }
3032
3052
  toCode(ctx, key) {
3033
3053
  return intToCode(this, ctx, key, "smallint");
@@ -3040,8 +3060,8 @@ class IntegerColumn extends IntegerBaseColumn {
3040
3060
  constructor(schema) {
3041
3061
  super(schema);
3042
3062
  this.dataType = "int4";
3043
- this.parseItem = parseInt;
3044
3063
  this.data.alias = "integer";
3064
+ this.data.parseItem = parseInt;
3045
3065
  }
3046
3066
  toCode(ctx, key) {
3047
3067
  return intToCode(this, ctx, key, "integer");
@@ -3067,8 +3087,8 @@ class RealColumn extends NumberBaseColumn {
3067
3087
  constructor(schema) {
3068
3088
  super(schema, schema.number());
3069
3089
  this.dataType = "float4";
3070
- this.parseItem = parseFloat;
3071
3090
  this.data.alias = "real";
3091
+ this.data.parseItem = parseFloat;
3072
3092
  }
3073
3093
  toCode(ctx, key) {
3074
3094
  return columnCode(
@@ -3093,9 +3113,9 @@ class SmallSerialColumn extends IntegerBaseColumn {
3093
3113
  constructor(schema) {
3094
3114
  super(schema);
3095
3115
  this.dataType = "int2";
3096
- this.parseItem = parseInt;
3097
3116
  this.data.int = true;
3098
3117
  this.data.alias = "smallSerial";
3118
+ this.data.parseItem = parseInt;
3099
3119
  }
3100
3120
  toSQL() {
3101
3121
  return "smallserial";
@@ -3117,9 +3137,9 @@ class SerialColumn extends IntegerBaseColumn {
3117
3137
  constructor(schema) {
3118
3138
  super(schema);
3119
3139
  this.dataType = "int4";
3120
- this.parseItem = parseInt;
3121
3140
  this.data.int = true;
3122
3141
  this.data.alias = "serial";
3142
+ this.data.parseItem = parseInt;
3123
3143
  }
3124
3144
  toSQL() {
3125
3145
  return "serial";
@@ -3151,29 +3171,31 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
3151
3171
  }
3152
3172
  }
3153
3173
 
3154
- const parseDateToNumber = (value) => value ? Date.parse(value) : value;
3155
- const parseDateToDate = (value) => value ? new Date(value) : value;
3156
- parseDateToNumber.hideFromCode = parseDateToDate.hideFromCode = true;
3174
+ const parseDateToDate = (value) => new Date(value);
3157
3175
  const defaultSchemaConfig = {
3176
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3158
3177
  parse(fn) {
3159
- return Object.assign(Object.create(this), {
3160
- parseFn: fn,
3161
- parseItem: fn
3162
- });
3178
+ return setColumnParse(this, fn);
3179
+ },
3180
+ parseNull(fn) {
3181
+ return setColumnParseNull(this, fn);
3163
3182
  },
3183
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3164
3184
  encode(fn) {
3165
- return Object.assign(Object.create(this), {
3166
- encodeFn: fn
3167
- });
3185
+ return orchidCore.setColumnData(this, "encode", fn);
3168
3186
  },
3169
3187
  asType() {
3170
3188
  return this;
3171
3189
  },
3172
3190
  dateAsNumber() {
3173
- return this.parse(parseDateToNumber);
3191
+ const c = this.parse(Date.parse);
3192
+ c.data.defaultParse = Date.parse;
3193
+ return c;
3174
3194
  },
3175
3195
  dateAsDate() {
3176
- return this.parse(parseDateToDate);
3196
+ const c = this.parse(parseDateToDate);
3197
+ c.data.defaultParse = parseDateToDate;
3198
+ return c;
3177
3199
  },
3178
3200
  enum(dataType, type) {
3179
3201
  return new EnumColumn(defaultSchemaConfig, dataType, type, void 0);
@@ -4277,9 +4299,8 @@ var __spreadValues$d = (a, b) => {
4277
4299
  };
4278
4300
  var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
4279
4301
  const addParserForRawExpression = (q, key, raw) => {
4280
- const type = raw.result.value;
4281
- if (type == null ? void 0 : type.parseFn)
4282
- orchidCore.setParserToQuery(q.q, key, type.parseFn);
4302
+ if (raw.result.value)
4303
+ addColumnParserToQuery(q.q, key, raw.result.value);
4283
4304
  };
4284
4305
  const addParsersForSelectJoined = (q, arg, as = arg) => {
4285
4306
  var _a, _b, _c, _d;
@@ -4904,7 +4925,6 @@ function queryFrom(self, arg) {
4904
4925
  data.as || (data.as = "t");
4905
4926
  } else if (Array.isArray(arg)) {
4906
4927
  const { shape } = data;
4907
- const parsers = (_c = data.parsers) != null ? _c : data.parsers = {};
4908
4928
  for (const item of arg) {
4909
4929
  if (typeof item === "string") {
4910
4930
  const w = data.withShapes[item];
@@ -4912,13 +4932,15 @@ function queryFrom(self, arg) {
4912
4932
  if (w.computeds)
4913
4933
  data.computeds = __spreadValues$b(__spreadValues$b({}, data.computeds), w.computeds);
4914
4934
  for (const key in w.shape) {
4915
- if (w.shape[key].parseFn) {
4916
- parsers[key] = w.shape[key].parseFn;
4917
- }
4935
+ addColumnParserToQuery(
4936
+ self,
4937
+ key,
4938
+ w.shape[key]
4939
+ );
4918
4940
  }
4919
4941
  } else if (!orchidCore.isExpression(item)) {
4920
4942
  Object.assign(shape, getShapeFromSelect(item, true));
4921
- Object.assign(parsers, item.q.parsers);
4943
+ Object.assign((_c = data.parsers) != null ? _c : data.parsers = {}, item.q.parsers);
4922
4944
  }
4923
4945
  }
4924
4946
  } else {
@@ -6282,45 +6304,46 @@ class PostgisGeographyPointColumn extends ColumnType {
6282
6304
  super(schema, schema.geographyPointSchema());
6283
6305
  this.dataType = "geography(Point)";
6284
6306
  this.operators = Operators.any;
6307
+ setColumnDefaultParse(this, defaultParse);
6308
+ this.data.encode = this.data.defaultEncode = defaultEncode;
6285
6309
  }
6286
6310
  static isDefaultPoint(typmod) {
6287
6311
  return typmodType(typmod) === "Point" && typmodSrid(typmod) === defaultSrid;
6288
6312
  }
6289
- parseFn(input) {
6290
- if (!input)
6291
- return null;
6292
- const bytes = new Uint8Array(20);
6293
- for (let i = 0; i < 40; i += 2) {
6294
- bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
6295
- }
6296
- const view = new DataView(bytes.buffer);
6297
- const srid = view.getUint32(0, true);
6298
- const lon = view.getFloat64(4, true);
6299
- const lat = view.getFloat64(12, true);
6300
- return srid === defaultSrid ? { lon, lat } : {
6301
- lon,
6302
- lat,
6303
- srid
6304
- };
6305
- }
6306
- encodeFn({ srid = defaultSrid, lon, lat }) {
6307
- const arr = new Uint8Array(25);
6308
- const view = new DataView(arr.buffer);
6309
- view.setInt8(0, 1);
6310
- view.setInt8(1, 1);
6311
- view.setInt8(4, 32);
6312
- view.setUint32(5, srid, true);
6313
- view.setFloat64(9, lon, true);
6314
- view.setFloat64(17, lat, true);
6315
- return uint8ArrToHex(arr);
6316
- }
6317
6313
  toCode(ctx, key) {
6318
- return columnCode(this, ctx, key, `geography.point()`, this.data, {
6319
- encodeFn: PostgisGeographyPointColumn.prototype.encodeFn,
6320
- parseFn: PostgisGeographyPointColumn.prototype.parseFn
6321
- });
6322
- }
6323
- }
6314
+ return columnCode(this, ctx, key, `geography.point()`);
6315
+ }
6316
+ }
6317
+ const defaultParse = (input) => {
6318
+ const bytes = new Uint8Array(20);
6319
+ for (let i = 0; i < 40; i += 2) {
6320
+ bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
6321
+ }
6322
+ const view = new DataView(bytes.buffer);
6323
+ const srid = view.getUint32(0, true);
6324
+ const lon = view.getFloat64(4, true);
6325
+ const lat = view.getFloat64(12, true);
6326
+ return srid === defaultSrid ? { lon, lat } : {
6327
+ lon,
6328
+ lat,
6329
+ srid
6330
+ };
6331
+ };
6332
+ const defaultEncode = ({
6333
+ srid = defaultSrid,
6334
+ lon,
6335
+ lat
6336
+ }) => {
6337
+ const arr = new Uint8Array(25);
6338
+ const view = new DataView(arr.buffer);
6339
+ view.setInt8(0, 1);
6340
+ view.setInt8(1, 1);
6341
+ view.setInt8(4, 32);
6342
+ view.setUint32(5, srid, true);
6343
+ view.setFloat64(9, lon, true);
6344
+ view.setFloat64(17, lat, true);
6345
+ return uint8ArrToHex(arr);
6346
+ };
6324
6347
  const typmodGetType = (typmod) => (typmod & 252) >> 2;
6325
6348
  const lwtypeName = (type) => [
6326
6349
  "Unknown",
@@ -6797,10 +6820,7 @@ class FnExpression extends orchidCore.Expression {
6797
6820
  query.q.returnsOne = true;
6798
6821
  query.q.getColumn = value;
6799
6822
  query.q.select = [this];
6800
- const { parseFn } = value;
6801
- if (parseFn) {
6802
- orchidCore.setParserToQuery(query.q, orchidCore.getValueKey, parseFn);
6803
- }
6823
+ addColumnParserToQuery(query.q, orchidCore.getValueKey, value);
6804
6824
  }
6805
6825
  // Builds function SQL.
6806
6826
  makeSQL(ctx, quotedAs) {
@@ -6890,18 +6910,14 @@ const isSelectingCount = (q) => {
6890
6910
  const { expr } = q.q;
6891
6911
  return expr instanceof FnExpression && expr.fn === "count" && expr.args[0] === "*";
6892
6912
  };
6893
- const int = new IntegerColumn(defaultSchemaConfig);
6894
- int.parseItem = int.parseFn = (input) => parseInt(input);
6895
- const nullableInt = new IntegerColumn(defaultSchemaConfig);
6896
- nullableInt.parseItem = nullableInt.parseFn = (input) => input === null ? null : parseInt(input);
6897
- const nullableFloat = new RealColumn(defaultSchemaConfig);
6898
- nullableFloat.parseItem = nullableFloat.parseFn = (input) => input === null ? null : parseFloat(input);
6913
+ const int = new IntegerColumn(defaultSchemaConfig).parse(parseInt);
6914
+ const float = new RealColumn(defaultSchemaConfig).parse(parseFloat);
6899
6915
  const stringAsNumber = new NumberAsStringBaseColumn(
6900
6916
  defaultSchemaConfig
6901
6917
  );
6902
6918
  const numericResultColumn = (q, arg) => {
6903
6919
  const type = typeof arg === "string" ? _getSelectableColumn(q, arg) : arg.result.value;
6904
- return type instanceof NumberBaseColumn ? nullableFloat : stringAsNumber;
6920
+ return type instanceof NumberBaseColumn ? float : stringAsNumber;
6905
6921
  };
6906
6922
  class AggregateMethods {
6907
6923
  /**
@@ -7363,7 +7379,7 @@ class AggregateMethods {
7363
7379
  * @param over - OVER clause config
7364
7380
  */
7365
7381
  rowNumber(over) {
7366
- return makeFnExpression(this, nullableInt, "row_number", orchidCore.emptyArray, {
7382
+ return makeFnExpression(this, int, "row_number", orchidCore.emptyArray, {
7367
7383
  over
7368
7384
  });
7369
7385
  }
@@ -7386,7 +7402,7 @@ class AggregateMethods {
7386
7402
  * @param over - OVER clause config
7387
7403
  */
7388
7404
  rank(over) {
7389
- return makeFnExpression(this, nullableInt, "rank", orchidCore.emptyArray, {
7405
+ return makeFnExpression(this, int, "rank", orchidCore.emptyArray, {
7390
7406
  over
7391
7407
  });
7392
7408
  }
@@ -7409,7 +7425,7 @@ class AggregateMethods {
7409
7425
  * @param over - OVER clause config
7410
7426
  */
7411
7427
  denseRank(over) {
7412
- return makeFnExpression(this, nullableInt, "dense_rank", orchidCore.emptyArray, {
7428
+ return makeFnExpression(this, int, "dense_rank", orchidCore.emptyArray, {
7413
7429
  over
7414
7430
  });
7415
7431
  }
@@ -7432,7 +7448,7 @@ class AggregateMethods {
7432
7448
  * @param over - OVER clause config
7433
7449
  */
7434
7450
  percentRank(over) {
7435
- return makeFnExpression(this, nullableInt, "percent_rank", orchidCore.emptyArray, {
7451
+ return makeFnExpression(this, int, "percent_rank", orchidCore.emptyArray, {
7436
7452
  over
7437
7453
  });
7438
7454
  }
@@ -7455,7 +7471,7 @@ class AggregateMethods {
7455
7471
  * @param over - OVER clause config
7456
7472
  */
7457
7473
  cumeDist(over) {
7458
- return makeFnExpression(this, nullableFloat, "cume_dist", orchidCore.emptyArray, {
7474
+ return makeFnExpression(this, float, "cume_dist", orchidCore.emptyArray, {
7459
7475
  over
7460
7476
  });
7461
7477
  }
@@ -7539,7 +7555,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
7539
7555
  }
7540
7556
  if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
7541
7557
  ctx.columns.set(key, ctx.columns.size);
7542
- encoders[key] = (_c = shape[key]) == null ? void 0 : _c.encodeFn;
7558
+ encoders[key] = (_c = shape[key]) == null ? void 0 : _c.data.encode;
7543
7559
  }
7544
7560
  }
7545
7561
  }
@@ -10687,7 +10703,7 @@ const _queryUpdate = (query, arg) => {
10687
10703
  set[key] = new RawSQL(`(SELECT * FROM "${as}")`);
10688
10704
  }
10689
10705
  } else {
10690
- const encode = shape[key].encodeFn;
10706
+ const encode = shape[key].data.encode;
10691
10707
  if (encode)
10692
10708
  set[key] = encode(value);
10693
10709
  }
@@ -12780,9 +12796,9 @@ class Db {
12780
12796
  for (const key in shape) {
12781
12797
  const column = shape[key];
12782
12798
  column.data.key = key;
12783
- if (column.parseFn) {
12799
+ if (column._parse) {
12784
12800
  hasParsers = true;
12785
- parsers[key] = column.parseFn;
12801
+ parsers[key] = column._parse;
12786
12802
  }
12787
12803
  if (column.data.name) {
12788
12804
  prepareSelectAll = true;
@@ -12808,10 +12824,9 @@ class Db {
12808
12824
  arr.push(key);
12809
12825
  if (!column.data.runtimeDefault) {
12810
12826
  const {
12811
- data: { default: def },
12812
- encodeFn
12827
+ data: { default: def, encode }
12813
12828
  } = column;
12814
- column.data.runtimeDefault = encodeFn ? () => encodeFn(def()) : def;
12829
+ column.data.runtimeDefault = encode ? () => encode(def()) : def;
12815
12830
  }
12816
12831
  }
12817
12832
  }
@@ -13397,6 +13412,7 @@ exports._queryWhereNotOneOf = _queryWhereNotOneOf;
13397
13412
  exports._queryWhereNotSql = _queryWhereNotSql;
13398
13413
  exports._queryWhereOneOf = _queryWhereOneOf;
13399
13414
  exports._queryWhereSql = _queryWhereSql;
13415
+ exports.addColumnParserToQuery = addColumnParserToQuery;
13400
13416
  exports.addParserForRawExpression = addParserForRawExpression;
13401
13417
  exports.addParserForSelectItem = addParserForSelectItem;
13402
13418
  exports.addQueryOn = addQueryOn;
@@ -13471,6 +13487,10 @@ exports.referencesArgsToCode = referencesArgsToCode;
13471
13487
  exports.resolveSubQueryCallback = resolveSubQueryCallback;
13472
13488
  exports.rollbackSql = rollbackSql$1;
13473
13489
  exports.saveSearchAlias = saveSearchAlias;
13490
+ exports.setColumnDefaultParse = setColumnDefaultParse;
13491
+ exports.setColumnEncode = setColumnEncode;
13492
+ exports.setColumnParse = setColumnParse;
13493
+ exports.setColumnParseNull = setColumnParseNull;
13474
13494
  exports.setParserForSelectedString = setParserForSelectedString;
13475
13495
  exports.setQueryObjectValue = setQueryObjectValue;
13476
13496
  exports.setQueryOperators = setQueryOperators;