UNPKG

@creamapi/cream

Version:

Concise REST API Maker - An extension library for express to create REST APIs faster

29 lines (28 loc) 1.21 kB
export declare const SERIALIZER_TRANSFORM_METADATA_KEY: unique symbol; /** * This decorator is used to transform a piece of data to another piece of data * Transform can change the data type aswell and the serializer will be able to detect it * * @remarks Transform only works with static transformations. Transformation that depend * on the current object (`this`) cannot be created with this method. For those kind of * methods it is preferrable to use {@link AutoMap} or {@link MapTo} with getters. * Also note that Transform is applied on a bottom-up approach, so Transform closer to * the decorated attribute will be applied first * * @example * ```ts * \@Serializable(CreamSerializers.JSON) * class MyClass { * * \@Transform((data: boolean) => data ? "data is enough" : "data is not enough") * \@Transform((data: number) => data < 5) * \@AutoMap * myData: number * } * ``` * * @param tranformFunction the lambda used for transforming the datum into a new piece * of information * @returns the decorator that will decorate the class field. */ export declare function Transform<T, R>(tranformFunction: (data: T) => R): (target: any, propertyName: string) => void;