Skip to main content

origin_sync/
target.rs

1use origin_domain::{AccountId, ConnectorId};
2use origin_storage::namespace;
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6/// One thing that gets synchronised: a kind of data, for one account, at one connector.
7///
8/// `name` is the product's own label — `notifications`, `projects`, `traffic`. Every
9/// target is account-scoped (ADR-0016), which is also what lets its state disappear
10/// with the account.
11#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
12#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
13pub struct SyncTarget {
14    pub connector: ConnectorId,
15    pub account: AccountId,
16    pub name: String,
17}
18
19impl SyncTarget {
20    pub fn new(connector: ConnectorId, account: AccountId, name: impl Into<String>) -> Self {
21        Self {
22            connector,
23            account,
24            name: name.into(),
25        }
26    }
27
28    /// Storage namespace holding this target's sync state.
29    ///
30    /// Under the account prefix, so disconnecting the account removes it (ADR-0019).
31    pub(crate) fn namespace(&self) -> String {
32        namespace::account(&self.connector, &self.account, "sync")
33    }
34}
35
36impl fmt::Display for SyncTarget {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(f, "{}/{}/{}", self.connector, self.account, self.name)
39    }
40}