node_modules/.cache/esm/6826f6c2f3ed612d.js
/**
 * Lookup an `mongodb+srv` connection string, combine the parts and reparse it as a normal
 * connection string.
 *
 * @param {string} uri The connection string to parse
 * @param {object} options Optional user provided connection string options
 * @param {function} callback
 */
Lookup an `mongodb+srv` connection string, combine the parts and reparse it as a normal
connection string.

@param {string} uri The connection string to parse
@param {object} options Optional user provided connection string options
@param {function} callback
Lookup an ` mongodb + srv ` connection string combine the parts and reparse it as a normal connection string . @param { string } uri The connection string to parse @param { object } options Optional user provided connection string options @param { function } callback
function parseSrvConnectionString(uri, options, callback) {
  const result = URL.parse(uri, true);
  if (result.hostname.split('.').length < 3) {
    return callback(new MongoParseError('URI does not have hostname, domain name and tld'));
  }
  result.domainLength = result.hostname.split('.').length;
  if (result.pathname && result.pathname.match(',')) {
    return callback(new MongoParseError('Invalid URI, cannot contain multiple hostnames'));
  }
  if (result.port) {
    return callback(new MongoParseError(`Ports not accepted with '${PROTOCOL_MONGODB_SRV}' URIs`));
  }
  let srvAddress = `_mongodb._tcp.${result.host}`;
  dns.resolveSrv(srvAddress, (err, addresses) => {
    if (err) return callback(err);
    if (addresses.length === 0) {
      return callback(new MongoParseError('No addresses found at host'));
    }
    for (let i = 0; i < addresses.length; i++) {
      if (!matchesParentDomain(addresses[i].name, result.hostname, result.domainLength)) {
        return callback(
          new MongoParseError('Server record does not share hostname with parent URI')
        );
      }
    }
    let base = result.auth ? `mongodb://${result.auth}@` : `mongodb://`;
    let connectionStrings = addresses.map(
      (address, i) =>
        i === 0 ? `${base}${address.name}:${address.port}` : `${address.name}:${address.port}`
    );
    let connectionString = `${connectionStrings.join(',')}/`;
    let connectionStringOptions = [];
    if (result.path) {
      let defaultDb = result.path.slice(1);
      if (defaultDb.indexOf('?') !== -1) {
        defaultDb = defaultDb.slice(0, defaultDb.indexOf('?'));
      }
      connectionString += defaultDb;
    }
    if (!options.ssl && (!result.search || result.query['ssl'] == null)) {
      connectionStringOptions.push('ssl=true');
    }
    if (result.search) {
      connectionStringOptions.push(result.search.replace('?', ''));
    }
    dns.resolveTxt(result.host, (err, record) => {
      if (err) {
        if (err.code !== 'ENODATA') {
          return callback(err);
        }
        record = null;
      }
      if (record) {
        if (record.length > 1) {
          return callback(new MongoParseError('Multiple text records not allowed'));
        }
        record = record[0];
        record = record.length > 1 ? record.join('') : record[0];
        if (record.indexOf('authSource') === -1 && record.indexOf('replicaSet') === -1) {
          return callback(
            new MongoParseError('Text record must only set `authSource` or `replicaSet`')
          );
        }
        connectionStringOptions.push(record);
      }
      if (connectionStringOptions.length) {
        connectionString += `?${connectionStringOptions.join('&')}`;
      }
      parseConnectionString(connectionString, callback);
    });
  });
}
function parseSrvConnectionString ( uri , options , callback ) { const result = URL . parse ( uri , true ) ; if ( result . hostname . split ( '.' ) . length < 3 ) { return callback ( new MongoParseError ( 'URI does not have hostname, domain name and tld' ) ) ; } result . domainLength = result . hostname . split ( '.' ) . length ; if ( result . pathname && result . pathname . match ( ',' ) ) { return callback ( new MongoParseError ( 'Invalid URI, cannot contain multiple hostnames' ) ) ; } if ( result . port ) { return callback ( new MongoParseError ( ` ${ PROTOCOL_MONGODB_SRV } ` ) ) ; } let srvAddress = ` ${ result . host } ` ; dns . resolveSrv ( srvAddress , ( err , addresses ) => { if ( err ) return callback ( err ) ; if ( addresses . length === 0 ) { return callback ( new MongoParseError ( 'No addresses found at host' ) ) ; } for ( let i = 0 ; i < addresses . length ; i ++ ) { if ( ! matchesParentDomain ( addresses [ i ] . name , result . hostname , result . domainLength ) ) { return callback ( new MongoParseError ( 'Server record does not share hostname with parent URI' ) ) ; } } let base = result . auth ? ` ${ result . auth } ` : ` ` ; let connectionStrings = addresses . map ( ( address , i ) => i === 0 ? ` ${ base } ${ address . name } ${ address . port } ` : ` ${ address . name } ${ address . port } ` ) ; let connectionString = ` ${ connectionStrings . join ( ',' ) } ` ; let connectionStringOptions = [ ] ; if ( result . path ) { let defaultDb = result . path . slice ( 1 ) ; if ( defaultDb . indexOf ( '?' ) !== - 1 ) { defaultDb = defaultDb . slice ( 0 , defaultDb . indexOf ( '?' ) ) ; } connectionString += defaultDb ; } if ( ! options . ssl && ( ! result . search || result . query [ 'ssl' ] == null ) ) { connectionStringOptions . push ( 'ssl=true' ) ; } if ( result . search ) { connectionStringOptions . push ( result . search . replace ( '?' , '' ) ) ; } dns . resolveTxt ( result . host , ( err , record ) => { if ( err ) { if ( err . code !== 'ENODATA' ) { return callback ( err ) ; } record = null ; } if ( record ) { if ( record . length > 1 ) { return callback ( new MongoParseError ( 'Multiple text records not allowed' ) ) ; } record = record [ 0 ] ; record = record . length > 1 ? record . join ( '' ) : record [ 0 ] ; if ( record . indexOf ( 'authSource' ) === - 1 && record . indexOf ( 'replicaSet' ) === - 1 ) { return callback ( new MongoParseError ( 'Text record must only set `authSource` or `replicaSet`' ) ) ; } connectionStringOptions . push ( record ) ; } if ( connectionStringOptions . length ) { connectionString += ` ${ connectionStringOptions . join ( '&' ) } ` ; } parseConnectionString ( connectionString , callback ) ; } ) ; } ) ; }
Lookup an `mongodb+srv` connection string, combine the parts and reparse it as a normal
 connection string.
Lookup an ` mongodb + srv ` connection string combine the parts and reparse it as a normal connection string .
// Add the default database if needed // Default to SSL true // Keep original uri options // Add any options to the connection string