evt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

evt

Documentation site

evt is a Go event-sourcing framework for systems that want immutable domain events, DynamoDB-backed persistence, deterministic read models, and practical operational tooling without a large application framework.

It was extracted from production patterns, but this repository is intentionally public-safe: examples use neutral table names, local emulator credentials, and no private application environment details.

Packages

Package Purpose
github.com/photon-grove/evt Core aggregate, command, event, metadata, transaction, repository, and rebuild contracts
github.com/photon-grove/evt/mem In-memory repository and store for unit tests
github.com/photon-grove/evt/dynamo DynamoDB event log, snapshots, views, stream helpers, and transaction groups
github.com/photon-grove/evt/snapshots Store implementation with snapshot loading and snapshot write thresholds
github.com/photon-grove/evt/stream Stream handler and publisher helpers for event fanout
github.com/photon-grove/evt/projectors DynamoDB Streams Lambda projector runtime with idempotency and retry classification
github.com/photon-grove/evt/publishers DynamoDB Streams publisher handler with ingress and retry budgets
github.com/photon-grove/evt/policy Backend-neutral retry helpers for commit paths
github.com/photon-grove/evt/policy/dynamodb DynamoDB-specific retry classification
github.com/photon-grove/evt/viewstore Typed JSON helper around evt.ViewRepository
github.com/photon-grove/evt/test Test aggregate, commands, events, and helpers for adopters and framework tests

Install

go get github.com/photon-grove/evt

Quick Start

Start with the memory store in tests:

repo := mem.NewRepository()
store := mem.NewStoreFromRepo(repo)

entity := account.NewEntity("acct-1")
err := store.Execute(ctx, entity, "acct-1", &account.Open{InitialBalance: 100}, evt.Metadata{})

Move production storage to DynamoDB without changing aggregate contracts:

repo := dynamo.NewRepository(dynamoClient, "event-log")
store := snapshots.NewStore(repo, 25)

Use factory helpers when aggregates carry injected dependencies:

entity, err := evt.ExecuteWithFactory(ctx, store, func() evt.Entity {
	return account.NewEntity("acct-1", projectors...)
}, "acct-1", command, metadata)

Local Development

pnpm install
go test ./...
moon run evt:test

DynamoDB integration tests run against a local AWS emulator:

docker run -d --name evt-moto -p 4566:5000 motoserver/moto:5.1.22
terraform -chdir=infra/local init
terraform -chdir=infra/local apply -auto-approve
AWS_ENDPOINT_URL=http://localhost:4566 moon run evt:integration

Documentation

The docs site includes architecture diagrams, examples, and an integration cookbook:

moon run website:dev
moon run website:build

Static docs live in docs/, and the interactive site lives in website/.

Operational Invariants

The central invariant is that event rows are the source of truth and view rows are derived state. Any projection/view table should be safe to wipe and rebuild from immutable events. Human decisions, external signals, publish flags, and review verdicts should be event-sourced before they appear in a view.

See BEHAVIORAL_INVARIANTS.md for the exact serialization and DynamoDB schema guarantees.

License

Apache-2.0. See LICENSE.


Built with care by Photon Grove — a Colorado software studio.

Documentation

Overview

Package evt provides an immutable event-sourcing framework with pluggable backends.

Index

Constants

View Source
const DefaultViewSK = "VIEW"

DefaultViewSK is the default sort key for single-item views.

Variables

This section is empty.

Functions

func CalculateAdditionalEvents

func CalculateAdditionalEvents(currentSequence EventSequence, numEvents int, maxSize int) int

CalculateAdditionalEvents calculates the number of additional events that can be applied after the next snapshot is taken.

func DecodeJSONView

func DecodeJSONView[T any](view *SerializedView, target T) error

DecodeJSONView decodes a SerializedView payload into target.

target must be a non-nil pointer. Passing a struct value, a nil pointer, or a nil slice/map returns an error rather than silently no-op'ing into a discarded local copy. Use a pointer to preserve constructor-injected fields on domain entities and to receive the decoded JSON payload.

func GetJSONView

func GetJSONView[T any](
	ctx context.Context,
	repo ViewRepository,
	pk string,
	newValue NewJSONViewValueFunc[T],
) (T, bool, error)

