/** * Node-compatible SQLite storage adapter using `better-sqlite3`. * * Implements the same `Storage` interface and SQL schema as `BunSQLiteStorage` * but uses `better-sqlite3` instead of `bun:sqlite`, enabling the same * storage layer to run on Node.js 22+. * * `better-sqlite3` is a peer dependency — it must be installed separately by * consumers who import `@lostgradient/weft/storage/sqlite/node`. * * @module storage/node-sqlite */ import type { BatchOperation, ConditionalBatchCondition, ScanOptions, Storage, StorageCapabilities } from './interface.ts'; import { type BetterSqliteConstructor } from './node-sqlite-loader.ts'; /** * Runtime-neutral alias for the Node SQLite adapter. Consumers that import * from `@lostgradient/weft/storage/sqlite` get this class under Node. */ export { NodeSQLiteStorage as SQLiteStorage }; /** * SQLite-backed {@link Storage} using `better-sqlite3` for Node.js 22+ * environments. * * Implements the same WAL-mode schema as {@link BunSQLiteStorage} * but resolves the `better-sqlite3` peer dependency lazily at construction time, * so the module compiles without it installed. Import from * `@lostgradient/weft/storage/sqlite/node` to use this adapter. * * Unlike BunSQLiteStorage, this adapter currently implements only the required * Storage methods (`get`, `put`, `delete`, `scan`, `batch`, and * `conditionalBatch`). The optional `has`, `keys`, `count`, `deletePrefix`, and * `scoped` helpers fall back to the generic implementations in * `@lostgradient/weft/storage/interface`; `deleteRange` falls back to `storageDeleteRange` * (exported from `@lostgradient/weft` / `@lostgradient/weft/storage`). There is no SQL passthrough * `query()` method. * * @example * ```ts * import { NodeSQLiteStorage } from '@lostgradient/weft/storage/sqlite/node'; * import { workflow, Engine } from '@lostgradient/weft'; * * // Requires: bun add better-sqlite3 * await using storage = new NodeSQLiteStorage('./weft.db'); * await using engine = new Engine({ storage }); * * engine.register(workflow({ name: 'ping' }).execute(async function* () { return 'pong'; })); * const handle = await engine.start('ping', null); * console.log(await handle.result()); // 'pong' * ``` */ export declare class NodeSQLiteStorage implements Storage { #private; /** * Number of distinct prepared-statement cache entries for scan(). * Exposed for regression tests that assert the cache stays bounded. */ get scanStatementCacheSize(): number; capabilities(): StorageCapabilities; constructor(path?: string, databaseConstructor?: BetterSqliteConstructor); get(key: string): Promise; put(key: string, value: Uint8Array): Promise; delete(key: string): Promise; scan(prefix: string, options?: ScanOptions): AsyncIterable<[string, Uint8Array]>; batch(operations: BatchOperation[]): Promise; conditionalBatch(conditions: ConditionalBatchCondition[], operations: BatchOperation[]): Promise; [Symbol.dispose](): void; }