yesod-core-1.2.0.4: Creation of type-safe, RESTful web applications.

Safe Haskell | None

Yesod.Core.Types

Synopsis

- type SessionMap = Map Text ByteString
- type SaveSession = SessionMap -> IO [Header]
- newtype SessionBackend = SessionBackend {
  - sbLoadSession :: Request -> IO (SessionMap, SaveSession)
  }
- data SessionCookie = SessionCookie (Either UTCTime ByteString) ByteString SessionMap
- data ClientSessionDateCache = ClientSessionDateCache {
  - csdcNow :: !UTCTime
  - csdcExpires :: !UTCTime
  - csdcExpiresSerialized :: !ByteString
  }
- data YesodRequest = YesodRequest {
  - reqGetParams :: ![(Text, Text)]
  - reqCookies :: ![(Text, Text)]
  - reqWaiRequest :: !Request
  - reqLangs :: ![Text]
  - reqToken :: !(Maybe Text)
  - reqSession :: !SessionMap
  - reqAccept :: ![ContentType]
  }
- data YesodResponse
  - = YRWai !Response
  - | YRPlain !Status ![Header] !ContentType !Content !SessionMap
- type RequestBodyContents = ([(Text, Text)], [(Text, FileInfo)])
- data FileInfo = FileInfo {
  - fileName :: !Text
  - fileContentType :: !Text
  - fileSourceRaw :: !(Source (ResourceT IO) ByteString)
  - fileMove :: !(FilePath -> IO ())
  }
- data FileUpload
  - = FileUploadMemory !(BackEnd ByteString)
  - | FileUploadDisk !(BackEnd FilePath)
  - | FileUploadSource !(BackEnd (Source (ResourceT IO) ByteString))
- data Approot master
  - = ApprootRelative
  - | ApprootStatic !Text
  - | ApprootMaster !(master -> Text)
  - | ApprootRequest !(master -> Request -> Text)
- type ResolvedApproot = Text
- data AuthResult
  - = Authorized
  - | AuthenticationRequired
  - | Unauthorized Text
- data ScriptLoadPosition master
  - = BottomOfBody
  - | BottomOfHeadBlocking
  - | BottomOfHeadAsync (BottomOfHeadAsync master)
- type BottomOfHeadAsync master = [Text] -> Maybe (HtmlUrl (Route master)) -> HtmlUrl (Route master)
- newtype Cache = Cache (Map TypeRep Dynamic)
- type Texts = [Text]
- newtype WaiSubsite = WaiSubsite {
  - runWaiSubsite :: Application
  }
- data RunHandlerEnv site = RunHandlerEnv {
  - rheRender :: !(Route site -> [(Text, Text)] -> Text)
  - rheRoute :: !(Maybe (Route site))
  - rheSite :: !site
  - rheUpload :: !(RequestBodyLength -> FileUpload)
  - rheLog :: !(Loc -> LogSource -> LogLevel -> LogStr -> IO ())
  - rheOnError :: !(ErrorResponse -> YesodApp)
  }
- data HandlerData site parentRoute = HandlerData {
  - handlerRequest :: !YesodRequest
  - handlerEnv :: !(RunHandlerEnv site)
  - handlerState :: !(IORef GHState)
  - handlerToParent :: !(Route site -> parentRoute)
  - handlerResource :: !InternalState
  }
- data YesodRunnerEnv site = YesodRunnerEnv {
  - yreLogger :: !Logger
  - yreSite :: !site
  - yreSessionBackend :: !(Maybe SessionBackend)
  }
- data YesodSubRunnerEnv sub parent parentMonad = YesodSubRunnerEnv {
  - ysreParentRunner :: !(ParentRunner parent parentMonad)
  - ysreGetSub :: !(parent -> sub)
  - ysreToParentRoute :: !(Route sub -> Route parent)
  - ysreParentEnv :: !(YesodRunnerEnv parent)
  }
- type ParentRunner parent m = m TypedContent -> YesodRunnerEnv parent -> Maybe (Route parent) -> Application
- newtype HandlerT site m a = HandlerT {
  - unHandlerT :: HandlerData site (MonadRoute m) -> m a
  }
