fix(api): сохранять большие идентификаторы серверов без округления

This commit is contained in:
Denozordec committed 2026-10-11 23:39:02 +07:00
1 parent 90e6c7be25
commit d3d8afaa0c
13 files changed
+1086 -19

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
import assert from "node:assert/strict"
import { parseDbServerId } from "./server-id.js"
for (const id of [1, "1", "001", " 1 ", 2147483648, "2147483648", Number.MAX_SAFE_INTEGER, String(Number.MAX_SAFE_INTEGER)]) assert.equal(parseDbServerId(id), Number(id))
for (const id of [undefined, null, false, {}, "", "srv1", "1abc", "1.5", "1e3", "-1", "0", NaN, Infinity, "9007199254740992", "9007199254740993", 9007199254740992, "9223372036854775807"]) assert.equal(parseDbServerId(id), null)
console.log("server-id: bigint/safe integer IDs preserved; malformed and unsafe IDs rejected without rounding")
+1 -1
View File
@@ -6,5 +6,5 @@ export function parseDbServerId(raw: unknown): number | null {
const s = String(raw ?? "").trim()
if (!/^\d+$/.test(s)) return null
const n = Number.parseInt(s, 10)
return Number.isFinite(n) && n >= 1 ? n : null
return Number.isSafeInteger(n) && n >= 1 ? n : null
}