jacquard_api/sh_tangled/git/temp/
get_archive.rs1#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::deps::bytes::Bytes;
12use jacquard_common::types::string::AtUri;
13use jacquard_derive::{IntoStatic, open_union};
14use serde::{Serialize, Deserialize};
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetArchive<'a> {
19 #[serde(default = "_default_format")]
21 #[serde(skip_serializing_if = "Option::is_none")]
22 #[serde(borrow)]
23 pub format: Option<CowStr<'a>>,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 #[serde(borrow)]
26 pub prefix: Option<CowStr<'a>>,
27 #[serde(borrow)]
28 pub r#ref: CowStr<'a>,
29 #[serde(borrow)]
30 pub repo: AtUri<'a>,
31}
32
33#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
36#[serde(rename_all = "camelCase")]
37pub struct GetArchiveOutput {
38 pub body: Bytes,
39}
40
41
42#[open_union]
43#[derive(
44 Serialize,
45 Deserialize,
46 Debug,
47 Clone,
48 PartialEq,
49 Eq,
50 thiserror::Error,
51 miette::Diagnostic,
52 IntoStatic
53)]
54
55#[serde(tag = "error", content = "message")]
56#[serde(bound(deserialize = "'de: 'a"))]
57pub enum GetArchiveError<'a> {
58 #[serde(rename = "RepoNotFound")]
60 RepoNotFound(Option<CowStr<'a>>),
61 #[serde(rename = "RefNotFound")]
63 RefNotFound(Option<CowStr<'a>>),
64 #[serde(rename = "InvalidRequest")]
66 InvalidRequest(Option<CowStr<'a>>),
67 #[serde(rename = "ArchiveError")]
69 ArchiveError(Option<CowStr<'a>>),
70}
71
72impl core::fmt::Display for GetArchiveError<'_> {
73 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74 match self {
75 Self::RepoNotFound(msg) => {
76 write!(f, "RepoNotFound")?;
77 if let Some(msg) = msg {
78 write!(f, ": {}", msg)?;
79 }
80 Ok(())
81 }
82 Self::RefNotFound(msg) => {
83 write!(f, "RefNotFound")?;
84 if let Some(msg) = msg {
85 write!(f, ": {}", msg)?;
86 }
87 Ok(())
88 }
89 Self::InvalidRequest(msg) => {
90 write!(f, "InvalidRequest")?;
91 if let Some(msg) = msg {
92 write!(f, ": {}", msg)?;
93 }
94 Ok(())
95 }
96 Self::ArchiveError(msg) => {
97 write!(f, "ArchiveError")?;
98 if let Some(msg) = msg {
99 write!(f, ": {}", msg)?;
100 }
101 Ok(())
102 }
103 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
104 }
105 }
106}
107
108pub struct GetArchiveResponse;
110impl jacquard_common::xrpc::XrpcResp for GetArchiveResponse {
111 const NSID: &'static str = "sh.tangled.git.temp.getArchive";
112 const ENCODING: &'static str = "*/*";
113 type Output<'de> = GetArchiveOutput;
114 type Err<'de> = GetArchiveError<'de>;
115 fn encode_output(
116 output: &Self::Output<'_>,
117 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
118 Ok(output.body.to_vec())
119 }
120 fn decode_output<'de>(
121 body: &'de [u8],
122 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
123 where
124 Self::Output<'de>: serde::Deserialize<'de>,
125 {
126 Ok(GetArchiveOutput {
127 body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
128 })
129 }
130}
131
132impl<'a> jacquard_common::xrpc::XrpcRequest for GetArchive<'a> {
133 const NSID: &'static str = "sh.tangled.git.temp.getArchive";
134 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
135 type Response = GetArchiveResponse;
136}
137
138pub struct GetArchiveRequest;
140impl jacquard_common::xrpc::XrpcEndpoint for GetArchiveRequest {
141 const PATH: &'static str = "/xrpc/sh.tangled.git.temp.getArchive";
142 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
143 type Request<'de> = GetArchive<'de>;
144 type Response = GetArchiveResponse;
145}
146
147fn _default_format() -> Option<CowStr<'static>> {
148 Some(CowStr::from("tar.gz"))
149}
150
151pub mod get_archive_state {
152
153 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
154 #[allow(unused)]
155 use ::core::marker::PhantomData;
156 mod sealed {
157 pub trait Sealed {}
158 }
159 pub trait State: sealed::Sealed {
161 type Ref;
162 type Repo;
163 }
164 pub struct Empty(());
166 impl sealed::Sealed for Empty {}
167 impl State for Empty {
168 type Ref = Unset;
169 type Repo = Unset;
170 }
171 pub struct SetRef<S: State = Empty>(PhantomData<fn() -> S>);
173 impl<S: State> sealed::Sealed for SetRef<S> {}
174 impl<S: State> State for SetRef<S> {
175 type Ref = Set<members::r#ref>;
176 type Repo = S::Repo;
177 }
178 pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
180 impl<S: State> sealed::Sealed for SetRepo<S> {}
181 impl<S: State> State for SetRepo<S> {
182 type Ref = S::Ref;
183 type Repo = Set<members::repo>;
184 }
185 #[allow(non_camel_case_types)]
187 pub mod members {
188 pub struct r#ref(());
190 pub struct repo(());
192 }
193}
194
195pub struct GetArchiveBuilder<'a, S: get_archive_state::State> {
197 _state: PhantomData<fn() -> S>,
198 _fields: (
199 Option<CowStr<'a>>,
200 Option<CowStr<'a>>,
201 Option<CowStr<'a>>,
202 Option<AtUri<'a>>,
203 ),
204 _lifetime: PhantomData<&'a ()>,
205}
206
207impl<'a> GetArchive<'a> {
208 pub fn new() -> GetArchiveBuilder<'a, get_archive_state::Empty> {
210 GetArchiveBuilder::new()
211 }
212}
213
214impl<'a> GetArchiveBuilder<'a, get_archive_state::Empty> {
215 pub fn new() -> Self {
217 GetArchiveBuilder {
218 _state: PhantomData,
219 _fields: (None, None, None, None),
220 _lifetime: PhantomData,
221 }
222 }
223}
224
225impl<'a, S: get_archive_state::State> GetArchiveBuilder<'a, S> {
226 pub fn format(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
228 self._fields.0 = value.into();
229 self
230 }
231 pub fn maybe_format(mut self, value: Option<CowStr<'a>>) -> Self {
233 self._fields.0 = value;
234 self
235 }
236}
237
238impl<'a, S: get_archive_state::State> GetArchiveBuilder<'a, S> {
239 pub fn prefix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
241 self._fields.1 = value.into();
242 self
243 }
244 pub fn maybe_prefix(mut self, value: Option<CowStr<'a>>) -> Self {
246 self._fields.1 = value;
247 self
248 }
249}
250
251impl<'a, S> GetArchiveBuilder<'a, S>
252where
253 S: get_archive_state::State,
254 S::Ref: get_archive_state::IsUnset,
255{
256 pub fn r#ref(
258 mut self,
259 value: impl Into<CowStr<'a>>,
260 ) -> GetArchiveBuilder<'a, get_archive_state::SetRef<S>> {
261 self._fields.2 = Option::Some(value.into());
262 GetArchiveBuilder {
263 _state: PhantomData,
264 _fields: self._fields,
265 _lifetime: PhantomData,
266 }
267 }
268}
269
270impl<'a, S> GetArchiveBuilder<'a, S>
271where
272 S: get_archive_state::State,
273 S::Repo: get_archive_state::IsUnset,
274{
275 pub fn repo(
277 mut self,
278 value: impl Into<AtUri<'a>>,
279 ) -> GetArchiveBuilder<'a, get_archive_state::SetRepo<S>> {
280 self._fields.3 = Option::Some(value.into());
281 GetArchiveBuilder {
282 _state: PhantomData,
283 _fields: self._fields,
284 _lifetime: PhantomData,
285 }
286 }
287}
288
289impl<'a, S> GetArchiveBuilder<'a, S>
290where
291 S: get_archive_state::State,
292 S::Ref: get_archive_state::IsSet,
293 S::Repo: get_archive_state::IsSet,
294{
295 pub fn build(self) -> GetArchive<'a> {
297 GetArchive {
298 format: self._fields.0,
299 prefix: self._fields.1,
300 r#ref: self._fields.2.unwrap(),
301 repo: self._fields.3.unwrap(),
302 }
303 }
304}