- type family MonadRoute m
- data GHState = GHState {
  - ghsSession :: SessionMap
  - ghsRBC :: Maybe RequestBodyContents
  - ghsIdent :: Int
  - ghsCache :: Cache
  - ghsHeaders :: Endo [Header]
  }
- type YesodApp = YesodRequest -> ResourceT IO YesodResponse
- newtype WidgetT site m a = WidgetT {
  - unWidgetT :: HandlerData site (MonadRoute m) -> m (a, GWData (Route site))
  }
- type RY master = Route master -> [(Text, Text)] -> Text
- newtype CssBuilder = CssBuilder {
  - unCssBuilder :: Builder
  }
- data PageContent url = PageContent {
  - pageTitle :: Html
  - pageHead :: HtmlUrl url
  - pageBody :: HtmlUrl url
  }
- data Content
  - = ContentBuilder !Builder !(Maybe Int)
  - | ContentSource !(Source (ResourceT IO) (Flush Builder))
  - | ContentFile !FilePath !(Maybe FilePart)
  - | ContentDontEvaluate !Content
- data TypedContent = TypedContent !ContentType !Content
- type RepHtml = Html
- newtype RepJson = RepJson Content
- newtype RepPlain = RepPlain Content
- newtype RepXml = RepXml Content
- type ContentType = ByteString
- newtype DontFullyEvaluate a = DontFullyEvaluate {
  - unDontFullyEvaluate :: a
  }
- data ErrorResponse
  - = NotFound
  - | InternalError Text
  - | InvalidArgs [Text]
  - | NotAuthenticated
  - | PermissionDenied Text
  - | BadMethod Method
- data Header
  - = AddCookie SetCookie
  - | DeleteCookie ByteString ByteString
  - | Header ByteString ByteString
- data Location url
  - = Local url
  - | Remote Text
- newtype UniqueList x = UniqueList ([x] -> [x])
- data Script url = Script {
  - scriptLocation :: Location url
  - scriptAttributes :: [(Text, Text)]
  }
- data Stylesheet url = Stylesheet {
  - styleLocation :: Location url
  - styleAttributes :: [(Text, Text)]
  }
- newtype Title = Title {
  - unTitle :: Html
  }
- newtype Head url = Head (HtmlUrl url)
- newtype Body url = Body (HtmlUrl url)
- type CssBuilderUrl a = (a -> [(Text, Text)] -> Text) -> Builder
- data GWData a = GWData {
  - gwdBody :: !(Body a)
  - gwdTitle :: !(Last Title)
  - gwdScripts :: !(UniqueList (Script a))
  - gwdStylesheets :: !(UniqueList (Stylesheet a))
  - gwdCss :: !(Map (Maybe Text) (CssBuilderUrl a))
  - gwdJavascript :: !(Maybe (JavascriptUrl a))
  - gwdHead :: !(Head a)
  }
- data HandlerContents
  - = HCContent Status !TypedContent
  - | HCError ErrorResponse
  - | HCSendFile ContentType FilePath (Maybe FilePart)
  - | HCRedirect Status Text
  - | HCCreated Text
  - | HCWai Response

# Documentation

type SessionMap = Map Text ByteString

type SaveSession

Arguments

= SessionMap | The session contents after running the handler
-> IO [Header] |

newtype SessionBackend

Constructors

SessionBackend |
Fields sbLoadSession :: Request -> IO (SessionMap, SaveSession) Return the session data and a function to save the session

data SessionCookie

Constructors

SessionCookie (Either UTCTime ByteString) ByteString SessionMap |

Instances

Read SessionCookie |
Show SessionCookie |
Serialize SessionCookie |

data ClientSessionDateCache

Constructors

ClientSessionDateCache |
Fields csdcNow :: !UTCTime csdcExpires :: !UTCTime csdcExpiresSerialized :: !ByteString

Instances

Eq ClientSessionDateCache |
Show ClientSessionDateCache |

data YesodRequest

The parsed request information. This type augments the standard WAI `Request` with additional information.

