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