UNPKG

@pebula/metap

Version:
46 lines (45 loc) 2.52 kB
import { Constructor } from '@pebula/utils'; import { SerializationFactory, BaseSerializer, BaseDeserializer } from '@pebula/metap/internal'; /** * Serialize a class instance into a plain object. * @param mapper * @param instance * @param type optional, if not set taken from instance.constructor * @returns */ export declare function serialize<T, Z>(serializer: BaseSerializer, target: Z & Constructor<T>): any; export declare function serialize<T, Z>(mapper: SerializationFactory, instance: T, target?: Z & Constructor<T>): any; /** * Automatically serialize an instance. * This method will serialize an instance by first trying to locate the target using the `constructor` function. * If a target is found and if it's a model target (i.e. ModelMetadata) it will try to get the mapper assign for that * model. * * If no target, model or mapper was found it will use the fallbackMapper mapper provided, or `directMapper` * if no fallback is provided provided. * * Note that when provided a fallback mapper, make sure it is able to serialize unknown targets. (plain objects) */ export declare function autoSerialize(instance: any, fallbackMapper?: SerializationFactory): any; /** * De-serialize a plain object into a the provided instance or, when no instance is provided, to a new instance. */ export declare function deserialize<T, Z extends Constructor<T>>(deserializer: BaseDeserializer<T, Z>, instance?: T): T; export declare function deserialize<T, Z>(mapper: SerializationFactory, plainObject: any, type: Z & Constructor<T>, instance?: T): T; /** * Automatically de-serialize an object to/into an instance. * This method will de-serialize an object by first trying to locate a model (i.e. ModelMetadata) for the target. * If a model is found it will try to get the mapper assign for that model. * * If no model or mapper was found it will use the fallbackMapper mapper provided, or `directMapper` * if no fallback is provided provided. * */ export declare function autoDeserialize<T, Z>(plainObject: any, type: Z & Constructor<T>, instance?: any, fallbackMapper?: SerializationFactory): T; /** * Performs a deep clone to the resource using serialization and deserialization, which means that all rules apply (i.e @Exclude) * * @param resource the resource (instance) to clone * @param serializationFactory Optional, The [[SerializationFactory]] to use, defaults to [[directMapper]]. */ export declare function clone<T>(resource: T, serializationFactory?: SerializationFactory): T;