From 13682a1930f879c8b23648bc07537cf28fbba828 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 28 May 2025 06:21:20 +0000 Subject: [PATCH] fix(db): add type declarations for SQL.js and absurd-sql modules - Create type declarations in interfaces/absurd-sql.d.ts - Import and use proper QueryExecResult and SqlValue types - Add declarations for all required modules: - @jlongster/sql.js - absurd-sql - absurd-sql/dist/indexeddb-backend - absurd-sql/dist/indexeddb-main-thread - Ensure type safety for database operations This change resolves TypeScript errors about missing type declarations while maintaining proper type safety for database operations. The declarations are placed in the interfaces folder to match the project's type organization. --- src/interfaces/absurd-sql.d.ts | 23 ++++++------- src/types/absurd-sql.d.ts | 62 ---------------------------------- 2 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 src/types/absurd-sql.d.ts diff --git a/src/interfaces/absurd-sql.d.ts b/src/interfaces/absurd-sql.d.ts index d2b1969d..e113fe75 100644 --- a/src/interfaces/absurd-sql.d.ts +++ b/src/interfaces/absurd-sql.d.ts @@ -1,4 +1,4 @@ -import type { QueryExecResult as DbQueryExecResult, SqlValue } from "@/interfaces/database"; +import type { QueryExecResult, SqlValue } from "./database"; declare module "@jlongster/sql.js" { interface SQL { @@ -13,25 +13,22 @@ declare module "@jlongster/sql.js" { } interface AbsurdSqlDatabase { - exec: (sql: string, params?: unknown[]) => Promise; + exec: (sql: string, params?: SqlValue[]) => Promise; run: ( sql: string, - params?: unknown[], + params?: SqlValue[], ) => Promise<{ changes: number; lastId?: number }>; } - interface QueryExecResult { - columns: string[]; - values: unknown[][]; - } - - export default function initSqlJs(options?: { + const initSqlJs: (options?: { locateFile?: (file: string) => string; - }): Promise; + }) => Promise; + + export default initSqlJs; } declare module "absurd-sql" { - import { SQL } from "@jlongster/sql.js"; + import type { SQL } from "@jlongster/sql.js"; export class SQLiteFS { constructor(fs: any, backend: any); @@ -44,7 +41,7 @@ declare module "absurd-sql/dist/indexeddb-backend" { } } -declare module 'absurd-sql/dist/indexeddb-main-thread' { +declare module "absurd-sql/dist/indexeddb-main-thread" { export interface SQLiteOptions { filename?: string; autoLoad?: boolean; @@ -52,7 +49,7 @@ declare module 'absurd-sql/dist/indexeddb-main-thread' { } export interface SQLiteDatabase { - exec: (sql: string, params?: any[]) => Promise; + exec: (sql: string, params?: SqlValue[]) => Promise; close: () => Promise; } diff --git a/src/types/absurd-sql.d.ts b/src/types/absurd-sql.d.ts deleted file mode 100644 index 0d0ce697..00000000 --- a/src/types/absurd-sql.d.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { QueryExecResult as DbQueryExecResult, SqlValue } from "../database"; - -declare module "@jlongster/sql.js" { - interface SQL { - Database: new (path: string, options?: { filename: boolean }) => AbsurdSqlDatabase; - FS: { - mkdir: (path: string) => void; - mount: (fs: any, options: any, path: string) => void; - open: (path: string, flags: string) => any; - close: (stream: any) => void; - }; - register_for_idb: (fs: any) => void; - } - - interface AbsurdSqlDatabase { - exec: (sql: string, params?: unknown[]) => Promise; - run: ( - sql: string, - params?: unknown[], - ) => Promise<{ changes: number; lastId?: number }>; - } - - interface QueryExecResult { - columns: string[]; - values: unknown[][]; - } - - export default function initSqlJs(options?: { - locateFile?: (file: string) => string; - }): Promise; -} - -declare module "absurd-sql" { - import { SQL } from "@jlongster/sql.js"; - - export class SQLiteFS { - constructor(fs: any, backend: any); - } -} - -declare module "absurd-sql/dist/indexeddb-backend" { - export default class IndexedDBBackend { - constructor(); - } -} - -declare module 'absurd-sql/dist/indexeddb-main-thread' { - export interface SQLiteOptions { - filename?: string; - autoLoad?: boolean; - debug?: boolean; - } - - export interface SQLiteDatabase { - exec: (sql: string, params?: any[]) => Promise; - close: () => Promise; - } - - export function initSqlJs(options?: any): Promise; - export function createDatabase(options?: SQLiteOptions): Promise; - export function openDatabase(options?: SQLiteOptions): Promise; -} \ No newline at end of file