UNPKG

@decaf-ts/decorator-validation

Version:
54 lines (53 loc) 1.9 kB
import { Constructor } from "../model/types"; import { Serializer } from "./types"; import { Model } from "../model/Model"; export declare const DefaultSerializationMethod = "json"; /** * @summary Concrete implementation of a {@link Serializer} in JSON format * @description JS's native JSON.stringify (used here) is not deterministic * and therefore should not be used for hashing purposes * * To keep dependencies low, we will not implement this, but we recommend * implementing a similar {@link JSONSerializer} using 'deterministic-json' libraries * * @class JSONSerializer * @implements Serializer * * @category Model */ export declare class JSONSerializer<T extends Model> implements Serializer<T> { constructor(); /** * @summary prepares the model for serialization * @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property * so the object can be recognized upon deserialization * * @param {T} model * @protected */ protected preSerialize(model: T): Record<string, any>; /** * @summary Rebuilds a model from a serialization * @param {string} str * * @throws {Error} If it fails to parse the string, or to build the model */ deserialize(str: string): T; /** * @summary Serializes a model * @param {T} model * * @throws {Error} if fails to serialize */ serialize(model: T): string; } export declare class Serialization { private static current; private static cache; private constructor(); private static get; static register(key: string, func: Constructor<Serializer<any>>, setDefault?: boolean): void; static serialize(obj: any, method?: string, ...args: any[]): any; static deserialize(obj: string, method?: string, ...args: any[]): any; static setDefault(method: string): void; }