GetJSONView loads a serialized view by partition key and decodes its JSON payload into T.

The boolean return value is false when no view exists for pk. Repository and JSON decode failures are returned as errors.

func IsConflictErr

func IsConflictErr(err error) bool

IsConflictErr returns true when err is a ConflictError.

func IsDuplicateCommandErr

func IsDuplicateCommandErr(err error) bool

IsDuplicateCommandErr returns true when err is a DuplicateCommandError.

func IsNoOpErr

func IsNoOpErr(err error) bool

IsNoOpErr returns true when err is a NoOpError.

func IsNotFoundErr

func IsNotFoundErr(err error) bool

IsNotFoundErr returns true when err is a NotFoundError.

func IsReplayStrictnessErr

func IsReplayStrictnessErr(err error) bool

IsReplayStrictnessErr returns true when err is a ReplayStrictnessError.

func ListJSONViewsByEntityType

func ListJSONViewsByEntityType[T any](
	ctx context.Context,
	repo ViewRepository,
	entityType EntityType,
	newValue NewJSONViewValueFunc[T],
) ([]T, error)

ListJSONViewsByEntityType lists views by entity type and strictly decodes every JSON payload into T.

Use ListValidJSONViewsByEntityType when invalid payloads should be skipped instead of failing the whole list.

func ListJSONViewsByPK

func ListJSONViewsByPK[T any](
	ctx context.Context,
	repo ViewRepository,
	pk string,
	newValue NewJSONViewValueFunc[T],
) ([]T, error)

ListJSONViewsByPK lists views by partition key and strictly decodes every JSON payload into T.

Use ListValidJSONViewsByPK when invalid payloads should be skipped instead of failing the whole list.

func ListValidJSONViewsByEntityType

func ListValidJSONViewsByEntityType[T any](
	ctx context.Context,
	repo ViewRepository,
	entityType EntityType,
	newValue NewJSONViewValueFunc[T],
	onDecodeError func(*SerializedView, error),
) ([]T, error)

ListValidJSONViewsByEntityType lists views by entity type and decodes valid JSON payloads into T, skipping invalid payloads.

When onDecodeError is non-nil, it is called for each skipped payload.

func ListValidJSONViewsByPK

func ListValidJSONViewsByPK[T any](
	ctx context.Context,
	repo ViewRepository,
	pk string,
	newValue NewJSONViewValueFunc[T],
	onDecodeError func(*SerializedView, error),
) ([]T, error)

ListValidJSONViewsByPK lists views by partition key and decodes valid JSON payloads into T, skipping invalid payloads.

When onDecodeError is non-nil, it is called for each skipped payload.

func LoadEntityWithFactory

func LoadEntityWithFactory(
	ctx context.Context,
	store Store,
	factory EntityFactory,
	entityID EntityID,
) (Entity, Context, error)

LoadEntityWithFactory creates a fresh entity instance and loads it from the store.

func PutJSONView

func PutJSONView(ctx context.Context, repo ViewRepository, view *SerializedView, value any) error

PutJSONView marshals value as JSON and writes it as the Payload of view.

The provided SerializedView is copied before mutation so callers can safely reuse metadata templates across writes.

Types

type BadCommandError

type BadCommandError struct {
	Command Command
}

BadCommandError means an invalid Command was sent to an Entity

func NewBadCommandError

func NewBadCommandError(command Command) *BadCommandError

NewBadCommandError creates a new instance of a BadCommandError

func (*BadCommandError) Error

func (e *BadCommandError) Error() string

Error provides the error message

type BadEventError

type BadEventError struct {
	Event Event
}

BadEventError is returned when an invalid Event is sent to an

func NewBadEventError

func NewBadEventError(event Event) *BadEventError

NewBadEventError creates a new instance of a BadEventError

func (*BadEventError) Error

func (e *BadEventError) Error() string

Error returns the error message string

type BaseEntity

type BaseEntity struct {
	ID        EntityID  `json:"id"`        // A unique identifier
	IsActive  bool      `json:"isActive"`  // Whether this record has been deleted
	CreatedAt time.Time `json:"createdAt"` // The date this record was originally created
	UpdatedAt time.Time `json:"updatedAt"` // The date this record was last updated
}

