idempotency-redis
Version:
Idempotency guarantee via Redis
48 lines (47 loc) • 1.79 kB
TypeScript
/**
* Interface defining a generic serializer.
*/
export interface Serializer<T> {
serialize(value: T): string;
deserialize(value: string): T;
}
/**
* A serializer for Error objects that utilizes serialize-error-cjs for
* converting Error objects to and from a JSON serializable format.
* This can be used as a base class for custom error serializers.
*/
export declare class DefaultErrorSerializer implements Serializer<Error> {
/**
* Serializes an Error object into a string using serialize-error-cjs and JSON.stringify.
* @param value The Error object to serialize.
* @returns A string representation of the Error.
*/
serialize(value: Error): string;
/**
* Deserializes a string back into an Error object using serialize-error-cjs and JSON.parse.
* Throws if the format is not recognized as a serialized Error object.
* @param value The string to deserialize.
* @returns The deserialized Error object.
* @throws SerializerError if the format is not recognized.
*/
deserialize(value: string): Error;
}
/**
* A JSON serializer that assumes the value is already in a JSON serializable format.
*/
export declare class JSONSerializer<T> implements Serializer<T> {
/**
* Serializes a value into a string using JSON.stringify.
* @param value The value to serialize.
* @returns A string representation of the value.
* @throws SerializerError if the value is not JSON serializable.
*/
serialize(value: T): string;
/**
* Deserializes a string back into a value using JSON.parse.
* @param value The string to deserialize.
* @returns The deserialized value.
* @throws SerializerError if the value is not valid JSON.
*/
deserialize(value: string): T;
}