tzientist
Version:
Scientist-like library for Node.js in TypeScript
51 lines (50 loc) • 2.53 kB
TypeScript
export type ExperimentFunction<TParams extends any[], TResult> = (...args: TParams) => TResult;
export type ExperimentAsyncFunction<TParams extends any[], TResult> = ExperimentFunction<TParams, Promise<TResult>>;
export interface Results<TParams extends any[], TResult> {
experimentName: string;
experimentArguments: TParams;
controlResult?: TResult;
candidateResult?: TResult;
controlError?: any;
candidateError?: any;
controlTimeMs?: number;
candidateTimeMs?: number;
}
export interface Options<TParams extends any[], TResult> {
publish?: (results: Results<TParams, TResult>) => void;
enabled?: (...args: TParams) => boolean;
}
export type OptionsSync<TParams extends any[], TResult> = Options<TParams, TResult>;
export type OptionsAsync<TParams extends any[], TResult> = Options<TParams, TResult> & {
inParallel?: boolean;
};
/**
* A factory that creates an experiment function.
*
* @param name - The name of the experiment, typically for use in publish.
* @param control - The legacy function you are trying to replace.
* @param candidate - The new function intended to replace the control.
* @param [options] - Options for the experiment. You will usually want to specify a publish function.
* @returns A function that acts like the control while also running the candidate and publishing results.
*/
export declare function experiment<TParams extends any[], TResult>({ name, control, candidate, options }: {
name: string;
control: ExperimentFunction<TParams, TResult>;
candidate: ExperimentFunction<TParams, TResult>;
options?: OptionsSync<TParams, TResult>;
}): ExperimentFunction<TParams, TResult>;
/**
* A factory that creates an asynchronous experiment function.
*
* @param name - The name of the experiment, typically for use in publish.
* @param control - The legacy async function you are trying to replace.
* @param candidate - The new async function intended to replace the control.
* @param [options] - Options for the experiment. You will usually want to specify a publish function.
* @returns An async function that acts like the control while also running the candidate and publishing results.
*/
export declare function experimentAsync<TParams extends any[], TResult>({ name, control, candidate, options }: {
name: string;
control: ExperimentAsyncFunction<TParams, TResult>;
candidate: ExperimentAsyncFunction<TParams, TResult>;
options?: OptionsAsync<TParams, TResult>;
}): ExperimentAsyncFunction<TParams, TResult>;