atproto blogging
at main 366 lines 13 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: app.bsky.notification.declaration 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8/// A declaration of the user's choices related to notifications that can be produced by them. 9#[jacquard_derive::lexicon] 10#[derive( 11 serde::Serialize, 12 serde::Deserialize, 13 Debug, 14 Clone, 15 PartialEq, 16 Eq, 17 jacquard_derive::IntoStatic 18)] 19#[serde(rename_all = "camelCase")] 20pub struct Declaration<'a> { 21 /// A declaration of the user's preference for allowing activity subscriptions from other users. Absence of a record implies 'followers'. 22 #[serde(borrow)] 23 pub allow_subscriptions: DeclarationAllowSubscriptions<'a>, 24} 25 26pub mod declaration_state { 27 28 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 29 #[allow(unused)] 30 use ::core::marker::PhantomData; 31 mod sealed { 32 pub trait Sealed {} 33 } 34 /// State trait tracking which required fields have been set 35 pub trait State: sealed::Sealed { 36 type AllowSubscriptions; 37 } 38 /// Empty state - all required fields are unset 39 pub struct Empty(()); 40 impl sealed::Sealed for Empty {} 41 impl State for Empty { 42 type AllowSubscriptions = Unset; 43 } 44 ///State transition - sets the `allow_subscriptions` field to Set 45 pub struct SetAllowSubscriptions<S: State = Empty>(PhantomData<fn() -> S>); 46 impl<S: State> sealed::Sealed for SetAllowSubscriptions<S> {} 47 impl<S: State> State for SetAllowSubscriptions<S> { 48 type AllowSubscriptions = Set<members::allow_subscriptions>; 49 } 50 /// Marker types for field names 51 #[allow(non_camel_case_types)] 52 pub mod members { 53 ///Marker type for the `allow_subscriptions` field 54 pub struct allow_subscriptions(()); 55 } 56} 57 58/// Builder for constructing an instance of this type 59pub struct DeclarationBuilder<'a, S: declaration_state::State> { 60 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 61 __unsafe_private_named: (::core::option::Option<DeclarationAllowSubscriptions<'a>>,), 62 _phantom: ::core::marker::PhantomData<&'a ()>, 63} 64 65impl<'a> Declaration<'a> { 66 /// Create a new builder for this type 67 pub fn new() -> DeclarationBuilder<'a, declaration_state::Empty> { 68 DeclarationBuilder::new() 69 } 70} 71 72impl<'a> DeclarationBuilder<'a, declaration_state::Empty> { 73 /// Create a new builder with all fields unset 74 pub fn new() -> Self { 75 DeclarationBuilder { 76 _phantom_state: ::core::marker::PhantomData, 77 __unsafe_private_named: (None,), 78 _phantom: ::core::marker::PhantomData, 79 } 80 } 81} 82 83impl<'a, S> DeclarationBuilder<'a, S> 84where 85 S: declaration_state::State, 86 S::AllowSubscriptions: declaration_state::IsUnset, 87{ 88 /// Set the `allowSubscriptions` field (required) 89 pub fn allow_subscriptions( 90 mut self, 91 value: impl Into<DeclarationAllowSubscriptions<'a>>, 92 ) -> DeclarationBuilder<'a, declaration_state::SetAllowSubscriptions<S>> { 93 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into()); 94 DeclarationBuilder { 95 _phantom_state: ::core::marker::PhantomData, 96 __unsafe_private_named: self.__unsafe_private_named, 97 _phantom: ::core::marker::PhantomData, 98 } 99 } 100} 101 102impl<'a, S> DeclarationBuilder<'a, S> 103where 104 S: declaration_state::State, 105 S::AllowSubscriptions: declaration_state::IsSet, 106{ 107 /// Build the final struct 108 pub fn build(self) -> Declaration<'a> { 109 Declaration { 110 allow_subscriptions: self.__unsafe_private_named.0.unwrap(), 111 extra_data: Default::default(), 112 } 113 } 114 /// Build the final struct with custom extra_data 115 pub fn build_with_data( 116 self, 117 extra_data: std::collections::BTreeMap< 118 jacquard_common::smol_str::SmolStr, 119 jacquard_common::types::value::Data<'a>, 120 >, 121 ) -> Declaration<'a> { 122 Declaration { 123 allow_subscriptions: self.__unsafe_private_named.0.unwrap(), 124 extra_data: Some(extra_data), 125 } 126 } 127} 128 129impl<'a> Declaration<'a> { 130 pub fn uri( 131 uri: impl Into<jacquard_common::CowStr<'a>>, 132 ) -> Result< 133 jacquard_common::types::uri::RecordUri<'a, DeclarationRecord>, 134 jacquard_common::types::uri::UriError, 135 > { 136 jacquard_common::types::uri::RecordUri::try_from_uri( 137 jacquard_common::types::string::AtUri::new_cow(uri.into())?, 138 ) 139 } 140} 141 142/// A declaration of the user's preference for allowing activity subscriptions from other users. Absence of a record implies 'followers'. 143#[derive(Debug, Clone, PartialEq, Eq, Hash)] 144pub enum DeclarationAllowSubscriptions<'a> { 145 Followers, 146 Mutuals, 147 None, 148 Other(jacquard_common::CowStr<'a>), 149} 150 151impl<'a> DeclarationAllowSubscriptions<'a> { 152 pub fn as_str(&self) -> &str { 153 match self { 154 Self::Followers => "followers", 155 Self::Mutuals => "mutuals", 156 Self::None => "none", 157 Self::Other(s) => s.as_ref(), 158 } 159 } 160} 161 162impl<'a> From<&'a str> for DeclarationAllowSubscriptions<'a> { 163 fn from(s: &'a str) -> Self { 164 match s { 165 "followers" => Self::Followers, 166 "mutuals" => Self::Mutuals, 167 "none" => Self::None, 168 _ => Self::Other(jacquard_common::CowStr::from(s)), 169 } 170 } 171} 172 173impl<'a> From<String> for DeclarationAllowSubscriptions<'a> { 174 fn from(s: String) -> Self { 175 match s.as_str() { 176 "followers" => Self::Followers, 177 "mutuals" => Self::Mutuals, 178 "none" => Self::None, 179 _ => Self::Other(jacquard_common::CowStr::from(s)), 180 } 181 } 182} 183 184impl<'a> core::fmt::Display for DeclarationAllowSubscriptions<'a> { 185 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 186 write!(f, "{}", self.as_str()) 187 } 188} 189 190impl<'a> AsRef<str> for DeclarationAllowSubscriptions<'a> { 191 fn as_ref(&self) -> &str { 192 self.as_str() 193 } 194} 195 196impl<'a> serde::Serialize for DeclarationAllowSubscriptions<'a> { 197 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 198 where 199 S: serde::Serializer, 200 { 201 serializer.serialize_str(self.as_str()) 202 } 203} 204 205impl<'de, 'a> serde::Deserialize<'de> for DeclarationAllowSubscriptions<'a> 206where 207 'de: 'a, 208{ 209 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 210 where 211 D: serde::Deserializer<'de>, 212 { 213 let s = <&'de str>::deserialize(deserializer)?; 214 Ok(Self::from(s)) 215 } 216} 217 218impl<'a> Default for DeclarationAllowSubscriptions<'a> { 219 fn default() -> Self { 220 Self::Other(Default::default()) 221 } 222} 223 224impl jacquard_common::IntoStatic for DeclarationAllowSubscriptions<'_> { 225 type Output = DeclarationAllowSubscriptions<'static>; 226 fn into_static(self) -> Self::Output { 227 match self { 228 DeclarationAllowSubscriptions::Followers => { 229 DeclarationAllowSubscriptions::Followers 230 } 231 DeclarationAllowSubscriptions::Mutuals => { 232 DeclarationAllowSubscriptions::Mutuals 233 } 234 DeclarationAllowSubscriptions::None => DeclarationAllowSubscriptions::None, 235 DeclarationAllowSubscriptions::Other(v) => { 236 DeclarationAllowSubscriptions::Other(v.into_static()) 237 } 238 } 239 } 240} 241 242/// Typed wrapper for GetRecord response with this collection's record type. 243#[derive( 244 serde::Serialize, 245 serde::Deserialize, 246 Debug, 247 Clone, 248 PartialEq, 249 Eq, 250 jacquard_derive::IntoStatic 251)] 252#[serde(rename_all = "camelCase")] 253pub struct DeclarationGetRecordOutput<'a> { 254 #[serde(skip_serializing_if = "std::option::Option::is_none")] 255 #[serde(borrow)] 256 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>, 257 #[serde(borrow)] 258 pub uri: jacquard_common::types::string::AtUri<'a>, 259 #[serde(borrow)] 260 pub value: Declaration<'a>, 261} 262 263impl From<DeclarationGetRecordOutput<'_>> for Declaration<'_> { 264 fn from(output: DeclarationGetRecordOutput<'_>) -> Self { 265 use jacquard_common::IntoStatic; 266 output.value.into_static() 267 } 268} 269 270impl jacquard_common::types::collection::Collection for Declaration<'_> { 271 const NSID: &'static str = "app.bsky.notification.declaration"; 272 type Record = DeclarationRecord; 273} 274 275/// Marker type for deserializing records from this collection. 276#[derive(Debug, serde::Serialize, serde::Deserialize)] 277pub struct DeclarationRecord; 278impl jacquard_common::xrpc::XrpcResp for DeclarationRecord { 279 const NSID: &'static str = "app.bsky.notification.declaration"; 280 const ENCODING: &'static str = "application/json"; 281 type Output<'de> = DeclarationGetRecordOutput<'de>; 282 type Err<'de> = jacquard_common::types::collection::RecordError<'de>; 283} 284 285impl jacquard_common::types::collection::Collection for DeclarationRecord { 286 const NSID: &'static str = "app.bsky.notification.declaration"; 287 type Record = DeclarationRecord; 288} 289 290impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Declaration<'a> { 291 fn nsid() -> &'static str { 292 "app.bsky.notification.declaration" 293 } 294 fn def_name() -> &'static str { 295 "main" 296 } 297 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { 298 lexicon_doc_app_bsky_notification_declaration() 299 } 300 fn validate( 301 &self, 302 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { 303 Ok(()) 304 } 305} 306 307fn lexicon_doc_app_bsky_notification_declaration() -> ::jacquard_lexicon::lexicon::LexiconDoc< 308 'static, 309> { 310 ::jacquard_lexicon::lexicon::LexiconDoc { 311 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, 312 id: ::jacquard_common::CowStr::new_static("app.bsky.notification.declaration"), 313 revision: None, 314 description: None, 315 defs: { 316 let mut map = ::alloc::collections::BTreeMap::new(); 317 map.insert( 318 ::jacquard_common::smol_str::SmolStr::new_static("main"), 319 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { 320 description: Some( 321 ::jacquard_common::CowStr::new_static( 322 "A declaration of the user's choices related to notifications that can be produced by them.", 323 ), 324 ), 325 key: Some(::jacquard_common::CowStr::new_static("literal:self")), 326 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { 327 description: None, 328 required: Some( 329 vec![ 330 ::jacquard_common::smol_str::SmolStr::new_static("allowSubscriptions") 331 ], 332 ), 333 nullable: None, 334 properties: { 335 #[allow(unused_mut)] 336 let mut map = ::alloc::collections::BTreeMap::new(); 337 map.insert( 338 ::jacquard_common::smol_str::SmolStr::new_static( 339 "allowSubscriptions", 340 ), 341 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { 342 description: Some( 343 ::jacquard_common::CowStr::new_static( 344 "A declaration of the user's preference for allowing activity subscriptions from other users. Absence of a record implies 'followers'.", 345 ), 346 ), 347 format: None, 348 default: None, 349 min_length: None, 350 max_length: None, 351 min_graphemes: None, 352 max_graphemes: None, 353 r#enum: None, 354 r#const: None, 355 known_values: None, 356 }), 357 ); 358 map 359 }, 360 }), 361 }), 362 ); 363 map 364 }, 365 } 366}