BaseEntity provides common fields for all entities.

func NewEntity

func NewEntity(id EntityID) BaseEntity

NewEntity creates a new BaseEntity with the given ID, setting IsActive to true and timestamps to now.

type ByCommandID

type ByCommandID []SerializedEvent

ByCommandID allows you to sort SerializedEvents by the CommandID in the Metadata, falling back to sorting by event ID if the CommandID is empty.

func (ByCommandID) Len

func (events ByCommandID) Len() int

Len returns the length of the slice.

func (ByCommandID) Less

func (events ByCommandID) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (ByCommandID) Swap

func (events ByCommandID) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type Command

type Command interface {
	Type() CommandType
	EntityType() EntityType
}

Command is implemented by all command types.

type CommandID

type CommandID string

CommandID is a unique identifier for a Command instance.

type CommandResult

type CommandResult struct {
	Events      []Event     `json:"events"`
	Transaction Transaction `json:"transaction"`
}

CommandResult is the outcome of executing a Command.

type CommandType

type CommandType string

CommandType is a unique identifier for the type of a Command.

type ConflictError

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

ConflictError indicates a domain-level conflict (e.g., duplicate resource)

func NewConflictError

func NewConflictError(msg string) *ConflictError

NewConflictError creates a new ConflictError with the given message.

func (*ConflictError) Error

func (e *ConflictError) Error() string

Error returns the error message string

type Context

type Context struct {
	Entity          Entity
	EntityID        EntityID
	CurrentSequence *EventSequence
	CurrentSnapshot *EventSequence
	SeenCommandIDs  map[CommandID]struct{} // CommandIDs observed during event replay (dedupe guard)
}

Context carries entity context for the EventStore.

func (Context) HasCommandID

func (c Context) HasCommandID(id CommandID) bool

HasCommandID reports whether the given CommandID was already seen during event replay.

func (*Context) RecordCommandID

func (c *Context) RecordCommandID(id CommandID)

RecordCommandID adds a CommandID to the seen set (initializing the map if needed).

type DuplicateCommandError

type DuplicateCommandError struct {
	CommandID CommandID
}

DuplicateCommandError indicates a command with the same CommandID has already been processed. Callers should treat this as an idempotent success rather than a failure.

func NewDuplicateCommandError

func NewDuplicateCommandError(id CommandID) *DuplicateCommandError

NewDuplicateCommandError creates a new DuplicateCommandError.

func (*DuplicateCommandError) Error

func (e *DuplicateCommandError) Error() string

Error returns the error message string.

type Endpoint

type Endpoint string

An Endpoint is the entrypoint the request came in through

type Entity

type Entity interface {
	Type() EntityType
	GetID() EntityID
	Base() BaseEntity
	Handle(context.Context, Command) (CommandResult, error)
	Apply(Event) error
	DeserializeEvent(serializedEvent SerializedEvent) (Event, error)
	EventUpcasters() []EventUpcaster
	Projectors() []EventProjector
}

Entity is an object whose state is made up of aggregated immutable change Events.

func ExecuteWithFactory

func ExecuteWithFactory(
	ctx context.Context,
	store Store,
	factory EntityFactory,
	entityID EntityID,
	command Command,
	metadata Metadata,
) (Entity, error)

ExecuteWithFactory creates a fresh entity instance, executes the command, and returns it.

type EntityFactory

type EntityFactory func() Entity

EntityFactory constructs a fresh zero-state aggregate instance for load/execute operations.

type EntityID

type EntityID string

EntityID is a unique identifier for an aggregated Entity instance.

type EntityType

type EntityType string

EntityType is the type of an aggregated Entity.

type Event

type Event interface {
	Type() EventType
	Version() EventVersion
	EntityType() EntityType
	EntityID() EntityID
}

Event is implemented by all event types.

func DeserializeEvent

func DeserializeEvent(serializedEvent SerializedEvent, entity Entity) (Event, error)

DeserializeEvent decodes Events with the Entity within the given Context, applying upcasters.

type EventID

type EventID string

EventID combines the entity ID and event sequence.

func GetEventID

func GetEventID(entityID EntityID, sequence EventSequence) EventID

GetEventID builds a stable event ID from the entity ID and sequence.

type EventProjector

