import { EventName } from '@centsideas/types/event-name' ; import { DomainEventInstance , EVENT_NAME_METADATA } from './domain-event' ; import { Aggregate } from './aggregate' ; /**
 * Takes an event class as an argument of the decorator
 * The method which is decorated will be called to handle
 * the aggregates state update
 */ export const Apply = ( Event ) => { return function ApplyDecorator ( target , propertyKey ) { if ( ! ( target instanceof Aggregate ) ) throw new Error ( `@Apply() decorator can only be used inside an Aggregate class.` + ` But ${ target } does not extend Aggregate!` ) ; /**
         * Get the event's name from the metadata saved on the
         * class of the event
         */ const eventName = EventName . fromString ( Reflect . getMetadata ( EVENT_NAME_METADATA , Event . prototype ) ) ; param eventName method Reflect . defineMetadata ( eventName . toString ( ) , propertyKey , target ) ; } ; } ;