atproto blogging
at main 640 lines 25 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: sh.weaver.collab.invite 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8/// The scope/type of collaboration. 9#[derive(Debug, Clone, PartialEq, Eq, Hash)] 10pub enum CollabScope<'a> { 11 ShWeaverCollabDefsNotebook, 12 ShWeaverCollabDefsEntry, 13 ShWeaverCollabDefsChapter, 14 Other(jacquard_common::CowStr<'a>), 15} 16 17impl<'a> CollabScope<'a> { 18 pub fn as_str(&self) -> &str { 19 match self { 20 Self::ShWeaverCollabDefsNotebook => "sh.weaver.collab.defs#notebook", 21 Self::ShWeaverCollabDefsEntry => "sh.weaver.collab.defs#entry", 22 Self::ShWeaverCollabDefsChapter => "sh.weaver.collab.defs#chapter", 23 Self::Other(s) => s.as_ref(), 24 } 25 } 26} 27 28impl<'a> From<&'a str> for CollabScope<'a> { 29 fn from(s: &'a str) -> Self { 30 match s { 31 "sh.weaver.collab.defs#notebook" => Self::ShWeaverCollabDefsNotebook, 32 "sh.weaver.collab.defs#entry" => Self::ShWeaverCollabDefsEntry, 33 "sh.weaver.collab.defs#chapter" => Self::ShWeaverCollabDefsChapter, 34 _ => Self::Other(jacquard_common::CowStr::from(s)), 35 } 36 } 37} 38 39impl<'a> From<String> for CollabScope<'a> { 40 fn from(s: String) -> Self { 41 match s.as_str() { 42 "sh.weaver.collab.defs#notebook" => Self::ShWeaverCollabDefsNotebook, 43 "sh.weaver.collab.defs#entry" => Self::ShWeaverCollabDefsEntry, 44 "sh.weaver.collab.defs#chapter" => Self::ShWeaverCollabDefsChapter, 45 _ => Self::Other(jacquard_common::CowStr::from(s)), 46 } 47 } 48} 49 50impl<'a> AsRef<str> for CollabScope<'a> { 51 fn as_ref(&self) -> &str { 52 self.as_str() 53 } 54} 55 56impl<'a> core::fmt::Display for CollabScope<'a> { 57 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 58 write!(f, "{}", self.as_str()) 59 } 60} 61 62impl<'a> serde::Serialize for CollabScope<'a> { 63 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 64 where 65 S: serde::Serializer, 66 { 67 serializer.serialize_str(self.as_str()) 68 } 69} 70 71impl<'de, 'a> serde::Deserialize<'de> for CollabScope<'a> 72where 73 'de: 'a, 74{ 75 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 76 where 77 D: serde::Deserializer<'de>, 78 { 79 let s = <&'de str>::deserialize(deserializer)?; 80 Ok(Self::from(s)) 81 } 82} 83 84impl jacquard_common::IntoStatic for CollabScope<'_> { 85 type Output = CollabScope<'static>; 86 fn into_static(self) -> Self::Output { 87 match self { 88 CollabScope::ShWeaverCollabDefsNotebook => { 89 CollabScope::ShWeaverCollabDefsNotebook 90 } 91 CollabScope::ShWeaverCollabDefsEntry => CollabScope::ShWeaverCollabDefsEntry, 92 CollabScope::ShWeaverCollabDefsChapter => { 93 CollabScope::ShWeaverCollabDefsChapter 94 } 95 CollabScope::Other(v) => CollabScope::Other(v.into_static()), 96 } 97 } 98} 99 100/// Invitation to collaborate on a resource (notebook, entry, chapter, etc.). Creates half of a two-way agreement. 101#[jacquard_derive::lexicon] 102#[derive( 103 serde::Serialize, 104 serde::Deserialize, 105 Debug, 106 Clone, 107 PartialEq, 108 Eq, 109 jacquard_derive::IntoStatic 110)] 111#[serde(rename_all = "camelCase")] 112pub struct Invite<'a> { 113 pub created_at: jacquard_common::types::string::Datetime, 114 /// Optional expiration for the invite. 115 #[serde(skip_serializing_if = "std::option::Option::is_none")] 116 pub expires_at: std::option::Option<jacquard_common::types::string::Datetime>, 117 /// DID of the user being invited. 118 #[serde(borrow)] 119 pub invitee: jacquard_common::types::string::Did<'a>, 120 /// Optional message to the invitee. 121 #[serde(skip_serializing_if = "std::option::Option::is_none")] 122 #[serde(borrow)] 123 pub message: std::option::Option<jacquard_common::CowStr<'a>>, 124 /// The resource to collaborate on (notebook, entry, chapter, etc.). 125 #[serde(borrow)] 126 pub resource: crate::com_atproto::repo::strong_ref::StrongRef<'a>, 127 /// Optional explicit scope type. If omitted, inferred from resource lexicon. 128 #[serde(skip_serializing_if = "std::option::Option::is_none")] 129 #[serde(borrow)] 130 pub scope: std::option::Option<crate::sh_weaver::collab::invite::CollabScope<'a>>, 131} 132 133pub mod invite_state { 134 135 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 136 #[allow(unused)] 137 use ::core::marker::PhantomData; 138 mod sealed { 139 pub trait Sealed {} 140 } 141 /// State trait tracking which required fields have been set 142 pub trait State: sealed::Sealed { 143 type Resource; 144 type CreatedAt; 145 type Invitee; 146 } 147 /// Empty state - all required fields are unset 148 pub struct Empty(()); 149 impl sealed::Sealed for Empty {} 150 impl State for Empty { 151 type Resource = Unset; 152 type CreatedAt = Unset; 153 type Invitee = Unset; 154 } 155 ///State transition - sets the `resource` field to Set 156 pub struct SetResource<S: State = Empty>(PhantomData<fn() -> S>); 157 impl<S: State> sealed::Sealed for SetResource<S> {} 158 impl<S: State> State for SetResource<S> { 159 type Resource = Set<members::resource>; 160 type CreatedAt = S::CreatedAt; 161 type Invitee = S::Invitee; 162 } 163 ///State transition - sets the `created_at` field to Set 164 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>); 165 impl<S: State> sealed::Sealed for SetCreatedAt<S> {} 166 impl<S: State> State for SetCreatedAt<S> { 167 type Resource = S::Resource; 168 type CreatedAt = Set<members::created_at>; 169 type Invitee = S::Invitee; 170 } 171 ///State transition - sets the `invitee` field to Set 172 pub struct SetInvitee<S: State = Empty>(PhantomData<fn() -> S>); 173 impl<S: State> sealed::Sealed for SetInvitee<S> {} 174 impl<S: State> State for SetInvitee<S> { 175 type Resource = S::Resource; 176 type CreatedAt = S::CreatedAt; 177 type Invitee = Set<members::invitee>; 178 } 179 /// Marker types for field names 180 #[allow(non_camel_case_types)] 181 pub mod members { 182 ///Marker type for the `resource` field 183 pub struct resource(()); 184 ///Marker type for the `created_at` field 185 pub struct created_at(()); 186 ///Marker type for the `invitee` field 187 pub struct invitee(()); 188 } 189} 190 191/// Builder for constructing an instance of this type 192pub struct InviteBuilder<'a, S: invite_state::State> { 193 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 194 __unsafe_private_named: ( 195 ::core::option::Option<jacquard_common::types::string::Datetime>, 196 ::core::option::Option<jacquard_common::types::string::Datetime>, 197 ::core::option::Option<jacquard_common::types::string::Did<'a>>, 198 ::core::option::Option<jacquard_common::CowStr<'a>>, 199 ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 200 ::core::option::Option<crate::sh_weaver::collab::invite::CollabScope<'a>>, 201 ), 202 _phantom: ::core::marker::PhantomData<&'a ()>, 203} 204 205impl<'a> Invite<'a> { 206 /// Create a new builder for this type 207 pub fn new() -> InviteBuilder<'a, invite_state::Empty> { 208 InviteBuilder::new() 209 } 210} 211 212impl<'a> InviteBuilder<'a, invite_state::Empty> { 213 /// Create a new builder with all fields unset 214 pub fn new() -> Self { 215 InviteBuilder { 216 _phantom_state: ::core::marker::PhantomData, 217 __unsafe_private_named: (None, None, None, None, None, None), 218 _phantom: ::core::marker::PhantomData, 219 } 220 } 221} 222 223impl<'a, S> InviteBuilder<'a, S> 224where 225 S: invite_state::State, 226 S::CreatedAt: invite_state::IsUnset, 227{ 228 /// Set the `createdAt` field (required) 229 pub fn created_at( 230 mut self, 231 value: impl Into<jacquard_common::types::string::Datetime>, 232 ) -> InviteBuilder<'a, invite_state::SetCreatedAt<S>> { 233 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into()); 234 InviteBuilder { 235 _phantom_state: ::core::marker::PhantomData, 236 __unsafe_private_named: self.__unsafe_private_named, 237 _phantom: ::core::marker::PhantomData, 238 } 239 } 240} 241 242impl<'a, S: invite_state::State> InviteBuilder<'a, S> { 243 /// Set the `expiresAt` field (optional) 244 pub fn expires_at( 245 mut self, 246 value: impl Into<Option<jacquard_common::types::string::Datetime>>, 247 ) -> Self { 248 self.__unsafe_private_named.1 = value.into(); 249 self 250 } 251 /// Set the `expiresAt` field to an Option value (optional) 252 pub fn maybe_expires_at( 253 mut self, 254 value: Option<jacquard_common::types::string::Datetime>, 255 ) -> Self { 256 self.__unsafe_private_named.1 = value; 257 self 258 } 259} 260 261impl<'a, S> InviteBuilder<'a, S> 262where 263 S: invite_state::State, 264 S::Invitee: invite_state::IsUnset, 265{ 266 /// Set the `invitee` field (required) 267 pub fn invitee( 268 mut self, 269 value: impl Into<jacquard_common::types::string::Did<'a>>, 270 ) -> InviteBuilder<'a, invite_state::SetInvitee<S>> { 271 self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into()); 272 InviteBuilder { 273 _phantom_state: ::core::marker::PhantomData, 274 __unsafe_private_named: self.__unsafe_private_named, 275 _phantom: ::core::marker::PhantomData, 276 } 277 } 278} 279 280impl<'a, S: invite_state::State> InviteBuilder<'a, S> { 281 /// Set the `message` field (optional) 282 pub fn message( 283 mut self, 284 value: impl Into<Option<jacquard_common::CowStr<'a>>>, 285 ) -> Self { 286 self.__unsafe_private_named.3 = value.into(); 287 self 288 } 289 /// Set the `message` field to an Option value (optional) 290 pub fn maybe_message(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self { 291 self.__unsafe_private_named.3 = value; 292 self 293 } 294} 295 296impl<'a, S> InviteBuilder<'a, S> 297where 298 S: invite_state::State, 299 S::Resource: invite_state::IsUnset, 300{ 301 /// Set the `resource` field (required) 302 pub fn resource( 303 mut self, 304 value: impl Into<crate::com_atproto::repo::strong_ref::StrongRef<'a>>, 305 ) -> InviteBuilder<'a, invite_state::SetResource<S>> { 306 self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into()); 307 InviteBuilder { 308 _phantom_state: ::core::marker::PhantomData, 309 __unsafe_private_named: self.__unsafe_private_named, 310 _phantom: ::core::marker::PhantomData, 311 } 312 } 313} 314 315impl<'a, S: invite_state::State> InviteBuilder<'a, S> { 316 /// Set the `scope` field (optional) 317 pub fn scope( 318 mut self, 319 value: impl Into<Option<crate::sh_weaver::collab::invite::CollabScope<'a>>>, 320 ) -> Self { 321 self.__unsafe_private_named.5 = value.into(); 322 self 323 } 324 /// Set the `scope` field to an Option value (optional) 325 pub fn maybe_scope( 326 mut self, 327 value: Option<crate::sh_weaver::collab::invite::CollabScope<'a>>, 328 ) -> Self { 329 self.__unsafe_private_named.5 = value; 330 self 331 } 332} 333 334impl<'a, S> InviteBuilder<'a, S> 335where 336 S: invite_state::State, 337 S::Resource: invite_state::IsSet, 338 S::CreatedAt: invite_state::IsSet, 339 S::Invitee: invite_state::IsSet, 340{ 341 /// Build the final struct 342 pub fn build(self) -> Invite<'a> { 343 Invite { 344 created_at: self.__unsafe_private_named.0.unwrap(), 345 expires_at: self.__unsafe_private_named.1, 346 invitee: self.__unsafe_private_named.2.unwrap(), 347 message: self.__unsafe_private_named.3, 348 resource: self.__unsafe_private_named.4.unwrap(), 349 scope: self.__unsafe_private_named.5, 350 extra_data: Default::default(), 351 } 352 } 353 /// Build the final struct with custom extra_data 354 pub fn build_with_data( 355 self, 356 extra_data: std::collections::BTreeMap< 357 jacquard_common::smol_str::SmolStr, 358 jacquard_common::types::value::Data<'a>, 359 >, 360 ) -> Invite<'a> { 361 Invite { 362 created_at: self.__unsafe_private_named.0.unwrap(), 363 expires_at: self.__unsafe_private_named.1, 364 invitee: self.__unsafe_private_named.2.unwrap(), 365 message: self.__unsafe_private_named.3, 366 resource: self.__unsafe_private_named.4.unwrap(), 367 scope: self.__unsafe_private_named.5, 368 extra_data: Some(extra_data), 369 } 370 } 371} 372 373impl<'a> Invite<'a> { 374 pub fn uri( 375 uri: impl Into<jacquard_common::CowStr<'a>>, 376 ) -> Result< 377 jacquard_common::types::uri::RecordUri<'a, InviteRecord>, 378 jacquard_common::types::uri::UriError, 379 > { 380 jacquard_common::types::uri::RecordUri::try_from_uri( 381 jacquard_common::types::string::AtUri::new_cow(uri.into())?, 382 ) 383 } 384} 385 386/// Typed wrapper for GetRecord response with this collection's record type. 387#[derive( 388 serde::Serialize, 389 serde::Deserialize, 390 Debug, 391 Clone, 392 PartialEq, 393 Eq, 394 jacquard_derive::IntoStatic 395)] 396#[serde(rename_all = "camelCase")] 397pub struct InviteGetRecordOutput<'a> { 398 #[serde(skip_serializing_if = "std::option::Option::is_none")] 399 #[serde(borrow)] 400 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>, 401 #[serde(borrow)] 402 pub uri: jacquard_common::types::string::AtUri<'a>, 403 #[serde(borrow)] 404 pub value: Invite<'a>, 405} 406 407impl From<InviteGetRecordOutput<'_>> for Invite<'_> { 408 fn from(output: InviteGetRecordOutput<'_>) -> Self { 409 use jacquard_common::IntoStatic; 410 output.value.into_static() 411 } 412} 413 414impl jacquard_common::types::collection::Collection for Invite<'_> { 415 const NSID: &'static str = "sh.weaver.collab.invite"; 416 type Record = InviteRecord; 417} 418 419/// Marker type for deserializing records from this collection. 420#[derive(Debug, serde::Serialize, serde::Deserialize)] 421pub struct InviteRecord; 422impl jacquard_common::xrpc::XrpcResp for InviteRecord { 423 const NSID: &'static str = "sh.weaver.collab.invite"; 424 const ENCODING: &'static str = "application/json"; 425 type Output<'de> = InviteGetRecordOutput<'de>; 426 type Err<'de> = jacquard_common::types::collection::RecordError<'de>; 427} 428 429impl jacquard_common::types::collection::Collection for InviteRecord { 430 const NSID: &'static str = "sh.weaver.collab.invite"; 431 type Record = InviteRecord; 432} 433 434impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Invite<'a> { 435 fn nsid() -> &'static str { 436 "sh.weaver.collab.invite" 437 } 438 fn def_name() -> &'static str { 439 "main" 440 } 441 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { 442 lexicon_doc_sh_weaver_collab_invite() 443 } 444 fn validate( 445 &self, 446 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { 447 if let Some(ref value) = self.message { 448 #[allow(unused_comparisons)] 449 if <str>::len(value.as_ref()) > 3000usize { 450 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength { 451 path: ::jacquard_lexicon::validation::ValidationPath::from_field( 452 "message", 453 ), 454 max: 3000usize, 455 actual: <str>::len(value.as_ref()), 456 }); 457 } 458 } 459 if let Some(ref value) = self.message { 460 { 461 let count = ::unicode_segmentation::UnicodeSegmentation::graphemes( 462 value.as_ref(), 463 true, 464 ) 465 .count(); 466 if count > 300usize { 467 return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes { 468 path: ::jacquard_lexicon::validation::ValidationPath::from_field( 469 "message", 470 ), 471 max: 300usize, 472 actual: count, 473 }); 474 } 475 } 476 } 477 Ok(()) 478 } 479} 480 481fn lexicon_doc_sh_weaver_collab_invite() -> ::jacquard_lexicon::lexicon::LexiconDoc< 482 'static, 483> { 484 ::jacquard_lexicon::lexicon::LexiconDoc { 485 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, 486 id: ::jacquard_common::CowStr::new_static("sh.weaver.collab.invite"), 487 revision: None, 488 description: None, 489 defs: { 490 let mut map = ::alloc::collections::BTreeMap::new(); 491 map.insert( 492 ::jacquard_common::smol_str::SmolStr::new_static("collabScope"), 493 ::jacquard_lexicon::lexicon::LexUserType::String(::jacquard_lexicon::lexicon::LexString { 494 description: Some( 495 ::jacquard_common::CowStr::new_static( 496 "The scope/type of collaboration.", 497 ), 498 ), 499 format: None, 500 default: None, 501 min_length: None, 502 max_length: None, 503 min_graphemes: None, 504 max_graphemes: None, 505 r#enum: None, 506 r#const: None, 507 known_values: None, 508 }), 509 ); 510 map.insert( 511 ::jacquard_common::smol_str::SmolStr::new_static("main"), 512 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { 513 description: Some( 514 ::jacquard_common::CowStr::new_static( 515 "Invitation to collaborate on a resource (notebook, entry, chapter, etc.). Creates half of a two-way agreement.", 516 ), 517 ), 518 key: Some(::jacquard_common::CowStr::new_static("tid")), 519 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { 520 description: None, 521 required: Some( 522 vec![ 523 ::jacquard_common::smol_str::SmolStr::new_static("resource"), 524 ::jacquard_common::smol_str::SmolStr::new_static("invitee"), 525 ::jacquard_common::smol_str::SmolStr::new_static("createdAt") 526 ], 527 ), 528 nullable: None, 529 properties: { 530 #[allow(unused_mut)] 531 let mut map = ::alloc::collections::BTreeMap::new(); 532 map.insert( 533 ::jacquard_common::smol_str::SmolStr::new_static( 534 "createdAt", 535 ), 536 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { 537 description: None, 538 format: Some( 539 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime, 540 ), 541 default: None, 542 min_length: None, 543 max_length: None, 544 min_graphemes: None, 545 max_graphemes: None, 546 r#enum: None, 547 r#const: None, 548 known_values: None, 549 }), 550 ); 551 map.insert( 552 ::jacquard_common::smol_str::SmolStr::new_static( 553 "expiresAt", 554 ), 555 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { 556 description: Some( 557 ::jacquard_common::CowStr::new_static( 558 "Optional expiration for the invite.", 559 ), 560 ), 561 format: Some( 562 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime, 563 ), 564 default: None, 565 min_length: None, 566 max_length: None, 567 min_graphemes: None, 568 max_graphemes: None, 569 r#enum: None, 570 r#const: None, 571 known_values: None, 572 }), 573 ); 574 map.insert( 575 ::jacquard_common::smol_str::SmolStr::new_static("invitee"), 576 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { 577 description: Some( 578 ::jacquard_common::CowStr::new_static( 579 "DID of the user being invited.", 580 ), 581 ), 582 format: Some( 583 ::jacquard_lexicon::lexicon::LexStringFormat::Did, 584 ), 585 default: None, 586 min_length: None, 587 max_length: None, 588 min_graphemes: None, 589 max_graphemes: None, 590 r#enum: None, 591 r#const: None, 592 known_values: None, 593 }), 594 ); 595 map.insert( 596 ::jacquard_common::smol_str::SmolStr::new_static("message"), 597 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { 598 description: Some( 599 ::jacquard_common::CowStr::new_static( 600 "Optional message to the invitee.", 601 ), 602 ), 603 format: None, 604 default: None, 605 min_length: None, 606 max_length: Some(3000usize), 607 min_graphemes: None, 608 max_graphemes: Some(300usize), 609 r#enum: None, 610 r#const: None, 611 known_values: None, 612 }), 613 ); 614 map.insert( 615 ::jacquard_common::smol_str::SmolStr::new_static( 616 "resource", 617 ), 618 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { 619 description: None, 620 r#ref: ::jacquard_common::CowStr::new_static( 621 "com.atproto.repo.strongRef", 622 ), 623 }), 624 ); 625 map.insert( 626 ::jacquard_common::smol_str::SmolStr::new_static("scope"), 627 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { 628 description: None, 629 r#ref: ::jacquard_common::CowStr::new_static("#collabScope"), 630 }), 631 ); 632 map 633 }, 634 }), 635 }), 636 ); 637 map 638 }, 639 } 640}