jacquard_api/sh_weaver/graph/
subscribe.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::collection::{Collection, RecordError};
18use jacquard_common::types::string::{AtUri, Cid, Datetime};
19use jacquard_common::types::uri::{RecordUri, UriError};
20use jacquard_common::xrpc::XrpcResp;
21use jacquard_derive::{IntoStatic, lexicon};
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Serialize, Deserialize};
28#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "sh.weaver.graph.subscribe", tag = "$type")]
33pub struct Subscribe<'a> {
34 pub created_at: Datetime,
35 #[serde(borrow)]
37 pub notebook: AtUri<'a>,
38}
39
40#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
43#[serde(rename_all = "camelCase")]
44pub struct SubscribeGetRecordOutput<'a> {
45 #[serde(skip_serializing_if = "Option::is_none")]
46 #[serde(borrow)]
47 pub cid: Option<Cid<'a>>,
48 #[serde(borrow)]
49 pub uri: AtUri<'a>,
50 #[serde(borrow)]
51 pub value: Subscribe<'a>,
52}
53
54impl<'a> Subscribe<'a> {
55 pub fn uri(
56 uri: impl Into<CowStr<'a>>,
57 ) -> Result<RecordUri<'a, SubscribeRecord>, UriError> {
58 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
59 }
60}
61
62#[derive(Debug, Serialize, Deserialize)]
65pub struct SubscribeRecord;
66impl XrpcResp for SubscribeRecord {
67 const NSID: &'static str = "sh.weaver.graph.subscribe";
68 const ENCODING: &'static str = "application/json";
69 type Output<'de> = SubscribeGetRecordOutput<'de>;
70 type Err<'de> = RecordError<'de>;
71}
72
73impl From<SubscribeGetRecordOutput<'_>> for Subscribe<'_> {
74 fn from(output: SubscribeGetRecordOutput<'_>) -> Self {
75 use jacquard_common::IntoStatic;
76 output.value.into_static()
77 }
78}
79
80impl Collection for Subscribe<'_> {
81 const NSID: &'static str = "sh.weaver.graph.subscribe";
82 type Record = SubscribeRecord;
83}
84
85impl Collection for SubscribeRecord {
86 const NSID: &'static str = "sh.weaver.graph.subscribe";
87 type Record = SubscribeRecord;
88}
89
90impl<'a> LexiconSchema for Subscribe<'a> {
91 fn nsid() -> &'static str {
92 "sh.weaver.graph.subscribe"
93 }
94 fn def_name() -> &'static str {
95 "main"
96 }
97 fn lexicon_doc() -> LexiconDoc<'static> {
98 lexicon_doc_sh_weaver_graph_subscribe()
99 }
100 fn validate(&self) -> Result<(), ConstraintError> {
101 Ok(())
102 }
103}
104
105pub mod subscribe_state {
106
107 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
108 #[allow(unused)]
109 use ::core::marker::PhantomData;
110 mod sealed {
111 pub trait Sealed {}
112 }
113 pub trait State: sealed::Sealed {
115 type Notebook;
116 type CreatedAt;
117 }
118 pub struct Empty(());
120 impl sealed::Sealed for Empty {}
121 impl State for Empty {
122 type Notebook = Unset;
123 type CreatedAt = Unset;
124 }
125 pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
127 impl<S: State> sealed::Sealed for SetNotebook<S> {}
128 impl<S: State> State for SetNotebook<S> {
129 type Notebook = Set<members::notebook>;
130 type CreatedAt = S::CreatedAt;
131 }
132 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
134 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
135 impl<S: State> State for SetCreatedAt<S> {
136 type Notebook = S::Notebook;
137 type CreatedAt = Set<members::created_at>;
138 }
139 #[allow(non_camel_case_types)]
141 pub mod members {
142 pub struct notebook(());
144 pub struct created_at(());
146 }
147}
148
149pub struct SubscribeBuilder<'a, S: subscribe_state::State> {
151 _state: PhantomData<fn() -> S>,
152 _fields: (Option<Datetime>, Option<AtUri<'a>>),
153 _lifetime: PhantomData<&'a ()>,
154}
155
156impl<'a> Subscribe<'a> {
157 pub fn new() -> SubscribeBuilder<'a, subscribe_state::Empty> {
159 SubscribeBuilder::new()
160 }
161}
162
163impl<'a> SubscribeBuilder<'a, subscribe_state::Empty> {
164 pub fn new() -> Self {
166 SubscribeBuilder {
167 _state: PhantomData,
168 _fields: (None, None),
169 _lifetime: PhantomData,
170 }
171 }
172}
173
174impl<'a, S> SubscribeBuilder<'a, S>
175where
176 S: subscribe_state::State,
177 S::CreatedAt: subscribe_state::IsUnset,
178{
179 pub fn created_at(
181 mut self,
182 value: impl Into<Datetime>,
183 ) -> SubscribeBuilder<'a, subscribe_state::SetCreatedAt<S>> {
184 self._fields.0 = Option::Some(value.into());
185 SubscribeBuilder {
186 _state: PhantomData,
187 _fields: self._fields,
188 _lifetime: PhantomData,
189 }
190 }
191}
192
193impl<'a, S> SubscribeBuilder<'a, S>
194where
195 S: subscribe_state::State,
196 S::Notebook: subscribe_state::IsUnset,
197{
198 pub fn notebook(
200 mut self,
201 value: impl Into<AtUri<'a>>,
202 ) -> SubscribeBuilder<'a, subscribe_state::SetNotebook<S>> {
203 self._fields.1 = Option::Some(value.into());
204 SubscribeBuilder {
205 _state: PhantomData,
206 _fields: self._fields,
207 _lifetime: PhantomData,
208 }
209 }
210}
211
212impl<'a, S> SubscribeBuilder<'a, S>
213where
214 S: subscribe_state::State,
215 S::Notebook: subscribe_state::IsSet,
216 S::CreatedAt: subscribe_state::IsSet,
217{
218 pub fn build(self) -> Subscribe<'a> {
220 Subscribe {
221 created_at: self._fields.0.unwrap(),
222 notebook: self._fields.1.unwrap(),
223 extra_data: Default::default(),
224 }
225 }
226 pub fn build_with_data(
228 self,
229 extra_data: BTreeMap<
230 jacquard_common::deps::smol_str::SmolStr,
231 jacquard_common::types::value::Data<'a>,
232 >,
233 ) -> Subscribe<'a> {
234 Subscribe {
235 created_at: self._fields.0.unwrap(),
236 notebook: self._fields.1.unwrap(),
237 extra_data: Some(extra_data),
238 }
239 }
240}
241
242fn lexicon_doc_sh_weaver_graph_subscribe() -> LexiconDoc<'static> {
243 #[allow(unused_imports)]
244 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
245 use jacquard_lexicon::lexicon::*;
246 use alloc::collections::BTreeMap;
247 LexiconDoc {
248 lexicon: Lexicon::Lexicon1,
249 id: CowStr::new_static("sh.weaver.graph.subscribe"),
250 defs: {
251 let mut map = BTreeMap::new();
252 map.insert(
253 SmolStr::new_static("main"),
254 LexUserType::Record(LexRecord {
255 description: Some(
256 CowStr::new_static(
257 "Request to subscribe to a notebook. Requires acceptance to be active.",
258 ),
259 ),
260 key: Some(CowStr::new_static("tid")),
261 record: LexRecordRecord::Object(LexObject {
262 required: Some(
263 vec![
264 SmolStr::new_static("notebook"),
265 SmolStr::new_static("createdAt")
266 ],
267 ),
268 properties: {
269 #[allow(unused_mut)]
270 let mut map = BTreeMap::new();
271 map.insert(
272 SmolStr::new_static("createdAt"),
273 LexObjectProperty::String(LexString {
274 format: Some(LexStringFormat::Datetime),
275 ..Default::default()
276 }),
277 );
278 map.insert(
279 SmolStr::new_static("notebook"),
280 LexObjectProperty::String(LexString {
281 description: Some(
282 CowStr::new_static("URI of the notebook to subscribe to."),
283 ),
284 format: Some(LexStringFormat::AtUri),
285 ..Default::default()
286 }),
287 );
288 map
289 },
290 ..Default::default()
291 }),
292 ..Default::default()
293 }),
294 );
295 map
296 },
297 ..Default::default()
298 }
299}