pub struct Ledger {
pub paths: EddaPaths,
/* private fields */
}Expand description
The append-only event ledger (SQLite backend).
Fields§
§paths: EddaPathsImplementations§
Source§impl Ledger
impl Ledger
Sourcepub fn open(repo_root: impl Into<PathBuf>) -> Result<Self>
pub fn open(repo_root: impl Into<PathBuf>) -> Result<Self>
Open an existing workspace. Fails if .edda/ does not exist.
Sourcepub fn open_or_init(repo_root: impl Into<PathBuf>) -> Result<Self>
pub fn open_or_init(repo_root: impl Into<PathBuf>) -> Result<Self>
Open a workspace, auto-initializing .edda/ if missing.
Use this for read-path consumers (e.g. edda watch) that should
work without requiring the user to run edda init first.
This is a lightweight init — it only creates the ledger directory
layout and SQLite DB. Config files (policy.yaml, actors.yaml) and
bridge hooks are NOT created; those require edda init.
Sourcepub fn ensure_initialized(repo_root: impl Into<PathBuf>) -> Result<()>
pub fn ensure_initialized(repo_root: impl Into<PathBuf>) -> Result<()>
Ensure .edda/ and ledger exist, without returning a Ledger handle.
Use this when you only need the side effect (workspace creation) and will open the ledger separately later.
Sourcepub fn open_path(repo_root: &Path) -> Result<Self>
pub fn open_path(repo_root: &Path) -> Result<Self>
Convenience: open from a Path ref (avoids Into
Sourcepub fn head_branch(&self) -> Result<String>
pub fn head_branch(&self) -> Result<String>
Read the current HEAD branch name.
Sourcepub fn set_head_branch(&self, name: &str) -> Result<()>
pub fn set_head_branch(&self, name: &str) -> Result<()>
Write the HEAD branch name.
Sourcepub fn append_event(&self, event: &Event) -> Result<()>
pub fn append_event(&self, event: &Event) -> Result<()>
Append an event to the ledger. Append-only (CONTRACT LEDGER-02).
Sourcepub fn last_event_hash(&self) -> Result<Option<String>>
pub fn last_event_hash(&self) -> Result<Option<String>>
Get the hash of the last event, or None if the ledger is empty.
Sourcepub fn iter_events(&self) -> Result<Vec<Event>>
pub fn iter_events(&self) -> Result<Vec<Event>>
Read all events in the ledger.
Sourcepub fn branches_json(&self) -> Result<Value>
pub fn branches_json(&self) -> Result<Value>
Read branches.json content.
Sourcepub fn set_branches_json(&self, value: &Value) -> Result<()>
pub fn set_branches_json(&self, value: &Value) -> Result<()>
Write branches.json content.
Sourcepub fn active_decisions(
&self,
domain: Option<&str>,
key_pattern: Option<&str>,
) -> Result<Vec<DecisionRow>>
pub fn active_decisions( &self, domain: Option<&str>, key_pattern: Option<&str>, ) -> Result<Vec<DecisionRow>>
Query active decisions, optionally filtered by domain or key pattern.
Sourcepub fn decision_timeline(&self, key: &str) -> Result<Vec<DecisionRow>>
pub fn decision_timeline(&self, key: &str) -> Result<Vec<DecisionRow>>
All decisions for a key (active + superseded), ordered by time.
Sourcepub fn domain_timeline(&self, domain: &str) -> Result<Vec<DecisionRow>>
pub fn domain_timeline(&self, domain: &str) -> Result<Vec<DecisionRow>>
All decisions for a domain (active + superseded), ordered by time.
Sourcepub fn list_domains(&self) -> Result<Vec<String>>
pub fn list_domains(&self) -> Result<Vec<String>>
Distinct domain values from active decisions.
Sourcepub fn find_active_decision(
&self,
branch: &str,
key: &str,
) -> Result<Option<DecisionRow>>
pub fn find_active_decision( &self, branch: &str, key: &str, ) -> Result<Option<DecisionRow>>
Find the active decision for a specific key on a branch.