Versions in this module Expand all Collapse all v1 v1.0.1 Apr 10, 2022 Changes in this version + var ErrAggregateAlreadyExists = errors.New("aggregate already exists") + var ErrAggregateNotFound = errors.New("aggregate not found") + var ErrAggregateRequiresEvents = errors.New("an aggregate requires events") + var ErrOptimisticConcurrency = errors.New("optimistic concurrency error") + var ErrSnapshotWithGreaterVersionThanAggregate = errors.New("snapshot version is greater than that of the aggregate") + type Aggregate interface + Changes func() []Event + ID func() ID + InitialVersion func() int + Snapshot func() ([]byte, error) + type AggregateFactory interface + NewAggregateFromEvents func([]Event) (T, error) + NewAggregateFromSnapshotAndEvents func(RawSnapshot, []Event) (T, error) + type AggregateType string + type Event interface + EventName func() string + type EventFactory interface + CreateEmptyEvent func(name string) (Event, error) + type EventMarshaler interface + MarshalEvent func(Event) ([]byte, error) + UnmarshalEvent func([]byte, Event) error + type EventRaiserAggregate struct + func NewEventRaiserAggregate(onEvent func(Event)) EventRaiserAggregate + func NewEventRaiserAggregateFromEvents(initialVersion int, events []Event, onEvent func(Event)) EventRaiserAggregate + func (a *EventRaiserAggregate) Raise(e Event) + func (a EventRaiserAggregate) Changes() []Event + func (a EventRaiserAggregate) InitialVersion() int + type EventStore interface + AddAggregate func(context.Context, AggregateType, ID, []RawEvent) error + AddSnapshot func(context.Context, AggregateType, ID, RawSnapshot) error + AppendEvents func(ctx context.Context, t AggregateType, id ID, fromVersion int, ...) error + ContainsAggregate func(context.Context, AggregateType, ID) (bool, error) + Events func(ctx context.Context, t AggregateType, id ID, fromEventNumber int) ([]RawEvent, error) + LatestSnapshot func(context.Context, AggregateType, ID) (*RawSnapshot, error) + type ID any + type JSONEventMarshaler struct + func (JSONEventMarshaler) MarshalEvent(e Event) ([]byte, error) + func (JSONEventMarshaler) UnmarshalEvent(b []byte, e Event) error + type MockAggregate struct + ChangesFn func() []Event + IDFn func() ID + InitialVersionFn func() int + SnapshotFn func() ([]byte, error) + func (m *MockAggregate) Changes() []Event + func (m *MockAggregate) ID() ID + func (m *MockAggregate) InitialVersion() int + func (m *MockAggregate) Snapshot() ([]byte, error) + type MockAggregateFactory struct + NewAggregateFromEventsFn func([]Event) (T, error) + NewAggregateFromSnapshotAndEventsFn func(RawSnapshot, []Event) (T, error) + func (m *MockAggregateFactory[T]) NewAggregateFromEvents(events []Event) (T, error) + func (m *MockAggregateFactory[T]) NewAggregateFromSnapshotAndEvents(snapshot RawSnapshot, events []Event) (T, error) + type MockEvent struct + EventNameFn func() string + func (m *MockEvent) EventName() string + type MockEventFactory struct + CreateEmptyEventFn func(name string) (Event, error) + func (m *MockEventFactory) CreateEmptyEvent(name string) (Event, error) + type MockEventMarshaler struct + MarshalEventFn func(Event) ([]byte, error) + UnmarshalEventFn func([]byte, Event) error + func (m *MockEventMarshaler) MarshalEvent(e Event) ([]byte, error) + func (m *MockEventMarshaler) UnmarshalEvent(b []byte, e Event) error + type MockEventStore struct + AddAggregateFn func(context.Context, AggregateType, ID, []RawEvent) error + AddSnapshotFn func(context.Context, AggregateType, ID, RawSnapshot) error + AppendEventsFn func(ctx context.Context, t AggregateType, id ID, fromVersion int, ...) error + ContainsAggregateFn func(context.Context, AggregateType, ID) (bool, error) + EventsFn func(context.Context, AggregateType, ID, int) ([]RawEvent, error) + LatestSnapshotFn func(context.Context, AggregateType, ID) (*RawSnapshot, error) + func (m *MockEventStore) AddAggregate(ctx context.Context, t AggregateType, id ID, re []RawEvent) error + func (m *MockEventStore) AddSnapshot(ctx context.Context, t AggregateType, id ID, snapshot RawSnapshot) error + func (m *MockEventStore) AppendEvents(ctx context.Context, t AggregateType, id ID, fromVersion int, ...) error + func (m *MockEventStore) ContainsAggregate(ctx context.Context, t AggregateType, id ID) (bool, error) + func (m *MockEventStore) Events(ctx context.Context, t AggregateType, id ID, fromEventNumber int) ([]RawEvent, error) + func (m *MockEventStore) LatestSnapshot(ctx context.Context, t AggregateType, id ID) (*RawSnapshot, error) + type RawEvent struct + Data []byte + Name string + func MarshalEvents(events []Event, marshaler EventMarshaler) ([]RawEvent, error) + type RawSnapshot struct + Data []byte + Version int + type Repository struct + func NewRepository(es EventStore, af AggregateFactory[T], ef EventFactory, ...) *Repository[T] + func (r *Repository[T]) Add(ctx context.Context, aggregate T) error + func (r *Repository[T]) Contains(ctx context.Context, id ID) (bool, error) + func (r *Repository[T]) FindByID(ctx context.Context, id ID) (T, error) + func (r *Repository[T]) Update(ctx context.Context, aggregate T) error + func (r *Repository[T]) UpdateByID(ctx context.Context, id ID, update func(aggregate T) error) error + type RepositoryOption func(*Repository[T]) + func RepositoryWithEventsMarshaler(eventMarshaler EventMarshaler) RepositoryOption[T] + func RepositoryWithEventsPerSnapshot(eventsPerSnapshot int) RepositoryOption[T] + func RepositoryWithLogger(log log.Logger) RepositoryOption[T]