import { Ctor , DependencyKey , Identifier , IdentifierSymbol } from './typings' ; import { dependencyIds , setDependencies } from './utils' ; export function createIdentifier < T > ( name ) { if ( dependencyIds . has ( name ) ) { console . warn ( `[wedi] duplicated identifier name ${ name }.` ) ; return dependencyIds . get ( name ) ! ; } const id = function ( target , _key , index ) : void { setDependencies ( target , id , index , false ) ; } as Identifier < T > ; id . toString = ( ) => name ; id [ IdentifierSymbol ] = true ; dependencyIds . set ( name , id ) ; return id ; } /**
 * wrap a Identifier with this function to make it optional
 */ export function Optional < T > ( key ) { return function ( target , _key , index ) { setDependencies ( target , key , index , true ) ; } ; } /**
 * used inside constructor for services to claim dependencies
 */ export function Need < T > ( key ) { return function < C > ( target , _key , index ) { setDependencies ( target , key , index , false ) ; } ; }