import {Type} from "./Type"; import {Model} from "../Model"; /** * Type definition of the constructor of a specific type. */ export type ConstructorOf = { new(): T; } /** * Type of a Sharkitek model value. */ export class ModelType extends Type { /** * Constructs a new model type of a Sharkitek model property. * @param modelConstructor - Constructor of the model. */ constructor(protected modelConstructor: ConstructorOf) { super(); } serialize(value: M): any { // Serializing the given model. return value.serialize(); } deserialize(value: any): M { // Deserializing the given object in the new model. return (new this.modelConstructor()).deserialize(value); } serializeDiff(value: M): any { // Serializing the given model. return value.serializeDiff(); } resetDiff(value: M): void { // Reset diff of the given model. value.resetDiff(); } } /** * Type of a Sharkitek model value. * @param modelConstructor - Constructor of the model. */ export function SModel(modelConstructor: ConstructorOf) { return new ModelType(modelConstructor); }