import { Logger } from "../logger" ; import { Metadata , ServiceMetadata } from "../metadata" ; import { Context } from "../types" ; export interface Service { log ? : Logger ; activate ? ( ctx ? ) : Promise < void > ; release ? ( ctx ? ) : Promise < void > ; } export function Service ( name ? ) { return function ( type ) { name = name || type . name ; let meta = ServiceMetadata . get ( type ) ; meta . name = meta . service = name ; for ( let x of Object . keys ( meta . permissions ) ) meta . permissions [ x ] . service = name ; for ( let x of Object . keys ( meta . httpMetadata ) ) meta . httpMetadata [ x ] . service = name ; for ( let x of Object . keys ( meta . remoteMetadata ) ) meta . remoteMetadata [ x ] . service = name ; for ( let x of Object . keys ( meta . bindingMetadata ) ) meta . bindingMetadata [ x ] . service = name ; for ( let x of Object . keys ( meta . eventMetadata ) ) meta . eventMetadata [ x ] . forEach ( h => h . service = name ) ; } ; } export function Inject ( resource ? , application ? ) { return function ( type , propertyKey ) { if ( ! resource ) { resource = Reflect . getMetadata ( "design:type" , type , propertyKey ) ; } if ( resource instanceof Function ) { resource = resource . name ; } else { resource = resource . toString ( ) ; } let metadata = Metadata . get ( type ) ; metadata . dependencies = metadata . dependencies || { } ; metadata . dependencies [ propertyKey ] = { resource , application } ; } ; }