1pub mod store;
2pub use store::{Error, Store};
3
4use localtime::LocalTime;
5
6use crate::git;
7use crate::node::KnownAddress;
8use crate::prelude::NodeId;
9use crate::storage::{refs::RefsAt, ReadRepository, RemoteId};
10
11#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
13#[serde(rename_all = "camelCase")]
14#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
15pub struct SyncedAt {
16 #[cfg_attr(feature = "schemars", schemars(with = "crate::schemars_ext::git::Oid"))]
18 pub oid: git_ext::Oid,
19 #[serde(with = "crate::serde_ext::localtime::time")]
21 #[cfg_attr(
22 feature = "schemars",
23 schemars(with = "crate::schemars_ext::localtime::LocalDurationInSeconds")
24 )]
25 pub timestamp: LocalTime,
26}
27
28impl SyncedAt {
29 pub fn load<S: ReadRepository>(repo: &S, remote: RemoteId) -> Result<Self, git::ext::Error> {
31 let refs = RefsAt::new(repo, remote)?;
32 let oid = refs.at;
33
34 Self::new(oid, repo)
35 }
36
37 pub fn new<S: ReadRepository>(oid: git::ext::Oid, repo: &S) -> Result<Self, git::ext::Error> {
39 let timestamp = repo.commit(oid)?.time();
40 let timestamp = LocalTime::from_secs(timestamp.seconds() as u64);
41
42 Ok(Self { oid, timestamp })
43 }
44}
45
46impl Ord for SyncedAt {
47 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
48 self.timestamp.cmp(&other.timestamp)
49 }
50}
51
52impl PartialOrd for SyncedAt {
53 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
54 Some(self.cmp(other))
55 }
56}
57
58#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct SyncedSeed {
62 pub nid: NodeId,
64 pub addresses: Vec<KnownAddress>,
66 pub synced_at: SyncedAt,
68}