mem

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mem provides an in-memory EventStore implementation for tests and local use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRepository

func NewRepository() evt.Repository

NewRepository creates a new instance of the Repository

func NewStore

func NewStore() evt.Store

NewStore constructs a SnapshotStore using the in-memory repo

func NewStoreFromRepo

func NewStoreFromRepo(repo evt.Repository) evt.Store

NewStoreFromRepo constructs a SnapshotStore wrapping the given Repository.

func ProvideRepository

func ProvideRepository(_ *do.Injector) (evt.Repository, error)

ProvideRepository uses the Dependency Injection system to create a new in-memory EventRepository

func ProvideStore

func ProvideStore(_ *do.Injector) (evt.Store, error)

ProvideStore uses the Dependency Injection system to create a new in-memory EventStore

Types

type Repository

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

This Repository lives in-memory for testing or local development

func (Repository) Commit

func (repo Repository) Commit(
	_ context.Context,
	result evt.SerializedResult,
) error

Commit Events to memory. It does not reject reused sequences, but like the durable backends it rejects a commit at or below the entity's snapshot, which compaction may have deleted below.

func (Repository) CommitStream

func (repo Repository) CommitStream(
	_ context.Context,
	channel <-chan result.Result[evt.SerializedResult],
) []error

CommitStream streams Events to memory

func (Repository) CommitWithSnapshot

func (repo Repository) CommitWithSnapshot(
	ctx context.Context,
	result evt.SerializedResult,
	entityType evt.EntityType,
	entityID evt.EntityID,
	payload []byte,
	currentSnapshot evt.EventSequence,
) error

CommitWithSnapshot commits Events with a Snapshot

func (Repository) CompactBelow added in v0.2.0

func (repo Repository) CompactBelow(
	_ context.Context,
	entityID evt.EntityID,
	throughSequence evt.EventSequence,
) (int, error)

CompactBelow deletes events for an entity whose sequence is in [1, throughSequence], but only after verifying a durable snapshot covers (>=) throughSequence. It implements evt.Compactor.

func (Repository) GetEvents

func (repo Repository) GetEvents(
	_ context.Context,
	entityID evt.EntityID,
) ([]evt.SerializedEvent, error)

GetEvents gets all Events

func (Repository) GetLatestEvents

func (repo Repository) GetLatestEvents(
	_ context.Context,
	entityID evt.EntityID,
	lastSequence evt.EventSequence,
) ([]evt.SerializedEvent, error)

GetLatestEvents gets all Events after a particular sequence

func (Repository) GetSnapshot

func (repo Repository) GetSnapshot(
	_ context.Context,
	entityID evt.EntityID,
) (*evt.SerializedSnapshot, error)

GetSnapshot gets a Snapshot

func (Repository) StreamAllEvents

func (repo Repository) StreamAllEvents(
	_ context.Context,
	filter evt.StreamFilter,
) <-chan result.Result[[]evt.SerializedEvent]

StreamAllEvents streams all Events, honoring the StreamFilter's entity-type narrowing client-side (the in-memory repository has no server-side filter to push down to).

func (Repository) StreamEntities

func (repo Repository) StreamEntities(
	ctx context.Context,
	filter evt.StreamFilter,
	applyEvent func(context.Context, evt.SerializedEvent, evt.Entity) (evt.Entity, error),
) <-chan result.Result[evt.Entity]

StreamEntities streams all collected Entities, honoring the StreamFilter's entity-type narrowing client-side (the in-memory repository has no server-side filter to push down to).

func (Repository) StreamEntitiesFromSnapshots added in v0.2.0

func (repo Repository) StreamEntitiesFromSnapshots(
	ctx context.Context,
	entityType evt.EntityType,
	seedEntity evt.SnapshotSeeder,
	applyEvent func(context.Context, evt.SerializedEvent, evt.Entity) (evt.Entity, error),
) <-chan result.Result[evt.Entity]

StreamEntitiesFromSnapshots streams collected Entities, seeding each from its snapshot (when present) before applying post-snapshot events. entityType, when non-empty, restricts the stream to entities of that type. It implements evt.SnapshotStreamer.

func (Repository) StreamEntityHeads added in v0.4.0

func (repo Repository) StreamEntityHeads(
	ctx context.Context,
	entityType evt.EntityType,
) (map[evt.EntityID]evt.EventSequence, error)

StreamEntityHeads implements evt.EntityHeadStreamer over the in-memory log. The head is the larger of the highest stored event sequence and the snapshot's recorded EventSequence, so it stays correct for streams whose early events were compacted away. entityType, when non-empty, restricts the result to that type.

func (Repository) StreamEntityHeadsFunc added in v0.5.0

func (repo Repository) StreamEntityHeadsFunc(
	_ context.Context,
	entityType evt.EntityType,
	visit func(evt.EntityID, evt.EventSequence) error,
) error

StreamEntityHeadsFunc implements evt.EntityHeadVisitor over the in-memory log, invoking visit once per entity without building the full map StreamEntityHeads returns. The in-memory backend holds the whole log anyway, so this is not constant-memory the way a paged heads table is; it exists so the in-memory repository can stand in for a streaming head source in tests and examples. The head has the same meaning as StreamEntityHeads (the larger of the highest stored event sequence and the snapshot's recorded EventSequence). If visit returns an error, enumeration stops and returns it.

Jump to

Keyboard shortcuts

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