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