1- {-# LANGUAGE DeriveFunctor #-}
2- {-# LANGUAGE DeriveGeneric #-}
3- {-# LANGUAGE FlexibleInstances #-}
4- {-# LANGUAGE GADTs #-}
5- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
6- {-# LANGUAGE MultiParamTypeClasses #-}
7- {-# LANGUAGE RankNTypes #-}
81{-# LANGUAGE TypeFamilies #-}
92{-# LANGUAGE TypeOperators #-}
103{-# LANGUAGE UndecidableInstances #-}
4+ {-# LANGUAGE RankNTypes #-}
5+ {-# LANGUAGE GADTs #-}
6+ {-# LANGUAGE MultiParamTypeClasses #-}
7+ {-# LANGUAGE FlexibleInstances #-}
8+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+ {-# LANGUAGE DeriveFunctor #-}
10+
11+ module Yesod.Core.Types (
12+ module Yesod.Core.Types
13+ , module Yesod.Core.Types.ErrorResponse
14+ , module Yesod.Core.Types.Content
15+ , module Yesod.Core.Types.TypedContent
16+ , module Yesod.Core.Types.HandlerContents
1117
12- module Yesod.Core.Types where
18+ , module Yesod.Core.Internal.Util
19+ , module Yesod.Routes.Class
20+ , module Yesod.Core.TypeCache
21+ ) where
1322
1423import Data.Aeson (ToJSON )
1524import qualified Data.ByteString.Builder as BB
@@ -34,9 +43,11 @@ import Data.Serialize (Serialize (..),
3443import Data.String (IsString (fromString ))
3544import Data.Text (Text )
3645import qualified Data.Text as T
46+ import Data.Text.Encoding
3747import qualified Data.Text.Lazy.Builder as TBuilder
3848import Data.Time (UTCTime )
3949import GHC.Generics (Generic )
50+ import qualified GHC.Int as I
4051import Language.Haskell.TH.Syntax (Loc )
4152import qualified Network.HTTP.Types as H
4253import Network.Wai (FilePart ,
@@ -57,6 +68,11 @@ import Yesod.Core.TypeCache (TypeMap, KeyedTypeMap)
5768import Control.Monad.Logger (MonadLoggerIO (.. ))
5869import UnliftIO (MonadUnliftIO (.. ), SomeException )
5970
71+ import Yesod.Core.Types.ErrorResponse
72+ import Yesod.Core.Types.Content
73+ import Yesod.Core.Types.TypedContent
74+ import Yesod.Core.Types.HandlerContents
75+
6076-- Sessions
6177type SessionMap = Map Text ByteString
6278
@@ -297,21 +313,12 @@ data PageContent url = PageContent
297313 , pageBody :: ! (HtmlUrl url )
298314 }
299315
300- data Content = ContentBuilder ! BB. Builder ! (Maybe Int ) -- ^ The content and optional content length.
301- | ContentSource ! (ConduitT () (Flush BB. Builder ) (ResourceT IO ) () )
302- | ContentFile ! FilePath ! (Maybe FilePart )
303- | ContentDontEvaluate ! Content
304-
305- data TypedContent = TypedContent ! ContentType ! Content
306-
307316type RepHtml = Html
308317{-# DEPRECATED RepHtml "Please use Html instead" #-}
309318newtype RepJson = RepJson Content
310319newtype RepPlain = RepPlain Content
311320newtype RepXml = RepXml Content
312321
313- type ContentType = ByteString -- FIXME Text?
314-
315322-- | Wrapper around types so that Handlers can return a domain type, even when
316323-- the data will eventually be encoded as JSON.
317324-- Example usage in a type signature:
@@ -332,34 +339,6 @@ data JSONResponse a where
332339-- Since 1.1.0
333340newtype DontFullyEvaluate a = DontFullyEvaluate { unDontFullyEvaluate :: a }
334341
335- -- | Responses to indicate some form of an error occurred.
336- data ErrorResponse =
337- NotFound
338- -- ^ The requested resource was not found.
339- -- Examples of when this occurs include when an incorrect URL is used, or @yesod-persistent@'s 'get404' doesn't find a value.
340- -- HTTP status: 404.
341- | InternalError ! Text
342- -- ^ Some sort of unexpected exception.
343- -- If your application uses `throwIO` or `error` to throw an exception, this is the form it would take.
344- -- HTTP status: 500.
345- | InvalidArgs ! [Text ]
346- -- ^ Indicates some sort of invalid or missing argument, like a missing query parameter or malformed JSON body.
347- -- Examples Yesod functions that send this include 'requireCheckJsonBody' and @Yesod.Auth.GoogleEmail2@.
348- -- HTTP status: 400.
349- | NotAuthenticated
350- -- ^ Indicates the user is not logged in.
351- -- This is thrown when 'isAuthorized' returns 'AuthenticationRequired'.
352- -- HTTP code: 401.
353- | PermissionDenied ! Text
354- -- ^ Indicates the user doesn't have permission to access the requested resource.
355- -- This is thrown when 'isAuthorized' returns 'Unauthorized'.
356- -- HTTP code: 403.
357- | BadMethod ! H. Method
358- -- ^ Indicates the URL would have been valid if used with a different HTTP method (e.g. a GET was used, but only POST is handled.)
359- -- HTTP code: 405.
360- deriving (Show , Eq , Generic )
361- instance NFData ErrorResponse
362-
363342----- header stuff
364343-- | Headers to be added to a 'Result'.
365344data Header =
@@ -423,25 +402,6 @@ instance Semigroup (GWData a) where
423402 (mappend a7 b7)
424403 (mappend a8 b8)
425404
426- data HandlerContents =
427- HCContent ! H. Status ! TypedContent
428- | HCError ! ErrorResponse
429- | HCSendFile ! ContentType ! FilePath ! (Maybe FilePart )
430- | HCRedirect ! H. Status ! Text
431- | HCCreated ! Text
432- | HCWai ! W. Response
433- | HCWaiApp ! W. Application
434-
435- instance Show HandlerContents where
436- show (HCContent status (TypedContent t _)) = " HCContent " ++ show (status, t)
437- show (HCError e) = " HCError " ++ show e
438- show (HCSendFile ct fp mfp) = " HCSendFile " ++ show (ct, fp, mfp)
439- show (HCRedirect s t) = " HCRedirect " ++ show (s, t)
440- show (HCCreated t) = " HCCreated " ++ show t
441- show (HCWai _) = " HCWai"
442- show (HCWaiApp _) = " HCWaiApp"
443- instance Exception HandlerContents
444-
445405-- Instances for WidgetFor
446406instance Applicative (WidgetFor site ) where
447407 pure = WidgetFor . const . pure
0 commit comments