@decaf-ts/decorator-validation
Version:
simple decorator based validation engine
42 lines (41 loc) • 1.42 kB
TypeScript
import { Serializer } from "./types";
import { Model } from "../model/Model";
/**
* @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<boolean>> 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, ...args: any[]): 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, ...args: any[]): T;
/**
* @summary Serializes a model
* @param {T} model
*
* @throws {Error} if fails to serialize
*/
serialize(model: T, ...args: any[]): string;
}