Skip to content
docsv0.1.0

FileEventStore

Append-only JSONL log of {@see Event}s: one JSON object per line, one line per event, never rewritten or truncated. Zero DB — a flat file is the entire durability story. `nextSeq()` and `replay()` both derive their answer from the file itself rather than from an in-memory counter, on purpose: a fresh `FileEventStore` pointed at the same path — a different process, a different request — must agree with every other instance about both "what happened" and "what comes next", and the file is the only thing every instance shares.

FileEventStore::__construct()

public function __construct(string $path):

Parameters

Parameters of __construct()
NameTypeDescription
$pathstringpath to the JSONL log file; its directory is created on first append if missing

FileEventStore::append()

public function append(Milpa\EventStore\Event $event): void

Appends `$event` as one JSON line, under an exclusive lock so concurrent appenders cannot interleave partial lines.

Parameters

Parameters of append()
NameTypeDescription
$eventMilpa\EventStore\Event

FileEventStore::replay()

public function replay(string $streamId): array

All events belonging to `$streamId`, in ascending `seq` order.

Parameters

Parameters of replay()
NameTypeDescription
$streamIdstring

FileEventStore::nextSeq()

public function nextSeq(): int

The next `seq` to assign, one past the highest `seq` currently in the store (across every stream) — `1` for an empty or missing log.

FileEventStore::streams()

public function streams(): array

Every distinct stream id present in the store, in the order each first appears (ascending `seq` of its first event).