@@ -30,12 +30,36 @@ import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions
3030 */
3131export default class SupabaseClient <
3232 Database = any ,
33- SchemaName extends string & keyof Database = 'public' extends keyof Database
33+ // The second type parameter is also used for specifying db_schema, so we
34+ // support both cases.
35+ // TODO: Allow setting db_schema from ClientOptions.
36+ SchemaNameOrClientOptions extends
37+ | ( string & keyof Omit < Database , '__InternalSupabase' > )
38+ | { PostgrestVersion : string } = 'public' extends keyof Omit < Database , '__InternalSupabase' >
3439 ? 'public'
35- : string & keyof Database ,
36- Schema extends GenericSchema = Database [ SchemaName ] extends GenericSchema
37- ? Database [ SchemaName ]
38- : any
40+ : string & keyof Omit < Database , '__InternalSupabase' > ,
41+ SchemaName extends string &
42+ keyof Omit < Database , '__InternalSupabase' > = SchemaNameOrClientOptions extends string &
43+ keyof Omit < Database , '__InternalSupabase' >
44+ ? SchemaNameOrClientOptions
45+ : 'public' extends keyof Omit < Database , '__InternalSupabase' >
46+ ? 'public'
47+ : string & keyof Omit < Omit < Database , '__InternalSupabase' > , '__InternalSupabase' > ,
48+ Schema extends Omit < Database , '__InternalSupabase' > [ SchemaName ] extends GenericSchema
49+ ? Omit < Database , '__InternalSupabase' > [ SchemaName ]
50+ : never = Omit < Database , '__InternalSupabase' > [ SchemaName ] extends GenericSchema
51+ ? Omit < Database , '__InternalSupabase' > [ SchemaName ]
52+ : never ,
53+ ClientOptions extends { PostgrestVersion : string } = SchemaNameOrClientOptions extends string &
54+ keyof Omit < Database , '__InternalSupabase' >
55+ ? // If the version isn't explicitly set, look for it in the __InternalSupabase object to infer the right version
56+ Database extends { __InternalSupabase : { PostgrestVersion : string } }
57+ ? Database [ '__InternalSupabase' ]
58+ : // otherwise default to 12
59+ { PostgrestVersion : '12' }
60+ : SchemaNameOrClientOptions extends { PostgrestVersion : string }
61+ ? SchemaNameOrClientOptions
62+ : never
3963> {
4064 /**
4165 * Supabase Auth allows you to create and manage user sessions for access to data that is secured by access policies.
@@ -51,7 +75,7 @@ export default class SupabaseClient<
5175 protected authUrl : URL
5276 protected storageUrl : URL
5377 protected functionsUrl : URL
54- protected rest : PostgrestClient < Database , SchemaName , Schema >
78+ protected rest : PostgrestClient < Database , ClientOptions , SchemaName >
5579 protected storageKey : string
5680 protected fetch ?: Fetch
5781 protected changedAccessToken ?: string
@@ -161,16 +185,16 @@ export default class SupabaseClient<
161185 from <
162186 TableName extends string & keyof Schema [ 'Tables' ] ,
163187 Table extends Schema [ 'Tables' ] [ TableName ]
164- > ( relation : TableName ) : PostgrestQueryBuilder < Schema , Table , TableName >
188+ > ( relation : TableName ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName >
165189 from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
166190 relation : ViewName
167- ) : PostgrestQueryBuilder < Schema , View , ViewName >
191+ ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName >
168192 /**
169193 * Perform a query on a table or a view.
170194 *
171195 * @param relation - The table or view name to query
172196 */
173- from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any > {
197+ from ( relation : string ) : PostgrestQueryBuilder < ClientOptions , Schema , any > {
174198 return this . rest . from ( relation )
175199 }
176200
@@ -182,10 +206,11 @@ export default class SupabaseClient<
182206 *
183207 * @param schema - The schema to query
184208 */
185- schema < DynamicSchema extends string & keyof Database > (
209+ schema < DynamicSchema extends string & keyof Omit < Database , '__InternalSupabase' > > (
186210 schema : DynamicSchema
187211 ) : PostgrestClient <
188212 Database ,
213+ ClientOptions ,
189214 DynamicSchema ,
190215 Database [ DynamicSchema ] extends GenericSchema ? Database [ DynamicSchema ] : any
191216 > {
@@ -225,6 +250,7 @@ export default class SupabaseClient<
225250 count ?: 'exact' | 'planned' | 'estimated'
226251 } = { }
227252 ) : PostgrestFilterBuilder <
253+ ClientOptions ,
228254 Schema ,
229255 Fn [ 'Returns' ] extends any [ ]
230256 ? Fn [ 'Returns' ] [ number ] extends Record < string , unknown >
@@ -233,7 +259,8 @@ export default class SupabaseClient<
233259 : never ,
234260 Fn [ 'Returns' ] ,
235261 FnName ,
236- null
262+ null ,
263+ 'RPC'
237264 > {
238265 return this . rest . rpc ( fn , args , options )
239266 }
0 commit comments