@@ -11,6 +11,8 @@ import localStorageDriver from "unstorage/drivers/localstorage"
1111import { z } from "zod"
1212
1313import type { ClientPostgresOptions } from "../../module.js"
14+ import type { LocalPgDbTypes } from "../types.js"
15+
1416
1517export const zMigrationJson = z . array ( z . object ( {
1618 sql : z . array ( z . string ( ) ) ,
@@ -56,7 +58,7 @@ export type ClientMigrationState = {
5658 skip : boolean
5759 storage ?: Storage < any >
5860}
59- type AllOptions = Partial < Omit < ClientPostgresOptions , "clientMigrationConfig" > & {
61+ export type AllOptions = Partial < Omit < ClientPostgresOptions , "clientMigrationConfig" > & {
6062 clientMigrationOptions : MigrationOptions
6163 clientPgliteOptions : ClientPostgresOptions [ "clientPgliteOptions" ] & {
6264 extensions ?: PGliteOptions [ "extensions" ]
@@ -72,7 +74,7 @@ type AllOptions = Partial<Omit<ClientPostgresOptions, "clientMigrationConfig"> &
7274 /** The schema to use for the client side database. This must be defined unless a proxy is being used. */
7375 schema ?: any
7476} >
75- type InitOptions = {
77+ export type InitOptions = {
7678 bypassEnvCheck ?: boolean
7779 addToWindowInDev ?: boolean
7880 logger ?: BaseLogger
@@ -213,15 +215,19 @@ export class ClientDatabaseManager {
213215 await this . useClientDb ( name , entry . options , entry . initOptions )
214216 }
215217
216- async useClientDb (
217- name : string = this . defaultDatabaseName ,
218+ async useClientDb <
219+ TName extends keyof LocalPgDbTypes | string ,
220+ TDb extends TName extends keyof LocalPgDbTypes ? LocalPgDbTypes [ TName ] : ( PgliteDatabase | PgRemoteDatabase )
221+ > (
222+ name : TName = this . defaultDatabaseName as TName ,
218223 opts ?: AllOptions , // do not define this or init will break
219224 {
220225 bypassEnvCheck = false ,
221226 addToWindowInDev = true ,
222227 logger = typeof console !== "undefined" ? console as any : { }
223228 } : InitOptions = { }
224- ) : Promise < PgliteDatabase | PgRemoteDatabase > {
229+ ) :
230+ Promise < TDb > {
225231 if ( ! bypassEnvCheck && ! import . meta. client ) {
226232 return { } as any
227233 }
@@ -255,7 +261,7 @@ export class ClientDatabaseManager {
255261 } )
256262 entry . migrationState . skip = true
257263 }
258- return entry . db
264+ return entry . db as any
259265 }
260266
261267 static useDefaultStorage ( ) : Storage < any > | undefined {
0 commit comments