// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: sh.weaver.collab.invite // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. /// The scope/type of collaboration. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum CollabScope<'a> { ShWeaverCollabDefsNotebook, ShWeaverCollabDefsEntry, ShWeaverCollabDefsChapter, Other(jacquard_common::CowStr<'a>), } impl<'a> CollabScope<'a> { pub fn as_str(&self) -> &str { match self { Self::ShWeaverCollabDefsNotebook => "sh.weaver.collab.defs#notebook", Self::ShWeaverCollabDefsEntry => "sh.weaver.collab.defs#entry", Self::ShWeaverCollabDefsChapter => "sh.weaver.collab.defs#chapter", Self::Other(s) => s.as_ref(), } } } impl<'a> From<&'a str> for CollabScope<'a> { fn from(s: &'a str) -> Self { match s { "sh.weaver.collab.defs#notebook" => Self::ShWeaverCollabDefsNotebook, "sh.weaver.collab.defs#entry" => Self::ShWeaverCollabDefsEntry, "sh.weaver.collab.defs#chapter" => Self::ShWeaverCollabDefsChapter, _ => Self::Other(jacquard_common::CowStr::from(s)), } } } impl<'a> From for CollabScope<'a> { fn from(s: String) -> Self { match s.as_str() { "sh.weaver.collab.defs#notebook" => Self::ShWeaverCollabDefsNotebook, "sh.weaver.collab.defs#entry" => Self::ShWeaverCollabDefsEntry, "sh.weaver.collab.defs#chapter" => Self::ShWeaverCollabDefsChapter, _ => Self::Other(jacquard_common::CowStr::from(s)), } } } impl<'a> AsRef for CollabScope<'a> { fn as_ref(&self) -> &str { self.as_str() } } impl<'a> core::fmt::Display for CollabScope<'a> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.as_str()) } } impl<'a> serde::Serialize for CollabScope<'a> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, 'a> serde::Deserialize<'de> for CollabScope<'a> where 'de: 'a, { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let s = <&'de str>::deserialize(deserializer)?; Ok(Self::from(s)) } } impl jacquard_common::IntoStatic for CollabScope<'_> { type Output = CollabScope<'static>; fn into_static(self) -> Self::Output { match self { CollabScope::ShWeaverCollabDefsNotebook => { CollabScope::ShWeaverCollabDefsNotebook } CollabScope::ShWeaverCollabDefsEntry => CollabScope::ShWeaverCollabDefsEntry, CollabScope::ShWeaverCollabDefsChapter => { CollabScope::ShWeaverCollabDefsChapter } CollabScope::Other(v) => CollabScope::Other(v.into_static()), } } } /// Invitation to collaborate on a resource (notebook, entry, chapter, etc.). Creates half of a two-way agreement. #[jacquard_derive::lexicon] #[derive( serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, jacquard_derive::IntoStatic )] #[serde(rename_all = "camelCase")] pub struct Invite<'a> { pub created_at: jacquard_common::types::string::Datetime, /// Optional expiration for the invite. #[serde(skip_serializing_if = "std::option::Option::is_none")] pub expires_at: std::option::Option, /// DID of the user being invited. #[serde(borrow)] pub invitee: jacquard_common::types::string::Did<'a>, /// Optional message to the invitee. #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub message: std::option::Option>, /// The resource to collaborate on (notebook, entry, chapter, etc.). #[serde(borrow)] pub resource: crate::com_atproto::repo::strong_ref::StrongRef<'a>, /// Optional explicit scope type. If omitted, inferred from resource lexicon. #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub scope: std::option::Option>, } pub mod invite_state { pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Resource; type CreatedAt; type Invitee; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Resource = Unset; type CreatedAt = Unset; type Invitee = Unset; } ///State transition - sets the `resource` field to Set pub struct SetResource(PhantomData S>); impl sealed::Sealed for SetResource {} impl State for SetResource { type Resource = Set; type CreatedAt = S::CreatedAt; type Invitee = S::Invitee; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData S>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type Resource = S::Resource; type CreatedAt = Set; type Invitee = S::Invitee; } ///State transition - sets the `invitee` field to Set pub struct SetInvitee(PhantomData S>); impl sealed::Sealed for SetInvitee {} impl State for SetInvitee { type Resource = S::Resource; type CreatedAt = S::CreatedAt; type Invitee = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `resource` field pub struct resource(()); ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `invitee` field pub struct invitee(()); } } /// Builder for constructing an instance of this type pub struct InviteBuilder<'a, S: invite_state::State> { _phantom_state: ::core::marker::PhantomData S>, __unsafe_private_named: ( ::core::option::Option, ::core::option::Option, ::core::option::Option>, ::core::option::Option>, ::core::option::Option>, ::core::option::Option>, ), _phantom: ::core::marker::PhantomData<&'a ()>, } impl<'a> Invite<'a> { /// Create a new builder for this type pub fn new() -> InviteBuilder<'a, invite_state::Empty> { InviteBuilder::new() } } impl<'a> InviteBuilder<'a, invite_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { InviteBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: (None, None, None, None, None, None), _phantom: ::core::marker::PhantomData, } } } impl<'a, S> InviteBuilder<'a, S> where S: invite_state::State, S::CreatedAt: invite_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> InviteBuilder<'a, invite_state::SetCreatedAt> { self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into()); InviteBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: self.__unsafe_private_named, _phantom: ::core::marker::PhantomData, } } } impl<'a, S: invite_state::State> InviteBuilder<'a, S> { /// Set the `expiresAt` field (optional) pub fn expires_at( mut self, value: impl Into>, ) -> Self { self.__unsafe_private_named.1 = value.into(); self } /// Set the `expiresAt` field to an Option value (optional) pub fn maybe_expires_at( mut self, value: Option, ) -> Self { self.__unsafe_private_named.1 = value; self } } impl<'a, S> InviteBuilder<'a, S> where S: invite_state::State, S::Invitee: invite_state::IsUnset, { /// Set the `invitee` field (required) pub fn invitee( mut self, value: impl Into>, ) -> InviteBuilder<'a, invite_state::SetInvitee> { self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into()); InviteBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: self.__unsafe_private_named, _phantom: ::core::marker::PhantomData, } } } impl<'a, S: invite_state::State> InviteBuilder<'a, S> { /// Set the `message` field (optional) pub fn message( mut self, value: impl Into>>, ) -> Self { self.__unsafe_private_named.3 = value.into(); self } /// Set the `message` field to an Option value (optional) pub fn maybe_message(mut self, value: Option>) -> Self { self.__unsafe_private_named.3 = value; self } } impl<'a, S> InviteBuilder<'a, S> where S: invite_state::State, S::Resource: invite_state::IsUnset, { /// Set the `resource` field (required) pub fn resource( mut self, value: impl Into>, ) -> InviteBuilder<'a, invite_state::SetResource> { self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into()); InviteBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: self.__unsafe_private_named, _phantom: ::core::marker::PhantomData, } } } impl<'a, S: invite_state::State> InviteBuilder<'a, S> { /// Set the `scope` field (optional) pub fn scope( mut self, value: impl Into>>, ) -> Self { self.__unsafe_private_named.5 = value.into(); self } /// Set the `scope` field to an Option value (optional) pub fn maybe_scope( mut self, value: Option>, ) -> Self { self.__unsafe_private_named.5 = value; self } } impl<'a, S> InviteBuilder<'a, S> where S: invite_state::State, S::Resource: invite_state::IsSet, S::CreatedAt: invite_state::IsSet, S::Invitee: invite_state::IsSet, { /// Build the final struct pub fn build(self) -> Invite<'a> { Invite { created_at: self.__unsafe_private_named.0.unwrap(), expires_at: self.__unsafe_private_named.1, invitee: self.__unsafe_private_named.2.unwrap(), message: self.__unsafe_private_named.3, resource: self.__unsafe_private_named.4.unwrap(), scope: self.__unsafe_private_named.5, extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: std::collections::BTreeMap< jacquard_common::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> Invite<'a> { Invite { created_at: self.__unsafe_private_named.0.unwrap(), expires_at: self.__unsafe_private_named.1, invitee: self.__unsafe_private_named.2.unwrap(), message: self.__unsafe_private_named.3, resource: self.__unsafe_private_named.4.unwrap(), scope: self.__unsafe_private_named.5, extra_data: Some(extra_data), } } } impl<'a> Invite<'a> { pub fn uri( uri: impl Into>, ) -> Result< jacquard_common::types::uri::RecordUri<'a, InviteRecord>, jacquard_common::types::uri::UriError, > { jacquard_common::types::uri::RecordUri::try_from_uri( jacquard_common::types::string::AtUri::new_cow(uri.into())?, ) } } /// Typed wrapper for GetRecord response with this collection's record type. #[derive( serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, jacquard_derive::IntoStatic )] #[serde(rename_all = "camelCase")] pub struct InviteGetRecordOutput<'a> { #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub cid: std::option::Option>, #[serde(borrow)] pub uri: jacquard_common::types::string::AtUri<'a>, #[serde(borrow)] pub value: Invite<'a>, } impl From> for Invite<'_> { fn from(output: InviteGetRecordOutput<'_>) -> Self { use jacquard_common::IntoStatic; output.value.into_static() } } impl jacquard_common::types::collection::Collection for Invite<'_> { const NSID: &'static str = "sh.weaver.collab.invite"; type Record = InviteRecord; } /// Marker type for deserializing records from this collection. #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct InviteRecord; impl jacquard_common::xrpc::XrpcResp for InviteRecord { const NSID: &'static str = "sh.weaver.collab.invite"; const ENCODING: &'static str = "application/json"; type Output<'de> = InviteGetRecordOutput<'de>; type Err<'de> = jacquard_common::types::collection::RecordError<'de>; } impl jacquard_common::types::collection::Collection for InviteRecord { const NSID: &'static str = "sh.weaver.collab.invite"; type Record = InviteRecord; } impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Invite<'a> { fn nsid() -> &'static str { "sh.weaver.collab.invite" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { lexicon_doc_sh_weaver_collab_invite() } fn validate( &self, ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { if let Some(ref value) = self.message { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 3000usize { return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength { path: ::jacquard_lexicon::validation::ValidationPath::from_field( "message", ), max: 3000usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.message { { let count = ::unicode_segmentation::UnicodeSegmentation::graphemes( value.as_ref(), true, ) .count(); if count > 300usize { return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes { path: ::jacquard_lexicon::validation::ValidationPath::from_field( "message", ), max: 300usize, actual: count, }); } } } Ok(()) } } fn lexicon_doc_sh_weaver_collab_invite() -> ::jacquard_lexicon::lexicon::LexiconDoc< 'static, > { ::jacquard_lexicon::lexicon::LexiconDoc { lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, id: ::jacquard_common::CowStr::new_static("sh.weaver.collab.invite"), revision: None, description: None, defs: { let mut map = ::alloc::collections::BTreeMap::new(); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("collabScope"), ::jacquard_lexicon::lexicon::LexUserType::String(::jacquard_lexicon::lexicon::LexString { description: Some( ::jacquard_common::CowStr::new_static( "The scope/type of collaboration.", ), ), format: None, default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("main"), ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { description: Some( ::jacquard_common::CowStr::new_static( "Invitation to collaborate on a resource (notebook, entry, chapter, etc.). Creates half of a two-way agreement.", ), ), key: Some(::jacquard_common::CowStr::new_static("tid")), record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { description: None, required: Some( vec![ ::jacquard_common::smol_str::SmolStr::new_static("resource"), ::jacquard_common::smol_str::SmolStr::new_static("invitee"), ::jacquard_common::smol_str::SmolStr::new_static("createdAt") ], ), nullable: None, properties: { #[allow(unused_mut)] let mut map = ::alloc::collections::BTreeMap::new(); map.insert( ::jacquard_common::smol_str::SmolStr::new_static( "createdAt", ), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: None, format: Some( ::jacquard_lexicon::lexicon::LexStringFormat::Datetime, ), default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static( "expiresAt", ), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: Some( ::jacquard_common::CowStr::new_static( "Optional expiration for the invite.", ), ), format: Some( ::jacquard_lexicon::lexicon::LexStringFormat::Datetime, ), default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("invitee"), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: Some( ::jacquard_common::CowStr::new_static( "DID of the user being invited.", ), ), format: Some( ::jacquard_lexicon::lexicon::LexStringFormat::Did, ), default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("message"), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: Some( ::jacquard_common::CowStr::new_static( "Optional message to the invitee.", ), ), format: None, default: None, min_length: None, max_length: Some(3000usize), min_graphemes: None, max_graphemes: Some(300usize), r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static( "resource", ), ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { description: None, r#ref: ::jacquard_common::CowStr::new_static( "com.atproto.repo.strongRef", ), }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("scope"), ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { description: None, r#ref: ::jacquard_common::CowStr::new_static("#collabScope"), }), ); map }, }), }), ); map }, } }