Skip to main content

compensating_event

Function compensating_event 

Source
pub fn compensating_event(
    original: &Event,
    prior_events: &[&Event],
    current_agent: &str,
    now: i64,
) -> Result<Event, UndoError>
Expand description

Generate a compensating event that reverses the effect of original.

prior_events must be all events for the same item that occurred before original, sorted in ascending chronological order. This context is required for:

  • item.move — to find the prior lifecycle state
  • item.update — to find the prior field value
  • item.delete — to reconstruct the original item.create data

The returned event has event_hash set to an empty string; callers are responsible for calling crate::event::writer::write_event to compute and fill the hash before appending to the shard.

§Errors

  • UndoError::GrowOnly — for item.comment, item.compact, item.snapshot, and item.redact.
  • UndoError::NoPriorState — when prior event context is needed but cannot be found (e.g. undo item.delete with no prior item.create).