{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Miso.Cookie
(
Cookie (..)
, CookieChangeEvent (..)
, cookieGet
, cookieGetAll
, cookieSet
, cookieDelete
, cookieDeleteWith
, defaultCookie
, cookieSet_
, cookieGet_
, cookieDelete_
, cookieDeleteWith_
, cookieGetAll_
) where
import Control.Concurrent (MVar, newEmptyMVar, putMVar, takeMVar)
import Control.Monad ((<=<), forM_, join)
import Prelude hiding ((!!))
import Miso.DSL
import Miso.Effect
import Miso.String (MisoString)
import qualified Miso.FFI.Internal as FFI
data Cookie = Cookie
{ Cookie -> MisoString
cookieName :: MisoString
, Cookie -> Maybe MisoString
cookieValue :: Maybe MisoString
, Cookie -> Maybe MisoString
cookieDomain :: Maybe MisoString
, Cookie -> MisoString
cookiePath :: MisoString
, Cookie -> Maybe Double
cookieExpires :: Maybe Double
, Cookie -> Bool
cookieSecure :: Bool
, Cookie -> MisoString
cookieSameSite :: MisoString
, Cookie -> Bool
cookiePartitioned :: Bool
} deriving (Int -> Cookie -> ShowS
[Cookie] -> ShowS
Cookie -> String
(Int -> Cookie -> ShowS)
-> (Cookie -> String) -> ([Cookie] -> ShowS) -> Show Cookie
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cookie -> ShowS
showsPrec :: Int -> Cookie -> ShowS
$cshow :: Cookie -> String
show :: Cookie -> String
$cshowList :: [Cookie] -> ShowS
showList :: [Cookie] -> ShowS
Show, Cookie -> Cookie -> Bool
(Cookie -> Cookie -> Bool)
-> (Cookie -> Cookie -> Bool) -> Eq Cookie
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Cookie -> Cookie -> Bool
== :: Cookie -> Cookie -> Bool
$c/= :: Cookie -> Cookie -> Bool
/= :: Cookie -> Cookie -> Bool
Eq)
instance ToJSVal Cookie where
toJSVal :: Cookie -> IO JSVal
toJSVal Cookie {Bool
Maybe Double
Maybe MisoString
MisoString
cookieName :: Cookie -> MisoString
cookieValue :: Cookie -> Maybe MisoString
cookieDomain :: Cookie -> Maybe MisoString
cookiePath :: Cookie -> MisoString
cookieExpires :: Cookie -> Maybe Double
cookieSecure :: Cookie -> Bool
cookieSameSite :: Cookie -> MisoString
cookiePartitioned :: Cookie -> Bool
cookieName :: MisoString
cookieValue :: Maybe MisoString
cookieDomain :: Maybe MisoString
cookiePath :: MisoString
cookieExpires :: Maybe Double
cookieSecure :: Bool
cookieSameSite :: MisoString
cookiePartitioned :: Bool
..} = do
Object
o <- IO Object
create
MisoString -> MisoString -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"name" MisoString
cookieName Object
o
MisoString -> Maybe MisoString -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"value" Maybe MisoString
cookieValue Object
o
MisoString -> MisoString -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"path" MisoString
cookiePath Object
o
MisoString -> Bool -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"secure" Bool
cookieSecure Object
o
MisoString -> MisoString -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"sameSite" MisoString
cookieSameSite Object
o
MisoString -> Bool -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"partitioned" Bool
cookiePartitioned Object
o
Maybe MisoString -> (MisoString -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe MisoString
cookieDomain ((MisoString -> IO ()) -> IO ()) -> (MisoString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \MisoString
d -> MisoString -> MisoString -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"domain" MisoString
d Object
o
Maybe Double -> (Double -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe Double
cookieExpires ((Double -> IO ()) -> IO ()) -> (Double -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Double
e -> MisoString -> Double -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"expires" Double
e Object
o
Object -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Object
o
{-# INLINE toJSVal #-}
instance FromJSVal Cookie where
fromJSVal :: JSVal -> IO (Maybe Cookie)
fromJSVal JSVal
v = do
Maybe MisoString
name_ <- JSVal -> IO (Maybe MisoString)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe MisoString))
-> IO JSVal -> IO (Maybe MisoString)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"name"
Maybe (Maybe MisoString)
value_ <- JSVal -> IO (Maybe (Maybe MisoString))
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe (Maybe MisoString)))
-> IO JSVal -> IO (Maybe (Maybe MisoString))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"value"
Maybe (Maybe MisoString)
domain_ <- JSVal -> IO (Maybe (Maybe MisoString))
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe (Maybe MisoString)))
-> IO JSVal -> IO (Maybe (Maybe MisoString))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"domain"
Maybe MisoString
path_ <- JSVal -> IO (Maybe MisoString)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe MisoString))
-> IO JSVal -> IO (Maybe MisoString)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"path"
Maybe (Maybe Double)
expires_ <- JSVal -> IO (Maybe (Maybe Double))
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe (Maybe Double)))
-> IO JSVal -> IO (Maybe (Maybe Double))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"expires"
Maybe Bool
secure_ <- JSVal -> IO (Maybe Bool)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe Bool)) -> IO JSVal -> IO (Maybe Bool)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"secure"
Maybe MisoString
sameSite_ <- JSVal -> IO (Maybe MisoString)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe MisoString))
-> IO JSVal -> IO (Maybe MisoString)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"sameSite"
Maybe Bool
partitioned_ <- JSVal -> IO (Maybe Bool)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal (JSVal -> IO (Maybe Bool)) -> IO JSVal -> IO (Maybe Bool)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
v JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"partitioned"
Maybe Cookie -> IO (Maybe Cookie)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Cookie -> IO (Maybe Cookie))
-> Maybe Cookie -> IO (Maybe Cookie)
forall a b. (a -> b) -> a -> b
$ do
MisoString
n <- Maybe MisoString
name_
Maybe MisoString
vl <- Maybe (Maybe MisoString)
value_
MisoString
p <- Maybe MisoString
path_
Bool
sec <- Maybe Bool
secure_
MisoString
ss <- Maybe MisoString
sameSite_
Bool
par <- Maybe Bool
partitioned_
Cookie -> Maybe Cookie
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Cookie
{ cookieName :: MisoString
cookieName = MisoString
n
, cookieValue :: Maybe MisoString
cookieValue = Maybe MisoString
vl
, cookieDomain :: Maybe MisoString
cookieDomain = Maybe (Maybe MisoString) -> Maybe MisoString
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join Maybe (Maybe MisoString)
domain_
, cookiePath :: MisoString
cookiePath = MisoString
p
, cookieExpires :: Maybe Double
cookieExpires = Maybe (Maybe Double) -> Maybe Double
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join Maybe (Maybe Double)
expires_
, cookieSecure :: Bool
cookieSecure = Bool
sec
, cookieSameSite :: MisoString
cookieSameSite = MisoString
ss
, cookiePartitioned :: Bool
cookiePartitioned = Bool
par
}
{-# INLINE fromJSVal #-}
data CookieChangeEvent = CookieChangeEvent
{ CookieChangeEvent -> [Cookie]
cookiesChanged :: [Cookie]
, CookieChangeEvent -> [Cookie]
cookiesDeleted :: [Cookie]
} deriving (Int -> CookieChangeEvent -> ShowS
[CookieChangeEvent] -> ShowS
CookieChangeEvent -> String
(Int -> CookieChangeEvent -> ShowS)
-> (CookieChangeEvent -> String)
-> ([CookieChangeEvent] -> ShowS)
-> Show CookieChangeEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CookieChangeEvent -> ShowS
showsPrec :: Int -> CookieChangeEvent -> ShowS
$cshow :: CookieChangeEvent -> String
show :: CookieChangeEvent -> String
$cshowList :: [CookieChangeEvent] -> ShowS
showList :: [CookieChangeEvent] -> ShowS
Show, CookieChangeEvent -> CookieChangeEvent -> Bool
(CookieChangeEvent -> CookieChangeEvent -> Bool)
-> (CookieChangeEvent -> CookieChangeEvent -> Bool)
-> Eq CookieChangeEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CookieChangeEvent -> CookieChangeEvent -> Bool
== :: CookieChangeEvent -> CookieChangeEvent -> Bool
$c/= :: CookieChangeEvent -> CookieChangeEvent -> Bool
/= :: CookieChangeEvent -> CookieChangeEvent -> Bool
Eq)
instance FromJSVal CookieChangeEvent where
fromJSVal :: JSVal -> IO (Maybe CookieChangeEvent)
fromJSVal JSVal
ev = do
Maybe [Cookie]
changed_ <- JSVal -> IO (Maybe [Cookie])
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked (JSVal -> IO (Maybe [Cookie])) -> IO JSVal -> IO (Maybe [Cookie])
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
ev JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"changed"
Maybe [Cookie]
deleted_ <- JSVal -> IO (Maybe [Cookie])
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked (JSVal -> IO (Maybe [Cookie])) -> IO JSVal -> IO (Maybe [Cookie])
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal
ev JSVal -> MisoString -> IO JSVal
forall o. ToObject o => o -> MisoString -> IO JSVal
! MisoString
"deleted"
Maybe CookieChangeEvent -> IO (Maybe CookieChangeEvent)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Cookie] -> [Cookie] -> CookieChangeEvent
CookieChangeEvent ([Cookie] -> [Cookie] -> CookieChangeEvent)
-> Maybe [Cookie] -> Maybe ([Cookie] -> CookieChangeEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [Cookie]
changed_ Maybe ([Cookie] -> CookieChangeEvent)
-> Maybe [Cookie] -> Maybe CookieChangeEvent
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe [Cookie]
deleted_)
{-# INLINE fromJSVal #-}
instance ToJSVal CookieChangeEvent where
toJSVal :: CookieChangeEvent -> IO JSVal
toJSVal CookieChangeEvent {[Cookie]
cookiesChanged :: CookieChangeEvent -> [Cookie]
cookiesDeleted :: CookieChangeEvent -> [Cookie]
cookiesChanged :: [Cookie]
cookiesDeleted :: [Cookie]
..} = do
Object
o <- IO Object
create
MisoString -> [Cookie] -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"changed" [Cookie]
cookiesChanged Object
o
MisoString -> [Cookie] -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"deleted" [Cookie]
cookiesDeleted Object
o
Object -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Object
o
{-# INLINE toJSVal #-}
instance ToArgs CookieChangeEvent where
toArgs :: CookieChangeEvent -> IO [JSVal]
toArgs CookieChangeEvent
ev = (JSVal -> [JSVal] -> [JSVal]
forall a. a -> [a] -> [a]
:[]) (JSVal -> [JSVal]) -> IO JSVal -> IO [JSVal]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CookieChangeEvent -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal CookieChangeEvent
ev
{-# INLINE toArgs #-}
cookieGet
:: MisoString
-> (Maybe MisoString -> action)
-> (MisoString -> action)
-> Effect context props model action
cookieGet :: forall action context props model.
MisoString
-> (Maybe MisoString -> action)
-> (MisoString -> action)
-> Effect context props model action
cookieGet MisoString
name Maybe MisoString -> action
successful MisoString -> action
errorful = (Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString -> (JSVal -> IO ()) -> (MisoString -> IO ()) -> IO ()
FFI.cookieGet MisoString
name
(Sink action
sink Sink action
-> (Maybe MisoString -> action) -> Maybe MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe MisoString -> action
successful (Maybe MisoString -> IO ())
-> (JSVal -> IO (Maybe MisoString)) -> JSVal -> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< JSVal -> IO (Maybe MisoString)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal)
(Sink action
sink Sink action -> (MisoString -> action) -> MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MisoString -> action
errorful)
cookieGetAll
:: ([Cookie] -> action)
-> (MisoString -> action)
-> Effect context props model action
cookieGetAll :: forall action context props model.
([Cookie] -> action)
-> (MisoString -> action) -> Effect context props model action
cookieGetAll [Cookie] -> action
successful MisoString -> action
errorful = (Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
(JSVal -> IO ()) -> (MisoString -> IO ()) -> IO ()
FFI.cookieGetAll
(Sink action
sink Sink action -> ([Cookie] -> action) -> [Cookie] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Cookie] -> action
successful ([Cookie] -> IO ()) -> (JSVal -> IO [Cookie]) -> JSVal -> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< JSVal -> IO [Cookie]
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked)
(Sink action
sink Sink action -> (MisoString -> action) -> MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MisoString -> action
errorful)
defaultCookie :: MisoString -> MisoString -> Cookie
defaultCookie :: MisoString -> MisoString -> Cookie
defaultCookie MisoString
name MisoString
value = Cookie
{ cookieName :: MisoString
cookieName = MisoString
name
, cookieValue :: Maybe MisoString
cookieValue = MisoString -> Maybe MisoString
forall a. a -> Maybe a
Just MisoString
value
, cookieDomain :: Maybe MisoString
cookieDomain = Maybe MisoString
forall a. Maybe a
Nothing
, cookiePath :: MisoString
cookiePath = MisoString
"/"
, cookieExpires :: Maybe Double
cookieExpires = Maybe Double
forall a. Maybe a
Nothing
, cookieSecure :: Bool
cookieSecure = Bool
False
, cookieSameSite :: MisoString
cookieSameSite = MisoString
"lax"
, cookiePartitioned :: Bool
cookiePartitioned = Bool
False
}
cookieSet
:: Cookie
-> action
-> (MisoString -> action)
-> Effect context props model action
cookieSet :: forall action context props model.
Cookie
-> action
-> (MisoString -> action)
-> Effect context props model action
cookieSet Cookie
cookie action
successful MisoString -> action
errorful = (Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
JSVal
c_ <- Cookie -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Cookie
cookie
JSVal -> IO () -> (MisoString -> IO ()) -> IO ()
FFI.cookieSet JSVal
c_ (Sink action
sink action
successful) (Sink action
sink Sink action -> (MisoString -> action) -> MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MisoString -> action
errorful)
cookieDelete
:: MisoString
-> action
-> (MisoString -> action)
-> Effect context props model action
cookieDelete :: forall action context props model.
MisoString
-> action
-> (MisoString -> action)
-> Effect context props model action
cookieDelete MisoString
name action
successful MisoString -> action
errorful = (Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString -> IO () -> (MisoString -> IO ()) -> IO ()
FFI.cookieDelete MisoString
name (Sink action
sink action
successful) (Sink action
sink Sink action -> (MisoString -> action) -> MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MisoString -> action
errorful)
cookieDeleteWith
:: Cookie
-> action
-> (MisoString -> action)
-> Effect context props model action
cookieDeleteWith :: forall action context props model.
Cookie
-> action
-> (MisoString -> action)
-> Effect context props model action
cookieDeleteWith Cookie
cookie action
successful MisoString -> action
errorful = (Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
JSVal
c_ <- Cookie -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Cookie
cookie
JSVal -> IO () -> (MisoString -> IO ()) -> IO ()
FFI.cookieDeleteWith JSVal
c_ (Sink action
sink action
successful) (Sink action
sink Sink action -> (MisoString -> action) -> MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MisoString -> action
errorful)
cookieSet_ :: Cookie -> IO (Either MisoString ())
cookieSet_ :: Cookie -> IO (Either MisoString ())
cookieSet_ Cookie
cookie = do
MVar (Either MisoString ())
mvar <- IO (MVar (Either MisoString ()))
forall a. IO (MVar a)
newEmptyMVar :: IO (MVar (Either MisoString ()))
JSVal
c_ <- Cookie -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Cookie
cookie
JSVal -> IO () -> (MisoString -> IO ()) -> IO ()
FFI.cookieSet JSVal
c_
(MVar (Either MisoString ()) -> Either MisoString () -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString ())
mvar (() -> Either MisoString ()
forall a b. b -> Either a b
Right ()))
(\MisoString
e -> MVar (Either MisoString ()) -> Either MisoString () -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString ())
mvar (MisoString -> Either MisoString ()
forall a b. a -> Either a b
Left MisoString
e))
MVar (Either MisoString ()) -> IO (Either MisoString ())
forall a. MVar a -> IO a
takeMVar MVar (Either MisoString ())
mvar
{-# INLINE cookieSet_ #-}
cookieGet_ :: MisoString -> IO (Either MisoString (Maybe MisoString))
cookieGet_ :: MisoString -> IO (Either MisoString (Maybe MisoString))
cookieGet_ MisoString
name = do
MVar (Either MisoString (Maybe MisoString))
mvar <- IO (MVar (Either MisoString (Maybe MisoString)))
forall a. IO (MVar a)
newEmptyMVar :: IO (MVar (Either MisoString (Maybe MisoString)))
MisoString -> (JSVal -> IO ()) -> (MisoString -> IO ()) -> IO ()
FFI.cookieGet MisoString
name
(\JSVal
v -> JSVal -> IO (Maybe MisoString)
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
v IO (Maybe MisoString) -> (Maybe MisoString -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MVar (Either MisoString (Maybe MisoString))
-> Either MisoString (Maybe MisoString) -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString (Maybe MisoString))
mvar (Either MisoString (Maybe MisoString) -> IO ())
-> (Maybe MisoString -> Either MisoString (Maybe MisoString))
-> Maybe MisoString
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe MisoString -> Either MisoString (Maybe MisoString)
forall a b. b -> Either a b
Right)
(\MisoString
e -> MVar (Either MisoString (Maybe MisoString))
-> Either MisoString (Maybe MisoString) -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString (Maybe MisoString))
mvar (MisoString -> Either MisoString (Maybe MisoString)
forall a b. a -> Either a b
Left MisoString
e))
MVar (Either MisoString (Maybe MisoString))
-> IO (Either MisoString (Maybe MisoString))
forall a. MVar a -> IO a
takeMVar MVar (Either MisoString (Maybe MisoString))
mvar
{-# INLINE cookieGet_ #-}
cookieDelete_ :: MisoString -> IO (Either MisoString ())
cookieDelete_ :: MisoString -> IO (Either MisoString ())
cookieDelete_ MisoString
name = do
MVar (Either MisoString ())
mvar <- IO (MVar (Either MisoString ()))
forall a. IO (MVar a)
newEmptyMVar :: IO (MVar (Either MisoString ()))
MisoString -> IO () -> (MisoString -> IO ()) -> IO ()
FFI.cookieDelete MisoString
name
(MVar (Either MisoString ()) -> Either MisoString () -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString ())
mvar (() -> Either MisoString ()
forall a b. b -> Either a b
Right ()))
(\MisoString
e -> MVar (Either MisoString ()) -> Either MisoString () -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString ())
mvar (MisoString -> Either MisoString ()
forall a b. a -> Either a b
Left MisoString
e))
MVar (Either MisoString ()) -> IO (Either MisoString ())
forall a. MVar a -> IO a
takeMVar MVar (Either MisoString ())
mvar
{-# INLINE cookieDelete_ #-}
cookieDeleteWith_ :: Cookie -> IO (Either MisoString ())
cookieDeleteWith_ :: Cookie -> IO (Either MisoString ())
cookieDeleteWith_ Cookie
cookie = do
MVar (Either MisoString ())
mvar <- IO (MVar (Either MisoString ()))
forall a. IO (MVar a)
newEmptyMVar :: IO (MVar (Either MisoString ()))
JSVal
c_ <- Cookie -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Cookie
cookie
JSVal -> IO () -> (MisoString -> IO ()) -> IO ()
FFI.cookieDeleteWith JSVal
c_
(MVar (Either MisoString ()) -> Either MisoString () -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString ())
mvar (() -> Either MisoString ()
forall a b. b -> Either a b
Right ()))
(\MisoString
e -> MVar (Either MisoString ()) -> Either MisoString () -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString ())
mvar (MisoString -> Either MisoString ()
forall a b. a -> Either a b
Left MisoString
e))
MVar (Either MisoString ()) -> IO (Either MisoString ())
forall a. MVar a -> IO a
takeMVar MVar (Either MisoString ())
mvar
{-# INLINE cookieDeleteWith_ #-}
cookieGetAll_ :: IO (Either MisoString [Cookie])
cookieGetAll_ :: IO (Either MisoString [Cookie])
cookieGetAll_ = do
MVar (Either MisoString [Cookie])
mvar <- IO (MVar (Either MisoString [Cookie]))
forall a. IO (MVar a)
newEmptyMVar :: IO (MVar (Either MisoString [Cookie]))
(JSVal -> IO ()) -> (MisoString -> IO ()) -> IO ()
FFI.cookieGetAll
(\JSVal
v -> JSVal -> IO [Cookie]
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
v IO [Cookie] -> ([Cookie] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MVar (Either MisoString [Cookie])
-> Either MisoString [Cookie] -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString [Cookie])
mvar (Either MisoString [Cookie] -> IO ())
-> ([Cookie] -> Either MisoString [Cookie]) -> [Cookie] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Cookie] -> Either MisoString [Cookie]
forall a b. b -> Either a b
Right)
(\MisoString
e -> MVar (Either MisoString [Cookie])
-> Either MisoString [Cookie] -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either MisoString [Cookie])
mvar (MisoString -> Either MisoString [Cookie]
forall a b. a -> Either a b
Left MisoString
e))
MVar (Either MisoString [Cookie])
-> IO (Either MisoString [Cookie])
forall a. MVar a -> IO a
takeMVar MVar (Either MisoString [Cookie])
mvar
{-# INLINE cookieGetAll_ #-}