types.ts (1433B)
1 import type { IdbClientConfig, ResolveError } from "@radroots/utils"; 2 import type { SqlValue } from "sql.js"; 3 import type { BackupSqlPayload } from "../backup/types.js"; 4 5 export type SqlJsExecOutcome = { 6 changes: number; 7 last_insert_id: number; 8 }; 9 10 export type SqlJsResultRow = Record<string, unknown>; 11 12 export type SqlJsMigrationRow = { 13 id: number; 14 name: string; 15 applied_at: string; 16 }; 17 18 export type SqlJsMigrationState = { 19 applied_names: string[]; 20 applied_count: number; 21 }; 22 23 export type SqlJsValue = SqlValue; 24 25 export type SqlJsParams = Readonly<Record<string, SqlJsValue>> | ReadonlyArray<SqlJsValue>; 26 27 export type WebSqlEngineConfig = { 28 store_key: string; 29 idb_config: IdbClientConfig; 30 cipher_config?: IdbClientConfig | null; 31 sql_wasm_path?: string; 32 }; 33 34 export interface IClientSqlEncryptedStore { 35 load(): Promise<Uint8Array | null>; 36 save(bytes: Uint8Array): Promise<void>; 37 remove(): Promise<void>; 38 } 39 40 export interface IWebSqlEngine { 41 close(): Promise<void>; 42 purge_storage(): Promise<void>; 43 exec(sql: string, params: SqlJsParams): SqlJsExecOutcome; 44 query(sql: string, params: SqlJsParams): SqlJsResultRow[]; 45 export_bytes(): Uint8Array; 46 import_bytes(bytes: Uint8Array): Promise<void>; 47 export_backup(): Promise<ResolveError<BackupSqlPayload>>; 48 import_backup(payload: BackupSqlPayload): Promise<ResolveError<void>>; 49 get_store_id(): string; 50 }