proto_blue_api/generated/com/atproto/sync/
getCheckout.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, thiserror::Error)]
16pub enum CallError {
17 #[error("{0}")]
18 Xrpc(proto_blue_xrpc::XrpcError),
19 #[error(transparent)]
20 Transport(#[from] proto_blue_xrpc::Error),
21 #[error(transparent)]
22 Json(#[from] serde_json::Error),
23}
24
25fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
26 CallError::Xrpc(err)
27}
28
29fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
30 let mut qp = proto_blue_xrpc::QueryParams::new();
31 { let v = &p.did; qp.insert("did".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
32 qp
33}
34
35pub async fn call(
37 client: &proto_blue_xrpc::XrpcClient,
38 params: Option<&Params>,
39 opts: Option<&proto_blue_xrpc::CallOptions>,
40) -> Result<serde_json::Value, CallError> {
41 let qp = params.map(to_query_params);
42 let response = match client.query("com.atproto.sync.getCheckout", qp.as_ref(), opts).await {
43 Ok(r) => r,
44 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
45 Err(e) => return Err(CallError::Transport(e)),
46 };
47 Ok(response.data)
48}
49
50#[cfg(feature = "server")]
52pub fn register<F, Fut>(
53server: proto_blue_xrpc::XrpcServer,
54handler: F,
55) -> proto_blue_xrpc::XrpcServer
56where
57 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
58 Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
59{
60 let handler = std::sync::Arc::new(handler);
61 server.query("com.atproto.sync.getCheckout", move |ctx| {
62 let handler = handler.clone();
63 async move {
64 let params = params_from_ctx(&ctx);
65 let out = handler(ctx, params).await?;
66 Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
67 }
68 })
69}
70
71#[cfg(feature = "server")]
72fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
73 Some(Params {
77 did: (ctx.params.get("did").cloned())?,
78 })
79}
80