module Web.Hyperbole.Types.Request
( Request (..)
, Host (..)
, Form (..)
, FormParam (..)
, Param
, FileParam
, File
, RequestId (..)
, UploadedFile (..)
) where
import Data.Aeson (Value)
import Data.ByteString qualified as BS
import Data.String (IsString (..))
import Data.String.Conversions (cs)
import Data.Text (Text)
import Network.HTTP.Types (Method)
import Network.Wai.Parse (File, Param)
import Web.Hyperbole.Data.Cookie (Cookies)
import Web.Hyperbole.Data.Encoded
import Web.Hyperbole.Data.URI (Path, Query)
import Web.Hyperbole.Types.Event (Event (..), TargetViewId)
newtype Host = Host {Host -> ByteString
text :: BS.ByteString}
deriving (Int -> Host -> ShowS
[Host] -> ShowS
Host -> String
(Int -> Host -> ShowS)
-> (Host -> String) -> ([Host] -> ShowS) -> Show Host
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Host -> ShowS
showsPrec :: Int -> Host -> ShowS
$cshow :: Host -> String
show :: Host -> String
$cshowList :: [Host] -> ShowS
showList :: [Host] -> ShowS
Show)
data UploadedFile = UploadedFile
{ UploadedFile -> String
filePath :: FilePath
, UploadedFile -> Text
fileName :: Text
, UploadedFile -> Text
contentType :: Text
}
deriving (Int -> UploadedFile -> ShowS
[UploadedFile] -> ShowS
UploadedFile -> String
(Int -> UploadedFile -> ShowS)
-> (UploadedFile -> String)
-> ([UploadedFile] -> ShowS)
-> Show UploadedFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UploadedFile -> ShowS
showsPrec :: Int -> UploadedFile -> ShowS
$cshow :: UploadedFile -> String
show :: UploadedFile -> String
$cshowList :: [UploadedFile] -> ShowS
showList :: [UploadedFile] -> ShowS
Show, UploadedFile -> UploadedFile -> Bool
(UploadedFile -> UploadedFile -> Bool)
-> (UploadedFile -> UploadedFile -> Bool) -> Eq UploadedFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UploadedFile -> UploadedFile -> Bool
== :: UploadedFile -> UploadedFile -> Bool
$c/= :: UploadedFile -> UploadedFile -> Bool
/= :: UploadedFile -> UploadedFile -> Bool
Eq)
type FileParam = (BS.ByteString, UploadedFile)
data Request = Request
{ Request -> Host
host :: Host
, Request -> Path
path :: Path
, Request -> Query
query :: Query
, Request -> ByteString
method :: Method
, Request -> Cookies
cookies :: Cookies
, Request -> Maybe (Event TargetViewId Encoded Value)
event :: Maybe (Event TargetViewId Encoded Value)
, Request -> RequestId
requestId :: RequestId
, Request -> Form
form :: Form
, Request -> Text
input :: Text
}
deriving (Int -> Request -> ShowS
[Request] -> ShowS
Request -> String
(Int -> Request -> ShowS)
-> (Request -> String) -> ([Request] -> ShowS) -> Show Request
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Request -> ShowS
showsPrec :: Int -> Request -> ShowS
$cshow :: Request -> String
show :: Request -> String
$cshowList :: [Request] -> ShowS
showList :: [Request] -> ShowS
Show)
data Form = Form
{ Form -> [Param]
params :: [Param]
, Form -> [FileParam]
files :: [FileParam]
}
deriving (Int -> Form -> ShowS
[Form] -> ShowS
Form -> String
(Int -> Form -> ShowS)
-> (Form -> String) -> ([Form] -> ShowS) -> Show Form
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Form -> ShowS
showsPrec :: Int -> Form -> ShowS
$cshow :: Form -> String
show :: Form -> String
$cshowList :: [Form] -> ShowS
showList :: [Form] -> ShowS
Show)
data FormParam
= FormParam Text
| FileParam UploadedFile
deriving (Int -> FormParam -> ShowS
[FormParam] -> ShowS
FormParam -> String
(Int -> FormParam -> ShowS)
-> (FormParam -> String)
-> ([FormParam] -> ShowS)
-> Show FormParam
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FormParam -> ShowS
showsPrec :: Int -> FormParam -> ShowS
$cshow :: FormParam -> String
show :: FormParam -> String
$cshowList :: [FormParam] -> ShowS
showList :: [FormParam] -> ShowS
Show, FormParam -> FormParam -> Bool
(FormParam -> FormParam -> Bool)
-> (FormParam -> FormParam -> Bool) -> Eq FormParam
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FormParam -> FormParam -> Bool
== :: FormParam -> FormParam -> Bool
$c/= :: FormParam -> FormParam -> Bool
/= :: FormParam -> FormParam -> Bool
Eq)
instance IsString FormParam where
fromString :: String -> FormParam
fromString String
s = Text -> FormParam
FormParam (String -> Text
forall a b. ConvertibleStrings a b => a -> b
cs String
s)
newtype RequestId = RequestId Text
deriving (Int -> RequestId -> ShowS
[RequestId] -> ShowS
RequestId -> String
(Int -> RequestId -> ShowS)
-> (RequestId -> String)
-> ([RequestId] -> ShowS)
-> Show RequestId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RequestId -> ShowS
showsPrec :: Int -> RequestId -> ShowS
$cshow :: RequestId -> String
show :: RequestId -> String
$cshowList :: [RequestId] -> ShowS
showList :: [RequestId] -> ShowS
Show, RequestId -> RequestId -> Bool
(RequestId -> RequestId -> Bool)
-> (RequestId -> RequestId -> Bool) -> Eq RequestId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RequestId -> RequestId -> Bool
== :: RequestId -> RequestId -> Bool
$c/= :: RequestId -> RequestId -> Bool
/= :: RequestId -> RequestId -> Bool
Eq)