pub mod create_webhook;
pub mod delete_webhook;
pub mod get_server_time;
pub mod get_webhook;
pub mod list_webhooks;
pub mod settings;
pub mod update_webhook;
#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{Datetime, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::place_stream::server;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct RewriteRule<S: BosStr = DefaultStr> {
pub from: S,
pub to: 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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Webhook<S: BosStr = DefaultStr> {
pub active: bool,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_count: Option<i64>,
pub events: Vec<S>,
pub id: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_triggered: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mute_words: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rewrite: Option<Vec<server::RewriteRule<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub suffix: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
pub url: UriValue<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for RewriteRule<S> {
fn nsid() -> &'static str {
"place.stream.server.defs"
}
fn def_name() -> &'static str {
"rewriteRule"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_stream_server_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.from;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("from"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.from;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("from"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.to;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("to"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Webhook<S> {
fn nsid() -> &'static str {
"place.stream.server.defs"
}
fn def_name() -> &'static str {
"webhook"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_stream_server_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.prefix {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("prefix"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.suffix {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("suffix"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn lexicon_doc_place_stream_server_defs() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("place.stream.server.defs"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("rewriteRule"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("from"), SmolStr::new_static("to")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("from"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Text to search for and replace.",
)),
min_length: Some(1usize),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("to"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Text to replace with.")),
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("webhook"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A webhook configuration for receiving Streamplace events.",
),
),
required: Some(
vec![
SmolStr::new_static("id"), SmolStr::new_static("url"),
SmolStr::new_static("events"), SmolStr::new_static("active"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("active"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this webhook was created."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A description of what this webhook is used for.",
),
),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("errorCount"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("events"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"The types of events this webhook should receive.",
),
),
items: LexArrayItem::String(LexString {
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("id"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Unique identifier for this webhook."),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("lastTriggered"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this webhook was last triggered."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("muteWords"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Words to filter out from chat messages. Messages containing any of these words will not be forwarded.",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(100usize),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("A user-friendly name for this webhook."),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("prefix"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Text to prepend to webhook messages."),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rewrite"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Text replacement rules for webhook messages.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#rewriteRule"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("suffix"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Text to append to webhook messages."),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this webhook was last updated."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The webhook URL where events will be sent.",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod webhook_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Active;
type Id;
type CreatedAt;
type Events;
type Url;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Active = Unset;
type Id = Unset;
type CreatedAt = Unset;
type Events = Unset;
type Url = Unset;
}
pub struct SetActive<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetActive<St> {}
impl<St: State> State for SetActive<St> {
type Active = Set<members::active>;
type Id = St::Id;
type CreatedAt = St::CreatedAt;
type Events = St::Events;
type Url = St::Url;
}
pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetId<St> {}
impl<St: State> State for SetId<St> {
type Active = St::Active;
type Id = Set<members::id>;
type CreatedAt = St::CreatedAt;
type Events = St::Events;
type Url = St::Url;
}
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 Active = St::Active;
type Id = St::Id;
type CreatedAt = Set<members::created_at>;
type Events = St::Events;
type Url = St::Url;
}
pub struct SetEvents<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEvents<St> {}
impl<St: State> State for SetEvents<St> {
type Active = St::Active;
type Id = St::Id;
type CreatedAt = St::CreatedAt;
type Events = Set<members::events>;
type Url = St::Url;
}
pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUrl<St> {}
impl<St: State> State for SetUrl<St> {
type Active = St::Active;
type Id = St::Id;
type CreatedAt = St::CreatedAt;
type Events = St::Events;
type Url = Set<members::url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct active(());
pub struct id(());
pub struct created_at(());
pub struct events(());
pub struct url(());
}
}
pub struct WebhookBuilder<S: BosStr, St: webhook_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<bool>,
Option<Datetime>,
Option<S>,
Option<i64>,
Option<Vec<S>>,
Option<S>,
Option<Datetime>,
Option<Vec<S>>,
Option<S>,
Option<S>,
Option<Vec<server::RewriteRule<S>>>,
Option<S>,
Option<Datetime>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Webhook<S> {
pub fn new() -> WebhookBuilder<S, webhook_state::Empty> {
WebhookBuilder::new()
}
}
impl<S: BosStr> WebhookBuilder<S, webhook_state::Empty> {
pub fn new() -> Self {
WebhookBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> WebhookBuilder<S, St>
where
St: webhook_state::State,
St::Active: webhook_state::IsUnset,
{
pub fn active(
mut self,
value: impl Into<bool>,
) -> WebhookBuilder<S, webhook_state::SetActive<St>> {
self._fields.0 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> WebhookBuilder<S, St>
where
St: webhook_state::State,
St::CreatedAt: webhook_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> WebhookBuilder<S, webhook_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn error_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_error_count(mut self, value: Option<i64>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> WebhookBuilder<S, St>
where
St: webhook_state::State,
St::Events: webhook_state::IsUnset,
{
pub fn events(
mut self,
value: impl Into<Vec<S>>,
) -> WebhookBuilder<S, webhook_state::SetEvents<St>> {
self._fields.4 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> WebhookBuilder<S, St>
where
St: webhook_state::State,
St::Id: webhook_state::IsUnset,
{
pub fn id(mut self, value: impl Into<S>) -> WebhookBuilder<S, webhook_state::SetId<St>> {
self._fields.5 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn last_triggered(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_last_triggered(mut self, value: Option<Datetime>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn mute_words(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_mute_words(mut self, value: Option<Vec<S>>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn prefix(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_prefix(mut self, value: Option<S>) -> Self {
self._fields.9 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn rewrite(mut self, value: impl Into<Option<Vec<server::RewriteRule<S>>>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_rewrite(mut self, value: Option<Vec<server::RewriteRule<S>>>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn suffix(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_suffix(mut self, value: Option<S>) -> Self {
self._fields.11 = value;
self
}
}
impl<S: BosStr, St: webhook_state::State> WebhookBuilder<S, St> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.12 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.12 = value;
self
}
}
impl<S: BosStr, St> WebhookBuilder<S, St>
where
St: webhook_state::State,
St::Url: webhook_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<UriValue<S>>,
) -> WebhookBuilder<S, webhook_state::SetUrl<St>> {
self._fields.13 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> WebhookBuilder<S, St>
where
St: webhook_state::State,
St::Active: webhook_state::IsSet,
St::Id: webhook_state::IsSet,
St::CreatedAt: webhook_state::IsSet,
St::Events: webhook_state::IsSet,
St::Url: webhook_state::IsSet,
{
pub fn build(self) -> Webhook<S> {
Webhook {
active: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
description: self._fields.2,
error_count: self._fields.3,
events: self._fields.4.unwrap(),
id: self._fields.5.unwrap(),
last_triggered: self._fields.6,
mute_words: self._fields.7,
name: self._fields.8,
prefix: self._fields.9,
rewrite: self._fields.10,
suffix: self._fields.11,
updated_at: self._fields.12,
url: self._fields.13.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Webhook<S> {
Webhook {
active: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
description: self._fields.2,
error_count: self._fields.3,
events: self._fields.4.unwrap(),
id: self._fields.5.unwrap(),
last_triggered: self._fields.6,
mute_words: self._fields.7,
name: self._fields.8,
prefix: self._fields.9,
rewrite: self._fields.10,
suffix: self._fields.11,
updated_at: self._fields.12,
url: self._fields.13.unwrap(),
extra_data: Some(extra_data),
}
}
}