/** * Data preparation helpers for the DashboardStore write queue. * * These functions transform in-memory records into SQLite-ready row * objects. They are pure (no I/O, no Knex dependency) so they can * be tested in isolation. */ import { sanitizeBindings } from './sensitive_patterns.js'; import type { EventRecord, EmailRecord } from '../debug/types.js'; import type { PersistRequestInput } from './dashboard_types.js'; import type { Knex } from 'knex'; export declare function hasWarned(path: string): boolean; export declare function markWarned(path: string): void; /** * Forget which write paths have warned. Called when a DashboardStore stops so * a re-initialized store in the same process warns afresh instead of * inheriting a spent latch from its predecessor. */ export declare function resetWriteWarnings(): void; /** * Normalize a SQL query by replacing literal values with `?` placeholders. * Used for grouping identical query patterns. * * Numeric replacement is restricted to value contexts (a digit run preceded * by whitespace, a comma, a paren, or an operator) so identifiers that contain * digits — e.g. `orders_2024` — are left intact and distinct queries are not * merged together. */ export declare function normalizeSql(sql: string): string; export { sanitizeBindings }; export interface PreparedQuery { sql_text: string; sql_normalized: string; bindings: string | null; duration: number; method: string; model: string | null; connection: string; in_transaction: number; } export interface PreparedTraceRow { method: string; url: string; status_code: number; total_duration: number; span_count: number; spans: string; warnings: string | null; } export interface PreparedRequest { input: PersistRequestInput; filteredQueries: PreparedQuery[]; traceRow: PreparedTraceRow | null; eventRows: EventRow[]; } export interface PreparedLog { [key: string]: unknown; level: string; message: string; request_id: string | null; data: string; } export interface EmailRow { [key: string]: unknown; from_addr: string; to_addr: string; cc: string | null; bcc: string | null; subject: string; html: string | null; text_body: string | null; mailer: string; status: string; message_id: string | null; attachment_count: number; } export interface EventRow { [key: string]: unknown; event_name: string; data: string | null; } /** * Pre-stringify and transform request inputs into SQLite-ready row objects. * This is done OUTSIDE the transaction so the synchronous better-sqlite3 * execution does not block the event loop on large spans. */ export declare function prepareRequestRows(requests: PersistRequestInput[]): PreparedRequest[]; /** * Transform raw log entries into SQLite-ready row objects. * * The full pino record lands in `data`, and log lines routinely carry bound * request context — authorization headers, cookies, tokens in payloads — so * the record is run through the shared redaction rules (secret-named keys and * credential-shaped values) before it is stringified. The `message` column is * kept verbatim: it is free text, and the shape rules are anchored to whole * values, so prose stays readable. */ export declare function prepareLogRows(logs: Record[]): PreparedLog[]; /** * Transform an EmailRecord into a SQLite-ready row object. */ export declare function buildEmailRow(record: EmailRecord): EmailRow; /** * Transform EventRecords into SQLite-ready row objects. */ /** * Build event rows. `request_id` is attached at insert time, once the owning * request row has an id — leaving it null here (as this did previously) meant * retention never reclaimed them, since events are only pruned via the * `server_stats_requests` foreign-key cascade. */ export declare function buildEventRows(events: EventRecord[]): EventRow[]; /** * Insert rows into a table in batches of 50. * * Yields to the event loop between chunks: better-sqlite3 is fully * synchronous, so without a real macrotask hop a large batch would execute * back-to-back on microtask continuations and stall the host app — the exact * failure mode `migrator_tables.ts` documents and guards against. */ export declare function batchInsert(trx: Knex.Transaction, table: string, rows: Record[]): Promise; export declare function flushRequests(trx: Knex.Transaction, preparedRequests: PreparedRequest[]): Promise; /** * Flush pending emails into the database. */ export declare function flushEmails(trx: Knex.Transaction, emails: EmailRecord[]): Promise; /** * Flush prepared logs into the database. */ export declare function flushLogs(trx: Knex.Transaction, preparedLogs: PreparedLog[]): Promise;