memoryprojection

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package memoryprojection provides utilities for building in-memory projections.

Memory projections do not persist any state, and therefore may only be useful for testing or with an event-sourcing engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func Query[T, R any, H MessageHandler[T]](p *Projection[T, H], q func(T) R) R

Query queries a value of type T to produce a result of type R.

q is called with the current value, which may be read within the lifetime of the call to fn. fn MUST NOT retain a reference to the value after the call returns. fn MUST NOT modify the value.

Types

type MessageHandler

type MessageHandler[T any] interface {
	// Configure declares the handler's configuration by calling methods on c.
	//
	// The configuration includes the handler's identity and message routes.
	//
	// The engine calls this method at least once during startup. It must
	// produce the same configuration each time it's called.
	Configure(c dogma.ProjectionConfigurer)

	// HandleEvent updates the projection to reflect the occurrence of a
	// [dogma.Event]. It may do so by modifying v in-place then returning it, or
	// by returning an entirely new value.
	HandleEvent(v T, s dogma.ProjectionEventScope, m dogma.Event) (T, error)

	// Compact reduces the projection's size by removing or consolidating data.
	// It may do so by modifying v in-place then returning it, or by returning
	// an entirely new value.
	Compact(v T, s dogma.ProjectionCompactScope) T
}

MessageHandler is a specialization of dogma.ProjectionMessageHandler that builds an in-memory projection represented by a value of type T.

type NoCompactBehavior

type NoCompactBehavior[T any] struct{}

NoCompactBehavior can be embedded in MessageHandler implementations to indicate that the projection does not require its data to be compacted.

It provides an implementation of MessageHandler.Compact() that does nothing.

func (NoCompactBehavior[T]) Compact

func (NoCompactBehavior[T]) Compact(v T, _ dogma.ProjectionCompactScope) T

Compact does nothing.

type Projection

type Projection[T any, H MessageHandler[T]] struct {
	Handler H
	// contains filtered or unexported fields
}

Projection is an in-memory projection that builds a value of type T.

func (*Projection[T, H]) CheckpointOffset added in v0.8.0

func (p *Projection[T, H]) CheckpointOffset(_ context.Context, id string) (uint64, error)

CheckpointOffset returns the offset at which the handler expects to resume handling events from a specific stream.

func (*Projection[T, H]) Compact

Compact reduces the size of the projection's data.

func (*Projection[T, H]) Configure

func (p *Projection[T, H]) Configure(c dogma.ProjectionConfigurer)

Configure produces a configuration for this handler by calling methods on the configurer c.

func (*Projection[T, H]) HandleEvent

func (p *Projection[T, H]) HandleEvent(
	_ context.Context,
	s dogma.ProjectionEventScope,
	m dogma.Event,
) (uint64, error)

HandleEvent updates the projection to reflect the occurrence of an event.

func (*Projection[T, H]) Reset added in v0.9.0

Reset resets the projection to its initial state.

Directories

Path Synopsis
internal
fixtures
Package fixtures is a set of test fixtures and mocks for in-memory projections.
Package fixtures is a set of test fixtures and mocks for in-memory projections.

Jump to

Keyboard shortcuts

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