jacquard_api/sh_tangled/repo/
diff.rs1#[derive(
9 serde::Serialize,
10 serde::Deserialize,
11 Debug,
12 Clone,
13 PartialEq,
14 Eq,
15 bon::Builder,
16 jacquard_derive::IntoStatic
17)]
18#[builder(start_fn = new)]
19#[serde(rename_all = "camelCase")]
20pub struct Diff<'a> {
21 #[serde(borrow)]
22 #[builder(into)]
23 pub r#ref: jacquard_common::CowStr<'a>,
24 #[serde(borrow)]
25 #[builder(into)]
26 pub repo: jacquard_common::CowStr<'a>,
27}
28
29#[derive(
30 serde::Serialize,
31 serde::Deserialize,
32 Debug,
33 Clone,
34 PartialEq,
35 Eq,
36 jacquard_derive::IntoStatic
37)]
38#[serde(rename_all = "camelCase")]
39pub struct DiffOutput {
40 pub body: bytes::Bytes,
41}
42
43#[jacquard_derive::open_union]
44#[derive(
45 serde::Serialize,
46 serde::Deserialize,
47 Debug,
48 Clone,
49 PartialEq,
50 Eq,
51 thiserror::Error,
52 miette::Diagnostic,
53 jacquard_derive::IntoStatic
54)]
55#[serde(tag = "error", content = "message")]
56#[serde(bound(deserialize = "'de: 'a"))]
57pub enum DiffError<'a> {
58 #[serde(rename = "RepoNotFound")]
60 RepoNotFound(std::option::Option<String>),
61 #[serde(rename = "RefNotFound")]
63 RefNotFound(std::option::Option<String>),
64 #[serde(rename = "InvalidRequest")]
66 InvalidRequest(std::option::Option<String>),
67}
68
69impl std::fmt::Display for DiffError<'_> {
70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 match self {
72 Self::RepoNotFound(msg) => {
73 write!(f, "RepoNotFound")?;
74 if let Some(msg) = msg {
75 write!(f, ": {}", msg)?;
76 }
77 Ok(())
78 }
79 Self::RefNotFound(msg) => {
80 write!(f, "RefNotFound")?;
81 if let Some(msg) = msg {
82 write!(f, ": {}", msg)?;
83 }
84 Ok(())
85 }
86 Self::InvalidRequest(msg) => {
87 write!(f, "InvalidRequest")?;
88 if let Some(msg) = msg {
89 write!(f, ": {}", msg)?;
90 }
91 Ok(())
92 }
93 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
94 }
95 }
96}
97
98pub struct DiffResponse;
101impl jacquard_common::xrpc::XrpcResp for DiffResponse {
102 const NSID: &'static str = "sh.tangled.repo.diff";
103 const ENCODING: &'static str = "*/*";
104 type Output<'de> = DiffOutput;
105 type Err<'de> = DiffError<'de>;
106 fn encode_output(
107 output: &Self::Output<'_>,
108 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
109 Ok(output.body.to_vec())
110 }
111 fn decode_output<'de>(
112 body: &'de [u8],
113 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
114 where
115 Self::Output<'de>: serde::Deserialize<'de>,
116 {
117 Ok(DiffOutput {
118 body: bytes::Bytes::copy_from_slice(body),
119 })
120 }
121}
122
123impl<'a> jacquard_common::xrpc::XrpcRequest for Diff<'a> {
124 const NSID: &'static str = "sh.tangled.repo.diff";
125 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
126 type Response = DiffResponse;
127}
128
129pub struct DiffRequest;
132impl jacquard_common::xrpc::XrpcEndpoint for DiffRequest {
133 const PATH: &'static str = "/xrpc/sh.tangled.repo.diff";
134 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
135 type Request<'de> = Diff<'de>;
136 type Response = DiffResponse;
137}