MCPcopy
hub / github.com/mongodb/node-mongodb-native / parseConnectOptions

Function parseConnectOptions

src/cmap/connect.ts:326–353  ·  view source on GitHub ↗
(options: ConnectionOptions)

Source from the content-addressed store, hash-verified

324] as const;
325
326function parseConnectOptions(options: ConnectionOptions): SocketConnectOpts {
327 const hostAddress = options.hostAddress;
328 if (!hostAddress) throw new MongoInvalidArgumentError('Option "hostAddress" is required');
329
330 const result: Partial<net.TcpNetConnectOpts & net.IpcNetConnectOpts> = {};
331 for (const name of LEGAL_TCP_SOCKET_OPTIONS) {
332 if (options[name] != null) {
333 (result as Document)[name] = options[name];
334 }
335 }
336 result.keepAliveInitialDelay ??= DEFAULT_KEEP_ALIVE_INITIAL_DELAY_MS;
337 result.keepAlive = true;
338 result.noDelay = options.noDelay ?? true;
339
340 if (typeof hostAddress.socketPath === 'string') {
341 result.path = hostAddress.socketPath;
342 return result as net.IpcNetConnectOpts;
343 } else if (typeof hostAddress.host === 'string') {
344 result.host = hostAddress.host;
345 result.port = hostAddress.port;
346 return result as net.TcpNetConnectOpts;
347 } else {
348 // This should never happen since we set up HostAddresses
349 // But if we don't throw here the socket could hang until timeout
350 // TODO(NODE-3483)
351 throw new MongoRuntimeError(`Unexpected HostAddress ${JSON.stringify(hostAddress)}`);
352 }
353}
354
355type MakeConnectionOptions = ConnectionOptions & { existingSocket?: Stream };
356

Callers 3

parseSslOptionsFunction · 0.85
makeSocketFunction · 0.85
makeSocks5ConnectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected