export interface CompatStatement { run(...params: any[]): { changes: number; lastInsertRowid: number | bigint; }; get(...params: any[]): any; all(...params: any[]): any[]; } export interface CompatDatabase { prepare(sql: string): CompatStatement; exec(sql: string): this; pragma(source: string, options?: any): any; transaction(fn: () => T): () => T; close(): void; /** * #171: atomic in-memory serialization of the DB image (wasm driver). Present * on the wasm adapter; better-sqlite3 also exposes a compatible `serialize()`. * Used by `snapshotToFile` for a tear-proof backup snapshot. */ serialize?(): Uint8Array; } export type SqliteDriver = "native" | "wasm"; /** * Write a consistent point-in-time snapshot of `db` to `destPath`, driver-aware. * - native: `VACUUM INTO` — a live-consistent online copy, safe even while the * daemon writes. * - wasm: serialize the in-memory image atomically (`serialize()` → sql.js * `.export()`) and write the bytes. TEAR-PROOF regardless of caller. A plain * copy of the write-back file would NOT be: the wasm flush is a bare * `fs.writeFileSync` (no temp-and-rename, no lock), so a concurrent reader can * observe it half-written — and a torn backup fails silently at restore. * * Branches on the ACTUAL db object handed in (`db instanceof WasmDatabase`), the * truest read-the-state: no env, no global, no captured driver that could go * stale — just the live connection. This also sidesteps the getActiveDriver() * gap where db.getDb()'s synchronous native fallback sets db.ts `_db` directly * and never registers a driver (#190 r2): the object itself is unambiguous. */ export declare function snapshotToFile(db: CompatDatabase, destPath: string): void; /** * Open an EXISTING SQLite file read-only, driver-aware. Backs the backup manifest * row-count read and the restore `PRAGMA integrity_check` — so both work under * the wasm driver, where the native better-sqlite3 binary is absent (the exact * npm-12 scripts-off scenario the wasm driver works around). * - native: better-sqlite3 `{ readonly: true }`. * - wasm: load the file bytes into a fresh sql.js instance. (Probe-only; close() * re-writes the identical bytes, which is a harmless no-op on a temp file.) * * The `driver` is an EXPLICIT PARAMETER, never inferred (#190 r3 ruling). Restore * deliberately closes the live DB before probing the archive, so there is NO live * state to read in that window — "read the state" has no answer once the state is * destroyed on purpose. The caller captures the driver identity WHILE the * connection is live (driverOf(db)) and passes it, or uses configuredDriver() in * the truly-fresh no-connection path. You cannot call this without having decided * — the same make-impossible property as keeping getDriverType private. Opens the * GIVEN file; does NOT create or init the main DB, so validating a corrupt archive * manufactures no state. */ export declare function openReadOnly(dbPath: string, driver: SqliteDriver): Promise; /** * Initialize the database. Must be called once at process startup (before * any getDb() call). For native: sync under the hood. For wasm: loads the * wasm binary async. Thread-safe: concurrent callers share the same promise. */ export declare function initializeDb(dbPath: string): Promise; /** * Get the initialized database handle. Throws if initializeDb() has not * been called yet. This is the sync access point all of src/db.ts uses. */ export declare function getInitializedDb(): CompatDatabase | null; export declare function getActiveDriver(): SqliteDriver | null; /** * The driver of an OPEN connection, read from the object itself — the truest * state, no global, no env, no tracker that can go stale. Used to capture the * driver identity WHILE a connection is live, to hand to openReadOnly (which * never infers). #190 r3. */ export declare function driverOf(db: CompatDatabase): SqliteDriver; /** * The CONFIGURED driver for a COLD open — the ONLY legitimate read of the * requested env: when there is NO live connection to read (a first-ever restore * probing an archive before any DB is initialized). Here the request IS the * reality: it is the driver the process will instantiate. NEVER use this where a * live connection exists — use driverOf(db) there. #190 r3. */ export declare function configuredDriver(): SqliteDriver; /** * Close and clear the initialized DB (for test cleanup). */ export declare function closeInitializedDb(): void; //# sourceMappingURL=sqlite-compat.d.ts.map