/** * Lazy loader for the optional `better-sqlite3` peer dependency used by * {@link NodeSQLiteStorage}. Kept in its own module — and deliberately NOT in the * package `exports` map — so the test-only injection seam * ({@link loadBetterSqlite3ForTest}) never becomes part of the documented public * surface. `node-sqlite.ts` imports `loadBetterSqlite3` (production path); * `node-sqlite.test.ts` imports the test entry directly from here. * * @module storage/node-sqlite-loader */ /** * Minimal `better-sqlite3` `Database` surface this adapter uses. Defined here so * both the loader and the storage module compile without the package installed. */ export type BetterSqliteStatement = { run(...parameters: unknown[]): unknown; get(...parameters: unknown[]): Record | undefined; all(...parameters: unknown[]): Record[]; }; export type BetterSqliteTransaction = (...args: unknown[]) => unknown; export type BetterSqliteDatabase = { pragma(source: string): unknown; exec(source: string): void; prepare(source: string): BetterSqliteStatement; transaction(fn: (...args: TArguments) => TResult): BetterSqliteTransaction; close(): void; }; export type BetterSqliteConstructor = new (path: string) => BetterSqliteDatabase; /** * Build the actionable error thrown when `better-sqlite3` cannot be loaded — * either because the optional dependency is absent or its native binding fails * to dlopen. */ export declare function createMissingBetterSqlite3Error(cause: unknown): Error; /** * Whether `error` is a recognizable `better-sqlite3` load failure (missing * package or native-binding dlopen failure) worth reshaping into the actionable * peer-dependency error rather than re-throwing raw. */ export declare function isBetterSqlite3LoadFailure(error: unknown): boolean; /** * Resolve the `better-sqlite3` module via a CommonJS require. This package is * ESM (`type: module`), so the global `require` is not defined — `createRequire` * from `node:module` builds a CommonJS require for loading the native binding. * * Extracted as a standalone function so tests can inject a throwing resolver * (see {@link loadBetterSqlite3ForTest}) to exercise the missing/failed-dependency * paths WITHOUT `mock.module('node:module', ...)`. That mock is irreversible in * Bun: it patches the CJS loader process-wide and `mock.restore()` does not undo * it, which poisons `require()` for every later test in the same process * (notably any WASM module that requires a core module during boot). */ declare function resolveBetterSqlite3Module(): { default?: BetterSqliteConstructor; } & BetterSqliteConstructor; /** Resolver for the `better-sqlite3` module. Injectable for tests. */ type BetterSqlite3ModuleResolver = typeof resolveBetterSqlite3Module; /** * Load (and cache) the `better-sqlite3` constructor. Reshapes a recognized load * failure into the actionable peer-dependency error. */ export declare function loadBetterSqlite3(resolveModule?: BetterSqlite3ModuleResolver): BetterSqliteConstructor; /** * Test-only entry that exercises {@link loadBetterSqlite3}'s module-resolution * and error-shaping with an injected resolver, bypassing the cached constructor * so the missing/failed-dependency paths run every call. This lets those paths be * tested without mocking the global `node:module` loader. Lives in this * non-exported module so it never reaches the public package surface. */ export declare function loadBetterSqlite3ForTest(resolveModule: BetterSqlite3ModuleResolver): BetterSqliteConstructor; export {};