mushroomdb 0.6.9

Embedded graph database with Cypher queries, rule triggers, and Arrow export
Documentation
use core_storage::Value;

// ── Edge history types ────────────────────────────────────────────────────────

/// Result wrapper for history queries. Carries the event list, the total
/// number of WAL commits, and the oldest commit still reachable.
///
/// Valid commit indices for `was_linked` are `horizon..total_commits`. Any index
/// outside that range is unreachable and `was_linked` will return
/// `CommitOutOfRange`.
#[derive(Debug)]
pub struct HistoryResult<T> {
    pub items: Vec<T>,
    /// Exclusive upper bound for valid commit indices.
    /// The horizon window is `[horizon, total_commits)`.
    pub total_commits: u64,
    /// The oldest commit index still reachable (the WAL horizon floor). `0`
    /// when nothing has been pruned; when `> 0`, events before this commit
    /// were pruned and are not part of `items`.
    pub horizon: u64,
}

/// A single add-or-retract event for an edge between two nodes.
#[derive(Debug, PartialEq)]
pub struct EdgeHistoryEvent {
    pub edge_type: String,
    /// 0-based WAL frame index of the commit that produced this event.
    pub commit: u64,
    pub event: EdgeEvent,
    /// `Some(rule_name)` for rule-derived edges, `None` for manually written
    /// edges. Derived edges are represented by `DerivedEdgeAdded` /
    /// `DerivedEdgeRetracted` WAL markers (discriminants 18/19) written by
    /// `log_then_apply_with` after each rule-firing mutation; see
    /// `derived_edge_state_records_not_wal_logged_markers_are` in rules.rs.
    pub rule: Option<String>,
}

/// Whether an edge was added or retracted.
#[derive(Debug, PartialEq)]
pub enum EdgeEvent {
    Added,
    Retracted,
}

// ── Node history types ────────────────────────────────────────────────────────

/// A single change event in a node's history, paired with the WAL commit that produced it.
///
/// ## Horizon
///
/// History reaches back only to the last WAL-truncating snapshot, exactly like `open_at`.
/// Snapshots written with `keep_wal: true` preserve deeper history. This is the honest,
/// zero-cost contract; a durable history log is out of scope.
///
/// ## Derived edges
///
/// Rule-created (derived) edges appear in edge history via `DerivedEdgeAdded` /
/// `DerivedEdgeRetracted` WAL markers; they do not appear in node history.
#[derive(Debug, PartialEq)]
pub struct HistoryEntry {
    /// 0-based WAL frame index of the commit that produced this change.
    pub commit: u64,
    pub change: HistoryChange,
}

#[derive(Debug, PartialEq)]
pub enum HistoryChange {
    NodeInserted {
        label: String,
    },
    PropSet {
        field: String,
        value: Value,
    },
    PropRemoved {
        field: String,
    },
    /// An edge involving this node was added.
    ///
    /// `outgoing` is `true` if this node is the source, `false` if it is the destination.
    ///
    /// Self-edges (src == dst == this node) produce a single entry with `outgoing: true`.
    EdgeAdded {
        edge_type: String,
        other: String,
        outgoing: bool,
    },
    /// An edge involving this node was removed.
    ///
    /// `outgoing` is `true` if this node is the source, `false` if it is the destination.
    ///
    /// Self-edges (src == dst == this node) produce a single entry with `outgoing: true`.
    EdgeRemoved {
        edge_type: String,
        other: String,
        outgoing: bool,
    },
    NodeDeleted,
}