#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Nsid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::garden_lexicon::service;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "garden.lexicon.service",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Service<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub methods: Option<Vec<service::Method<S>>>,
pub service_type: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub url_templates: Option<Vec<service::UrlTemplate<S>>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ServiceGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Service<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Method<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_methods: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<bool>,
pub lexicon: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct UrlTemplate<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub collections: Option<Vec<Nsid<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub url: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Service<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ServiceRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[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<S: BosStr> = ServiceGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ServiceGetRecordOutput<S>> for Service<S> {
fn from(output: ServiceGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Service<S> {
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<S: BosStr> LexiconSchema for Service<S> {
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<S: BosStr> LexiconSchema for Method<S> {
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<S: BosStr> LexiconSchema for UrlTemplate<S> {
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::{IsSet, IsUnset, Set, Unset};
#[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<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetServiceType<St> {}
impl<St: State> State for SetServiceType<St> {
type ServiceType = Set<members::service_type>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct service_type(());
}
}
pub struct ServiceBuilder<S: BosStr, St: service_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Vec<service::Method<S>>>,
Option<S>,
Option<Vec<service::UrlTemplate<S>>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Service<S> {
pub fn new() -> ServiceBuilder<S, service_state::Empty> {
ServiceBuilder::new()
}
}
impl<S: BosStr> ServiceBuilder<S, service_state::Empty> {
pub fn new() -> Self {
ServiceBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: service_state::State> ServiceBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: service_state::State> ServiceBuilder<S, St> {
pub fn methods(mut self, value: impl Into<Option<Vec<service::Method<S>>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_methods(mut self, value: Option<Vec<service::Method<S>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ServiceBuilder<S, St>
where
St: service_state::State,
St::ServiceType: service_state::IsUnset,
{
pub fn service_type(
mut self,
value: impl Into<S>,
) -> ServiceBuilder<S, service_state::SetServiceType<St>> {
self._fields.2 = Option::Some(value.into());
ServiceBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: service_state::State> ServiceBuilder<S, St> {
pub fn url_templates(mut self, value: impl Into<Option<Vec<service::UrlTemplate<S>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_url_templates(mut self, value: Option<Vec<service::UrlTemplate<S>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> ServiceBuilder<S, St>
where
St: service_state::State,
St::ServiceType: service_state::IsSet,
{
pub fn build(self) -> Service<S> {
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<SmolStr, Data<S>>) -> Service<S> {
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> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
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::{IsSet, IsUnset, Set, Unset};
#[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<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLexicon<St> {}
impl<St: State> State for SetLexicon<St> {
type Lexicon = Set<members::lexicon>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct lexicon(());
}
}
pub struct MethodBuilder<S: BosStr, St: method_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<S>>, Option<bool>, Option<AtUri<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Method<S> {
pub fn new() -> MethodBuilder<S, method_state::Empty> {
MethodBuilder::new()
}
}
impl<S: BosStr> MethodBuilder<S, method_state::Empty> {
pub fn new() -> Self {
MethodBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: method_state::State> MethodBuilder<S, St> {
pub fn auth_methods(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_auth_methods(mut self, value: Option<Vec<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: method_state::State> MethodBuilder<S, St> {
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<S: BosStr, St> MethodBuilder<S, St>
where
St: method_state::State,
St::Lexicon: method_state::IsUnset,
{
pub fn lexicon(
mut self,
value: impl Into<AtUri<S>>,
) -> MethodBuilder<S, method_state::SetLexicon<St>> {
self._fields.2 = Option::Some(value.into());
MethodBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> MethodBuilder<S, St>
where
St: method_state::State,
St::Lexicon: method_state::IsSet,
{
pub fn build(self) -> Method<S> {
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<SmolStr, Data<S>>) -> Method<S> {
Method {
auth_methods: self._fields.0,
deprecated: self._fields.1,
lexicon: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}