type EventProjector interface {
	// Project produces a transaction group for the given entity state. Returning nil
	// indicates no operations are required.
	Project(context.Context, Entity, []Event) (TransactionGroup, error)
}

EventProjector generates transactional view operations that should be committed alongside events.

type EventSequence

type EventSequence int

EventSequence is a unique sequence number within an entity instance.

type EventType

type EventType string

EventType identifies an event kind.

type EventUpcaster

type EventUpcaster interface {
	CanUpcast(EventType, EventVersion) bool
	Upcast(SerializedEvent) (SerializedEvent, error)
}

EventUpcaster migrates a serialized event from an older version to a newer version before aggregate replay.

type EventVersion

type EventVersion int

EventVersion is the schema version of an event.

type JSONViewDecodeError

type JSONViewDecodeError struct {
	PK  string
	SK  string
	Err error
}

JSONViewDecodeError describes a payload decode failure for a serialized view.

func (*JSONViewDecodeError) Error

func (e *JSONViewDecodeError) Error() string

Error returns a human-readable decode error message.

func (*JSONViewDecodeError) Unwrap

func (e *JSONViewDecodeError) Unwrap() error

Unwrap returns the underlying JSON decode error.

type Metadata

type Metadata struct {
	CommandID *CommandID              `json:"commandId"`
	Trace     *propagation.MapCarrier `json:"trace"`
	Origin    *Origin                 `json:"origin"`
	Address   *string                 `json:"address"`
	Region    string                  `json:"region"`
	Timestamp string                  `json:"timestamp"`
}

Metadata is a set of additional data carried along with an Event. Any changes should be backwards compatible, and bad data should always be tested.

func NewMetadata

func NewMetadata(ctx context.Context, region *string, opts ...MetadataOption) Metadata

NewMetadata initializes a Metadata k-v store

type MetadataOption

type MetadataOption func(Metadata) Metadata

MetadataOption is used to add properties to metadata

func WithAddress

func WithAddress(address string) MetadataOption

WithAddress adds the caller-provided address to metadata.

func WithCommandID

func WithCommandID(cmdid CommandID) MetadataOption

WithCommandID adds the provided commandId to metadata

func WithOrigin

func WithOrigin(origin Origin) MetadataOption

WithOrigin adds the Origin to the request Metadata

func WithTrace

func WithTrace(ctx context.Context) MetadataOption

WithTrace adds trace context to metadata

type NewJSONViewValueFunc

type NewJSONViewValueFunc[T any] func() T

NewJSONViewValueFunc creates a destination value for JSON view decoding.

For pointer-backed domain entities that need constructor-injected dependencies, pass the app-specific constructor:

entity, found, err := evt.GetJSONView(ctx, repo, pk, func() *Entity {
	return NewEntity(projectors...)
})

For plain value types, callers may pass nil and the zero value of T will be used as the decode destination.

type NoOpError

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

NoOpError indicates a command would produce no changes.

func NewNoOpError

func NewNoOpError(msg string) *NoOpError

NewNoOpError creates a new NoOpError with the given message.

func (*NoOpError) Error

func (e *NoOpError) Error() string

Error returns the error message string.

type NotFoundError

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

A NotFoundError indicates a required record was not found

func NewNotFoundError

func NewNotFoundError(msg string) *NotFoundError

NewNotFoundError creates a new instance of a NotFoundError from a message

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error returns the error message string

type Origin

type Origin struct {
	Source   Source   `json:"source"`
	Endpoint Endpoint `json:"endpoint"`
}

An Origin is the combination of the source and the endpoint

type PagedResult

type PagedResult struct {
	Views      []*SerializedView
	NextCursor string
}

PagedResult wraps a page of views with an optional cursor for the next page.

type RebuildConfig

