eventsourcing

package
v0.0.0-...-3014034 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate interface {
	// Appply updates aggregate based on event.
	Apply(event Event) error

	// Changes returns a list of uncommitted events.
	GetChanges() []Event

	// AppendChanges add a event to a uncommitted event list.
	AppendChanges(event Event)

	// SetAggregateID assigns identifier to aggregate.
	SetAggregateID(uuid.UUID)

	// GetAggregateID returns unique identifier of aggregate.
	GetAggregateID() uuid.UUID

	// GetVersion return current version of the aggregate.
	GetVersion() int

	// SetVersion sets current version of the aggregate.
	SetVersion(int)

	// EventTable return the table name.
	EventTable() string

	StateMachine
}

type AggregateLoader

type AggregateLoader interface {
	Load(ctx context.Context, id uuid.UUID) (Aggregate, error)
}

type AggregateRepository

type AggregateRepository interface {
	Load(ctx context.Context, id uint64) (Aggregate, error)
	Save(ctx context.Context, aggregate Aggregate) error
}

type AggregateSaver

type AggregateSaver interface {
	Save(ctx context.Context, aggregate Aggregate) error
}

type BaseAggregate

type BaseAggregate struct {
	Version int
	ID      uuid.UUID
	// contains filtered or unexported fields
}

BaseAggregate implements common functionality for Aggregate interface.

It doesn't implement Apply, EventTable.

func (*BaseAggregate) AppendChanges

func (ba *BaseAggregate) AppendChanges(event Event)

func (*BaseAggregate) Apply

func (*BaseAggregate) Apply(_ Event) error

func (*BaseAggregate) EventTable

func (*BaseAggregate) EventTable() string

func (*BaseAggregate) GetAggregateID

func (ba *BaseAggregate) GetAggregateID() uuid.UUID

func (*BaseAggregate) GetChanges

func (ba *BaseAggregate) GetChanges() []Event

func (*BaseAggregate) GetCurrentState

func (ba *BaseAggregate) GetCurrentState() State

func (*BaseAggregate) GetTransitions

func (ba *BaseAggregate) GetTransitions() []Transition

func (*BaseAggregate) GetVersion

func (ba *BaseAggregate) GetVersion() int

func (*BaseAggregate) SetAggregateID

func (ba *BaseAggregate) SetAggregateID(id uuid.UUID)

func (*BaseAggregate) SetVersion

func (ba *BaseAggregate) SetVersion(version int)

func (*BaseAggregate) SkipTransition

func (ba *BaseAggregate) SkipTransition(Event) bool

type BaseEvent

type BaseEvent struct {
	CreatedAt   time.Time
	Version     int
	ID          uuid.UUID
	AggregateID uuid.UUID
	ParentID    uuid.UUID
}

BaseEvent implements common functionality for Event interface.

It doesn't implement EventType method.

func (*BaseEvent) EventType

func (*BaseEvent) EventType() EventType

func (*BaseEvent) GetAggregateID

func (be *BaseEvent) GetAggregateID() uuid.UUID

func (*BaseEvent) GetCreatedAt

func (be *BaseEvent) GetCreatedAt() time.Time

func (*BaseEvent) GetParentID

func (be *BaseEvent) GetParentID() uuid.UUID

func (*BaseEvent) GetVersion

func (be *BaseEvent) GetVersion() int

func (*BaseEvent) SetAggregateID

func (be *BaseEvent) SetAggregateID(id uuid.UUID)

func (*BaseEvent) SetCreatedAt

func (be *BaseEvent) SetCreatedAt(createdAt time.Time)

func (*BaseEvent) SetParentID

func (be *BaseEvent) SetParentID(parentID uuid.UUID)

func (*BaseEvent) SetVersion

func (be *BaseEvent) SetVersion(version int)

func (*BaseEvent) Validate

func (be *BaseEvent) Validate() error

type Event

type Event interface {
	// EventType returns the name of event.
	EventType() EventType

	// GetAggregateID returns event's aggregate id.
	GetAggregateID() uuid.UUID

	// SetAggregateID changes event's aggregate id.
	SetAggregateID(uuid.UUID)

	// GetParentID returns event's parent id
	GetParentID() uuid.UUID

	// SetParentID changes event's parent id
	SetParentID(uuid.UUID)

	// GetVersion returns event's version
	GetVersion() int

	// SetVersion changes event's version
	SetVersion(int)

	// GetCreatedAt returns event's create time
	GetCreatedAt() time.Time

	// SetCreatedAt changes event's create time
	SetCreatedAt(time.Time)

	// Validate checks if event is valid
	Validate() error
}

type EventNotRegisteredError

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

func (*EventNotRegisteredError) Error

func (enre *EventNotRegisteredError) Error() string

type EventRegistry

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

func NewEventRegistry

func NewEventRegistry() *EventRegistry

func NewEventRegistryFromStateMachine

func NewEventRegistryFromStateMachine(stateMachine StateMachine) *EventRegistry

func (*EventRegistry) Get

func (er *EventRegistry) Get(eventType EventType) (reflect.Type, error)

func (*EventRegistry) GetInstance

func (er *EventRegistry) GetInstance(eventType EventType) (Event, error)

func (*EventRegistry) Register

func (er *EventRegistry) Register(event Event)

type EventStore

type EventStore[T Aggregate] interface {
	Load(ctx context.Context, aggregateID uint64, startVersion int) ([]Event, error)
	Append(ctx context.Context, events []Event) error
}

type EventType

type EventType string

type InvalidEventError

type InvalidEventError struct {
	Err  error
	Type EventType
}

func (*InvalidEventError) Error

func (e *InvalidEventError) Error() string

func (*InvalidEventError) Unwrap

func (e *InvalidEventError) Unwrap() error

type NoTransitionError

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

func (*NoTransitionError) Error

func (nte *NoTransitionError) Error() string

type Projector

type Projector interface {
	Handle(ctx context.Context, event Event) error
}

type State

type State string

func TransistOnEvent

func TransistOnEvent(stateMachine StateMachine, event Event) (State, error)

TransistOnEvent returns the new state given current state and event.

type StateMachine

type StateMachine interface {
	// GetStates returns current state of a aggregate.
	GetCurrentState() State

	// GetTransitions return all possible state transition for a aggregate
	GetTransitions() []Transition

	// SkipTransition returns true if the transition should be skipped.
	SkipTransition(event Event) bool
}

type Transition

type Transition struct {
	Event     Event
	FromState State
	ToState   State
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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