/** * Data builder is an abstract class builders can inherit to make working with the {@linkplain dossierProxy} easier. * * ```typescript * export class ShapeBuilder extends DataBuilder { * constructor() { * super({ * name: randomString(10, 20), * sides: randomNumberBetween(1, 4), * colour: randomElement(['Blue', 'Red', 'Yellow', 'Green']), * }) * } * * public withName(name: string) { * return this.with('name', name + ' Intercepted') * } * } * * export const shapeBuilder = dossierProxy(ShapeBuilder) * ``` */ export declare abstract class DataBuilder { protected thing: T; protected constructor(thing: T); with(key: K, value: T[K]): this; build(): T; clone(): this; } type WithMethods = CoerceIntellisense<{ [K in keyof T as K extends string ? `with${Capitalize}` : never]-?: (d: T[K]) => WithMethods & TBuilder; } & TBuilder>; export type CoerceIntellisense = T extends infer O ? { [K in keyof O]: O[K]; } : never; type DynamicDataBuilder = TDataBuilder & WithMethods; /** * The proxy builder allows one to easily create a builder and have a [proxy]{@link https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/proxy/proxy} * instance handle any with* methods not specifically declared by the builder itself. * * ```typescript * class ShapeBuilder extends DataBuilder { * constructor() { * super({ * name: randomString(10, 20), * sides: randomNumberBetween(1, 4), * colour: randomElement(['Blue', 'Red', 'Yellow', 'Green']), * }) * } * * public withName(name: string) { * return this.with('name', name + ' Intercepted') * } * } * * const shapeBuilder = dossierProxy(ShapeBuilder) * * const shape = shapeBuilder().withName('Square').withSides(4).withColour('Red').build() * * console.log(shape) // Outputs { name: 'Square Intercepted', sides: 4, colour: 'Red' } * ``` * @param builder The constructor to call to create a new instance of the builder. */ export declare function dossierProxy(builder: new () => TDataBuilder): () => DynamicDataBuilder; export {};