eventsourcing

package
v0.44.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package eventsourcing is a generic, domain-agnostic decider host over store.EventStore: Load (snapshot + replay-tail via Evolve) and Append (encode + optimistic append + snapshot), parameterized per aggregate by a Decider value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decider

type Decider[S, E any] struct {
	Initial           func() S
	Evolve            func(S, E) S
	MarshalEvent      func(E) (typeTag string, data []byte, err error)
	UnmarshalEvent    func(typeTag string, data []byte) (E, error)
	MarshalSnapshot   func(S) ([]byte, error)
	UnmarshalSnapshot func([]byte) (S, error)
}

Decider bundles the per-aggregate funcs the host needs. Domains supply these as plain funcs; the host owns no domain types. Decide/React/action-execution and any fixpoint stay in the domain shell — only the event-sourcing plumbing is generic.

func (Decider[S, E]) Append

func (d Decider[S, E]) Append(es *store.EventStore, streamID string, expectedVersion int, evs []E, newState S) error

Append encodes evs, appends them at expectedVersion (optimistic concurrency via store.EventStore), then snapshots newState at the resulting version. No-op when evs is empty. Returns store.ErrConcurrencyConflict on a version mismatch.

func (Decider[S, E]) Load

func (d Decider[S, E]) Load(es *store.EventStore, streamID string) (S, int, error)

Load reconstructs a stream's state: latest snapshot folded forward over any newer events via Evolve. Returns the folded state and the stream's current version (Initial() at version 0 for an empty stream).

Jump to

Keyboard shortcuts

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