#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::place_stream::ActivityGame;
use crate::place_stream::ActivityLabel;
use crate::place_stream::media::SourceClip;
use crate::place_stream::media::SourceTracks;
use crate::place_stream::metadata::content_rights::ContentRights;
use crate::place_stream::metadata::content_warnings::ContentWarnings;
use crate::place_stream::richtext::video_facet::VideoFacet;
use crate::place_stream::video;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Connection<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub r#ref: Option<StrongRef<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "place.stream.video",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Video<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub activity: Option<VideoActivity<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<video::Connection<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_rights: Option<ContentRights<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_warnings: Option<ContentWarnings<S>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description_facets: Option<Vec<VideoFacet<S>>>,
pub duration_ms: i64,
pub source: VideoSource<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<BlobRef<S>>,
pub title: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum VideoActivity<S: BosStr = DefaultStr> {
#[serde(rename = "place.stream.defs#activityGame")]
ActivityGame(Box<ActivityGame<S>>),
#[serde(rename = "place.stream.defs#activityLabel")]
ActivityLabel(Box<ActivityLabel<S>>),
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum VideoSource<S: BosStr = DefaultStr> {
#[serde(rename = "place.stream.media.defs#sourceTracks")]
SourceTracks(Box<SourceTracks<S>>),
#[serde(rename = "place.stream.media.defs#sourceClip")]
SourceClip(Box<SourceClip<S>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct VideoGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Video<S>,
}
impl<S: BosStr> Video<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, VideoRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for Connection<S> {
fn nsid() -> &'static str {
"place.stream.video"
}
fn def_name() -> &'static str {
"connection"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_stream_video()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VideoRecord;
impl XrpcResp for VideoRecord {
const NSID: &'static str = "place.stream.video";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = VideoGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<VideoGetRecordOutput<S>> for Video<S> {
fn from(output: VideoGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Video<S> {
const NSID: &'static str = "place.stream.video";
type Record = VideoRecord;
}
impl Collection for VideoRecord {
const NSID: &'static str = "place.stream.video";
type Record = VideoRecord;
}
impl<S: BosStr> LexiconSchema for Video<S> {
fn nsid() -> &'static str {
"place.stream.video"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_stream_video()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 50000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 5000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("description"),
max: 5000usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.tags {
#[allow(unused_comparisons)]
if value.len() > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 10usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.thumb {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("thumb"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.thumb {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("thumb"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1400usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 1400usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 140usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 140usize,
actual: count,
});
}
}
}
Ok(())
}
}
fn lexicon_doc_place_stream_video() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("place.stream.video"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("connection"),
LexUserType::Object(LexObject {
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("ref"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("Some audiovisual content.")),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"), SmolStr::new_static("source"),
SmolStr::new_static("durationMs"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("activity"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static("The game or activity in the video."),
),
refs: vec![
CowStr::new_static("place.stream.defs#activityGame"),
CowStr::new_static("place.stream.defs#activityLabel")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("connections"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Free-form list of atproto records related in some way to this video",
),
),
items: LexArrayItem::Union(LexRefUnion {
refs: vec![CowStr::new_static("#connection")],
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("contentRights"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"place.stream.metadata.contentRights",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("contentWarnings"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"place.stream.metadata.contentWarnings",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when this video record was created. Populated server-side at publication time by place.stream.media.publishVideo.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Description of this video"),
),
max_length: Some(50000usize),
max_graphemes: Some(5000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("descriptionFacets"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Annotations of text (mentions, URLs, etc)",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"place.stream.richtext.videoFacet",
),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("durationMs"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("source"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static("What is the source of this video?"),
),
refs: vec![
CowStr::new_static("place.stream.media.defs#sourceTracks"),
CowStr::new_static("place.stream.media.defs#sourceClip")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Freeform tags for this stream. Each tag must be alphanumeric (a-z, A-Z, 0-9) plus colon. Tags with colons indicate a specific tag group (e.g. 'lang:en' indicates the stream's primary language).",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(640usize),
max_graphemes: Some(64usize),
..Default::default()
}),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("thumb"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Title of the video referenced by this record",
),
),
max_length: Some(1400usize),
max_graphemes: Some(140usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod video_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type CreatedAt;
type DurationMs;
type Source;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type DurationMs = Unset;
type Source = Unset;
type Title = Unset;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type CreatedAt = Set<members::created_at>;
type DurationMs = St::DurationMs;
type Source = St::Source;
type Title = St::Title;
}
pub struct SetDurationMs<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDurationMs<St> {}
impl<St: State> State for SetDurationMs<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = Set<members::duration_ms>;
type Source = St::Source;
type Title = St::Title;
}
pub struct SetSource<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSource<St> {}
impl<St: State> State for SetSource<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = St::DurationMs;
type Source = Set<members::source>;
type Title = St::Title;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = St::DurationMs;
type Source = St::Source;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct duration_ms(());
pub struct source(());
pub struct title(());
}
}
pub struct VideoBuilder<St: video_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<VideoActivity<S>>,
Option<Vec<video::Connection<S>>>,
Option<ContentRights<S>>,
Option<ContentWarnings<S>>,
Option<Datetime>,
Option<S>,
Option<Vec<VideoFacet<S>>>,
Option<i64>,
Option<VideoSource<S>>,
Option<Vec<S>>,
Option<BlobRef<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl Video<DefaultStr> {
pub fn new() -> VideoBuilder<video_state::Empty, DefaultStr> {
VideoBuilder::new()
}
}
impl<S: BosStr> Video<S> {
pub fn builder() -> VideoBuilder<video_state::Empty, S> {
VideoBuilder::builder()
}
}
impl VideoBuilder<video_state::Empty, DefaultStr> {
pub fn new() -> Self {
VideoBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr> VideoBuilder<video_state::Empty, S> {
pub fn builder() -> Self {
VideoBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_type: PhantomData,
}
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn activity(mut self, value: impl Into<Option<VideoActivity<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_activity(mut self, value: Option<VideoActivity<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn connections(
mut self,
value: impl Into<Option<Vec<video::Connection<S>>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_connections(
mut self,
value: Option<Vec<video::Connection<S>>>,
) -> Self {
self._fields.1 = value;
self
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn content_rights(mut self, value: impl Into<Option<ContentRights<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_content_rights(mut self, value: Option<ContentRights<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn content_warnings(
mut self,
value: impl Into<Option<ContentWarnings<S>>>,
) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_content_warnings(mut self, value: Option<ContentWarnings<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<St, S: BosStr> VideoBuilder<St, S>
where
St: video_state::State,
St::CreatedAt: video_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> VideoBuilder<video_state::SetCreatedAt<St>, S> {
self._fields.4 = Option::Some(value.into());
VideoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn description_facets(
mut self,
value: impl Into<Option<Vec<VideoFacet<S>>>>,
) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_description_facets(
mut self,
value: Option<Vec<VideoFacet<S>>>,
) -> Self {
self._fields.6 = value;
self
}
}
impl<St, S: BosStr> VideoBuilder<St, S>
where
St: video_state::State,
St::DurationMs: video_state::IsUnset,
{
pub fn duration_ms(
mut self,
value: impl Into<i64>,
) -> VideoBuilder<video_state::SetDurationMs<St>, S> {
self._fields.7 = Option::Some(value.into());
VideoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> VideoBuilder<St, S>
where
St: video_state::State,
St::Source: video_state::IsUnset,
{
pub fn source(
mut self,
value: impl Into<VideoSource<S>>,
) -> VideoBuilder<video_state::SetSource<St>, S> {
self._fields.8 = Option::Some(value.into());
VideoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
self._fields.9 = value;
self
}
}
impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
pub fn thumb(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_thumb(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.10 = value;
self
}
}
impl<St, S: BosStr> VideoBuilder<St, S>
where
St: video_state::State,
St::Title: video_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> VideoBuilder<video_state::SetTitle<St>, S> {
self._fields.11 = Option::Some(value.into());
VideoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> VideoBuilder<St, S>
where
St: video_state::State,
St::CreatedAt: video_state::IsSet,
St::DurationMs: video_state::IsSet,
St::Source: video_state::IsSet,
St::Title: video_state::IsSet,
{
pub fn build(self) -> Video<S> {
Video {
activity: self._fields.0,
connections: self._fields.1,
content_rights: self._fields.2,
content_warnings: self._fields.3,
created_at: self._fields.4.unwrap(),
description: self._fields.5,
description_facets: self._fields.6,
duration_ms: self._fields.7.unwrap(),
source: self._fields.8.unwrap(),
tags: self._fields.9,
thumb: self._fields.10,
title: self._fields.11.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Video<S> {
Video {
activity: self._fields.0,
connections: self._fields.1,
content_rights: self._fields.2,
content_warnings: self._fields.3,
created_at: self._fields.4.unwrap(),
description: self._fields.5,
description_facets: self._fields.6,
duration_ms: self._fields.7.unwrap(),
source: self._fields.8.unwrap(),
tags: self._fields.9,
thumb: self._fields.10,
title: self._fields.11.unwrap(),
extra_data: Some(extra_data),
}
}
}