type RebuildConfig struct {
	// EntityType filters entities to rebuild. Only entities matching this type are processed.
	EntityType EntityType

	// Projectors are the projection functions to run against each entity.
	Projectors []EventProjector

	// CommitGroup writes a TransactionGroup produced by a projector. Required when DryRun is false.
	// For DynamoDB-backed views this typically executes the ViewPutGroup's write items via
	// BatchWriteItem or TransactWriteItems.
	CommitGroup func(ctx context.Context, group TransactionGroup) error

	// DryRun when true skips writing views and only reports what would change.
	DryRun bool

	// MaxErrors caps the number of per-entity errors collected before the rebuild stops early.
	// Zero means no limit.
	MaxErrors int

	// OnProgress, if non-nil, is called after each entity is successfully processed
	// by the projectors or when an error is encountered (stream, projector, or commit).
	// Skipped entities (nil or wrong type) do not trigger this callback.
	// The processed argument is the count of successfully processed entities so far,
	// and errors is the cumulative number of errors encountered.
	OnProgress func(processed, errors int)

	// Logger receives rebuild telemetry. If nil, slog.Default() is used.
	Logger *slog.Logger
}

RebuildConfig configures a projection rebuild run.

type RebuildResult

type RebuildResult struct {
	// Processed is the number of entities successfully replayed through all projectors.
	Processed int

	// Skipped is the number of entities skipped (wrong type or nil).
	Skipped int

	// Errors collects per-entity errors that did not halt the run.
	// Capped by MaxErrors if configured.
	Errors []error
}

RebuildResult summarizes a projection rebuild run.

Note: Processed counts only entities where all projectors succeeded. Entities that produced errors are counted in Errors, not Processed or Skipped.

func RebuildProjections

func RebuildProjections(
	ctx context.Context,
	repo Repository,
	applyEvent func(context.Context, SerializedEvent, Entity) (Entity, error),
	cfg RebuildConfig,
) (*RebuildResult, error)

RebuildProjections replays all entities from the repository through the configured projectors, regenerating view data. Entities are streamed via StreamEntities, so this works with any Repository implementation.

The applyEvent callback is the same function used by StreamEntities to reconstitute entities from serialized events. Callers typically pass the same function they use for normal event replay (deserialize + apply).

type ReplayStrictnessError

type ReplayStrictnessError struct {
	EventType EventType
	Version   EventVersion
	Phase     string
	Err       error
}

ReplayStrictnessError indicates replay failed closed while upcasting or deserializing an event.

func (*ReplayStrictnessError) Error

func (e *ReplayStrictnessError) Error() string

Error returns the underlying error message.

func (*ReplayStrictnessError) Unwrap

func (e *ReplayStrictnessError) Unwrap() error

Unwrap returns the underlying error.

type Repository

type Repository interface {
	// Commit new Events for an Entity instance.
	Commit(ctx context.Context, result SerializedResult) error

	// Commit a stream of Events using whatever batch size works best for the Repository.
	CommitStream(ctx context.Context, channel <-chan result.Result[SerializedResult]) []error

	// Commit new Events for an Entity instance while also saving the given Snapshot.
	CommitWithSnapshot(
		ctx context.Context,
		result SerializedResult,
		entityType EntityType,
		entityID EntityID,
		payload []byte,
		currentSnapshot EventSequence,
	) error

	// Get all Events for an Entity instance.
	GetEvents(
		ctx context.Context,
		entityID EntityID,
	) ([]SerializedEvent, error)

	// Get the latest Events beyond the given sequence number for an Entity, used for
	// finding Events after a particular Snapshot.
	GetLatestEvents(
		ctx context.Context,
		entityID EntityID,
		lastSequence EventSequence,
	) ([]SerializedEvent, error)

	// Get the latest Snapshot for an Entity instance.
	GetSnapshot(
		ctx context.Context,
		entityID EntityID,
	) (*SerializedSnapshot, error)

	// StreamAllEvents returns a channel of all Events in the Repository, optionally filtered by the
	// given DynamoDB expression.
	StreamAllEvents(
		ctx context.Context,
		expr *expression.Expression,
	) <-chan result.Result[[]SerializedEvent]

	// StreamEntities returns a channel of all Entities in the Repository, optionally filtered by
	// the given DynamoDB expression, and with the given function applied to each Entity to apply
	// the application-specific Events to each instance.
	StreamEntities(
		ctx context.Context,
		expr *expression.Expression,
		applyEvent func(context.Context, SerializedEvent, Entity) (Entity, error),
	) <-chan result.Result[Entity]
}

Repository manages events for entities consistently and persists snapshots to improve load time.

type SerializedEvent

