jacquard_api/place_stream/multistream/
target.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, 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.multistream.target",
35 tag = "$type"
36)]
37pub struct Target<'a> {
38 pub active: bool,
40 pub created_at: Datetime,
42 #[serde(skip_serializing_if = "Option::is_none")]
44 #[serde(borrow)]
45 pub name: Option<CowStr<'a>>,
46 #[serde(borrow)]
48 pub url: UriValue<'a>,
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
54#[serde(rename_all = "camelCase")]
55pub struct TargetGetRecordOutput<'a> {
56 #[serde(skip_serializing_if = "Option::is_none")]
57 #[serde(borrow)]
58 pub cid: Option<Cid<'a>>,
59 #[serde(borrow)]
60 pub uri: AtUri<'a>,
61 #[serde(borrow)]
62 pub value: Target<'a>,
63}
64
65impl<'a> Target<'a> {
66 pub fn uri(
67 uri: impl Into<CowStr<'a>>,
68 ) -> Result<RecordUri<'a, TargetRecord>, UriError> {
69 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
70 }
71}
72
73#[derive(Debug, Serialize, Deserialize)]
76pub struct TargetRecord;
77impl XrpcResp for TargetRecord {
78 const NSID: &'static str = "place.stream.multistream.target";
79 const ENCODING: &'static str = "application/json";
80 type Output<'de> = TargetGetRecordOutput<'de>;
81 type Err<'de> = RecordError<'de>;
82}
83
84impl From<TargetGetRecordOutput<'_>> for Target<'_> {
85 fn from(output: TargetGetRecordOutput<'_>) -> Self {
86 use jacquard_common::IntoStatic;
87 output.value.into_static()
88 }
89}
90
91impl Collection for Target<'_> {
92 const NSID: &'static str = "place.stream.multistream.target";
93 type Record = TargetRecord;
94}
95
96impl Collection for TargetRecord {
97 const NSID: &'static str = "place.stream.multistream.target";
98 type Record = TargetRecord;
99}
100
101impl<'a> LexiconSchema for Target<'a> {
102 fn nsid() -> &'static str {
103 "place.stream.multistream.target"
104 }
105 fn def_name() -> &'static str {
106 "main"
107 }
108 fn lexicon_doc() -> LexiconDoc<'static> {
109 lexicon_doc_place_stream_multistream_target()
110 }
111 fn validate(&self) -> Result<(), ConstraintError> {
112 if let Some(ref value) = self.name {
113 #[allow(unused_comparisons)]
114 if <str>::len(value.as_ref()) > 100usize {
115 return Err(ConstraintError::MaxLength {
116 path: ValidationPath::from_field("name"),
117 max: 100usize,
118 actual: <str>::len(value.as_ref()),
119 });
120 }
121 }
122 Ok(())
123 }
124}
125
126pub mod target_state {
127
128 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
129 #[allow(unused)]
130 use ::core::marker::PhantomData;
131 mod sealed {
132 pub trait Sealed {}
133 }
134 pub trait State: sealed::Sealed {
136 type Active;
137 type CreatedAt;
138 type Url;
139 }
140 pub struct Empty(());
142 impl sealed::Sealed for Empty {}
143 impl State for Empty {
144 type Active = Unset;
145 type CreatedAt = Unset;
146 type Url = Unset;
147 }
148 pub struct SetActive<S: State = Empty>(PhantomData<fn() -> S>);
150 impl<S: State> sealed::Sealed for SetActive<S> {}
151 impl<S: State> State for SetActive<S> {
152 type Active = Set<members::active>;
153 type CreatedAt = S::CreatedAt;
154 type Url = S::Url;
155 }
156 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
158 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
159 impl<S: State> State for SetCreatedAt<S> {
160 type Active = S::Active;
161 type CreatedAt = Set<members::created_at>;
162 type Url = S::Url;
163 }
164 pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
166 impl<S: State> sealed::Sealed for SetUrl<S> {}
167 impl<S: State> State for SetUrl<S> {
168 type Active = S::Active;
169 type CreatedAt = S::CreatedAt;
170 type Url = Set<members::url>;
171 }
172 #[allow(non_camel_case_types)]
174 pub mod members {
175 pub struct active(());
177 pub struct created_at(());
179 pub struct url(());
181 }
182}
183
184pub struct TargetBuilder<'a, S: target_state::State> {
186 _state: PhantomData<fn() -> S>,
187 _fields: (Option<bool>, Option<Datetime>, Option<CowStr<'a>>, Option<UriValue<'a>>),
188 _lifetime: PhantomData<&'a ()>,
189}
190
191impl<'a> Target<'a> {
192 pub fn new() -> TargetBuilder<'a, target_state::Empty> {
194 TargetBuilder::new()
195 }
196}
197
198impl<'a> TargetBuilder<'a, target_state::Empty> {
199 pub fn new() -> Self {
201 TargetBuilder {
202 _state: PhantomData,
203 _fields: (None, None, None, None),
204 _lifetime: PhantomData,
205 }
206 }
207}
208
209impl<'a, S> TargetBuilder<'a, S>
210where
211 S: target_state::State,
212 S::Active: target_state::IsUnset,
213{
214 pub fn active(
216 mut self,
217 value: impl Into<bool>,
218 ) -> TargetBuilder<'a, target_state::SetActive<S>> {
219 self._fields.0 = Option::Some(value.into());
220 TargetBuilder {
221 _state: PhantomData,
222 _fields: self._fields,
223 _lifetime: PhantomData,
224 }
225 }
226}
227
228impl<'a, S> TargetBuilder<'a, S>
229where
230 S: target_state::State,
231 S::CreatedAt: target_state::IsUnset,
232{
233 pub fn created_at(
235 mut self,
236 value: impl Into<Datetime>,
237 ) -> TargetBuilder<'a, target_state::SetCreatedAt<S>> {
238 self._fields.1 = Option::Some(value.into());
239 TargetBuilder {
240 _state: PhantomData,
241 _fields: self._fields,
242 _lifetime: PhantomData,
243 }
244 }
245}
246
247impl<'a, S: target_state::State> TargetBuilder<'a, S> {
248 pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
250 self._fields.2 = value.into();
251 self
252 }
253 pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
255 self._fields.2 = value;
256 self
257 }
258}
259
260impl<'a, S> TargetBuilder<'a, S>
261where
262 S: target_state::State,
263 S::Url: target_state::IsUnset,
264{
265 pub fn url(
267 mut self,
268 value: impl Into<UriValue<'a>>,
269 ) -> TargetBuilder<'a, target_state::SetUrl<S>> {
270 self._fields.3 = Option::Some(value.into());
271 TargetBuilder {
272 _state: PhantomData,
273 _fields: self._fields,
274 _lifetime: PhantomData,
275 }
276 }
277}
278
279impl<'a, S> TargetBuilder<'a, S>
280where
281 S: target_state::State,
282 S::Active: target_state::IsSet,
283 S::CreatedAt: target_state::IsSet,
284 S::Url: target_state::IsSet,
285{
286 pub fn build(self) -> Target<'a> {
288 Target {
289 active: self._fields.0.unwrap(),
290 created_at: self._fields.1.unwrap(),
291 name: self._fields.2,
292 url: self._fields.3.unwrap(),
293 extra_data: Default::default(),
294 }
295 }
296 pub fn build_with_data(
298 self,
299 extra_data: BTreeMap<
300 jacquard_common::deps::smol_str::SmolStr,
301 jacquard_common::types::value::Data<'a>,
302 >,
303 ) -> Target<'a> {
304 Target {
305 active: self._fields.0.unwrap(),
306 created_at: self._fields.1.unwrap(),
307 name: self._fields.2,
308 url: self._fields.3.unwrap(),
309 extra_data: Some(extra_data),
310 }
311 }
312}
313
314fn lexicon_doc_place_stream_multistream_target() -> LexiconDoc<'static> {
315 #[allow(unused_imports)]
316 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
317 use jacquard_lexicon::lexicon::*;
318 use alloc::collections::BTreeMap;
319 LexiconDoc {
320 lexicon: Lexicon::Lexicon1,
321 id: CowStr::new_static("place.stream.multistream.target"),
322 defs: {
323 let mut map = BTreeMap::new();
324 map.insert(
325 SmolStr::new_static("main"),
326 LexUserType::Record(LexRecord {
327 description: Some(
328 CowStr::new_static(
329 "An external server for rebroadcasting a Streamplace stream",
330 ),
331 ),
332 key: Some(CowStr::new_static("tid")),
333 record: LexRecordRecord::Object(LexObject {
334 required: Some(
335 vec![
336 SmolStr::new_static("url"), SmolStr::new_static("active"),
337 SmolStr::new_static("createdAt")
338 ],
339 ),
340 properties: {
341 #[allow(unused_mut)]
342 let mut map = BTreeMap::new();
343 map.insert(
344 SmolStr::new_static("active"),
345 LexObjectProperty::Boolean(LexBoolean {
346 ..Default::default()
347 }),
348 );
349 map.insert(
350 SmolStr::new_static("createdAt"),
351 LexObjectProperty::String(LexString {
352 description: Some(
353 CowStr::new_static("When this target was created."),
354 ),
355 format: Some(LexStringFormat::Datetime),
356 ..Default::default()
357 }),
358 );
359 map.insert(
360 SmolStr::new_static("name"),
361 LexObjectProperty::String(LexString {
362 description: Some(
363 CowStr::new_static("A user-friendly name for this target."),
364 ),
365 max_length: Some(100usize),
366 ..Default::default()
367 }),
368 );
369 map.insert(
370 SmolStr::new_static("url"),
371 LexObjectProperty::String(LexString {
372 description: Some(
373 CowStr::new_static(
374 "The rtmp:// or rtmps:// url of the target server.",
375 ),
376 ),
377 format: Some(LexStringFormat::Uri),
378 ..Default::default()
379 }),
380 );
381 map
382 },
383 ..Default::default()
384 }),
385 ..Default::default()
386 }),
387 );
388 map
389 },
390 ..Default::default()
391 }
392}