projector

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 6 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrModelNotSet = errors.New("model not set")

ErrModelNotSet is when a model factory is not set on the EventHandler.

Functions

This section is empty.

Types

type Error

type Error struct {
	// Err is the error that happened when projecting the event.
	Err error
	// Projector is the projector where the error happened.
	Projector string
	// EventVersion is the version of the event.
	EventVersion int
	// EntityVersion is the version of the entity.
	EntityVersion int
}

Error is an error in the projector.

func (Error) Cause added in v0.9.0

func (e Error) Cause() error

Cause implements the github.com/pkg/errors Unwrap method.

func (Error) Error

func (e Error) Error() string

Error implements the Error method of the errors.Error interface.

func (Error) Unwrap added in v0.9.0

func (e Error) Unwrap() error

Unwrap implements the errors.Unwrap method.

type EventHandler

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

EventHandler is a CQRS projection handler to run a Projector implementation.

func NewEventHandler

func NewEventHandler(projector Projector, repo eh.ReadWriteRepo, options ...Option) *EventHandler

NewEventHandler creates a new EventHandler.

func (*EventHandler) HandleEvent

func (h *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error

HandleEvent implements the HandleEvent method of the eventhorizon.EventHandler interface. It will try to find the correct version of the model, waiting for it the projector has the WithWait option set.

func (*EventHandler) HandlerType added in v0.4.0

func (h *EventHandler) HandlerType() eh.EventHandlerType

HandlerType implements the HandlerType method of the eventhorizon.EventHandler interface.

func (*EventHandler) SetEntityFactory

func (h *EventHandler) SetEntityFactory(f func() eh.Entity)

SetEntityFactory sets a factory function that creates concrete entity types.

type Option added in v0.8.0

type Option func(*EventHandler)

Option is an option setter used to configure creation.

func WithEntityLookup added in v0.14.3

func WithEntityLookup(f func(eh.Event) uuid.UUID) Option

WithEntityLookup can be used to provide an alternative ID (from the aggregate ID) for fetching the projected entity. The lookup func can for example extract another field from the event or use a static ID for some singleton-like projections.

func WithIrregularVersioning added in v0.14.2

func WithIrregularVersioning() Option

WithIrregularVersioning sets the option to allow gaps in the version numbers. This can be useful for projectors that project only some events of a larger aggregate, which will lead to gaps in the versions.

func WithWait added in v0.8.0

func WithWait() Option

WithWait adds waiting for the correct version when projecting.

type Projector

type Projector interface {
	// ProjectorType returns the type of the projector.
	ProjectorType() Type

	// Project projects an event onto a model and returns the updated model or
	// an error.
	Project(context.Context, eh.Event, eh.Entity) (eh.Entity, error)
}

Projector is a projector of events onto models.

type Type

type Type string

Type is the type of a projector, used as its unique identifier.

func (Type) String added in v0.9.0

func (t Type) String() string

String returns the string representation of a projector type.

Jump to

Keyboard shortcuts

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