Skip to content

Commit baf138d

Browse files
committed
Revert "Merge pull request #1416 from supabase/chore/upgrade-postgrest-js-deps"
This reverts commit a4ec228, reversing changes made to 62ee92a.
1 parent 6a3ad19 commit baf138d

File tree

7 files changed

+31
-113
lines changed

7 files changed

+31
-113
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.21.0",
55+
"@supabase/postgrest-js": "1.19.4",
5656
"@supabase/realtime-js": "2.11.15",
5757
"@supabase/storage-js": "2.7.1"
5858
},

src/SupabaseClient.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
PostgrestClient,
55
PostgrestFilterBuilder,
66
PostgrestQueryBuilder,
7-
ClientServerOptions as PostgrestClientServerOption,
8-
GetGenericDatabaseWithOptions,
97
} from '@supabase/postgrest-js'
108
import {
119
RealtimeChannel,
@@ -30,18 +28,13 @@ import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions
3028
*
3129
* An isomorphic Javascript client for interacting with Postgres.
3230
*/
33-
34-
export type ServicesOptions = PostgrestClientServerOption & {}
35-
3631
export default class SupabaseClient<
3732
Database = any,
38-
ClientOptions extends ServicesOptions = { PostgrestVersion: '12' },
39-
SchemaName extends string &
40-
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
33+
SchemaName extends string & keyof Database = 'public' extends keyof Database
4134
? 'public'
42-
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
43-
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
44-
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
35+
: string & keyof Database,
36+
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
37+
? Database[SchemaName]
4538
: any
4639
> {
4740
/**
@@ -54,7 +47,7 @@ export default class SupabaseClient<
5447
protected authUrl: URL
5548
protected storageUrl: URL
5649
protected functionsUrl: URL
57-
protected rest: PostgrestClient<Database, ClientOptions, SchemaName, Schema>
50+
protected rest: PostgrestClient<Database, SchemaName, Schema>
5851
protected storageKey: string
5952
protected fetch?: Fetch
6053
protected changedAccessToken?: string
@@ -163,16 +156,16 @@ export default class SupabaseClient<
163156
from<
164157
TableName extends string & keyof Schema['Tables'],
165158
Table extends Schema['Tables'][TableName]
166-
>(relation: TableName): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName>
159+
>(relation: TableName): PostgrestQueryBuilder<Schema, Table, TableName>
167160
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
168161
relation: ViewName
169-
): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>
162+
): PostgrestQueryBuilder<Schema, View, ViewName>
170163
/**
171164
* Perform a query on a table or a view.
172165
*
173166
* @param relation - The table or view name to query
174167
*/
175-
from(relation: string): PostgrestQueryBuilder<ClientOptions, Schema, any, any> {
168+
from(relation: string): PostgrestQueryBuilder<Schema, any, any> {
176169
return this.rest.from(relation)
177170
}
178171

@@ -184,11 +177,10 @@ export default class SupabaseClient<
184177
*
185178
* @param schema - The schema to query
186179
*/
187-
schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>['db']>(
180+
schema<DynamicSchema extends string & keyof Database>(
188181
schema: DynamicSchema
189182
): PostgrestClient<
190183
Database,
191-
ClientOptions,
192184
DynamicSchema,
193185
Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any
194186
> {
@@ -228,7 +220,6 @@ export default class SupabaseClient<
228220
count?: 'exact' | 'planned' | 'estimated'
229221
} = {}
230222
): PostgrestFilterBuilder<
231-
ClientOptions,
232223
Schema,
233224
Fn['Returns'] extends any[]
234225
? Fn['Returns'][number] extends Record<string, unknown>
@@ -237,8 +228,7 @@ export default class SupabaseClient<
237228
: never,
238229
Fn['Returns'],
239230
FnName,
240-
null,
241-
'RPC'
231+
null
242232
> {
243233
return this.rest.rpc(fn, args, options)
244234
}

src/index.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
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'
53

64
export * from '@supabase/auth-js'
75
export type { User as AuthUser, Session as AuthSession } from '@supabase/auth-js'
@@ -28,28 +26,16 @@ export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from '
2826
*/
2927
export const createClient = <
3028
Database = any,
31-
ClientOptions extends ServicesOptions = GetGenericDatabaseWithOptions<Database>['options'],
32-
SchemaName extends string &
33-
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
29+
SchemaName extends string & keyof Database = 'public' extends keyof Database
3430
? 'public'
35-
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
36-
Schema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
37-
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
31+
: string & keyof Database,
32+
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
33+
? Database[SchemaName]
3834
: any
3935
>(
4036
supabaseUrl: string,
4137
supabaseKey: string,
4238
options?: SupabaseClientOptions<SchemaName>
43-
): SupabaseClient<
44-
Database,
45-
ClientOptions,
46-
SchemaName,
47-
Schema extends GenericSchema ? Schema : any
48-
> => {
49-
return new SupabaseClient<
50-
Database,
51-
ClientOptions,
52-
SchemaName,
53-
Schema extends GenericSchema ? Schema : any
54-
>(supabaseUrl, supabaseKey, options)
39+
): SupabaseClient<Database, SchemaName, Schema> => {
40+
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
5541
}

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 as string)
62+
.eq('id', createdTodo!.id)
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 as string)
70+
.eq('id', createdTodo!.id)
7171
.single()
7272

7373
assertExists(fetchError)

test/types/index.test-d.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -136,59 +136,3 @@ const supabase = createClient<Database>(URL, KEY)
136136
}[]
137137
>(channels)
138138
}
139-
// Test Postgrest13
140-
// should be able to declare specific PostgrestVersion
141-
{
142-
// @ts-expect-error should raise error if provinding invalid version
143-
createClient<Database, { PostgrestVersion: 42 }>('HTTP://localhost:3000', KEY)
144-
}
145-
// should be able to infer PostgrestVersion from Database __InternalSupabase
146-
{
147-
type DatabaseWithInternals = {
148-
__InternalSupabase: {
149-
PostgrestVersion: '13'
150-
}
151-
public: {
152-
Tables: {
153-
shops: {
154-
Row: {
155-
address: string | null
156-
id: number
157-
shop_geom: unknown | null
158-
}
159-
Insert: {
160-
address?: string | null
161-
id: number
162-
shop_geom?: unknown | null
163-
}
164-
Update: {
165-
address?: string | null
166-
id?: number
167-
shop_geom?: unknown | null
168-
}
169-
Relationships: []
170-
}
171-
}
172-
Views: {
173-
[_ in never]: never
174-
}
175-
Functions: {
176-
[_ in never]: never
177-
}
178-
Enums: {
179-
[_ in never]: never
180-
}
181-
CompositeTypes: {
182-
[_ in never]: never
183-
}
184-
}
185-
}
186-
// Note: The template argument properties (PostgrestVersion) will not be autocompleted
187-
// due to a Typescript bug tracked here: https://github.com/microsoft/TypeScript/issues/56299
188-
const pg13Client = createClient<DatabaseWithInternals>('HTTP://localhost:3000', KEY)
189-
const pg12Client = createClient<Database>('HTTP://localhost:3000', KEY)
190-
const res13 = await pg13Client.from('shops').update({ id: 21 }).maxAffected(1)
191-
const res12 = await pg12Client.from('shops').update({ id: 21 }).maxAffected(1)
192-
expectType<typeof res13.data>(null)
193-
expectType<typeof res12.Error>('maxAffected method only available on postgrest 13+')
194-
}

