type-transformer
Version:
Transformation / serialization / deserialization of plain JavaScript objects to typed objects and vice versa
43 lines (42 loc) • 1.57 kB
TypeScript
export declare enum CircularRefStrategy {
NONE = "NONE",
BREAK = "BREAK",
RESOLVE = "RESOLVE",
ERROR = "ERROR"
}
declare class ReferenceNode {
readonly object: Object;
referencedBy: Map<Object, ReferenceNode>;
targetObject: any;
constructor(object: Object, referencedBy?: ReferenceNode);
/**
* Checks if the object of this node is referenced by the given object.
*/
isReferencedBy(object: Object): boolean;
/**
* Gets the object that references the given one, if any.
*/
getReferencing(object: Object): any;
addReferencer(node: ReferenceNode): void;
}
export declare class ReferenceGraph {
private nodeStack;
private allNodes;
private circularStrategy;
constructor(circularStrategy?: CircularRefStrategy);
readonly current: ReferenceNode | undefined;
/**
* Check if a value would introduce a circular dependency.
* If so, react according to the configured strategy (@see CircularRefStrategy).
* If not, call the @param handleValue() function.
* @param targetObject the (empty) object that is populated by handleValue
* @returns the result of either the handling of a circular dependency
* or the @param targetObject
*/
preventCircularDependencies(value: any, targetObject: any, handleValue: Function): any;
descend(object: Object): ReferenceNode;
ascend(): void;
isCircularReference(referred: Object): boolean;
handleCircularReference(referred: Object): any;
}
export {};