memory

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package memory provides in-memory implementations of the persistence ports defined in internal/ports. It is the canonical backend used by tests; production code should use the SQLite or Postgres backends.

Registers itself with the top-level store factory under the "memory" scheme. Per Mnemos ADR 0001 §3, ?namespace= is accepted but produces independent state per Open — there is no shared process-wide map, so each call to store.Open("memory://...") returns a fresh, empty backend regardless of namespace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	EntityStates *EntityStateRepository
	Signals      *SignalRepository
	// contains filtered or unexported fields
}

Conn bundles the in-memory repositories. The zero value is unusable; use New.

func New

func New() *Conn

New creates a fresh in-memory Conn with all repositories wired up.

func (*Conn) Close

func (c *Conn) Close() error

Close is a no-op; the in-memory store has no resources to release. It satisfies io.Closer so the same factory wiring works as for the SQL backends.

type EntityStateRepository

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

EntityStateRepository implements ports.EntityStateRepository in memory.

func (*EntityStateRepository) Count

func (r *EntityStateRepository) Count(_ context.Context, adapterName string) (int64, error)

Count returns the total number of states recorded by adapterName.

func (*EntityStateRepository) DeleteOlderThan

func (r *EntityStateRepository) DeleteOlderThan(_ context.Context, cutoff time.Time, adapterName string) error

DeleteOlderThan removes states observed before cutoff for the named adapter.

func (*EntityStateRepository) Ingest

func (r *EntityStateRepository) Ingest(_ context.Context, adapterName string, state chronos.EntityState) error

Ingest persists a single observation.

func (*EntityStateRepository) ListByEntity

func (r *EntityStateRepository) ListByEntity(_ context.Context, entityID uuid.UUID) ([]chronos.EntityState, error)

ListByEntity scans all scopes for observations of entityID, most recent first.

func (*EntityStateRepository) ListByScope

func (r *EntityStateRepository) ListByScope(_ context.Context, scopeID uuid.UUID) ([]chronos.EntityState, error)

ListByScope returns a defensive copy of all states recorded under scopeID, most recent first.

func (*EntityStateRepository) ListScopes

func (r *EntityStateRepository) ListScopes(_ context.Context) ([]uuid.UUID, error)

ListScopes returns the distinct ScopeIDs that have at least one observation. Order is unspecified. The scheduler uses this to know which scopes to detect over.

func (*EntityStateRepository) Save

func (r *EntityStateRepository) Save(_ context.Context, adapterName string, states []chronos.EntityState) error

Save persists a batch of observations.

type SignalRepository

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

SignalRepository implements ports.SignalRepository in memory.

func (*SignalRepository) Count

func (r *SignalRepository) Count(_ context.Context, filter ports.SignalFilter) (int64, error)

Count returns the number of signals matching filter.

func (*SignalRepository) Get

Get returns a single signal by ID.

func (*SignalRepository) List

List returns signals matching the filter, ordered detected-at desc then confidence desc.

func (*SignalRepository) Save

Save appends or replaces a signal by ID.

Jump to

Keyboard shortcuts

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