Skip to content

Commit 9d1dce9

Browse files
committed
Mark handler methods as 'private'
1 parent 63e15d1 commit 9d1dce9

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

packages/pg/lib/client.js

+48-47
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ class Client extends EventEmitter {
141141
if (this._connectionCallback) {
142142
this._connectionCallback(error)
143143
} else {
144-
this.handleErrorWhileConnected(error)
144+
this._handleErrorEvent(error)
145145
}
146146
} else if (!this._connectionError) {
147-
this.handleErrorWhileConnected(error)
147+
this._handleErrorEvent(error)
148148
}
149149
}
150150

@@ -173,27 +173,27 @@ class Client extends EventEmitter {
173173

174174
_attachListeners(con) {
175175
// password request handling
176-
con.on('authenticationCleartextPassword', this.handleAuthenticationCleartextPassword.bind(this))
176+
con.on('authenticationCleartextPassword', this._handleAuthCleartextPassword.bind(this))
177177
// password request handling
178-
con.on('authenticationMD5Password', this.handleAuthenticationMD5Password.bind(this))
178+
con.on('authenticationMD5Password', this._handleAuthMD5Password.bind(this))
179179
// password request handling (SASL)
180-
con.on('authenticationSASL', this.handleAuthenticationSASL.bind(this))
181-
con.on('authenticationSASLContinue', this.handleAuthenticationSASLContinue.bind(this))
182-
con.on('authenticationSASLFinal', this.handleAuthenticationSASLFinal.bind(this))
183-
con.on('backendKeyData', this.handleBackendKeyData.bind(this))
184-
con.on('error', this.handleErrorWhileConnecting)
185-
con.on('errorMessage', this.handleErrorMessage)
186-
con.on('readyForQuery', this.handleReadyForQuery.bind(this))
187-
con.on('notice', this.handleNotice.bind(this))
188-
con.on('rowDescription', this.handleRowDescription.bind(this))
189-
con.on('dataRow', this.handleDataRow.bind(this))
190-
con.on('portalSuspended', this.handlePortalSuspended.bind(this))
191-
con.on('emptyQuery', this.handleEmptyQuery.bind(this))
192-
con.on('commandComplete', this.handleCommandComplete.bind(this))
193-
con.on('parseComplete', this.handleParseComplete.bind(this))
194-
con.on('copyInResponse', this.handleCopyInResponse.bind(this))
195-
con.on('copyData', this.handleCopyData.bind(this))
196-
con.on('notification', this.handleNotification.bind(this))
180+
con.on('authenticationSASL', this._handleAuthSASL.bind(this))
181+
con.on('authenticationSASLContinue', this._handleAuthSASLContinue.bind(this))
182+
con.on('authenticationSASLFinal', this._handleAuthSASLFinal.bind(this))
183+
con.on('backendKeyData', this._handleBackendKeyData.bind(this))
184+
con.on('error', this._handleErrorEvent)
185+
con.on('errorMessage', this._handleErrorMessage)
186+
con.on('readyForQuery', this._handleReadyForQuery.bind(this))
187+
con.on('notice', this._handleNotice.bind(this))
188+
con.on('rowDescription', this._handleRowDescription.bind(this))
189+
con.on('dataRow', this._handleDataRow.bind(this))
190+
con.on('portalSuspended', this._handlePortalSuspended.bind(this))
191+
con.on('emptyQuery', this._handleEmptyQuery.bind(this))
192+
con.on('commandComplete', this._handleCommandComplete.bind(this))
193+
con.on('parseComplete', this._handleParseComplete.bind(this))
194+
con.on('copyInResponse', this._handleCopyInResponse.bind(this))
195+
con.on('copyData', this._handleCopyData.bind(this))
196+
con.on('notification', this._handleNotification.bind(this))
197197
}
198198

199199
// TODO(bmc): deprecate pgpass "built in" integration since this.password can be a function
@@ -232,50 +232,47 @@ class Client extends EventEmitter {
232232
}
233233
}
234234

