UNPKG

@jackfranklin/test-data-bot

Version:
54 lines 2.4 kB
export interface SequenceGenerator<T> { generatorType: 'sequence'; call: (counter: number) => T; } export interface PerBuildGenerator<T> { generatorType: 'perBuild'; call: () => T; } export interface OneOfGenerator<T> { generatorType: 'oneOf'; call: () => T; } export type FieldGenerator<T> = SequenceGenerator<T> | OneOfGenerator<T> | PerBuildGenerator<T>; export type Field<T = any> = T | FieldGenerator<T> | FieldsConfiguration<T>; export type FieldsConfiguration<FactoryResultType> = { readonly [Key in keyof FactoryResultType]: Field<FactoryResultType[Key]>; }; export type Overrides<FactoryResultType = any> = { [Key in keyof FactoryResultType]?: Field<FactoryResultType[Key]>; }; export interface BuildTimeConfig<FactoryResultType> { overrides?: Overrides<FactoryResultType>; map?: (builtThing: FactoryResultType) => FactoryResultType; traits?: string | string[]; } export interface TraitsConfiguration<FactoryResultType> { readonly [traitName: string]: { overrides?: Overrides<FactoryResultType>; postBuild?: (builtThing: FactoryResultType) => FactoryResultType; }; } export interface BuildConfiguration<FactoryResultType> { readonly fields: FieldsConfiguration<FactoryResultType>; readonly traits?: TraitsConfiguration<FactoryResultType>; readonly postBuild?: (x: FactoryResultType) => FactoryResultType; } export type ValueOf<T> = T[keyof T]; export interface Builder<FactoryResultType> { (buildTimeConfig?: BuildTimeConfig<FactoryResultType>): FactoryResultType; reset(): void; one(buildTimeConfig?: BuildTimeConfig<FactoryResultType>): FactoryResultType; many(count: number, buildTimeConfig?: BuildTimeConfig<FactoryResultType>): FactoryResultType[]; } export declare const build: <FactoryResultType>(factoryNameOrConfig: string | BuildConfiguration<FactoryResultType>, configObject?: BuildConfiguration<FactoryResultType> | undefined) => Builder<FactoryResultType>; export declare const oneOf: <T>(...options: T[]) => OneOfGenerator<T>; export declare const bool: () => OneOfGenerator<boolean>; type Sequence = { (): SequenceGenerator<number>; <T>(userProvidedFunction: (count: number) => T): SequenceGenerator<T>; }; export declare const sequence: Sequence; export declare const perBuild: <T>(func: () => T) => PerBuildGenerator<T>; export {}; //# sourceMappingURL=index.d.ts.map