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