Skip to content

Commit 4eb677a

Browse files
soedirgokamilogorek
authored andcommitted
fix: revert to using class methods
Reverts #935. It's no longer needed because we now pin the specific postgrest-js version, so the out-of-sync issue mentioned in the PR can be avoided.
1 parent a77be48 commit 4eb677a

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

src/SupabaseClient.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { FunctionsClient } from '@supabase/functions-js'
22
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'
48
import {
59
RealtimeChannel,
610
RealtimeChannelOptions,
@@ -125,31 +129,43 @@ export default class SupabaseClient<
125129
return new SupabaseStorageClient(this.storageUrl, this.headers, this.fetch)
126130
}
127131

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>
128141
/**
129142
* Perform a query on a table or a view.
130143
*
131144
* @param relation - The table or view name to query
132145
*/
133-
from: PostgrestClient<Database, SchemaName>['from'] = (relation: string) => {
146+
from(relation: string): PostgrestQueryBuilder<Schema, any, any> {
134147
return this.rest.from(relation)
135148
}
136149

150+
// NOTE: signatures must be kept in sync with PostgrestClient.schema
137151
/**
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.
140153
*
141154
* The schema needs to be on the list of exposed schemas inside Supabase.
142155
*
143-
* @param schema - The name of the schema to query
156+
* @param schema - The schema to query
144157
*/
145-
schema: PostgrestClient<Database, SchemaName>['schema'] = <
146-
DynamicSchema extends string & keyof Database
147-
>(
158+
schema<DynamicSchema extends string & keyof Database>(
148159
schema: DynamicSchema
149-
) => {
160+
): PostgrestClient<
161+
Database,
162+
DynamicSchema,
163+
Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any
164+
> {
150165
return this.rest.schema<DynamicSchema>(schema)
151166
}
152167

168+
// NOTE: signatures must be kept in sync with PostgrestClient.rpc
153169
/**
154170
* Perform a function call.
155171
*
@@ -171,17 +187,22 @@ export default class SupabaseClient<
171187
* `"estimated"`: Uses exact count for low numbers and planned count for high
172188
* numbers.
173189
*/
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: {
181194
head?: boolean
182195
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+
> {
185206
return this.rest.rpc(fn, args, options)
186207
}
187208

0 commit comments

Comments
 (0)