import { ReceiveType } from './reflection/reflection.js'; import { NamingStrategy, SerializationOptions, SerializeFunction, Serializer, TemplateRegistry } from './serializer.js'; import { JSONPartial, JSONSingle } from './utils.js'; import { DeepPartial } from './changes.js'; import { TypeClass, TypeObjectLiteral } from './reflection/type.js'; /** * Casts/coerces a given data structure to the target data type and validates all attached validators. * * Same as validatedDeserialize(). * * @throws ValidationError if casting or validation fails */ export declare function cast(data: JSONPartial | unknown, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): T; /** * Same as cast but returns a ready to use function. Used to improve performance. */ export declare function castFunction(serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): (data: JSONPartial | unknown, options?: SerializationOptions) => T; /** * Deserialize given data structure from JSON data objects to JavaScript objects, without running any validators. * * Types that are already correct will be used as-is. * * ```typescript * interface Data { * created: Date; * } * * const data = deserialize({created: '2009-02-13T23:31:30.123Z'}); * //data is {created: Date(2009-02-13T23:31:30.123Z)} * * @throws ValidationError when deserialization fails. * ``` */ export declare function deserialize(data: JSONPartial | unknown, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): T; /** * Same as deserialize but returns a ready to use function. Used to improve performance. */ export declare function deserializeFunction(serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): SerializeFunction; /** * Patch serialization for deep dot paths, e.g. `{'user.shippingAddress.street': 'abc'}` * If a naming strategy is used, it could be converted to `{'user.shipping_address.street': 'abc'}`. */ export declare function patch(data: DeepPartial, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): (data: JSONPartial | unknown) => T; /** * Create a serializer/deserializer function including validator for the given type for a patch structure. * This is handy for deep patch structures like e.g '{user.address.street: "new street"}'. */ export declare function getPatchSerializeFunction(type: TypeClass | TypeObjectLiteral, registry: TemplateRegistry, namingStrategy?: NamingStrategy): (data: any, state?: SerializationOptions, patch?: { normalizeArrayIndex: boolean; }) => any; /** * Serialize given data structure to JSON data objects (not a JSON string). * * The resulting JSON object can be stringified using JSON.stringify(). * * ```typescript * interface Data { * created: Date; * } * * const json = serialize({created: new Date(1234567890123)}); * //json is {created: '2009-02-13T23:31:30.123Z'} * * const jsonString = JSON.stringify(json); * //jsonString is '{"created":"2009-02-13T23:31:30.123Z"}' * ``` * * @throws ValidationError when serialization or validation fails. */ export declare function serialize(data: T, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): JSONSingle; /** * Same as serialize but returns a ready to use function. Used to improve performance. */ export declare function serializeFunction(serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): SerializeFunction; /** * Clones a class instance deeply. */ export declare function cloneClass(target: T, options?: SerializationOptions): T; /** * Tries to deserialize given data as T, and throws an error if it's not possible or validation after conversion fails. * * @deprecated use cast() instead * * @throws ValidationError when serialization or validation fails. */ export declare function validatedDeserialize(data: any, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType): T;