11import PostgrestBuilder from './PostgrestBuilder'
22import PostgrestFilterBuilder from './PostgrestFilterBuilder'
33import { GetResult } from './select-query-parser/result'
4- import { Fetch , GenericSchema , GenericTable , GenericView } from './types'
4+ import { ClientServerOptions , Fetch , GenericSchema , GenericTable , GenericView } from './types'
55
66export default class PostgrestQueryBuilder <
7+ ClientOptions extends ClientServerOptions ,
78 Schema extends GenericSchema ,
89 Relation extends GenericTable | GenericView ,
910 RelationName = unknown ,
@@ -56,7 +57,14 @@ export default class PostgrestQueryBuilder<
5657 */
5758 select <
5859 Query extends string = '*' ,
59- ResultOne = GetResult < Schema , Relation [ 'Row' ] , RelationName , Relationships , Query >
60+ ResultOne = GetResult <
61+ Schema ,
62+ Relation [ 'Row' ] ,
63+ RelationName ,
64+ Relationships ,
65+ Query ,
66+ ClientOptions
67+ >
6068 > (
6169 columns ?: Query ,
6270 {
@@ -67,6 +75,7 @@ export default class PostgrestQueryBuilder<
6775 count ?: 'exact' | 'planned' | 'estimated'
6876 } = { }
6977 ) : PostgrestFilterBuilder <
78+ ClientOptions ,
7079 Schema ,
7180 Relation [ 'Row' ] ,
7281 ResultOne [ ] ,
@@ -101,7 +110,7 @@ export default class PostgrestQueryBuilder<
101110 schema : this . schema ,
102111 fetch : this . fetch ,
103112 allowEmpty : false ,
104- } as unknown as PostgrestBuilder < ResultOne [ ] > )
113+ } as unknown as PostgrestBuilder < ClientOptions , ResultOne [ ] > )
105114 }
106115
107116 // TODO(v3): Make `defaultToNull` consistent for both single & bulk inserts.
@@ -110,14 +119,30 @@ export default class PostgrestQueryBuilder<
110119 options ?: {
111120 count ?: 'exact' | 'planned' | 'estimated'
112121 }
113- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
122+ ) : PostgrestFilterBuilder <
123+ ClientOptions ,
124+ Schema ,
125+ Relation [ 'Row' ] ,
126+ null ,
127+ RelationName ,
128+ Relationships ,
129+ 'POST'
130+ >
114131 insert < Row extends Relation extends { Insert : unknown } ? Relation [ 'Insert' ] : never > (
115132 values : Row [ ] ,
116133 options ?: {
117134 count ?: 'exact' | 'planned' | 'estimated'
118135 defaultToNull ?: boolean
119136 }
120- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
137+ ) : PostgrestFilterBuilder <
138+ ClientOptions ,
139+ Schema ,
140+ Relation [ 'Row' ] ,
141+ null ,
142+ RelationName ,
143+ Relationships ,
144+ 'POST'
145+ >
121146 /**
122147 * Perform an INSERT into the table or view.
123148 *
@@ -153,7 +178,15 @@ export default class PostgrestQueryBuilder<
153178 count ?: 'exact' | 'planned' | 'estimated'
154179 defaultToNull ?: boolean
155180 } = { }
156- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' > {
181+ ) : PostgrestFilterBuilder <
182+ ClientOptions ,
183+ Schema ,
184+ Relation [ 'Row' ] ,
185+ null ,
186+ RelationName ,
187+ Relationships ,
188+ 'POST'
189+ > {
157190 const method = 'POST'
158191
159192 const prefersHeaders = [ ]
@@ -184,7 +217,7 @@ export default class PostgrestQueryBuilder<
184217 body : values ,
185218 fetch : this . fetch ,
186219 allowEmpty : false ,
187- } as unknown as PostgrestBuilder < null > )
220+ } as unknown as PostgrestBuilder < ClientOptions , null > )
188221 }
189222
190223 // TODO(v3): Make `defaultToNull` consistent for both single & bulk upserts.
@@ -195,7 +228,15 @@ export default class PostgrestQueryBuilder<
195228 ignoreDuplicates ?: boolean
196229 count ?: 'exact' | 'planned' | 'estimated'
197230 }
198- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
231+ ) : PostgrestFilterBuilder <
232+ ClientOptions ,
233+ Schema ,
234+ Relation [ 'Row' ] ,
235+ null ,
236+ RelationName ,
237+ Relationships ,
238+ 'POST'
239+ >
199240 upsert < Row extends Relation extends { Insert : unknown } ? Relation [ 'Insert' ] : never > (
200241 values : Row [ ] ,
201242 options ?: {
@@ -204,7 +245,15 @@ export default class PostgrestQueryBuilder<
204245 count ?: 'exact' | 'planned' | 'estimated'
205246 defaultToNull ?: boolean
206247 }
207- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
248+ ) : PostgrestFilterBuilder <
249+ ClientOptions ,
250+ Schema ,
251+ Relation [ 'Row' ] ,
252+ null ,
253+ RelationName ,
254+ Relationships ,
255+ 'POST'
256+ >
208257 /**
209258 * Perform an UPSERT on the table or view. Depending on the column(s) passed
210259 * to `onConflict`, `.upsert()` allows you to perform the equivalent of
@@ -256,7 +305,15 @@ export default class PostgrestQueryBuilder<
256305 count ?: 'exact' | 'planned' | 'estimated'
257306 defaultToNull ?: boolean
258307 } = { }
259- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' > {
308+ ) : PostgrestFilterBuilder <
309+ ClientOptions ,
310+ Schema ,
311+ Relation [ 'Row' ] ,
312+ null ,
313+ RelationName ,
314+ Relationships ,
315+ 'POST'
316+ > {
260317 const method = 'POST'
261318
262319 const prefersHeaders = [ `resolution=${ ignoreDuplicates ? 'ignore' : 'merge' } -duplicates` ]
@@ -289,7 +346,7 @@ export default class PostgrestQueryBuilder<
289346 body : values ,
290347 fetch : this . fetch ,
291348 allowEmpty : false ,
292- } as unknown as PostgrestBuilder < null > )
349+ } as unknown as PostgrestBuilder < ClientOptions , null > )
293350 }
294351
295352 /**
@@ -320,7 +377,15 @@ export default class PostgrestQueryBuilder<
320377 } : {
321378 count ?: 'exact' | 'planned' | 'estimated'
322379 } = { }
323- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'PATCH' > {
380+ ) : PostgrestFilterBuilder <
381+ ClientOptions ,
382+ Schema ,
383+ Relation [ 'Row' ] ,
384+ null ,
385+ RelationName ,
386+ Relationships ,
387+ 'PATCH'
388+ > {
324389 const method = 'PATCH'
325390 const prefersHeaders = [ ]
326391 if ( this . headers [ 'Prefer' ] ) {
@@ -339,7 +404,7 @@ export default class PostgrestQueryBuilder<
339404 body : values ,
340405 fetch : this . fetch ,
341406 allowEmpty : false ,
342- } as unknown as PostgrestBuilder < null > )
407+ } as unknown as PostgrestBuilder < ClientOptions , null > )
343408 }
344409
345410 /**
@@ -366,6 +431,7 @@ export default class PostgrestQueryBuilder<
366431 } : {
367432 count ?: 'exact' | 'planned' | 'estimated'
368433 } = { } ) : PostgrestFilterBuilder <
434+ ClientOptions ,
369435 Schema ,
370436 Relation [ 'Row' ] ,
371437 null ,
@@ -390,6 +456,6 @@ export default class PostgrestQueryBuilder<
390456 schema : this . schema ,
391457 fetch : this . fetch ,
392458 allowEmpty : false ,
393- } as unknown as PostgrestBuilder < null > )
459+ } as unknown as PostgrestBuilder < ClientOptions , null > )
394460 }
395461}
0 commit comments