Overview
What this package owns in the runtime
Event source adds aggregate rehydration, stream persistence, optimistic concurrency checks, and stored-event publication to xtaskjs. It keeps event application inside aggregate roots while exposing repositories, stores, publishers, and subscribers through the same DI lifecycle used by the rest of the framework.
What it provides
- EventSourcedAggregate() and ApplyEvent() let aggregates raise and replay domain events with explicit appliers.
- EventSourceRepository is registered in the container and supports create(), load(), loadOrCreate(), and save() with optimistic stream appends.
- InMemoryEventStore works by default, while createTypeOrmEventStore() adds durable event-stream persistence.
- createQueueEventPublisher() and EventSourceSubscriber() connect stored events to queues, projections, and side-effect handlers without replacing CQRS buses.
How it fits
- Configured through @EventSource(...) or configureEventSource() before CreateApplication() so store and publisher bindings are ready during bootstrap.
- Pairs naturally with @xtaskjs/typeorm for durable event storage and with @xtaskjs/queues for broker-backed event publication.
- Works beside @xtaskjs/cqrs when commands load aggregates through repositories and downstream read models react to stored events.