@tsed/json-mapper
Version:
Json mapper module for Ts.ED Framework
61 lines (60 loc) • 2.48 kB
TypeScript
import { Type } from "@tsed/core";
import { JsonSchema } from "@tsed/schema";
export type JsonMapperCallback<Options> = (input: any, options?: Options) => any;
export type CachedJsonMapper<Options> = {
id: string;
fn: JsonMapperCallback<Options>;
};
export type CachedGroupsJsonMapper<Options> = Map<string, CachedJsonMapper<Options>>;
export declare abstract class JsonMapperCompiler<Options extends Record<string, any> = any> {
/**
* Cached mappers metadata
* @protected
*/
protected cache: Map<string | Type<any>, CachedGroupsJsonMapper<Options>>;
/**
* Cached executable mappers by his id
* @protected
*/
protected mappers: Record<string, JsonMapperCallback<Options>>;
/**
* Cached schemas
* @protected
*/
protected schemes: Record<string, any>;
/**
* Cached classes by his id
* @protected
*/
protected constructors: Record<string, Type<any>>;
/**
* Global variables available in the mapper
* @protected
*/
protected globals: Record<string, any>;
constructor();
addTypeMapper(model: Type<any> | string, fn: any): this;
removeTypeMapper(model: Type<any> | string): void;
addGlobal(key: string, value: any): this;
eval(mapper: string, { id, groupsId, model }: {
id: string;
model: Type<any> | string;
groupsId: string;
}): CachedJsonMapper<Options>;
createContext(options: Options): Options & {
cache: Map<string | Type<any>, CachedGroupsJsonMapper<Options>>;
};
compile(model: Type<any> | string, groups: false | string[], opts?: {
mapper?: any;
}): CachedJsonMapper<Options>;
protected execMapper(id: string, value: any, options: Options): any;
protected abstract map(input: any, options: Options): any;
protected abstract alterValue(schemaId: string, value: any, options: Options): any;
protected abstract createMapper(model: Type<any>, id: string, groups: false | string[]): string;
protected getType(model: Type<any>): Type<any> | MapConstructor | ObjectConstructor | ArrayConstructor | SetConstructor;
protected alterIgnore(id: string, options: Options): any;
protected alterGroups(schema: JsonSchema, groups: false | string[]): boolean;
protected getGroupsId(groups: false | string[]): string;
protected getId(model: Type<any> | string, groupsId: string): string;
protected getSchemaId(id: string, propertyKey: string): string;
}