atproto blogging
1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.collab.session
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8/// Active real-time collaboration session. Published when joining a collaborative editing session, deleted on disconnect.
9#[jacquard_derive::lexicon]
10#[derive(
11 serde::Serialize,
12 serde::Deserialize,
13 Debug,
14 Clone,
15 PartialEq,
16 Eq,
17 jacquard_derive::IntoStatic
18)]
19#[serde(rename_all = "camelCase")]
20pub struct Session<'a> {
21 pub created_at: jacquard_common::types::string::Datetime,
22 /// Session TTL. Should be refreshed periodically while active.
23 #[serde(skip_serializing_if = "std::option::Option::is_none")]
24 pub expires_at: std::option::Option<jacquard_common::types::string::Datetime>,
25 /// iroh NodeId in z-base32 encoding for P2P connection.
26 #[serde(borrow)]
27 pub node_id: jacquard_common::CowStr<'a>,
28 /// DERP relay URL if using relay-only mode (browser clients).
29 #[serde(skip_serializing_if = "std::option::Option::is_none")]
30 #[serde(borrow)]
31 pub relay_url: std::option::Option<jacquard_common::types::string::Uri<'a>>,
32 /// The resource being collaboratively edited.
33 #[serde(borrow)]
34 pub resource: crate::com_atproto::repo::strong_ref::StrongRef<'a>,
35}
36
37pub mod session_state {
38
39 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
40 #[allow(unused)]
41 use ::core::marker::PhantomData;
42 mod sealed {
43 pub trait Sealed {}
44 }
45 /// State trait tracking which required fields have been set
46 pub trait State: sealed::Sealed {
47 type CreatedAt;
48 type Resource;
49 type NodeId;
50 }
51 /// Empty state - all required fields are unset
52 pub struct Empty(());
53 impl sealed::Sealed for Empty {}
54 impl State for Empty {
55 type CreatedAt = Unset;
56 type Resource = Unset;
57 type NodeId = Unset;
58 }
59 ///State transition - sets the `created_at` field to Set
60 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
61 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
62 impl<S: State> State for SetCreatedAt<S> {
63 type CreatedAt = Set<members::created_at>;
64 type Resource = S::Resource;
65 type NodeId = S::NodeId;
66 }
67 ///State transition - sets the `resource` field to Set
68 pub struct SetResource<S: State = Empty>(PhantomData<fn() -> S>);
69 impl<S: State> sealed::Sealed for SetResource<S> {}
70 impl<S: State> State for SetResource<S> {
71 type CreatedAt = S::CreatedAt;
72 type Resource = Set<members::resource>;
73 type NodeId = S::NodeId;
74 }
75 ///State transition - sets the `node_id` field to Set
76 pub struct SetNodeId<S: State = Empty>(PhantomData<fn() -> S>);
77 impl<S: State> sealed::Sealed for SetNodeId<S> {}
78 impl<S: State> State for SetNodeId<S> {
79 type CreatedAt = S::CreatedAt;
80 type Resource = S::Resource;
81 type NodeId = Set<members::node_id>;
82 }
83 /// Marker types for field names
84 #[allow(non_camel_case_types)]
85 pub mod members {
86 ///Marker type for the `created_at` field
87 pub struct created_at(());
88 ///Marker type for the `resource` field
89 pub struct resource(());
90 ///Marker type for the `node_id` field
91 pub struct node_id(());
92 }
93}
94
95/// Builder for constructing an instance of this type
96pub struct SessionBuilder<'a, S: session_state::State> {
97 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
98 __unsafe_private_named: (
99 ::core::option::Option<jacquard_common::types::string::Datetime>,
100 ::core::option::Option<jacquard_common::types::string::Datetime>,
101 ::core::option::Option<jacquard_common::CowStr<'a>>,
102 ::core::option::Option<jacquard_common::types::string::Uri<'a>>,
103 ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
104 ),
105 _phantom: ::core::marker::PhantomData<&'a ()>,
106}
107
108impl<'a> Session<'a> {
109 /// Create a new builder for this type
110 pub fn new() -> SessionBuilder<'a, session_state::Empty> {
111 SessionBuilder::new()
112 }
113}
114
115impl<'a> SessionBuilder<'a, session_state::Empty> {
116 /// Create a new builder with all fields unset
117 pub fn new() -> Self {
118 SessionBuilder {
119 _phantom_state: ::core::marker::PhantomData,
120 __unsafe_private_named: (None, None, None, None, None),
121 _phantom: ::core::marker::PhantomData,
122 }
123 }
124}
125
126impl<'a, S> SessionBuilder<'a, S>
127where
128 S: session_state::State,
129 S::CreatedAt: session_state::IsUnset,
130{
131 /// Set the `createdAt` field (required)
132 pub fn created_at(
133 mut self,
134 value: impl Into<jacquard_common::types::string::Datetime>,
135 ) -> SessionBuilder<'a, session_state::SetCreatedAt<S>> {
136 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
137 SessionBuilder {
138 _phantom_state: ::core::marker::PhantomData,
139 __unsafe_private_named: self.__unsafe_private_named,
140 _phantom: ::core::marker::PhantomData,
141 }
142 }
143}
144
145impl<'a, S: session_state::State> SessionBuilder<'a, S> {
146 /// Set the `expiresAt` field (optional)
147 pub fn expires_at(
148 mut self,
149 value: impl Into<Option<jacquard_common::types::string::Datetime>>,
150 ) -> Self {
151 self.__unsafe_private_named.1 = value.into();
152 self
153 }
154 /// Set the `expiresAt` field to an Option value (optional)
155 pub fn maybe_expires_at(
156 mut self,
157 value: Option<jacquard_common::types::string::Datetime>,
158 ) -> Self {
159 self.__unsafe_private_named.1 = value;
160 self
161 }
162}
163
164impl<'a, S> SessionBuilder<'a, S>
165where
166 S: session_state::State,
167 S::NodeId: session_state::IsUnset,
168{
169 /// Set the `nodeId` field (required)
170 pub fn node_id(
171 mut self,
172 value: impl Into<jacquard_common::CowStr<'a>>,
173 ) -> SessionBuilder<'a, session_state::SetNodeId<S>> {
174 self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
175 SessionBuilder {
176 _phantom_state: ::core::marker::PhantomData,
177 __unsafe_private_named: self.__unsafe_private_named,
178 _phantom: ::core::marker::PhantomData,
179 }
180 }
181}
182
183impl<'a, S: session_state::State> SessionBuilder<'a, S> {
184 /// Set the `relayUrl` field (optional)
185 pub fn relay_url(
186 mut self,
187 value: impl Into<Option<jacquard_common::types::string::Uri<'a>>>,
188 ) -> Self {
189 self.__unsafe_private_named.3 = value.into();
190 self
191 }
192 /// Set the `relayUrl` field to an Option value (optional)
193 pub fn maybe_relay_url(
194 mut self,
195 value: Option<jacquard_common::types::string::Uri<'a>>,
196 ) -> Self {
197 self.__unsafe_private_named.3 = value;
198 self
199 }
200}
201
202impl<'a, S> SessionBuilder<'a, S>
203where
204 S: session_state::State,
205 S::Resource: session_state::IsUnset,
206{
207 /// Set the `resource` field (required)
208 pub fn resource(
209 mut self,
210 value: impl Into<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
211 ) -> SessionBuilder<'a, session_state::SetResource<S>> {
212 self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into());
213 SessionBuilder {
214 _phantom_state: ::core::marker::PhantomData,
215 __unsafe_private_named: self.__unsafe_private_named,
216 _phantom: ::core::marker::PhantomData,
217 }
218 }
219}
220
221impl<'a, S> SessionBuilder<'a, S>
222where
223 S: session_state::State,
224 S::CreatedAt: session_state::IsSet,
225 S::Resource: session_state::IsSet,
226 S::NodeId: session_state::IsSet,
227{
228 /// Build the final struct
229 pub fn build(self) -> Session<'a> {
230 Session {
231 created_at: self.__unsafe_private_named.0.unwrap(),
232 expires_at: self.__unsafe_private_named.1,
233 node_id: self.__unsafe_private_named.2.unwrap(),
234 relay_url: self.__unsafe_private_named.3,
235 resource: self.__unsafe_private_named.4.unwrap(),
236 extra_data: Default::default(),
237 }
238 }
239 /// Build the final struct with custom extra_data
240 pub fn build_with_data(
241 self,
242 extra_data: std::collections::BTreeMap<
243 jacquard_common::smol_str::SmolStr,
244 jacquard_common::types::value::Data<'a>,
245 >,
246 ) -> Session<'a> {
247 Session {
248 created_at: self.__unsafe_private_named.0.unwrap(),
249 expires_at: self.__unsafe_private_named.1,
250 node_id: self.__unsafe_private_named.2.unwrap(),
251 relay_url: self.__unsafe_private_named.3,
252 resource: self.__unsafe_private_named.4.unwrap(),
253 extra_data: Some(extra_data),
254 }
255 }
256}
257
258impl<'a> Session<'a> {
259 pub fn uri(
260 uri: impl Into<jacquard_common::CowStr<'a>>,
261 ) -> Result<
262 jacquard_common::types::uri::RecordUri<'a, SessionRecord>,
263 jacquard_common::types::uri::UriError,
264 > {
265 jacquard_common::types::uri::RecordUri::try_from_uri(
266 jacquard_common::types::string::AtUri::new_cow(uri.into())?,
267 )
268 }
269}
270
271/// Typed wrapper for GetRecord response with this collection's record type.
272#[derive(
273 serde::Serialize,
274 serde::Deserialize,
275 Debug,
276 Clone,
277 PartialEq,
278 Eq,
279 jacquard_derive::IntoStatic
280)]
281#[serde(rename_all = "camelCase")]
282pub struct SessionGetRecordOutput<'a> {
283 #[serde(skip_serializing_if = "std::option::Option::is_none")]
284 #[serde(borrow)]
285 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
286 #[serde(borrow)]
287 pub uri: jacquard_common::types::string::AtUri<'a>,
288 #[serde(borrow)]
289 pub value: Session<'a>,
290}
291
292impl From<SessionGetRecordOutput<'_>> for Session<'_> {
293 fn from(output: SessionGetRecordOutput<'_>) -> Self {
294 use jacquard_common::IntoStatic;
295 output.value.into_static()
296 }
297}
298
299impl jacquard_common::types::collection::Collection for Session<'_> {
300 const NSID: &'static str = "sh.weaver.collab.session";
301 type Record = SessionRecord;
302}
303
304/// Marker type for deserializing records from this collection.
305#[derive(Debug, serde::Serialize, serde::Deserialize)]
306pub struct SessionRecord;
307impl jacquard_common::xrpc::XrpcResp for SessionRecord {
308 const NSID: &'static str = "sh.weaver.collab.session";
309 const ENCODING: &'static str = "application/json";
310 type Output<'de> = SessionGetRecordOutput<'de>;
311 type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
312}
313
314impl jacquard_common::types::collection::Collection for SessionRecord {
315 const NSID: &'static str = "sh.weaver.collab.session";
316 type Record = SessionRecord;
317}
318
319impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Session<'a> {
320 fn nsid() -> &'static str {
321 "sh.weaver.collab.session"
322 }
323 fn def_name() -> &'static str {
324 "main"
325 }
326 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
327 lexicon_doc_sh_weaver_collab_session()
328 }
329 fn validate(
330 &self,
331 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
332 Ok(())
333 }
334}
335
336fn lexicon_doc_sh_weaver_collab_session() -> ::jacquard_lexicon::lexicon::LexiconDoc<
337 'static,
338> {
339 ::jacquard_lexicon::lexicon::LexiconDoc {
340 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
341 id: ::jacquard_common::CowStr::new_static("sh.weaver.collab.session"),
342 revision: None,
343 description: None,
344 defs: {
345 let mut map = ::alloc::collections::BTreeMap::new();
346 map.insert(
347 ::jacquard_common::smol_str::SmolStr::new_static("main"),
348 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
349 description: Some(
350 ::jacquard_common::CowStr::new_static(
351 "Active real-time collaboration session. Published when joining a collaborative editing session, deleted on disconnect.",
352 ),
353 ),
354 key: Some(::jacquard_common::CowStr::new_static("tid")),
355 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
356 description: None,
357 required: Some(
358 vec![
359 ::jacquard_common::smol_str::SmolStr::new_static("resource"),
360 ::jacquard_common::smol_str::SmolStr::new_static("nodeId"),
361 ::jacquard_common::smol_str::SmolStr::new_static("createdAt")
362 ],
363 ),
364 nullable: None,
365 properties: {
366 #[allow(unused_mut)]
367 let mut map = ::alloc::collections::BTreeMap::new();
368 map.insert(
369 ::jacquard_common::smol_str::SmolStr::new_static(
370 "createdAt",
371 ),
372 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
373 description: None,
374 format: Some(
375 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
376 ),
377 default: None,
378 min_length: None,
379 max_length: None,
380 min_graphemes: None,
381 max_graphemes: None,
382 r#enum: None,
383 r#const: None,
384 known_values: None,
385 }),
386 );
387 map.insert(
388 ::jacquard_common::smol_str::SmolStr::new_static(
389 "expiresAt",
390 ),
391 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
392 description: Some(
393 ::jacquard_common::CowStr::new_static(
394 "Session TTL. Should be refreshed periodically while active.",
395 ),
396 ),
397 format: Some(
398 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
399 ),
400 default: None,
401 min_length: None,
402 max_length: None,
403 min_graphemes: None,
404 max_graphemes: None,
405 r#enum: None,
406 r#const: None,
407 known_values: None,
408 }),
409 );
410 map.insert(
411 ::jacquard_common::smol_str::SmolStr::new_static("nodeId"),
412 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
413 description: Some(
414 ::jacquard_common::CowStr::new_static(
415 "iroh NodeId in z-base32 encoding for P2P connection.",
416 ),
417 ),
418 format: None,
419 default: None,
420 min_length: None,
421 max_length: None,
422 min_graphemes: None,
423 max_graphemes: None,
424 r#enum: None,
425 r#const: None,
426 known_values: None,
427 }),
428 );
429 map.insert(
430 ::jacquard_common::smol_str::SmolStr::new_static(
431 "relayUrl",
432 ),
433 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
434 description: Some(
435 ::jacquard_common::CowStr::new_static(
436 "DERP relay URL if using relay-only mode (browser clients).",
437 ),
438 ),
439 format: Some(
440 ::jacquard_lexicon::lexicon::LexStringFormat::Uri,
441 ),
442 default: None,
443 min_length: None,
444 max_length: None,
445 min_graphemes: None,
446 max_graphemes: None,
447 r#enum: None,
448 r#const: None,
449 known_values: None,
450 }),
451 );
452 map.insert(
453 ::jacquard_common::smol_str::SmolStr::new_static(
454 "resource",
455 ),
456 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
457 description: None,
458 r#ref: ::jacquard_common::CowStr::new_static(
459 "com.atproto.repo.strongRef",
460 ),
461 }),
462 );
463 map
464 },
465 }),
466 }),
467 );
468 map
469 },
470 }
471}