import 'reflect-metadata' ; export class NamespacedReflect { param namespace constructor ( private namespace ? ) { } private getMetadataKey ( metadataKey ) { return this . namespace ? this . namespace + ':' + metadataKey : metadataKey ; } /**
     * define metadata for a target class or it's property/method
     */ defineMetadata ( metadataKey , metadataValue , target , propertyKey ? ) { metadataKey = this . getMetadataKey ( metadataKey ) ; if ( propertyKey ) { Reflect . defineMetadata ( metadataKey , metadataValue , target , propertyKey ) ; } else { Reflect . defineMetadata ( metadataKey , metadataValue , target ) ; } } /**
     * lookup metadata from a target object and its prototype chain
     */ getMetadata ( metadataKey , target , propertyKey ? ) { metadataKey = this . getMetadataKey ( metadataKey ) ; if ( propertyKey ) { return Reflect . getMetadata ( metadataKey , target , propertyKey ) ; } return Reflect . getMetadata ( metadataKey , target ) ; } /**
     * get own metadata for a target object or it's property/method
     */ getOwnMetadata ( metadataKey , target , propertyKey ? ) { metadataKey = this . getMetadataKey ( metadataKey ) ; if ( propertyKey ) { return Reflect . getOwnMetadata ( metadataKey , target , propertyKey ) ; } return Reflect . getOwnMetadata ( metadataKey , target ) ; } param metadataKey param target param propertyKey hasMetadata ( metadataKey , target , propertyKey ? ) { metadataKey = this . getMetadataKey ( metadataKey ) ; if ( propertyKey ) { return Reflect . hasMetadata ( metadataKey , target , propertyKey ) ; } return Reflect . hasMetadata ( metadataKey , target ) ; } hasOwnMetadata ( metadataKey , target , propertyKey ? ) { metadataKey = this . getMetadataKey ( metadataKey ) ; if ( propertyKey ) { return Reflect . hasOwnMetadata ( metadataKey , target , propertyKey ) ; } return Reflect . hasOwnMetadata ( metadataKey , target ) ; } deleteMetadata ( metadataKey , target , propertyKey ? ) { metadataKey = this . getMetadataKey ( metadataKey ) ; if ( propertyKey ) { return Reflect . deleteMetadata ( metadataKey , target , propertyKey ) ; } return Reflect . deleteMetadata ( metadataKey , target ) ; } getMetadataKeys ( target , propertyKey ? ) { let keys ; if ( propertyKey ) { keys = Reflect . getMetadataKeys ( target , propertyKey ) ; } else { keys = Reflect . getMetadataKeys ( target ) ; } const metaKeys = [ ] ; if ( keys ) { if ( ! this . namespace ) return keys ; const prefix = this . namespace + ':' ; for ( const key of keys ) { if ( key . indexOf ( prefix ) === 0 ) { metaKeys . push ( key . substr ( prefix . length ) ) ; } } } return metaKeys ; } getOwnMetadataKeys ( target , propertyKey ? ) { let keys ; if ( propertyKey ) { keys = Reflect . getOwnMetadataKeys ( target , propertyKey ) ; } else { keys = Reflect . getOwnMetadataKeys ( target ) ; } const metaKeys = [ ] ; if ( keys ) { if ( ! this . namespace ) return keys ; const prefix = this . namespace + ':' ; for ( const key of keys ) { if ( key . indexOf ( prefix ) === 0 ) { metaKeys . push ( key . substr ( prefix . length ) ) ; } } } return metaKeys ; } decorate ( decorators , target , targetKey ? , descriptor ? ) ; decorate ( decorators , target ) ; decorate ( decorators , target , targetKey ? , descriptor ? ) { if ( targetKey ) { return Reflect . decorate ( < ( PropertyDecorator | MethodDecorator ) [ ] > decorators , target , targetKey , descriptor ) ; } else { return Reflect . decorate ( < ClassDecorator [ ] > decorators , < Function > target ) ; } } metadata ( metadataKey , metadataValue ) { metadataKey = this . getMetadataKey ( metadataKey ) ; return Reflect . metadata ( metadataKey , metadataValue ) ; } } export const Reflector = new NamespacedReflect ( 'loopback' ) ;