Skip to main content

StoreLookup

Type Alias StoreLookup 

Source
pub type StoreLookup<'a> = &'a dyn Fn(&EntityId) -> Option<String>;
Expand description

Synthesise per-entity events for a folder-backed mem by reading <mem_root>/.memstead/changes.jsonl and bucketing events by entity.

Net-effect rules per entity:

  • Last event = Delete → Removed
  • First event = Create → Added
  • Anything else → Updated

A rename row records only the id the entity now carries (the ledger’s on-disk shape); with store present the replay pairs it with the id that vanished: an id the ledger knows, absent from the store, never deleted, whose creation instant matches the renamed entity’s created_date (a rename keeps it), falling back to the nearest vanished id before the rename row. A pair inside one window surfaces as one event: renamed with from_id and to_id, or added under the final id when the entity was also created in the window. A vanished id that pairs with nothing surfaces as removed: an added row for an id no reader can fetch is the one shape the feed never serves. Without store (a bare replay) a rename row surfaces as updated under the new id. Batch events have no entity id and don’t contribute envelopes. The cursor is an RFC-3339 timestamp; the EMPTY_TREE_SHA sentinel and the empty string mean “from the beginning”. Any other non-parseable cursor refuses with the typed INVALID_TS_CURSOR: marker (lifted by the engine to the INVALID_CURSOR code): the folder ledger’s timestamps are compared lexically, and a mutation’s write_id — fixed-width hex minted from a nanosecond clock — sorts below every timestamp, so the old tolerant reading silently replayed the whole history to exactly the caller who confused the two. head echoes the latest timestamp seen, falling back to since.

Envelopes are id-only (title / entity_type are None); the engine wrapper enriches from its in-memory store. The store’s view the folder replay pairs renames with: for an id the store serves, its created_date as written in the frontmatter; None for an id it does not serve.