import { ServiceManager } from '../ServiceManager' ; const metaKey = Symbol ( 'stix:di:patch' ) ; type PatchArgumentsType = { name : string ; method : Function ; factory : boolean ; } ; export const patch = ( name , method , factory = false ) => { return ( target ) => { const meta = Reflect . getMetadata ( metaKey , target ) || [ ] ; meta . push ( { name , method , factory } ) ; Reflect . defineMetadata ( metaKey , meta , target ) ; } ; } ; export const applyPatches = ( sm , target ) => { const patches = Reflect . getMetadata ( metaKey , target . constructor ) ; if ( ! patches ) { return target ; } return patches . reduce ( ( target , { name , method , factory } ) => { if ( typeof target [ name ] !== 'function' ) { target [ name ] = ( factory ? method ( sm , target ) : method ) . bind ( target ) ; } return target ; } , target ) ; } ; type ServiceType = { [ property ] : any ; } ;