<commit_before>const Hooter = require('hooter')
const defaultSchema = require('./schema')


const EVENTS = [
  ['schema', 'sync'],
  ['init', 'sync'],
  ['configure', 'sync'],
  ['start', 'sync'],
  ['execute', 'async'],
  ['process', 'async'],
  ['handle', 'async'],
  ['error', 'sync'],
]


module.exports = function comanche(args, plugins) {
  let lifecycle = new Hooter()

  if (!Array.isArray(plugins)) {
    throw new Error('Plugins must be an array of functions')
  }

  EVENTS.forEach(([event, mode]) => {
    lifecycle.register(event, mode)
  })

  plugins.forEach((plugin) => {
    let boundLifecycle = lifecycle.bind(plugin)
    plugin = boundLifecycle.wrap(plugin)
    plugin(boundLifecycle)
  })

  let schema = lifecycle.tootWith('schema', (schema) => schema, defaultSchema)

  return lifecycle.tootWith('init', (_, createApi) => {
    if (!createApi) {
      throw new Error(
        'No interface has been defined. At least one plugin must define ' +
        'an interface during the "init" event'
      )
    }

    if (typeof createApi !== 'function') {
      throw new Error('The result of "init" must be a function')
    }

    return createApi(...args)
  }, schema)
}<commit_msg>Rename defaultSchema to baseSchema<commit_after>const Hooter = require('hooter')
const baseSchema = require('./schema')


const EVENTS = [
  ['schema', 'sync'],
  ['init', 'sync'],
  ['configure', 'sync'],
  ['start', 'sync'],
  ['execute', 'async'],
  ['process', 'async'],
  ['handle', 'async'],
  ['error', 'sync'],
]


module.exports = function comanche(args, plugins) {
  let lifecycle = new Hooter()

  if (!Array.isArray(plugins)) {
    throw new Error('Plugins must be an array of functions')
  }

  EVENTS.forEach(([event, mode]) => {
    lifecycle.register(event, mode)
  })

  plugins.forEach((plugin) => {
    let boundLifecycle = lifecycle.bind(plugin)
    plugin = boundLifecycle.wrap(plugin)
    plugin(boundLifecycle)
  })

  let schema = lifecycle.tootWith('schema', (schema) => schema, baseSchema)

  return lifecycle.tootWith('init', (_, createApi) => {
    if (!createApi) {
      throw new Error(
        'No interface has been defined. At least one plugin must define ' +
        'an interface during the "init" event'
      )
    }

    if (typeof createApi !== 'function') {
      throw new Error('The result of "init" must be a function')
    }

    return createApi(...args)
  }, schema)
}
{'fraction_non_alphanumeric': 0.16563146997929606, 'fraction_numerical': 0.0, 'mean_word_length': 3.4411764705882355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6151524', 'n_tokens_mistral': 765, 'n_tokens_neox': 741, 'n_words': 207}