@@ -2,7 +2,7 @@ import PostgrestQueryBuilder from './PostgrestQueryBuilder'
22import PostgrestFilterBuilder from './PostgrestFilterBuilder'
33import PostgrestBuilder from './PostgrestBuilder'
44import { DEFAULT_HEADERS } from './constants'
5- import { Fetch , GenericSchema } from './types'
5+ import { Fetch , GenericSchema , ClientServerOptions , GetGenericDatabaseWithOptions } from './types'
66
77/**
88 * PostgREST client.
@@ -16,11 +16,16 @@ import { Fetch, GenericSchema } from './types'
1616 */
1717export default class PostgrestClient <
1818 Database = any ,
19- SchemaName extends string & keyof Database = 'public' extends keyof Database
19+ ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions <
20+ Database ,
21+ { PostgrestVersion : '12' }
22+ > [ 'options' ] ,
23+ SchemaName extends string &
24+ keyof GetGenericDatabaseWithOptions < Database > [ 'db' ] = 'public' extends keyof GetGenericDatabaseWithOptions < Database > [ 'db' ]
2025 ? 'public'
21- : string & keyof Database ,
22- Schema extends GenericSchema = Database [ SchemaName ] extends GenericSchema
23- ? Database [ SchemaName ]
26+ : string & keyof GetGenericDatabaseWithOptions < Database > [ 'db' ] ,
27+ Schema extends GenericSchema = GetGenericDatabaseWithOptions < Database > [ 'db' ] [ SchemaName ] extends GenericSchema
28+ ? GetGenericDatabaseWithOptions < Database > [ 'db' ] [ SchemaName ]
2429 : any
2530> {
2631 url : string
@@ -59,16 +64,16 @@ export default class PostgrestClient<
5964 from <
6065 TableName extends string & keyof Schema [ 'Tables' ] ,
6166 Table extends Schema [ 'Tables' ] [ TableName ]
62- > ( relation : TableName ) : PostgrestQueryBuilder < Schema , Table , TableName >
67+ > ( relation : TableName ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName >
6368 from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
6469 relation : ViewName
65- ) : PostgrestQueryBuilder < Schema , View , ViewName >
70+ ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName >
6671 /**
6772 * Perform a query on a table or a view.
6873 *
6974 * @param relation - The table or view name to query
7075 */
71- from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any > {
76+ from ( relation : string ) : PostgrestQueryBuilder < ClientOptions , Schema , any , any > {
7277 const url = new URL ( `${ this . url } /${ relation } ` )
7378 return new PostgrestQueryBuilder ( url , {
7479 headers : { ...this . headers } ,
@@ -84,10 +89,11 @@ export default class PostgrestClient<
8489 *
8590 * @param schema - The schema to query
8691 */
87- schema < DynamicSchema extends string & keyof Database > (
92+ schema < DynamicSchema extends string & keyof GetGenericDatabaseWithOptions < Database > [ 'db' ] > (
8893 schema : DynamicSchema
8994 ) : PostgrestClient <
9095 Database ,
96+ ClientOptions ,
9197 DynamicSchema ,
9298 Database [ DynamicSchema ] extends GenericSchema ? Database [ DynamicSchema ] : any
9399 > {
@@ -134,6 +140,7 @@ export default class PostgrestClient<
134140 count ?: 'exact' | 'planned' | 'estimated'
135141 } = { }
136142 ) : PostgrestFilterBuilder <
143+ ClientOptions ,
137144 Schema ,
138145 Fn [ 'Returns' ] extends any [ ]
139146 ? Fn [ 'Returns' ] [ number ] extends Record < string , unknown >
@@ -176,6 +183,6 @@ export default class PostgrestClient<
176183 body,
177184 fetch : this . fetch ,
178185 allowEmpty : false ,
179- } as unknown as PostgrestBuilder < Fn [ 'Returns' ] > )
186+ } as unknown as PostgrestBuilder < ClientOptions , Fn [ 'Returns' ] > )
180187 }
181188}
0 commit comments