proto_blue_api/generated/com/atproto/sync/
getRepoStatus.rs1use serde::{Deserialize, Serialize};
5
6#[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#[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
51pub 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#[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 Some(Params {
95 did: (ctx.params.get("did").cloned())?,
96 })
97}
98