Skip to main content

proto_blue_api/generated/app/bsky/graph/
getStarterPack.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: app.bsky.graph.getStarterPack
3#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7/// Gets a view of a starter pack.
8/// XRPC Query: app.bsky.graph.getStarterPack
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Params {
12    pub starter_pack: proto_blue_syntax::AtUri,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Output {
18    pub starter_pack: crate::app::bsky::graph::defs::StarterPackView,
19}
20
21/// Errors a `call()` on this method can return.
22#[derive(Debug, thiserror::Error)]
23pub enum CallError {
24    #[error("{0}")]
25    Xrpc(proto_blue_xrpc::XrpcError),
26    #[error(transparent)]
27    Transport(#[from] proto_blue_xrpc::Error),
28    #[error(transparent)]
29    Json(#[from] serde_json::Error),
30}
31
32fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
33    CallError::Xrpc(err)
34}
35
36fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
37    let mut qp = proto_blue_xrpc::QueryParams::new();
38    {
39        let v = &p.starter_pack;
40        qp.insert(
41            "starterPack".to_string(),
42            proto_blue_xrpc::QueryValue::String(v.to_string()),
43        );
44    }
45    qp
46}
47
48/// Execute the query.
49pub async fn call(
50    client: &proto_blue_xrpc::XrpcClient,
51    params: Option<&Params>,
52    opts: Option<&proto_blue_xrpc::CallOptions>,
53) -> Result<Output, CallError> {
54    let qp = params.map(to_query_params);
55    let response = match client
56        .query("app.bsky.graph.getStarterPack", qp.as_ref(), opts)
57        .await
58    {
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 [`proto_blue_xrpc::XrpcServer`].
67#[cfg(feature = "server")]
68pub fn register<F, Fut>(
69    server: proto_blue_xrpc::XrpcServer,
70    handler: 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>>
75        + Send
76        + 'static,
77{
78    let handler = std::sync::Arc::new(handler);
79    server.query("app.bsky.graph.getStarterPack", move |ctx| {
80        let handler = handler.clone();
81        async move {
82            let params = params_from_ctx(&ctx);
83            let out = handler(ctx, params).await?;
84            let value = serde_json::to_value(&out).map_err(|e| {
85                proto_blue_xrpc::XrpcServerError::new(
86                    proto_blue_xrpc::ResponseType::InternalServerError,
87                    format!("output serialize: {e}"),
88                )
89            })?;
90            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
91        }
92    })
93}
94
95#[cfg(feature = "server")]
96fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
97    // Always construct a `Params` — required fields are
98    // validated upstream by the lexicon validator when enabled;
99    // missing values surface as runtime errors from the handler.
100    Some(Params {
101        starter_pack: (ctx
102            .params
103            .get("starterPack")
104            .and_then(|v| proto_blue_syntax::AtUri::new(v).ok()))?,
105    })
106}