@vibeorm/sql 5.7.0 → 5.8.0

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
@@ -672,6 +672,27 @@ function scalar(type, valid) {
672
672
  }
673
673
  var stringDecoder = scalar("String", (value) => typeof value === "string");
674
674
  var dateDecoder = scalar("DateTime", (value) => value instanceof Date && Number.isFinite(value.getTime()));
675
+ var bigIntDecoder = scalar("BigInt", (value) => typeof value === "bigint");
676
+ var SAFE_INTEGER_LIMIT = BigInt(Number.MAX_SAFE_INTEGER);
677
+ var bigIntNumberDecoder = registerScalar({ identity: JSON.stringify(["scalar", "BigInt", "number"]), contract: { scalar: "BigInt", nullable: false, list: false }, decoder: Object.freeze({
678
+ decode: (params) => {
679
+ const exact = bigIntDecoder.decode(params);
680
+ if (exact > SAFE_INTEGER_LIMIT || exact < -SAFE_INTEGER_LIMIT)
681
+ refuse(false, `BigInt ${exact.toString()} is beyond Number.MAX_SAFE_INTEGER, so it cannot read as a safe number`);
682
+ return Number(exact);
683
+ },
684
+ encode: (params) => {
685
+ const { value } = params;
686
+ const unsafe = `${String(value)} is not a safe integer, so it is refused instead of rounded`;
687
+ if (typeof value === "number" && !Number.isSafeInteger(value))
688
+ refuse(true, unsafe);
689
+ const encoded = bigIntDecoder.encode(params);
690
+ const exact = BigInt(String(encoded));
691
+ if (exact > SAFE_INTEGER_LIMIT || exact < -SAFE_INTEGER_LIMIT)
692
+ refuse(true, unsafe);
693
+ return encoded;
694
+ }
695
+ }) });
675
696
  var extendedDecoder = registerScalar({ identity: "extended-date-time", contract: { scalar: "DateTime", nullable: false, list: false }, decoder: Object.freeze({
676
697
  decode: (params) => {
677
698
  if (params.value === "infinity" || params.value === Infinity)
@@ -752,7 +773,8 @@ var decode = Object.freeze({
752
773
  boolean: scalar("Boolean", (value) => typeof value === "boolean"),
753
774
  int: scalar("Int", (value) => typeof value === "number" && Number.isSafeInteger(value)),
754
775
  float: scalar("Float", (value) => typeof value === "number" && Number.isFinite(value)),
755
- bigInt: scalar("BigInt", (value) => typeof value === "bigint"),
776
+ bigInt: bigIntDecoder,
777
+ bigIntNumber: bigIntNumberDecoder,
756
778
  decimal: scalar("Decimal", (value) => typeof value === "string" && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(value)),
757
779
  dateTime: dateDecoder,
758
780
  extendedDateTime: extendedDecoder,
@@ -6587,4 +6609,4 @@ export {
6587
6609
  toPgArrayLiteral
6588
6610
  };
6589
6611
 
6590
- //# debugId=0EA38AD633C52F8C64756E2164756E21
6612
+ //# debugId=D4C3C7B84AC363A964756E2164756E21