Skip to content

Commit 942ab4f

Browse files
committed
chore: sync types
1 parent 609dc51 commit 942ab4f

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/SupabaseClient.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
PostgrestFilterBuilder,
66
PostgrestQueryBuilder,
77
ClientServerOptions as PostgrestClientServerOption,
8+
GetGenericDatabaseWithOptions,
89
} from '@supabase/postgrest-js'
910
import {
1011
RealtimeChannel,
@@ -34,12 +35,13 @@ export type ServicesOptions = PostgrestClientServerOption & {}
3435

3536
export default class SupabaseClient<
3637
Database = any,
37-
ClientOptions extends ServicesOptions = { postgrestVersion: 12 },
38-
SchemaName extends string & keyof Database = 'public' extends keyof Database
38+
ClientOptions extends ServicesOptions = { PostgrestVersion: '12' },
39+
SchemaName extends string &
40+
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
3941
? 'public'
40-
: string & keyof Database,
41-
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
42-
? Database[SchemaName]
42+
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
43+
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
44+
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
4345
: any
4446
> {
4547
/**
@@ -180,7 +182,7 @@ export default class SupabaseClient<
180182
*
181183
* @param schema - The schema to query
182184
*/
183-
schema<DynamicSchema extends string & keyof Database>(
185+
schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>['db']>(
184186
schema: DynamicSchema
185187
): PostgrestClient<
186188
Database,
@@ -233,7 +235,8 @@ export default class SupabaseClient<
233235
: never,
234236
Fn['Returns'],
235237
FnName,
236-
null
238+
null,
239+
'RPC'
237240
> {
238241
return this.rest.rpc(fn, args, options)
239242
}

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SupabaseClient from './SupabaseClient'
22
import type { GenericSchema, SupabaseClientOptions } from './lib/types'
33
import type { ServicesOptions } from './SupabaseClient'
4+
import type { GetGenericDatabaseWithOptions } from '@supabase/postgrest-js'
45

56
export * from '@supabase/auth-js'
67
export type { User as AuthUser, Session as AuthSession } from '@supabase/auth-js'
@@ -27,12 +28,13 @@ export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from '
2728
*/
2829
export const createClient = <
2930
Database = any,
30-
ClientOptions extends ServicesOptions = { postgrestVersion: 12 },
31-
SchemaName extends string & keyof Database = 'public' extends keyof Database
31+
ClientOptions extends ServicesOptions = { PostgrestVersion: '12' },
32+
SchemaName extends string &
33+
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
3234
? 'public'
33-
: string & keyof Database,
34-
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
35-
? Database[SchemaName]
35+
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
36+
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
37+
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
3638
: any
3739
>(
3840
supabaseUrl: string,

test/client.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ describe('Custom Headers', () => {
3535

3636
const request = createClient(URL, KEY, { global: { headers: customHeader } }).rpc('')
3737

38-
// @ts-ignore
39-
const getHeaders = request.headers
38+
//@ts-expect-error headers is protected attribute
39+
const requestHeader = request.headers.get('X-Test-Header')
4040

41-
expect(getHeaders).toHaveProperty('X-Test-Header', 'value')
41+
expect(requestHeader).toBe(customHeader['X-Test-Header'])
4242
})
4343
})
4444

@@ -80,13 +80,13 @@ describe('Dynamic schema', () => {
8080
})
8181

8282
describe('Postgrest 13 client', () => {
83-
test('should be able to declare specific postgrestVersion ', async () => {
84-
// Note: The template argument properties (postgrestVersion) will not be autocompleted
83+
test('should be able to declare specific PostgrestVersion ', async () => {
84+
// Note: The template argument properties (PostgrestVersion) will not be autocompleted
8585
// due to a Typescript bug tracked here: https://github.com/microsoft/TypeScript/issues/56299
86-
createClient<Database, { postgrestVersion: 13 }>('HTTP://localhost:3000', KEY)
87-
createClient<Database, { postgrestVersion: 12 }>('HTTP://localhost:3000', KEY)
86+
createClient<Database, { PostgrestVersion: '13' }>('HTTP://localhost:3000', KEY)
87+
createClient<Database, { PostgrestVersion: '12' }>('HTTP://localhost:3000', KEY)
8888
// @ts-expect-error should raise error if provinding invalid version
89-
createClient<Database, { postgrestVersion: 42 }>('HTTP://localhost:3000', KEY)
89+
createClient<Database, { PostgrestVersion: 42 }>('HTTP://localhost:3000', KEY)
9090
})
9191
})
9292

0 commit comments

Comments
 (0)