import { Injectable } from '@nestjs/common' ; import { StoreEventBus } from './store-event-bus' ; import { IEvent , AggregateRoot } from '@nestjs/cqrs' ; export interface Constructor < T > { new ( ... args ) : T ; } @ Injectable ( ) export class StoreEventPublisher { constructor ( private readonly eventBus ) { } mergeClassContext < T extends Constructor < AggregateRoot > > ( metatype ) { const eventBus = this . eventBus ; return class extends metatype { publish ( event ) { eventBus . publish ( event ) ; } } ; } mergeObjectContext < T extends AggregateRoot > ( object ) { const eventBus = this . eventBus ; object . publish = ( event ) => { eventBus . publish ( event ) ; } ; return object ; } }