Skip to content

Commit 3be45ad

Browse files
committed
chore: use string for postgrestVersion
Allows loosy matching over the version minor
1 parent 4110185 commit 3be45ad

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

src/PostgrestClient.ts

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

src/select-query-parser/result.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {
2121
SelectQueryError,
2222
} from './utils'
2323

24-
export type SpreadOnManyEnabled<postgrestVersion extends number | undefined> =
25-
postgrestVersion extends 13 ? true : false
24+
export type SpreadOnManyEnabled<postgrestVersion extends string | undefined> =
25+
postgrestVersion extends `13${string}` ? true : false
2626

2727
/**
2828
* Main entry point for constructing the result type of a PostgREST query.

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-
type PostgRESTMajorVersion = number
7574
export type ClientServerOptions = {
76-
postgrestVersion?: PostgRESTMajorVersion
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)