-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Storage backend for serversession using acid-state.
--   
--   API docs and the README are available at
--   <a>http://www.stackage.org/package/serversession-backend-acid-state</a>
@package serversession-backend-acid-state
@version 1.0.3


-- | Internal module exposing the guts of the package. Use at your own
--   risk. No API stability guarantees apply.
module Web.ServerSession.Backend.Acid.Internal

-- | Map from session IDs to sessions. The most important map, allowing us
--   efficient access to a session given its ID.
type SessionIdToSession sess = HashMap (SessionId sess) (Session sess)

-- | Map from auth IDs to session IDs. Allow us to invalidate all sessions
--   of given user without having to iterate through the whole
--   <a>SessionIdToSession</a> map.
type AuthIdToSessionId sess = HashMap AuthId (Set (SessionId sess))

-- | The current sessions.
--   
--   Besides the obvious map from session IDs to sessions, we also maintain
--   a map of auth IDs to session IDs. This allow us to quickly invalidate
--   all sessions of a given user.
data ServerSessionAcidState sess
ServerSessionAcidState :: !(SessionIdToSession sess) -> !(AuthIdToSessionId sess) -> ServerSessionAcidState sess
[sessionIdToSession] :: ServerSessionAcidState sess -> !(SessionIdToSession sess)
[authIdToSessionId] :: ServerSessionAcidState sess -> !(AuthIdToSessionId sess)

-- | Empty <a>ServerSessionAcidState</a> used to bootstrap the
--   <a>AcidState</a>.
emptyState :: ServerSessionAcidState sess

-- | Remove the given <tt>SessionId</tt> from the set of the given
--   <tt>AuthId</tt> on the map. Does not do anything if no <tt>AuthId</tt>
--   is provided.
removeSessionFromAuthId :: SessionId sess -> Maybe AuthId -> AuthIdToSessionId sess -> AuthIdToSessionId sess

-- | Insert the given session ID as being part of the given auth ID.
--   Conceptually the opposite of <a>removeSessionFromAuthId</a>. Does not
--   do anything if no <tt>AuthId</tt> is provided.
insertSessionForAuthId :: SessionId sess -> Maybe AuthId -> AuthIdToSessionId sess -> AuthIdToSessionId sess

-- | Get the session for the given session ID.
getSession :: Storage (AcidStorage sess) => SessionId sess -> Query (ServerSessionAcidState sess) (Maybe (Session sess))

-- | Delete the session with given session ID.
deleteSession :: Storage (AcidStorage sess) => SessionId sess -> Update (ServerSessionAcidState sess) ()

-- | Delete all sessions of the given auth ID.
deleteAllSessionsOfAuthId :: Storage (AcidStorage sess) => AuthId -> Update (ServerSessionAcidState sess) ()

-- | Insert a new session.
insertSession :: Storage (AcidStorage sess) => Session sess -> Update (ServerSessionAcidState sess) ()

-- | Replace the contents of a session.
replaceSession :: Storage (AcidStorage sess) => Session sess -> Update (ServerSessionAcidState sess) ()
data GetSession sess
data DeleteSession sess
data DeleteAllSessionsOfAuthId sess
data InsertSession sess
data ReplaceSession sess

-- | Session storage backend using <tt>acid-state</tt>.
newtype AcidStorage sess
AcidStorage :: AcidState (ServerSessionAcidState sess) -> AcidStorage sess

-- | Open <a>AcidState</a> of server sessions.
[acidState] :: AcidStorage sess -> AcidState (ServerSessionAcidState sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Common.QueryEvent (Web.ServerSession.Backend.Acid.Internal.GetSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Common.UpdateEvent (Web.ServerSession.Backend.Acid.Internal.DeleteSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Common.UpdateEvent (Web.ServerSession.Backend.Acid.Internal.DeleteAllSessionsOfAuthId sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Common.UpdateEvent (Web.ServerSession.Backend.Acid.Internal.InsertSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Common.UpdateEvent (Web.ServerSession.Backend.Acid.Internal.ReplaceSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Core.Method (Web.ServerSession.Backend.Acid.Internal.GetSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Core.Method (Web.ServerSession.Backend.Acid.Internal.DeleteSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Core.Method (Web.ServerSession.Backend.Acid.Internal.DeleteAllSessionsOfAuthId sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Core.Method (Web.ServerSession.Backend.Acid.Internal.InsertSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Core.Method (Web.ServerSession.Backend.Acid.Internal.ReplaceSession sess)
instance Web.ServerSession.Backend.Acid.Internal.AcidContext sess => Data.Acid.Common.IsAcidic (Web.ServerSession.Backend.Acid.Internal.ServerSessionAcidState sess)
instance (Web.ServerSession.Core.Internal.IsSessionData sess, Data.SafeCopy.SafeCopy.SafeCopy sess, Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.Decomposed sess)) => Web.ServerSession.Core.Internal.Storage (Web.ServerSession.Backend.Acid.Internal.AcidStorage sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.Decomposed sess) => Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Backend.Acid.Internal.ReplaceSession sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.Decomposed sess) => Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Backend.Acid.Internal.InsertSession sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Backend.Acid.Internal.DeleteAllSessionsOfAuthId sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Backend.Acid.Internal.DeleteSession sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Backend.Acid.Internal.GetSession sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.Decomposed sess) => Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Backend.Acid.Internal.ServerSessionAcidState sess)
instance Data.SafeCopy.SafeCopy.SafeCopy Web.ServerSession.Core.Internal.SessionMap
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.SessionId sess)
instance Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.Decomposed sess) => Data.SafeCopy.SafeCopy.SafeCopy (Web.ServerSession.Core.Internal.Session sess)


-- | Storage backend for <tt>serversession</tt> using <tt>acid-state</tt>.
--   
--   In order to use this backend, just open the <tt>AcidState</tt>. For
--   example:
--   
--   <pre>
--   import Control.Exception (bracket)
--   import Data.Acid.Local (openLocalState, createCheckpointAndClose)
--   import Web.ServerSession.Backend.Acid (AcidStorage(..), emptyState)
--   
--   withSessionStorage :: (AcidStorage -&gt; IO a) -&gt; IO a
--   withSessionStorage =
--     bracket
--       (<a>AcidStorage</a> &lt;$&gt; openLocalState <a>emptyState</a>)
--       (createCheckpointAndClose . <a>acidState</a>)
--   </pre>
module Web.ServerSession.Backend.Acid

-- | Session storage backend using <tt>acid-state</tt>.
newtype AcidStorage sess
AcidStorage :: AcidState (ServerSessionAcidState sess) -> AcidStorage sess

-- | Open <a>AcidState</a> of server sessions.
[acidState] :: AcidStorage sess -> AcidState (ServerSessionAcidState sess)

-- | Empty <a>ServerSessionAcidState</a> used to bootstrap the
--   <a>AcidState</a>.
emptyState :: ServerSessionAcidState sess

-- | The current sessions.
--   
--   Besides the obvious map from session IDs to sessions, we also maintain
--   a map of auth IDs to session IDs. This allow us to quickly invalidate
--   all sessions of a given user.
data ServerSessionAcidState sess
