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.
This commit is contained in:
Matthew Raymer
2025-05-28 06:21:20 +00:00
parent 7cab40f7f2
commit 7ff9ef04ae
2 changed files with 10 additions and 75 deletions

View File

@@ -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<DbQueryExecResult[]>;
exec: (sql: string, params?: SqlValue[]) => Promise<QueryExecResult[]>;
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<SQL>;
}) => Promise<SQL>;
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<any>;
exec: (sql: string, params?: SqlValue[]) => Promise<QueryExecResult[]>;
close: () => Promise<void>;
}