1
1
import { FunctionsClient } from '@supabase/functions-js'
2
2
import { AuthChangeEvent } from '@supabase/gotrue-js'
3
- import { PostgrestClient } from '@supabase/postgrest-js'
3
+ import {
4
+ PostgrestClient ,
5
+ PostgrestFilterBuilder ,
6
+ PostgrestQueryBuilder ,
7
+ } from '@supabase/postgrest-js'
4
8
import {
5
9
RealtimeChannel ,
6
10
RealtimeChannelOptions ,
@@ -125,31 +129,43 @@ export default class SupabaseClient<
125
129
return new SupabaseStorageClient ( this . storageUrl , this . headers , this . fetch )
126
130
}
127
131
132
+ // NOTE: signatures must be kept in sync with PostgrestClient.from
133
+ from <
134
+ TableName extends string & keyof Schema [ 'Tables' ] ,
135
+ Table extends Schema [ 'Tables' ] [ TableName ]
136
+ > ( relation : TableName ) : PostgrestQueryBuilder < Schema , Table , TableName >
137
+ from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
138
+ relation : ViewName
139
+ ) : PostgrestQueryBuilder < Schema , View , ViewName >
140
+ from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any >
128
141
/**
129
142
* Perform a query on a table or a view.
130
143
*
131
144
* @param relation - The table or view name to query
132
145
*/
133
- from : PostgrestClient < Database , SchemaName > [ 'from' ] = ( relation : string ) = > {
146
+ from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any > {
134
147
return this . rest . from ( relation )
135
148
}
136
149
150
+ // NOTE: signatures must be kept in sync with PostgrestClient.schema
137
151
/**
138
- * Perform a query on a schema distinct from the default schema supplied via
139
- * the `options.db.schema` constructor parameter.
152
+ * Select a schema to query or perform an function (rpc) call.
140
153
*
141
154
* The schema needs to be on the list of exposed schemas inside Supabase.
142
155
*
143
- * @param schema - The name of the schema to query
156
+ * @param schema - The schema to query
144
157
*/
145
- schema : PostgrestClient < Database , SchemaName > [ 'schema' ] = <
146
- DynamicSchema extends string & keyof Database
147
- > (
158
+ schema < DynamicSchema extends string & keyof Database > (
148
159
schema : DynamicSchema
149
- ) => {
160
+ ) : PostgrestClient <
161
+ Database ,
162
+ DynamicSchema ,
163
+ Database [ DynamicSchema ] extends GenericSchema ? Database [ DynamicSchema ] : any
164
+ > {
150
165
return this . rest . schema < DynamicSchema > ( schema )
151
166
}
152
167
168
+ // NOTE: signatures must be kept in sync with PostgrestClient.rpc
153
169
/**
154
170
* Perform a function call.
155
171
*
@@ -171,17 +187,22 @@ export default class SupabaseClient<
171
187
* `"estimated"`: Uses exact count for low numbers and planned count for high
172
188
* numbers.
173
189
*/
174
- rpc : PostgrestClient < Database , SchemaName > [ 'rpc' ] = <
175
- FunctionName extends string & keyof Schema [ 'Functions' ] ,
176
- Function_ extends Schema [ 'Functions' ] [ FunctionName ]
177
- > (
178
- fn : FunctionName ,
179
- args : Function_ [ 'Args' ] = { } ,
180
- options ?: {
190
+ rpc < FnName extends string & keyof Schema [ 'Functions' ] , Fn extends Schema [ 'Functions' ] [ FnName ] > (
191
+ fn : FnName ,
192
+ args : Fn [ 'Args' ] = { } ,
193
+ options : {
181
194
head ?: boolean
182
195
count ?: 'exact' | 'planned' | 'estimated'
183
- }
184
- ) => {
196
+ } = { }
197
+ ) : PostgrestFilterBuilder <
198
+ Schema ,
199
+ Fn [ 'Returns' ] extends any [ ]
200
+ ? Fn [ 'Returns' ] [ number ] extends Record < string , unknown >
201
+ ? Fn [ 'Returns' ] [ number ]
202
+ : never
203
+ : never ,
204
+ Fn [ 'Returns' ]
205
+ > {
185
206
return this . rest . rpc ( fn , args , options )
186
207
}
187
208
0 commit comments