@@ -11,6 +11,10 @@ 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+
16+
17+
1418
1519export const zMigrationJson = z . array ( z . object ( {
1620 sql : z . array ( z . string ( ) ) ,
@@ -56,7 +60,7 @@ export type ClientMigrationState = {
5660 skip : boolean
5761 storage ?: Storage < any >
5862}
59- type AllOptions = Partial < Omit < ClientPostgresOptions , "clientMigrationConfig" > & {
63+ export type AllOptions = Partial < Omit < ClientPostgresOptions , "clientMigrationConfig" > & {
6064 clientMigrationOptions : MigrationOptions
6165 clientPgliteOptions : ClientPostgresOptions [ "clientPgliteOptions" ] & {
6266 extensions ?: PGliteOptions [ "extensions" ]
@@ -72,7 +76,7 @@ type AllOptions = Partial<Omit<ClientPostgresOptions, "clientMigrationConfig"> &
7276 /** The schema to use for the client side database. This must be defined unless a proxy is being used. */
7377 schema ?: any
7478} >
75- type InitOptions = {
79+ export type InitOptions = {
7680 bypassEnvCheck ?: boolean
7781 addToWindowInDev ?: boolean
7882 logger ?: BaseLogger
@@ -213,15 +217,20 @@ export class ClientDatabaseManager {
213217 await this . useClientDb ( name , entry . options , entry . initOptions )
214218 }
215219
216- async useClientDb (
217- name : string = this . defaultDatabaseName ,
220+ async useClientDb <
221+ TName extends keyof LocalPgDbTypes | string ,
222+ TDb extends TName extends keyof LocalPgDbTypes ? LocalPgDbTypes [ TName ] : ( PgliteDatabase | PgRemoteDatabase )
223+ > (
224+ name : TName = this . defaultDatabaseName as TName ,
218225 opts ?: AllOptions , // do not define this or init will break
219226 {
220227 bypassEnvCheck = false ,
221228 addToWindowInDev = true ,
222229 logger = typeof console !== "undefined" ? console as any : { }
223230 } : InitOptions = { }
224- ) : Promise < PgliteDatabase | PgRemoteDatabase > {
231+ ) :
232+ Promise < TDb >
233+ {
225234 if ( ! bypassEnvCheck && ! import . meta. client ) {
226235 return { } as any
227236 }
@@ -255,7 +264,7 @@ export class ClientDatabaseManager {
255264 } )
256265 entry . migrationState . skip = true
257266 }
258- return entry . db
267+ return entry . db as any
259268 }
260269
261270 static useDefaultStorage ( ) : Storage < any > | undefined {
0 commit comments