use core::marker::PhantomData;
use super::*;
use crate::graphql::carrier::Builtin;
pub struct TextFilter<S, I = Builtin> {
pub(crate) eq: Option<S>,
pub(crate) ne: Option<S>,
pub(crate) gt: Option<S>,
pub(crate) gte: Option<S>,
pub(crate) lt: Option<S>,
pub(crate) lte: Option<S>,
pub(crate) contains: Option<S>,
pub(crate) contains_nocase: Option<S>,
pub(crate) not_contains: Option<S>,
pub(crate) not_contains_nocase: Option<S>,
pub(crate) starts_with: Option<S>,
pub(crate) starts_with_nocase: Option<S>,
pub(crate) not_starts_with: Option<S>,
pub(crate) not_starts_with_nocase: Option<S>,
pub(crate) ends_with: Option<S>,
pub(crate) ends_with_nocase: Option<S>,
pub(crate) not_ends_with: Option<S>,
pub(crate) not_ends_with_nocase: Option<S>,
pub(crate) in_: Option<Box<[S]>>,
pub(crate) not_in: Option<Box<[S]>>,
pub(crate) wire: PhantomData<fn() -> I>,
}
impl<S, I> TextFilter<S, I> {
#[inline]
pub const fn new() -> Self {
Self {
eq: None,
ne: None,
gt: None,
gte: None,
lt: None,
lte: None,
contains: None,
contains_nocase: None,
not_contains: None,
not_contains_nocase: None,
starts_with: None,
starts_with_nocase: None,
not_starts_with: None,
not_starts_with_nocase: None,
ends_with: None,
ends_with_nocase: None,
not_ends_with: None,
not_ends_with_nocase: None,
in_: None,
not_in: None,
wire: PhantomData,
}
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.eq.is_none()
&& self.ne.is_none()
&& self.gt.is_none()
&& self.gte.is_none()
&& self.lt.is_none()
&& self.lte.is_none()
&& self.contains.is_none()
&& self.contains_nocase.is_none()
&& self.not_contains.is_none()
&& self.not_contains_nocase.is_none()
&& self.starts_with.is_none()
&& self.starts_with_nocase.is_none()
&& self.not_starts_with.is_none()
&& self.not_starts_with_nocase.is_none()
&& self.ends_with.is_none()
&& self.ends_with_nocase.is_none()
&& self.not_ends_with.is_none()
&& self.not_ends_with_nocase.is_none()
&& self.in_.is_none()
&& self.not_in.is_none()
}
opt_accessor!(eq: S => with_eq, set_eq, maybe_eq, update_eq);
opt_accessor!(ne: S => with_ne, set_ne, maybe_ne, update_ne);
opt_accessor!(gt: S => with_gt, set_gt, maybe_gt, update_gt);
opt_accessor!(gte: S => with_gte, set_gte, maybe_gte, update_gte);
opt_accessor!(lt: S => with_lt, set_lt, maybe_lt, update_lt);
opt_accessor!(lte: S => with_lte, set_lte, maybe_lte, update_lte);
opt_accessor!(contains: S => with_contains, set_contains, maybe_contains, update_contains);
opt_accessor!(
contains_nocase: S =>
with_contains_nocase,
set_contains_nocase,
maybe_contains_nocase,
update_contains_nocase
);
opt_accessor!(
not_contains: S => with_not_contains, set_not_contains, maybe_not_contains, update_not_contains
);
opt_accessor!(
not_contains_nocase: S =>
with_not_contains_nocase,
set_not_contains_nocase,
maybe_not_contains_nocase,
update_not_contains_nocase
);
opt_accessor!(
starts_with: S => with_starts_with, set_starts_with, maybe_starts_with, update_starts_with
);
opt_accessor!(
starts_with_nocase: S =>
with_starts_with_nocase,
set_starts_with_nocase,
maybe_starts_with_nocase,
update_starts_with_nocase
);
opt_accessor!(
not_starts_with: S =>
with_not_starts_with,
set_not_starts_with,
maybe_not_starts_with,
update_not_starts_with
);
opt_accessor!(
not_starts_with_nocase: S =>
with_not_starts_with_nocase,
set_not_starts_with_nocase,
maybe_not_starts_with_nocase,
update_not_starts_with_nocase
);
opt_accessor!(ends_with: S => with_ends_with, set_ends_with, maybe_ends_with, update_ends_with);
opt_accessor!(
ends_with_nocase: S =>
with_ends_with_nocase,
set_ends_with_nocase,
maybe_ends_with_nocase,
update_ends_with_nocase
);
opt_accessor!(
not_ends_with: S =>
with_not_ends_with,
set_not_ends_with,
maybe_not_ends_with,
update_not_ends_with
);
opt_accessor!(
not_ends_with_nocase: S =>
with_not_ends_with_nocase,
set_not_ends_with_nocase,
maybe_not_ends_with_nocase,
update_not_ends_with_nocase
);
opt_accessor!(in_: [S] => with_in_, set_in_, maybe_in_, update_in_);
opt_accessor!(not_in: [S] => with_not_in, set_not_in, maybe_not_in, update_not_in);
#[inline]
pub const fn is_referential(&self) -> bool {
(self.eq.is_some() ^ self.in_.is_some())
&& self.ne.is_none()
&& self.gt.is_none()
&& self.gte.is_none()
&& self.lt.is_none()
&& self.lte.is_none()
&& self.contains.is_none()
&& self.contains_nocase.is_none()
&& self.not_contains.is_none()
&& self.not_contains_nocase.is_none()
&& self.starts_with.is_none()
&& self.starts_with_nocase.is_none()
&& self.not_starts_with.is_none()
&& self.not_starts_with_nocase.is_none()
&& self.ends_with.is_none()
&& self.ends_with_nocase.is_none()
&& self.not_ends_with.is_none()
&& self.not_ends_with_nocase.is_none()
&& self.not_in.is_none()
}
pub fn try_map<U, E, F>(self, mut f: F) -> Result<TextFilter<U, I>, E>
where
F: FnMut(S) -> Result<U, E>,
{
Ok(TextFilter {
eq: map_operand(self.eq, &mut f)?,
ne: map_operand(self.ne, &mut f)?,
gt: map_operand(self.gt, &mut f)?,
gte: map_operand(self.gte, &mut f)?,
lt: map_operand(self.lt, &mut f)?,
lte: map_operand(self.lte, &mut f)?,
contains: map_operand(self.contains, &mut f)?,
contains_nocase: map_operand(self.contains_nocase, &mut f)?,
not_contains: map_operand(self.not_contains, &mut f)?,
not_contains_nocase: map_operand(self.not_contains_nocase, &mut f)?,
starts_with: map_operand(self.starts_with, &mut f)?,
starts_with_nocase: map_operand(self.starts_with_nocase, &mut f)?,
not_starts_with: map_operand(self.not_starts_with, &mut f)?,
not_starts_with_nocase: map_operand(self.not_starts_with_nocase, &mut f)?,
ends_with: map_operand(self.ends_with, &mut f)?,
ends_with_nocase: map_operand(self.ends_with_nocase, &mut f)?,
not_ends_with: map_operand(self.not_ends_with, &mut f)?,
not_ends_with_nocase: map_operand(self.not_ends_with_nocase, &mut f)?,
in_: map_operands(self.in_, &mut f)?,
not_in: map_operands(self.not_in, &mut f)?,
wire: PhantomData,
})
}
}
impl<S, I> Default for TextFilter<S, I> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<S: core::fmt::Debug, I> core::fmt::Debug for TextFilter<S, I> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("TextFilter")
.field("eq", &self.eq)
.field("ne", &self.ne)
.field("gt", &self.gt)
.field("gte", &self.gte)
.field("lt", &self.lt)
.field("lte", &self.lte)
.field("contains", &self.contains)
.field("contains_nocase", &self.contains_nocase)
.field("not_contains", &self.not_contains)
.field("not_contains_nocase", &self.not_contains_nocase)
.field("starts_with", &self.starts_with)
.field("starts_with_nocase", &self.starts_with_nocase)
.field("not_starts_with", &self.not_starts_with)
.field("not_starts_with_nocase", &self.not_starts_with_nocase)
.field("ends_with", &self.ends_with)
.field("ends_with_nocase", &self.ends_with_nocase)
.field("not_ends_with", &self.not_ends_with)
.field("not_ends_with_nocase", &self.not_ends_with_nocase)
.field("in_", &self.in_)
.field("not_in", &self.not_in)
.finish()
}
}
impl<S: Clone, I> Clone for TextFilter<S, I> {
fn clone(&self) -> Self {
Self {
eq: self.eq.clone(),
ne: self.ne.clone(),
gt: self.gt.clone(),
gte: self.gte.clone(),
lt: self.lt.clone(),
lte: self.lte.clone(),
contains: self.contains.clone(),
contains_nocase: self.contains_nocase.clone(),
not_contains: self.not_contains.clone(),
not_contains_nocase: self.not_contains_nocase.clone(),
starts_with: self.starts_with.clone(),
starts_with_nocase: self.starts_with_nocase.clone(),
not_starts_with: self.not_starts_with.clone(),
not_starts_with_nocase: self.not_starts_with_nocase.clone(),
ends_with: self.ends_with.clone(),
ends_with_nocase: self.ends_with_nocase.clone(),
not_ends_with: self.not_ends_with.clone(),
not_ends_with_nocase: self.not_ends_with_nocase.clone(),
in_: self.in_.clone(),
not_in: self.not_in.clone(),
wire: PhantomData,
}
}
}
impl<S: PartialEq, I> PartialEq for TextFilter<S, I> {
fn eq(&self, other: &Self) -> bool {
self.eq == other.eq
&& self.ne == other.ne
&& self.gt == other.gt
&& self.gte == other.gte
&& self.lt == other.lt
&& self.lte == other.lte
&& self.contains == other.contains
&& self.contains_nocase == other.contains_nocase
&& self.not_contains == other.not_contains
&& self.not_contains_nocase == other.not_contains_nocase
&& self.starts_with == other.starts_with
&& self.starts_with_nocase == other.starts_with_nocase
&& self.not_starts_with == other.not_starts_with
&& self.not_starts_with_nocase == other.not_starts_with_nocase
&& self.ends_with == other.ends_with
&& self.ends_with_nocase == other.ends_with_nocase
&& self.not_ends_with == other.not_ends_with
&& self.not_ends_with_nocase == other.not_ends_with_nocase
&& self.in_ == other.in_
&& self.not_in == other.not_in
}
}
impl<S, U, I> TryMapFilter<S, U> for TextFilter<S, I> {
type Mapped = TextFilter<U, I>;
#[inline]
fn try_map_filter<E, F>(self, f: F) -> Result<Self::Mapped, E>
where
F: FnMut(S) -> Result<U, E>,
{
self.try_map(f)
}
}
impl<S, I> EqualsFilter<S> for TextFilter<S, I> {
#[inline]
fn equals(value: S) -> Self {
Self::new().with_eq(value)
}
}
impl<S, I> GraphqlFilter for TextFilter<S, I> {
#[inline]
fn is_empty(&self) -> bool {
Self::is_empty(self)
}
}
#[cfg(feature = "async-graphql")]
fn cross_slot<S, I, F>(
object: &async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value>,
name: &str,
) -> Result<Option<S>, async_graphql::InputValueError<F>>
where
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
F: async_graphql::InputType,
{
via::crossed(object, name, I::cross)
}
#[cfg(feature = "async-graphql")]
fn cross_slots<S, I, F>(
object: &async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value>,
name: &str,
) -> Result<Option<Box<[S]>>, async_graphql::InputValueError<F>>
where
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
F: async_graphql::InputType,
{
via::crossed_list(object, name, I::cross)
}
#[cfg(feature = "async-graphql")]
fn carry_slot<S, I>(slot: &Option<S>) -> async_graphql::Value
where
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
via::carried(slot, I::carry)
}
#[cfg(feature = "async-graphql")]
fn carry_slots<S, I>(slot: &Option<Box<[S]>>) -> async_graphql::Value
where
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
via::carried_list(slot, I::carry)
}
#[cfg(feature = "async-graphql")]
fn text_fields<S, I>(
registry: &mut async_graphql::registry::Registry,
) -> async_graphql::indexmap::IndexMap<::std::string::String, async_graphql::registry::MetaInputValue>
where
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
__ingraph_filter_input_fields!(
registry,
"eq" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"ne" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"gt" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"gte" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"lt" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"lte" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"contains" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"containsNocase" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"notContains" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"notContainsNocase" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"startsWith" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"startsWithNocase" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"notStartsWith" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"notStartsWithNocase" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"endsWith" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"endsWithNocase" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"notEndsWith" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"notEndsWithNocase" : ::core::option::Option<<I as crate::TextWire<S>>::Carrier>,
"in" : ::core::option::Option<::std::boxed::Box<[<I as crate::TextWire<S>>::Carrier]>>,
"notIn" : ::core::option::Option<::std::boxed::Box<[<I as crate::TextWire<S>>::Carrier]>>,
)
}
#[cfg(feature = "async-graphql")]
fn text_values<S, I>(
filter: &TextFilter<S, I>,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value>
where
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
let mut map = async_graphql::indexmap::IndexMap::new();
map.insert(
async_graphql::Name::new("eq"),
carry_slot::<S, I>(&filter.eq),
);
map.insert(
async_graphql::Name::new("ne"),
carry_slot::<S, I>(&filter.ne),
);
map.insert(
async_graphql::Name::new("gt"),
carry_slot::<S, I>(&filter.gt),
);
map.insert(
async_graphql::Name::new("gte"),
carry_slot::<S, I>(&filter.gte),
);
map.insert(
async_graphql::Name::new("lt"),
carry_slot::<S, I>(&filter.lt),
);
map.insert(
async_graphql::Name::new("lte"),
carry_slot::<S, I>(&filter.lte),
);
map.insert(
async_graphql::Name::new("contains"),
carry_slot::<S, I>(&filter.contains),
);
map.insert(
async_graphql::Name::new("containsNocase"),
carry_slot::<S, I>(&filter.contains_nocase),
);
map.insert(
async_graphql::Name::new("notContains"),
carry_slot::<S, I>(&filter.not_contains),
);
map.insert(
async_graphql::Name::new("notContainsNocase"),
carry_slot::<S, I>(&filter.not_contains_nocase),
);
map.insert(
async_graphql::Name::new("startsWith"),
carry_slot::<S, I>(&filter.starts_with),
);
map.insert(
async_graphql::Name::new("startsWithNocase"),
carry_slot::<S, I>(&filter.starts_with_nocase),
);
map.insert(
async_graphql::Name::new("notStartsWith"),
carry_slot::<S, I>(&filter.not_starts_with),
);
map.insert(
async_graphql::Name::new("notStartsWithNocase"),
carry_slot::<S, I>(&filter.not_starts_with_nocase),
);
map.insert(
async_graphql::Name::new("endsWith"),
carry_slot::<S, I>(&filter.ends_with),
);
map.insert(
async_graphql::Name::new("endsWithNocase"),
carry_slot::<S, I>(&filter.ends_with_nocase),
);
map.insert(
async_graphql::Name::new("notEndsWith"),
carry_slot::<S, I>(&filter.not_ends_with),
);
map.insert(
async_graphql::Name::new("notEndsWithNocase"),
carry_slot::<S, I>(&filter.not_ends_with_nocase),
);
map.insert(
async_graphql::Name::new("in"),
carry_slots::<S, I>(&filter.in_),
);
map.insert(
async_graphql::Name::new("notIn"),
carry_slots::<S, I>(&filter.not_in),
);
map
}
#[cfg(feature = "async-graphql")]
impl<S, I> async_graphql::InputType for TextFilter<S, I>
where
S: Send + Sync,
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
type RawValueType = Self;
#[inline]
fn type_name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed(<I as crate::TextWire<S>>::NAME)
}
fn create_type_info(registry: &mut async_graphql::registry::Registry) -> ::std::string::String {
registry.create_input_type::<Self, _>(
async_graphql::registry::MetaTypeId::InputObject,
|registry| async_graphql::registry::MetaType::InputObject {
name: ::std::string::String::from(<I as crate::TextWire<S>>::NAME),
description: ::std::option::Option::None,
input_fields: text_fields::<S, I>(registry),
visible: ::std::option::Option::None,
inaccessible: false,
tags: ::std::vec::Vec::new(),
rust_typename: ::std::option::Option::Some(::std::any::type_name::<Self>()),
oneof: false,
directive_invocations: ::std::vec::Vec::new(),
},
)
}
fn parse(
value: ::std::option::Option<async_graphql::Value>,
) -> async_graphql::InputValueResult<Self> {
let object = match super::sent(value) {
super::Sent::Longhand(object) => object,
super::Sent::Bare(bare) => {
let mut object = async_graphql::indexmap::IndexMap::new();
object.insert(async_graphql::Name::new("eq"), bare);
object
}
super::Sent::Null => {
return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(
async_graphql::Value::Null,
));
}
super::Sent::Refused(sent) => {
return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(sent));
}
};
{
::std::result::Result::Ok(Self {
eq: cross_slot::<S, I, Self>(&object, "eq")?,
ne: cross_slot::<S, I, Self>(&object, "ne")?,
gt: cross_slot::<S, I, Self>(&object, "gt")?,
gte: cross_slot::<S, I, Self>(&object, "gte")?,
lt: cross_slot::<S, I, Self>(&object, "lt")?,
lte: cross_slot::<S, I, Self>(&object, "lte")?,
contains: cross_slot::<S, I, Self>(&object, "contains")?,
contains_nocase: cross_slot::<S, I, Self>(&object, "containsNocase")?,
not_contains: cross_slot::<S, I, Self>(&object, "notContains")?,
not_contains_nocase: cross_slot::<S, I, Self>(&object, "notContainsNocase")?,
starts_with: cross_slot::<S, I, Self>(&object, "startsWith")?,
starts_with_nocase: cross_slot::<S, I, Self>(&object, "startsWithNocase")?,
not_starts_with: cross_slot::<S, I, Self>(&object, "notStartsWith")?,
not_starts_with_nocase: cross_slot::<S, I, Self>(&object, "notStartsWithNocase")?,
ends_with: cross_slot::<S, I, Self>(&object, "endsWith")?,
ends_with_nocase: cross_slot::<S, I, Self>(&object, "endsWithNocase")?,
not_ends_with: cross_slot::<S, I, Self>(&object, "notEndsWith")?,
not_ends_with_nocase: cross_slot::<S, I, Self>(&object, "notEndsWithNocase")?,
in_: cross_slots::<S, I, Self>(&object, "in")?,
not_in: cross_slots::<S, I, Self>(&object, "notIn")?,
wire: PhantomData,
})
}
}
fn to_value(&self) -> async_graphql::Value {
async_graphql::Value::Object(text_values::<S, I>(self))
}
#[inline]
fn as_raw_value(&self) -> ::std::option::Option<&Self::RawValueType> {
::std::option::Option::Some(self)
}
}
#[cfg(feature = "async-graphql")]
impl<S, I> async_graphql::InputObjectType for TextFilter<S, I>
where
S: Send + Sync,
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
}
#[cfg(feature = "async-graphql")]
impl<S, I> crate::NullableFace for TextFilter<S, I>
where
S: Send + Sync,
I: crate::TextWire<S>,
I::Carrier: async_graphql::InputType,
{
fn bare_fields(
registry: &mut async_graphql::registry::Registry,
) -> async_graphql::indexmap::IndexMap<
::std::string::String,
async_graphql::registry::MetaInputValue,
> {
text_fields::<S, I>(registry)
}
fn bare_values(
&self,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value> {
text_values::<S, I>(self)
}
}