jacquard_api/sh_weaver/notebook/
get_book_entry.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_weaver::notebook::BookEntryView;
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetBookEntry<'a> {
19 #[serde(default = "_default_index")]
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub index: Option<i64>,
23 #[serde(borrow)]
24 pub notebook: AtUri<'a>,
25}
26
27
28#[jacquard_derive::lexicon]
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
30#[serde(rename_all = "camelCase")]
31pub struct GetBookEntryOutput<'a> {
32 #[serde(flatten)]
33 #[serde(borrow)]
34 pub value: BookEntryView<'a>,
35}
36
37
38#[open_union]
39#[derive(
40 Serialize,
41 Deserialize,
42 Debug,
43 Clone,
44 PartialEq,
45 Eq,
46 thiserror::Error,
47 miette::Diagnostic,
48 IntoStatic
49)]
50
51#[serde(tag = "error", content = "message")]
52#[serde(bound(deserialize = "'de: 'a"))]
53pub enum GetBookEntryError<'a> {
54 #[serde(rename = "NotebookNotFound")]
55 NotebookNotFound(Option<CowStr<'a>>),
56 #[serde(rename = "EntryNotFound")]
57 EntryNotFound(Option<CowStr<'a>>),
58}
59
60impl core::fmt::Display for GetBookEntryError<'_> {
61 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 match self {
63 Self::NotebookNotFound(msg) => {
64 write!(f, "NotebookNotFound")?;
65 if let Some(msg) = msg {
66 write!(f, ": {}", msg)?;
67 }
68 Ok(())
69 }
70 Self::EntryNotFound(msg) => {
71 write!(f, "EntryNotFound")?;
72 if let Some(msg) = msg {
73 write!(f, ": {}", msg)?;
74 }
75 Ok(())
76 }
77 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
78 }
79 }
80}
81
82pub struct GetBookEntryResponse;
84impl jacquard_common::xrpc::XrpcResp for GetBookEntryResponse {
85 const NSID: &'static str = "sh.weaver.notebook.getBookEntry";
86 const ENCODING: &'static str = "application/json";
87 type Output<'de> = GetBookEntryOutput<'de>;
88 type Err<'de> = GetBookEntryError<'de>;
89}
90
91impl<'a> jacquard_common::xrpc::XrpcRequest for GetBookEntry<'a> {
92 const NSID: &'static str = "sh.weaver.notebook.getBookEntry";
93 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
94 type Response = GetBookEntryResponse;
95}
96
97pub struct GetBookEntryRequest;
99impl jacquard_common::xrpc::XrpcEndpoint for GetBookEntryRequest {
100 const PATH: &'static str = "/xrpc/sh.weaver.notebook.getBookEntry";
101 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
102 type Request<'de> = GetBookEntry<'de>;
103 type Response = GetBookEntryResponse;
104}
105
106fn _default_index() -> Option<i64> {
107 Some(0i64)
108}
109
110pub mod get_book_entry_state {
111
112 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
113 #[allow(unused)]
114 use ::core::marker::PhantomData;
115 mod sealed {
116 pub trait Sealed {}
117 }
118 pub trait State: sealed::Sealed {
120 type Notebook;
121 }
122 pub struct Empty(());
124 impl sealed::Sealed for Empty {}
125 impl State for Empty {
126 type Notebook = Unset;
127 }
128 pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
130 impl<S: State> sealed::Sealed for SetNotebook<S> {}
131 impl<S: State> State for SetNotebook<S> {
132 type Notebook = Set<members::notebook>;
133 }
134 #[allow(non_camel_case_types)]
136 pub mod members {
137 pub struct notebook(());
139 }
140}
141
142pub struct GetBookEntryBuilder<'a, S: get_book_entry_state::State> {
144 _state: PhantomData<fn() -> S>,
145 _fields: (Option<i64>, Option<AtUri<'a>>),
146 _lifetime: PhantomData<&'a ()>,
147}
148
149impl<'a> GetBookEntry<'a> {
150 pub fn new() -> GetBookEntryBuilder<'a, get_book_entry_state::Empty> {
152 GetBookEntryBuilder::new()
153 }
154}
155
156impl<'a> GetBookEntryBuilder<'a, get_book_entry_state::Empty> {
157 pub fn new() -> Self {
159 GetBookEntryBuilder {
160 _state: PhantomData,
161 _fields: (None, None),
162 _lifetime: PhantomData,
163 }
164 }
165}
166
167impl<'a, S: get_book_entry_state::State> GetBookEntryBuilder<'a, S> {
168 pub fn index(mut self, value: impl Into<Option<i64>>) -> Self {
170 self._fields.0 = value.into();
171 self
172 }
173 pub fn maybe_index(mut self, value: Option<i64>) -> Self {
175 self._fields.0 = value;
176 self
177 }
178}
179
180impl<'a, S> GetBookEntryBuilder<'a, S>
181where
182 S: get_book_entry_state::State,
183 S::Notebook: get_book_entry_state::IsUnset,
184{
185 pub fn notebook(
187 mut self,
188 value: impl Into<AtUri<'a>>,
189 ) -> GetBookEntryBuilder<'a, get_book_entry_state::SetNotebook<S>> {
190 self._fields.1 = Option::Some(value.into());
191 GetBookEntryBuilder {
192 _state: PhantomData,
193 _fields: self._fields,
194 _lifetime: PhantomData,
195 }
196 }
197}
198
199impl<'a, S> GetBookEntryBuilder<'a, S>
200where
201 S: get_book_entry_state::State,
202 S::Notebook: get_book_entry_state::IsSet,
203{
204 pub fn build(self) -> GetBookEntry<'a> {
206 GetBookEntry {
207 index: self._fields.0,
208 notebook: self._fields.1.unwrap(),
209 }
210 }
211}