module Web.Minion.Request.Query (
  QueryForm (..),
  QueryFlag (..),
  QueryParamName,
  queryParamsForm,
  queryFlag,
  queryFlag',
  queryParam,
  queryParam',
  queryParamLenient,
  queryParamLenient',
) where

import Control.Monad (join, (>=>))
import Control.Monad.Catch (MonadThrow (throwM))
import Data.ByteString qualified as Bytes
import Data.ByteString.Lazy qualified as Bytes.Lazy
import Data.String.Conversions (ConvertibleStrings (convertString))
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Text.Encoding qualified as Text.Encode
import Network.HTTP.Types qualified as Http
import Network.Wai qualified as Http
import Web.FormUrlEncoded (FromForm)
import Web.FormUrlEncoded qualified as Http
import Web.HttpApiData (FromHttpApiData)
import Web.Minion.Args.Internal
import Web.Minion.Introspect qualified as I
import Web.Minion.Request
import Web.Minion.Request.Query.Internal
import Web.Minion.Router.Internal

type QueryParamName = Text.Text

{- | Tries to get query param

@
'queryParam'' "foo" pure '/>' ...
@
-}
{-# INLINE queryParam' #-}
queryParam' ::
  forall a m i ts.
  (FromHttpApiData a, I.Introspection i I.QueryParam a, MonadThrow m) =>
  -- | .
  QueryParamName ->
  ValueCombinator i (WithQueryParam Required Strict m a) ts m
queryParam' :: forall a (m :: * -> *) i ts.
(FromHttpApiData a, Introspection i 'QueryParam a, MonadThrow m) =>
QueryParamName
-> ValueCombinator i (WithQueryParam Required Strict m a) ts m
queryParam' QueryParamName
qn = ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg Required Strict a))
-> Router' i (ts :+ WithQueryParam Required Strict m a) m
-> Router' i ts m
forall a presence parsing (m :: * -> *) ts i.
(Introspection i 'QueryParam a, IsRequired presence,
 IsLenient parsing) =>
ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg presence parsing a))
-> Router' i (ts :+ WithQueryParam presence parsing m a) m
-> Router' i ts m
QueryParam (QueryParamName -> ByteString
Text.Encode.encodeUtf8 QueryParamName
qn) \MakeError
makeError ->
  let badReq :: (QueryParamName -> ByteString) -> m a
badReq QueryParamName -> ByteString
err = ServerError -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (ServerError -> m a) -> ServerError -> m a
forall a b. (a -> b) -> a -> b
$ MakeError
makeError Status
Http.status400 (ByteString -> ServerError) -> ByteString -> ServerError
forall a b. (a -> b) -> a -> b
$ QueryParamName -> ByteString
err QueryParamName
qn
   in m a -> (Maybe ByteString -> m a) -> Maybe (Maybe ByteString) -> m a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
        do (QueryParamName -> ByteString) -> m a
badReq QueryParamName -> ByteString
queryParamKeyNotFoundError
        do
          m a -> (ByteString -> m a) -> Maybe ByteString -> m a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
            ((QueryParamName -> ByteString) -> m a
badReq QueryParamName -> ByteString
queryParamValueNotFoundError)
            ((ServerError -> m a) -> (a -> m a) -> Either ServerError a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ServerError -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ServerError a -> m a)
-> (ByteString -> Either ServerError a) -> ByteString -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MakeError -> ByteString -> Either ServerError a
forall a.
FromHttpApiData a =>
MakeError -> ByteString -> Either ServerError a
decodeQueryParamOrServerError MakeError
makeError)

