jacquard_api/sh_tangled/git/temp/
get_entity.rs1#[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 #[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 #[serde(rename = "RepoNotFound")]
59 RepoNotFound(Option<CowStr<'a>>),
60 #[serde(rename = "BlobNotFound")]
62 BlobNotFound(Option<CowStr<'a>>),
63 #[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
97pub 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
112pub 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 pub trait State: sealed::Sealed {
135 type Repo;
136 type Path;
137 }
138 pub struct Empty(());
140 impl sealed::Sealed for Empty {}
141 impl State for Empty {
142 type Repo = Unset;
143 type Path = Unset;
144 }
145 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 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 #[allow(non_camel_case_types)]
161 pub mod members {
162 pub struct repo(());
164 pub struct path(());
166 }
167}
168
169pub 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 pub fn new() -> GetEntityBuilder<'a, get_entity_state::Empty> {
179 GetEntityBuilder::new()
180 }
181}
182
183impl<'a> GetEntityBuilder<'a, get_entity_state::Empty> {
184 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 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 pub fn r#ref(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
216 self._fields.1 = value.into();
217 self
218 }
219 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 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 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}