bazis 0.140.1 → 0.140.2
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.
|
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
|
|
|
232
232
|
if (method === "account/updated") this.modelCache = undefined;
|
|
233
233
|
}, () => { this.clearLogin(); this.modelCache = undefined; });
|
|
234
234
|
const initialized = await client.request("initialize", {
|
|
235
|
-
clientInfo: { name: "bazis", title: "Bazis", version: "0.140.
|
|
235
|
+
clientInfo: { name: "bazis", title: "Bazis", version: "0.140.2" }, capabilities: { experimentalApi: true },
|
|
236
236
|
}, 15_000, signal);
|
|
237
237
|
if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
|
|
238
238
|
client.notify("initialized");
|
|
@@ -4,6 +4,7 @@ import { projectCheckAstIdentifiers, renderCheck } from "../Schema/CheckExpressi
|
|
|
4
4
|
import { resolvedForeignKey } from "./resolvedForeignKey";
|
|
5
5
|
import { physicalTableIdentity, primaryKeyName } from "../Schema/tableKey";
|
|
6
6
|
import { decimalParameter } from "./decimalValue";
|
|
7
|
+
import { integerParameter } from "./integerValue";
|
|
7
8
|
|
|
8
9
|
const jsonScalarParameters = new WeakSet<object>();
|
|
9
10
|
|
|
@@ -54,6 +55,7 @@ export class PostgresDialect implements SqlDialect {
|
|
|
54
55
|
// Pre-serializing them would store JSON text as another JSON string.
|
|
55
56
|
return value as SqlParam;
|
|
56
57
|
case "integer":
|
|
58
|
+
return integerParameter(value);
|
|
57
59
|
case "real":
|
|
58
60
|
return typeof value === "bigint" ? value : Number(value);
|
|
59
61
|
case "decimal":
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const INTEGER_TEXT = /^[+-]?\d{1,40}$/u;
|
|
2
|
+
const INT8_MIN = -(2n ** 63n);
|
|
3
|
+
const INT8_MAX = 2n ** 63n - 1n;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The parameter for an integer column (`bigint` in PostgreSQL). A JavaScript
|
|
7
|
+
* number is a double: sent as one, an integer beyond 2^53 makes the database
|
|
8
|
+
* turn the column into doubles too, and `id = "1234567890123456789"` finds the
|
|
9
|
+
* neighbouring row as well. So an integer written as a string, and a whole
|
|
10
|
+
* number of that size, go as a `bigint` and are compared exactly.
|
|
11
|
+
*
|
|
12
|
+
* Anything else — a fraction, a value outside `bigint` — goes as a number, as
|
|
13
|
+
* before: the database compares it as a double or refuses it.
|
|
14
|
+
*/
|
|
15
|
+
export function integerParameter(value: unknown): number | bigint {
|
|
16
|
+
if (typeof value === "bigint") return value;
|
|
17
|
+
if (typeof value === "string") {
|
|
18
|
+
const text = value.trim();
|
|
19
|
+
return INTEGER_TEXT.test(text) ? exact(BigInt(text), Number(text)) : Number(value);
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) return exact(BigInt(value), value);
|
|
22
|
+
return Number(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A number while it holds the integer exactly, a `bigint` while the column can hold it, the double otherwise. */
|
|
26
|
+
function exact(integer: bigint, double: number): number | bigint {
|
|
27
|
+
if (Number.isSafeInteger(double)) return double;
|
|
28
|
+
return integer >= INT8_MIN && integer <= INT8_MAX ? integer : double;
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bazis",
|
|
3
|
-
"version": "0.140.
|
|
3
|
+
"version": "0.140.2",
|
|
4
4
|
"description": "Modular backend framework for Bun in TypeScript: DI wired by codegen, HTTP, a PostgreSQL ORM, JWT, WebSocket, agents and a CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexander Alenin",
|