eventstore

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventData added in v0.119.0

func EventData(event EventPusher) ([]byte, error)

func MapEventsToV1Events added in v0.119.0

func MapEventsToV1Events(events []EventReader) []*models.Event

func WithResourceOwner added in v0.119.0

func WithResourceOwner(resourceOwner string) aggregateOpt

WithResourceOwner overwrites the resource owner of the aggregate by default the resource owner is set by the context

Types

type Aggregate added in v0.119.0

type Aggregate struct {
	//ID is the unique identitfier of this aggregate
	ID string `json:"-"`
	//Type is the name of the aggregate.
	Type AggregateType `json:"-"`
	//ResourceOwner is the org this aggregates belongs to
	ResourceOwner string `json:"-"`
	//Version is the semver this aggregate represents
	Version Version `json:"-"`
}

Aggregate is the basic implementation of Aggregater

func AggregateFromWriteModel added in v0.119.0

func AggregateFromWriteModel(
	wm *WriteModel,
	typ AggregateType,
	version Version,
) *Aggregate

AggregateFromWriteModel maps the given WriteModel to an Aggregate

func NewAggregate added in v0.119.0

func NewAggregate(
	ctx context.Context,
	id string,
	typ AggregateType,
	version Version,
	opts ...aggregateOpt,
) *Aggregate

NewAggregate is the default constructor of an aggregate opts overwrite values calculated by given parameters

type AggregateType added in v0.119.0

type AggregateType repository.AggregateType

AggregateType is the object name

type Asset added in v1.1.0

type Asset struct {
	// ID is to refer to the asset
	ID string
	//Asset is the actual image
	Asset []byte
	//Action defines if asset should be added or removed
	Action AssetAction
}

func NewAddAsset added in v1.1.0

func NewAddAsset(
	id string,
	asset []byte) *Asset

func NewRemoveAsset added in v1.1.0

func NewRemoveAsset(
	id string) *Asset

type AssetAction added in v1.1.0

type AssetAction int32
const (
	AssetAdd AssetAction = iota
	AssetRemove
)

type BaseEvent added in v0.119.0

type BaseEvent struct {
	EventType EventType `json:"-"`

	//User who created the event
	User string `json:"-"`
	//Service which created the event
	Service string `json:"-"`
	Data    []byte `json:"-"`
	// contains filtered or unexported fields
}

BaseEvent represents the minimum metadata of an event

func BaseEventFromRepo added in v0.119.0

func BaseEventFromRepo(event *repository.Event) *BaseEvent

BaseEventFromRepo maps a stored event to a BaseEvent

func NewBaseEventForPush added in v0.119.0

func NewBaseEventForPush(ctx context.Context, aggregate *Aggregate, typ EventType) *BaseEvent

NewBaseEventForPush is the constructor for event's which will be pushed into the eventstore the resource owner of the aggregate is only used if it's the first event of this aggregate type afterwards the resource owner of the first previous events is taken

func (*BaseEvent) Aggregate added in v0.119.0

func (e *BaseEvent) Aggregate() Aggregate

Aggregate represents the metadata of the event's aggregate

func (*BaseEvent) CreationDate added in v0.119.0

func (e *BaseEvent) CreationDate() time.Time

CreationDate is the the time, the event is inserted into the eventstore

func (*BaseEvent) DataAsBytes added in v0.119.0

func (e *BaseEvent) DataAsBytes() []byte

Data returns the payload of the event. It represent the changed fields by the event

func (*BaseEvent) EditorService added in v0.119.0

func (e *BaseEvent) EditorService() string

EditorService implements EventPusher

func (*BaseEvent) EditorUser added in v0.119.0

func (e *BaseEvent) EditorUser() string

EditorUser implements EventPusher

func (*BaseEvent) PreviousAggregateSequence added in v1.31.0

func (e *BaseEvent) PreviousAggregateSequence() uint64

PreviousAggregateSequence implements EventReader

func (*BaseEvent) PreviousAggregateTypeSequence added in v1.31.0

func (e *BaseEvent) PreviousAggregateTypeSequence() uint64

PreviousAggregateTypeSequence implements EventReader

func (*BaseEvent) Sequence added in v0.119.0

func (e *BaseEvent) Sequence() uint64

Sequence is an upcounting unique number of the event

func (*BaseEvent) Type added in v0.119.0

func (e *BaseEvent) Type() EventType

Type implements EventPusher

type Columns added in v0.119.0

type Columns repository.Columns

Columns defines which fields of the event are needed for the query

const (
	//ColumnsEvent represents all fields of an event
	ColumnsEvent Columns = repository.ColumnsEvent
	// ColumnsMaxSequence represents the latest sequence of the filtered events
	ColumnsMaxSequence Columns = repository.ColumnsMaxSequence
)

type EventPusher added in v0.119.0

