Module event_sourcing

Module event_sourcing 

Source
Expand description

Systematic Event Sourcing

Provides from_events() reconstruction for all core entities, extending the pattern established in agent_state.rs.

ยงDesign

The EventSourced trait defines a common interface for entities that can be reconstructed from their event history. Each entity implementation:

  1. Sorts events by timestamp to handle out-of-order delivery
  2. Filters for relevant event kinds using relevant_event_kinds()
  3. Applies events in order via apply_event() to build up state
  4. Returns None from from_events() if the creation event is missing

ยงEntities

  • Trajectory: TRAJECTORY_CREATED -> TRAJECTORY_UPDATED -> TRAJECTORY_COMPLETED/FAILED/DELETED
  • Scope: SCOPE_CREATED -> SCOPE_UPDATED -> SCOPE_CLOSED
  • Artifact: ARTIFACT_CREATED -> ARTIFACT_UPDATED -> ARTIFACT_DELETED
  • Note: NOTE_CREATED -> NOTE_UPDATED -> NOTE_DELETED

Traitsยง

EventSourced
Trait for entities that can be reconstructed from their event history.

Functionsยง

extract_i32 ๐Ÿ”’
Extract an i32 from a JSON payload field, with a default.
extract_id ๐Ÿ”’
Extract a typed ID from a JSON payload field.
extract_optional_i32 ๐Ÿ”’
Extract an i32 from a JSON payload field, returning None if absent.
extract_optional_string ๐Ÿ”’
Extract an optional string from a JSON payload field.
extract_string ๐Ÿ”’
Extract a string from a JSON payload field.
sorted_relevant_events ๐Ÿ”’
Sort events by timestamp (ascending), then filter for relevant kinds.
timestamp_to_datetime ๐Ÿ”’
Convert a microsecond timestamp to a chrono DateTime.