Skip to content

Commit c5f81be

Browse files
authored
Merge branch 'avallete/psql-436-feedback-request-postgrest-js-and-postgrest-v13-integration' into avallete/psql-372-postgrest-add-maxaffected-in-client-libraries
2 parents ff593be + 3be45ad commit c5f81be

File tree

9 files changed

+18
-14
lines changed

9 files changed

+18
-14
lines changed

src/PostgrestClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class PostgrestClient<
1616
Database = any,
1717
ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions<
1818
Database,
19-
{ postgrestVersion: 12 }
19+
{ postgrestVersion: '12' }
2020
>['options'],
2121
SchemaName extends string &
2222
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export type {
2929
PostgrestSingleResponse,
3030
PostgrestMaybeSingleResponse,
3131
ClientServerOptions,
32-
PostgRESTVersion,
3332
} from './types'
3433
// https://github.com/supabase/postgrest-js/issues/551
3534
// To be replaced with a helper type that only uses public types

src/select-query-parser/result.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
SelectQueryError,
2222
} from './utils'
2323

24+
export type SpreadOnManyEnabled<postgrestVersion extends string | undefined> =
25+
postgrestVersion extends `13${string}` ? true : false
26+
2427
/**
2528
* Main entry point for constructing the result type of a PostgREST query.
2629
*
@@ -445,7 +448,7 @@ type ProcessSpreadNode<
445448
? Result extends SelectQueryError<infer E>
446449
? SelectQueryError<E>
447450
: ExtractFirstProperty<Result> extends unknown[]
448-
? ClientOptions['postgrestVersion'] extends 13 // Spread over an many-to-many relationship, turn all the result fields into correlated arrays
451+
? SpreadOnManyEnabled<ClientOptions['postgrestVersion']> extends true // Spread over an many-to-many relationship, turn all the result fields into correlated arrays
449452
? ProcessManyToManySpreadNodeResult<Result>
450453
: {
451454
[K in Spread['target']['name']]: SelectQueryError<`"${RelationName}" and "${Spread['target']['name']}" do not form a many-to-one or one-to-one relationship spread not possible`>

src/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ export type GenericSchema = {
7171
Functions: Record<string, GenericFunction>
7272
}
7373

74-
export type PostgRESTVersion = 12 | 13
7574
export type ClientServerOptions = {
76-
postgrestVersion?: PostgRESTVersion
75+
postgrestVersion?: string
7776
}
7877

7978
export type DatabaseWithOptions<Database, Options extends ClientServerOptions> = {
@@ -85,7 +84,7 @@ const INTERNAL_SUPABASE_OPTIONS = '__internal_supabase'
8584

8685
export type GetGenericDatabaseWithOptions<
8786
Database,
88-
Opts extends ClientServerOptions = { postgrestVersion: 12 }
87+
Opts extends ClientServerOptions = { postgrestVersion: '12' }
8988
> = IsAny<Database> extends true
9089
? DatabaseWithOptions<Database, Opts>
9190
: typeof INTERNAL_SUPABASE_OPTIONS extends keyof Database

test/basic.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,12 @@ describe('custom prefer headers with ', () => {
319319
})
320320

321321
test('switch schema', async () => {
322-
const postgrest = new PostgrestClient<Database, { postgrestVersion: 12 }, 'personal'>(REST_URL, {
323-
schema: 'personal',
324-
})
322+
const postgrest = new PostgrestClient<Database, { postgrestVersion: '12' }, 'personal'>(
323+
REST_URL,
324+
{
325+
schema: 'personal',
326+
}
327+
)
325328
const res = await postgrest.from('users').select()
326329
expect(res).toMatchInlineSnapshot(`
327330
Object {

test/relationships.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Database as DatabaseWithOptions13 } from './types.override-with-options
55
const REST_URL = 'http://localhost:3000'
66
export const postgrest = new PostgrestClient<Database>(REST_URL)
77
const REST_URL_13 = 'http://localhost:3001'
8-
const postgrest13 = new PostgrestClient<Database, { postgrestVersion: 13 }>(REST_URL_13)
8+
const postgrest13 = new PostgrestClient<Database, { postgrestVersion: '13' }>(REST_URL_13)
99
const postgrest13FromDatabaseTypes = new PostgrestClient<DatabaseWithOptions13>(REST_URL_13)
1010

1111
const userColumn: 'catchphrase' | 'username' = 'username'

test/returns.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
5353
.returns<{ username: string }[]>()
5454
expectType<
5555
PostgrestBuilder<
56-
{ postgrestVersion: 12 },
56+
{ postgrestVersion: '12' },
5757
{
5858
Error: 'Type mismatch: Cannot cast single object to array type. Remove Array wrapper from return type or make sure you are not using .single() up in the calling chain'
5959
},

test/select-query-parser/result.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type SelectQueryFromTableResult<
1616
TableName,
1717
Database['public']['Tables'][TableName]['Relationships'],
1818
Q,
19-
{ postgrestVersion: 12 }
19+
{ postgrestVersion: '12' }
2020
>
2121

2222
// This test file is here to help develop, debug and maintain the GetResult
@@ -132,7 +132,7 @@ type SelectQueryFromTableResult<
132132
TableName,
133133
Database['personal']['Tables'][TableName]['Relationships'],
134134
Q,
135-
{ postgrestVersion: 12 }
135+
{ postgrestVersion: '12' }
136136
>
137137
// Should work with Json object accessor
138138
{

test/types.generated-with-options-postgrest13.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type Database = {
44
// This is a dummy non existent schema to allow automatically passing down options
55
// to the instanciated client at type levels from the introspected database
66
__internal_supabase: {
7-
postgrestVersion: 13
7+
postgrestVersion: '13.0.12'
88
// We make this still abide to `GenericSchema` to allow types helpers bellow to work the same
99
Tables: {
1010
[_ in never]: never

0 commit comments

Comments
 (0)