type EventPusher interface {
	//Aggregate is the metadata of an aggregate
	Aggregate() Aggregate
	// EditorService is the service who wants to push the event
	EditorService() string
	//EditorUser is the user who wants to push the event
	EditorUser() string
	//KeyType must return an event type which should be unique in the aggregate
	Type() EventType
	//Data returns the payload of the event. It represent the changed fields by the event
	// valid types are:
	// * nil (no payload),
	// * json byte array
	// * struct which can be marshalled to json
	// * pointer to struct which can be marshalled to json
	Data() interface{}
	//UniqueConstraints should be added for unique attributes of an event, if nil constraints will not be checked
	UniqueConstraints() []*EventUniqueConstraint
}

type EventReader added in v0.119.0

type EventReader interface {
	// EditorService is the service who pushed the event
	EditorService() string
	//EditorUser is the user who pushed the event
	EditorUser() string
	//KeyType is the type of the event
	Type() EventType

	Aggregate() Aggregate

	Sequence() uint64
	CreationDate() time.Time
	//PreviousAggregateSequence returns the previous sequence of the aggregate root (e.g. for org.42508134)
	PreviousAggregateSequence() uint64
	//PreviousAggregateTypeSequence returns the previous sequence of the aggregate type (e.g. for org)
	PreviousAggregateTypeSequence() uint64
	//DataAsBytes returns the payload of the event. It represent the changed fields by the event
	DataAsBytes() []byte
}

type EventType added in v0.119.0

type EventType repository.EventType

EventType is the description of the change

type EventUniqueConstraint added in v0.119.0

type EventUniqueConstraint struct {
	// UniqueType is the table name for the unique constraint
	UniqueType string
	//UniqueField is the unique key
	UniqueField string
	//Action defines if unique constraint should be added or removed
	Action UniqueConstraintAction
	//ErrorMessage defines the translation file key for the error message
	ErrorMessage string
}

func NewAddEventUniqueConstraint added in v0.119.0

func NewAddEventUniqueConstraint(
	uniqueType,
	uniqueField,
	errMessage string) *EventUniqueConstraint

func NewRemoveEventUniqueConstraint added in v0.119.0

func NewRemoveEventUniqueConstraint(
	uniqueType,
	uniqueField string) *EventUniqueConstraint

type Eventstore

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

Eventstore abstracts all functions needed to store valid events and filters the stored events

func NewEventstore added in v0.119.0

func NewEventstore(repo repository.Repository) *Eventstore

func Start

func Start(sqlConfig types.SQL) (*Eventstore, error)

func StartWithUser added in v0.119.0

func StartWithUser(baseConfig types.SQLBase, userConfig types.SQLUser) (*Eventstore, error)

func (*Eventstore) FilterEvents

func (es *Eventstore) FilterEvents(ctx context.Context, queryFactory *SearchQueryBuilder) ([]EventReader, error)

FilterEvents filters the stored events based on the searchQuery and maps the events to the defined event structs

func (*Eventstore) FilterToQueryReducer added in v0.119.0

func (es *Eventstore) FilterToQueryReducer(ctx context.Context, r queryReducer) error

FilterToQueryReducer filters the events based on the search query of the query function, appends all events to the reducer and calls it's reduce function

func (*Eventstore) FilterToReducer added in v0.119.0

func (es *Eventstore) FilterToReducer(ctx context.Context, searchQuery *SearchQueryBuilder, r reducer) error

FilterToReducer filters the events based on the search query, appends all events to the reducer and calls it's reduce function

func (*Eventstore) Health

func (es *Eventstore) Health(ctx context.Context) error

Health checks if the eventstore can properly work It checks if the repository can serve load

func (*Eventstore) LatestSequence added in v0.64.4

func (es *Eventstore) LatestSequence(ctx context.Context, queryFactory *SearchQueryBuilder) (uint64, error)

LatestSequence filters the latest sequence for the given search query

func (*Eventstore) PushEvents added in v0.119.0

func (es *Eventstore) PushEvents(ctx context.Context, pushEvents ...EventPusher) ([]EventReader, error)

PushEvents pushes the events in a single transaction an event needs at least an aggregate

func (*Eventstore) RegisterFilterEventMapper added in v0.119.0

func (es *Eventstore) RegisterFilterEventMapper(eventType EventType, mapper func(*repository.Event) (EventReader, error)) *Eventstore

RegisterFilterEventMapper registers a function for mapping an eventstore event to an event

func (*Eventstore) Step20 added in v1.34.2

func (es *Eventstore) Step20(ctx context.Context, latestSequence uint64) error

type ReadModel added in v0.119.0

type ReadModel struct {
	AggregateID       string        `json:"-"`
	ProcessedSequence uint64        `json:"-"`
	CreationDate      time.Time     `json:"-"`
	ChangeDate        time.Time     `json:"-"`
	Events            []EventReader `json:"-"`
	ResourceOwner     string        `json:"-"`
}

ReadModel is the minimum representation of a read model. It implements a basic reducer it might be saved in a database or in memory

func (*ReadModel) AppendEvents added in v0.119.0

func (rm *ReadModel) AppendEvents(events ...EventReader) *ReadModel

AppendEvents adds all the events to the read model. The function doesn't compute the new state of the read model

func (*ReadModel) Reduce added in v0.119.0

func (rm *ReadModel) Reduce() error

Reduce is the basic implementation of reducer If this function is extended the extending function should be the last step

type SearchQuery added in v1.19.4

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