Constructors

YesodRequest |
Fields reqGetParams :: ![(Text, Text)] Same as `queryString`, but decoded to `Text`. reqCookies :: ![(Text, Text)] reqWaiRequest :: !Request reqLangs :: ![Text] Languages which the client supports. This is an ordered list by preference. reqToken :: !(Maybe Text) A random, session-specific token used to prevent CSRF attacks. reqSession :: !SessionMap Initial session sent from the client. Since 1.2.0 reqAccept :: ![ContentType] An ordered list of the accepted content types. Since 1.2.0

data YesodResponse

An augmented WAI `Response`. This can either be a standard `Response`, or a higher-level data structure which Yesod will turn into a `Response`.

Constructors

YRWai !Response |
YRPlain !Status ![Header] !ContentType !Content !SessionMap |

type RequestBodyContents = ([(Text, Text)], [(Text, FileInfo)])

A tuple containing both the POST parameters and submitted files.

data FileInfo

Constructors

FileInfo |
Fields fileName :: !Text fileContentType :: !Text fileSourceRaw :: !(Source (ResourceT IO) ByteString) fileMove :: !(FilePath -> IO ())

data FileUpload

Constructors

FileUploadMemory !(BackEnd ByteString) |
FileUploadDisk !(BackEnd FilePath) |
FileUploadSource !(BackEnd (Source (ResourceT IO) ByteString)) |

data Approot master

How to determine the root of the application for constructing URLs.

Note that future versions of Yesod may add new constructors without bumping the major version number. As a result, you should not pattern match on `Approot` values.

Constructors

ApprootRelative | No application root.
ApprootStatic !Text |
ApprootMaster !(master -> Text) |
ApprootRequest !(master -> Request -> Text) |

type ResolvedApproot = Text

data AuthResult

Constructors

Authorized |
AuthenticationRequired |
Unauthorized Text |

Instances

Eq AuthResult |
Read AuthResult |
Show AuthResult |

data ScriptLoadPosition master

Constructors

BottomOfBody |
BottomOfHeadBlocking |
BottomOfHeadAsync (BottomOfHeadAsync master) |

type BottomOfHeadAsync master

Arguments

= [Text] | urls to load asynchronously
-> Maybe (HtmlUrl (Route master)) | widget of js to run on async completion
-> HtmlUrl (Route master) | widget to insert at the bottom of head

newtype Cache

Constructors

Cache (Map TypeRep Dynamic) |

Instances

Monoid Cache |

type Texts = [Text]

newtype WaiSubsite

Wrap up a normal WAI application as a Yesod subsite.

Constructors

WaiSubsite |
Fields runWaiSubsite :: Application

Instances

RenderRoute WaiSubsite |
ParseRoute WaiSubsite |
YesodSubDispatch WaiSubsite master |
Eq (Route WaiSubsite) |
Ord (Route WaiSubsite) |
Read (Route WaiSubsite) |
Show (Route WaiSubsite) |

data RunHandlerEnv site

Constructors

RunHandlerEnv |
Fields rheRender :: !(Route site -> [(Text, Text)] -> Text) rheRoute :: !(Maybe (Route site)) rheSite :: !site rheUpload :: !(RequestBodyLength -> FileUpload) rheLog :: !(Loc -> LogSource -> LogLevel -> LogStr -> IO ()) rheOnError :: !(ErrorResponse -> YesodApp) How to respond when an error is thrown internally. Since 1.2.0

data HandlerData site parentRoute

Constructors

HandlerData |
Fields handlerRequest :: !YesodRequest handlerEnv :: !(RunHandlerEnv site) handlerState :: !(IORef GHState) handlerToParent :: !(Route site -> parentRoute) handlerResource :: !InternalState

data YesodRunnerEnv site

Constructors

YesodRunnerEnv |
Fields yreLogger :: !Logger yreSite :: !site yreSessionBackend :: !(Maybe SessionBackend)

data YesodSubRunnerEnv sub parent parentMonad

Constructors

