/** * SQLite-backed audit log. * * Alternative to the JSONL writer in `audit.ts` for deployments that want * queryable audit history. Supports indexed filters on `caller`, `photon`, * `timestamp` without scanning the file. * * Runtime-agnostic loader: uses `bun:sqlite` under Bun, `better-sqlite3` * under Node. Falls back to JSONL if neither is available. * * Row cap: deletes oldest rows when count exceeds `maxRows` (default 100k). * Cheaper than the JSONL rotate/delete dance and preserves query index * integrity automatically. */ import type { AuditEntry } from './audit.js'; import { type SqliteDatabase } from './sqlite-runtime.js'; export interface AuditQuery { /** Only rows at or after this timestamp. */ since?: Date; /** Only rows at or before this timestamp. */ until?: Date; /** Filter by photon name. */ photon?: string; /** Filter by authenticated caller (sub claim). */ client?: string; /** Filter by event type. */ event?: string; /** Max rows to return. Default 1000. */ limit?: number; /** Sort direction on timestamp. Default descending (most recent first). */ order?: 'asc' | 'desc'; } /** * Open a SQLite-backed audit store. Returns a backend with write/query/close. */ export declare function openAuditDatabase(path: string): Promise; export interface AuditBackend { write(entry: AuditEntry): void; query(q: AuditQuery): AuditEntry[]; count(): number; close(): void; } export declare class SqliteAuditBackend implements AuditBackend { private db; private maxRows; /** Check row count every N writes to avoid COUNT(*) per insert. */ private trimInterval; private insert; private countStmt; private trimStmt; private writes; /** Known columns we store in dedicated fields; anything else goes into `extra`. */ private static readonly WELL_KNOWN; constructor(db: SqliteDatabase, maxRows?: number, /** Check row count every N writes to avoid COUNT(*) per insert. */ trimInterval?: number); write(entry: AuditEntry): void; query(q?: AuditQuery): AuditEntry[]; count(): number; close(): void; private trimIfNeeded; } //# sourceMappingURL=audit-sqlite.d.ts.map