@@ -86,9 +86,7 @@ function assertSuccessfulAuthentication(auth_message: Message) {
86
86
throw new PostgresError ( parseNoticeMessage ( auth_message ) ) ;
87
87
}
88
88
89
- if (
90
- auth_message . type !== INCOMING_AUTHENTICATION_MESSAGES . AUTHENTICATION
91
- ) {
89
+ if ( auth_message . type !== INCOMING_AUTHENTICATION_MESSAGES . AUTHENTICATION ) {
92
90
throw new Error ( `Unexpected auth response: ${ auth_message . type } .` ) ;
93
91
}
94
92
@@ -118,10 +116,7 @@ export class Connection {
118
116
#onDisconnection: ( ) => Promise < void > ;
119
117
#packetWriter = new PacketWriter ( ) ;
120
118
#pid?: number ;
121
- #queryLock: DeferredStack < undefined > = new DeferredStack (
122
- 1 ,
123
- [ undefined ] ,
124
- ) ;
119
+ #queryLock: DeferredStack < undefined > = new DeferredStack ( 1 , [ undefined ] ) ;
125
120
// TODO
126
121
// Find out what the secret key is for
127
122
#secretKey?: number ;
@@ -180,10 +175,7 @@ export class Connection {
180
175
async #serverAcceptsTLS( ) : Promise < boolean > {
181
176
const writer = this . #packetWriter;
182
177
writer . clear ( ) ;
183
- writer
184
- . addInt32 ( 8 )
185
- . addInt32 ( 80877103 )
186
- . join ( ) ;
178
+ writer . addInt32 ( 8 ) . addInt32 ( 80877103 ) . join ( ) ;
187
179
188
180
await this . #bufWriter. write ( writer . flush ( ) ) ;
189
181
await this . #bufWriter. flush ( ) ;
@@ -216,16 +208,20 @@ export class Connection {
216
208
// TODO: recognize other parameters
217
209
writer . addCString ( "user" ) . addCString ( this . #connection_params. user ) ;
218
210
writer . addCString ( "database" ) . addCString ( this . #connection_params. database ) ;
219
- writer . addCString ( "application_name" ) . addCString (
220
- this . #connection_params . applicationName ,
221
- ) ;
211
+ writer
212
+ . addCString ( "application_name" )
213
+ . addCString ( this . #connection_params . applicationName ) ;
222
214
223
215
const connection_options = Object . entries ( this . #connection_params. options ) ;
224
216
if ( connection_options . length > 0 ) {
225
217
// The database expects options in the --key=value
226
- writer . addCString ( "options" ) . addCString (
227
- connection_options . map ( ( [ key , value ] ) => `--${ key } =${ value } ` ) . join ( " " ) ,
228
- ) ;
218
+ writer
219
+ . addCString ( "options" )
220
+ . addCString (
221
+ connection_options
222
+ . map ( ( [ key , value ] ) => `--${ key } =${ value } ` )
223
+ . join ( " " ) ,
224
+ ) ;
229
225
}
230
226
231
227
// terminator after all parameters were writter
@@ -236,10 +232,7 @@ export class Connection {
236
232
237
233
writer . clear ( ) ;
238
234
239
- const finalBuffer = writer
240
- . addInt32 ( bodyLength )
241
- . add ( bodyBuffer )
242
- . join ( ) ;
235
+ const finalBuffer = writer . addInt32 ( bodyLength ) . add ( bodyBuffer ) . join ( ) ;
243
236
244
237
await this . #bufWriter. write ( finalBuffer ) ;
245
238
await this . #bufWriter. flush ( ) ;
@@ -248,7 +241,7 @@ export class Connection {
248
241
}
249
242
250
243
async #openConnection( options : ConnectOptions ) {
251
- // @ts -ignore This will throw in runtime if the options passed to it are socket related and deno is running
244
+ // @ts -expect-error This will throw in runtime if the options passed to it are socket related and deno is running
252
245
// on stable
253
246
this . #conn = await Deno . connect ( options ) ;
254
247
this . #bufWriter = new BufWriter ( this . #conn) ;
@@ -257,9 +250,7 @@ export class Connection {
257
250
258
251
async #openSocketConnection( path : string , port : number ) {
259
252
if ( Deno . build . os === "windows" ) {
260
- throw new Error (
261
- "Socket connection is only available on UNIX systems" ,
262
- ) ;
253
+ throw new Error ( "Socket connection is only available on UNIX systems" ) ;
263
254
}
264
255
const socket = await Deno . stat ( path ) ;
265
256
@@ -296,10 +287,7 @@ export class Connection {
296
287
this . connected = false ;
297
288
this . #packetWriter = new PacketWriter ( ) ;
298
289
this . #pid = undefined ;
299
- this . #queryLock = new DeferredStack (
300
- 1 ,
301
- [ undefined ] ,
302
- ) ;
290
+ this . #queryLock = new DeferredStack ( 1 , [ undefined ] ) ;
303
291
this . #secretKey = undefined ;
304
292
this . #tls = undefined ;
305
293
this . #transport = undefined ;
@@ -319,14 +307,10 @@ export class Connection {
319
307
this . #closeConnection( ) ;
320
308
321
309
const {
322
- hostname,
323
310
host_type,
311
+ hostname,
324
312
port,
325
- tls : {
326
- enabled : tls_enabled ,
327
- enforce : tls_enforced ,
328
- caCertificates,
329
- } ,
313
+ tls : { caCertificates, enabled : tls_enabled , enforce : tls_enforced } ,
330
314
} = this . #connection_params;
331
315
332
316
if ( host_type === "socket" ) {
@@ -341,12 +325,11 @@ export class Connection {
341
325
342
326
if ( tls_enabled ) {
343
327
// If TLS is disabled, we don't even try to connect.
344
- const accepts_tls = await this . #serverAcceptsTLS( )
345
- . catch ( ( e ) => {
346
- // Make sure to close the connection if the TLS validation throws
347
- this . #closeConnection( ) ;
348
- throw e ;
349
- } ) ;
328
+ const accepts_tls = await this . #serverAcceptsTLS( ) . catch ( ( e ) => {
329
+ // Make sure to close the connection if the TLS validation throws
330
+ this . #closeConnection( ) ;
331
+ throw e ;
332
+ } ) ;
350
333
351
334
// https://www.postgresql.org/docs/14/protocol-flow.html#id-1.10.5.7.11
352
335
if ( accepts_tls ) {
@@ -657,24 +640,18 @@ export class Connection {
657
640
`Unexpected message in SASL finalization: ${ maybe_sasl_continue . type } ` ,
658
641
) ;
659
642
}
660
- const sasl_final = utf8 . decode (
661
- maybe_sasl_final . reader . readAllBytes ( ) ,
662
- ) ;
643
+ const sasl_final = utf8 . decode ( maybe_sasl_final . reader . readAllBytes ( ) ) ;
663
644
await client . receiveResponse ( sasl_final ) ;
664
645
665
646
// Return authentication result
666
647
return this . #readMessage( ) ;
667
648
}
668
649
669
- async #simpleQuery(
670
- query : Query < ResultType . ARRAY > ,
671
- ) : Promise < QueryArrayResult > ;
650
+ async #simpleQuery( query : Query < ResultType . ARRAY > ) : Promise < QueryArrayResult > ;
672
651
async #simpleQuery(
673
652
query : Query < ResultType . OBJECT > ,
674
653
) : Promise < QueryObjectResult > ;
675
- async #simpleQuery(
676
- query : Query < ResultType > ,
677
- ) : Promise < QueryResult > {
654
+ async #simpleQuery( query : Query < ResultType > ) : Promise < QueryResult > {
678
655
this . #packetWriter. clear ( ) ;
679
656
680
657
const buffer = this . #packetWriter. addCString ( query . text ) . flush ( 0x51 ) ;
@@ -757,9 +734,7 @@ export class Connection {
757
734
await this . #bufWriter. write ( buffer ) ;
758
735
}
759
736
760
- async #appendArgumentsToMessage< T extends ResultType > (
761
- query : Query < T > ,
762
- ) {
737
+ async #appendArgumentsToMessage< T extends ResultType > ( query : Query < T > ) {
763
738
this . #packetWriter. clear ( ) ;
764
739
765
740
const hasBinaryArgs = query . args . some ( ( arg ) => arg instanceof Uint8Array ) ;
@@ -830,10 +805,7 @@ export class Connection {
830
805
831
806
// TODO
832
807
// Rename process function to a more meaningful name and move out of class
833
- async #processErrorUnsafe(
834
- msg : Message ,
835
- recoverable = true ,
836
- ) {
808
+ async #processErrorUnsafe( msg : Message , recoverable = true ) {
837
809
const error = new PostgresError ( parseNoticeMessage ( msg ) ) ;
838
810
if ( recoverable ) {
839
811
let maybe_ready_message = await this . #readMessage( ) ;
@@ -930,15 +902,9 @@ export class Connection {
930
902
return result ;
931
903
}
932
904
933
- async query (
934
- query : Query < ResultType . ARRAY > ,
935
- ) : Promise < QueryArrayResult > ;
936
- async query (
937
- query : Query < ResultType . OBJECT > ,
938
- ) : Promise < QueryObjectResult > ;
939
- async query (
940
- query : Query < ResultType > ,
941
- ) : Promise < QueryResult > {
905
+ async query ( query : Query < ResultType . ARRAY > ) : Promise < QueryArrayResult > ;
906
+ async query ( query : Query < ResultType . OBJECT > ) : Promise < QueryObjectResult > ;
907
+ async query ( query : Query < ResultType > ) : Promise < QueryResult > {
942
908
if ( ! this . connected ) {
943
909
await this . startup ( true ) ;
944
910
}
0 commit comments