import * as METADATA_KEY from '../constants/metadata_keys' ; import { interfaces } from '../interfaces/interfaces' ; import { id } from '../utils/id' ; import { getSymbolDescription } from '../utils/serialization' ; import { Metadata } from './metadata' ; import { QueryableString } from './queryable_string' ; class Target implements interfaces . Target { public id : number ; public type : interfaces . TargetType ; public serviceIdentifier : interfaces . ServiceIdentifier ; public name : interfaces . QueryableString ; public identifier : string | symbol ; public key ! : string | symbol ; public metadata ! : Metadata [ ] ; public constructor ( type , identifier , serviceIdentifier , namedOrTagged ? ) { this . id = id ( ) ; this . type = type ; this . serviceIdentifier = serviceIdentifier ; const queryableName = typeof identifier === 'symbol' ? getSymbolDescription ( identifier ) : identifier ; this . name = new QueryableString ( queryableName || "" ) ; this . identifier = identifier ; this . metadata = new Array ( ) ; let metadataItem = null ; if ( typeof namedOrTagged === 'string' ) { metadataItem = new Metadata ( METADATA_KEY . NAMED_TAG , namedOrTagged ) ; } else if ( namedOrTagged instanceof Metadata ) { metadataItem = namedOrTagged ; } if ( metadataItem !== null ) { this . metadata . push ( metadataItem ) ; } } public hasTag ( key ) { for ( const m of this . metadata ) { if ( m . key === key ) { return true ; } } return false ; } public isArray ( ) { return this . hasTag ( METADATA_KEY . MULTI_INJECT_TAG ) ; } public matchesArray ( name ) { return this . matchesTag ( METADATA_KEY . MULTI_INJECT_TAG ) ( name ) ; } public isNamed ( ) { return this . hasTag ( METADATA_KEY . NAMED_TAG ) ; } public isTagged ( ) { return this . metadata . some ( ( metadata ) => METADATA_KEY . NON_CUSTOM_TAG_KEYS . every ( ( key ) => metadata . key !== key ) ) ; } public isOptional ( ) { return this . matchesTag ( METADATA_KEY . OPTIONAL_TAG ) ( true ) ; } public getNamedTag ( ) { if ( this . isNamed ( ) ) { return this . metadata . filter ( ( m ) => m . key === METADATA_KEY . NAMED_TAG ) [ 0 ] as interfaces . Metadata < string > ; } return null ; } public getCustomTags ( ) { if ( this . isTagged ( ) ) { return this . metadata . filter ( ( metadata ) => METADATA_KEY . NON_CUSTOM_TAG_KEYS . every ( ( key ) => metadata . key !== key ) ) ; } else { return null ; } } public matchesNamedTag ( name ) { return this . matchesTag ( METADATA_KEY . NAMED_TAG ) ( name ) ; } public matchesTag ( key ) { return ( value ) => { for ( const m of this . metadata ) { if ( m . key === key && m . value === value ) { return true ; } } return false ; } ; } } export { Target } ;