@@ -3,7 +3,7 @@ import EventEmitter from 'node:events'
33
44import { SSLError , ConnectionError , ClientStateError , AuthenticationError } from './errors.js'
55import { Query } from './query.js'
6- import { FrontendMessage } from './frontend_message.js'
6+ import { StartupMessage , SSLRequestMessage } from './frontend_message.js'
77import { ParseMessageFromBuffer } from './backend_message.js'
88import { AuthenticationMethods } from './authentication.js' ;
99import { startTLS } from './starttls.js' ;
@@ -52,7 +52,7 @@ class Connection extends EventEmitter {
5252 this . connection . setKeepAlive ( true ) ;
5353 }
5454 if ( this . connectionOptions . ssl ) {
55- this . writeMessage ( new FrontendMessage . SSLRequest ) ;
55+ this . writeMessage ( new SSLRequestMessage ) ;
5656 this . connection . once ( 'data' , function ( buffer ) {
5757 var conn , err , sslOptions ;
5858 if ( 'S' === buffer . toString ( 'utf-8' ) ) {
@@ -110,7 +110,7 @@ class Connection extends EventEmitter {
110110 this . _onError ( error ) ;
111111 }
112112 if ( this . connection . connected ) {
113- this . writeMessage ( new FrontendMessage . Terminate ( ) ) ;
113+ this . writeMessage ( new TerminateMessage ( ) ) ;
114114 }
115115 return this . connection . end ( ) ;
116116 }
@@ -184,7 +184,7 @@ class Connection extends EventEmitter {
184184 } ) ;
185185 case AuthenticationMethods . CLEARTEXT_PASSWORD :
186186 case AuthenticationMethods . MD5_PASSWORD :
187- this . writeMessage ( new FrontendMessage . Password ( this . connectionOptions . password , msg . method , {
187+ this . writeMessage ( new PasswordMessage ( this . connectionOptions . password , msg . method , {
188188 salt : msg . salt ,
189189 user : this . connectionOptions . user
190190 } ) ) ;
@@ -195,7 +195,7 @@ class Connection extends EventEmitter {
195195 }
196196
197197 this . connection . on ( 'data' , this . _onData . bind ( this ) ) ;
198- this . writeMessage ( new FrontendMessage . Startup ( this . connectionOptions . user , this . connectionOptions . database ) ) ;
198+ this . writeMessage ( new StartupMessage ( this . connectionOptions . user , this . connectionOptions . database ) ) ;
199199
200200 this . once ( 'ErrorResponse' , authenticationFailureHandler ) ;
201201 this . once ( 'Authentication' , authenticationHandler ) ;
@@ -312,24 +312,23 @@ class Connection extends EventEmitter {
312312 }
313313
314314 _onData ( buffer ) {
315- var bufferedData , message , size ;
315+
316316 if ( this . incomingData . length === 0 ) {
317317 this . incomingData = buffer ;
318318 } else {
319- bufferedData = Buffer . alloc ( this . incomingData . length + buffer . length ) ;
319+ const bufferedData = Buffer . alloc ( this . incomingData . length + buffer . length ) ;
320320 this . incomingData . copy ( bufferedData ) ;
321321 buffer . copy ( bufferedData , this . incomingData . length ) ;
322322 this . incomingData = bufferedData ;
323323 }
324324 while ( this . incomingData . length >= 5 ) {
325- size = this . incomingData . readUInt32BE ( 1 ) ;
325+ const size = this . incomingData . readUInt32BE ( 1 ) ;
326326 if ( size + 1 <= this . incomingData . length ) {
327- message = ParseMessageFromBuffer ( this . incomingData . slice ( 0 , size + 1 ) ) ;
328- console . debug ( typeof message . constructor . name ) ;
327+ const msg = ParseMessageFromBuffer ( this . incomingData . slice ( 0 , size + 1 ) ) ;
329328 if ( this . debug ) {
330- console . debug ( '<=' , message ) ;
329+ console . debug ( '<=' , msg ) ;
331330 }
332- this . emit ( message . constructor . name , message ) ;
331+ this . emit ( msg . constructor . name , msg ) ;
333332 this . incomingData = this . incomingData . slice ( size + 1 ) ;
334333 } else {
335334 break ;
@@ -371,7 +370,7 @@ class Connection extends EventEmitter {
371370
372371 writeMessage ( msg , callback ) {
373372 if ( this . debug ) {
374- console . log ( '=>' , msg ) ;
373+ console . debug ( '=>' , msg ) ;
375374 }
376375 return this . connection . write ( msg . toBuffer ( ) , callback ) ;
377376 } ;
0 commit comments