Skip to main content

jacquard_api/sh_tangled/git/temp/
get_archive.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.git.temp.getArchive
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::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    ///Defaults to `"tar.gz"`.
20    #[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/// Binary archive data
34
35#[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    /// Repository not found or access denied
59    #[serde(rename = "RepoNotFound")]
60    RepoNotFound(Option<CowStr<'a>>),
61    /// Git reference not found
62    #[serde(rename = "RefNotFound")]
63    RefNotFound(Option<CowStr<'a>>),
64    /// Invalid request parameters
65    #[serde(rename = "InvalidRequest")]
66    InvalidRequest(Option<CowStr<'a>>),
67    /// Failed to create archive
68    #[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
108/// Response type for sh.tangled.git.temp.getArchive
109pub 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
138/// Endpoint type for sh.tangled.git.temp.getArchive
139pub 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    /// State trait tracking which required fields have been set
160    pub trait State: sealed::Sealed {
161        type Ref;
162        type Repo;
163    }
164    /// Empty state - all required fields are unset
165    pub struct Empty(());
166    impl sealed::Sealed for Empty {}
167    impl State for Empty {
168        type Ref = Unset;
169        type Repo = Unset;
170    }
171    ///State transition - sets the `ref` field to Set
172    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    ///State transition - sets the `repo` field to Set
179    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    /// Marker types for field names
186    #[allow(non_camel_case_types)]
187    pub mod members {
188        ///Marker type for the `ref` field
189        pub struct r#ref(());
190        ///Marker type for the `repo` field
191        pub struct repo(());
192    }
193}
194
195/// Builder for constructing an instance of this type
196pub 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    /// Create a new builder for this type
209    pub fn new() -> GetArchiveBuilder<'a, get_archive_state::Empty> {
210        GetArchiveBuilder::new()
211    }
212}
213
214impl<'a> GetArchiveBuilder<'a, get_archive_state::Empty> {
215    /// Create a new builder with all fields unset
216    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    /// Set the `format` field (optional)
227    pub fn format(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
228        self._fields.0 = value.into();
229        self
230    }
231    /// Set the `format` field to an Option value (optional)
232    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    /// Set the `prefix` field (optional)
240    pub fn prefix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
241        self._fields.1 = value.into();
242        self
243    }
244    /// Set the `prefix` field to an Option value (optional)
245    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    /// Set the `ref` field (required)
257    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    /// Set the `repo` field (required)
276    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    /// Build the final struct
296    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}