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::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Datetime, UriValue};
use jacquard_derive::{IntoStatic, lexicon};
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::place_stream::server;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct RewriteRule<'a> {
#[serde(borrow)]
pub from: CowStr<'a>,
#[serde(borrow)]
pub to: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Webhook<'a> {
pub active: bool,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_count: Option<i64>,
#[serde(borrow)]
pub events: Vec<CowStr<'a>>,
#[serde(borrow)]
pub id: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_triggered: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub mute_words: Option<Vec<CowStr<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub name: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub prefix: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub rewrite: Option<Vec<server::RewriteRule<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub suffix: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[serde(borrow)]
pub url: UriValue<'a>,
}
impl<'a> LexiconSchema for RewriteRule<'a> {
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<'a> LexiconSchema for Webhook<'a> {
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> {
#[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.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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Id;
type Events;
type CreatedAt;
type Active;
type Url;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Id = Unset;
type Events = Unset;
type CreatedAt = Unset;
type Active = Unset;
type Url = Unset;
}
pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetId<S> {}
impl<S: State> State for SetId<S> {
type Id = Set<members::id>;
type Events = S::Events;
type CreatedAt = S::CreatedAt;
type Active = S::Active;
type Url = S::Url;
}
pub struct SetEvents<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetEvents<S> {}
impl<S: State> State for SetEvents<S> {
type Id = S::Id;
type Events = Set<members::events>;
type CreatedAt = S::CreatedAt;
type Active = S::Active;
type Url = S::Url;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Id = S::Id;
type Events = S::Events;
type CreatedAt = Set<members::created_at>;
type Active = S::Active;
type Url = S::Url;
}
pub struct SetActive<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetActive<S> {}
impl<S: State> State for SetActive<S> {
type Id = S::Id;
type Events = S::Events;
type CreatedAt = S::CreatedAt;
type Active = Set<members::active>;
type Url = S::Url;
}
pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUrl<S> {}
impl<S: State> State for SetUrl<S> {
type Id = S::Id;
type Events = S::Events;
type CreatedAt = S::CreatedAt;
type Active = S::Active;
type Url = Set<members::url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct id(());
pub struct events(());
pub struct created_at(());
pub struct active(());
pub struct url(());
}
}
pub struct WebhookBuilder<'a, S: webhook_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<bool>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<i64>,
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<Vec<server::RewriteRule<'a>>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<UriValue<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Webhook<'a> {
pub fn new() -> WebhookBuilder<'a, webhook_state::Empty> {
WebhookBuilder::new()
}
}
impl<'a> WebhookBuilder<'a, 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,
),
_lifetime: PhantomData,
}
}
}
impl<'a, S> WebhookBuilder<'a, S>
where
S: webhook_state::State,
S::Active: webhook_state::IsUnset,
{
pub fn active(
mut self,
value: impl Into<bool>,
) -> WebhookBuilder<'a, webhook_state::SetActive<S>> {
self._fields.0 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> WebhookBuilder<'a, S>
where
S: webhook_state::State,
S::CreatedAt: webhook_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> WebhookBuilder<'a, webhook_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
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<'a, S> WebhookBuilder<'a, S>
where
S: webhook_state::State,
S::Events: webhook_state::IsUnset,
{
pub fn events(
mut self,
value: impl Into<Vec<CowStr<'a>>>,
) -> WebhookBuilder<'a, webhook_state::SetEvents<S>> {
self._fields.4 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> WebhookBuilder<'a, S>
where
S: webhook_state::State,
S::Id: webhook_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<CowStr<'a>>,
) -> WebhookBuilder<'a, webhook_state::SetId<S>> {
self._fields.5 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
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<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
pub fn mute_words(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_mute_words(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.8 = value;
self
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
pub fn prefix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_prefix(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.9 = value;
self
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
pub fn rewrite(
mut self,
value: impl Into<Option<Vec<server::RewriteRule<'a>>>>,
) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_rewrite(mut self, value: Option<Vec<server::RewriteRule<'a>>>) -> Self {
self._fields.10 = value;
self
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
pub fn suffix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_suffix(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.11 = value;
self
}
}
impl<'a, S: webhook_state::State> WebhookBuilder<'a, S> {
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<'a, S> WebhookBuilder<'a, S>
where
S: webhook_state::State,
S::Url: webhook_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<UriValue<'a>>,
) -> WebhookBuilder<'a, webhook_state::SetUrl<S>> {
self._fields.13 = Option::Some(value.into());
WebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> WebhookBuilder<'a, S>
where
S: webhook_state::State,
S::Id: webhook_state::IsSet,
S::Events: webhook_state::IsSet,
S::CreatedAt: webhook_state::IsSet,
S::Active: webhook_state::IsSet,
S::Url: webhook_state::IsSet,
{
pub fn build(self) -> Webhook<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Webhook<'a> {
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),
}
}
}