YesodSubRunnerEnv |
Fields ysreParentRunner :: !(ParentRunner parent parentMonad) ysreGetSub :: !(parent -> sub) ysreToParentRoute :: !(Route sub -> Route parent) ysreParentEnv :: !(YesodRunnerEnv parent)

type ParentRunner parent m = m TypedContent -> YesodRunnerEnv parent -> Maybe (Route parent) -> Application

newtype HandlerT site m a

A generic handler monad, which can have a different subsite and master site. We define a newtype for better error message.

Constructors

HandlerT |
Fields unHandlerT :: HandlerData site (MonadRoute m) -> m a

Instances

MonadBaseControl b m => MonadBaseControl b (HandlerT site m) | Note: although we provide a `MonadBaseControl` instance, `lifted-base`'s `fork` function is incompatible with the underlying `ResourceT` system. Instead, if you must fork a separate thread, you should use `resourceForkIO`. Using fork usually leads to an exception that says "Control.Monad.Trans.Resource.register': The mutable state is being accessed after cleanup. Please contact the maintainers."
MonadBase b m => MonadBase b (HandlerT site m) |
MonadTrans (HandlerT site) |
Monad m => Monad (HandlerT site m) |
Monad m => Functor (HandlerT site m) |
Monad m => Applicative (HandlerT site m) |
MonadThrow m => MonadThrow (HandlerT site m) |
(MonadIO m, MonadUnsafeIO m, MonadThrow m) => MonadResource (HandlerT site m) |
MonadIO m => MonadLogger (HandlerT site m) |
MonadIO m => MonadIO (HandlerT site m) |
MonadResourceBase m => MonadHandler (HandlerT site m) |

type family MonadRoute m

data GHState

Constructors

GHState |
Fields ghsSession :: SessionMap ghsRBC :: Maybe RequestBodyContents ghsIdent :: Int ghsCache :: Cache ghsHeaders :: Endo [Header]

type YesodApp = YesodRequest -> ResourceT IO YesodResponse

An extension of the basic WAI `Application` datatype to provide extra features needed by Yesod. Users should never need to use this directly, as the `HandlerT` monad and template haskell code should hide it away.

newtype WidgetT site m a

A generic widget, allowing specification of both the subsite and master site datatypes. While this is simply a `WriterT`, we define a newtype for better error messages.

Constructors

WidgetT |
Fields unWidgetT :: HandlerData site (MonadRoute m) -> m (a, GWData (Route site))

Instances

