Skip to main content

proto_blue_api/generated/com/atproto/sync/
getRepoStatus.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.sync.getRepoStatus
3
4use serde::{Deserialize, Serialize};
5
6/// Get the hosting status for a repository, on this server. Expected to be implemented by PDS and Relay.
7/// XRPC Query: com.atproto.sync.getRepoStatus
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11    pub did: String,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Output {
17    pub active: bool,
18    pub did: String,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub rev: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub status: Option<String>,
23}
24
25/// Errors a `call()` on this method can return.
26#[derive(Debug, thiserror::Error)]
27pub enum CallError {
28    #[error("RepoNotFound")]
29    RepoNotFound,
30    #[error("{0}")]
31    Xrpc(proto_blue_xrpc::XrpcError),
32    #[error(transparent)]
33    Transport(#[from] proto_blue_xrpc::Error),
34    #[error(transparent)]
35    Json(#[from] serde_json::Error),
36}
37
38fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
39    match err.error.as_deref() {
40        Some("RepoNotFound") => CallError::RepoNotFound,
41        _ => CallError::Xrpc(err),
42    }
43}
44
45fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
46    let mut qp = proto_blue_xrpc::QueryParams::new();
47    { let v = &p.did; qp.insert("did".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
48    qp
49}
50
51/// Execute the query.
52pub async fn call(
53    client: &proto_blue_xrpc::XrpcClient,
54    params: Option<&Params>,
55    opts: Option<&proto_blue_xrpc::CallOptions>,
56) -> Result<Output, CallError> {
57    let qp = params.map(to_query_params);
58    let response = match client.query("com.atproto.sync.getRepoStatus", qp.as_ref(), opts).await {
59        Ok(r) => r,
60        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
61        Err(e) => return Err(CallError::Transport(e)),
62    };
63    Ok(serde_json::from_value(response.data)?)
64}
65
66/// Register a typed handler for this method on an [`XrpcServer`].
67#[cfg(feature = "server")]
68pub fn register<F, Fut>(
69server: proto_blue_xrpc::XrpcServer,
70handler: F,
71) -> proto_blue_xrpc::XrpcServer
72where
73    F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
74    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
75{
76    let handler = std::sync::Arc::new(handler);
77    server.query("com.atproto.sync.getRepoStatus", move |ctx| {
78        let handler = handler.clone();
79        async move {
80            let params = params_from_ctx(&ctx);
81            let out = handler(ctx, params).await?;
82            let value = serde_json::to_value(&out)
83                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
84            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
85        }
86    })
87}
88
89#[cfg(feature = "server")]
90fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
91    // Always construct a `Params` — required fields are
92    // validated upstream by the lexicon validator when enabled;
93    // missing values surface as runtime errors from the handler.
94    Some(Params {
95        did: (ctx.params.get("did").cloned())?,
96    })
97}
98