import * as METADATA_KEY from "../constants/metadata_keys" ; import { interfaces } from "../interfaces/interfaces" ; import { Metadata } from "../planning/metadata" ; const traverseAncerstors = ( request , constraint ) : boolean => { const parent = request . parentRequest ; if ( parent !== null ) { return constraint ( parent ) ? true : traverseAncerstors ( parent , constraint ) ; } else { return false ; } } ; const taggedConstraint = ( key ) => ( value ) => { const constraint = ( request ) => request !== null && request . target !== null && request . target . matchesTag ( key ) ( value ) ; constraint . metaData = new Metadata ( key , value ) ; return constraint ; } ; const namedConstraint = taggedConstraint ( METADATA_KEY . NAMED_TAG ) ; const typeConstraint = ( type ) => ( request ) => { let binding = null ; if ( request !== null ) { binding = request . bindings [ 0 ] as interfaces . Binding < unknown > ; if ( typeof type === "string" ) { const serviceIdentifier = binding . serviceIdentifier ; return serviceIdentifier === type ; } else { const constructor = ( request . bindings [ 0 ] as interfaces . Binding < unknown > ) . implementationType ; return type === constructor ; } } return false ; } ; export { traverseAncerstors , taggedConstraint , namedConstraint , typeConstraint } ;