235-
handleAuthenticationCleartextPassword(msg) {
235+
_handleAuthCleartextPassword(msg) {
236236
this._checkPgPass(() => {
237237
this.connection.password(this.password)
238238
})
239239
}
240240

241-
handleAuthenticationMD5Password(msg) {
241+
_handleAuthMD5Password(msg) {
242242
this._checkPgPass((msg) => {
243243
const hashedPassword = utils.postgresMd5PasswordHash(this.user, this.password, msg.salt)
244244
this.connection.password(hashedPassword)
245245
})
246246
}
247247

248-
handleAuthenticationSASL(msg) {
248+
_handleAuthSASL(msg) {
249249
this._checkPgPass((msg) => {
250250
this.saslSession = sasl.startSession(msg.mechanisms)
251251
const con = this.connection
252252
con.sendSASLInitialResponseMessage(saslSession.mechanism, saslSession.response)
253253
})
254254
}
255255

256-
handleAuthenticationSASLContinue(msg) {
256+
_handleAuthSASLContinue(msg) {
257257
const { saslSession } = this
258258
sasl.continueSession(saslSession, this.password, msg.data)
259259
con.sendSCRAMClientFinalMessage(saslSession.response)
260260
}
261261

262-
handleAuthenticationSASLFinal(msg) {
262+
_handleAuthSASLFinal(msg) {
263263
sasl.finalizeSession(this.saslSession, msg.data)
264264
this.saslSession = null
265265
}
266266

267-
handleBackendKeyData(msg) {
267+
_handleBackendKeyData(msg) {
268268
this.processID = msg.processID
269269
this.secretKey = msg.secretKey
270270
}
271271

272-
handleReadyForQuery(msg) {
272+
_handleReadyForQuery(msg) {
273273
if (this._connecting) {
274274
this._connecting = false
275275
this._connected = true
276-
const con = this.connection
277-
con.removeListener('error', this.handleErrorWhileConnecting)
278-
con.on('error', this.handleErrorWhileConnected)
279276
clearTimeout(this.connectionTimeoutHandle)
280277

281278
// process possible callback argument to Client#connect
@@ -296,8 +293,9 @@ class Client extends EventEmitter {
296293
this._pulseQueryQueue()
297294
}
298295

299-
// if we receieve an error event or error message during the connection process we handle it here
300-
handleErrorWhileConnecting = (err) => {
296+
// if we receieve an error event or error message
297+
// during the connection process we handle it here
298+
_handleErrorWhileConnecting = (err) => {
301299
if (this._connectionError) {
302300
// TODO(bmc): this is swallowing errors - we shouldn't do this
303301
return
@@ -313,54 +311,57 @@ class Client extends EventEmitter {
313311
// if we're connected and we receive an error event from the connection
314312
// this means the socket is dead - do a hard abort of all queries and emit
315313
// the socket error on the client as well
316-
handleErrorWhileConnected = (err) => {
314+
_handleErrorEvent = (err) => {
315+
if (this._connecting) {
316+
return this._handleErrorWhileConnecting(err)
317+
}
317318
this._queryable = false
318319
this._errorAllQueries(err)
319320
this.emit('error', err)
320321
}
321322

322323
// handle error messages from the postgres backend
323-
handleErrorMessage = (msg) => {
324+
_handleErrorMessage = (msg) => {
324325
if (this._connecting) {
325-
return this.handleErrorWhileConnecting(msg)
326+
return this._handleErrorWhileConnecting(msg)
326327
}
327328
const activeQuery = this.activeQuery
328329

329330
if (!activeQuery) {
330-
this.handleErrorWhileConnected(msg)
331+
this._handleErrorEvent(msg)
331332
return
332333
}
333334

334335
this.activeQuery = null
335336
activeQuery.handleError(msg, this.connection)
336337
}
337338

338-
handleRowDescription(msg) {
339+
_handleRowDescription(msg) {
339340
// delegate rowDescription to active query
340341
this.activeQuery.handleRowDescription(msg)
341342
}
342343

343-
handleDataRow(msg) {
344+
_handleDataRow(msg) {
344345
// delegate dataRow to active query
345346
this.activeQuery.handleDataRow(msg)
346347
}
347348

348-
handlePortalSuspended(msg) {
349+
_handlePortalSuspended(msg) {
349350
// delegate portalSuspended to active query
350351
this.activeQuery.handlePortalSuspended(this.connection)
351352
}
352353

353-
handleEmptyQuery(msg) {
354+
_handleEmptyQuery(msg) {
354355
// delegate emptyQuery to active query
355356
this.activeQuery.handleEmptyQuery(this.connection)
356357
}
357358

358-
handleCommandComplete(msg) {
359+
_handleCommandComplete(msg) {
359360
// delegate commandComplete to active query
360361
this.activeQuery.handleCommandComplete(msg, this.connection)
361362
}
362363

363-
handleParseComplete(msg) {
364+
_handleParseComplete(msg) {
364365
// if a prepared statement has a name and properly parses
365366
// we track that its already been executed so we don't parse
366367
// it again on the same client
@@ -369,19 +370,19 @@ class Client extends EventEmitter {
369370
}
370371
}
371372

372-
handleCopyInResponse(msg) {
373+
_handleCopyInResponse(msg) {
373374
this.activeQuery.handleCopyInResponse(this.connection)
374375
}
375376

376-
handleCopyData(msg) {
377+
_handleCopyData(msg) {
377378
this.activeQuery.handleCopyData(msg, this.connection)
378379
}
379380

380-
handleNotification(msg) {
381+
_handleNotification(msg) {
381382
this.emit('notification', msg)
382383
}
383384

384-
handleNotice(msg) {
385+
_handleNotice(msg) {
385386
this.emit('notice', msg)
386387
}
387388

0 commit comments

Comments
 (0)