atproto blogging
at main 255 lines 9.0 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: com.atproto.lexicon.schema 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8/// Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc). 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 Schema<'a> { 21 /// Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system. 22 pub lexicon: i64, 23} 24 25pub mod schema_state { 26 27 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 28 #[allow(unused)] 29 use ::core::marker::PhantomData; 30 mod sealed { 31 pub trait Sealed {} 32 } 33 /// State trait tracking which required fields have been set 34 pub trait State: sealed::Sealed { 35 type Lexicon; 36 } 37 /// Empty state - all required fields are unset 38 pub struct Empty(()); 39 impl sealed::Sealed for Empty {} 40 impl State for Empty { 41 type Lexicon = Unset; 42 } 43 ///State transition - sets the `lexicon` field to Set 44 pub struct SetLexicon<S: State = Empty>(PhantomData<fn() -> S>); 45 impl<S: State> sealed::Sealed for SetLexicon<S> {} 46 impl<S: State> State for SetLexicon<S> { 47 type Lexicon = Set<members::lexicon>; 48 } 49 /// Marker types for field names 50 #[allow(non_camel_case_types)] 51 pub mod members { 52 ///Marker type for the `lexicon` field 53 pub struct lexicon(()); 54 } 55} 56 57/// Builder for constructing an instance of this type 58pub struct SchemaBuilder<'a, S: schema_state::State> { 59 _phantom_state: ::core::marker::PhantomData<fn() -> S>, 60 __unsafe_private_named: (::core::option::Option<i64>,), 61 _phantom: ::core::marker::PhantomData<&'a ()>, 62} 63 64impl<'a> Schema<'a> { 65 /// Create a new builder for this type 66 pub fn new() -> SchemaBuilder<'a, schema_state::Empty> { 67 SchemaBuilder::new() 68 } 69} 70 71impl<'a> SchemaBuilder<'a, schema_state::Empty> { 72 /// Create a new builder with all fields unset 73 pub fn new() -> Self { 74 SchemaBuilder { 75 _phantom_state: ::core::marker::PhantomData, 76 __unsafe_private_named: (None,), 77 _phantom: ::core::marker::PhantomData, 78 } 79 } 80} 81 82impl<'a, S> SchemaBuilder<'a, S> 83where 84 S: schema_state::State, 85 S::Lexicon: schema_state::IsUnset, 86{ 87 /// Set the `lexicon` field (required) 88 pub fn lexicon( 89 mut self, 90 value: impl Into<i64>, 91 ) -> SchemaBuilder<'a, schema_state::SetLexicon<S>> { 92 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into()); 93 SchemaBuilder { 94 _phantom_state: ::core::marker::PhantomData, 95 __unsafe_private_named: self.__unsafe_private_named, 96 _phantom: ::core::marker::PhantomData, 97 } 98 } 99} 100 101impl<'a, S> SchemaBuilder<'a, S> 102where 103 S: schema_state::State, 104 S::Lexicon: schema_state::IsSet, 105{ 106 /// Build the final struct 107 pub fn build(self) -> Schema<'a> { 108 Schema { 109 lexicon: self.__unsafe_private_named.0.unwrap(), 110 extra_data: Default::default(), 111 } 112 } 113 /// Build the final struct with custom extra_data 114 pub fn build_with_data( 115 self, 116 extra_data: std::collections::BTreeMap< 117 jacquard_common::smol_str::SmolStr, 118 jacquard_common::types::value::Data<'a>, 119 >, 120 ) -> Schema<'a> { 121 Schema { 122 lexicon: self.__unsafe_private_named.0.unwrap(), 123 extra_data: Some(extra_data), 124 } 125 } 126} 127 128impl<'a> Schema<'a> { 129 pub fn uri( 130 uri: impl Into<jacquard_common::CowStr<'a>>, 131 ) -> Result< 132 jacquard_common::types::uri::RecordUri<'a, SchemaRecord>, 133 jacquard_common::types::uri::UriError, 134 > { 135 jacquard_common::types::uri::RecordUri::try_from_uri( 136 jacquard_common::types::string::AtUri::new_cow(uri.into())?, 137 ) 138 } 139} 140 141/// Typed wrapper for GetRecord response with this collection's record type. 142#[derive( 143 serde::Serialize, 144 serde::Deserialize, 145 Debug, 146 Clone, 147 PartialEq, 148 Eq, 149 jacquard_derive::IntoStatic 150)] 151#[serde(rename_all = "camelCase")] 152pub struct SchemaGetRecordOutput<'a> { 153 #[serde(skip_serializing_if = "std::option::Option::is_none")] 154 #[serde(borrow)] 155 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>, 156 #[serde(borrow)] 157 pub uri: jacquard_common::types::string::AtUri<'a>, 158 #[serde(borrow)] 159 pub value: Schema<'a>, 160} 161 162impl From<SchemaGetRecordOutput<'_>> for Schema<'_> { 163 fn from(output: SchemaGetRecordOutput<'_>) -> Self { 164 use jacquard_common::IntoStatic; 165 output.value.into_static() 166 } 167} 168 169impl jacquard_common::types::collection::Collection for Schema<'_> { 170 const NSID: &'static str = "com.atproto.lexicon.schema"; 171 type Record = SchemaRecord; 172} 173 174/// Marker type for deserializing records from this collection. 175#[derive(Debug, serde::Serialize, serde::Deserialize)] 176pub struct SchemaRecord; 177impl jacquard_common::xrpc::XrpcResp for SchemaRecord { 178 const NSID: &'static str = "com.atproto.lexicon.schema"; 179 const ENCODING: &'static str = "application/json"; 180 type Output<'de> = SchemaGetRecordOutput<'de>; 181 type Err<'de> = jacquard_common::types::collection::RecordError<'de>; 182} 183 184impl jacquard_common::types::collection::Collection for SchemaRecord { 185 const NSID: &'static str = "com.atproto.lexicon.schema"; 186 type Record = SchemaRecord; 187} 188 189impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Schema<'a> { 190 fn nsid() -> &'static str { 191 "com.atproto.lexicon.schema" 192 } 193 fn def_name() -> &'static str { 194 "main" 195 } 196 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { 197 lexicon_doc_com_atproto_lexicon_schema() 198 } 199 fn validate( 200 &self, 201 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { 202 Ok(()) 203 } 204} 205 206fn lexicon_doc_com_atproto_lexicon_schema() -> ::jacquard_lexicon::lexicon::LexiconDoc< 207 'static, 208> { 209 ::jacquard_lexicon::lexicon::LexiconDoc { 210 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, 211 id: ::jacquard_common::CowStr::new_static("com.atproto.lexicon.schema"), 212 revision: None, 213 description: None, 214 defs: { 215 let mut map = ::alloc::collections::BTreeMap::new(); 216 map.insert( 217 ::jacquard_common::smol_str::SmolStr::new_static("main"), 218 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { 219 description: Some( 220 ::jacquard_common::CowStr::new_static( 221 "Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc).", 222 ), 223 ), 224 key: Some(::jacquard_common::CowStr::new_static("nsid")), 225 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { 226 description: None, 227 required: Some( 228 vec![ 229 ::jacquard_common::smol_str::SmolStr::new_static("lexicon") 230 ], 231 ), 232 nullable: None, 233 properties: { 234 #[allow(unused_mut)] 235 let mut map = ::alloc::collections::BTreeMap::new(); 236 map.insert( 237 ::jacquard_common::smol_str::SmolStr::new_static("lexicon"), 238 ::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger { 239 description: None, 240 default: None, 241 minimum: None, 242 maximum: None, 243 r#enum: None, 244 r#const: None, 245 }), 246 ); 247 map 248 }, 249 }), 250 }), 251 ); 252 map 253 }, 254 } 255}