import 'reflect-metadata' ; import { ScalarType } from '../helpers/scalar-type' ; import { MetadataManager } from '../metadata/metadata-manager' ; import { AttributeRawMetadataOptions , PrimaryKey , } from '../metadata/metadata-storage' ; import { MissingReflectMetadataError } from '../error' ; export type AttributeOptionsUniqueType = boolean | PrimaryKey ; export interface AttributeOptions < Entity > { default unique ? : AttributeOptionsUniqueType ; required default isEnum ? : boolean ; /**
     * Assign default value to attribute
     */ default ? : ScalarType | ( ( entity : Entity ) => ScalarType ) ; default hidden ? : boolean ; } export function Attribute < Entity = any > ( options ? ) { return ( target , propertyKey ) : void => { const reflectedMetadata = Reflect . getMetadata ( 'design:type' , target , propertyKey ) ; if ( ! reflectedMetadata ) { throw new MissingReflectMetadataError ( 'design:type' ) ; } let type = reflectedMetadata . name ; if ( options ?. isEnum ) { type = 'String' ; } const attributeProps = { name : propertyKey . toString ( ) , type , unique : options ?. unique , default : options ?. default , hidden : options ?. hidden , } as AttributeRawMetadataOptions ; MetadataManager . metadataStorage . addRawAttribute ( target . constructor , attributeProps ) ; } ; }