@@ -12,7 +12,7 @@ import { type Collection } from '../collection';
1212import { type FindCursor } from '../cursor/find_cursor' ;
1313import { type Db } from '../db' ;
1414import { getMongoDBClientEncryption } from '../deps' ;
15- import { type MongoClient } from '../mongo_client' ;
15+ import { type MongoClient , type MongoClientOptions } from '../mongo_client' ;
1616import { type Filter , type WithId } from '../mongo_types' ;
1717import { type CreateCollectionOptions } from '../operations/create_collection' ;
1818import { type DeleteResult } from '../operations/delete' ;
@@ -66,8 +66,6 @@ export class ClientEncryption {
6666 _tlsOptions : CSFLEKMSTlsOptions ;
6767 /** @internal */
6868 _kmsProviders : KMSProviders ;
69- /** @internal */
70- _socketOptions : ClientEncryptionSocketOptions ;
7169
7270 /** @internal */
7371 _mongoCrypt : MongoCrypt ;
@@ -114,15 +112,6 @@ export class ClientEncryption {
114112 this . _proxyOptions = options . proxyOptions ?? { } ;
115113 this . _tlsOptions = options . tlsOptions ?? { } ;
116114 this . _kmsProviders = options . kmsProviders || { } ;
117- this . _socketOptions = { } ;
118-
119- if ( 'autoSelectFamily' in client . s . options ) {
120- this . _socketOptions . autoSelectFamily = client . s . options . autoSelectFamily ;
121- }
122- if ( 'autoSelectFamilyAttemptTimeout' in client . s . options ) {
123- this . _socketOptions . autoSelectFamilyAttemptTimeout =
124- client . s . options . autoSelectFamilyAttemptTimeout ;
125- }
126115
127116 if ( options . keyVaultNamespace == null ) {
128117 throw new MongoCryptInvalidArgumentError ( 'Missing required option `keyVaultNamespace`' ) ;
@@ -215,7 +204,7 @@ export class ClientEncryption {
215204 const stateMachine = new StateMachine ( {
216205 proxyOptions : this . _proxyOptions ,
217206 tlsOptions : this . _tlsOptions ,
218- socketOptions : this . _socketOptions
207+ socketOptions : autoSelectSocketOptions ( this . _client . s . options )
219208 } ) ;
220209
221210 const dataKey = deserialize ( await stateMachine . execute ( this , context ) ) as DataKey ;
@@ -273,7 +262,7 @@ export class ClientEncryption {
273262 const stateMachine = new StateMachine ( {
274263 proxyOptions : this . _proxyOptions ,
275264 tlsOptions : this . _tlsOptions ,
276- socketOptions : this . _socketOptions
265+ socketOptions : autoSelectSocketOptions ( this . _client . s . options )
277266 } ) ;
278267
279268 const { v : dataKeys } = deserialize ( await stateMachine . execute ( this , context ) ) ;
@@ -655,7 +644,7 @@ export class ClientEncryption {
655644 const stateMachine = new StateMachine ( {
656645 proxyOptions : this . _proxyOptions ,
657646 tlsOptions : this . _tlsOptions ,
658- socketOptions : this . _socketOptions
647+ socketOptions : autoSelectSocketOptions ( this . _client . s . options )
659648 } ) ;
660649
661650 const { v } = deserialize ( await stateMachine . execute ( this , context ) ) ;
@@ -734,7 +723,7 @@ export class ClientEncryption {
734723 const stateMachine = new StateMachine ( {
735724 proxyOptions : this . _proxyOptions ,
736725 tlsOptions : this . _tlsOptions ,
737- socketOptions : this . _socketOptions
726+ socketOptions : autoSelectSocketOptions ( this . _client . s . options )
738727 } ) ;
739728 const context = this . _mongoCrypt . makeExplicitEncryptionContext ( valueBuffer , contextOptions ) ;
740729
@@ -976,3 +965,21 @@ export interface RangeOptions {
976965 sparsity : Long ;
977966 precision ?: number ;
978967}
968+
969+ /**
970+ * Get the socket options from the client.
971+ * @param baseOptions - The mongo client options.
972+ * @returns ClientEncryptionSocketOptions
973+ */
974+ export function autoSelectSocketOptions (
975+ baseOptions : MongoClientOptions
976+ ) : ClientEncryptionSocketOptions {
977+ const options : ClientEncryptionSocketOptions = { autoSelectFamily : true } ;
978+ if ( 'autoSelectFamily' in baseOptions ) {
979+ options . autoSelectFamily = baseOptions . autoSelectFamily ;
980+ }
981+ if ( 'autoSelectFamilyAttemptTimeout' in baseOptions ) {
982+ options . autoSelectFamilyAttemptTimeout = baseOptions . autoSelectFamilyAttemptTimeout ;
983+ }
984+ return options ;
985+ }
0 commit comments