func (*SearchQuery) AggregateIDs added in v1.19.4

func (query *SearchQuery) AggregateIDs(ids ...string) *SearchQuery

AggregateIDs filters for events with the given aggregate id's

func (*SearchQuery) AggregateTypes added in v1.19.4

func (query *SearchQuery) AggregateTypes(types ...AggregateType) *SearchQuery

AggregateTypes filters for events with the given aggregate types

func (*SearchQuery) Builder added in v1.19.4

func (query *SearchQuery) Builder() *SearchQueryBuilder

Builder returns the SearchQueryBuilder of the sub query

func (*SearchQuery) EventData added in v1.19.4

func (query *SearchQuery) EventData(data map[string]interface{}) *SearchQuery

EventData filters for events with the given event data. Use this call with care as it will be slower than the other filters.

func (*SearchQuery) EventTypes added in v1.19.4

func (query *SearchQuery) EventTypes(types ...EventType) *SearchQuery

EventTypes filters for events with the given event types

func (SearchQuery) Or added in v1.19.4

func (query SearchQuery) Or() *SearchQuery

Or creates a new sub query on the search query builder

func (*SearchQuery) SequenceGreater added in v1.19.4

func (query *SearchQuery) SequenceGreater(sequence uint64) *SearchQuery

SequenceGreater filters for events with sequence greater the requested sequence

func (*SearchQuery) SequenceLess added in v1.31.0

func (query *SearchQuery) SequenceLess(sequence uint64) *SearchQuery

SequenceLess filters for events with sequence less the requested sequence

type SearchQueryBuilder added in v0.119.0

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

SearchQueryBuilder represents the builder for your filter if invalid data are set the filter will fail

func NewSearchQueryBuilder added in v0.119.0

func NewSearchQueryBuilder(columns Columns) *SearchQueryBuilder

NewSearchQueryBuilder creates a new builder for event filters aggregateTypes must contain at least one aggregate type

func (*SearchQueryBuilder) AddQuery added in v1.19.4

func (factory *SearchQueryBuilder) AddQuery() *SearchQuery

AddQuery creates a new sub query. All fields in the sub query are AND-connected in the storage request. Multiple sub queries are OR-connected in the storage request.

func (*SearchQueryBuilder) Columns added in v0.119.0

func (factory *SearchQueryBuilder) Columns(columns Columns) *SearchQueryBuilder

Columns defines which fields are set

func (*SearchQueryBuilder) Limit added in v0.119.0

func (factory *SearchQueryBuilder) Limit(limit uint64) *SearchQueryBuilder

Limit defines how many events are returned maximally.

func (*SearchQueryBuilder) OrderAsc added in v0.119.0

func (factory *SearchQueryBuilder) OrderAsc() *SearchQueryBuilder

OrderAsc changes the sorting order of the returned events to ascending

func (*SearchQueryBuilder) OrderDesc added in v0.119.0

func (factory *SearchQueryBuilder) OrderDesc() *SearchQueryBuilder

OrderDesc changes the sorting order of the returned events to descending

func (*SearchQueryBuilder) ResourceOwner added in v0.119.0

func (factory *SearchQueryBuilder) ResourceOwner(resourceOwner string) *SearchQueryBuilder

ResourceOwner defines the resource owner (org) of the events

type Subscription added in v0.109.13

type Subscription struct {
	Events chan EventReader
	// contains filtered or unexported fields
}

func SubscribeAggregates added in v1.31.0

func SubscribeAggregates(eventQueue chan EventReader, aggregates ...AggregateType) *Subscription

SubscribeAggregates subscribes for all events on the given aggregates

func SubscribeEventTypes added in v1.31.0

func SubscribeEventTypes(eventQueue chan EventReader, types map[AggregateType][]EventType) *Subscription

SubscribeEventTypes subscribes for the given event types if no event types are provided the subscription is for all events of the aggregate

func (*Subscription) Unsubscribe added in v0.109.13

func (s *Subscription) Unsubscribe()

type UniqueConstraintAction added in v0.119.0

type UniqueConstraintAction int32
const (
	UniqueConstraintAdd UniqueConstraintAction = iota
	UniqueConstraintRemove
)

type Version added in v0.119.0

type Version repository.Version

type WriteModel added in v0.119.0

type WriteModel struct {
	AggregateID       string        `json:"-"`
	ProcessedSequence uint64        `json:"-"`
	Events            []EventReader `json:"-"`
	ResourceOwner     string        `json:"-"`
	ChangeDate        time.Time     `json:"-"`
}

WriteModel is the minimum representation of a command side write model. It implements a basic reducer it's purpose is to reduce events to create new ones

func (*WriteModel) AppendEvents added in v0.119.0

func (rm *WriteModel) AppendEvents(events ...EventReader)

AppendEvents adds all the events to the read model. The function doesn't compute the new state of the read model

func (*WriteModel) Reduce added in v0.119.0

func (wm *WriteModel) Reduce() error

Reduce is the basic implementaion of reducer If this function is extended the extending function should be the last step

Directories

Path Synopsis
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
sql
v1
internal/repository/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
sdk
spooler/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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