type SerializedEvent struct {
	ID         EventID       `json:"id"` // Composed of the EntityID and EventSequence
	Sequence   EventSequence `json:"sequence"`
	Type       EventType     `json:"type"`
	Version    EventVersion  `json:"version"`
	EntityID   EntityID      `json:"entityId"`
	EntityType EntityType    `json:"entityType"`
	Payload    []byte        `json:"payload"`
	Metadata   Metadata      `json:"metadata"`
}

SerializedEvent is a common event format that is ready to be committed to an Event Store and streamed to downstream event listeners.

func SerializeEvents

func SerializeEvents(
	events []Event,
	sequence EventSequence,
	entityID EntityID,
	metadata Metadata,
) ([]SerializedEvent, error)

SerializeEvents prepares an Event for serialization and storage.

func SerializeEventsWithContext

func SerializeEventsWithContext(events []Event, eventContext *Context, metadata Metadata) ([]SerializedEvent, error)

SerializeEventsWithContext serializes Events with the Entity within the given Context.

type SerializedResult

type SerializedResult struct {
	Events      []SerializedEvent `json:"events"`
	Transaction Transaction       `json:"transactions"`
}

SerializedResult is similar to CommandResult but uses SerializedEvents instead.

func SerializeResult

func SerializeResult(
	eventContext Context,
	entity Entity,
	events []Event,
	transaction Transaction,
) (SerializedResult, error)

SerializeResult creates a SerializedResult from events using the given context and entity. This is a convenience function for testing and integration scenarios.

type SerializedSnapshot

type SerializedSnapshot struct {
	EntityType    EntityType    `json:"entityType"`
	EntityID      EntityID      `json:"entityID"`
	Sequence      EventSequence `json:"sequence"`
	EventSequence EventSequence `json:"eventSequence"`
	Payload       []byte        `json:"payload"`
}

SerializedSnapshot represents a snapshot of current Entity state that is ready to be committed to a Repository.

type SerializedView

type SerializedView struct {
	PK         string     `json:"pk"`
	SK         string     `json:"sk"`
	EntityID   EntityID   `json:"entityID"`
	EntityType EntityType `json:"entityType"`
	Payload    []byte     `json:"payload"`
	TTL        int64      `json:"ttl,omitempty"`
}

SerializedView is a simple representation of a materialized entity view stored in the backing store.

type Source

type Source string

A Source is the system that initiated the request

type StorageType

type StorageType string

StorageType identifies the backend storage system a Repository uses.

type Store

type Store interface {
	// LoadEntity loads the given Entity instance with the given id, retrieving Snapshots
	// and Events from the Repository.
	LoadEntity(
		ctx context.Context,
		entity Entity,
		entityID EntityID,
	) (Context, error)

	// Commit new Events to the Entity within the given context, with optional Metadata.
	Commit(
		ctx context.Context,
		result CommandResult,
		context Context,
		metadata Metadata,
	) ([]SerializedEvent, error)

	// Execute takes an empty Entity instance, loads it from the Repository, handles the given
	// Command, commits the resulting Events using the given Metadata, and applies those Events to the
	// current Entity instance.
	Execute(
		ctx context.Context,
		entity Entity,
		entityID EntityID,
		command Command,
		metadata Metadata,
	) error
}

Store handles executing Commands, committing Events yielded by those Commands, and loading Entity instances from a Repository.

type Transaction

type Transaction = []TransactionGroup

A Transaction is a collection of grouped operations that should be rolled back together in the event of failure.

func MergeTransactions

func MergeTransactions(transaction, with Transaction) Transaction

MergeTransactions takes two Transactions to merge together, and returns a new Transaction that contains the groups from both Transactions (or either, if one is nil)

type TransactionGroup

type TransactionGroup interface {
	Len() int
	Merge(with TransactionGroup) (TransactionGroup, error)
	StorageType() StorageType
	TransactionType() TransactionType
	HandleError(error, int) error
}

A TransactionGroup is a group of operations included in a Transaction

func Merge

func Merge(group, with TransactionGroup) (TransactionGroup, error)

Merge combines two TransactionGroups into one, gracefully handling nil values.

func MergeTransactionGroups

func MergeTransactionGroups(group, with TransactionGroup) (TransactionGroup, error)

