jacquard_api/com_atproto/server/
get_session.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::deps::smol_str::SmolStr;
14use jacquard_common::types::string::{Did, Handle};
15use jacquard_common::types::value::Data;
16use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
17use jacquard_derive::IntoStatic;
18use serde::{Deserialize, Serialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(
22 rename_all = "camelCase",
23 bound(deserialize = "S: Deserialize<'de> + BosStr")
24)]
25pub struct GetSessionOutput<S: BosStr = DefaultStr> {
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub active: Option<bool>,
28 pub did: Did<S>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub did_doc: Option<Data<S>>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub email: Option<S>,
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub email_auth_factor: Option<bool>,
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub email_confirmed: Option<bool>,
37 pub handle: Handle<S>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 pub status: Option<GetSessionOutputStatus<S>>,
41 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
42 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq, Hash)]
48pub enum GetSessionOutputStatus<S: BosStr = DefaultStr> {
49 Takendown,
50 Suspended,
51 Deactivated,
52 Other(S),
53}
54
55impl<S: BosStr> GetSessionOutputStatus<S> {
56 pub fn as_str(&self) -> &str {
57 match self {
58 Self::Takendown => "takendown",
59 Self::Suspended => "suspended",
60 Self::Deactivated => "deactivated",
61 Self::Other(s) => s.as_ref(),
62 }
63 }
64 pub fn from_value(s: S) -> Self {
66 match s.as_ref() {
67 "takendown" => Self::Takendown,
68 "suspended" => Self::Suspended,
69 "deactivated" => Self::Deactivated,
70 _ => Self::Other(s),
71 }
72 }
73}
74
75impl<S: BosStr> core::fmt::Display for GetSessionOutputStatus<S> {
76 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 write!(f, "{}", self.as_str())
78 }
79}
80
81impl<S: BosStr> AsRef<str> for GetSessionOutputStatus<S> {
82 fn as_ref(&self) -> &str {
83 self.as_str()
84 }
85}
86
87impl<S: BosStr> Serialize for GetSessionOutputStatus<S> {
88 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
89 where
90 Ser: serde::Serializer,
91 {
92 serializer.serialize_str(self.as_str())
93 }
94}
95
96impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for GetSessionOutputStatus<S> {
97 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
98 where
99 D: serde::Deserializer<'de>,
100 {
101 let s = S::deserialize(deserializer)?;
102 Ok(Self::from_value(s))
103 }
104}
105
106impl<S: BosStr + Default> Default for GetSessionOutputStatus<S> {
107 fn default() -> Self {
108 Self::Other(Default::default())
109 }
110}
111
112impl<S: BosStr> jacquard_common::IntoStatic for GetSessionOutputStatus<S>
113where
114 S: BosStr + jacquard_common::IntoStatic,
115 S::Output: BosStr,
116{
117 type Output = GetSessionOutputStatus<S::Output>;
118 fn into_static(self) -> Self::Output {
119 match self {
120 GetSessionOutputStatus::Takendown => GetSessionOutputStatus::Takendown,
121 GetSessionOutputStatus::Suspended => GetSessionOutputStatus::Suspended,
122 GetSessionOutputStatus::Deactivated => GetSessionOutputStatus::Deactivated,
123 GetSessionOutputStatus::Other(v) => GetSessionOutputStatus::Other(v.into_static()),
124 }
125 }
126}
127
128#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
133pub struct GetSession;
134pub struct GetSessionResponse;
138impl jacquard_common::xrpc::XrpcResp for GetSessionResponse {
139 const NSID: &'static str = "com.atproto.server.getSession";
140 const ENCODING: &'static str = "application/json";
141 type Output<S: BosStr> = GetSessionOutput<S>;
142 type Err = jacquard_common::xrpc::GenericError;
143}
144
145impl jacquard_common::xrpc::XrpcRequest for GetSession {
146 const NSID: &'static str = "com.atproto.server.getSession";
147 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
148 type Response = GetSessionResponse;
149}
150
151pub struct GetSessionRequest;
155impl jacquard_common::xrpc::XrpcEndpoint for GetSessionRequest {
156 const PATH: &'static str = "/xrpc/com.atproto.server.getSession";
157 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
158 type Request<S: BosStr> = GetSession;
159 type Response = GetSessionResponse;
160}