#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ResolveSchema<'a> {
#[serde(borrow)]
pub handle: CowStr<'a>,
#[serde(borrow)]
pub schema_id: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub version: Option<CowStr<'a>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ResolveSchemaOutput<'a> {
#[serde(borrow)]
pub cid: CowStr<'a>,
#[serde(borrow)]
pub record: Data<'a>,
#[serde(borrow)]
pub uri: AtUri<'a>,
}
#[open_union]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic,
IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ResolveSchemaError<'a> {
#[serde(rename = "SchemaNotFound")]
SchemaNotFound(Option<CowStr<'a>>),
}
impl core::fmt::Display for ResolveSchemaError<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::SchemaNotFound(msg) => {
write!(f, "SchemaNotFound")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
pub struct ResolveSchemaResponse;
impl jacquard_common::xrpc::XrpcResp for ResolveSchemaResponse {
const NSID: &'static str = "science.alt.dataset.resolveSchema";
const ENCODING: &'static str = "application/json";
type Output<'de> = ResolveSchemaOutput<'de>;
type Err<'de> = ResolveSchemaError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for ResolveSchema<'a> {
const NSID: &'static str = "science.alt.dataset.resolveSchema";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Response = ResolveSchemaResponse;
}
pub struct ResolveSchemaRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ResolveSchemaRequest {
const PATH: &'static str = "/xrpc/science.alt.dataset.resolveSchema";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Request<'de> = ResolveSchema<'de>;
type Response = ResolveSchemaResponse;
}
pub mod resolve_schema_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 SchemaId;
type Handle;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type SchemaId = Unset;
type Handle = Unset;
}
pub struct SetSchemaId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSchemaId<S> {}
impl<S: State> State for SetSchemaId<S> {
type SchemaId = Set<members::schema_id>;
type Handle = S::Handle;
}
pub struct SetHandle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetHandle<S> {}
impl<S: State> State for SetHandle<S> {
type SchemaId = S::SchemaId;
type Handle = Set<members::handle>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct schema_id(());
pub struct handle(());
}
}
pub struct ResolveSchemaBuilder<'a, S: resolve_schema_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> ResolveSchema<'a> {
pub fn new() -> ResolveSchemaBuilder<'a, resolve_schema_state::Empty> {
ResolveSchemaBuilder::new()
}
}
impl<'a> ResolveSchemaBuilder<'a, resolve_schema_state::Empty> {
pub fn new() -> Self {
ResolveSchemaBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ResolveSchemaBuilder<'a, S>
where
S: resolve_schema_state::State,
S::Handle: resolve_schema_state::IsUnset,
{
pub fn handle(
mut self,
value: impl Into<CowStr<'a>>,
) -> ResolveSchemaBuilder<'a, resolve_schema_state::SetHandle<S>> {
self._fields.0 = Option::Some(value.into());
ResolveSchemaBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ResolveSchemaBuilder<'a, S>
where
S: resolve_schema_state::State,
S::SchemaId: resolve_schema_state::IsUnset,
{
pub fn schema_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> ResolveSchemaBuilder<'a, resolve_schema_state::SetSchemaId<S>> {
self._fields.1 = Option::Some(value.into());
ResolveSchemaBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: resolve_schema_state::State> ResolveSchemaBuilder<'a, S> {
pub fn version(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_version(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> ResolveSchemaBuilder<'a, S>
where
S: resolve_schema_state::State,
S::SchemaId: resolve_schema_state::IsSet,
S::Handle: resolve_schema_state::IsSet,
{
pub fn build(self) -> ResolveSchema<'a> {
ResolveSchema {
handle: self._fields.0.unwrap(),
schema_id: self._fields.1.unwrap(),
version: self._fields.2,
}
}
}