MergeTransactionGroups takes two TransactionGroups to merge together, and returns a new TransactionGroup that contains the operations from both TransactionGroups (or either, if one is nil)

type TransactionType

type TransactionType string

A TransactionType is a type of operation included in the Transaction.

type UpcastError

type UpcastError struct {
	Err             error           `json:"err"`
	SerializedEvent SerializedEvent `json:"serializedEvent"`
}

UpcastError wraps a failure that occurred while upcasting a serialized event.

func NewUpcastError

func NewUpcastError(err error, serializedEvent SerializedEvent) *UpcastError

NewUpcastError creates a new UpcastError instance.

func (*UpcastError) Error

func (e *UpcastError) Error() string

Error returns the wrapped error message.

type ViewRepository

type ViewRepository interface {
	// GetView retrieves a view by partition key (pk). Returns nil if not found.
	GetView(ctx context.Context, pk string) (*SerializedView, error)

	// PutView writes or replaces the given view.
	PutView(ctx context.Context, view *SerializedView) error

	// ListViewsByEntityType returns serialized views for the provided entity type.
	ListViewsByEntityType(ctx context.Context, entityType EntityType) ([]*SerializedView, error)

	// ListViewsByEntityTypePaged returns a page of views for the provided entity type.
	// limit controls page size; cursor is an opaque pagination token (empty for the first page).
	ListViewsByEntityTypePaged(ctx context.Context, entityType EntityType, limit int, cursor string) (*PagedResult, error)

	// ListViewsByPK returns all serialized views for the given partition key.
	// Used for composite keys where pk identifies a collection (e.g., USER#<id>#teams).
	ListViewsByPK(ctx context.Context, pk string) ([]*SerializedView, error)

	// ListViewsByPKPaged returns a page of views for the given partition key.
	// limit controls page size; cursor is an opaque pagination token (empty for the first page).
	ListViewsByPKPaged(ctx context.Context, pk string, limit int, cursor string) (*PagedResult, error)
}

ViewRepository is a lightweight repository interface for reading/writing entity views.

Directories

Path Synopsis
cmd
evt-doctor command
Package dynamo implements an EventStore backed by DynamoDB and related utilities.
Package dynamo implements an EventStore backed by DynamoDB and related utilities.
mock
Package mock provides DynamoDB client mocks nolint:errcheck
Package mock provides DynamoDB client mocks nolint:errcheck
examples
banking command
go module
Package mem provides an in-memory EventStore implementation for tests and local use.
Package mem provides an in-memory EventStore implementation for tests and local use.
Package policy provides shared retry and failure-classification primitives for evt-backed handlers.
Package policy provides shared retry and failure-classification primitives for evt-backed handlers.
dynamodb
Package dynamodb provides DynamoDB-specific retry classification for evt policy.
Package dynamodb provides DynamoDB-specific retry classification for evt policy.
Package projectors provides an async projector runtime for processing DynamoDB Streams events.
Package projectors provides an async projector runtime for processing DynamoDB Streams events.
Package publishers provides reusable Lambda helpers for publishing event-log records from DynamoDB Streams to downstream event transports.
Package publishers provides reusable Lambda helpers for publishing event-log records from DynamoDB Streams to downstream event transports.
Package result provides a Rust-style Result type for propagating success or error values.
Package result provides a Rust-style Result type for propagating success or error values.
Package snapshots defines a snapshot event store
Package snapshots defines a snapshot event store
Package stream provides interfaces and implementations for publishing events to streaming services.
Package stream provides interfaces and implementations for publishing events to streaming services.
Package test contains fixtures and helpers for testing event-sourced entities.
Package test contains fixtures and helpers for testing event-sourced entities.
Package viewstore provides a typed wrapper around evt.ViewRepository that binds a JSON codec, an evt.EntityType, and an optional value factory so individual stores only need to express their domain key conventions (pk/sk builders) rather than re-implementing JSON encode/decode plumbing.
Package viewstore provides a typed wrapper around evt.ViewRepository that binds a JSON codec, an evt.EntityType, and an optional value factory so individual stores only need to express their domain key conventions (pk/sk builders) rather than re-implementing JSON encode/decode plumbing.

Jump to

Keyboard shortcuts

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