<commit_before>'use strict';

// Load modules

const Url = require('url');
const Async = require('async');
const Boom = require('boom');
const Traverse = require('traverse');
const Hoek = require('hoek');
const Joi = require('joi');
const { promisify } = require('util');

const asyncSeries = promisify(Async.series);
const asyncParallel = promisify(Async.parallel);

// Declare internals

const internals = {};

module.exports.config = function (settings) {

    return {
        handler: async function (request, h) {

            const requests = [];
            const payloads = [];
            const resultsData = {
                results: [],
                resultsMap: []
            };

            let errorMessage = null;

            request.payload.requests.every((req, idx) => {

                const requestParts = [];
                const result = req.path.replace(internals.requestRegex, (match, p1, p2) => {

                    if (!p1) {
                        requestParts.push({ type: 'text', value: p2 });
                        return '';
                    }

                    if (p1 < idx) {
                        requestParts.push({ type: 'ref', index: p1, value: p2 });
                        return '';
                    }

                    errorMessage = `Request reference is beyond array size: ${idx}`;
                    return match;
                });

                // Make sure entire string was processed (empty)

                if (result === '') {
                    requests.push(requestParts);
                }
                else {
                    errorMessage = errorMessage || `Invalid request format in item: ${idx}`;
                    return false;
                }

                const payloadParts = internals.parsePayload(req.payload);

                payloads.push(payloadParts || []);
                return true;
            });

            if (errorMessage !== null) {
                throw Boom.badRequest(errorMessage);
            }

            try {
                await internals.process(request, requests, payloads, resultsData);
            }
            catch (err) {
                // console.log("ERROR ", err);
                throw Boom.badRequest(err);
            }

            return h.response(resultsData.results).code(200);
        },
        notes: settings.notes,
        description: settings.description,
        validate: {<commit_msg>Remove a leftover console.log<commit_after>'use strict';

// Load modules

const Url = require('url');
const Async = require('async');
const Boom = require('boom');
const Traverse = require('traverse');
const Hoek = require('hoek');
const Joi = require('joi');
const { promisify } = require('util');

const asyncSeries = promisify(Async.series);
const asyncParallel = promisify(Async.parallel);

// Declare internals

const internals = {};

module.exports.config = function (settings) {

    return {
        handler: async function (request, h) {

            const requests = [];
            const payloads = [];
            const resultsData = {
                results: [],
                resultsMap: []
            };

            let errorMessage = null;

            request.payload.requests.every((req, idx) => {

                const requestParts = [];
                const result = req.path.replace(internals.requestRegex, (match, p1, p2) => {

                    if (!p1) {
                        requestParts.push({ type: 'text', value: p2 });
                        return '';
                    }

                    if (p1 < idx) {
                        requestParts.push({ type: 'ref', index: p1, value: p2 });
                        return '';
                    }

                    errorMessage = `Request reference is beyond array size: ${idx}`;
                    return match;
                });

                // Make sure entire string was processed (empty)

                if (result === '') {
                    requests.push(requestParts);
                }
                else {
                    errorMessage = errorMessage || `Invalid request format in item: ${idx}`;
                    return false;
                }

                const payloadParts = internals.parsePayload(req.payload);

                payloads.push(payloadParts || []);
                return true;
            });

            if (errorMessage !== null) {
                throw Boom.badRequest(errorMessage);
            }

            try {
                await internals.process(request, requests, payloads, resultsData);
            }
            catch (err) {
                throw Boom.badRequest(err);
            }

            return h.response(resultsData.results).code(200);
        },
        notes: settings.notes,
        description: settings.description,
        validate: {
{'fraction_non_alphanumeric': 0.11450851631438538, 'fraction_numerical': 0.004104247896572953, 'mean_word_length': 1.3892156862745098, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4252257', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1135, 'n_words': 291}