Skip to content

Commit db24e0c

Browse files
committed
refactor: rename misleading param
1 parent c2fa440 commit db24e0c

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

src/utils.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -359,29 +359,14 @@ export function uuidV4(): Buffer {
359359
* A helper function for determining `maxWireVersion` between legacy and new topology instances
360360
* @internal
361361
*/
362-
export function maxWireVersion(topologyOrServer?: Connection | Topology | Server): number {
363-
if (topologyOrServer) {
364-
if (topologyOrServer.serverApi?.version) {
362+
export function maxWireVersion(handshakeAware?: Connection | Topology | Server): number {
363+
if (handshakeAware) {
364+
if (handshakeAware.serverApi?.version) {
365365
// We return the max supported wire version for serverAPI.
366366
return MAX_SUPPORTED_WIRE_VERSION;
367367
}
368-
if (topologyOrServer.hello) {
369-
return topologyOrServer.hello.maxWireVersion;
370-
}
371-
372-
if ('lastHello' in topologyOrServer && typeof topologyOrServer.lastHello === 'function') {
373-
const lastHello = topologyOrServer.lastHello();
374-
if (lastHello) {
375-
return lastHello.maxWireVersion;
376-
}
377-
}
378-
379-
if (
380-
topologyOrServer.description &&
381-
'maxWireVersion' in topologyOrServer.description &&
382-
topologyOrServer.description.maxWireVersion != null
383-
) {
384-
return topologyOrServer.description.maxWireVersion;
368+
if (handshakeAware.hello) {
369+
return handshakeAware.hello.maxWireVersion;
385370
}
386371

387372
// This is the fallback case for load balanced mode. If we are building commands the
@@ -391,9 +376,24 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server
391376
// the max wire version so we support retryability. Once we have a min supported
392377
// wire version of 9, then the needsRetryableWriteLabel() check can remove the
393378
// usage of passing the wire version into it.
394-
if (topologyOrServer.loadBalanced) {
379+
if (handshakeAware.loadBalanced) {
395380
return MAX_SUPPORTED_WIRE_VERSION;
396381
}
382+
383+
if ('lastHello' in handshakeAware && typeof handshakeAware.lastHello === 'function') {
384+
const lastHello = handshakeAware.lastHello();
385+
if (lastHello) {
386+
return lastHello.maxWireVersion;
387+
}
388+
}
389+
390+
if (
391+
handshakeAware.description &&
392+
'maxWireVersion' in handshakeAware.description &&
393+
handshakeAware.description.maxWireVersion != null
394+
) {
395+
return handshakeAware.description.maxWireVersion;
396+
}
397397
}
398398

399399
return 0;

0 commit comments

Comments
 (0)