@@ -2,7 +2,7 @@ import PostgrestQueryBuilder from './PostgrestQueryBuilder'
2
2
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
3
3
import PostgrestBuilder from './PostgrestBuilder'
4
4
import { DEFAULT_HEADERS } from './constants'
5
- import { Fetch , GenericSchema } from './types'
5
+ import { Fetch , GenericSchema , ClientServerOptions , GetGenericDatabaseWithOptions } from './types'
6
6
7
7
/**
8
8
* PostgREST client.
@@ -16,11 +16,16 @@ import { Fetch, GenericSchema } from './types'
16
16
*/
17
17
export default class PostgrestClient <
18
18
Database = any ,
19
- SchemaName extends string & keyof Database = 'public' extends keyof Database
19
+ ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions <
20
+ Database ,
21
+ { PostgrestVersion : '12' }
22
+ > [ 'options' ] ,
23
+ SchemaName extends string &
24
+ keyof GetGenericDatabaseWithOptions < Database > [ 'db' ] = 'public' extends keyof GetGenericDatabaseWithOptions < Database > [ 'db' ]
20
25
? 'public'
21
- : string & keyof Database ,
22
- Schema extends GenericSchema = Database [ SchemaName ] extends GenericSchema
23
- ? Database [ SchemaName ]
26
+ : string & keyof GetGenericDatabaseWithOptions < Database > [ 'db' ] ,
27
+ Schema extends GenericSchema = GetGenericDatabaseWithOptions < Database > [ 'db' ] [ SchemaName ] extends GenericSchema
28
+ ? GetGenericDatabaseWithOptions < Database > [ 'db' ] [ SchemaName ]
24
29
: any
25
30
> {
26
31
url : string
@@ -59,16 +64,16 @@ export default class PostgrestClient<
59
64
from <
60
65
TableName extends string & keyof Schema [ 'Tables' ] ,
61
66
Table extends Schema [ 'Tables' ] [ TableName ]
62
- > ( relation : TableName ) : PostgrestQueryBuilder < Schema , Table , TableName >
67
+ > ( relation : TableName ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName >
63
68
from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
64
69
relation : ViewName
65
- ) : PostgrestQueryBuilder < Schema , View , ViewName >
70
+ ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName >
66
71
/**
67
72
* Perform a query on a table or a view.
68
73
*
69
74
* @param relation - The table or view name to query
70
75
*/
71
- from ( relation : string ) : PostgrestQueryBuilder < Schema , any , any > {
76
+ from ( relation : string ) : PostgrestQueryBuilder < ClientOptions , Schema , any , any > {
72
77
const url = new URL ( `${ this . url } /${ relation } ` )
73
78
return new PostgrestQueryBuilder ( url , {
74
79
headers : { ...this . headers } ,
@@ -84,10 +89,11 @@ export default class PostgrestClient<
84
89
*
85
90
* @param schema - The schema to query
86
91
*/
87
- schema < DynamicSchema extends string & keyof Database > (
92
+ schema < DynamicSchema extends string & keyof GetGenericDatabaseWithOptions < Database > [ 'db' ] > (
88
93
schema : DynamicSchema
89
94
) : PostgrestClient <
90
95
Database ,
96
+ ClientOptions ,
91
97
DynamicSchema ,
92
98
Database [ DynamicSchema ] extends GenericSchema ? Database [ DynamicSchema ] : any
93
99
> {
@@ -134,6 +140,7 @@ export default class PostgrestClient<
134
140
count ?: 'exact' | 'planned' | 'estimated'
135
141
} = { }
136
142
) : PostgrestFilterBuilder <
143
+ ClientOptions ,
137
144
Schema ,
138
145
Fn [ 'Returns' ] extends any [ ]
139
146
? Fn [ 'Returns' ] [ number ] extends Record < string , unknown >
@@ -176,6 +183,6 @@ export default class PostgrestClient<
176
183
body,
177
184
fetch : this . fetch ,
178
185
allowEmpty : false ,
179
- } as unknown as PostgrestBuilder < Fn [ 'Returns' ] > )
186
+ } as unknown as PostgrestBuilder < ClientOptions , Fn [ 'Returns' ] > )
180
187
}
181
188
}
0 commit comments