pub mod add_rule;
pub mod query_events;
pub mod query_rules;
pub mod remove_rule;
pub mod update_rule;
#[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, Did};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::tools_ozone::safelink;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ActionType<S: BosStr = DefaultStr> {
Block,
Warn,
Whitelist,
Other(S),
}
impl<S: BosStr> ActionType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Block => "block",
Self::Warn => "warn",
Self::Whitelist => "whitelist",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"block" => Self::Block,
"warn" => Self::Warn,
"whitelist" => Self::Whitelist,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> AsRef<str> for ActionType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> core::fmt::Display for ActionType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> Serialize for ActionType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ActionType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ActionType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ActionType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ActionType::Block => ActionType::Block,
ActionType::Warn => ActionType::Warn,
ActionType::Whitelist => ActionType::Whitelist,
ActionType::Other(v) => ActionType::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Event<S: BosStr = DefaultStr> {
pub action: safelink::ActionType<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<S>,
pub created_at: Datetime,
pub created_by: Did<S>,
pub event_type: safelink::EventType<S>,
pub id: i64,
pub pattern: safelink::PatternType<S>,
pub reason: safelink::ReasonType<S>,
pub url: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EventType<S: BosStr = DefaultStr> {
AddRule,
UpdateRule,
RemoveRule,
Other(S),
}
impl<S: BosStr> EventType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::AddRule => "addRule",
Self::UpdateRule => "updateRule",
Self::RemoveRule => "removeRule",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"addRule" => Self::AddRule,
"updateRule" => Self::UpdateRule,
"removeRule" => Self::RemoveRule,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> AsRef<str> for EventType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> core::fmt::Display for EventType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> Serialize for EventType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for EventType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr> jacquard_common::IntoStatic for EventType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = EventType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
EventType::AddRule => EventType::AddRule,
EventType::UpdateRule => EventType::UpdateRule,
EventType::RemoveRule => EventType::RemoveRule,
EventType::Other(v) => EventType::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PatternType<S: BosStr = DefaultStr> {
Domain,
Url,
Other(S),
}
impl<S: BosStr> PatternType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Domain => "domain",
Self::Url => "url",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"domain" => Self::Domain,
"url" => Self::Url,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> AsRef<str> for PatternType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> core::fmt::Display for PatternType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> Serialize for PatternType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for PatternType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr> jacquard_common::IntoStatic for PatternType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = PatternType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
PatternType::Domain => PatternType::Domain,
PatternType::Url => PatternType::Url,
PatternType::Other(v) => PatternType::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ReasonType<S: BosStr = DefaultStr> {
Csam,
Spam,
Phishing,
None,
Other(S),
}
impl<S: BosStr> ReasonType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Csam => "csam",
Self::Spam => "spam",
Self::Phishing => "phishing",
Self::None => "none",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"csam" => Self::Csam,
"spam" => Self::Spam,
"phishing" => Self::Phishing,
"none" => Self::None,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> AsRef<str> for ReasonType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> core::fmt::Display for ReasonType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> Serialize for ReasonType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ReasonType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ReasonType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ReasonType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ReasonType::Csam => ReasonType::Csam,
ReasonType::Spam => ReasonType::Spam,
ReasonType::Phishing => ReasonType::Phishing,
ReasonType::None => ReasonType::None,
ReasonType::Other(v) => ReasonType::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct UrlRule<S: BosStr = DefaultStr> {
pub action: safelink::ActionType<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<S>,
pub created_at: Datetime,
pub created_by: Did<S>,
pub pattern: safelink::PatternType<S>,
pub reason: safelink::ReasonType<S>,
pub updated_at: Datetime,
pub url: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for Event<S> {
fn nsid() -> &'static str {
"tools.ozone.safelink.defs"
}
fn def_name() -> &'static str {
"event"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_tools_ozone_safelink_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for UrlRule<S> {
fn nsid() -> &'static str {
"tools.ozone.safelink.defs"
}
fn def_name() -> &'static str {
"urlRule"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_tools_ozone_safelink_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod event_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 Reason;
type Url;
type Action;
type CreatedAt;
type EventType;
type CreatedBy;
type Id;
type Pattern;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Reason = Unset;
type Url = Unset;
type Action = Unset;
type CreatedAt = Unset;
type EventType = Unset;
type CreatedBy = Unset;
type Id = Unset;
type Pattern = Unset;
}
pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetReason<St> {}
impl<St: State> State for SetReason<St> {
type Reason = Set<members::reason>;
type Url = St::Url;
type Action = St::Action;
type CreatedAt = St::CreatedAt;
type EventType = St::EventType;
type CreatedBy = St::CreatedBy;
type Id = St::Id;
type Pattern = St::Pattern;
}
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 Reason = St::Reason;
type Url = Set<members::url>;
type Action = St::Action;
type CreatedAt = St::CreatedAt;
type EventType = St::EventType;
type CreatedBy = St::CreatedBy;
type Id = St::Id;
type Pattern = St::Pattern;
}
pub struct SetAction<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAction<St> {}
impl<St: State> State for SetAction<St> {
type Reason = St::Reason;
type Url = St::Url;
type Action = Set<members::action>;
type CreatedAt = St::CreatedAt;
type EventType = St::EventType;
type CreatedBy = St::CreatedBy;
type Id = St::Id;
type Pattern = St::Pattern;
}
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 Reason = St::Reason;
type Url = St::Url;
type Action = St::Action;
type CreatedAt = Set<members::created_at>;
type EventType = St::EventType;
type CreatedBy = St::CreatedBy;
type Id = St::Id;
type Pattern = St::Pattern;
}
pub struct SetEventType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEventType<St> {}
impl<St: State> State for SetEventType<St> {
type Reason = St::Reason;
type Url = St::Url;
type Action = St::Action;
type CreatedAt = St::CreatedAt;
type EventType = Set<members::event_type>;
type CreatedBy = St::CreatedBy;
type Id = St::Id;
type Pattern = St::Pattern;
}
pub struct SetCreatedBy<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedBy<St> {}
impl<St: State> State for SetCreatedBy<St> {
type Reason = St::Reason;
type Url = St::Url;
type Action = St::Action;
type CreatedAt = St::CreatedAt;
type EventType = St::EventType;
type CreatedBy = Set<members::created_by>;
type Id = St::Id;
type Pattern = St::Pattern;
}
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 Reason = St::Reason;
type Url = St::Url;
type Action = St::Action;
type CreatedAt = St::CreatedAt;
type EventType = St::EventType;
type CreatedBy = St::CreatedBy;
type Id = Set<members::id>;
type Pattern = St::Pattern;
}
pub struct SetPattern<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPattern<St> {}
impl<St: State> State for SetPattern<St> {
type Reason = St::Reason;
type Url = St::Url;
type Action = St::Action;
type CreatedAt = St::CreatedAt;
type EventType = St::EventType;
type CreatedBy = St::CreatedBy;
type Id = St::Id;
type Pattern = Set<members::pattern>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct reason(());
pub struct url(());
pub struct action(());
pub struct created_at(());
pub struct event_type(());
pub struct created_by(());
pub struct id(());
pub struct pattern(());
}
}
pub struct EventBuilder<S: BosStr, St: event_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<safelink::ActionType<S>>,
Option<S>,
Option<Datetime>,
Option<Did<S>>,
Option<safelink::EventType<S>>,
Option<i64>,
Option<safelink::PatternType<S>>,
Option<safelink::ReasonType<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Event<S> {
pub fn new() -> EventBuilder<S, event_state::Empty> {
EventBuilder::new()
}
}
impl<S: BosStr> EventBuilder<S, event_state::Empty> {
pub fn new() -> Self {
EventBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Action: event_state::IsUnset,
{
pub fn action(
mut self,
value: impl Into<safelink::ActionType<S>>,
) -> EventBuilder<S, event_state::SetAction<St>> {
self._fields.0 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: event_state::State> EventBuilder<S, St> {
pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_comment(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::CreatedAt: event_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> EventBuilder<S, event_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::CreatedBy: event_state::IsUnset,
{
pub fn created_by(
mut self,
value: impl Into<Did<S>>,
) -> EventBuilder<S, event_state::SetCreatedBy<St>> {
self._fields.3 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::EventType: event_state::IsUnset,
{
pub fn event_type(
mut self,
value: impl Into<safelink::EventType<S>>,
) -> EventBuilder<S, event_state::SetEventType<St>> {
self._fields.4 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Id: event_state::IsUnset,
{
pub fn id(mut self, value: impl Into<i64>) -> EventBuilder<S, event_state::SetId<St>> {
self._fields.5 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Pattern: event_state::IsUnset,
{
pub fn pattern(
mut self,
value: impl Into<safelink::PatternType<S>>,
) -> EventBuilder<S, event_state::SetPattern<St>> {
self._fields.6 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Reason: event_state::IsUnset,
{
pub fn reason(
mut self,
value: impl Into<safelink::ReasonType<S>>,
) -> EventBuilder<S, event_state::SetReason<St>> {
self._fields.7 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Url: event_state::IsUnset,
{
pub fn url(mut self, value: impl Into<S>) -> EventBuilder<S, event_state::SetUrl<St>> {
self._fields.8 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Reason: event_state::IsSet,
St::Url: event_state::IsSet,
St::Action: event_state::IsSet,
St::CreatedAt: event_state::IsSet,
St::EventType: event_state::IsSet,
St::CreatedBy: event_state::IsSet,
St::Id: event_state::IsSet,
St::Pattern: event_state::IsSet,
{
pub fn build(self) -> Event<S> {
Event {
action: self._fields.0.unwrap(),
comment: self._fields.1,
created_at: self._fields.2.unwrap(),
created_by: self._fields.3.unwrap(),
event_type: self._fields.4.unwrap(),
id: self._fields.5.unwrap(),
pattern: self._fields.6.unwrap(),
reason: self._fields.7.unwrap(),
url: self._fields.8.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Event<S> {
Event {
action: self._fields.0.unwrap(),
comment: self._fields.1,
created_at: self._fields.2.unwrap(),
created_by: self._fields.3.unwrap(),
event_type: self._fields.4.unwrap(),
id: self._fields.5.unwrap(),
pattern: self._fields.6.unwrap(),
reason: self._fields.7.unwrap(),
url: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_tools_ozone_safelink_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("tools.ozone.safelink.defs"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("actionType"),
LexUserType::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("event"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("An event for URL safety decisions")),
required: Some(vec![
SmolStr::new_static("id"),
SmolStr::new_static("eventType"),
SmolStr::new_static("url"),
SmolStr::new_static("pattern"),
SmolStr::new_static("action"),
SmolStr::new_static("reason"),
SmolStr::new_static("createdBy"),
SmolStr::new_static("createdAt"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("action"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#actionType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("comment"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Optional comment about the decision",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdBy"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"DID of the user who created this rule",
)),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("eventType"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#eventType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("id"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("pattern"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#patternType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("reason"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#reasonType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"The URL that this rule applies to",
)),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("eventType"),
LexUserType::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("patternType"),
LexUserType::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("reasonType"),
LexUserType::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("urlRule"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("Input for creating a URL safety rule")),
required: Some(vec![
SmolStr::new_static("url"),
SmolStr::new_static("pattern"),
SmolStr::new_static("action"),
SmolStr::new_static("reason"),
SmolStr::new_static("createdBy"),
SmolStr::new_static("createdAt"),
SmolStr::new_static("updatedAt"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("action"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#actionType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("comment"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Optional comment about the decision",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Timestamp when the rule was created",
)),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdBy"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"DID of the user added the rule.",
)),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("pattern"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#patternType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("reason"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#reasonType"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Timestamp when the rule was last updated",
)),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"The URL or domain to apply the rule to",
)),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod url_rule_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 UpdatedAt;
type Reason;
type Action;
type CreatedBy;
type CreatedAt;
type Pattern;
type Url;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type UpdatedAt = Unset;
type Reason = Unset;
type Action = Unset;
type CreatedBy = Unset;
type CreatedAt = Unset;
type Pattern = Unset;
type Url = Unset;
}
pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
impl<St: State> State for SetUpdatedAt<St> {
type UpdatedAt = Set<members::updated_at>;
type Reason = St::Reason;
type Action = St::Action;
type CreatedBy = St::CreatedBy;
type CreatedAt = St::CreatedAt;
type Pattern = St::Pattern;
type Url = St::Url;
}
pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetReason<St> {}
impl<St: State> State for SetReason<St> {
type UpdatedAt = St::UpdatedAt;
type Reason = Set<members::reason>;
type Action = St::Action;
type CreatedBy = St::CreatedBy;
type CreatedAt = St::CreatedAt;
type Pattern = St::Pattern;
type Url = St::Url;
}
pub struct SetAction<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAction<St> {}
impl<St: State> State for SetAction<St> {
type UpdatedAt = St::UpdatedAt;
type Reason = St::Reason;
type Action = Set<members::action>;
type CreatedBy = St::CreatedBy;
type CreatedAt = St::CreatedAt;
type Pattern = St::Pattern;
type Url = St::Url;
}
pub struct SetCreatedBy<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedBy<St> {}
impl<St: State> State for SetCreatedBy<St> {
type UpdatedAt = St::UpdatedAt;
type Reason = St::Reason;
type Action = St::Action;
type CreatedBy = Set<members::created_by>;
type CreatedAt = St::CreatedAt;
type Pattern = St::Pattern;
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 UpdatedAt = St::UpdatedAt;
type Reason = St::Reason;
type Action = St::Action;
type CreatedBy = St::CreatedBy;
type CreatedAt = Set<members::created_at>;
type Pattern = St::Pattern;
type Url = St::Url;
}
pub struct SetPattern<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPattern<St> {}
impl<St: State> State for SetPattern<St> {
type UpdatedAt = St::UpdatedAt;
type Reason = St::Reason;
type Action = St::Action;
type CreatedBy = St::CreatedBy;
type CreatedAt = St::CreatedAt;
type Pattern = Set<members::pattern>;
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 UpdatedAt = St::UpdatedAt;
type Reason = St::Reason;
type Action = St::Action;
type CreatedBy = St::CreatedBy;
type CreatedAt = St::CreatedAt;
type Pattern = St::Pattern;
type Url = Set<members::url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct updated_at(());
pub struct reason(());
pub struct action(());
pub struct created_by(());
pub struct created_at(());
pub struct pattern(());
pub struct url(());
}
}
pub struct UrlRuleBuilder<S: BosStr, St: url_rule_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<safelink::ActionType<S>>,
Option<S>,
Option<Datetime>,
Option<Did<S>>,
Option<safelink::PatternType<S>>,
Option<safelink::ReasonType<S>>,
Option<Datetime>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> UrlRule<S> {
pub fn new() -> UrlRuleBuilder<S, url_rule_state::Empty> {
UrlRuleBuilder::new()
}
}
impl<S: BosStr> UrlRuleBuilder<S, url_rule_state::Empty> {
pub fn new() -> Self {
UrlRuleBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::Action: url_rule_state::IsUnset,
{
pub fn action(
mut self,
value: impl Into<safelink::ActionType<S>>,
) -> UrlRuleBuilder<S, url_rule_state::SetAction<St>> {
self._fields.0 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: url_rule_state::State> UrlRuleBuilder<S, St> {
pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_comment(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::CreatedAt: url_rule_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> UrlRuleBuilder<S, url_rule_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::CreatedBy: url_rule_state::IsUnset,
{
pub fn created_by(
mut self,
value: impl Into<Did<S>>,
) -> UrlRuleBuilder<S, url_rule_state::SetCreatedBy<St>> {
self._fields.3 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::Pattern: url_rule_state::IsUnset,
{
pub fn pattern(
mut self,
value: impl Into<safelink::PatternType<S>>,
) -> UrlRuleBuilder<S, url_rule_state::SetPattern<St>> {
self._fields.4 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::Reason: url_rule_state::IsUnset,
{
pub fn reason(
mut self,
value: impl Into<safelink::ReasonType<S>>,
) -> UrlRuleBuilder<S, url_rule_state::SetReason<St>> {
self._fields.5 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::UpdatedAt: url_rule_state::IsUnset,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> UrlRuleBuilder<S, url_rule_state::SetUpdatedAt<St>> {
self._fields.6 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::Url: url_rule_state::IsUnset,
{
pub fn url(mut self, value: impl Into<S>) -> UrlRuleBuilder<S, url_rule_state::SetUrl<St>> {
self._fields.7 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlRuleBuilder<S, St>
where
St: url_rule_state::State,
St::UpdatedAt: url_rule_state::IsSet,
St::Reason: url_rule_state::IsSet,
St::Action: url_rule_state::IsSet,
St::CreatedBy: url_rule_state::IsSet,
St::CreatedAt: url_rule_state::IsSet,
St::Pattern: url_rule_state::IsSet,
St::Url: url_rule_state::IsSet,
{
pub fn build(self) -> UrlRule<S> {
UrlRule {
action: self._fields.0.unwrap(),
comment: self._fields.1,
created_at: self._fields.2.unwrap(),
created_by: self._fields.3.unwrap(),
pattern: self._fields.4.unwrap(),
reason: self._fields.5.unwrap(),
updated_at: self._fields.6.unwrap(),
url: self._fields.7.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> UrlRule<S> {
UrlRule {
action: self._fields.0.unwrap(),
comment: self._fields.1,
created_at: self._fields.2.unwrap(),
created_by: self._fields.3.unwrap(),
pattern: self._fields.4.unwrap(),
reason: self._fields.5.unwrap(),
updated_at: self._fields.6.unwrap(),
url: self._fields.7.unwrap(),
extra_data: Some(extra_data),
}
}
}