forked from trent_larson/crowd-funder-for-time-pwa
WIP: fix(AbsurdSqlDatabaseService) fixes to typing and other curious beasts
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
// @ts-expect-error but not sure why it's not in there
|
|
||||||
import { initBackend } from "absurd-sql/dist/indexeddb-main-thread";
|
import { initBackend } from "absurd-sql/dist/indexeddb-main-thread";
|
||||||
import { initializeApp } from "./main.common";
|
import { initializeApp } from "./main.common";
|
||||||
|
|
||||||
|
|||||||
45
src/types/absurd-sql.d.ts
vendored
Normal file
45
src/types/absurd-sql.d.ts
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
declare module 'absurd-sql/dist/indexeddb-backend' {
|
||||||
|
export default class IndexedDBBackend {
|
||||||
|
constructor(options?: {
|
||||||
|
dbName?: string;
|
||||||
|
storeName?: string;
|
||||||
|
onReady?: () => void;
|
||||||
|
onError?: (error: Error) => void;
|
||||||
|
});
|
||||||
|
init(): Promise<void>;
|
||||||
|
exec(sql: string, params?: any[]): Promise<any>;
|
||||||
|
close(): Promise<void>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'absurd-sql/dist/indexeddb-main-thread' {
|
||||||
|
export function initBackend(worker: Worker): Promise<void>;
|
||||||
|
|
||||||
|
export default class IndexedDBMainThread {
|
||||||
|
constructor(options?: {
|
||||||
|
dbName?: string;
|
||||||
|
storeName?: string;
|
||||||
|
onReady?: () => void;
|
||||||
|
onError?: (error: Error) => void;
|
||||||
|
});
|
||||||
|
init(): Promise<void>;
|
||||||
|
exec(sql: string, params?: any[]): Promise<any>;
|
||||||
|
close(): Promise<void>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'absurd-sql' {
|
||||||
|
export class SQLiteFS {
|
||||||
|
constructor(fs: unknown, backend: IndexedDBBackend);
|
||||||
|
init(): Promise<void>;
|
||||||
|
close(): Promise<void>;
|
||||||
|
exec(sql: string, params?: any[]): Promise<any>;
|
||||||
|
prepare(sql: string): Promise<any>;
|
||||||
|
run(sql: string, params?: any[]): Promise<any>;
|
||||||
|
get(sql: string, params?: any[]): Promise<any>;
|
||||||
|
all(sql: string, params?: any[]): Promise<any[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export * from 'absurd-sql/dist/indexeddb-backend';
|
||||||
|
export * from 'absurd-sql/dist/indexeddb-main-thread';
|
||||||
|
}
|
||||||
36
src/types/global.d.ts
vendored
Normal file
36
src/types/global.d.ts
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import type { QueryExecResult, SqlValue } from "./database";
|
||||||
|
|
||||||
|
declare module '@jlongster/sql.js' {
|
||||||
|
interface SQL {
|
||||||
|
Database: new (path: string, options?: { filename: boolean }) => Database;
|
||||||
|
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 Database {
|
||||||
|
exec: (sql: string, params?: unknown[]) => Promise<QueryExecResult[]>;
|
||||||
|
run: (sql: string, params?: unknown[]) => Promise<{ changes: number; lastId?: number }>;
|
||||||
|
get: (sql: string, params?: unknown[]) => Promise<SqlValue[]>;
|
||||||
|
all: (sql: string, params?: unknown[]) => Promise<SqlValue[][]>;
|
||||||
|
prepare: (sql: string) => Promise<Statement>;
|
||||||
|
close: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Statement {
|
||||||
|
run: (params?: unknown[]) => Promise<{ changes: number; lastId?: number }>;
|
||||||
|
get: (params?: unknown[]) => Promise<SqlValue[]>;
|
||||||
|
all: (params?: unknown[]) => Promise<SqlValue[][]>;
|
||||||
|
finalize: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initSqlJs: (options?: {
|
||||||
|
locateFile?: (file: string) => string;
|
||||||
|
}) => Promise<SQL>;
|
||||||
|
|
||||||
|
export default initSqlJs;
|
||||||
|
}
|
||||||
67
src/types/modules.d.ts
vendored
Normal file
67
src/types/modules.d.ts
vendored
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import type { QueryExecResult, SqlValue } from "./database";
|
||||||
|
|
||||||
|
declare module '@jlongster/sql.js' {
|
||||||
|
interface SQL {
|
||||||
|
Database: new (path: string, options?: { filename: boolean }) => Database;
|
||||||
|
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 Database {
|
||||||
|
exec: (sql: string, params?: unknown[]) => Promise<QueryExecResult[]>;
|
||||||
|
run: (sql: string, params?: unknown[]) => Promise<{ changes: number; lastId?: number }>;
|
||||||
|
get: (sql: string, params?: unknown[]) => Promise<SqlValue[]>;
|
||||||
|
all: (sql: string, params?: unknown[]) => Promise<SqlValue[][]>;
|
||||||
|
prepare: (sql: string) => Promise<Statement>;
|
||||||
|
close: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Statement {
|
||||||
|
run: (params?: unknown[]) => Promise<{ changes: number; lastId?: number }>;
|
||||||
|
get: (params?: unknown[]) => Promise<SqlValue[]>;
|
||||||
|
all: (params?: unknown[]) => Promise<SqlValue[][]>;
|
||||||
|
finalize: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initSqlJs: (options?: {
|
||||||
|
locateFile?: (file: string) => string;
|
||||||
|
}) => Promise<SQL>;
|
||||||
|
|
||||||
|
export default initSqlJs;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'absurd-sql' {
|
||||||
|
import type { 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' {
|
||||||
|
import type { QueryExecResult } from './database';
|
||||||
|
export interface SQLiteOptions {
|
||||||
|
filename?: string;
|
||||||
|
autoLoad?: boolean;
|
||||||
|
debug?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SQLiteDatabase {
|
||||||
|
exec: (sql: string, params?: unknown[]) => Promise<QueryExecResult[]>;
|
||||||
|
close: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initSqlJs(options?: any): Promise<any>;
|
||||||
|
export function createDatabase(options?: SQLiteOptions): Promise<SQLiteDatabase>;
|
||||||
|
export function openDatabase(options?: SQLiteOptions): Promise<SQLiteDatabase>;
|
||||||
|
}
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
"types": ["vite/client"],
|
"types": ["vite/client"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
}
|
},
|
||||||
|
"typeRoots": ["./node_modules/@types", "./src/types"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts",
|
"src/**/*.ts",
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
}
|
},
|
||||||
|
"typeRoots": ["./node_modules/@types", "./src/types"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts",
|
"src/**/*.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user