Coverage for object_streams/history/base.py: 100%
16 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-02 17:07 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-02 17:07 +0000
1"""Base protocols for history-backed source adapters."""
3from __future__ import annotations
5from dataclasses import dataclass
6from typing import Any
7from typing import Protocol
9from object_streams.events import SourceRef
12__all__ = ("HistoryAdapter", "HistoryRecordRef")
15@dataclass(frozen=True, slots=True)
16class HistoryRecordRef:
17 """Reference to an application history record that caused a stream event."""
19 model: str
20 pk: str
21 history_model: str
22 history_id: str
24 def as_source_ref(self) -> SourceRef:
25 return SourceRef(
26 model=self.model,
27 pk=self.pk,
28 history_model=self.history_model,
29 history_id=self.history_id,
30 )
33class HistoryAdapter(Protocol):
34 def source_ref_for_history(self, history_record: Any) -> SourceRef:
35 """Return a source reference for a history record."""