proto_blue_api/generated/app/bsky/contact/
removeData.rs1#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Input {}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct Output {}
16
17#[derive(Debug, thiserror::Error)]
19pub enum CallError {
20 #[error("InvalidDid")]
21 InvalidDid,
22 #[error("InternalError")]
23 InternalError,
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 match err.error.as_deref() {
34 Some("InvalidDid") => CallError::InvalidDid,
35 Some("InternalError") => CallError::InternalError,
36 _ => CallError::Xrpc(err),
37 }
38}
39
40pub async fn call(
42 client: &proto_blue_xrpc::XrpcClient,
43 input: &Input,
44 opts: Option<&proto_blue_xrpc::CallOptions>,
45) -> Result<Output, CallError> {
46 let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
47 let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
48 let response = match client
49 .procedure("app.bsky.contact.removeData", qp_ref, Some(body), opts)
50 .await
51 {
52 Ok(r) => r,
53 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
54 Err(e) => return Err(CallError::Transport(e)),
55 };
56 Ok(serde_json::from_value(response.data)?)
57}
58
59#[cfg(feature = "server")]
61pub fn register<F, Fut>(
62 server: proto_blue_xrpc::XrpcServer,
63 handler: F,
64) -> proto_blue_xrpc::XrpcServer
65where
66 F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
67 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
68 + Send
69 + 'static,
70{
71 let handler = std::sync::Arc::new(handler);
72 server.procedure("app.bsky.contact.removeData", move |ctx| {
73 let handler = handler.clone();
74 async move {
75 let input = match ctx.json_body()? {
76 Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
77 proto_blue_xrpc::XrpcServerError::new(
78 proto_blue_xrpc::ResponseType::InvalidRequest,
79 format!("input deserialize: {e}"),
80 )
81 })?),
82 None => None,
83 };
84 let out = handler(ctx, input).await?;
85 let value = serde_json::to_value(&out).map_err(|e| {
86 proto_blue_xrpc::XrpcServerError::new(
87 proto_blue_xrpc::ResponseType::InternalServerError,
88 format!("output serialize: {e}"),
89 )
90 })?;
91 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
92 }
93 })
94}