Skip to content

Commit 2e5f26c

Browse files
committed
chore(wip): upgrade postgrest-js introduce services version options
1 parent 70d7199 commit 2e5f26c

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/SupabaseClient.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
PostgrestClient,
55
PostgrestFilterBuilder,
66
PostgrestQueryBuilder,
7+
ClientServerOptions as PostgrestClientServerOption,
78
} from '@supabase/postgrest-js'
89
import {
910
RealtimeChannel,
@@ -28,8 +29,12 @@ import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions
2829
*
2930
* An isomorphic Javascript client for interacting with Postgres.
3031
*/
32+
33+
export type ServicesOptions = PostgrestClientServerOption & {}
34+
3135
export default class SupabaseClient<
3236
Database = any,
37+
ClientOptions extends ServicesOptions = { postgrestVersion: 12 },
3338
SchemaName extends string & keyof Database = 'public' extends keyof Database
3439
? 'public'
3540
: string & keyof Database,
@@ -47,7 +52,7 @@ export default class SupabaseClient<
4752
protected authUrl: string
4853
protected storageUrl: string
4954
protected functionsUrl: string
50-
protected rest: PostgrestClient<Database, SchemaName, Schema>
55+
protected rest: PostgrestClient<Database, ClientOptions, SchemaName, Schema>
5156
protected storageKey: string
5257
protected fetch?: Fetch
5358
protected changedAccessToken?: string
@@ -154,16 +159,16 @@ export default class SupabaseClient<
154159
from<
155160
TableName extends string & keyof Schema['Tables'],
156161
Table extends Schema['Tables'][TableName]
157-
>(relation: TableName): PostgrestQueryBuilder<Schema, Table, TableName>
162+
>(relation: TableName): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName>
158163
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
159164
relation: ViewName
160-
): PostgrestQueryBuilder<Schema, View, ViewName>
165+
): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>
161166
/**
162167
* Perform a query on a table or a view.
163168
*
164169
* @param relation - The table or view name to query
165170
*/
166-
from(relation: string): PostgrestQueryBuilder<Schema, any, any> {
171+
from(relation: string): PostgrestQueryBuilder<ClientOptions, Schema, any, any> {
167172
return this.rest.from(relation)
168173
}
169174

@@ -179,6 +184,7 @@ export default class SupabaseClient<
179184
schema: DynamicSchema
180185
): PostgrestClient<
181186
Database,
187+
ClientOptions,
182188
DynamicSchema,
183189
Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any
184190
> {
@@ -218,6 +224,7 @@ export default class SupabaseClient<
218224
count?: 'exact' | 'planned' | 'estimated'
219225
} = {}
220226
): PostgrestFilterBuilder<
227+
ClientOptions,
221228
Schema,
222229
Fn['Returns'] extends any[]
223230
? Fn['Returns'][number] extends Record<string, unknown>

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SupabaseClient from './SupabaseClient'
22
import type { GenericSchema, SupabaseClientOptions } from './lib/types'
3+
import type { ServicesOptions } from './SupabaseClient'
34

45
export * from '@supabase/auth-js'
56
export type { User as AuthUser, Session as AuthSession } from '@supabase/auth-js'
@@ -26,6 +27,7 @@ export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from '
2627
*/
2728
export const createClient = <
2829
Database = any,
30+
ClientOptions extends ServicesOptions = { postgrestVersion: 12 },
2931
SchemaName extends string & keyof Database = 'public' extends keyof Database
3032
? 'public'
3133
: string & keyof Database,
@@ -36,6 +38,10 @@ export const createClient = <
3638
supabaseUrl: string,
3739
supabaseKey: string,
3840
options?: SupabaseClientOptions<SchemaName>
39-
): SupabaseClient<Database, SchemaName, Schema> => {
40-
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
41+
): SupabaseClient<Database, ClientOptions, SchemaName, Schema> => {
42+
return new SupabaseClient<Database, ClientOptions, SchemaName, Schema>(
43+
supabaseUrl,
44+
supabaseKey,
45+
options
46+
)
4147
}

test/client.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ describe('Dynamic schema', () => {
7979
})
8080
})
8181

82+
describe('Postgrest 13 client', () => {
83+
test('should be able to declare specific postgrestVersion ', async () => {
84+
createClient<Database, { postgrestVersion: 13 }>('HTTP://localhost:3000', KEY)
85+
createClient<Database, { postgrestVersion: 12 }>('HTTP://localhost:3000', KEY)
86+
// @ts-expect-error should raise error if provinding invalid version
87+
createClient<Database, { postgrestVersion: 42 }>('HTTP://localhost:3000', KEY)
88+
})
89+
})
90+
8291
// Socket should close when there are no open connections
8392
// https://github.com/supabase/supabase-js/issues/44
8493

0 commit comments

Comments
 (0)