projector.py 577 B

12345678910111213141516
  1. class ReferenceProjector:
  2. """Tiny transactional projection used to prove cursor/idempotency semantics."""
  3. def __init__(self) -> None:
  4. self.cursor = 0
  5. self.rows = {}
  6. async def load_cursor(self, application_ref, root_trace_id):
  7. del application_ref, root_trace_id
  8. return self.cursor
  9. async def project(self, event, expected_cursor):
  10. if expected_cursor != self.cursor:
  11. raise ValueError("stale projection cursor")
  12. self.rows.setdefault(event.event_key, event.payload)
  13. self.cursor = event.event_id