es

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSnapshotStrategy = NewMaxChangesSnapshotStrategy(10)

DefaultSnapshotStrategy is a strategy that triggers snapshots every 10 changes

View Source
var ErrAggregateNotFound = errors.New("aggregate not found")

ErrAggregateNotFound is returned when no root was found for a given aggregate id

View Source
var ErrAggregateVersionMismatch = errors.New("aggregate version mismatch")

ErrAggregateVersionMismatch should be returned by stores when new events cannot be appended due to version conflicts

View Source
var ErrPendingChanges = fmt.Errorf("cannot process command while pending changes exist")

ErrPendingChanges is the error returned when a second command is applied to an aggregate without clearing changes

Functions

This section is empty.

Types

type Aggregate

type Aggregate interface {
	core.Entity

	ProcessCommand(command core.Command) error
	ApplyEvent(event core.Event) error
	ApplySnapshot(snapshot core.Snapshot) error
	ToSnapshot() (core.Snapshot, error)
	// contains filtered or unexported methods
}

Aggregate is a domain object that will be used at the base of other domain objects

type AggregateBase

type AggregateBase struct {
	core.EntityBase
	// contains filtered or unexported fields
}

AggregateBase provides aggregates a base to build on

func (AggregateBase) ID

func (a AggregateBase) ID() string

ID returns to the immutable ID of the aggregate

type AggregateRepository

type AggregateRepository interface {
	Load(ctx context.Context, aggregateID string) (*AggregateRoot, error)
	Save(ctx context.Context, command core.Command, options ...AggregateRootOption) (*AggregateRoot, error)
	Update(ctx context.Context, aggregateID string, command core.Command, options ...AggregateRootOption) (*AggregateRoot, error)
}

AggregateRepository interface

type AggregateRoot

type AggregateRoot struct {
	// contains filtered or unexported fields
}

AggregateRoot is the base for Aggregates

func NewAggregateRoot

func NewAggregateRoot(aggregate Aggregate, options ...AggregateRootOption) *AggregateRoot

NewAggregateRoot constructor for *AggregateRoot

func (*AggregateRoot) AddEvent

func (r *AggregateRoot) AddEvent(events ...core.Event)

AddEvent stores entity events on the aggregate

func (AggregateRoot) Aggregate

func (r AggregateRoot) Aggregate() Aggregate

Aggregate returns the aggregate that resides at the root

func (AggregateRoot) AggregateID

func (r AggregateRoot) AggregateID() string

AggregateID returns the ID for the root aggregate

func (AggregateRoot) AggregateName

func (r AggregateRoot) AggregateName() string

AggregateName returns the Name of the root aggregate

func (*AggregateRoot) ClearEvents

func (r *AggregateRoot) ClearEvents()

ClearEvents clears any pending events without committing them

func (*AggregateRoot) CommitEvents

func (r *AggregateRoot) CommitEvents()

CommitEvents clears any pending events and updates the last committed version value

func (AggregateRoot) EntityName

func (r AggregateRoot) EntityName() string

EntityName returns the Name of the root aggregate

func (AggregateRoot) Events

func (r AggregateRoot) Events() []core.Event

Events returns the list of pending events

func (AggregateRoot) ID

func (r AggregateRoot) ID() string

ID returns the ID for the root aggregate

func (*AggregateRoot) LoadEvent

func (r *AggregateRoot) LoadEvent(events ...core.Event) error

LoadEvent is used to rerun events essentially left folding over the aggregate state

func (*AggregateRoot) LoadSnapshot

func (r *AggregateRoot) LoadSnapshot(snapshot core.Snapshot, version int) error

LoadSnapshot is used to apply a snapshot to the aggregate to save having to rerun all events

func (AggregateRoot) PendingVersion

func (r AggregateRoot) PendingVersion() int

PendingVersion is the version of the aggregate taking into account pending events

func (*AggregateRoot) ProcessCommand

func (r *AggregateRoot) ProcessCommand(command core.Command) error

ProcessCommand runs the command and records the changes as pending events or returns an error

func (AggregateRoot) Version

func (r AggregateRoot) Version() int

Version is the version of the aggregate as it was created or loaded

type AggregateRootOption

type AggregateRootOption func(r *AggregateRoot)

AggregateRootOption options for AggregateRoots

func WithAggregateRootID

func WithAggregateRootID(aggregateID string) AggregateRootOption

WithAggregateRootID is an option to set the ID of the AggregateRoot

type AggregateRootRepository

type AggregateRootRepository struct {
	// contains filtered or unexported fields
}

AggregateRootRepository uses stores to load and save the changes to aggregates as events

func NewAggregateRootRepository

func NewAggregateRootRepository(constructor func() Aggregate, store AggregateRootStore) *AggregateRootRepository

NewAggregateRootRepository constructs a new AggregateRootRepository

func (*AggregateRootRepository) Load

func (r *AggregateRootRepository) Load(ctx context.Context, aggregateID string) (*AggregateRoot, error)

Load finds aggregates in the provided store

func (*AggregateRootRepository) Save

Save applies the given command to a new aggregate and persists it into the store

func (*AggregateRootRepository) Update

func (r *AggregateRootRepository) Update(ctx context.Context, aggregateID string, command core.Command, options ...AggregateRootOption) (*AggregateRoot, error)

Update locates an existing aggregate, applies the commands and persists the result into the store

type AggregateRootStore

type AggregateRootStore interface {
	Load(ctx context.Context, aggregate *AggregateRoot) error
	Save(ctx context.Context, aggregate *AggregateRoot) error
}

AggregateRootStore is the interface that infrastructures should implement to be used in AggregateRootRepositories

type AggregateRootStoreMiddleware

type AggregateRootStoreMiddleware func(store AggregateRootStore) AggregateRootStore

AggregateRootStoreMiddleware interface for embedding stores

type SnapshotStrategy

type SnapshotStrategy interface {
	ShouldSnapshot(aggregate *AggregateRoot) bool
}

SnapshotStrategy interface

func NewMaxChangesSnapshotStrategy

func NewMaxChangesSnapshotStrategy(maxChanges int) SnapshotStrategy

NewMaxChangesSnapshotStrategy constructs a new SnapshotStrategy with "max changes" rules

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL