From b28283bf347cc3d5630a2704b3a646ea86fc241c Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 31 Jan 2026 12:08:23 -0500 Subject: [PATCH] Fix db types --- src/db.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/db.ts b/src/db.ts index 458e2b8..c19eecb 100644 --- a/src/db.ts +++ b/src/db.ts @@ -3,6 +3,17 @@ import { Database } from "bun:sqlite"; import type { Device, OutputLog, PromptData, Session } from "./types"; +// Raw row returned from SQLite before JSON parsing +interface RawPromptRow { + id: number; + session_id: number; + created_at: number; + prompt_text: string; + response: string | null; + responded_at: number | null; + prompt_json: string | null; +} + // Extend Prompt interface to include prompt_json field export interface Prompt { id: number; @@ -58,9 +69,12 @@ function runMigrations(): void { for (const migration of migrations) { try { db.exec(migration); - } catch (error: any) { + } catch (error: unknown) { // Ignore "duplicate column" errors - column already exists - if (!error.message?.includes("duplicate column")) { + if ( + !(error instanceof Error) || + !error.message?.includes("duplicate column") + ) { throw error; } } @@ -221,7 +235,7 @@ export function createPrompt( promptText, promptJson ?? null, ); - const prompt = row as any; + const prompt = row as RawPromptRow; // Parse prompt_json if present if (prompt.prompt_json) { @@ -239,7 +253,7 @@ export function getPrompt(promptId: number): Prompt | null { const row = getPromptStmt.get(promptId); if (!row) return null; - const prompt = row as any; + const prompt = row as RawPromptRow; // Parse prompt_json if present if (prompt.prompt_json) { @@ -258,9 +272,9 @@ export function respondToPrompt(promptId: number, response: string): void { } export function getPendingPrompts(): Prompt[] { - const rows = getPendingPromptsStmt.all(); + const rows = getPendingPromptsStmt.all() as RawPromptRow[]; - return rows.map((row: any) => { + return rows.map((row) => { // Parse prompt_json if present if (row.prompt_json) { try {