<commit_before>/* jslint node: true */
'use strict';

//  ENiGMA½
const moduleUtil            = require('./module_util.js');
const Log                   = require('./logger.js').log;
const Config                = require('./config.js').get;
const asset                 = require('./asset.js');
const { MCIViewFactory }    = require('./mci_view_factory.js');
const { Errors }            = require('./enig_error.js');

//  deps
const paths                 = require('path');
const async                 = require('async');
const _                     = require('lodash');

exports.loadMenu                        = loadMenu;
exports.getFormConfigByIDAndMap         = getFormConfigByIDAndMap;
exports.handleAction                    = handleAction;
exports.getResolvedSpec                 = getResolvedSpec;
exports.handleNext                      = handleNext;

function getMenuConfig(client, name, cb) {
    async.waterfall(
        [
            function locateMenuConfig(callback) {
                const menuConfig = _.get(client.currentTheme, [ 'menus', name ]);
                if (menuConfig) {
                    return callback(null, menuConfig);
                }

                return callback(Errors.DoesNotExist(`No menu entry for "${name}"`));
            },
            function locatePromptConfig(menuConfig, callback) {
                if(_.isString(menuConfig.prompt)) {
                    if(_.has(client.currentTheme, [ 'prompts', menuConfig.prompt ])) {
                        menuConfig.promptConfig = client.currentTheme.prompts[menuConfig.prompt];
                        return callback(null, menuConfig);
                    }
                    return callback(Error.DoesNotExist(`No prompt entry for "${menuConfig.prompt}"`));
                }
                return callback(null, menuConfig);
            }
        ],
        (err, menuConfig) => {
            return cb(err, menuConfig);
        }
    );
}

//  :TODO: name/client should not be part of options - they are required always
function loadMenu(options, cb) {
    if(!_.isString(options.name) || !_.isObject(options.client)) {
        return cb(Errors.MissingParam('Missing required options'));
    }

    async.waterfall(
        [
            function getMenuConfiguration(callback) {
                getMenuConfig(options.client, options.name, (err, menuConfig) => {<commit_msg>Fix DoesNotExist error<commit_after>/* jslint node: true */
'use strict';

//  ENiGMA½
const moduleUtil            = require('./module_util.js');
const Log                   = require('./logger.js').log;
const Config                = require('./config.js').get;
const asset                 = require('./asset.js');
const { MCIViewFactory }    = require('./mci_view_factory.js');
const { Errors }            = require('./enig_error.js');

//  deps
const paths                 = require('path');
const async                 = require('async');
const _                     = require('lodash');

exports.loadMenu                        = loadMenu;
exports.getFormConfigByIDAndMap         = getFormConfigByIDAndMap;
exports.handleAction                    = handleAction;
exports.getResolvedSpec                 = getResolvedSpec;
exports.handleNext                      = handleNext;

function getMenuConfig(client, name, cb) {
    async.waterfall(
        [
            function locateMenuConfig(callback) {
                const menuConfig = _.get(client.currentTheme, [ 'menus', name ]);
                if (menuConfig) {
                    return callback(null, menuConfig);
                }

                return callback(Errors.DoesNotExist(`No menu entry for "${name}"`));
            },
            function locatePromptConfig(menuConfig, callback) {
                if(_.isString(menuConfig.prompt)) {
                    if(_.has(client.currentTheme, [ 'prompts', menuConfig.prompt ])) {
                        menuConfig.promptConfig = client.currentTheme.prompts[menuConfig.prompt];
                        return callback(null, menuConfig);
                    }
                    return callback(Errors.DoesNotExist(`No prompt entry for "${menuConfig.prompt}"`));
                }
                return callback(null, menuConfig);
            }
        ],
        (err, menuConfig) => {
            return cb(err, menuConfig);
        }
    );
}

//  :TODO: name/client should not be part of options - they are required always
function loadMenu(options, cb) {
    if(!_.isString(options.name) || !_.isObject(options.client)) {
        return cb(Errors.MissingParam('Missing required options'));
    }

    async.waterfall(
        [
            function getMenuConfiguration(callback) {
                getMenuConfig(options.client, options.name, (err, menuConfig) => {
{'fraction_non_alphanumeric': 0.117079311791859, 'fraction_numerical': 0.0, 'mean_word_length': 1.7893504973668812, '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': '4777678', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1183, 'n_words': 244}