#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Nsid, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::garden_lexicon::service;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Service<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub methods: Option<Vec<service::Method<'a>>>,
#[serde(borrow)]
pub service_type: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub url_templates: Option<Vec<service::UrlTemplate<'a>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ServiceGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Service<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Method<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub auth_methods: Option<Vec<CowStr<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<bool>,
#[serde(borrow)]
pub lexicon: AtUri<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct UrlTemplate<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub collections: Option<Vec<Nsid<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(borrow)]
pub url: CowStr<'a>,
}
impl<'a> Service<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, ServiceRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ServiceRecord;
impl XrpcResp for ServiceRecord {
const NSID: &'static str = "garden.lexicon.service";
const ENCODING: &'static str = "application/json";
type Output<'de> = ServiceGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<ServiceGetRecordOutput<'_>> for Service<'_> {
fn from(output: ServiceGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Service<'_> {
const NSID: &'static str = "garden.lexicon.service";
type Record = ServiceRecord;
}
impl Collection for ServiceRecord {
const NSID: &'static str = "garden.lexicon.service";
type Record = ServiceRecord;
}
impl<'a> LexiconSchema for Service<'a> {
fn nsid() -> &'static str {
"garden.lexicon.service"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_service()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.service_type;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("service_type"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for Method<'a> {
fn nsid() -> &'static str {
"garden.lexicon.service"
}
fn def_name() -> &'static str {
"method"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_service()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<'a> LexiconSchema for UrlTemplate<'a> {
fn nsid() -> &'static str {
"garden.lexicon.service"
}
fn def_name() -> &'static str {
"urlTemplate"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_service()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.url;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("url"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod service_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type ServiceType;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type ServiceType = Unset;
}
pub struct SetServiceType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetServiceType<S> {}
impl<S: State> State for SetServiceType<S> {
type ServiceType = Set<members::service_type>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct service_type(());
}
}
pub struct ServiceBuilder<'a, S: service_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Vec<service::Method<'a>>>,
Option<CowStr<'a>>,
Option<Vec<service::UrlTemplate<'a>>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Service<'a> {
pub fn new() -> ServiceBuilder<'a, service_state::Empty> {
ServiceBuilder::new()
}
}
impl<'a> ServiceBuilder<'a, service_state::Empty> {
pub fn new() -> Self {
ServiceBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: service_state::State> ServiceBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: service_state::State> ServiceBuilder<'a, S> {
pub fn methods(
mut self,
value: impl Into<Option<Vec<service::Method<'a>>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_methods(mut self, value: Option<Vec<service::Method<'a>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> ServiceBuilder<'a, S>
where
S: service_state::State,
S::ServiceType: service_state::IsUnset,
{
pub fn service_type(
mut self,
value: impl Into<CowStr<'a>>,
) -> ServiceBuilder<'a, service_state::SetServiceType<S>> {
self._fields.2 = Option::Some(value.into());
ServiceBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: service_state::State> ServiceBuilder<'a, S> {
pub fn url_templates(
mut self,
value: impl Into<Option<Vec<service::UrlTemplate<'a>>>>,
) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_url_templates(
mut self,
value: Option<Vec<service::UrlTemplate<'a>>>,
) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> ServiceBuilder<'a, S>
where
S: service_state::State,
S::ServiceType: service_state::IsSet,
{
pub fn build(self) -> Service<'a> {
Service {
description: self._fields.0,
methods: self._fields.1,
service_type: self._fields.2.unwrap(),
url_templates: self._fields.3,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Service<'a> {
Service {
description: self._fields.0,
methods: self._fields.1,
service_type: self._fields.2.unwrap(),
url_templates: self._fields.3,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_garden_lexicon_service() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("garden.lexicon.service"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Declares XRPC methods available on a DID document service. The rkey is the service fragment ID without the # prefix (e.g., 'atproto_pds' for '#atproto_pds').",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(vec![SmolStr::new_static("serviceType")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Description of what this service provides.",
),
),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("methods"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Methods available on this service."),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#method"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("serviceType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The type of service being declared."),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("urlTemplates"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"URL templates for constructing web URLs from AT-URIs or record data. Useful for linking to web views of records.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#urlTemplate"),
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("method"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("lexicon")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("authMethods"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Authentication methods supported by this method.",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(50usize),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("deprecated"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("lexicon"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI pointing to a lexicon schema that defines this method.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("urlTemplate"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("url")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("collections"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"NSIDs of collections this URL template applies to.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::Nsid),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Description of what this URL template is for.",
),
),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URI template with placeholders for record data",
),
),
max_length: Some(2000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod method_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Lexicon;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Lexicon = Unset;
}
pub struct SetLexicon<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLexicon<S> {}
impl<S: State> State for SetLexicon<S> {
type Lexicon = Set<members::lexicon>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct lexicon(());
}
}
pub struct MethodBuilder<'a, S: method_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Vec<CowStr<'a>>>, Option<bool>, Option<AtUri<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Method<'a> {
pub fn new() -> MethodBuilder<'a, method_state::Empty> {
MethodBuilder::new()
}
}
impl<'a> MethodBuilder<'a, method_state::Empty> {
pub fn new() -> Self {
MethodBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: method_state::State> MethodBuilder<'a, S> {
pub fn auth_methods(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_auth_methods(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: method_state::State> MethodBuilder<'a, S> {
pub fn deprecated(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_deprecated(mut self, value: Option<bool>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> MethodBuilder<'a, S>
where
S: method_state::State,
S::Lexicon: method_state::IsUnset,
{
pub fn lexicon(
mut self,
value: impl Into<AtUri<'a>>,
) -> MethodBuilder<'a, method_state::SetLexicon<S>> {
self._fields.2 = Option::Some(value.into());
MethodBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> MethodBuilder<'a, S>
where
S: method_state::State,
S::Lexicon: method_state::IsSet,
{
pub fn build(self) -> Method<'a> {
Method {
auth_methods: self._fields.0,
deprecated: self._fields.1,
lexicon: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Method<'a> {
Method {
auth_methods: self._fields.0,
deprecated: self._fields.1,
lexicon: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}