Skip to main content

jacquard_api/sh_weaver/notebook/
resolve_notebook.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.notebook.resolveNotebook
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 alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::ident::AtIdentifier;
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::sh_weaver::notebook::BookEntryView;
18use crate::sh_weaver::notebook::NotebookView;
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase")]
22pub struct ResolveNotebook<'a> {
23    #[serde(borrow)]
24    pub actor: AtIdentifier<'a>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[serde(borrow)]
27    pub entry_cursor: Option<CowStr<'a>>,
28    ///Defaults to `50`. Min: 1. Max: 100.
29    #[serde(default = "_default_entry_limit")]
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub entry_limit: Option<i64>,
32    #[serde(borrow)]
33    pub name: CowStr<'a>,
34}
35
36
37#[lexicon]
38#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
39#[serde(rename_all = "camelCase")]
40pub struct ResolveNotebookOutput<'a> {
41    #[serde(borrow)]
42    pub entries: Vec<BookEntryView<'a>>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[serde(borrow)]
45    pub entry_cursor: Option<CowStr<'a>>,
46    #[serde(borrow)]
47    pub notebook: NotebookView<'a>,
48}
49
50
51#[open_union]
52#[derive(
53    Serialize,
54    Deserialize,
55    Debug,
56    Clone,
57    PartialEq,
58    Eq,
59    thiserror::Error,
60    miette::Diagnostic,
61    IntoStatic
62)]
63
64#[serde(tag = "error", content = "message")]
65#[serde(bound(deserialize = "'de: 'a"))]
66pub enum ResolveNotebookError<'a> {
67    #[serde(rename = "NotebookNotFound")]
68    NotebookNotFound(Option<CowStr<'a>>),
69}
70
71impl core::fmt::Display for ResolveNotebookError<'_> {
72    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73        match self {
74            Self::NotebookNotFound(msg) => {
75                write!(f, "NotebookNotFound")?;
76                if let Some(msg) = msg {
77                    write!(f, ": {}", msg)?;
78                }
79                Ok(())
80            }
81            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
82        }
83    }
84}
85
86/// Response type for sh.weaver.notebook.resolveNotebook
87pub struct ResolveNotebookResponse;
88impl jacquard_common::xrpc::XrpcResp for ResolveNotebookResponse {
89    const NSID: &'static str = "sh.weaver.notebook.resolveNotebook";
90    const ENCODING: &'static str = "application/json";
91    type Output<'de> = ResolveNotebookOutput<'de>;
92    type Err<'de> = ResolveNotebookError<'de>;
93}
94
95impl<'a> jacquard_common::xrpc::XrpcRequest for ResolveNotebook<'a> {
96    const NSID: &'static str = "sh.weaver.notebook.resolveNotebook";
97    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
98    type Response = ResolveNotebookResponse;
99}
100
101/// Endpoint type for sh.weaver.notebook.resolveNotebook
102pub struct ResolveNotebookRequest;
103impl jacquard_common::xrpc::XrpcEndpoint for ResolveNotebookRequest {
104    const PATH: &'static str = "/xrpc/sh.weaver.notebook.resolveNotebook";
105    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
106    type Request<'de> = ResolveNotebook<'de>;
107    type Response = ResolveNotebookResponse;
108}
109
110fn _default_entry_limit() -> Option<i64> {
111    Some(50i64)
112}
113
114pub mod resolve_notebook_state {
115
116    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
117    #[allow(unused)]
118    use ::core::marker::PhantomData;
119    mod sealed {
120        pub trait Sealed {}
121    }
122    /// State trait tracking which required fields have been set
123    pub trait State: sealed::Sealed {
124        type Actor;
125        type Name;
126    }
127    /// Empty state - all required fields are unset
128    pub struct Empty(());
129    impl sealed::Sealed for Empty {}
130    impl State for Empty {
131        type Actor = Unset;
132        type Name = Unset;
133    }
134    ///State transition - sets the `actor` field to Set
135    pub struct SetActor<S: State = Empty>(PhantomData<fn() -> S>);
136    impl<S: State> sealed::Sealed for SetActor<S> {}
137    impl<S: State> State for SetActor<S> {
138        type Actor = Set<members::actor>;
139        type Name = S::Name;
140    }
141    ///State transition - sets the `name` field to Set
142    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
143    impl<S: State> sealed::Sealed for SetName<S> {}
144    impl<S: State> State for SetName<S> {
145        type Actor = S::Actor;
146        type Name = Set<members::name>;
147    }
148    /// Marker types for field names
149    #[allow(non_camel_case_types)]
150    pub mod members {
151        ///Marker type for the `actor` field
152        pub struct actor(());
153        ///Marker type for the `name` field
154        pub struct name(());
155    }
156}
157
158/// Builder for constructing an instance of this type
159pub struct ResolveNotebookBuilder<'a, S: resolve_notebook_state::State> {
160    _state: PhantomData<fn() -> S>,
161    _fields: (
162        Option<AtIdentifier<'a>>,
163        Option<CowStr<'a>>,
164        Option<i64>,
165        Option<CowStr<'a>>,
166    ),
167    _lifetime: PhantomData<&'a ()>,
168}
169
170impl<'a> ResolveNotebook<'a> {
171    /// Create a new builder for this type
172    pub fn new() -> ResolveNotebookBuilder<'a, resolve_notebook_state::Empty> {
173        ResolveNotebookBuilder::new()
174    }
175}
176
177impl<'a> ResolveNotebookBuilder<'a, resolve_notebook_state::Empty> {
178    /// Create a new builder with all fields unset
179    pub fn new() -> Self {
180        ResolveNotebookBuilder {
181            _state: PhantomData,
182            _fields: (None, None, None, None),
183            _lifetime: PhantomData,
184        }
185    }
186}
187
188impl<'a, S> ResolveNotebookBuilder<'a, S>
189where
190    S: resolve_notebook_state::State,
191    S::Actor: resolve_notebook_state::IsUnset,
192{
193    /// Set the `actor` field (required)
194    pub fn actor(
195        mut self,
196        value: impl Into<AtIdentifier<'a>>,
197    ) -> ResolveNotebookBuilder<'a, resolve_notebook_state::SetActor<S>> {
198        self._fields.0 = Option::Some(value.into());
199        ResolveNotebookBuilder {
200            _state: PhantomData,
201            _fields: self._fields,
202            _lifetime: PhantomData,
203        }
204    }
205}
206
207impl<'a, S: resolve_notebook_state::State> ResolveNotebookBuilder<'a, S> {
208    /// Set the `entryCursor` field (optional)
209    pub fn entry_cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
210        self._fields.1 = value.into();
211        self
212    }
213    /// Set the `entryCursor` field to an Option value (optional)
214    pub fn maybe_entry_cursor(mut self, value: Option<CowStr<'a>>) -> Self {
215        self._fields.1 = value;
216        self
217    }
218}
219
220impl<'a, S: resolve_notebook_state::State> ResolveNotebookBuilder<'a, S> {
221    /// Set the `entryLimit` field (optional)
222    pub fn entry_limit(mut self, value: impl Into<Option<i64>>) -> Self {
223        self._fields.2 = value.into();
224        self
225    }
226    /// Set the `entryLimit` field to an Option value (optional)
227    pub fn maybe_entry_limit(mut self, value: Option<i64>) -> Self {
228        self._fields.2 = value;
229        self
230    }
231}
232
233impl<'a, S> ResolveNotebookBuilder<'a, S>
234where
235    S: resolve_notebook_state::State,
236    S::Name: resolve_notebook_state::IsUnset,
237{
238    /// Set the `name` field (required)
239    pub fn name(
240        mut self,
241        value: impl Into<CowStr<'a>>,
242    ) -> ResolveNotebookBuilder<'a, resolve_notebook_state::SetName<S>> {
243        self._fields.3 = Option::Some(value.into());
244        ResolveNotebookBuilder {
245            _state: PhantomData,
246            _fields: self._fields,
247            _lifetime: PhantomData,
248        }
249    }
250}
251
252impl<'a, S> ResolveNotebookBuilder<'a, S>
253where
254    S: resolve_notebook_state::State,
255    S::Actor: resolve_notebook_state::IsSet,
256    S::Name: resolve_notebook_state::IsSet,
257{
258    /// Build the final struct
259    pub fn build(self) -> ResolveNotebook<'a> {
260        ResolveNotebook {
261            actor: self._fields.0.unwrap(),
262            entry_cursor: self._fields.1,
263            entry_limit: self._fields.2,
264            name: self._fields.3.unwrap(),
265        }
266    }
267}