@@ -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