text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.parseConnectionString = parseConnectionString;
  exports.loadConfig = loadConfig;
  
  var _typeorm = require("typeorm");
  
  function parseConnectionString(configOrString) {
    if (typeof configOrString !== "string") {
      return configOrString;
    }
  
    try {
      const parsedUrl = new URL(configOrString);
      const config = {};
  
      if (parsedUrl.protocol.startsWith("mongodb+srv")) {
        config.type = "mongodb";
        config.url = configOrString.replace(/\?(.*)$/, "");
        config.useNewUrlParser = true;
      } else {
        config.type = parsedUrl.protocol.replace(/:$/, "");
        config.host = parsedUrl.hostname;
        config.port = Number(parsedUrl.port);
        config.username = parsedUrl.username;
        config.password = parsedUrl.password;
        config.database = parsedUrl.pathname.replace(/^\//, "").replace(/\?(.*)$/, "");
        config.options = {};
      }
  
      if (config.type === "mongodb") {
        config.useUnifiedTopology = true;
      }
  
      if (config.type === "mssql") {
        config.options.enableArithAbort = true;
      }
  
      if (parsedUrl.search) {
        parsedUrl.search.replace(/^\?/, "").split("&").forEach(keyValuePair => {
          let [key, value] = keyValuePair.split("=");
  
          if (value === "true") {
            value = true;
          }
  
          if (value === "false") {
            value = false;
          }
  
          config[key] = value;
        });
      }
  
      return config;
    } catch (error) {
      return {
        url: configOrString
      };
    }
  }
  
  function loadConfig(config, {
    models,
    namingStrategy
  }) {
    const defaultConfig = {
      name: "nextauth",
      autoLoadEntities: true,
      entities: [new _typeorm.EntitySchema(models.User.schema), new _typeorm.EntitySchema(models.Account.schema), new _typeorm.EntitySchema(models.Session.schema), new _typeorm.EntitySchema(models.VerificationRequest.schema)],
      timezone: "Z",
      logging: false,
      namingStrategy
    };
    return { ...defaultConfig,
      ...config
    };
  }