Files
orca/src/main/sqlite/sqlite-integer-reader.ts
T
OrcaWin 6fc3cdcad6 Bundle Bun for headless Orca and profile persistence (#22635)
Bundle a pinned, verified Bun runtime for headless Orca so existing Node launch commands can hand off before opening a profile. Keep desktop execution on Electron.

Add the Bun SQLite adapter and terminal backend, bounded shutdown, process inspection and cross-platform artifact qualification. Keep future managed SSH deployment separate from current production launch paths.
2026-09-25 22:49:06 -07:00

41 lines
1.1 KiB
TypeScript

import type { StatementResultingChanges } from 'node:sqlite'
import type { SqliteRow } from './sqlite-statement'
export class SqliteIntegerReader {
readBigInts = false
row(row: SqliteRow): SqliteRow {
if (!this.readBigInts) {
for (const key of Object.keys(row)) {
const value = row[key]
if (typeof value === 'bigint') {
row[key] = this.integer(value)
}
}
}
return row
}
result(result: StatementResultingChanges): StatementResultingChanges {
return {
changes: this.integer(result.changes, false),
lastInsertRowid: this.integer(result.lastInsertRowid, false)
}
}
private integer(value: number | bigint, requireSafeNumber = true): number | bigint {
if (this.readBigInts) {
return BigInt(value)
}
const number = Number(value)
if (!Number.isSafeInteger(number)) {
// Metadata conversion must not report failure after a write has committed.
if (!requireSafeNumber) {
return BigInt(value)
}
throw new RangeError('SQLite integer cannot be represented safely as a JavaScript number')
}
return number
}
}