Skip to content

Commit a4ec228

Browse files
authored
Merge pull request #1416 from supabase/chore/upgrade-postgrest-js-deps
chore(deps): upgrade postgrest-js introduce services version options
2 parents 62ee92a + d4f1cf8 commit a4ec228

File tree

10 files changed

+7909
-41
lines changed

10 files changed

+7909
-41
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@supabase/auth-js": "2.70.0",
5353
"@supabase/functions-js": "2.4.5",
5454
"@supabase/node-fetch": "2.6.15",
55-
"@supabase/postgrest-js": "1.19.4",
55+
"@supabase/postgrest-js": "1.21.0",
5656
"@supabase/realtime-js": "2.11.15",
5757
"@supabase/storage-js": "2.7.1"
5858
},

src/SupabaseClient.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
PostgrestClient,
55
PostgrestFilterBuilder,
66
PostgrestQueryBuilder,
7+
ClientServerOptions as PostgrestClientServerOption,
8+
GetGenericDatabaseWithOptions,
79
} from '@supabase/postgrest-js'
810
import {
911
RealtimeChannel,
@@ -28,13 +30,18 @@ import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions
2830
*
2931
* An isomorphic Javascript client for interacting with Postgres.
3032
*/
33+
34+
export type ServicesOptions = PostgrestClientServerOption & {}
35+
3136
export default class SupabaseClient<
3237
Database = any,
33-
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']
3441
? 'public'
35-
: string & keyof Database,
36-
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
37-
? Database[SchemaName]
42+
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
43+
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
44+
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
3845
: any
3946
> {
4047
/**
@@ -47,7 +54,7 @@ export default class SupabaseClient<
4754
protected authUrl: URL
4855
protected storageUrl: URL
4956
protected functionsUrl: URL
50-
protected rest: PostgrestClient<Database, SchemaName, Schema>
57+
protected rest: PostgrestClient<Database, ClientOptions, SchemaName, Schema>
5158
protected storageKey: string
5259
protected fetch?: Fetch
5360
protected changedAccessToken?: string
@@ -156,16 +163,16 @@ export default class SupabaseClient<
156163
from<
157164
TableName extends string & keyof Schema['Tables'],
158165
Table extends Schema['Tables'][TableName]
159-
>(relation: TableName): PostgrestQueryBuilder<Schema, Table, TableName>
166+
>(relation: TableName): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName>
160167
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
161168
relation: ViewName
162-
): PostgrestQueryBuilder<Schema, View, ViewName>
169+
): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>
163170
/**
164171
* Perform a query on a table or a view.
165172
*
166173
* @param relation - The table or view name to query
167174
*/
168-
from(relation: string): PostgrestQueryBuilder<Schema, any, any> {
175+
from(relation: string): PostgrestQueryBuilder<ClientOptions, Schema, any, any> {
169176
return this.rest.from(relation)
170177
}
171178

@@ -177,10 +184,11 @@ export default class SupabaseClient<
177184
*
178185
* @param schema - The schema to query
179186
*/
180-
schema<DynamicSchema extends string & keyof Database>(
187+
schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>['db']>(
181188
schema: DynamicSchema
182189
): PostgrestClient<
183190
Database,
191+
ClientOptions,
184192
DynamicSchema,
185193
Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any
186194
> {
@@ -220,6 +228,7 @@ export default class SupabaseClient<
220228
count?: 'exact' | 'planned' | 'estimated'
221229
} = {}
222230
): PostgrestFilterBuilder<
231+
ClientOptions,
223232
Schema,
224233
Fn['Returns'] extends any[]
225234
? Fn['Returns'][number] extends Record<string, unknown>
@@ -228,7 +237,8 @@ export default class SupabaseClient<
228237
: never,
229238
Fn['Returns'],
230239
FnName,
231-
null
240+
null,
241+
'RPC'
232242
> {
233243
return this.rest.rpc(fn, args, options)
234244
}

src/index.ts

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

46
export * from '@supabase/auth-js'
57
export type { User as AuthUser, Session as AuthSession } from '@supabase/auth-js'
@@ -26,16 +28,23 @@ export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from '
2628
*/
2729
export const createClient = <
2830
Database = any,
29-
SchemaName extends string & keyof Database = 'public' extends keyof Database
31+
ClientOptions extends ServicesOptions = GetGenericDatabaseWithOptions<Database>['options'],
32+
SchemaName extends string &
33+
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
3034
? 'public'
31-
: string & keyof Database,
32-
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
33-
? Database[SchemaName]
35+
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
36+
Schema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
37+
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
3438
: any
3539
>(
3640
supabaseUrl: string,
3741
supabaseKey: string,
3842
options?: SupabaseClientOptions<SchemaName>
39-
): SupabaseClient<Database, SchemaName, Schema> => {
40-
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
43+
) => {
44+
return new SupabaseClient<
45+
Database,
46+
ClientOptions,
47+
SchemaName,
48+
Schema extends GenericSchema ? Schema : any
49+
>(supabaseUrl, supabaseKey, options)
4150
}

test/deno/integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ Deno.test(
5959
const { error: deleteError } = await supabase
6060
.from('todos')
6161
.delete()
62-
.eq('id', createdTodo!.id)
62+
.eq('id', createdTodo!.id as string)
6363

6464
assertEquals(deleteError, null)
6565

6666
// Verify the todo was deleted
6767
const { data: fetchedTodo, error: fetchError } = await supabase
6868
.from('todos')
6969
.select('*')
70-
.eq('id', createdTodo!.id)
70+
.eq('id', createdTodo!.id as string)
7171
.single()
7272

7373
assertExists(fetchError)

test/deno/package-lock.json

Lines changed: 176 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)