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,CAAA;AAED;;GAEG;AACH,+BAAsC,MAA8B;IAEhE,MAAM,CAAC,UAAU,MAAgB,EAAE,WAAmB,EAAE,UAA8B;QAClF,IAAM,gBAAgB,GAAqB,IAAI,mCAAgB,EAAE,CAAC;QAClE,IAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG;YAAS,cAAc;iBAAd,WAAc,CAAd,sBAAc,CAAd,IAAc;gBAAd,6BAAc;;YACtC,IAAM,MAAM,GAAQ,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACrD,IAAM,SAAS,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;YAEhI,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,gBAAgB,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAA3C,CAA2C,CAAC,GAAG,gBAAgB,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/I,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AAbe,6BAAqB,wBAapC,CAAA","file":"decorators.js","sourcesContent":["import {ClassTransformer} from \"./ClassTransformer\";\nimport {defaultMetadataStorage} from \"./storage\";\nimport {TypeMetadata} from \"./metadata/TypeMetadata\";\nimport {ExposeMetadata} from \"./metadata/ExposeMetadata\";\nimport {ExposeOptions, ExcludeOptions, TypeOptions, TransformOptions} from \"./metadata/ExposeExcludeOptions\";\nimport {ExcludeMetadata} from \"./metadata/ExcludeMetadata\";\nimport {TransformMetadata} from \"./metadata/TransformMetadata\";\nimport {ClassTransformOptions} from \"./ClassTransformOptions\";\n\n/**\n * Defines a custom logic for value transformation.\n */\nexport function Transform(transformFn: (value: any) => any, options?: TransformOptions) {\n return function(target: any, key: string) {\n const metadata = new TransformMetadata(target.constructor, key, transformFn, options);\n defaultMetadataStorage.addTransformMetadata(metadata);\n };\n}\n\n/**\n * Specifies a type of the property.\n */\nexport function Type(typeFunction?: (type?: TypeOptions) => Function) {\n return function(target: any, key: string) {\n const type = (Reflect as any).getMetadata(\"design:type\", target, key);\n const metadata = new TypeMetadata(target.constructor, key, type, typeFunction);\n defaultMetadataStorage.addTypeMetadata(metadata);\n };\n}\n\n/**\n * Marks property as included in the process of transformation. By default it includes the property for both\n * constructorToPlain and plainToConstructor transformations, however you can specify on which of transformation types\n * you want to skip this property.\n */\nexport function Expose(options?: ExposeOptions) {\n return function(object: Object|Function, propertyName?: string) {\n const metadata = new ExposeMetadata(object instanceof Function ? object : object.constructor, propertyName, options || {});\n defaultMetadataStorage.addExposeMetadata(metadata);\n };\n}\n\n/**\n * Marks property as excluded from the process of transformation. By default it excludes the property for both\n * constructorToPlain and plainToConstructor transformations, however you can specify on which of transformation types\n * you want to skip this property.\n */\nexport function Exclude(options?: ExcludeOptions) {\n return function(object: Object|Function, propertyName?: string) {\n const metadata = new ExcludeMetadata(object instanceof Function ? object : object.constructor, propertyName, options || {});\n defaultMetadataStorage.addExcludeMetadata(metadata);\n };\n}\n\n/**\n * Transform the object from class to plain object and return only with the exposed properties.\n */\nexport function TransformClassToPlain(params?: ClassTransformOptions): Function {\n\n return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {\n const classTransformer: ClassTransformer = new ClassTransformer();\n const originalMethod = descriptor.value;\n \n descriptor.value = function(...args: any[]) {\n const result: any = originalMethod.apply(this, args);\n const isPromise = !!result && (typeof result === \"object\" || typeof result === \"function\") && typeof result.then === \"function\"; \n\n return isPromise ? result.then((data: any) => classTransformer.classToPlain(data, params)) : classTransformer.classToPlain(result, params);\n };\n };\n}\n\n/**\n * Return the class instance only with the exposed properties.\n */\nexport function TransformClassToClass(params?: ClassTransformOptions): Function {\n\n return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {\n const classTransformer: ClassTransformer = new ClassTransformer();\n const originalMethod = descriptor.value;\n \n descriptor.value = function(...args: any[]) {\n const result: any = originalMethod.apply(this, args);\n const isPromise = !!result && (typeof result === \"object\" || typeof result === \"function\") && typeof result.then === \"function\";\n\n return isPromise ? result.then((data: any) => classTransformer.classToClass(data, params)) : classTransformer.classToClass(result, params);\n };\n };\n}"],"sourceRoot":"."}
\No newline at end of file