@@ -30,12 +30,36 @@ import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions
30
30
*/
31
31
export default class SupabaseClient <
32
32
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' >
34
39
? '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
39
63
> {
40
64
/**
41
65
* 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<
51
75
protected authUrl : URL
52
76
protected storageUrl : URL
53
77
protected functionsUrl : URL
54
- protected rest : PostgrestClient < Database , SchemaName , Schema >
78
+ protected rest : PostgrestClient < Database , ClientOptions , SchemaName >
55
79
protected storageKey : string
56
80
protected fetch ?: Fetch
57
81
protected changedAccessToken ?: string
@@ -161,16 +185,16 @@ export default class SupabaseClient<
161
185
from <
162
186
TableName extends string & keyof Schema [ 'Tables' ] ,
163
187
Table extends Schema [ 'Tables' ] [ TableName ]
164
- > ( relation : TableName ) : PostgrestQueryBuilder < Schema , Table , TableName >
188
+ > ( relation : TableName ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName >
165
189
from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
166
190
relation : ViewName
167
- ) : PostgrestQueryBuilder < Schema , View , ViewName >
191
+ ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName >
168
192
/**
169
193
* Perform a query on a table or a view.
170
194
*
171
195
* @param relation - The table or view name to query
172
196
*/
173
- from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any > {
197
+ from ( relation : string ) : PostgrestQueryBuilder < ClientOptions , Schema , any > {
174
198
return this . rest . from ( relation )
175
199
}
176
200
@@ -182,10 +206,11 @@ export default class SupabaseClient<
182
206
*
183
207
* @param schema - The schema to query
184
208
*/
185
- schema < DynamicSchema extends string & keyof Database > (
209
+ schema < DynamicSchema extends string & keyof Omit < Database , '__InternalSupabase' > > (
186
210
schema : DynamicSchema
187
211
) : PostgrestClient <
188
212
Database ,
213
+ ClientOptions ,
189
214
DynamicSchema ,
190
215
Database [ DynamicSchema ] extends GenericSchema ? Database [ DynamicSchema ] : any
191
216
> {
@@ -225,6 +250,7 @@ export default class SupabaseClient<
225
250
count ?: 'exact' | 'planned' | 'estimated'
226
251
} = { }
227
252
) : PostgrestFilterBuilder <
253
+ ClientOptions ,
228
254
Schema ,
229
255
Fn [ 'Returns' ] extends any [ ]
230
256
? Fn [ 'Returns' ] [ number ] extends Record < string , unknown >
@@ -233,7 +259,8 @@ export default class SupabaseClient<
233
259
: never ,
234
260
Fn [ 'Returns' ] ,
235
261
FnName ,
236
- null
262
+ null ,
263
+ 'RPC'
237
264
> {
238
265
return this . rest . rpc ( fn , args , options )
239
266
}
0 commit comments