event

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: BSD-3-Clause Imports: 17 Imported by: 6

Documentation

Overview

package event implements functionality for working with an eventstore.

Index

Constants

This section is empty.

Variables

View Source
var ErrShouldExist = errors.New("should exist")
View Source
var ErrShouldNotExist = errors.New("should not exist")
View Source
var NilEvent = &nilEvent{}

Functions

func Append

func Append(a Aggregate, lis ...Event)

Append adds new committed events

func EncodeEvents

func EncodeEvents(events ...Event) (lis [][]byte, err error)

func EventID

func EventID(e Event) ulid.ULID

func Init

func Init(ctx context.Context) error

func MarshalBinary

func MarshalBinary(e Event) ([]byte, error)

func NotExists

func NotExists(a Aggregate) error

NotExists returns error if there are no events present.

func Raise

func Raise(a Aggregate, lis ...Event)

Raise adds new uncommitted events

func Register

func Register(ctx context.Context, lis ...Event) error

Register a type container for Unmarshalling values into. The type must implement Event and not be a nil value.

func RegisterName

func RegisterName(ctx context.Context, name string, e Event) error

func SetEventID

func SetEventID(e Event, id ulid.ULID)

func SetPosition

func SetPosition(e Event, i uint64)

func SetStreamID

func SetStreamID(id string, lis ...Event)

func ShouldExist

func ShouldExist(a Aggregate) error

ShouldExists returns error if there are no events present.

func Start

func Start(a Aggregate, i uint64)

func StreamID

func StreamID(e Event) streamID

func TypeOf

func TypeOf(e any) string

func Values

func Values(e Event) map[string]any

Types

type AGG

type AGG interface{ ApplyEvent(...Event) }

type Aggregate

type Aggregate interface {
	// ApplyEvent  applies the event to the aggrigate state
	ApplyEvent(...Event)

	AggregateRoot
}

Aggregate implements functionality for working with event store streams as an aggregate. When creating a new Aggregate the struct should have an ApplyEvent method and embed the AggregateRoot.

func AsAggregate

func AsAggregate[T AGG](e T) Aggregate

type AggregateRoot

type AggregateRoot interface {
	// Events returns the aggregate events
	// pass true for only uncommitted events
	Events(bool) Events
	// StreamID returns aggregate stream ID
	StreamID() string
	// SetStreamID sets aggregate stream ID
	SetStreamID(streamID string)
	// StreamVersion returns last commit events
	StreamVersion() uint64
	// Version returns the current aggrigate version. (committed + uncommitted)
	Version() uint64

	Commit()
	// contains filtered or unexported methods
}

type Event

type Event interface {
	EventMeta() Meta
	SetEventMeta(Meta)
}

Event implements functionality of an individual event used with the event store. It should implement the getter/setter for EventMeta and BinaryMarshaler/BinaryUnmarshaler.

func AsEvent

func AsEvent[T any](e T) Event

func GetContainer

func GetContainer(ctx context.Context, s string) Event

func UnmarshalBinary

func UnmarshalBinary(ctx context.Context, txt []byte, pos uint64) (e Event, err error)

type EventPtr

type EventPtr struct {
	StreamID string `json:"stream_id"`
	Pos      uint64 `json:"pos"`

	IsEvent
}

func NewPtr

func NewPtr(streamID string, pos uint64) *EventPtr

func (*EventPtr) MarshalBinary

func (e *EventPtr) MarshalBinary() (data []byte, err error)

MarshalBinary implements Event

func (*EventPtr) UnmarshalBinary

func (e *EventPtr) UnmarshalBinary(data []byte) error

UnmarshalBinary implements Event

func (*EventPtr) Values

func (e *EventPtr) Values() any

type Events

type Events []Event

Events is a list of events

func DecodeEvents

func DecodeEvents(ctx context.Context, lis ...[]byte) (Events, error)

DecodeEvents unmarshals the byte list into Events.

func NewEvents

func NewEvents(lis ...Event) Events

func (Events) Count

func (lis Events) Count() int64

func (Events) First

func (lis Events) First() Event

func (Events) Last

func (lis Events) Last() Event

func (Events) Rest

func (lis Events) Rest() Events

func (Events) SetStreamID

func (lis Events) SetStreamID(streamID string)

func (Events) StreamID

func (lis Events) StreamID() string

type FeedTruncated

type FeedTruncated struct {
	IsEvent
}

func (*FeedTruncated) Values

func (e *FeedTruncated) Values() any

type IsAggregate

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

func (*IsAggregate) Commit

func (a *IsAggregate) Commit()

func (*IsAggregate) Events

func (a *IsAggregate) Events(new bool) Events

func (*IsAggregate) SetStreamID

func (a *IsAggregate) SetStreamID(streamID string)

func (*IsAggregate) StreamID

func (a *IsAggregate) StreamID() string

func (*IsAggregate) StreamVersion

func (a *IsAggregate) StreamVersion() uint64

func (*IsAggregate) Version

func (a *IsAggregate) Version() uint64

type IsEvent

type IsEvent = property[Meta]

type Meta

type Meta struct {
	EventID        ulid.ULID
	StreamID       string
	Position       uint64
	ActualStreamID string
	ActualPosition uint64
}

func (Meta) Created

func (m Meta) Created() time.Time

func (Meta) GetEventID

func (m Meta) GetEventID() string

type UnknownEvent

type UnknownEvent struct {
	IsEvent
	// contains filtered or unexported fields
}

func NewUnknownEventFromRaw

func NewUnknownEventFromRaw(eventType string, meta Meta, values map[string]json.RawMessage) *UnknownEvent

func NewUnknownEventFromValues

func NewUnknownEventFromValues(eventType string, meta Meta, values url.Values) *UnknownEvent

func (UnknownEvent) EventType

func (u UnknownEvent) EventType() string

func (*UnknownEvent) MarshalBinary

func (u *UnknownEvent) MarshalBinary() ([]byte, error)

func (*UnknownEvent) UnmarshalBinary

func (u *UnknownEvent) UnmarshalBinary(b []byte) error

Jump to

Keyboard shortcuts

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