import "reflect-metadata" ; import { MetadataStorage , DOption , OptionType , OptionValueType , OptionParams , Modifier , } from "../.." ; import { DSlash } from "../classes/DSlash" ; export function Option ( name ) ; export function Option ( name , type ) ; export function Option ( name , params ) ; export function Option ( name , type , params ) ; export function Option ( name , typeOrParams ? , params ? ) { return ( target , key , index ) => { const isParams = typeof typeOrParams === "object" ; let finalParams = params || { } ; let type = Reflect . getMetadata ( "design:paramtypes" , target , key ) [ index ] as OptionValueType ; if ( isParams ) { finalParams = typeOrParams as OptionParams ; } else if ( typeOrParams !== undefined ) { type = typeOrParams as OptionValueType ; } const option = DOption . create ( name || key , type , finalParams ?. description , finalParams ?. required , index ) . decorate ( target . constructor , key , target [ key ] , target . constructor , index ) ; option . isNode = true ; MetadataStorage . instance . addModifier ( Modifier . create < DSlash > ( async ( original ) => { original . options = [ ... original . options , option ] ; } , DSlash ) . decorate ( target . constructor , key , target [ key ] , target . constructor , index ) ) ; MetadataStorage . instance . addOption ( option ) ; } ; }