Skip to main content

proto_blue_api/generated/app/bsky/contact/
removeData.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: app.bsky.contact.removeData
3
4use serde::{Deserialize, Serialize};
5
6/// Removes all stored hashes used for contact matching, existing matches, and sync status. Requires authentication.
7/// XRPC Procedure: app.bsky.contact.removeData
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct Output {
16}
17
18/// Errors a `call()` on this method can return.
19#[derive(Debug, thiserror::Error)]
20pub enum CallError {
21    #[error("InvalidDid")]
22    InvalidDid,
23    #[error("InternalError")]
24    InternalError,
25    #[error("{0}")]
26    Xrpc(proto_blue_xrpc::XrpcError),
27    #[error(transparent)]
28    Transport(#[from] proto_blue_xrpc::Error),
29    #[error(transparent)]
30    Json(#[from] serde_json::Error),
31}
32
33fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
34    match err.error.as_deref() {
35        Some("InvalidDid") => CallError::InvalidDid,
36        Some("InternalError") => CallError::InternalError,
37        _ => CallError::Xrpc(err),
38    }
39}
40
41/// Execute the procedure.
42pub async fn call(
43    client: &proto_blue_xrpc::XrpcClient,
44    input: &Input,
45    opts: Option<&proto_blue_xrpc::CallOptions>,
46) -> Result<Output, CallError> {
47    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
48    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
49    let response = match client.procedure("app.bsky.contact.removeData", qp_ref, Some(body), opts).await {
50        Ok(r) => r,
51        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
52        Err(e) => return Err(CallError::Transport(e)),
53    };
54    Ok(serde_json::from_value(response.data)?)
55}
56
57/// Register a typed handler for this procedure on an [`XrpcServer`].
58#[cfg(feature = "server")]
59pub fn register<F, Fut>(
60server: proto_blue_xrpc::XrpcServer,
61handler: F,
62) -> proto_blue_xrpc::XrpcServer
63where
64    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
65    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
66{
67    let handler = std::sync::Arc::new(handler);
68    server.procedure("app.bsky.contact.removeData", move |ctx| {
69        let handler = handler.clone();
70        async move {
71            let input = match ctx.json_body()? {
72                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
73                None => None,
74            };
75            let out = handler(ctx, input).await?;
76            let value = serde_json::to_value(&out)
77                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
78            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
79        }
80    })
81}
82