{- | Tries to get query param

@
'queryParam' "foo" pure '/>' ...
@
-}
{-# INLINE queryParam #-}
queryParam ::
  forall a m i ts.
  (FromHttpApiData a, I.Introspection i I.QueryParam a, MonadThrow m) =>
  -- | .
  QueryParamName ->
  ValueCombinator i (WithQueryParam Optional Strict m a) ts m
queryParam :: forall a (m :: * -> *) i ts.
(FromHttpApiData a, Introspection i 'QueryParam a, MonadThrow m) =>
QueryParamName
-> ValueCombinator i (WithQueryParam Optional Strict m a) ts m
queryParam QueryParamName
qn = ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg Optional Strict a))
-> Router' i (ts :+ WithQueryParam Optional Strict m a) m
-> Router' i ts m
forall a presence parsing (m :: * -> *) ts i.
(Introspection i 'QueryParam a, IsRequired presence,
 IsLenient parsing) =>
ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg presence parsing a))
-> Router' i (ts :+ WithQueryParam presence parsing m a) m
-> Router' i ts m
QueryParam (QueryParamName -> ByteString
Text.Encode.encodeUtf8 QueryParamName
qn) \MakeError
makeError ->
  m (Maybe a)
-> (ByteString -> m (Maybe a)) -> Maybe ByteString -> m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    (Maybe a -> m (Maybe a)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing)
    ((a -> Maybe a) -> m a -> m (Maybe a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (m a -> m (Maybe a))
-> (ByteString -> m a) -> ByteString -> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ServerError -> m a) -> (a -> m a) -> Either ServerError a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ServerError -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ServerError a -> m a)
-> (ByteString -> Either ServerError a) -> ByteString -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a.
FromHttpApiData a =>
MakeError -> ByteString -> Either ServerError a
decodeQueryParamOrServerError @a MakeError
makeError)
    (Maybe ByteString -> m (Maybe a))
-> (Maybe (Maybe ByteString) -> Maybe ByteString)
-> Maybe (Maybe ByteString)
-> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Maybe ByteString) -> Maybe ByteString
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join

{- | Tries to get query param

@
'queryParam' "foo" pure '/>' ...
@
-}
{-# INLINE queryParamLenient #-}
queryParamLenient ::
  forall a m i ts.
  (FromHttpApiData a, I.Introspection i I.QueryParam a, Monad m) =>
  -- | .
  QueryParamName ->
  ValueCombinator i (WithQueryParam Optional (Lenient Text) m a) ts m
queryParamLenient :: forall a (m :: * -> *) i ts.
(FromHttpApiData a, Introspection i 'QueryParam a, Monad m) =>
QueryParamName
-> ValueCombinator
     i (WithQueryParam Optional (Lenient QueryParamName) m a) ts m
queryParamLenient QueryParamName
qn = ByteString
-> (MakeError
    -> Maybe (Maybe ByteString)
    -> m (Arg Optional (Lenient QueryParamName) a))
-> Router'
     i (ts :+ WithQueryParam Optional (Lenient QueryParamName) m a) m
-> Router' i ts m
forall a presence parsing (m :: * -> *) ts i.
(Introspection i 'QueryParam a, IsRequired presence,
 IsLenient parsing) =>
ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg presence parsing a))
-> Router' i (ts :+ WithQueryParam presence parsing m a) m
-> Router' i ts m
QueryParam (QueryParamName -> ByteString
Text.Encode.encodeUtf8 QueryParamName
qn) \MakeError
_ ->
  m (Maybe (Either QueryParamName a))
-> (ByteString -> m (Maybe (Either QueryParamName a)))
-> Maybe ByteString
-> m (Maybe (Either QueryParamName a))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    (Maybe (Either QueryParamName a)
-> m (Maybe (Either QueryParamName a))
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Either QueryParamName a)
forall a. Maybe a
Nothing)
    (Maybe (Either QueryParamName a)
-> m (Maybe (Either QueryParamName a))
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Either QueryParamName a)
 -> m (Maybe (Either QueryParamName a)))
