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::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, Datetime};
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::tools_ozone::safelink;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ActionType<'a> {
Block,
Warn,
Whitelist,
Other(CowStr<'a>),
}
impl<'a> ActionType<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Block => "block",
Self::Warn => "warn",
Self::Whitelist => "whitelist",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for ActionType<'a> {
fn from(s: &'a str) -> Self {
match s {
"block" => Self::Block,
"warn" => Self::Warn,
"whitelist" => Self::Whitelist,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for ActionType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"block" => Self::Block,
"warn" => Self::Warn,
"whitelist" => Self::Whitelist,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> AsRef<str> for ActionType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> core::fmt::Display for ActionType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> serde::Serialize for ActionType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for ActionType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl jacquard_common::IntoStatic for ActionType<'_> {
type Output = ActionType<'static>;
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()),
}
}
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Event<'a> {
#[serde(borrow)]
pub action: safelink::ActionType<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub comment: Option<CowStr<'a>>,
pub created_at: Datetime,
#[serde(borrow)]
pub created_by: Did<'a>,
#[serde(borrow)]
pub event_type: safelink::EventType<'a>,
pub id: i64,
#[serde(borrow)]
pub pattern: safelink::PatternType<'a>,
#[serde(borrow)]
pub reason: safelink::ReasonType<'a>,
#[serde(borrow)]
pub url: CowStr<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EventType<'a> {
AddRule,
UpdateRule,
RemoveRule,
Other(CowStr<'a>),
}
impl<'a> EventType<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::AddRule => "addRule",
Self::UpdateRule => "updateRule",
Self::RemoveRule => "removeRule",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for EventType<'a> {
fn from(s: &'a str) -> Self {
match s {
"addRule" => Self::AddRule,
"updateRule" => Self::UpdateRule,
"removeRule" => Self::RemoveRule,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for EventType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"addRule" => Self::AddRule,
"updateRule" => Self::UpdateRule,
"removeRule" => Self::RemoveRule,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> AsRef<str> for EventType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> core::fmt::Display for EventType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> serde::Serialize for EventType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for EventType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl jacquard_common::IntoStatic for EventType<'_> {
type Output = EventType<'static>;
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<'a> {
Domain,
Url,
Other(CowStr<'a>),
}
impl<'a> PatternType<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Domain => "domain",
Self::Url => "url",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for PatternType<'a> {
fn from(s: &'a str) -> Self {
match s {
"domain" => Self::Domain,
"url" => Self::Url,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for PatternType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"domain" => Self::Domain,
"url" => Self::Url,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> AsRef<str> for PatternType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> core::fmt::Display for PatternType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> serde::Serialize for PatternType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for PatternType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl jacquard_common::IntoStatic for PatternType<'_> {
type Output = PatternType<'static>;
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<'a> {
Csam,
Spam,
Phishing,
None,
Other(CowStr<'a>),
}
impl<'a> ReasonType<'a> {
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(),
}
}
}
impl<'a> From<&'a str> for ReasonType<'a> {
fn from(s: &'a str) -> Self {
match s {
"csam" => Self::Csam,
"spam" => Self::Spam,
"phishing" => Self::Phishing,
"none" => Self::None,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for ReasonType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"csam" => Self::Csam,
"spam" => Self::Spam,
"phishing" => Self::Phishing,
"none" => Self::None,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> AsRef<str> for ReasonType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> core::fmt::Display for ReasonType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> serde::Serialize for ReasonType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for ReasonType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl jacquard_common::IntoStatic for ReasonType<'_> {
type Output = ReasonType<'static>;
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()),
}
}
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UrlRule<'a> {
#[serde(borrow)]
pub action: safelink::ActionType<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub comment: Option<CowStr<'a>>,
pub created_at: Datetime,
#[serde(borrow)]
pub created_by: Did<'a>,
#[serde(borrow)]
pub pattern: safelink::PatternType<'a>,
#[serde(borrow)]
pub reason: safelink::ReasonType<'a>,
pub updated_at: Datetime,
#[serde(borrow)]
pub url: CowStr<'a>,
}
impl<'a> LexiconSchema for Event<'a> {
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<'a> LexiconSchema for UrlRule<'a> {
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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Reason;
type EventType;
type CreatedBy;
type Url;
type Pattern;
type CreatedAt;
type Id;
type Action;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Reason = Unset;
type EventType = Unset;
type CreatedBy = Unset;
type Url = Unset;
type Pattern = Unset;
type CreatedAt = Unset;
type Id = Unset;
type Action = Unset;
}
pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetReason<S> {}
impl<S: State> State for SetReason<S> {
type Reason = Set<members::reason>;
type EventType = S::EventType;
type CreatedBy = S::CreatedBy;
type Url = S::Url;
type Pattern = S::Pattern;
type CreatedAt = S::CreatedAt;
type Id = S::Id;
type Action = S::Action;
}
pub struct SetEventType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetEventType<S> {}
impl<S: State> State for SetEventType<S> {
type Reason = S::Reason;
type EventType = Set<members::event_type>;
type CreatedBy = S::CreatedBy;
type Url = S::Url;
type Pattern = S::Pattern;
type CreatedAt = S::CreatedAt;
type Id = S::Id;
type Action = S::Action;
}
pub struct SetCreatedBy<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedBy<S> {}
impl<S: State> State for SetCreatedBy<S> {
type Reason = S::Reason;
type EventType = S::EventType;
type CreatedBy = Set<members::created_by>;
type Url = S::Url;
type Pattern = S::Pattern;
type CreatedAt = S::CreatedAt;
type Id = S::Id;
type Action = S::Action;
}
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 Reason = S::Reason;
type EventType = S::EventType;
type CreatedBy = S::CreatedBy;
type Url = Set<members::url>;
type Pattern = S::Pattern;
type CreatedAt = S::CreatedAt;
type Id = S::Id;
type Action = S::Action;
}
pub struct SetPattern<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPattern<S> {}
impl<S: State> State for SetPattern<S> {
type Reason = S::Reason;
type EventType = S::EventType;
type CreatedBy = S::CreatedBy;
type Url = S::Url;
type Pattern = Set<members::pattern>;
type CreatedAt = S::CreatedAt;
type Id = S::Id;
type Action = S::Action;
}
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 Reason = S::Reason;
type EventType = S::EventType;
type CreatedBy = S::CreatedBy;
type Url = S::Url;
type Pattern = S::Pattern;
type CreatedAt = Set<members::created_at>;
type Id = S::Id;
type Action = S::Action;
}
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 Reason = S::Reason;
type EventType = S::EventType;
type CreatedBy = S::CreatedBy;
type Url = S::Url;
type Pattern = S::Pattern;
type CreatedAt = S::CreatedAt;
type Id = Set<members::id>;
type Action = S::Action;
}
pub struct SetAction<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAction<S> {}
impl<S: State> State for SetAction<S> {
type Reason = S::Reason;
type EventType = S::EventType;
type CreatedBy = S::CreatedBy;
type Url = S::Url;
type Pattern = S::Pattern;
type CreatedAt = S::CreatedAt;
type Id = S::Id;
type Action = Set<members::action>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct reason(());
pub struct event_type(());
pub struct created_by(());
pub struct url(());
pub struct pattern(());
pub struct created_at(());
pub struct id(());
pub struct action(());
}
}
pub struct EventBuilder<'a, S: event_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<safelink::ActionType<'a>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<Did<'a>>,
Option<safelink::EventType<'a>>,
Option<i64>,
Option<safelink::PatternType<'a>>,
Option<safelink::ReasonType<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Event<'a> {
pub fn new() -> EventBuilder<'a, event_state::Empty> {
EventBuilder::new()
}
}
impl<'a> EventBuilder<'a, event_state::Empty> {
pub fn new() -> Self {
EventBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Action: event_state::IsUnset,
{
pub fn action(
mut self,
value: impl Into<safelink::ActionType<'a>>,
) -> EventBuilder<'a, event_state::SetAction<S>> {
self._fields.0 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: event_state::State> EventBuilder<'a, S> {
pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::CreatedAt: event_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> EventBuilder<'a, event_state::SetCreatedAt<S>> {
self._fields.2 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::CreatedBy: event_state::IsUnset,
{
pub fn created_by(
mut self,
value: impl Into<Did<'a>>,
) -> EventBuilder<'a, event_state::SetCreatedBy<S>> {
self._fields.3 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::EventType: event_state::IsUnset,
{
pub fn event_type(
mut self,
value: impl Into<safelink::EventType<'a>>,
) -> EventBuilder<'a, event_state::SetEventType<S>> {
self._fields.4 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Id: event_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<i64>,
) -> EventBuilder<'a, event_state::SetId<S>> {
self._fields.5 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Pattern: event_state::IsUnset,
{
pub fn pattern(
mut self,
value: impl Into<safelink::PatternType<'a>>,
) -> EventBuilder<'a, event_state::SetPattern<S>> {
self._fields.6 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Reason: event_state::IsUnset,
{
pub fn reason(
mut self,
value: impl Into<safelink::ReasonType<'a>>,
) -> EventBuilder<'a, event_state::SetReason<S>> {
self._fields.7 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Url: event_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<CowStr<'a>>,
) -> EventBuilder<'a, event_state::SetUrl<S>> {
self._fields.8 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EventBuilder<'a, S>
where
S: event_state::State,
S::Reason: event_state::IsSet,
S::EventType: event_state::IsSet,
S::CreatedBy: event_state::IsSet,
S::Url: event_state::IsSet,
S::Pattern: event_state::IsSet,
S::CreatedAt: event_state::IsSet,
S::Id: event_state::IsSet,
S::Action: event_state::IsSet,
{
pub fn build(self) -> Event<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Event<'a> {
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> {
#[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("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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Pattern;
type Action;
type Url;
type Reason;
type CreatedAt;
type CreatedBy;
type UpdatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Pattern = Unset;
type Action = Unset;
type Url = Unset;
type Reason = Unset;
type CreatedAt = Unset;
type CreatedBy = Unset;
type UpdatedAt = Unset;
}
pub struct SetPattern<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPattern<S> {}
impl<S: State> State for SetPattern<S> {
type Pattern = Set<members::pattern>;
type Action = S::Action;
type Url = S::Url;
type Reason = S::Reason;
type CreatedAt = S::CreatedAt;
type CreatedBy = S::CreatedBy;
type UpdatedAt = S::UpdatedAt;
}
pub struct SetAction<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAction<S> {}
impl<S: State> State for SetAction<S> {
type Pattern = S::Pattern;
type Action = Set<members::action>;
type Url = S::Url;
type Reason = S::Reason;
type CreatedAt = S::CreatedAt;
type CreatedBy = S::CreatedBy;
type UpdatedAt = S::UpdatedAt;
}
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 Pattern = S::Pattern;
type Action = S::Action;
type Url = Set<members::url>;
type Reason = S::Reason;
type CreatedAt = S::CreatedAt;
type CreatedBy = S::CreatedBy;
type UpdatedAt = S::UpdatedAt;
}
pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetReason<S> {}
impl<S: State> State for SetReason<S> {
type Pattern = S::Pattern;
type Action = S::Action;
type Url = S::Url;
type Reason = Set<members::reason>;
type CreatedAt = S::CreatedAt;
type CreatedBy = S::CreatedBy;
type UpdatedAt = S::UpdatedAt;
}
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 Pattern = S::Pattern;
type Action = S::Action;
type Url = S::Url;
type Reason = S::Reason;
type CreatedAt = Set<members::created_at>;
type CreatedBy = S::CreatedBy;
type UpdatedAt = S::UpdatedAt;
}
pub struct SetCreatedBy<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedBy<S> {}
impl<S: State> State for SetCreatedBy<S> {
type Pattern = S::Pattern;
type Action = S::Action;
type Url = S::Url;
type Reason = S::Reason;
type CreatedAt = S::CreatedAt;
type CreatedBy = Set<members::created_by>;
type UpdatedAt = S::UpdatedAt;
}
pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
impl<S: State> State for SetUpdatedAt<S> {
type Pattern = S::Pattern;
type Action = S::Action;
type Url = S::Url;
type Reason = S::Reason;
type CreatedAt = S::CreatedAt;
type CreatedBy = S::CreatedBy;
type UpdatedAt = Set<members::updated_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct pattern(());
pub struct action(());
pub struct url(());
pub struct reason(());
pub struct created_at(());
pub struct created_by(());
pub struct updated_at(());
}
}
pub struct UrlRuleBuilder<'a, S: url_rule_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<safelink::ActionType<'a>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<Did<'a>>,
Option<safelink::PatternType<'a>>,
Option<safelink::ReasonType<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> UrlRule<'a> {
pub fn new() -> UrlRuleBuilder<'a, url_rule_state::Empty> {
UrlRuleBuilder::new()
}
}
impl<'a> UrlRuleBuilder<'a, url_rule_state::Empty> {
pub fn new() -> Self {
UrlRuleBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::Action: url_rule_state::IsUnset,
{
pub fn action(
mut self,
value: impl Into<safelink::ActionType<'a>>,
) -> UrlRuleBuilder<'a, url_rule_state::SetAction<S>> {
self._fields.0 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: url_rule_state::State> UrlRuleBuilder<'a, S> {
pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::CreatedAt: url_rule_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> UrlRuleBuilder<'a, url_rule_state::SetCreatedAt<S>> {
self._fields.2 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::CreatedBy: url_rule_state::IsUnset,
{
pub fn created_by(
mut self,
value: impl Into<Did<'a>>,
) -> UrlRuleBuilder<'a, url_rule_state::SetCreatedBy<S>> {
self._fields.3 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::Pattern: url_rule_state::IsUnset,
{
pub fn pattern(
mut self,
value: impl Into<safelink::PatternType<'a>>,
) -> UrlRuleBuilder<'a, url_rule_state::SetPattern<S>> {
self._fields.4 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::Reason: url_rule_state::IsUnset,
{
pub fn reason(
mut self,
value: impl Into<safelink::ReasonType<'a>>,
) -> UrlRuleBuilder<'a, url_rule_state::SetReason<S>> {
self._fields.5 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::UpdatedAt: url_rule_state::IsUnset,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> UrlRuleBuilder<'a, url_rule_state::SetUpdatedAt<S>> {
self._fields.6 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::Url: url_rule_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<CowStr<'a>>,
) -> UrlRuleBuilder<'a, url_rule_state::SetUrl<S>> {
self._fields.7 = Option::Some(value.into());
UrlRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> UrlRuleBuilder<'a, S>
where
S: url_rule_state::State,
S::Pattern: url_rule_state::IsSet,
S::Action: url_rule_state::IsSet,
S::Url: url_rule_state::IsSet,
S::Reason: url_rule_state::IsSet,
S::CreatedAt: url_rule_state::IsSet,
S::CreatedBy: url_rule_state::IsSet,
S::UpdatedAt: url_rule_state::IsSet,
{
pub fn build(self) -> UrlRule<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> UrlRule<'a> {
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),
}
}
}