@vibeorm/sql 5.6.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/ast.d.ts +5 -2
- package/dist/index.js +36 -7
- package/dist/index.js.map +5 -5
- package/dist/query/index.js.map +1 -1
- package/dist/result-decoder.d.ts +2 -0
- package/package.json +2 -2
package/dist/ast.d.ts
CHANGED
|
@@ -1393,7 +1393,10 @@ export type ChainResult = {
|
|
|
1393
1393
|
* array_agg("__vibe_i")::text FROM (SELECT DISTINCT ARRAY["c0", "c1"] AS
|
|
1394
1394
|
* "__vibe_i" FROM "step" LIMIT $n) AS "__vibe_d")` — a two-dimensional text
|
|
1395
1395
|
* array literal of at most `limit` distinct images, NULL when the step
|
|
1396
|
-
* returned no row.
|
|
1396
|
+
* returned no row. With `inserted`, both read the update arm's rows only
|
|
1397
|
+
* (`WHERE NOT` the marker), and `_a` is left out with `insertedOnly`;
|
|
1398
|
+
* - `<alias>_ia` (with `inserted` and `after`): the insert arm's after images
|
|
1399
|
+
* (`WHERE` the marker), so an upsert's after images arrive per arm.
|
|
1397
1400
|
*
|
|
1398
1401
|
* `before` / `after` name columns the step RETURNS (its
|
|
1399
1402
|
* {@link CaptureReturningColumn} aliases), in image order. `limit` is bound once.
|
|
@@ -1403,7 +1406,7 @@ export type ChainCapture = {
|
|
|
1403
1406
|
readonly alias: string;
|
|
1404
1407
|
/** The step's `"inserted"` arm-marker column, for an `INSERT … ON CONFLICT DO UPDATE` step. */
|
|
1405
1408
|
readonly inserted?: string;
|
|
1406
|
-
/** With `inserted`: images of inserted rows only —
|
|
1409
|
+
/** With `inserted`: images of inserted rows only — `<alias>_ia`, no `<alias>_a`. */
|
|
1407
1410
|
readonly insertedOnly?: true;
|
|
1408
1411
|
readonly before?: readonly string[];
|
|
1409
1412
|
readonly after?: readonly string[];
|
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:
|
|
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,
|
|
@@ -5596,8 +5618,12 @@ function captureAliases(params) {
|
|
|
5596
5618
|
out.push(`${entry.alias}_i`);
|
|
5597
5619
|
if (entry.before !== undefined && entry.before.length > 0)
|
|
5598
5620
|
out.push(`${entry.alias}_b`);
|
|
5599
|
-
if (entry.after !== undefined && entry.after.length > 0)
|
|
5600
|
-
|
|
5621
|
+
if (entry.after !== undefined && entry.after.length > 0) {
|
|
5622
|
+
if (entry.inserted === undefined || entry.insertedOnly !== true)
|
|
5623
|
+
out.push(`${entry.alias}_a`);
|
|
5624
|
+
if (entry.inserted !== undefined)
|
|
5625
|
+
out.push(`${entry.alias}_ia`);
|
|
5626
|
+
}
|
|
5601
5627
|
}
|
|
5602
5628
|
return out;
|
|
5603
5629
|
}
|
|
@@ -5622,10 +5648,13 @@ function renderChainCaptures(params) {
|
|
|
5622
5648
|
const limit = collector.add(entry.limit);
|
|
5623
5649
|
const item = quote("__vibe_i");
|
|
5624
5650
|
const image = (columns, filter) => `(SELECT array_agg(${item})::text FROM (SELECT DISTINCT ARRAY[${columns.map(quote).join(", ")}] AS ${item} FROM ${step}${filter} LIMIT ${limit}) AS ${quote("__vibe_d")})`;
|
|
5651
|
+
const updatedRows = marker === undefined ? "" : ` WHERE NOT ${marker}`;
|
|
5625
5652
|
if (before.length > 0)
|
|
5626
|
-
out.push(`${image(before,
|
|
5627
|
-
if (after.length > 0)
|
|
5628
|
-
out.push(`${image(after,
|
|
5653
|
+
out.push(`${image(before, updatedRows)} AS ${quote(`${entry.alias}_b`)}`);
|
|
5654
|
+
if (after.length > 0 && (marker === undefined || entry.insertedOnly !== true))
|
|
5655
|
+
out.push(`${image(after, updatedRows)} AS ${quote(`${entry.alias}_a`)}`);
|
|
5656
|
+
if (after.length > 0 && marker !== undefined)
|
|
5657
|
+
out.push(`${image(after, ` WHERE ${marker}`)} AS ${quote(`${entry.alias}_ia`)}`);
|
|
5629
5658
|
}
|
|
5630
5659
|
return out;
|
|
5631
5660
|
}
|
|
@@ -6580,4 +6609,4 @@ export {
|
|
|
6580
6609
|
toPgArrayLiteral
|
|
6581
6610
|
};
|
|
6582
6611
|
|
|
6583
|
-
//# debugId=
|
|
6612
|
+
//# debugId=D4C3C7B84AC363A964756E2164756E21
|