From 29908b77e304f2d1d0115822fa274c5e3c3787d3 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 28 May 2025 11:16:56 +0000 Subject: [PATCH] feat(types): add comprehensive type definitions for @jlongster/sql.js - Add FileSystem and FileStream interfaces for filesystem operations - Update Database interface with proper Promise-based return types - Add QueryExecResult interface for structured query results - Include FS and register_for_idb in initialization result - Fix Database constructor to support path and options parameters - Add proper JSDoc documentation with author and description This change resolves TypeScript compilation errors in AbsurdSqlDatabaseService by providing complete type coverage for the SQL.js WASM module with filesystem support. --- src/types/sql.js.d.ts | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/types/sql.js.d.ts diff --git a/src/types/sql.js.d.ts b/src/types/sql.js.d.ts new file mode 100644 index 00000000..ddee2828 --- /dev/null +++ b/src/types/sql.js.d.ts @@ -0,0 +1,57 @@ +/** + * Type definitions for @jlongster/sql.js + * @author Matthew Raymer + * @description TypeScript declaration file for the SQL.js WASM module with filesystem support + */ + +declare module '@jlongster/sql.js' { + export interface FileSystem { + mkdir(path: string): void; + mount(fs: any, opts: any, mountpoint: string): void; + open(path: string, flags: string): FileStream; + close(stream: FileStream): void; + } + + export interface FileStream { + node: { + contents: { + readIfFallback(): Promise; + }; + }; + } + + export interface Database { + exec(sql: string, params?: any[]): Promise; + prepare(sql: string): Statement; + run(sql: string, params?: any[]): Promise<{ changes: number; lastId?: number }>; + close(): void; + } + + export interface QueryExecResult { + columns: string[]; + values: any[][]; + } + + export interface Statement { + bind(params: any[]): void; + step(): boolean; + get(): any[]; + getColumnNames(): string[]; + reset(): void; + free(): void; + } + + export interface InitSqlJsStatic { + (config?: { + locateFile?: (file: string) => string; + wasmBinary?: ArrayBuffer; + }): Promise<{ + Database: new (path?: string | Uint8Array, opts?: { filename?: boolean }) => Database; + FS: FileSystem; + register_for_idb: (fs: any) => void; + }>; + } + + const initSqlJs: InitSqlJsStatic; + export default initSqlJs; +} \ No newline at end of file