#[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::string::{Did, Nsid};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::at_inlay::Element;
use crate::at_inlay::Response;
#[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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct List<S: BosStr = DefaultStr> {
pub did: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input: Option<Data<S>>,
pub query: Nsid<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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ListOutput<S: BosStr = DefaultStr> {
#[serde(flatten)]
pub value: Response<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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Page<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<S>,
pub items: Vec<Element<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
pub struct ListResponse;
impl jacquard_common::xrpc::XrpcResp for ListResponse {
const NSID: &'static str = "org.atsui.List";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ListOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for List<S> {
const NSID: &'static str = "org.atsui.List";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Response = ListResponse;
}
pub struct ListRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListRequest {
const PATH: &'static str = "/xrpc/org.atsui.List";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Request<S: BosStr> = List<S>;
type Response = ListResponse;
}
impl<S: BosStr> LexiconSchema for Page<S> {
fn nsid() -> &'static str {
"org.atsui.List"
}
fn def_name() -> &'static str {
"page"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_atsui_List()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.cursor {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("cursor"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod list_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 Query;
type Did;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Query = Unset;
type Did = Unset;
}
pub struct SetQuery<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetQuery<St> {}
impl<St: State> State for SetQuery<St> {
type Query = Set<members::query>;
type Did = St::Did;
}
pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDid<St> {}
impl<St: State> State for SetDid<St> {
type Query = St::Query;
type Did = Set<members::did>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct query(());
pub struct did(());
}
}
pub struct ListBuilder<S: BosStr, St: list_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Did<S>>, Option<Data<S>>, Option<Nsid<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> List<S> {
pub fn new() -> ListBuilder<S, list_state::Empty> {
ListBuilder::new()
}
}
impl<S: BosStr> ListBuilder<S, list_state::Empty> {
pub fn new() -> Self {
ListBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ListBuilder<S, St>
where
St: list_state::State,
St::Did: list_state::IsUnset,
{
pub fn did(mut self, value: impl Into<Did<S>>) -> ListBuilder<S, list_state::SetDid<St>> {
self._fields.0 = Option::Some(value.into());
ListBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: list_state::State> ListBuilder<S, St> {
pub fn input(mut self, value: impl Into<Option<Data<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_input(mut self, value: Option<Data<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ListBuilder<S, St>
where
St: list_state::State,
St::Query: list_state::IsUnset,
{
pub fn query(mut self, value: impl Into<Nsid<S>>) -> ListBuilder<S, list_state::SetQuery<St>> {
self._fields.2 = Option::Some(value.into());
ListBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ListBuilder<S, St>
where
St: list_state::State,
St::Query: list_state::IsSet,
St::Did: list_state::IsSet,
{
pub fn build(self) -> List<S> {
List {
did: self._fields.0.unwrap(),
input: self._fields.1,
query: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> List<S> {
List {
did: self._fields.0.unwrap(),
input: self._fields.1,
query: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod page_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 Items;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Items = Unset;
}
pub struct SetItems<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetItems<St> {}
impl<St: State> State for SetItems<St> {
type Items = Set<members::items>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct items(());
}
}
pub struct PageBuilder<S: BosStr, St: page_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<Vec<Element<S>>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Page<S> {
pub fn new() -> PageBuilder<S, page_state::Empty> {
PageBuilder::new()
}
}
impl<S: BosStr> PageBuilder<S, page_state::Empty> {
pub fn new() -> Self {
PageBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: page_state::State> PageBuilder<S, St> {
pub fn cursor(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_cursor(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> PageBuilder<S, St>
where
St: page_state::State,
St::Items: page_state::IsUnset,
{
pub fn items(
mut self,
value: impl Into<Vec<Element<S>>>,
) -> PageBuilder<S, page_state::SetItems<St>> {
self._fields.1 = Option::Some(value.into());
PageBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PageBuilder<S, St>
where
St: page_state::State,
St::Items: page_state::IsSet,
{
pub fn build(self) -> Page<S> {
Page {
cursor: self._fields.0,
items: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Page<S> {
Page {
cursor: self._fields.0,
items: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_atsui_List() -> 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("org.atsui.List"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::XrpcProcedure(LexXrpcProcedure {
input: Some(LexXrpcBody {
encoding: CowStr::new_static("application/json"),
schema: Some(LexXrpcBodySchema::Object(LexObject {
required: Some(vec![
SmolStr::new_static("query"),
SmolStr::new_static("did"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("did"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"DID of the service that implements the query.",
)),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("input"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("query"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"XRPC query to call for pages of items.",
)),
format: Some(LexStringFormat::Nsid),
..Default::default()
}),
);
map
},
..Default::default()
})),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("page"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static(
"Response shape from a List data source query.",
)),
required: Some(vec![SmolStr::new_static("items")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("cursor"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Opaque pagination token. Absent means no more items.",
)),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("items"),
LexObjectProperty::Array(LexArray {
description: Some(CowStr::new_static(
"Elements to render as list rows.",
)),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("at.inlay.defs#element"),
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}