import {Imparsable} from ".."; import {DescriptionManager} from "../description-manager"; import {ParsingSchema} from "../types"; export type Constructor = { new(): T; } export type DecoratedClass> = C & { prototype: { toJSON(): any } }; export type ClassDecoratorOptions = Partial> export function imparsable(parsingDescription?: ClassDecoratorOptions) { return function >(constructor: C): DecoratedClass { let maker = new ClassDecoratorMaker(); if (parsingDescription) DescriptionManager.mergeDescription(constructor, parsingDescription); // constructor = DescriptionManager.decorateClass(constructor, parsingDescription) as C; return maker.decorateConstructor(constructor); } } class ClassDecoratorMaker> { decorateConstructor(constructor: C): DecoratedClass { if (constructor.prototype.toJSON == null) { constructor.prototype.toJSON = function () { return Imparsable.stringify(this); }; } return constructor; } }