use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use cid::Cid;
use knot_types::{MstKey, OwnerDid, RecordBody, RepoDid, RepoName};
use crate::plan::repo_token;
use crate::store::RepoStore;
pub mod chain;
pub mod cob_state;
pub mod crawl;
pub mod pds;
pub mod pool;
#[cfg(test)]
pub(crate) mod tests;
#[cfg(test)]
pub use crate::xrpc::{ATPROTO_DIR, emit};
pub use crate::xrpc::{emit_with, locations, reroute};
pub use chain::{chain_head, created_at, published_spindle, unix_now};
pub(crate) use chain::{record_file, short_hash, write_json};
pub(crate) use cob_state::Version;
#[cfg(test)]
pub use cob_state::record_cob_state;
pub(crate) use cob_state::{SyncedIndex, cob_state_synced, cob_tips};
pub use cob_state::{cob_state, cob_state_dirs, kept_cob_states};
#[cfg(test)]
pub(crate) use pool::APPLIED;
pub(crate) use pool::{POOLED, Pool, Prior, settle_at};
pub use pool::{kept_served, last_seal, served_dirs, settle};
pub struct RepoSource {
pub did: RepoDid,
pub owner: OwnerDid,
pub name: RepoName,
pub export_dir: PathBuf,
pub cobs: Option<CobState>,
pub served: RepoStore,
pub verify: bool,
}
#[derive(Default)]
pub struct CobState {
/// erased and contested cobs are left out, and an unreadable body is `None`.
pub records: BTreeMap<MstKey, Option<RecordBody>>,
/// erased cobs are in here too, unlike `records`.
pub versions: BTreeMap<String, Vec<Version>>,
}
pub(crate) struct ChainState {
pub(crate) did: RepoDid,
pub(crate) commit: Cid,
pub(crate) rev: String,
pub(crate) collections: Vec<String>,
pub(crate) records: Vec<ServedRecord>,
pub(crate) versions: BTreeMap<String, Vec<Version>>,
pub(crate) car: Vec<u8>,
}
pub struct SettledRepo {
pub did: RepoDid,
pub commit: Cid,
pub rev: String,
pub entry_key: String,
pub(crate) pool: PathBuf,
pub blobs: BTreeSet<String>,
pub(crate) rows: crate::xrpc::Rows,
}
#[derive(serde::Serialize, serde::Deserialize)]
pub(crate) struct ServedRecord {
pub(crate) collection: String,
pub(crate) rkey: String,
pub(crate) answer: serde_json::Value,
}
impl SettledRepo {
pub(crate) fn dir_name(&self) -> String {
repo_token(self.did.as_str())
}
}
impl ChainState {
pub(crate) fn dir_name(&self) -> String {
repo_token(self.did.as_str())
}
}