neos / Neos.EventSourcing

A library for Event Sourcing and CQRS for Flow projects.
MIT License
44 stars 30 forks source link

Defer Event (de)normalization #241

Open bwaidelich opened 4 years ago

bwaidelich commented 4 years ago

Currently events are converted to an EventEnvelope instance (with RawEvent and the denormalized DomainEventInterface instance) when iterating an event stream.

Instead the denormalization should only happen when actually required (i.e. when invoking the corresponding when*() method).

bwaidelich commented 4 years ago

Some more thoughts I had on this one: IMO the notion of DomainEvent should be removed completely from the Event Store "sub package" so that it can be simplified to sth like:

final class Event {
    public function __construct(string $identifier, string $type, array $data, array $metadata)
}

(currently WriteableEvent) when committing events, and:

final class EventEnvelope {
    public function __construct(Event $event, StreamName $streamName, int $version, int $sequenceNumber, \DateTimeInterface $recordedAt)
}

when reading events.

The conversion from and to DomainEventInterface instances would happen outside of the Event Store part (and only as soon as required, if at all)

bwaidelich commented 4 years ago

As for the reasoning:

bwaidelich commented 2 years ago

An additional reason:

It's a major design flaw that EventStorageInterface::load() returns an EventStream (https://github.com/neos/Neos.EventSourcing/blob/master/Classes/EventStore/Storage/EventStorageInterface.php#L32) since the event stream requires an instance of the EventNormalizer (https://github.com/neos/Neos.EventSourcing/blob/master/Classes/EventStore/EventStream.php#L43)

=> for custom event type converters etc. we always have to create a dedicated EventStorage instance and the factory won't support that out of the box