type-transformer
Version:
Transformation / serialization / deserialization of plain JavaScript objects to typed objects and vice versa
66 lines (65 loc) • 2.45 kB
TypeScript
import { Direction, Selectable, SelectFunction, SelectOptions } from './selection';
interface PropNameFn {
(inObj: any, direction: Direction): string;
}
export interface ExposeOptions extends SelectOptions {
propName?: string | PropNameFn;
}
export declare class Schema {
readonly registry: any;
readonly type: Function;
inherits: boolean;
private _defaultVisibility;
private _fields;
private _postProcessors;
constructor(registry: any, type: Function);
getField(fieldName: string): Field;
readonly defaultVisibility: any;
/**
* Get all fields defined in this schema and its ancestors as an iterator.
*/
readonly fields: IterableIterator<Field>;
excludeAll(): this;
exposeAll(): this;
inherit(): this;
postProcess(postProcessFn: ObjectTransformationFunction, options?: SelectOptions): this;
getPostProcessors(obj: any, direction: Direction): ObjectTransformer[];
/**
* Get a list of all schemas in the inheritance chain of this schema (including itself).
*/
private inheritanceChain;
/**
* Get the nearest ancestor schema.
*/
private getAncestor;
}
export declare class Field extends Selectable {
readonly name: string;
nestedType: any;
private _propName?;
private _transformers;
constructor(name: string);
select(selectFn: SelectFunction): this;
exclude(options?: SelectOptions): this;
expose(options?: ExposeOptions): this;
nested(type: any): this;
transform(transformFn: ValueTransformationFunction, options?: SelectOptions): this;
getValueTransformers(obj: any, direction: Direction): ValueTransformer[];
readonly propName: string | PropNameFn;
}
declare class Transformer<TransformFn extends Function> extends Selectable {
readonly transformFn: TransformFn;
constructor(transformFn: TransformFn, options?: SelectOptions);
transform(inValue: any, targetObj: any, direction: Direction): any;
}
export interface ValueTransformationFunction {
(value: any, obj: any, direction: Direction): any;
}
export declare class ValueTransformer extends Transformer<ValueTransformationFunction> {
}
export interface ObjectTransformationFunction {
(inObj: any, outObj: any, direction: Direction): any;
}
export declare class ObjectTransformer extends Transformer<ObjectTransformationFunction> {
}
export {};