Documentation ¶
Index ¶
- Variables
- func AssertAndGet[H Aggregate, W Aggregate](have H, want W) (W, error)
- func ErrIsSnapshotNotFound(err error) bool
- func FromSnapshot(snapshot *Snapshot, a Aggregate)
- func MarshalES(object any) ([]byte, error)
- func On(ctx context.Context, a Aggregate, event Event, new bool)
- func Raise(ctx context.Context, aggregate Aggregate, changes ...Event)
- func Sort(ee []Event)
- func UnmarshalES(b []byte, object any) error
- type Aggregate
- type AggregateID
- type AggregateType
- type AggregateVersion
- type BaseAggregate
- func (a *BaseAggregate) Changes() []Event
- func (a *BaseAggregate) ID() AggregateID
- func (a *BaseAggregate) IncrementVersion()
- func (a *BaseAggregate) PrepareForLoading()
- func (a *BaseAggregate) SetVersion(version AggregateVersion)
- func (a *BaseAggregate) SnapshotsWithFrequency(frequency int) []*Snapshot
- func (a *BaseAggregate) StackChange(change Event)
- func (a *BaseAggregate) StackSnapshot(snapshot *Snapshot)
- func (a *BaseAggregate) StackedSnapshots() []*Snapshot
- func (a *BaseAggregate) Type() AggregateType
- func (a *BaseAggregate) Version() AggregateVersion
- type BaseEvent
- func (e *BaseEvent) AggregateID() AggregateID
- func (e *BaseEvent) AggregateType() AggregateType
- func (e *BaseEvent) AggregateVersion() AggregateVersion
- func (e *BaseEvent) ID() EventID
- func (e *BaseEvent) Metadata() Metadata
- func (e *BaseEvent) OccurredAt() time.Time
- func (e *BaseEvent) SetVersion(version AggregateVersion)
- func (e *BaseEvent) String() string
- type Event
- type EventID
- type EventReadModel
- type EventStore
- type EventType
- type Marshaler
- type Metadata
- type SaveOption
- type SaveOptions
- type Snapshot
- type Transaction
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoEventsToStore = errors.New("no events to store") ErrNoSnapshotFound = errors.New("no snapshot found") ErrTransactionIsRequired = errors.New("transaction is required") ErrAggregateDoNotExist = errors.New("aggregate do not exist") )
View Source
var (
ErrAssertionFailed = errors.New("assertion failed")
)
Functions ¶
func AssertAndGet ¶ added in v0.3.0
func ErrIsSnapshotNotFound ¶
func FromSnapshot ¶ added in v0.3.0
func UnmarshalES ¶ added in v0.3.0
Types ¶
type Aggregate ¶ added in v0.3.0
type Aggregate interface { ID() AggregateID Type() AggregateType Version() AggregateVersion Changes() []Event StackChange(change Event) StackSnapshot(snapshot *Snapshot) StackedSnapshots() []*Snapshot SnapshotsWithFrequency(frequency int) []*Snapshot SetVersion(version AggregateVersion) IncrementVersion() PrepareForLoading() ParseEvents(context.Context, ...EventReadModel) []Event }
type AggregateID ¶
type AggregateID string
func (AggregateID) IsZero ¶
func (id AggregateID) IsZero() bool
func (AggregateID) String ¶
func (id AggregateID) String() string
type AggregateType ¶
type AggregateType string
func (AggregateType) IsZero ¶
func (t AggregateType) IsZero() bool
func (AggregateType) String ¶
func (t AggregateType) String() string
type AggregateVersion ¶
type AggregateVersion int
func (AggregateVersion) Int ¶ added in v0.3.0
func (v AggregateVersion) Int() int
func (AggregateVersion) Int64 ¶
func (v AggregateVersion) Int64() int64
func (AggregateVersion) IsZero ¶
func (v AggregateVersion) IsZero() bool
func (AggregateVersion) Next ¶ added in v0.3.0
func (v AggregateVersion) Next() AggregateVersion
type BaseAggregate ¶
type BaseAggregate struct {
// contains filtered or unexported fields
}
func InitAggregate ¶ added in v0.3.0
func InitAggregate(id string, t AggregateType) *BaseAggregate
func (*BaseAggregate) Changes ¶
func (a *BaseAggregate) Changes() []Event
func (*BaseAggregate) ID ¶
func (a *BaseAggregate) ID() AggregateID
func (*BaseAggregate) IncrementVersion ¶
func (a *BaseAggregate) IncrementVersion()
func (*BaseAggregate) PrepareForLoading ¶ added in v0.4.0
func (a *BaseAggregate) PrepareForLoading()
func (*BaseAggregate) SetVersion ¶
func (a *BaseAggregate) SetVersion(version AggregateVersion)
func (*BaseAggregate) SnapshotsWithFrequency ¶
func (a *BaseAggregate) SnapshotsWithFrequency(frequency int) []*Snapshot
func (*BaseAggregate) StackChange ¶
func (a *BaseAggregate) StackChange(change Event)
func (*BaseAggregate) StackSnapshot ¶
func (a *BaseAggregate) StackSnapshot(snapshot *Snapshot)
func (*BaseAggregate) StackedSnapshots ¶
func (a *BaseAggregate) StackedSnapshots() []*Snapshot
func (*BaseAggregate) Type ¶ added in v0.3.0
func (a *BaseAggregate) Type() AggregateType
func (*BaseAggregate) Version ¶
func (a *BaseAggregate) Version() AggregateVersion
type BaseEvent ¶
type BaseEvent struct {
// contains filtered or unexported fields
}
func NewBaseEvent ¶ added in v0.3.0
func (*BaseEvent) AggregateID ¶
func (e *BaseEvent) AggregateID() AggregateID
func (*BaseEvent) AggregateType ¶
func (e *BaseEvent) AggregateType() AggregateType
func (*BaseEvent) AggregateVersion ¶
func (e *BaseEvent) AggregateVersion() AggregateVersion
func (*BaseEvent) OccurredAt ¶
func (*BaseEvent) SetVersion ¶
func (e *BaseEvent) SetVersion(version AggregateVersion)
type Event ¶
type Event interface { fmt.Stringer ApplyTo(ctx context.Context, aggregate Aggregate) // ApplyTo applies the event to the aggregate ID() EventID // ID returns the id of the event. Type() EventType // Type returns the type of the event. OccurredAt() time.Time // OccurredAt of when the event was created. AggregateID() AggregateID // AggregateID is the id of the aggregate that the event belongs to. AggregateType() AggregateType // AggregateType is the type of the aggregate that the event can be applied to. AggregateVersion() AggregateVersion // AggregateVersion is the version of the aggregate after the event has been applied. SetVersion(AggregateVersion) // SetVersion sets the aggregate version of the event Metadata() Metadata // Metadata is app-specific metadata such as request AggregateID, originating user etc. }
type EventReadModel ¶
type EventReadModel struct { ID EventID `json:"id"` Type EventType `json:"type"` OccurredAt time.Time `json:"occurred_at"` AggregateID AggregateID `json:"aggregate_id"` AggregateType AggregateType `json:"aggregate_type"` AggregateVersion AggregateVersion `json:"aggregate_version"` Metadata map[string]interface{} `json:"metadata"` Data json.RawMessage `json:"data"` }
func (*EventReadModel) InitBaseEvent ¶
func (r *EventReadModel) InitBaseEvent() *BaseEvent
type EventStore ¶
type EventStore interface { Save(ctx context.Context, tx Transaction, a Aggregate, opts ...SaveOption) error Load(ctx context.Context, tx Transaction, a Aggregate) (Aggregate, error) EventsHistory(ctx context.Context, tx Transaction, aggregateID, aggregateType string, fromVersion int, limit int) ([]EventReadModel, error) }
type Metadata ¶
type Metadata map[string]interface{}
func NewMetadata ¶ added in v0.3.0
func NewMetadata() Metadata
type SaveOption ¶ added in v0.3.0
type SaveOption func(*SaveOptions)
func WithSnapshot ¶ added in v0.3.0
func WithSnapshot(frequency int) SaveOption
type SaveOptions ¶
func NewSaveOptions ¶ added in v0.3.0
func NewSaveOptions(opts ...SaveOption) *SaveOptions
type Snapshot ¶
type Snapshot struct { AggregateID AggregateID AggregateType AggregateType AggregateVersion AggregateVersion TakenAt time.Time Data []byte }
func NewSnapshot ¶ added in v0.3.0
type Transaction ¶
type Unmarshaler ¶ added in v0.8.0
Source Files ¶
Click to show internal directories.
Click to hide internal directories.