import { ExtendableSettings, ISimulation, SimulatorResponse, SimulatorRequest, NextSimulator, SimulationConfig, SimulatorContext, SimulatorContextCallback, SelectorHandler } from "./common/types"; /** * Abstract BaseSimulator class * * This is where all the magic happens before we propagate the requests down to the simulation layers. * Every request will come through this class first, before the calls propagate to the instantiating class * via the `abstract evaluate` function. * */ export declare abstract class BaseSimulator implements ISimulation { namespace: string; protected config: SimulationConfig; constructor(config: SimulationConfig); /** * ingest implementation * * TODO: This will need to be cleaned up a little. * * @param req SimulatorRequest handler which holds the client request context * @param res SimulatorResponse handler which holds the client response context * @param next NextSimulator callback which we need to call if we want to progress to the next layer, unless the simulator ends the request prematurely */ ingest(req: SimulatorRequest, res: SimulatorResponse, next: NextSimulator): any; protected castSettings(globalSettings: any): ExtendableSettings; /** * We call this function to create our simulator context with all of the necessary properties * which enable us visibility into the request data, settings and request/resoonse handlers. * * @param body the request body * @param globalSettings global settings from the main request body * @param req SimulatorRequest * @param res SimulatorResponse * @param next NextSimulator */ protected contextualize(body: any, selector: SelectorHandler, req: SimulatorRequest, res: SimulatorResponse, next: NextSimulator): SimulatorContext; /** * Function that generates the occurence of a failure based on `probabilityOfFailure. * * Example: Probability of 0.2 indicates 20% chance of failure * * @param probabilityOfFailure failure probability value between 0.0 - no failure to 1.0 - certain failure. */ private generateFailure; /** * Pretty logging * * @param section what section are you currently in * @param message the message * @param newLine whether we want to have a line separator between stdout outputs */ protected log(section: string, message: string, newLine?: boolean): void; /** * Every simulation layer must implement the `evaluate` method. Here, we use "chain of responsibility" pattern * where the parent (base class) calls the child to run (evaluate) the failure simulation * * @param context simulation context associated with the request * @param callback optional callback function to the abstract base class */ protected abstract evaluate(context: SimulatorContext, callback?: SimulatorContextCallback): void; }