@@ -38,18 +38,43 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep
3838 super ( query ) ;
3939 }
4040
41- async execute ( placeholderValues : Record < string , unknown > | undefined = { } ) : Promise < T [ 'execute' ] > {
41+ async execute ( placeholderValues : Record < string , unknown > | undefined ) : Promise < T [ 'execute' ] > ;
42+ /** @internal */
43+ async execute ( placeholderValues : Record < string , unknown > | undefined , token ?: string ) : Promise < T [ 'execute' ] > ;
44+ /** @internal */
45+ async execute (
46+ placeholderValues : Record < string , unknown > | undefined = { } ,
47+ token : string | undefined = this . authToken ,
48+ ) : Promise < T [ 'execute' ] > {
4249 const params = fillPlaceholders ( this . query . params , placeholderValues ) ;
4350
4451 this . logger . logQuery ( this . query . sql , params ) ;
4552
4653 const { fields, client, query, customResultMapper } = this ;
4754
4855 if ( ! fields && ! customResultMapper ) {
49- return client ( query . sql , params , rawQueryConfig ) ;
56+ return client (
57+ query . sql ,
58+ params ,
59+ token === undefined
60+ ? rawQueryConfig
61+ : {
62+ ...rawQueryConfig ,
63+ authToken : token ,
64+ } ,
65+ ) ;
5066 }
5167
52- const result = await client ( query . sql , params , queryConfig ) ;
68+ const result = await client (
69+ query . sql ,
70+ params ,
71+ token === undefined
72+ ? queryConfig
73+ : {
74+ ...queryConfig ,
75+ authToken : token ,
76+ } ,
77+ ) ;
5378
5479 return this . mapResult ( result ) ;
5580 }
@@ -71,13 +96,26 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep
7196 all ( placeholderValues : Record < string , unknown > | undefined = { } ) : Promise < T [ 'all' ] > {
7297 const params = fillPlaceholders ( this . query . params , placeholderValues ) ;
7398 this . logger . logQuery ( this . query . sql , params ) ;
74- return this . client ( this . query . sql , params , rawQueryConfig ) . then ( ( result ) => result . rows ) ;
99+ return this . client (
100+ this . query . sql ,
101+ params ,
102+ this . authToken === undefined ? rawQueryConfig : {
103+ ...rawQueryConfig ,
104+ authToken : this . authToken ,
105+ } ,
106+ ) . then ( ( result ) => result . rows ) ;
75107 }
76108
77- values ( placeholderValues : Record < string , unknown > | undefined = { } ) : Promise < T [ 'values' ] > {
109+ values ( placeholderValues : Record < string , unknown > | undefined ) : Promise < T [ 'values' ] > ;
110+ /** @internal */
111+ values ( placeholderValues : Record < string , unknown > | undefined , token ?: string ) : Promise < T [ 'values' ] > ;
112+ /** @internal */
113+ values ( placeholderValues : Record < string , unknown > | undefined = { } , token ?: string ) : Promise < T [ 'values' ] > {
78114 const params = fillPlaceholders ( this . query . params , placeholderValues ) ;
79115 this . logger . logQuery ( this . query . sql , params ) ;
80- return this . client ( this . query . sql , params , { arrayMode : true , fullResults : true } ) . then ( ( result ) => result . rows ) ;
116+ return this . client ( this . query . sql , params , { arrayMode : true , fullResults : true , authToken : token } ) . then ( (
117+ result ,
118+ ) => result . rows ) ;
81119 }
82120
83121 /** @internal */
@@ -125,7 +163,9 @@ export class NeonHttpSession<
125163 ) ;
126164 }
127165
128- async batch < U extends BatchItem < 'pg' > , T extends Readonly < [ U , ...U [ ] ] > > ( queries : T ) {
166+ async batch < U extends BatchItem < 'pg' > , T extends Readonly < [ U , ...U [ ] ] > > (
167+ queries : T ,
168+ ) {
129169 const preparedQueries : PreparedQuery [ ] = [ ] ;
130170 const builtQueries : NeonQueryPromise < any , true > [ ] = [ ] ;
131171
@@ -143,7 +183,7 @@ export class NeonHttpSession<
143183
144184 const batchResults = await this . client . transaction ( builtQueries , queryConfig ) ;
145185
146- return batchResults . map ( ( result , i ) => preparedQueries [ i ] ! . mapResult ( result , true ) ) ;
186+ return batchResults . map ( ( result , i ) => preparedQueries [ i ] ! . mapResult ( result , true ) ) as any ;
147187 }
148188
149189 // change return type to QueryRows<true>
@@ -161,8 +201,12 @@ export class NeonHttpSession<
161201 return this . client ( query , params , { arrayMode : false , fullResults : true } ) ;
162202 }
163203
164- override async count ( sql : SQL ) : Promise < number > {
165- const res = await this . execute < { rows : [ { count : string } ] } > ( sql ) ;
204+ override async count ( sql : SQL ) : Promise < number > ;
205+ /** @internal */
206+ override async count ( sql : SQL , token ?: string ) : Promise < number > ;
207+ /** @internal */
208+ override async count ( sql : SQL , token ?: string ) : Promise < number > {
209+ const res = await this . execute < { rows : [ { count : string } ] } > ( sql , token ) ;
166210
167211 return Number (
168212 res [ 'rows' ] [ 0 ] [ 'count' ] ,
0 commit comments