proto-blue-api 0.3.3

AT Protocol high-level API: agent, rich text, moderation, generated types
Documentation
// Generated by atproto-codegen. Do not edit.
//! Lexicon: com.atproto.identity.getRecommendedDidCredentials
#![allow(clippy::pedantic, clippy::nursery, clippy::all)]

use serde::{Deserialize, Serialize};

/// Describe the credentials that should be included in the DID doc of an account that is migrating to this service.
/// XRPC Query: com.atproto.identity.getRecommendedDidCredentials
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Output {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub also_known_as: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rotation_keys: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub services: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub verification_methods: Option<serde_json::Value>,
}

/// Errors a `call()` on this method can return.
#[derive(Debug, thiserror::Error)]
pub enum CallError {
    #[error("{0}")]
    Xrpc(proto_blue_xrpc::XrpcError),
    #[error(transparent)]
    Transport(#[from] proto_blue_xrpc::Error),
    #[error(transparent)]
    Json(#[from] serde_json::Error),
}

fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
    CallError::Xrpc(err)
}

/// Execute the query.
pub async fn call(
    client: &proto_blue_xrpc::XrpcClient,
    opts: Option<&proto_blue_xrpc::CallOptions>,
) -> Result<Output, CallError> {
    let response = match client
        .query(
            "com.atproto.identity.getRecommendedDidCredentials",
            None,
            opts,
        )
        .await
    {
        Ok(r) => r,
        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
        Err(e) => return Err(CallError::Transport(e)),
    };
    Ok(serde_json::from_value(response.data)?)
}

/// Register a typed handler for this method on an [`proto_blue_xrpc::XrpcServer`].
#[cfg(feature = "server")]
pub fn register<F, Fut>(
    server: proto_blue_xrpc::XrpcServer,
    handler: F,
) -> proto_blue_xrpc::XrpcServer
where
    F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
        + Send
        + 'static,
{
    let handler = std::sync::Arc::new(handler);
    server.query(
        "com.atproto.identity.getRecommendedDidCredentials",
        move |ctx| {
            let handler = handler.clone();
            async move {
                let out = handler(ctx).await?;
                let value = serde_json::to_value(&out).map_err(|e| {
                    proto_blue_xrpc::XrpcServerError::new(
                        proto_blue_xrpc::ResponseType::InternalServerError,
                        format!("output serialize: {e}"),
                    )
                })?;
                Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
            }
        },
    )
}