@@ -30,12 +30,32 @@ 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 Database )
38+ | { PostgrestVersion : string } = 'public' extends keyof Database
3439 ? 'public'
3540 : string & keyof Database ,
36- Schema extends GenericSchema = Database [ SchemaName ] extends GenericSchema
37- ? Database [ SchemaName ]
38- : any
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+ ? { PostgrestVersion : '12' }
56+ : SchemaNameOrClientOptions extends { PostgrestVersion : string }
57+ ? SchemaNameOrClientOptions
58+ : never
3959> {
4060 /**
4161 * Supabase Auth allows you to create and manage user sessions for access to data that is secured by access policies.
@@ -51,7 +71,7 @@ export default class SupabaseClient<
5171 protected authUrl : URL
5272 protected storageUrl : URL
5373 protected functionsUrl : URL
54- protected rest : PostgrestClient < Database , SchemaName , Schema >
74+ protected rest : PostgrestClient < Database , ClientOptions , SchemaName >
5575 protected storageKey : string
5676 protected fetch ?: Fetch
5777 protected changedAccessToken ?: string
@@ -161,16 +181,16 @@ export default class SupabaseClient<
161181 from <
162182 TableName extends string & keyof Schema [ 'Tables' ] ,
163183 Table extends Schema [ 'Tables' ] [ TableName ]
164- > ( relation : TableName ) : PostgrestQueryBuilder < Schema , Table , TableName >
184+ > ( relation : TableName ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName >
165185 from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
166186 relation : ViewName
167- ) : PostgrestQueryBuilder < Schema , View , ViewName >
187+ ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName >
168188 /**
169189 * Perform a query on a table or a view.
170190 *
171191 * @param relation - The table or view name to query
172192 */
173- from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any > {
193+ from ( relation : string ) : PostgrestQueryBuilder < ClientOptions , Schema , any > {
174194 return this . rest . from ( relation )
175195 }
176196
@@ -182,10 +202,11 @@ export default class SupabaseClient<
182202 *
183203 * @param schema - The schema to query
184204 */
185- schema < DynamicSchema extends string & keyof Database > (
205+ schema < DynamicSchema extends string & keyof Omit < Database , '__InternalSupabase' > > (
186206 schema : DynamicSchema
187207 ) : PostgrestClient <
188208 Database ,
209+ ClientOptions ,
189210 DynamicSchema ,
190211 Database [ DynamicSchema ] extends GenericSchema ? Database [ DynamicSchema ] : any
191212 > {
@@ -225,6 +246,7 @@ export default class SupabaseClient<
225246 count ?: 'exact' | 'planned' | 'estimated'
226247 } = { }
227248 ) : PostgrestFilterBuilder <
249+ ClientOptions ,
228250 Schema ,
229251 Fn [ 'Returns' ] extends any [ ]
230252 ? Fn [ 'Returns' ] [ number ] extends Record < string , unknown >
@@ -233,7 +255,8 @@ export default class SupabaseClient<
233255 : never ,
234256 Fn [ 'Returns' ] ,
235257 FnName ,
236- null
258+ null ,
259+ 'RPC'
237260 > {
238261 return this . rest . rpc ( fn , args , options )
239262 }
0 commit comments