<commit_before>import _ from 'lodash';
import type from 'type-of';
import Database from './Database';

function constructNaomi() {
  let engines = [];

  /**
   * Registers the given database engine under the designated identifier.
   * @param {String} id database engine identifier, e.g. "mysql", "postgres"
   * @param {Database} engine the database engine itself.
   * @throws {TypeError} if params are invalid or unspecified.
   */
  function registerDatabaseEngine(id, engine) {
    if (!_.isString(id)) {
      throw new TypeError(`Invalid id variable; expected string, received ${type(id)}`);
    }

    engines.push({
      id: id,
      re: new RegExp(id, 'i'),
      Database: engine
    });
  }

  /**
   * Creates and returns a new Database of the designated type.
   * Please note: connection properties may vary depending on the database type.
   * @param {String} id database engine identifier, e.g. "mysql", "postgres"
   * @param {Object} [connectionProperties={}] connection properties
   * @throws {TypeError} if params are invalid or unspecified.
   * @throws {UnknownDatabaseEngine} if the specified engine identifier is unknown to Naomi.
   * @returns {Database}
   */
  function createDatabase(id: string, connectionProperties: ?Object): Database {
    if (!_.isString(id)) {
      throw new TypeError(`Invalid id variable; expected string, received ${type(id)}`);
    }

    // handle optional params
    connectionProperties = connectionProperties || {};

    // find engine by id
    const engine = _.find(engines, (e) => e.re.test(id));

    // create + return new db
    if (engine) {
      return new engine.Database(connectionProperties);
    }

    throw new TypeError(`Unknown database engine; please specify one of ${engines.map((e) => e.id).join(', ')}`);
  }

  // expose public API
  return Object.freeze({
    registerDatabaseEngine,
    database: createDatabase,
    create: createDatabase,
  });
}

export default constructNaomi(); // singleton<commit_msg>Rename registerDatabaseEngine to simply register<commit_after>import _ from 'lodash';
import type from 'type-of';
import Database from './Database';

function constructNaomi() {
  let engines = [];

  /**
   * Registers the supplied database engine under the designated identifier.
   * @param {String} id database engine identifier, e.g. "mysql", "postgres"
   * @param {Database} engine the database engine itself.
   * @throws {TypeError} if params are invalid or unspecified.
   */
  function register(id, engine) {
    if (!_.isString(id)) {
      throw new TypeError(`Invalid id variable; expected string, received ${type(id)}`);
    }

    engines.push({
      id: id,
      re: new RegExp(id, 'i'),
      Database: engine
    });
  }

  /**
   * Creates and returns a new Database of the designated type.
   * Please note: connection properties may vary depending on the database type.
   * @param {String} id database engine identifier, e.g. "mysql", "postgres"
   * @param {Object} [connectionProperties={}] connection properties
   * @throws {TypeError} if params are invalid or unspecified.
   * @throws {UnknownDatabaseEngine} if the specified engine identifier is unknown to Naomi.
   * @returns {Database}
   */
  function createDatabase(id: string, connectionProperties: ?Object): Database {
    if (!_.isString(id)) {
      throw new TypeError(`Invalid id variable; expected string, received ${type(id)}`);
    }

    // handle optional params
    connectionProperties = connectionProperties || {};

    // find engine by id
    const engine = _.find(engines, (e) => e.re.test(id));

    // create + return new db
    if (engine) {
      return new engine.Database(connectionProperties);
    }

    throw new TypeError(`Unknown database engine; please specify one of ${engines.map((e) => e.id).join(', ')}`);
  }

  // expose public API
  return Object.freeze({
    register,
    create,
    database: create,
  });
}

export default constructNaomi(); // singleton
{'fraction_non_alphanumeric': 0.12198189134808853, 'fraction_numerical': 0.0, 'mean_word_length': 3.418888888888889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1591185', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1077, 'n_words': 386}