forked from jsnbuchanan/crowd-funder-for-time-pwa
fix(db): improve type safety in AbsurdSqlDatabaseService
- Move external module type declarations to dedicated .d.ts file - Make SQL.js types compatible with our database interface - Fix type compatibility between operation queue and database results - Add proper typing for database operations and results This change improves type safety by: 1. Properly declaring types for external modules 2. Ensuring database operation results match our interface 3. Making the operation queue type-safe with generics 4. Removing duplicate type definitions The remaining module resolution warnings can be safely ignored as they don't affect runtime behavior and our type declarations are working.
This commit is contained in:
46
src/types/absurd-sql.d.ts
vendored
46
src/types/absurd-sql.d.ts
vendored
@@ -1,3 +1,49 @@
|
||||
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<DbQueryExecResult[]>;
|
||||
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<SQL>;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user