-> (ByteString -> Maybe (Either QueryParamName a))
-> ByteString
-> m (Maybe (Either QueryParamName a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either QueryParamName a -> Maybe (Either QueryParamName a)
forall a. a -> Maybe a
Just (Either QueryParamName a -> Maybe (Either QueryParamName a))
-> (ByteString -> Either QueryParamName a)
-> ByteString
-> Maybe (Either QueryParamName a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either QueryParamName a
forall a.
FromHttpApiData a =>
ByteString -> Either QueryParamName a
decodeQueryParam)
    (Maybe ByteString -> m (Maybe (Either QueryParamName a)))
-> (Maybe (Maybe ByteString) -> Maybe ByteString)
-> Maybe (Maybe ByteString)
-> m (Maybe (Either QueryParamName a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Maybe ByteString) -> Maybe ByteString
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join

{- | Tries to get query param

@
'queryParam' "foo" pure '/>' ...
@
-}
{-# INLINE queryParamLenient' #-}
queryParamLenient' ::
  forall a m i ts.
  (FromHttpApiData a, I.Introspection i I.QueryParam a, MonadThrow m) =>
  -- | .
  QueryParamName ->
  ValueCombinator i (WithQueryParam Required (Lenient Text) m a) ts m
queryParamLenient' :: forall a (m :: * -> *) i ts.
(FromHttpApiData a, Introspection i 'QueryParam a, MonadThrow m) =>
QueryParamName
-> ValueCombinator
     i (WithQueryParam Required (Lenient QueryParamName) m a) ts m
queryParamLenient' QueryParamName
qn = ByteString
-> (MakeError
    -> Maybe (Maybe ByteString)
    -> m (Arg Required (Lenient QueryParamName) a))
-> Router'
     i (ts :+ WithQueryParam Required (Lenient QueryParamName) m a) m
-> Router' i ts m
forall a presence parsing (m :: * -> *) ts i.
(Introspection i 'QueryParam a, IsRequired presence,
 IsLenient parsing) =>
ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg presence parsing a))
-> Router' i (ts :+ WithQueryParam presence parsing m a) m
-> Router' i ts m
QueryParam (QueryParamName -> ByteString
Text.Encode.encodeUtf8 QueryParamName
qn) \MakeError
makeError ->
  let badReq :: (QueryParamName -> ByteString) -> m (Either QueryParamName a)
badReq QueryParamName -> ByteString
err = ServerError -> m (Either QueryParamName a)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (ServerError -> m (Either QueryParamName a))
-> ServerError -> m (Either QueryParamName a)
forall a b. (a -> b) -> a -> b
$ MakeError
makeError Status
Http.status400 (ByteString -> ServerError) -> ByteString -> ServerError
forall a b. (a -> b) -> a -> b
$ QueryParamName -> ByteString
err QueryParamName
qn
   in m (Either QueryParamName a)
-> (Maybe ByteString -> m (Either QueryParamName a))
-> Maybe (Maybe ByteString)
-> m (Either QueryParamName a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
        ((QueryParamName -> ByteString) -> m (Either QueryParamName a)
badReq QueryParamName -> ByteString
queryParamKeyNotFoundError)
        (m (Either QueryParamName a)
-> (ByteString -> m (Either QueryParamName a))
-> Maybe ByteString
-> m (Either QueryParamName a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((QueryParamName -> ByteString) -> m (Either QueryParamName a)
badReq QueryParamName -> ByteString
queryParamValueNotFoundError) ((ByteString -> m (Either QueryParamName a))
 -> Maybe ByteString -> m (Either QueryParamName a))
-> (ByteString -> m (Either QueryParamName a))
-> Maybe ByteString
-> m (Either QueryParamName a)
forall a b. (a -> b) -> a -> b
$ Either QueryParamName a -> m (Either QueryParamName a)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either QueryParamName a -> m (Either QueryParamName a))
-> (ByteString -> Either QueryParamName a)
-> ByteString
-> m (Either QueryParamName a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either QueryParamName a
forall a.
FromHttpApiData a =>
ByteString -> Either QueryParamName a
decodeQueryParam)

{- | Extracts query string to `Form`

@
... '/>' 'queryParamsForm' \@MyForm '.>' ...
@
-}
{-# INLINE queryParamsForm #-}
queryParamsForm ::
  forall r m i ts.
  (I.Introspection i I.Request (QueryForm r), MonadThrow m, FromForm r) =>
  -- | .
  ValueCombinator i (WithReq m (QueryForm r)) ts m
queryParamsForm :: forall r (m :: * -> *) i ts.
(Introspection i 'Request (QueryForm r), MonadThrow m,
 FromForm r) =>
ValueCombinator i (WithReq m (QueryForm r)) ts m
queryParamsForm = (ErrorBuilder -> Request -> m (QueryForm r))
-> Router' i (ts :+ WithReq m (QueryForm r)) m -> Router' i ts m
forall r (m :: * -> *) i ts.
(Introspection i 'Request r, IsRequest r) =>
(ErrorBuilder -> Request -> m r)
-> Router' i (ts :+ WithReq m r) m -> Router' i ts m
Request \ErrorBuilder
makeError Request
req ->
  (QueryParamName -> m (QueryForm r))
-> (r -> m (QueryForm r))
-> Either QueryParamName r
-> m (QueryForm r)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ServerError -> m (QueryForm r)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (ServerError -> m (QueryForm r))
-> (QueryParamName -> ServerError)
-> QueryParamName
-> m (QueryForm r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorBuilder
makeError Request
req Status
Http.status400 (ByteString -> ServerError)
-> (QueryParamName -> ByteString) -> QueryParamName -> ServerError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryParamName -> ByteString
forall a b. ConvertibleStrings a b => a -> b
convertString) (QueryForm r -> m (QueryForm r)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QueryForm r -> m (QueryForm r))
-> (r -> QueryForm r) -> r -> m (QueryForm r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> QueryForm r
forall a. a -> QueryForm a
QueryForm)
    (Either QueryParamName r -> m (QueryForm r))
-> (Request -> Either QueryParamName r)
-> Request
-> m (QueryForm r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Either QueryParamName Form
Http.urlDecodeForm (ByteString -> Either QueryParamName Form)
-> (Form -> Either QueryParamName r)
-> ByteString
-> Either QueryParamName r
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Form -> Either QueryParamName r
forall a. FromForm a => Form -> Either QueryParamName a
Http.fromForm)
    (ByteString -> Either QueryParamName r)
-> (Request -> ByteString) -> Request -> Either QueryParamName r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Bytes.Lazy.fromStrict
    (ByteString -> ByteString)
-> (Request -> ByteString) -> Request -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> ByteString
Http.rawQueryString
    (Request -> m (QueryForm r)) -> Request -> m (QueryForm r)
forall a b. (a -> b) -> a -> b
$ Request
req

newtype QueryFlag = QueryFlag Bool

{-# INLINE queryFlag' #-}
queryFlag' ::
  forall m i ts.
  (I.Introspection i I.QueryParam QueryFlag, MonadThrow m) =>
  -- | .
  QueryParamName ->
  ValueCombinator i (WithQueryParam Required Strict m QueryFlag) ts m
queryFlag' :: forall (m :: * -> *) i ts.
(Introspection i 'QueryParam QueryFlag, MonadThrow m) =>
QueryParamName
-> ValueCombinator
     i (WithQueryParam Required Strict m QueryFlag) ts m
queryFlag' QueryParamName
qn = ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg Required Strict QueryFlag))
-> Router' i (ts :+ WithQueryParam Required Strict m QueryFlag) m
-> Router' i ts m
forall a presence parsing (m :: * -> *) ts i.
(Introspection i 'QueryParam a, IsRequired presence,
 IsLenient parsing) =>
ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg presence parsing a))
-> Router' i (ts :+ WithQueryParam presence parsing m a) m
-> Router' i ts m
QueryParam (QueryParamName -> ByteString
Text.Encode.encodeUtf8 QueryParamName
qn) \MakeError
makeError ->
  m QueryFlag
-> (Maybe ByteString -> m QueryFlag)
-> Maybe (Maybe ByteString)
-> m QueryFlag
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    (ServerError -> m QueryFlag
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (ServerError -> m QueryFlag) -> ServerError -> m QueryFlag
forall a b. (a -> b) -> a -> b
$ MakeError
makeError Status
Http.status400 (ByteString -> ServerError) -> ByteString -> ServerError
forall a b. (a -> b) -> a -> b
$ QueryParamName -> ByteString
queryParamKeyNotFoundError QueryParamName
qn)
    (m QueryFlag
-> (ByteString -> m QueryFlag) -> Maybe ByteString -> m QueryFlag
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (QueryFlag -> m QueryFlag
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> QueryFlag
QueryFlag Bool
True)) ((ByteString -> m QueryFlag) -> Maybe ByteString -> m QueryFlag)
-> (ByteString -> m QueryFlag) -> Maybe ByteString -> m QueryFlag
forall a b. (a -> b) -> a -> b
$ QueryFlag -> m QueryFlag
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QueryFlag -> m QueryFlag)
-> (ByteString -> QueryFlag) -> ByteString -> m QueryFlag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> QueryFlag
parseQueryFlag)

{-# INLINE queryFlag #-}
queryFlag ::
  forall m i ts.
  (I.Introspection i I.QueryParam QueryFlag, Monad m) =>
  -- | .
  QueryParamName ->
  ValueCombinator i (WithQueryParam Optional Strict m QueryFlag) ts m
queryFlag :: forall (m :: * -> *) i ts.
(Introspection i 'QueryParam QueryFlag, Monad m) =>
QueryParamName
-> ValueCombinator
     i (WithQueryParam Optional Strict m QueryFlag) ts m
queryFlag QueryParamName
qn = ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg Optional Strict QueryFlag))
-> Router' i (ts :+ WithQueryParam Optional Strict m QueryFlag) m
-> Router' i ts m
forall a presence parsing (m :: * -> *) ts i.
(Introspection i 'QueryParam a, IsRequired presence,
 IsLenient parsing) =>
ByteString
-> (MakeError
    -> Maybe (Maybe ByteString) -> m (Arg presence parsing a))
-> Router' i (ts :+ WithQueryParam presence parsing m a) m
-> Router' i ts m
QueryParam (QueryParamName -> ByteString
Text.Encode.encodeUtf8 QueryParamName
qn) \MakeError
_ ->
  m (Maybe QueryFlag)
-> (Maybe ByteString -> m (Maybe QueryFlag))
-> Maybe (Maybe ByteString)
-> m (Maybe QueryFlag)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    (Maybe QueryFlag -> m (Maybe QueryFlag)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe QueryFlag
forall a. Maybe a
Nothing)
    ((QueryFlag -> Maybe QueryFlag)
-> m QueryFlag -> m (Maybe QueryFlag)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap QueryFlag -> Maybe QueryFlag
forall a. a -> Maybe a
Just (m QueryFlag -> m (Maybe QueryFlag))
-> (Maybe ByteString -> m QueryFlag)
-> Maybe ByteString
-> m (Maybe QueryFlag)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m QueryFlag
-> (ByteString -> m QueryFlag) -> Maybe ByteString -> m QueryFlag
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (QueryFlag -> m QueryFlag
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> QueryFlag
QueryFlag Bool
True)) (QueryFlag -> m QueryFlag
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QueryFlag -> m QueryFlag)
-> (ByteString -> QueryFlag) -> ByteString -> m QueryFlag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> QueryFlag
parseQueryFlag))

parseQueryFlag :: Bytes.ByteString -> QueryFlag
parseQueryFlag :: ByteString -> QueryFlag
parseQueryFlag = Bool -> QueryFlag
QueryFlag (Bool -> QueryFlag)
-> (ByteString -> Bool) -> ByteString -> QueryFlag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> Bool)
-> [ByteString] -> ByteString -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem @[]) [ByteString
Item [ByteString]
"1", ByteString
Item [ByteString]
"true", ByteString
Item [ByteString]
""]

newtype QueryForm a = QueryForm a

instance IsRequest (QueryForm a) where
  type RequestValue (QueryForm a) = a
  getRequestValue :: QueryForm a -> RequestValue (QueryForm a)
getRequestValue (QueryForm a
a) = a
RequestValue (QueryForm a)
a