Skip to main content

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

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