import { Id } from '@centsideas/types' ; import { StreamVersion } from './stream-version' ; import { IDomainEvent } from './domain-event' ; class StreamEvent { constructor ( public readonly event , public readonly version ) { } } export class StreamEvents { constructor ( public readonly aggregateId , private readonly events ) { } static empty ( id ) { return new StreamEvents ( id , [ ] ) ; } add ( event , version ) { /**
         * create a copy of the `StreamVersion` because it would otherwise
         * continue counting when this.version.next() is invoked
         */ const versionCopy = StreamVersion . fromNumber ( version . toNumber ( ) ) ; this . events . push ( new StreamEvent ( event , versionCopy ) ) ; } toArray ( ) { return this . events ; } toEvents ( ) { return this . events . map ( e => e . event ) ; } isEmpty ( ) { return this . events . length <= 0 ; } }