store/mem
import "github.com/barevoidco/zelk/core/store/mem"Package mem is an in-memory store.LogStore, for tests and ephemeral sessions that are never persisted. Everything is lost when the process exits.
It encodes events on append and decodes them on read, like a durable store, so it rejects the same events a durable store would, preserves unknown payloads byte for byte, and never shares memory with its callers.
Inbox keeps observer occurrences outside the session log without requiring a lease. Pending durably seals payloads before returning them for admission; Trim follows log acknowledgment. Both bounds and immutability are enforced.
type Store struct { // contains filtered or unexported fields}Store is an in-memory store.LogStore. The zero value is an empty store ready to use. A Store is safe for concurrent use.
Example
ctx := context.Background()s := mem.New()tok := lease.Token{Session: "s1", Fence: 1}
now := time.Date(2026, 10, 15, 9, 0, 0, 0, time.UTC)_ = s.Append(ctx, "s1", 0, tok, event.Event{Seq: 1, Time: now, Payload: event.Warning{Code: "first"}}, event.Event{Seq: 2, Time: now, Payload: event.Warning{Code: "second"}},)// A second writer that still thinks the log is empty is refused.err := s.Append(ctx, "s1", 0, tok, event.Event{Seq: 1, Time: now, Payload: event.Warning{Code: "late"}})fmt.Println(err != nil)
for ev, err := range s.Read(ctx, "s1", 0) { if err != nil { panic(err) } fmt.Println(ev.Seq, ev.Payload.(event.Warning).Code)}// Output:// true// 1 first// 2 secondOutput:
true1 first2 secondfunc New() *StoreNew returns an empty store.
Store.Adopt
Section titled “Store.Adopt”func (s *Store) Adopt(ctx context.Context, session string, token lease.Token) (uint64, error)Adopt records token’s fence and returns the log’s last sequence number. Everything a Store holds is as durable as the Store itself, so there is nothing to sync.
Store.Append
Section titled “Store.Append”func (s *Store) Append(ctx context.Context, session string, expectSeq uint64, token lease.Token, evs ...event.Event) errorAppend atomically adds evs to the session’s log.
Store.Blobs
Section titled “Store.Blobs”func (s *Store) Blobs() store.BlobStoreBlobs returns the store of the sessions’ outputs.
Store.DropHistory
Section titled “Store.DropHistory”func (s *Store) DropHistory(ctx context.Context, session string) errorDropHistory removes the session’s whole checkpoint history.
Store.Durable
Section titled “Store.Durable”func (*Store) Durable() boolDurable reports false: logs live only as long as the Store.
Store.GetVersion
Section titled “Store.GetVersion”func (s *Store) GetVersion(ctx context.Context, session string, ref blob.Ref) ([]byte, error)GetVersion returns a version of the session’s checkpoint history.
Store.Inbox
Section titled “Store.Inbox”func (s *Store) Inbox() store.InboxInbox returns the store’s observer inbox. It requires no lease and shares the Store’s lifetime and concurrency safety.
Example
s := mem.New()ctx := context.Background()err := s.Inbox().Append(ctx, "session", "build", store.Occurrence{Payload: event.OccurrencePayload{Text: "Build failed"}})if err != nil { panic(err)}pending, err := s.Inbox().Pending(ctx, "session", "build", 0)if err != nil { panic(err)}fmt.Println(pending[0].Number, pending[0].Payload.Text)if err = s.Inbox().Trim(ctx, "session", "build", pending[0].Number); err != nil { panic(err)}// Output: 1 Build failedOutput:
1 Build failedStore.Leftovers
Section titled “Store.Leftovers”func (s *Store) Leftovers(ctx context.Context) iter.Seq2[string, error]Leftovers yields the sessions the listing leaves out that still hold storage: tombstoned logs, and outputs, file history or inboxes with no log.
Store.PruneVersions
Section titled “Store.PruneVersions”func (s *Store) PruneVersions(ctx context.Context, session string, keep func(digest string) bool) errorPruneVersions removes the session’s versions keep rejects.
Store.PutVersion
Section titled “Store.PutVersion”func (s *Store) PutVersion(ctx context.Context, session string, data []byte) (blob.Ref, error)PutVersion stores data in the session’s checkpoint history.
Store.Read
Section titled “Store.Read”func (s *Store) Read(ctx context.Context, session string, fromSeq uint64) iter.Seq2[event.Event, error]Read yields the session’s events from fromSeq on.
Store.RemoveSession
Section titled “Store.RemoveSession”func (s *Store) RemoveSession(ctx context.Context, session string, token lease.Token) errorRemoveSession removes the session’s outputs, inbox, file history and log. Its fence stays, so a holder whose lease ended before the removal stays refused.
Store.Sessions
Section titled “Store.Sessions”func (s *Store) Sessions(ctx context.Context) iter.Seq2[store.SessionInfo, error]Sessions yields the sessions whose logs hold an event, most recently updated first.