#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::AtUri;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::sh_tangled::git::temp::Blob;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetEntity<'a> {
#[serde(borrow)]
pub path: CowStr<'a>,
#[serde(default = "_default_ref")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub r#ref: Option<CowStr<'a>>,
#[serde(borrow)]
pub repo: AtUri<'a>,
}
#[jacquard_derive::lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetEntityOutput<'a> {
#[serde(flatten)]
#[serde(borrow)]
pub value: Blob<'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 GetEntityError<'a> {
#[serde(rename = "RepoNotFound")]
RepoNotFound(Option<CowStr<'a>>),
#[serde(rename = "BlobNotFound")]
BlobNotFound(Option<CowStr<'a>>),
#[serde(rename = "InvalidRequest")]
InvalidRequest(Option<CowStr<'a>>),
}
impl core::fmt::Display for GetEntityError<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::RepoNotFound(msg) => {
write!(f, "RepoNotFound")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::BlobNotFound(msg) => {
write!(f, "BlobNotFound")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::InvalidRequest(msg) => {
write!(f, "InvalidRequest")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
pub struct GetEntityResponse;
impl jacquard_common::xrpc::XrpcResp for GetEntityResponse {
const NSID: &'static str = "sh.tangled.git.temp.getEntity";
const ENCODING: &'static str = "application/json";
type Output<'de> = GetEntityOutput<'de>;
type Err<'de> = GetEntityError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for GetEntity<'a> {
const NSID: &'static str = "sh.tangled.git.temp.getEntity";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Response = GetEntityResponse;
}
pub struct GetEntityRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetEntityRequest {
const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getEntity";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Request<'de> = GetEntity<'de>;
type Response = GetEntityResponse;
}
fn _default_ref() -> Option<CowStr<'static>> {
Some(CowStr::from("HEAD"))
}
pub mod get_entity_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 Repo;
type Path;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Repo = Unset;
type Path = Unset;
}
pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRepo<S> {}
impl<S: State> State for SetRepo<S> {
type Repo = Set<members::repo>;
type Path = S::Path;
}
pub struct SetPath<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPath<S> {}
impl<S: State> State for SetPath<S> {
type Repo = S::Repo;
type Path = Set<members::path>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct repo(());
pub struct path(());
}
}
pub struct GetEntityBuilder<'a, S: get_entity_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<AtUri<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> GetEntity<'a> {
pub fn new() -> GetEntityBuilder<'a, get_entity_state::Empty> {
GetEntityBuilder::new()
}
}
impl<'a> GetEntityBuilder<'a, get_entity_state::Empty> {
pub fn new() -> Self {
GetEntityBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> GetEntityBuilder<'a, S>
where
S: get_entity_state::State,
S::Path: get_entity_state::IsUnset,
{
pub fn path(
mut self,
value: impl Into<CowStr<'a>>,
) -> GetEntityBuilder<'a, get_entity_state::SetPath<S>> {
self._fields.0 = Option::Some(value.into());
GetEntityBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: get_entity_state::State> GetEntityBuilder<'a, S> {
pub fn r#ref(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_ref(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> GetEntityBuilder<'a, S>
where
S: get_entity_state::State,
S::Repo: get_entity_state::IsUnset,
{
pub fn repo(
mut self,
value: impl Into<AtUri<'a>>,
) -> GetEntityBuilder<'a, get_entity_state::SetRepo<S>> {
self._fields.2 = Option::Some(value.into());
GetEntityBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GetEntityBuilder<'a, S>
where
S: get_entity_state::State,
S::Repo: get_entity_state::IsSet,
S::Path: get_entity_state::IsSet,
{
pub fn build(self) -> GetEntity<'a> {
GetEntity {
path: self._fields.0.unwrap(),
r#ref: self._fields.1,
repo: self._fields.2.unwrap(),
}
}
}