1#[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::{Did, AtUri, Cid, Datetime, UriValue};
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(
33 rename_all = "camelCase",
34 rename = "place.stream.broadcast.origin",
35 tag = "$type"
36)]
37pub struct Origin<'a> {
38 #[serde(skip_serializing_if = "Option::is_none")]
40 #[serde(borrow)]
41 pub broadcaster: Option<Did<'a>>,
42 #[serde(skip_serializing_if = "Option::is_none")]
44 #[serde(borrow)]
45 pub iroh_ticket: Option<CowStr<'a>>,
46 #[serde(borrow)]
48 pub server: Did<'a>,
49 #[serde(borrow)]
51 pub streamer: Did<'a>,
52 pub updated_at: Datetime,
54 #[serde(skip_serializing_if = "Option::is_none")]
56 #[serde(borrow)]
57 pub websocket_url: Option<UriValue<'a>>,
58}
59
60#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
63#[serde(rename_all = "camelCase")]
64pub struct OriginGetRecordOutput<'a> {
65 #[serde(skip_serializing_if = "Option::is_none")]
66 #[serde(borrow)]
67 pub cid: Option<Cid<'a>>,
68 #[serde(borrow)]
69 pub uri: AtUri<'a>,
70 #[serde(borrow)]
71 pub value: Origin<'a>,
72}
73
74impl<'a> Origin<'a> {
75 pub fn uri(
76 uri: impl Into<CowStr<'a>>,
77 ) -> Result<RecordUri<'a, OriginRecord>, UriError> {
78 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
79 }
80}
81
82#[derive(Debug, Serialize, Deserialize)]
85pub struct OriginRecord;
86impl XrpcResp for OriginRecord {
87 const NSID: &'static str = "place.stream.broadcast.origin";
88 const ENCODING: &'static str = "application/json";
89 type Output<'de> = OriginGetRecordOutput<'de>;
90 type Err<'de> = RecordError<'de>;
91}
92
93impl From<OriginGetRecordOutput<'_>> for Origin<'_> {
94 fn from(output: OriginGetRecordOutput<'_>) -> Self {
95 use jacquard_common::IntoStatic;
96 output.value.into_static()
97 }
98}
99
100impl Collection for Origin<'_> {
101 const NSID: &'static str = "place.stream.broadcast.origin";
102 type Record = OriginRecord;
103}
104
105impl Collection for OriginRecord {
106 const NSID: &'static str = "place.stream.broadcast.origin";
107 type Record = OriginRecord;
108}
109
110impl<'a> LexiconSchema for Origin<'a> {
111 fn nsid() -> &'static str {
112 "place.stream.broadcast.origin"
113 }
114 fn def_name() -> &'static str {
115 "main"
116 }
117 fn lexicon_doc() -> LexiconDoc<'static> {
118 lexicon_doc_place_stream_broadcast_origin()
119 }
120 fn validate(&self) -> Result<(), ConstraintError> {
121 if let Some(ref value) = self.iroh_ticket {
122 #[allow(unused_comparisons)]
123 if <str>::len(value.as_ref()) > 2048usize {
124 return Err(ConstraintError::MaxLength {
125 path: ValidationPath::from_field("iroh_ticket"),
126 max: 2048usize,
127 actual: <str>::len(value.as_ref()),
128 });
129 }
130 }
131 Ok(())
132 }
133}
134
135pub mod origin_state {
136
137 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
138 #[allow(unused)]
139 use ::core::marker::PhantomData;
140 mod sealed {
141 pub trait Sealed {}
142 }
143 pub trait State: sealed::Sealed {
145 type Streamer;
146 type Server;
147 type UpdatedAt;
148 }
149 pub struct Empty(());
151 impl sealed::Sealed for Empty {}
152 impl State for Empty {
153 type Streamer = Unset;
154 type Server = Unset;
155 type UpdatedAt = Unset;
156 }
157 pub struct SetStreamer<S: State = Empty>(PhantomData<fn() -> S>);
159 impl<S: State> sealed::Sealed for SetStreamer<S> {}
160 impl<S: State> State for SetStreamer<S> {
161 type Streamer = Set<members::streamer>;
162 type Server = S::Server;
163 type UpdatedAt = S::UpdatedAt;
164 }
165 pub struct SetServer<S: State = Empty>(PhantomData<fn() -> S>);
167 impl<S: State> sealed::Sealed for SetServer<S> {}
168 impl<S: State> State for SetServer<S> {
169 type Streamer = S::Streamer;
170 type Server = Set<members::server>;
171 type UpdatedAt = S::UpdatedAt;
172 }
173 pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
175 impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
176 impl<S: State> State for SetUpdatedAt<S> {
177 type Streamer = S::Streamer;
178 type Server = S::Server;
179 type UpdatedAt = Set<members::updated_at>;
180 }
181 #[allow(non_camel_case_types)]
183 pub mod members {
184 pub struct streamer(());
186 pub struct server(());
188 pub struct updated_at(());
190 }
191}
192
193pub struct OriginBuilder<'a, S: origin_state::State> {
195 _state: PhantomData<fn() -> S>,
196 _fields: (
197 Option<Did<'a>>,
198 Option<CowStr<'a>>,
199 Option<Did<'a>>,
200 Option<Did<'a>>,
201 Option<Datetime>,
202 Option<UriValue<'a>>,
203 ),
204 _lifetime: PhantomData<&'a ()>,
205}
206
207impl<'a> Origin<'a> {
208 pub fn new() -> OriginBuilder<'a, origin_state::Empty> {
210 OriginBuilder::new()
211 }
212}
213
214impl<'a> OriginBuilder<'a, origin_state::Empty> {
215 pub fn new() -> Self {
217 OriginBuilder {
218 _state: PhantomData,
219 _fields: (None, None, None, None, None, None),
220 _lifetime: PhantomData,
221 }
222 }
223}
224
225impl<'a, S: origin_state::State> OriginBuilder<'a, S> {
226 pub fn broadcaster(mut self, value: impl Into<Option<Did<'a>>>) -> Self {
228 self._fields.0 = value.into();
229 self
230 }
231 pub fn maybe_broadcaster(mut self, value: Option<Did<'a>>) -> Self {
233 self._fields.0 = value;
234 self
235 }
236}
237
238impl<'a, S: origin_state::State> OriginBuilder<'a, S> {
239 pub fn iroh_ticket(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
241 self._fields.1 = value.into();
242 self
243 }
244 pub fn maybe_iroh_ticket(mut self, value: Option<CowStr<'a>>) -> Self {
246 self._fields.1 = value;
247 self
248 }
249}
250
251impl<'a, S> OriginBuilder<'a, S>
252where
253 S: origin_state::State,
254 S::Server: origin_state::IsUnset,
255{
256 pub fn server(
258 mut self,
259 value: impl Into<Did<'a>>,
260 ) -> OriginBuilder<'a, origin_state::SetServer<S>> {
261 self._fields.2 = Option::Some(value.into());
262 OriginBuilder {
263 _state: PhantomData,
264 _fields: self._fields,
265 _lifetime: PhantomData,
266 }
267 }
268}
269
270impl<'a, S> OriginBuilder<'a, S>
271where
272 S: origin_state::State,
273 S::Streamer: origin_state::IsUnset,
274{
275 pub fn streamer(
277 mut self,
278 value: impl Into<Did<'a>>,
279 ) -> OriginBuilder<'a, origin_state::SetStreamer<S>> {
280 self._fields.3 = Option::Some(value.into());
281 OriginBuilder {
282 _state: PhantomData,
283 _fields: self._fields,
284 _lifetime: PhantomData,
285 }
286 }
287}
288
289impl<'a, S> OriginBuilder<'a, S>
290where
291 S: origin_state::State,
292 S::UpdatedAt: origin_state::IsUnset,
293{
294 pub fn updated_at(
296 mut self,
297 value: impl Into<Datetime>,
298 ) -> OriginBuilder<'a, origin_state::SetUpdatedAt<S>> {
299 self._fields.4 = Option::Some(value.into());
300 OriginBuilder {
301 _state: PhantomData,
302 _fields: self._fields,
303 _lifetime: PhantomData,
304 }
305 }
306}
307
308impl<'a, S: origin_state::State> OriginBuilder<'a, S> {
309 pub fn websocket_url(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
311 self._fields.5 = value.into();
312 self
313 }
314 pub fn maybe_websocket_url(mut self, value: Option<UriValue<'a>>) -> Self {
316 self._fields.5 = value;
317 self
318 }
319}
320
321impl<'a, S> OriginBuilder<'a, S>
322where
323 S: origin_state::State,
324 S::Streamer: origin_state::IsSet,
325 S::Server: origin_state::IsSet,
326 S::UpdatedAt: origin_state::IsSet,
327{
328 pub fn build(self) -> Origin<'a> {
330 Origin {
331 broadcaster: self._fields.0,
332 iroh_ticket: self._fields.1,
333 server: self._fields.2.unwrap(),
334 streamer: self._fields.3.unwrap(),
335 updated_at: self._fields.4.unwrap(),
336 websocket_url: self._fields.5,
337 extra_data: Default::default(),
338 }
339 }
340 pub fn build_with_data(
342 self,
343 extra_data: BTreeMap<
344 jacquard_common::deps::smol_str::SmolStr,
345 jacquard_common::types::value::Data<'a>,
346 >,
347 ) -> Origin<'a> {
348 Origin {
349 broadcaster: self._fields.0,
350 iroh_ticket: self._fields.1,
351 server: self._fields.2.unwrap(),
352 streamer: self._fields.3.unwrap(),
353 updated_at: self._fields.4.unwrap(),
354 websocket_url: self._fields.5,
355 extra_data: Some(extra_data),
356 }
357 }
358}
359
360fn lexicon_doc_place_stream_broadcast_origin() -> LexiconDoc<'static> {
361 #[allow(unused_imports)]
362 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
363 use jacquard_lexicon::lexicon::*;
364 use alloc::collections::BTreeMap;
365 LexiconDoc {
366 lexicon: Lexicon::Lexicon1,
367 id: CowStr::new_static("place.stream.broadcast.origin"),
368 defs: {
369 let mut map = BTreeMap::new();
370 map.insert(
371 SmolStr::new_static("main"),
372 LexUserType::Record(LexRecord {
373 description: Some(
374 CowStr::new_static(
375 "Record indicating a livestream is published and available for replication at a given address. By convention, the record key is streamer::server",
376 ),
377 ),
378 key: Some(CowStr::new_static("any")),
379 record: LexRecordRecord::Object(LexObject {
380 required: Some(
381 vec![
382 SmolStr::new_static("streamer"),
383 SmolStr::new_static("server"),
384 SmolStr::new_static("updatedAt")
385 ],
386 ),
387 properties: {
388 #[allow(unused_mut)]
389 let mut map = BTreeMap::new();
390 map.insert(
391 SmolStr::new_static("broadcaster"),
392 LexObjectProperty::String(LexString {
393 description: Some(
394 CowStr::new_static(
395 "did of the broadcaster that operates the server syndicating the livestream",
396 ),
397 ),
398 format: Some(LexStringFormat::Did),
399 ..Default::default()
400 }),
401 );
402 map.insert(
403 SmolStr::new_static("irohTicket"),
404 LexObjectProperty::String(LexString {
405 description: Some(
406 CowStr::new_static(
407 "Iroh ticket that can be used to access the livestream from the server",
408 ),
409 ),
410 max_length: Some(2048usize),
411 ..Default::default()
412 }),
413 );
414 map.insert(
415 SmolStr::new_static("server"),
416 LexObjectProperty::String(LexString {
417 description: Some(
418 CowStr::new_static(
419 "did of the server that's currently rebroadcasting the livestream",
420 ),
421 ),
422 format: Some(LexStringFormat::Did),
423 ..Default::default()
424 }),
425 );
426 map.insert(
427 SmolStr::new_static("streamer"),
428 LexObjectProperty::String(LexString {
429 description: Some(
430 CowStr::new_static(
431 "DID of the streamer whose livestream is being published",
432 ),
433 ),
434 format: Some(LexStringFormat::Did),
435 ..Default::default()
436 }),
437 );
438 map.insert(
439 SmolStr::new_static("updatedAt"),
440 LexObjectProperty::String(LexString {
441 description: Some(
442 CowStr::new_static(
443 "Periodically updated timestamp when this origin last saw a livestream",
444 ),
445 ),
446 format: Some(LexStringFormat::Datetime),
447 ..Default::default()
448 }),
449 );
450 map.insert(
451 SmolStr::new_static("websocketURL"),
452 LexObjectProperty::String(LexString {
453 description: Some(
454 CowStr::new_static(
455 "URL of the websocket endpoint for the livestream",
456 ),
457 ),
458 format: Some(LexStringFormat::Uri),
459 ..Default::default()
460 }),
461 );
462 map
463 },
464 ..Default::default()
465 }),
466 ..Default::default()
467 }),
468 );
469 map
470 },
471 ..Default::default()
472 }
473}