Browse Source

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.
pull/137/head
Matthew Raymer 1 week ago
parent
commit
13682a1930
  1. 23
      src/interfaces/absurd-sql.d.ts
  2. 62
      src/types/absurd-sql.d.ts

23
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<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>;
}

62
src/types/absurd-sql.d.ts

@ -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<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;
autoLoad?: boolean;
debug?: boolean;
}
export interface SQLiteDatabase {
exec: (sql: string, params?: any[]) => Promise<any>;
close: () => Promise<void>;
}
export function initSqlJs(options?: any): Promise<any>;
export function createDatabase(options?: SQLiteOptions): Promise<SQLiteDatabase>;
export function openDatabase(options?: SQLiteOptions): Promise<SQLiteDatabase>;
}
Loading…
Cancel
Save