typed-mapper
Version:
Mapping engine which converts from one data structure to another while working with Typescripts generics to allow for strong typing
49 lines (43 loc) • 2.23 kB
TypeScript
import * as brilliant_errors from 'brilliant-errors';
declare type IFunctionalMapping<I, O> = (input?: I, set?: I[]) => O;
declare type IStaticMapping<I> = keyof I;
declare type IMapperConfiguration<I, O> = {
[K in keyof O]: (keyof I & O[K]) | IFunctionalMapping<I, O[K]>;
};
declare type IPassthroughConfig<I, O> = Array<keyof O> | true | false;
declare type IExcludeConfig<I, O> = Array<keyof O> | false;
declare class TypedMapper<I = any, O = any> {
private _map?;
private _aggregate?;
private _data?;
private _passthrough;
private _exclude;
static map<I = any, O = any>(config: IMapperConfiguration<I, O>): TypedMapper<I, O>;
static passthrough<I = any, O = any>(config: IPassthroughConfig<I, O>): TypedMapper<I, O>;
static exclude<I = any, O = any>(config: IExcludeConfig<I, O>): TypedMapper<I, O>;
static aggregate<I = any, O = any>(config: IMapperConfiguration<I, O>): TypedMapper<I, O>;
get mapConfig(): IMapperConfiguration<I, O> | undefined;
map(config: IMapperConfiguration<I, O>): this;
passthrough(config: IPassthroughConfig<I, O>): this;
exclude(config: IExcludeConfig<I, O>): this;
input(data: I | I[]): this;
get inputData(): I | I[] | undefined;
/**
* Converts the input data, using the mapping configuration,
* into the output format.
*/
convert(data?: I | I[]): O | O[];
convertArray(data?: I[]): O[];
convertObject(data?: I): O;
private _convertObject;
private _convertArray;
/**
* Converts input data into an aggregate record
*/
aggregate(config: IMapperConfiguration<I, O>): this;
}
declare function dasherize(name: string): string;
declare function camelize(name: string): string;
declare function pascalize(name: string): string;
declare const MapperError: brilliant_errors.Constructor<[message: string, classification: `${string}/${string}`, options?: brilliant_errors.IErrorRuntimeOptions<number> | undefined], brilliant_errors.IBrilliantError<"MapperError", "typed-mapper", string, string, number, "standard">>;
export { IExcludeConfig, IFunctionalMapping, IMapperConfiguration, IPassthroughConfig, IStaticMapping, MapperError, TypedMapper, camelize, dasherize, pascalize };