/** * A {@link ReadCodec} defines how some data type, {@link T}, is parsed from a `string` or {@link Buffer}. */ export interface ReadCodec { /** * Parse the serialized {@link value} into a data object, {@link T}. */ read(value: string): T; } /** * A {@link WriteCodec} defines how some data type, {@link T}, is serialize as a `string` or {@link Buffer}. */ export interface WriteCodec { /** * Serialize a data object, {@link T}, to a `string` or {@link Buffer}. */ write(value: T): string; } /** * A {@link Codec} defines how some data type, {@link T}, is serialized to/from a `string` or {@link Buffer}. */ export interface Codec extends ReadCodec, WriteCodec { } export declare enum DataType { String = "String", Json = "Json" } /** * A {@link Serializer} creates a {@link Codec} for serializing a data type, {@link T}. */ export interface Serializer { dataType: DataType; /** * Create a {@link Codec} for serializing data objects of type, {@link T}. */ create(): Codec; } export declare namespace Serializer { function text(): TextSerializer; function json(props?: JsonSerializerProps): JsonSerializer; } export declare class TextSerializer implements Serializer { readonly dataType = DataType.String; create(): Codec; } export interface JsonSerializerProps { /** * Optional validation logic to run on values prior to serialization and after deserialization. */ validate?: (value: any) => asserts value is T; /** * Optional reviver function to be passed to {@link JSON.parse}. */ reviver?: (this: any, key: string, value: any) => any; /** * Optional replacer function to be passed to {@link JSON.replacer}. */ replacer?: (this: any, key: string, value: any) => any; } /** * A {@link Serializer} for reading and writing data objects as JSON using * NodeJS's intrinsic {@link JSON.parse} and {@link JSON.stringify} functions. */ export declare class JsonSerializer implements Serializer { readonly props?: JsonSerializerProps | undefined; readonly dataType = DataType.Json; constructor(props?: JsonSerializerProps | undefined); create(): Codec; } //# sourceMappingURL=serializer.d.ts.map