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UAAU,CAAC;YAEhI,OAAO,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,gBAAgB,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,EAAtD,CAAsD,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACrK,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AAbD,sDAaC","file":"decorators.js","sourcesContent":["import {ClassTransformer} from \"./ClassTransformer\";\r\nimport {defaultMetadataStorage} from \"./storage\";\r\nimport {TypeMetadata} from \"./metadata/TypeMetadata\";\r\nimport {ExposeMetadata} from \"./metadata/ExposeMetadata\";\r\nimport {ExposeOptions, ExcludeOptions, TypeHelpOptions, TransformOptions, Discriminator, TypeOptions} from \"./metadata/ExposeExcludeOptions\";\r\nimport {ExcludeMetadata} from \"./metadata/ExcludeMetadata\";\r\nimport {TransformMetadata} from \"./metadata/TransformMetadata\";\r\nimport {ClassTransformOptions} from \"./ClassTransformOptions\";\r\nimport {TransformationType} from \"./TransformOperationExecutor\";\r\n\r\n/**\r\n * Defines a custom logic for value transformation.\r\n */\r\nexport function Transform(transformFn: (value: any, obj: any, transformationType: TransformationType) => any, options?: TransformOptions) {\r\n return function(target: any, key: string) {\r\n const metadata = new TransformMetadata(target.constructor, key, transformFn, options);\r\n defaultMetadataStorage.addTransformMetadata(metadata);\r\n };\r\n}\r\n\r\n/**\r\n * Specifies a type of the property.\r\n * The given TypeFunction can return a constructor. A discriminator can be given in the options.\r\n */\r\nexport function Type(typeFunction?: (type?: TypeHelpOptions) => Function, options?: TypeOptions) {\r\n return function(target: any, key: string) {\r\n const type = (Reflect as any).getMetadata(\"design:type\", target, key);\r\n const metadata = new TypeMetadata(target.constructor, key, type, typeFunction, options);\r\n defaultMetadataStorage.addTypeMetadata(metadata);\r\n };\r\n}\r\n\r\n/**\r\n * Marks property as included in the process of transformation. By default it includes the property for both\r\n * constructorToPlain and plainToConstructor transformations, however you can specify on which of transformation types\r\n * you want to skip this property.\r\n */\r\nexport function Expose(options?: ExposeOptions) {\r\n return function(object: Object|Function, propertyName?: string) {\r\n const metadata = new ExposeMetadata(object instanceof Function ? object : object.constructor, propertyName, options || {});\r\n defaultMetadataStorage.addExposeMetadata(metadata);\r\n };\r\n}\r\n\r\n/**\r\n * Marks property as excluded from the process of transformation. By default it excludes the property for both\r\n * constructorToPlain and plainToConstructor transformations, however you can specify on which of transformation types\r\n * you want to skip this property.\r\n */\r\nexport function Exclude(options?: ExcludeOptions) {\r\n return function(object: Object|Function, propertyName?: string) {\r\n const metadata = new ExcludeMetadata(object instanceof Function ? object : object.constructor, propertyName, options || {});\r\n defaultMetadataStorage.addExcludeMetadata(metadata);\r\n };\r\n}\r\n\r\n/**\r\n * Transform the object from class to plain object and return only with the exposed properties.\r\n */\r\nexport function TransformClassToPlain(params?: ClassTransformOptions): Function {\r\n\r\n return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {\r\n const classTransformer: ClassTransformer = new ClassTransformer();\r\n const originalMethod = descriptor.value;\r\n\r\n descriptor.value = function(...args: any[]) {\r\n const result: any = originalMethod.apply(this, args);\r\n const isPromise = !!result && (typeof result === \"object\" || typeof result === \"function\") && typeof result.then === \"function\";\r\n\r\n return isPromise ? result.then((data: any) => classTransformer.classToPlain(data, params)) : classTransformer.classToPlain(result, params);\r\n };\r\n };\r\n}\r\n\r\n/**\r\n * Return the class instance only with the exposed properties.\r\n */\r\nexport function TransformClassToClass(params?: ClassTransformOptions): Function {\r\n\r\n return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {\r\n const classTransformer: ClassTransformer = new ClassTransformer();\r\n const originalMethod = descriptor.value;\r\n\r\n descriptor.value = function(...args: any[]) {\r\n const result: any = originalMethod.apply(this, args);\r\n const isPromise = !!result && (typeof result === \"object\" || typeof result === \"function\") && typeof result.then === \"function\";\r\n\r\n return isPromise ? result.then((data: any) => classTransformer.classToClass(data, params)) : classTransformer.classToClass(result, params);\r\n };\r\n };\r\n}\r\n\r\n/**\r\n * Return the class instance only with the exposed properties.\r\n */\r\nexport function TransformPlainToClass(classType: any, params?: ClassTransformOptions): Function {\r\n\r\n return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {\r\n const classTransformer: ClassTransformer = new ClassTransformer();\r\n const originalMethod = descriptor.value;\r\n\r\n descriptor.value = function(...args: any[]) {\r\n const result: any = originalMethod.apply(this, args);\r\n const isPromise = !!result && (typeof result === \"object\" || typeof result === \"function\") && typeof result.then === \"function\";\r\n\r\n return isPromise ? result.then((data: any) => classTransformer.plainToClass(classType, data, params)) : classTransformer.plainToClass(classType, result, params);\r\n };\r\n };\r\n}\r\n"],"sourceRoot":"."}
\No newline at end of file