MonadBaseControl b m => MonadBaseControl b (WidgetT site m) |
MonadBase b m => MonadBase b (WidgetT site m) |
(~ * site' site, ~ (* -> *) IO m, ~ * a ()) => ToWidget site' (WidgetT site m a) |
MonadTrans (WidgetT site) |
Monad m => Monad (WidgetT site m) |
Monad m => Functor (WidgetT site m) |
Monad m => Applicative (WidgetT site m) |
MonadThrow m => MonadThrow (WidgetT site m) |
(Applicative m, MonadIO m, MonadUnsafeIO m, MonadThrow m) => MonadResource (WidgetT site m) |
MonadIO m => MonadLogger (WidgetT site m) |
MonadIO m => MonadIO (WidgetT site m) |
MonadResourceBase m => MonadWidget (WidgetT site m) |
MonadResourceBase m => MonadHandler (WidgetT site m) |
(~ * a (), Monad m) => Monoid (WidgetT site m a) |

type RY master = Route master -> [(Text, Text)] -> Text

newtype CssBuilder

Newtype wrapper allowing injection of arbitrary content into CSS.

Usage:

     toWidget $ CssBuilder "p { color: red }"

Since: 1.1.3

Constructors

CssBuilder |
Fields unCssBuilder :: Builder

Instances

~ * render (RY site) => ToWidgetHead site (render -> CssBuilder) |
~ * render (RY site) => ToWidgetMedia site (render -> CssBuilder) |
~ * render (RY site) => ToWidget site (render -> CssBuilder) |

data PageContent url

Content for a web page. By providing this datatype, we can easily create generic site templates, which would have the type signature:

     PageContent url -> HtmlUrl url

Constructors

PageContent |
Fields pageTitle :: Html pageHead :: HtmlUrl url pageBody :: HtmlUrl url

data Content

Constructors

ContentBuilder !Builder !(Maybe Int) | The content and optional content length.
ContentSource !(Source (ResourceT IO) (Flush Builder)) |
ContentFile !FilePath !(Maybe FilePart) |
ContentDontEvaluate !Content |

Instances

IsString Content |
ToContent Content |
ToTypedContent (ContentType, Content) |
ToContent (ContentType, Content) |

data TypedContent

Constructors

TypedContent !ContentType !Content |

Instances

ToTypedContent TypedContent |
ToContent TypedContent |

type RepHtml = Html

newtype RepJson

Constructors

RepJson Content |

Instances

ToTypedContent RepJson |
HasContentType RepJson |
ToContent RepJson |

newtype RepPlain

Constructors

RepPlain Content |

Instances

ToTypedContent RepPlain |
HasContentType RepPlain |
ToContent RepPlain |

newtype RepXml

Constructors

RepXml Content |

Instances

ToTypedContent RepXml |
HasContentType RepXml |
ToContent RepXml |

type ContentType = ByteString

newtype DontFullyEvaluate a

Prevents a response body from being fully evaluated before sending the request.

Since 1.1.0

Constructors

DontFullyEvaluate |
Fields unDontFullyEvaluate :: a

Instances

ToTypedContent a => ToTypedContent (DontFullyEvaluate a) |
HasContentType a => HasContentType (DontFullyEvaluate a) |
ToContent a => ToContent (DontFullyEvaluate a) |

data ErrorResponse

Responses to indicate some form of an error occurred. These are different from `SpecialResponse` in that they allow for custom error pages.

Constructors

NotFound |
InternalError Text |
InvalidArgs [Text] |
NotAuthenticated |
PermissionDenied Text |
BadMethod Method |

Instances

Eq ErrorResponse |
Show ErrorResponse |
Typeable ErrorResponse |

data Header

Headers to be added to a `Result`.

Constructors

AddCookie SetCookie |
DeleteCookie ByteString ByteString |
Header ByteString ByteString |

Instances

Eq Header |
Show Header |

data Location url

Constructors

Local url |
Remote Text |

Instances

Eq url => Eq (Location url) |
Show url => Show (Location url) |

newtype UniqueList x

Constructors

UniqueList ([x] -> [x]) |

Instances

Monoid (UniqueList x) |

data Script url

Constructors

Script |
Fields scriptLocation :: Location url scriptAttributes :: [(Text, Text)]

Instances

Eq url => Eq (Script url) |
Show url => Show (Script url) |

data Stylesheet url

Constructors

Stylesheet |
Fields styleLocation :: Location url styleAttributes :: [(Text, Text)]

Instances

Eq url => Eq (Stylesheet url) |
Show url => Show (Stylesheet url) |

newtype Title

Constructors

Title |
Fields unTitle :: Html

newtype Head url

Constructors

Head (HtmlUrl url) |

Instances

Monoid (Head url) |

newtype Body url

Constructors

Body (HtmlUrl url) |

Instances

Monoid (Body url) |

type CssBuilderUrl a = (a -> [(Text, Text)] -> Text) -> Builder

data GWData a

Constructors

GWData |
Fields gwdBody :: !(Body a) gwdTitle :: !(Last Title) gwdScripts :: !(UniqueList (Script a)) gwdStylesheets :: !(UniqueList (Stylesheet a)) gwdCss :: !(Map (Maybe Text) (CssBuilderUrl a)) gwdJavascript :: !(Maybe (JavascriptUrl a)) gwdHead :: !(Head a)

Instances

Monoid (GWData a) |

data HandlerContents

Constructors

HCContent Status !TypedContent |
HCError ErrorResponse |
HCSendFile ContentType FilePath (Maybe FilePart) |
HCRedirect Status Text |
HCCreated Text |
HCWai Response |

Instances

Show HandlerContents |
Typeable HandlerContents |
Exception HandlerContents |