#![allow(missing_docs)]
use mempill_types::{
AgentId, Claim, ClaimEdge, ClaimRef, LedgerEntry, TransactionTime, ValidityAssertion,
};
pub trait Txn: Send + 'static {
fn agent_id(&self) -> &AgentId;
}
pub trait PersistencePort: Send + Sync + 'static {
type Transaction: Txn;
type Error: std::error::Error + Send + Sync + 'static;
fn begin_atomic(&self, agent_id: &AgentId) -> Result<Self::Transaction, Self::Error>;
fn append_claim(
&self,
txn: &mut Self::Transaction,
claim: &Claim,
) -> Result<ClaimRef, Self::Error>;
fn append_validity_assertion(
&self,
txn: &mut Self::Transaction,
assertion: &ValidityAssertion,
) -> Result<(), Self::Error>;
fn append_ledger_entry(
&self,
txn: &mut Self::Transaction,
entry: &LedgerEntry,
) -> Result<(), Self::Error>;
fn append_claim_edge(
&self,
txn: &mut Self::Transaction,
edge: &ClaimEdge,
) -> Result<(), Self::Error>;
fn commit(&self, txn: Self::Transaction) -> Result<(), Self::Error>;
fn rollback(&self, txn: Self::Transaction) -> Result<(), Self::Error>;
fn load_subject_line(
&self,
agent_id: &AgentId,
subject: &str,
predicate: &str,
) -> Result<Vec<Claim>, Self::Error>;
fn load_claim(
&self,
agent_id: &AgentId,
claim_ref: &ClaimRef,
) -> Result<Option<Claim>, Self::Error>;
fn load_validity_assertions_for(
&self,
agent_id: &AgentId,
claim_ref: &ClaimRef,
) -> Result<Vec<ValidityAssertion>, Self::Error>;
fn load_ledger(
&self,
agent_id: &AgentId,
from: Option<&TransactionTime>,
limit: usize,
) -> Result<Vec<LedgerEntry>, Self::Error>;
fn load_ledger_for_claims(
&self,
agent_id: &AgentId,
claim_refs: &[ClaimRef],
) -> Result<Vec<LedgerEntry>, Self::Error>;
fn load_edges_for(
&self,
agent_id: &AgentId,
claim_ref: &ClaimRef,
) -> Result<Vec<ClaimEdge>, Self::Error>;
fn load_injected_claims(
&self,
agent_id: &AgentId,
) -> Result<Vec<ClaimRef>, Self::Error>;
fn load_lineage(
&self,
agent_id: &AgentId,
claim_ref: &ClaimRef,
) -> Result<Vec<ClaimEdge>, Self::Error>;
fn requires_global_write_serialization(&self) -> bool {
true
}
}