test/unit/SupabaseClient.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,18 @@ describe('SupabaseClient', () => {
7474
test('should have custom header set', () => {
7575
const customHeader = { 'X-Test-Header': 'value' }
7676
const request = createClient(URL, KEY, { global: { headers: customHeader } }).rpc('')
77-
//@ts-expect-error headers is protected attribute
78-
const requestHeader = request.headers.get('X-Test-Header')
79-
expect(requestHeader).toBe(customHeader['X-Test-Header'])
77+
// @ts-ignore
78+
const getHeaders = request.headers
79+
expect(getHeaders).toHaveProperty('X-Test-Header', 'value')
8080
})
8181

8282
test('should merge custom headers with default headers', () => {
8383
const customHeader = { 'X-Test-Header': 'value' }
84-
const request = createClient(URL, KEY, { global: { headers: customHeader } }).rpc('')
85-
86-
//@ts-expect-error headers is protected attribute
87-
const requestHeader = request.headers.get('X-Test-Header')
88-
expect(requestHeader).toBe(customHeader['X-Test-Header'])
89-
//@ts-expect-error headers is protected attribute
90-
expect(request.headers.get('X-Client-Info')).not.toBeNull()
84+
const client = createClient(URL, KEY, { global: { headers: customHeader } })
85+
// @ts-ignore
86+
expect(client.headers).toHaveProperty('X-Test-Header', 'value')
87+
// @ts-ignore
88+
expect(client.headers).toHaveProperty('X-Client-Info')
9189
})
9290
})
9391

0 commit comments

Comments
 (0)