proto_blue_api/generated/com/atproto/server/
getSession.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 Output {
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub active: Option<bool>,
14 pub did: proto_blue_syntax::Did,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub did_doc: Option<serde_json::Value>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub email: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub email_auth_factor: Option<bool>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub email_confirmed: Option<bool>,
23 pub handle: proto_blue_syntax::Handle,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub status: Option<String>,
26}
27
28#[derive(Debug, thiserror::Error)]
30pub enum CallError {
31 #[error("{0}")]
32 Xrpc(proto_blue_xrpc::XrpcError),
33 #[error(transparent)]
34 Transport(#[from] proto_blue_xrpc::Error),
35 #[error(transparent)]
36 Json(#[from] serde_json::Error),
37}
38
39fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
40 CallError::Xrpc(err)
41}
42
43pub async fn call(
45 client: &proto_blue_xrpc::XrpcClient,
46 opts: Option<&proto_blue_xrpc::CallOptions>,
47) -> Result<Output, CallError> {
48 let response = match client
49 .query("com.atproto.server.getSession", None, 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) -> 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.query("com.atproto.server.getSession", move |ctx| {
73 let handler = handler.clone();
74 async move {
75 let out = handler(ctx).await?;
76 let value = serde_json::to_value(&out).map_err(|e| {
77 proto_blue_xrpc::XrpcServerError::new(
78 proto_blue_xrpc::ResponseType::InternalServerError,
79 format!("output serialize: {e}"),
80 )
81 })?;
82 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
83 }
84 })
85}