/** * Copyright 2017 Yahoo Holdings Inc. * Licensed under the terms of the MIT license. See LICENSE file in project root for terms. */ /** * Definition of terms: * * Entry * ------------ * The object to be evaluated. Entries have the following schema: * * { * setting: 'acb', * value: 1, * except: [{ * value: 2, * locale: ['en', 'uk'] * }] * } * * * Except * ------------ * Every entry contains at least one except block. Here's what an except block looks like: * `{ * value: 111, * lang: ['en', 'us'], * farm: [1111, 2222] * }` * * Every except block must contain an answer and at least one condition. In the above example, the except block * contains an answer (the value) and two conditions (lang and farm). * * * Answer * ------------ * Either `enabled` or `value`. Every entry contains a default answer, which is specified at the top level * of an entry. However, based on the conditions in the except block and the context given by the user, * the answer may change. * * * Condition * ------------ * Conditions are used to evaluate whether to change the default answer or not. The context passed in by the * user may or may not meet the conditions. All conditions must be met to change the default answer. * * * Context * ------------ * The data passed in by the user. It is used to determine whether the conditions of except blocks are satisfied. * The keys of the context object must be the same as the conditions it is trying to fulfill. */ export declare class Evaluator { /** This allows the evaluator to make optimizations on each rule */ static prepareEntry(configEntry: any): any; /** * @param {Object} entry Setting object * * { * setting: 'acb', * value: 1, * except: [{ * value: 2, * locale: ['en', 'uk'] * }] * } * * @param {Object} context Contextual data about the user * @param {Object} overrides Any specific overrides of the config for the user * @param {Object} answers An object containing the resolved answers. * @param {Object} customEvaluators Any custom evaluators for the config * @return {} The answer for the entry */ static evaluate(entry: any, context: any, overrides?: any, answers?: any, customEvaluators?: any): { key: any; value: any; }; /** * Checks whether the context satisfies ALL conditions of the given except block. * @param {Object} entry Setting. Required because we need to know the name of the setting. * @param {Object} exceptBlock * `{ * value: 111, * lang: ['en', 'us'], * farm: [1111, 2222] * }` * @param {Object} context Contextual data about the user * @param {Object} answers An object containing the resolved answers. * @param {Object} customEvaluators Any custom evaluators for the config * @return {Boolean} TRUE if ALL conditions match, FALSE if ANY of the conditions fail. */ private static _evaluateExceptBlock; /** * For the definiton of what an answer is, please refer to the `Definition of Terms` at the top of the file. * * @param {Object} entry Setting. Required because we need to know the name of the setting. * @param {Object} [Optional] exceptBlock If an except block is passed, that means we want to get the answer from it * We have to pass in the entry along with the exceptBlock because the exceptBlock does not contain the * name of the setting. * @return {Object} An object that contains both the name and the value of the setting in this format: * ``` * { * key: name of the setting * value: value of the setting * } * ``` * It is returned in this format for the ease of use by the caller. */ private static _getAnswer; /** * Evaluates a percentage condition and returns true if the percentage is less than the * requested 'qualifiedPercentage'. * * We require a context value 'percentageSeed' to be supplied in order to personalize * the percentage crc calculation. 'percentageSeed' can be either a string or a number. * The implementor should select a value for 'percentageSeed' that is unique for the user. * * @param {string} settingName The entry setting name. Required because we need to know the name of the setting. * @param {Object} context Contextual data about the user * @param {number} qualifiedPercentage The percentage that we should qualify (return true). */ private static _evaluatePercentage; }