atproto blogging
at main 445 lines 17 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: sh.weaver.edit.diff 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8/// An edit record for a notebook. 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 Diff<'a> { 21 #[serde(skip_serializing_if = "std::option::Option::is_none")] 22 pub created_at: std::option::Option<jacquard_common::types::string::Datetime>, 23 #[serde(borrow)] 24 pub doc: crate::sh_weaver::edit::DocRef<'a>, 25 /// An inline diff for for small edit batches. Either this or snapshot must be present to be valid 26 #[serde(skip_serializing_if = "std::option::Option::is_none")] 27 #[serde(default, with = "jacquard_common::opt_serde_bytes_helper")] 28 pub inline_diff: std::option::Option<bytes::Bytes>, 29 #[serde(skip_serializing_if = "std::option::Option::is_none")] 30 #[serde(borrow)] 31 pub prev: std::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 32 #[serde(borrow)] 33 pub root: crate::com_atproto::repo::strong_ref::StrongRef<'a>, 34 /// Diff from previous diff. Either this or inlineDiff must be present to be valid 35 #[serde(skip_serializing_if = "std::option::Option::is_none")] 36 #[serde(borrow)] 37 pub snapshot: std::option::Option<jacquard_common::types::blob::BlobRef<'a>>, 38} 39 40pub mod diff_state { 41 42 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 43 #[allow(unused)] 44 use ::core::marker::PhantomData; 45 mod sealed { 46 pub trait Sealed {} 47 } 48 /// State trait tracking which required fields have been set 49 pub trait State: sealed::Sealed { 50 type Doc; 51 type Root; 52 } 53 /// Empty state - all required fields are unset 54 pub struct Empty(()); 55 impl sealed::Sealed for Empty {} 56 impl State for Empty { 57 type Doc = Unset; 58 type Root = Unset; 59 } 60 ///State transition - sets the `doc` field to Set 61 pub struct SetDoc<S: State = Empty>(PhantomData<fn() -> S>); 62 impl<S: State> sealed::Sealed for SetDoc<S> {} 63 impl<S: State> State for SetDoc<S> { 64 type Doc = Set<members::doc>; 65 type Root = S::Root; 66 } 67 ///State transition - sets the `root` field to Set 68 pub struct SetRoot<S: State = Empty>(PhantomData<fn() -> S>); 69 impl<S: State> sealed::Sealed for SetRoot<S> {} 70 impl<S: State> State for SetRoot<S> { 71 type Doc = S::Doc; 72 type Root = Set<members::root>; 73 } 74 /// Marker types for field names 75 #[allow(non_camel_case_types)] 76 pub mod members { 77 ///Marker type for the `doc` field 78 pub struct doc(()); 79 ///Marker type for the `root` field 80 pub struct root(()); 81 } 82} 83 84/// Builder for constructing an instance of this type 85pub struct DiffBuilder<'a, S: diff_state::State> { 86 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 87 __unsafe_private_named: ( 88 ::core::option::Option<jacquard_common::types::string::Datetime>, 89 ::core::option::Option<crate::sh_weaver::edit::DocRef<'a>>, 90 ::core::option::Option<bytes::Bytes>, 91 ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 92 ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 93 ::core::option::Option<jacquard_common::types::blob::BlobRef<'a>>, 94 ), 95 _phantom: ::core::marker::PhantomData<&'a ()>, 96} 97 98impl<'a> Diff<'a> { 99 /// Create a new builder for this type 100 pub fn new() -> DiffBuilder<'a, diff_state::Empty> { 101 DiffBuilder::new() 102 } 103} 104 105impl<'a> DiffBuilder<'a, diff_state::Empty> { 106 /// Create a new builder with all fields unset 107 pub fn new() -> Self { 108 DiffBuilder { 109 _phantom_state: ::core::marker::PhantomData, 110 __unsafe_private_named: (None, None, None, None, None, None), 111 _phantom: ::core::marker::PhantomData, 112 } 113 } 114} 115 116impl<'a, S: diff_state::State> DiffBuilder<'a, S> { 117 /// Set the `createdAt` field (optional) 118 pub fn created_at( 119 mut self, 120 value: impl Into<Option<jacquard_common::types::string::Datetime>>, 121 ) -> Self { 122 self.__unsafe_private_named.0 = value.into(); 123 self 124 } 125 /// Set the `createdAt` field to an Option value (optional) 126 pub fn maybe_created_at( 127 mut self, 128 value: Option<jacquard_common::types::string::Datetime>, 129 ) -> Self { 130 self.__unsafe_private_named.0 = value; 131 self 132 } 133} 134 135impl<'a, S> DiffBuilder<'a, S> 136where 137 S: diff_state::State, 138 S::Doc: diff_state::IsUnset, 139{ 140 /// Set the `doc` field (required) 141 pub fn doc( 142 mut self, 143 value: impl Into<crate::sh_weaver::edit::DocRef<'a>>, 144 ) -> DiffBuilder<'a, diff_state::SetDoc<S>> { 145 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into()); 146 DiffBuilder { 147 _phantom_state: ::core::marker::PhantomData, 148 __unsafe_private_named: self.__unsafe_private_named, 149 _phantom: ::core::marker::PhantomData, 150 } 151 } 152} 153 154impl<'a, S: diff_state::State> DiffBuilder<'a, S> { 155 /// Set the `inlineDiff` field (optional) 156 pub fn inline_diff(mut self, value: impl Into<Option<bytes::Bytes>>) -> Self { 157 self.__unsafe_private_named.2 = value.into(); 158 self 159 } 160 /// Set the `inlineDiff` field to an Option value (optional) 161 pub fn maybe_inline_diff(mut self, value: Option<bytes::Bytes>) -> Self { 162 self.__unsafe_private_named.2 = value; 163 self 164 } 165} 166 167impl<'a, S: diff_state::State> DiffBuilder<'a, S> { 168 /// Set the `prev` field (optional) 169 pub fn prev( 170 mut self, 171 value: impl Into<Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>>, 172 ) -> Self { 173 self.__unsafe_private_named.3 = value.into(); 174 self 175 } 176 /// Set the `prev` field to an Option value (optional) 177 pub fn maybe_prev( 178 mut self, 179 value: Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 180 ) -> Self { 181 self.__unsafe_private_named.3 = value; 182 self 183 } 184} 185 186impl<'a, S> DiffBuilder<'a, S> 187where 188 S: diff_state::State, 189 S::Root: diff_state::IsUnset, 190{ 191 /// Set the `root` field (required) 192 pub fn root( 193 mut self, 194 value: impl Into<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 195 ) -> DiffBuilder<'a, diff_state::SetRoot<S>> { 196 self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into()); 197 DiffBuilder { 198 _phantom_state: ::core::marker::PhantomData, 199 __unsafe_private_named: self.__unsafe_private_named, 200 _phantom: ::core::marker::PhantomData, 201 } 202 } 203} 204 205impl<'a, S: diff_state::State> DiffBuilder<'a, S> { 206 /// Set the `snapshot` field (optional) 207 pub fn snapshot( 208 mut self, 209 value: impl Into<Option<jacquard_common::types::blob::BlobRef<'a>>>, 210 ) -> Self { 211 self.__unsafe_private_named.5 = value.into(); 212 self 213 } 214 /// Set the `snapshot` field to an Option value (optional) 215 pub fn maybe_snapshot( 216 mut self, 217 value: Option<jacquard_common::types::blob::BlobRef<'a>>, 218 ) -> Self { 219 self.__unsafe_private_named.5 = value; 220 self 221 } 222} 223 224impl<'a, S> DiffBuilder<'a, S> 225where 226 S: diff_state::State, 227 S::Doc: diff_state::IsSet, 228 S::Root: diff_state::IsSet, 229{ 230 /// Build the final struct 231 pub fn build(self) -> Diff<'a> { 232 Diff { 233 created_at: self.__unsafe_private_named.0, 234 doc: self.__unsafe_private_named.1.unwrap(), 235 inline_diff: self.__unsafe_private_named.2, 236 prev: self.__unsafe_private_named.3, 237 root: self.__unsafe_private_named.4.unwrap(), 238 snapshot: self.__unsafe_private_named.5, 239 extra_data: Default::default(), 240 } 241 } 242 /// Build the final struct with custom extra_data 243 pub fn build_with_data( 244 self, 245 extra_data: std::collections::BTreeMap< 246 jacquard_common::smol_str::SmolStr, 247 jacquard_common::types::value::Data<'a>, 248 >, 249 ) -> Diff<'a> { 250 Diff { 251 created_at: self.__unsafe_private_named.0, 252 doc: self.__unsafe_private_named.1.unwrap(), 253 inline_diff: self.__unsafe_private_named.2, 254 prev: self.__unsafe_private_named.3, 255 root: self.__unsafe_private_named.4.unwrap(), 256 snapshot: self.__unsafe_private_named.5, 257 extra_data: Some(extra_data), 258 } 259 } 260} 261 262impl<'a> Diff<'a> { 263 pub fn uri( 264 uri: impl Into<jacquard_common::CowStr<'a>>, 265 ) -> Result< 266 jacquard_common::types::uri::RecordUri<'a, DiffRecord>, 267 jacquard_common::types::uri::UriError, 268 > { 269 jacquard_common::types::uri::RecordUri::try_from_uri( 270 jacquard_common::types::string::AtUri::new_cow(uri.into())?, 271 ) 272 } 273} 274 275/// Typed wrapper for GetRecord response with this collection's record type. 276#[derive( 277 serde::Serialize, 278 serde::Deserialize, 279 Debug, 280 Clone, 281 PartialEq, 282 Eq, 283 jacquard_derive::IntoStatic 284)] 285#[serde(rename_all = "camelCase")] 286pub struct DiffGetRecordOutput<'a> { 287 #[serde(skip_serializing_if = "std::option::Option::is_none")] 288 #[serde(borrow)] 289 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>, 290 #[serde(borrow)] 291 pub uri: jacquard_common::types::string::AtUri<'a>, 292 #[serde(borrow)] 293 pub value: Diff<'a>, 294} 295 296impl From<DiffGetRecordOutput<'_>> for Diff<'_> { 297 fn from(output: DiffGetRecordOutput<'_>) -> Self { 298 use jacquard_common::IntoStatic; 299 output.value.into_static() 300 } 301} 302 303impl jacquard_common::types::collection::Collection for Diff<'_> { 304 const NSID: &'static str = "sh.weaver.edit.diff"; 305 type Record = DiffRecord; 306} 307 308/// Marker type for deserializing records from this collection. 309#[derive(Debug, serde::Serialize, serde::Deserialize)] 310pub struct DiffRecord; 311impl jacquard_common::xrpc::XrpcResp for DiffRecord { 312 const NSID: &'static str = "sh.weaver.edit.diff"; 313 const ENCODING: &'static str = "application/json"; 314 type Output<'de> = DiffGetRecordOutput<'de>; 315 type Err<'de> = jacquard_common::types::collection::RecordError<'de>; 316} 317 318impl jacquard_common::types::collection::Collection for DiffRecord { 319 const NSID: &'static str = "sh.weaver.edit.diff"; 320 type Record = DiffRecord; 321} 322 323impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Diff<'a> { 324 fn nsid() -> &'static str { 325 "sh.weaver.edit.diff" 326 } 327 fn def_name() -> &'static str { 328 "main" 329 } 330 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { 331 lexicon_doc_sh_weaver_edit_diff() 332 } 333 fn validate( 334 &self, 335 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { 336 Ok(()) 337 } 338} 339 340fn lexicon_doc_sh_weaver_edit_diff() -> ::jacquard_lexicon::lexicon::LexiconDoc< 341 'static, 342> { 343 ::jacquard_lexicon::lexicon::LexiconDoc { 344 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, 345 id: ::jacquard_common::CowStr::new_static("sh.weaver.edit.diff"), 346 revision: None, 347 description: None, 348 defs: { 349 let mut map = ::alloc::collections::BTreeMap::new(); 350 map.insert( 351 ::jacquard_common::smol_str::SmolStr::new_static("main"), 352 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { 353 description: Some( 354 ::jacquard_common::CowStr::new_static( 355 "An edit record for a notebook.", 356 ), 357 ), 358 key: Some(::jacquard_common::CowStr::new_static("tid")), 359 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { 360 description: None, 361 required: Some( 362 vec![ 363 ::jacquard_common::smol_str::SmolStr::new_static("root"), 364 ::jacquard_common::smol_str::SmolStr::new_static("doc") 365 ], 366 ), 367 nullable: None, 368 properties: { 369 #[allow(unused_mut)] 370 let mut map = ::alloc::collections::BTreeMap::new(); 371 map.insert( 372 ::jacquard_common::smol_str::SmolStr::new_static( 373 "createdAt", 374 ), 375 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { 376 description: None, 377 format: Some( 378 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime, 379 ), 380 default: None, 381 min_length: None, 382 max_length: None, 383 min_graphemes: None, 384 max_graphemes: None, 385 r#enum: None, 386 r#const: None, 387 known_values: None, 388 }), 389 ); 390 map.insert( 391 ::jacquard_common::smol_str::SmolStr::new_static("doc"), 392 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { 393 description: None, 394 r#ref: ::jacquard_common::CowStr::new_static( 395 "sh.weaver.edit.defs#docRef", 396 ), 397 }), 398 ); 399 map.insert( 400 ::jacquard_common::smol_str::SmolStr::new_static( 401 "inlineDiff", 402 ), 403 ::jacquard_lexicon::lexicon::LexObjectProperty::Bytes(::jacquard_lexicon::lexicon::LexBytes { 404 description: None, 405 max_length: Some(8192usize), 406 min_length: None, 407 }), 408 ); 409 map.insert( 410 ::jacquard_common::smol_str::SmolStr::new_static("prev"), 411 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { 412 description: None, 413 r#ref: ::jacquard_common::CowStr::new_static( 414 "com.atproto.repo.strongRef", 415 ), 416 }), 417 ); 418 map.insert( 419 ::jacquard_common::smol_str::SmolStr::new_static("root"), 420 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { 421 description: None, 422 r#ref: ::jacquard_common::CowStr::new_static( 423 "com.atproto.repo.strongRef", 424 ), 425 }), 426 ); 427 map.insert( 428 ::jacquard_common::smol_str::SmolStr::new_static( 429 "snapshot", 430 ), 431 ::jacquard_lexicon::lexicon::LexObjectProperty::Blob(::jacquard_lexicon::lexicon::LexBlob { 432 description: None, 433 accept: None, 434 max_size: None, 435 }), 436 ); 437 map 438 }, 439 }), 440 }), 441 ); 442 map 443 }, 444 } 445}