<commit_before>// Const transconsole = require('../transaction-console/transaction-console');
const debug = require('debug')('jsonapi:core');
const fs = require('fs');

// Get all the data_handlers
const files = fs.readdirSync(`${__dirname}/data_handlers`);
const dataHandlers = {};
for (let file of files) {
  dataHandlers[file.replace('.js', '')] = require(`${__dirname}/data_handlers/${file}`);
}
debug(`Core handlers loaded ${JSON.stringify(dataHandlers)}`);

// Decide the appropiate handler module
module.exports.processMessage = function (request, callback) {
  debug(`Core processing message ${JSON.stringify(request)}`);
  const dataType = request.data_type;
  // NOTE(garcianavalon) quick and simple implementation data_type == handler_module_name
  // A more complex solution may be required in the future
  const Handler = dataHandlers[dataType];
  debug(`Delegating to handler ${Handler.name}`);
  if (!Handler) {
    // TODO(garcianavalon) better error handling
    return callback({
      error: `There is no handler for ${dataType}`
    });
  }
  const handler = new Handler(request, callback);
  handler.handle();
};
<commit_msg>moved logging statement to prevent stupid issues<commit_after>// Const transconsole = require('../transaction-console/transaction-console');
const debug = require('debug')('jsonapi:core');
const fs = require('fs');

// Get all the data_handlers
const files = fs.readdirSync(`${__dirname}/data_handlers`);
const dataHandlers = {};
for (let file of files) {
  dataHandlers[file.replace('.js', '')] = require(`${__dirname}/data_handlers/${file}`);
}
debug(`Core handlers loaded ${JSON.stringify(dataHandlers)}`);

// Decide the appropiate handler module
module.exports.processMessage = function (request, callback) {
  debug(`Core processing message ${JSON.stringify(request)}`);
  const dataType = request.data_type;
  // NOTE(garcianavalon) quick and simple implementation data_type == handler_module_name
  // A more complex solution may be required in the future
  const Handler = dataHandlers[dataType];
  if (!Handler) {
    // TODO(garcianavalon) better error handling
    return callback({
      error: `There is no handler for ${dataType}`
    });
  }
  debug(`Delegating to handler ${Handler.name}`);
  const handler = new Handler(request, callback);
  handler.handle();
};

{'fraction_non_alphanumeric': 0.14267296948861194, 'fraction_numerical': 0.0, 'mean_word_length': 5.046753246753247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7232930', 'n_tokens_mistral': 658, 'n_tokens_neox': 665, 'n_words': 188}