<commit_before>/* eslint valid-jsdoc:0 */
/* eslint no-use-before-define:0 */

'use strict'

var Q = require('q')
var Transformer = require('transformer')

/**
* Creates a rejected promise structure as per our plugin interface dictates
* @param {Object} error - A reason why the promise is being rejected.
* @param {Object} context - A structure containing the values passed by the caller.
*/
function buildReject (error, context) {
  return {
    error: error,
    origin: 'pluginTransformer',
    data: context
  }
}

exports.register = function (server, pluginOptions, next) {
  var transformer = new Transformer()

  transformer.startReplication()
  .then(function () {
    // Replication always on, once it's finished successfully allow access to our get() function
    server.expose('getConfiguration', getConfiguration)
    next()
  })

  function getConfiguration (options) {
    var deferred = Q.defer()

    try {
      // check for everything thats required
      if (!options) {
        throw new Error('invalid options')
      }

      transformer.get(options)
      .then(function (result) {
        deferred.resolve(result)
      }, function (error) {
        deferred.reject(buildReject(error, options))
      })
    } catch (error) {
      // any exceptions that have been thrown we need to send that back with a rejected deferred<commit_msg>WEB-10927 logs for circle ci debugging<commit_after>/* eslint valid-jsdoc:0 */
/* eslint no-use-before-define:0 */

'use strict'

var Q = require('q')
var Transformer = require('transformer')

/**
* Creates a rejected promise structure as per our plugin interface dictates
* @param {Object} error - A reason why the promise is being rejected.
* @param {Object} context - A structure containing the values passed by the caller.
*/
function buildReject (error, context) {
  return {
    error: error,
    origin: 'pluginTransformer',
    data: context
  }
}

exports.register = function (server, pluginOptions, next) {
  console.log('plugin-transformer register()')
  var transformer = new Transformer()

  transformer.startReplication()
  .then(function () {

      console.log('plugin-transformer startReplication().then()')

    // Replication always on, once it's finished successfully allow access to our get() function
    server.expose('getConfiguration', getConfiguration)
    next()

  })

  function getConfiguration (options) {
    console.log('plugin-transformer getConfiguration()')
    var deferred = Q.defer()

    try {
      // check for everything thats required
      if (!options) {
        throw new Error('invalid options')
      }

      transformer.get(options)
      .then(function (result) {
        deferred.resolve(result)
      }, function (error) {
        deferred.reject(buildReject(error, options))
      })
    } catch (error) {
      // any exceptions that have been thrown we need to send that back with a rejected deferred
{'fraction_non_alphanumeric': 0.1083676268861454, 'fraction_numerical': 0.0030864197530864196, 'mean_word_length': 3.2834067547723937, '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': '2065831', 'n_tokens_mistral': 807, 'n_tokens_neox': 781, 'n_words': 268}