/** * SQLite connection factory for PD Runtime v2 state store. * * Opens (or creates) the workspace-level DB at `/.pd/state.db` * with WAL journal mode, 5-second busy timeout, and synchronous NORMAL. * Initializes the tasks and runs tables on first open. * * @example * const conn = new SqliteConnection('/path/to/workspace'); * const db = conn.getDb(); * // ... use db * conn.close(); */ import Database from 'better-sqlite3'; export interface SqliteConnectionOptions { workspaceDir: string; readonly?: boolean; /** Keep read-only access side-effect free when state.db has not been initialized. */ bootstrapIfMissing?: boolean; } export interface SqlitePragmaReport { journalMode: string; busyTimeout: number; synchronous: string; foreignKeys: boolean; healthy: boolean; issues: string[]; } export declare class SqliteConnection { private db; private readonly dbPath; private readonly readonlyMode; private readonly bootstrapIfMissing; /** * Schema initialization warnings collected during getDb(). Populated when initSchema() * or migrateSchema() fails (rc-9: no silent fallback — callers can read these warnings * to surface degraded state). Empty array means no warnings. */ private readonly schemaInitWarnings; constructor(workspaceDirOrOpts: string | SqliteConnectionOptions); /** * Returns warnings collected during schema initialization (rc-9: no silent fallback). * Empty if no warnings. Call after getDb() to inspect degraded schema state. */ getSchemaInitWarnings(): string[]; getDb(): Database.Database; /** * Derive workspaceDir from dbPath (used for readonly bootstrap). * dbPath is /.pd/state.db, so workspaceDir is two levels up. */ private workspaceDirFromDbPath; getPragmaReport(): SqlitePragmaReport; /** * Returns the current schema version of state.db. * Versions are stored as TEXT and compared lexicographically (e.g., '000' < '001'). * Returns '000' for fresh databases or if the table is somehow missing. */ getSchemaVersion(): string; /** * Records a new schema version after a migration is applied. * Each call inserts a new row (append-only history for audit). */ setSchemaVersion(version: string): void; private initSchema; private migrateSchema; /** Closes the underlying database connection. */ close(): void; } //# sourceMappingURL=sqlite-connection.d.ts.map