jacquard_api/sh_weaver/notebook/
resolve_entry.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::ident::AtIdentifier;
15use jacquard_common::types::value::Data;
16use jacquard_derive::{IntoStatic, lexicon, open_union};
17use serde::{Serialize, Deserialize};
18use crate::sh_weaver::notebook::EntryView;
19use crate::sh_weaver::notebook::NotebookView;
20
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
22#[serde(rename_all = "camelCase")]
23pub struct ResolveEntry<'a> {
24 #[serde(borrow)]
25 pub actor: AtIdentifier<'a>,
26 #[serde(borrow)]
27 pub entry: CowStr<'a>,
28 #[serde(borrow)]
29 pub notebook: CowStr<'a>,
30}
31
32
33#[lexicon]
34#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
35#[serde(rename_all = "camelCase")]
36pub struct ResolveEntryOutput<'a> {
37 #[serde(borrow)]
38 pub entry: EntryView<'a>,
39 pub notebook_count: i64,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub notebooks: Option<Vec<NotebookView<'a>>>,
43 #[serde(borrow)]
44 pub record: Data<'a>,
45}
46
47
48#[open_union]
49#[derive(
50 Serialize,
51 Deserialize,
52 Debug,
53 Clone,
54 PartialEq,
55 Eq,
56 thiserror::Error,
57 miette::Diagnostic,
58 IntoStatic
59)]
60
61#[serde(tag = "error", content = "message")]
62#[serde(bound(deserialize = "'de: 'a"))]
63pub enum ResolveEntryError<'a> {
64 #[serde(rename = "NotebookNotFound")]
65 NotebookNotFound(Option<CowStr<'a>>),
66 #[serde(rename = "EntryNotFound")]
67 EntryNotFound(Option<CowStr<'a>>),
68}
69
70impl core::fmt::Display for ResolveEntryError<'_> {
71 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
72 match self {
73 Self::NotebookNotFound(msg) => {
74 write!(f, "NotebookNotFound")?;
75 if let Some(msg) = msg {
76 write!(f, ": {}", msg)?;
77 }
78 Ok(())
79 }
80 Self::EntryNotFound(msg) => {
81 write!(f, "EntryNotFound")?;
82 if let Some(msg) = msg {
83 write!(f, ": {}", msg)?;
84 }
85 Ok(())
86 }
87 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
88 }
89 }
90}
91
92pub struct ResolveEntryResponse;
94impl jacquard_common::xrpc::XrpcResp for ResolveEntryResponse {
95 const NSID: &'static str = "sh.weaver.notebook.resolveEntry";
96 const ENCODING: &'static str = "application/json";
97 type Output<'de> = ResolveEntryOutput<'de>;
98 type Err<'de> = ResolveEntryError<'de>;
99}
100
101impl<'a> jacquard_common::xrpc::XrpcRequest for ResolveEntry<'a> {
102 const NSID: &'static str = "sh.weaver.notebook.resolveEntry";
103 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
104 type Response = ResolveEntryResponse;
105}
106
107pub struct ResolveEntryRequest;
109impl jacquard_common::xrpc::XrpcEndpoint for ResolveEntryRequest {
110 const PATH: &'static str = "/xrpc/sh.weaver.notebook.resolveEntry";
111 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
112 type Request<'de> = ResolveEntry<'de>;
113 type Response = ResolveEntryResponse;
114}
115
116pub mod resolve_entry_state {
117
118 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
119 #[allow(unused)]
120 use ::core::marker::PhantomData;
121 mod sealed {
122 pub trait Sealed {}
123 }
124 pub trait State: sealed::Sealed {
126 type Entry;
127 type Actor;
128 type Notebook;
129 }
130 pub struct Empty(());
132 impl sealed::Sealed for Empty {}
133 impl State for Empty {
134 type Entry = Unset;
135 type Actor = Unset;
136 type Notebook = Unset;
137 }
138 pub struct SetEntry<S: State = Empty>(PhantomData<fn() -> S>);
140 impl<S: State> sealed::Sealed for SetEntry<S> {}
141 impl<S: State> State for SetEntry<S> {
142 type Entry = Set<members::entry>;
143 type Actor = S::Actor;
144 type Notebook = S::Notebook;
145 }
146 pub struct SetActor<S: State = Empty>(PhantomData<fn() -> S>);
148 impl<S: State> sealed::Sealed for SetActor<S> {}
149 impl<S: State> State for SetActor<S> {
150 type Entry = S::Entry;
151 type Actor = Set<members::actor>;
152 type Notebook = S::Notebook;
153 }
154 pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
156 impl<S: State> sealed::Sealed for SetNotebook<S> {}
157 impl<S: State> State for SetNotebook<S> {
158 type Entry = S::Entry;
159 type Actor = S::Actor;
160 type Notebook = Set<members::notebook>;
161 }
162 #[allow(non_camel_case_types)]
164 pub mod members {
165 pub struct entry(());
167 pub struct actor(());
169 pub struct notebook(());
171 }
172}
173
174pub struct ResolveEntryBuilder<'a, S: resolve_entry_state::State> {
176 _state: PhantomData<fn() -> S>,
177 _fields: (Option<AtIdentifier<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
178 _lifetime: PhantomData<&'a ()>,
179}
180
181impl<'a> ResolveEntry<'a> {
182 pub fn new() -> ResolveEntryBuilder<'a, resolve_entry_state::Empty> {
184 ResolveEntryBuilder::new()
185 }
186}
187
188impl<'a> ResolveEntryBuilder<'a, resolve_entry_state::Empty> {
189 pub fn new() -> Self {
191 ResolveEntryBuilder {
192 _state: PhantomData,
193 _fields: (None, None, None),
194 _lifetime: PhantomData,
195 }
196 }
197}
198
199impl<'a, S> ResolveEntryBuilder<'a, S>
200where
201 S: resolve_entry_state::State,
202 S::Actor: resolve_entry_state::IsUnset,
203{
204 pub fn actor(
206 mut self,
207 value: impl Into<AtIdentifier<'a>>,
208 ) -> ResolveEntryBuilder<'a, resolve_entry_state::SetActor<S>> {
209 self._fields.0 = Option::Some(value.into());
210 ResolveEntryBuilder {
211 _state: PhantomData,
212 _fields: self._fields,
213 _lifetime: PhantomData,
214 }
215 }
216}
217
218impl<'a, S> ResolveEntryBuilder<'a, S>
219where
220 S: resolve_entry_state::State,
221 S::Entry: resolve_entry_state::IsUnset,
222{
223 pub fn entry(
225 mut self,
226 value: impl Into<CowStr<'a>>,
227 ) -> ResolveEntryBuilder<'a, resolve_entry_state::SetEntry<S>> {
228 self._fields.1 = Option::Some(value.into());
229 ResolveEntryBuilder {
230 _state: PhantomData,
231 _fields: self._fields,
232 _lifetime: PhantomData,
233 }
234 }
235}
236
237impl<'a, S> ResolveEntryBuilder<'a, S>
238where
239 S: resolve_entry_state::State,
240 S::Notebook: resolve_entry_state::IsUnset,
241{
242 pub fn notebook(
244 mut self,
245 value: impl Into<CowStr<'a>>,
246 ) -> ResolveEntryBuilder<'a, resolve_entry_state::SetNotebook<S>> {
247 self._fields.2 = Option::Some(value.into());
248 ResolveEntryBuilder {
249 _state: PhantomData,
250 _fields: self._fields,
251 _lifetime: PhantomData,
252 }
253 }
254}
255
256impl<'a, S> ResolveEntryBuilder<'a, S>
257where
258 S: resolve_entry_state::State,
259 S::Entry: resolve_entry_state::IsSet,
260 S::Actor: resolve_entry_state::IsSet,
261 S::Notebook: resolve_entry_state::IsSet,
262{
263 pub fn build(self) -> ResolveEntry<'a> {
265 ResolveEntry {
266 actor: self._fields.0.unwrap(),
267 entry: self._fields.1.unwrap(),
268 notebook: self._fields.2.unwrap(),
269 }
270 }
271}