Skip to main content

jacquard_api/sh_tangled/git/temp/
get_entity.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.git.temp.getEntity
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::types::string::AtUri;
12use jacquard_derive::{IntoStatic, open_union};
13use serde::{Serialize, Deserialize};
14use crate::sh_tangled::git::temp::Blob;
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetEntity<'a> {
19    #[serde(borrow)]
20    pub path: CowStr<'a>,
21    ///Defaults to `"HEAD"`.
22    #[serde(default = "_default_ref")]
23    #[serde(skip_serializing_if = "Option::is_none")]
24    #[serde(borrow)]
25    pub r#ref: Option<CowStr<'a>>,
26    #[serde(borrow)]
27    pub repo: AtUri<'a>,
28}
29
30
31#[jacquard_derive::lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(rename_all = "camelCase")]
34pub struct GetEntityOutput<'a> {
35    #[serde(flatten)]
36    #[serde(borrow)]
37    pub value: Blob<'a>,
38}
39
40
41#[open_union]
42#[derive(
43    Serialize,
44    Deserialize,
45    Debug,
46    Clone,
47    PartialEq,
48    Eq,
49    thiserror::Error,
50    miette::Diagnostic,
51    IntoStatic
52)]
53
54#[serde(tag = "error", content = "message")]
55#[serde(bound(deserialize = "'de: 'a"))]
56pub enum GetEntityError<'a> {
57    /// Repository not found or access denied
58    #[serde(rename = "RepoNotFound")]
59    RepoNotFound(Option<CowStr<'a>>),
60    /// Blob not found
61    #[serde(rename = "BlobNotFound")]
62    BlobNotFound(Option<CowStr<'a>>),
63    /// Invalid request parameters
64    #[serde(rename = "InvalidRequest")]
65    InvalidRequest(Option<CowStr<'a>>),
66}
67
68impl core::fmt::Display for GetEntityError<'_> {
69    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
70        match self {
71            Self::RepoNotFound(msg) => {
72                write!(f, "RepoNotFound")?;
73                if let Some(msg) = msg {
74                    write!(f, ": {}", msg)?;
75                }
76                Ok(())
77            }
78            Self::BlobNotFound(msg) => {
79                write!(f, "BlobNotFound")?;
80                if let Some(msg) = msg {
81                    write!(f, ": {}", msg)?;
82                }
83                Ok(())
84            }
85            Self::InvalidRequest(msg) => {
86                write!(f, "InvalidRequest")?;
87                if let Some(msg) = msg {
88                    write!(f, ": {}", msg)?;
89                }
90                Ok(())
91            }
92            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
93        }
94    }
95}
96
97/// Response type for sh.tangled.git.temp.getEntity
98pub struct GetEntityResponse;
99impl jacquard_common::xrpc::XrpcResp for GetEntityResponse {
100    const NSID: &'static str = "sh.tangled.git.temp.getEntity";
101    const ENCODING: &'static str = "application/json";
102    type Output<'de> = GetEntityOutput<'de>;
103    type Err<'de> = GetEntityError<'de>;
104}
105
106impl<'a> jacquard_common::xrpc::XrpcRequest for GetEntity<'a> {
107    const NSID: &'static str = "sh.tangled.git.temp.getEntity";
108    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
109    type Response = GetEntityResponse;
110}
111
112/// Endpoint type for sh.tangled.git.temp.getEntity
113pub struct GetEntityRequest;
114impl jacquard_common::xrpc::XrpcEndpoint for GetEntityRequest {
115    const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getEntity";
116    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
117    type Request<'de> = GetEntity<'de>;
118    type Response = GetEntityResponse;
119}
120
121fn _default_ref() -> Option<CowStr<'static>> {
122    Some(CowStr::from("HEAD"))
123}
124
125pub mod get_entity_state {
126
127    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
128    #[allow(unused)]
129    use ::core::marker::PhantomData;
130    mod sealed {
131        pub trait Sealed {}
132    }
133    /// State trait tracking which required fields have been set
134    pub trait State: sealed::Sealed {
135        type Repo;
136        type Path;
137    }
138    /// Empty state - all required fields are unset
139    pub struct Empty(());
140    impl sealed::Sealed for Empty {}
141    impl State for Empty {
142        type Repo = Unset;
143        type Path = Unset;
144    }
145    ///State transition - sets the `repo` field to Set
146    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
147    impl<S: State> sealed::Sealed for SetRepo<S> {}
148    impl<S: State> State for SetRepo<S> {
149        type Repo = Set<members::repo>;
150        type Path = S::Path;
151    }
152    ///State transition - sets the `path` field to Set
153    pub struct SetPath<S: State = Empty>(PhantomData<fn() -> S>);
154    impl<S: State> sealed::Sealed for SetPath<S> {}
155    impl<S: State> State for SetPath<S> {
156        type Repo = S::Repo;
157        type Path = Set<members::path>;
158    }
159    /// Marker types for field names
160    #[allow(non_camel_case_types)]
161    pub mod members {
162        ///Marker type for the `repo` field
163        pub struct repo(());
164        ///Marker type for the `path` field
165        pub struct path(());
166    }
167}
168
169/// Builder for constructing an instance of this type
170pub struct GetEntityBuilder<'a, S: get_entity_state::State> {
171    _state: PhantomData<fn() -> S>,
172    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<AtUri<'a>>),
173    _lifetime: PhantomData<&'a ()>,
174}
175
176impl<'a> GetEntity<'a> {
177    /// Create a new builder for this type
178    pub fn new() -> GetEntityBuilder<'a, get_entity_state::Empty> {
179        GetEntityBuilder::new()
180    }
181}
182
183impl<'a> GetEntityBuilder<'a, get_entity_state::Empty> {
184    /// Create a new builder with all fields unset
185    pub fn new() -> Self {
186        GetEntityBuilder {
187            _state: PhantomData,
188            _fields: (None, None, None),
189            _lifetime: PhantomData,
190        }
191    }
192}
193
194impl<'a, S> GetEntityBuilder<'a, S>
195where
196    S: get_entity_state::State,
197    S::Path: get_entity_state::IsUnset,
198{
199    /// Set the `path` field (required)
200    pub fn path(
201        mut self,
202        value: impl Into<CowStr<'a>>,
203    ) -> GetEntityBuilder<'a, get_entity_state::SetPath<S>> {
204        self._fields.0 = Option::Some(value.into());
205        GetEntityBuilder {
206            _state: PhantomData,
207            _fields: self._fields,
208            _lifetime: PhantomData,
209        }
210    }
211}
212
213impl<'a, S: get_entity_state::State> GetEntityBuilder<'a, S> {
214    /// Set the `ref` field (optional)
215    pub fn r#ref(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
216        self._fields.1 = value.into();
217        self
218    }
219    /// Set the `ref` field to an Option value (optional)
220    pub fn maybe_ref(mut self, value: Option<CowStr<'a>>) -> Self {
221        self._fields.1 = value;
222        self
223    }
224}
225
226impl<'a, S> GetEntityBuilder<'a, S>
227where
228    S: get_entity_state::State,
229    S::Repo: get_entity_state::IsUnset,
230{
231    /// Set the `repo` field (required)
232    pub fn repo(
233        mut self,
234        value: impl Into<AtUri<'a>>,
235    ) -> GetEntityBuilder<'a, get_entity_state::SetRepo<S>> {
236        self._fields.2 = Option::Some(value.into());
237        GetEntityBuilder {
238            _state: PhantomData,
239            _fields: self._fields,
240            _lifetime: PhantomData,
241        }
242    }
243}
244
245impl<'a, S> GetEntityBuilder<'a, S>
246where
247    S: get_entity_state::State,
248    S::Repo: get_entity_state::IsSet,
249    S::Path: get_entity_state::IsSet,
250{
251    /// Build the final struct
252    pub fn build(self) -> GetEntity<'a> {
253        GetEntity {
254            path: self._fields.0.unwrap(),
255            r#ref: self._fields.1,
256            repo: self._fields.2.unwrap(),
257        }
258    }
259}