module WebDriverPreCore.BiDi.Session
( SubscriptionId (..),
SessionSubscibe (..),
SessionUnsubscribe (..),
SessionNewResult (..),
SessionStatusResult (..),
SessionSubscribeResult (..),
)
where
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), object, withObject, (.:), (.=))
import Data.Aeson.Types (Parser)
import Data.Text (Text)
import GHC.Generics (Generic)
import WebDriverPreCore.BiDi.Capabilities (CapabilitiesResult)
import WebDriverPreCore.BiDi.CoreTypes (BrowsingContext, UserContext, SubscriptionType)
import AesonUtils (toJSONOmitNothing)
newtype SubscriptionId = MkSubscriptionId {SubscriptionId -> Text
subscriptionId :: Text}
deriving newtype (Int -> SubscriptionId -> ShowS
[SubscriptionId] -> ShowS
SubscriptionId -> String
(Int -> SubscriptionId -> ShowS)
-> (SubscriptionId -> String)
-> ([SubscriptionId] -> ShowS)
-> Show SubscriptionId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubscriptionId -> ShowS
showsPrec :: Int -> SubscriptionId -> ShowS
$cshow :: SubscriptionId -> String
show :: SubscriptionId -> String
$cshowList :: [SubscriptionId] -> ShowS
showList :: [SubscriptionId] -> ShowS
Show, SubscriptionId -> SubscriptionId -> Bool
(SubscriptionId -> SubscriptionId -> Bool)
-> (SubscriptionId -> SubscriptionId -> Bool) -> Eq SubscriptionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubscriptionId -> SubscriptionId -> Bool
== :: SubscriptionId -> SubscriptionId -> Bool
$c/= :: SubscriptionId -> SubscriptionId -> Bool
/= :: SubscriptionId -> SubscriptionId -> Bool
Eq, Maybe SubscriptionId
Value -> Parser [SubscriptionId]
Value -> Parser SubscriptionId
(Value -> Parser SubscriptionId)
-> (Value -> Parser [SubscriptionId])
-> Maybe SubscriptionId
-> FromJSON SubscriptionId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser SubscriptionId
parseJSON :: Value -> Parser SubscriptionId
$cparseJSONList :: Value -> Parser [SubscriptionId]
parseJSONList :: Value -> Parser [SubscriptionId]
$comittedField :: Maybe SubscriptionId
omittedField :: Maybe SubscriptionId
FromJSON, [SubscriptionId] -> Value
[SubscriptionId] -> Encoding
SubscriptionId -> Bool
SubscriptionId -> Value
SubscriptionId -> Encoding
(SubscriptionId -> Value)
-> (SubscriptionId -> Encoding)
-> ([SubscriptionId] -> Value)
-> ([SubscriptionId] -> Encoding)
-> (SubscriptionId -> Bool)
-> ToJSON SubscriptionId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: SubscriptionId -> Value
toJSON :: SubscriptionId -> Value
$ctoEncoding :: SubscriptionId -> Encoding
toEncoding :: SubscriptionId -> Encoding
$ctoJSONList :: [SubscriptionId] -> Value
toJSONList :: [SubscriptionId] -> Value
$ctoEncodingList :: [SubscriptionId] -> Encoding
toEncodingList :: [SubscriptionId] -> Encoding
$comitField :: SubscriptionId -> Bool
omitField :: SubscriptionId -> Bool
ToJSON)
data SessionSubscibe = MkSessionSubscribe
{ SessionSubscibe -> [SubscriptionType]
events :: [SubscriptionType],
SessionSubscibe -> Maybe [BrowsingContext]
contexts :: Maybe [BrowsingContext],
SessionSubscibe -> Maybe [UserContext]
userContexts :: Maybe [UserContext]
}
deriving (Int -> SessionSubscibe -> ShowS
[SessionSubscibe] -> ShowS
SessionSubscibe -> String
(Int -> SessionSubscibe -> ShowS)
-> (SessionSubscibe -> String)
-> ([SessionSubscibe] -> ShowS)
-> Show SessionSubscibe
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionSubscibe -> ShowS
showsPrec :: Int -> SessionSubscibe -> ShowS
$cshow :: SessionSubscibe -> String
show :: SessionSubscibe -> String
$cshowList :: [SessionSubscibe] -> ShowS
showList :: [SessionSubscibe] -> ShowS
Show, SessionSubscibe -> SessionSubscibe -> Bool
(SessionSubscibe -> SessionSubscibe -> Bool)
-> (SessionSubscibe -> SessionSubscibe -> Bool)
-> Eq SessionSubscibe
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionSubscibe -> SessionSubscibe -> Bool
== :: SessionSubscibe -> SessionSubscibe -> Bool
$c/= :: SessionSubscibe -> SessionSubscibe -> Bool
/= :: SessionSubscibe -> SessionSubscibe -> Bool
Eq, (forall x. SessionSubscibe -> Rep SessionSubscibe x)
-> (forall x. Rep SessionSubscibe x -> SessionSubscibe)
-> Generic SessionSubscibe
forall x. Rep SessionSubscibe x -> SessionSubscibe
forall x. SessionSubscibe -> Rep SessionSubscibe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SessionSubscibe -> Rep SessionSubscibe x
from :: forall x. SessionSubscibe -> Rep SessionSubscibe x
$cto :: forall x. Rep SessionSubscibe x -> SessionSubscibe
to :: forall x. Rep SessionSubscibe x -> SessionSubscibe
Generic)
instance ToJSON SessionSubscibe where
toJSON :: SessionSubscibe -> Value
toJSON :: SessionSubscibe -> Value
toJSON = SessionSubscibe -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing
data SessionUnsubscribe
= UnsubscribeById
{SessionUnsubscribe -> [SubscriptionId]
subscriptions :: [SubscriptionId]}
| UnsubscribeByAttributes
{ SessionUnsubscribe -> [SubscriptionType]
unsubEvents :: [SubscriptionType]
}
deriving (Int -> SessionUnsubscribe -> ShowS
[SessionUnsubscribe] -> ShowS
SessionUnsubscribe -> String
(Int -> SessionUnsubscribe -> ShowS)
-> (SessionUnsubscribe -> String)
-> ([SessionUnsubscribe] -> ShowS)
-> Show SessionUnsubscribe
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionUnsubscribe -> ShowS
showsPrec :: Int -> SessionUnsubscribe -> ShowS
$cshow :: SessionUnsubscribe -> String
show :: SessionUnsubscribe -> String
$cshowList :: [SessionUnsubscribe] -> ShowS
showList :: [SessionUnsubscribe] -> ShowS
Show, SessionUnsubscribe -> SessionUnsubscribe -> Bool
(SessionUnsubscribe -> SessionUnsubscribe -> Bool)
-> (SessionUnsubscribe -> SessionUnsubscribe -> Bool)
-> Eq SessionUnsubscribe
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionUnsubscribe -> SessionUnsubscribe -> Bool
== :: SessionUnsubscribe -> SessionUnsubscribe -> Bool
$c/= :: SessionUnsubscribe -> SessionUnsubscribe -> Bool
/= :: SessionUnsubscribe -> SessionUnsubscribe -> Bool
Eq, (forall x. SessionUnsubscribe -> Rep SessionUnsubscribe x)
-> (forall x. Rep SessionUnsubscribe x -> SessionUnsubscribe)
-> Generic SessionUnsubscribe
forall x. Rep SessionUnsubscribe x -> SessionUnsubscribe
forall x. SessionUnsubscribe -> Rep SessionUnsubscribe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SessionUnsubscribe -> Rep SessionUnsubscribe x
from :: forall x. SessionUnsubscribe -> Rep SessionUnsubscribe x
$cto :: forall x. Rep SessionUnsubscribe x -> SessionUnsubscribe
to :: forall x. Rep SessionUnsubscribe x -> SessionUnsubscribe
Generic)
instance ToJSON SessionUnsubscribe where
toJSON :: SessionUnsubscribe -> Value
toJSON :: SessionUnsubscribe -> Value
toJSON (UnsubscribeById {[SubscriptionId]
subscriptions :: SessionUnsubscribe -> [SubscriptionId]
subscriptions :: [SubscriptionId]
subscriptions}) =
[Pair] -> Value
object [Key
"subscriptions" Key -> [SubscriptionId] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [SubscriptionId]
subscriptions]
toJSON (UnsubscribeByAttributes {[SubscriptionType]
unsubEvents :: SessionUnsubscribe -> [SubscriptionType]
unsubEvents :: [SubscriptionType]
unsubEvents}) =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[Key
"events" Key -> [SubscriptionType] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [SubscriptionType]
unsubEvents]
data SessionNewResult = MkSessionNewResult
{ SessionNewResult -> Text
sessionId :: Text,
SessionNewResult -> CapabilitiesResult
capabilities :: CapabilitiesResult
}
deriving (Int -> SessionNewResult -> ShowS
[SessionNewResult] -> ShowS
SessionNewResult -> String
(Int -> SessionNewResult -> ShowS)
-> (SessionNewResult -> String)
-> ([SessionNewResult] -> ShowS)
-> Show SessionNewResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionNewResult -> ShowS
showsPrec :: Int -> SessionNewResult -> ShowS
$cshow :: SessionNewResult -> String
show :: SessionNewResult -> String
$cshowList :: [SessionNewResult] -> ShowS
showList :: [SessionNewResult] -> ShowS
Show, SessionNewResult -> SessionNewResult -> Bool
(SessionNewResult -> SessionNewResult -> Bool)
-> (SessionNewResult -> SessionNewResult -> Bool)
-> Eq SessionNewResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionNewResult -> SessionNewResult -> Bool
== :: SessionNewResult -> SessionNewResult -> Bool
$c/= :: SessionNewResult -> SessionNewResult -> Bool
/= :: SessionNewResult -> SessionNewResult -> Bool
Eq, (forall x. SessionNewResult -> Rep SessionNewResult x)
-> (forall x. Rep SessionNewResult x -> SessionNewResult)
-> Generic SessionNewResult
forall x. Rep SessionNewResult x -> SessionNewResult
forall x. SessionNewResult -> Rep SessionNewResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SessionNewResult -> Rep SessionNewResult x
from :: forall x. SessionNewResult -> Rep SessionNewResult x
$cto :: forall x. Rep SessionNewResult x -> SessionNewResult
to :: forall x. Rep SessionNewResult x -> SessionNewResult
Generic)
instance ToJSON SessionNewResult where
toJSON :: SessionNewResult -> Value
toJSON :: SessionNewResult -> Value
toJSON (MkSessionNewResult Text
sessionId CapabilitiesResult
capabilities) =
[Pair] -> Value
object
[ Key
"sessionId" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
sessionId,
Key
"capabilities" Key -> CapabilitiesResult -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= CapabilitiesResult
capabilities
]
instance FromJSON SessionNewResult where
parseJSON :: Value -> Parser SessionNewResult
parseJSON :: Value -> Parser SessionNewResult
parseJSON = String
-> (Object -> Parser SessionNewResult)
-> Value
-> Parser SessionNewResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SessionNewResult" ((Object -> Parser SessionNewResult)
-> Value -> Parser SessionNewResult)
-> (Object -> Parser SessionNewResult)
-> Value
-> Parser SessionNewResult
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text -> CapabilitiesResult -> SessionNewResult
MkSessionNewResult
(Text -> CapabilitiesResult -> SessionNewResult)
-> Parser Text -> Parser (CapabilitiesResult -> SessionNewResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"sessionId"
Parser (CapabilitiesResult -> SessionNewResult)
-> Parser CapabilitiesResult -> Parser SessionNewResult
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser CapabilitiesResult
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"capabilities"
data SessionStatusResult = MkSessionStatusResult
{ SessionStatusResult -> Bool
ready :: Bool,
SessionStatusResult -> Text
message :: Text
}
deriving (Int -> SessionStatusResult -> ShowS
[SessionStatusResult] -> ShowS
SessionStatusResult -> String
(Int -> SessionStatusResult -> ShowS)
-> (SessionStatusResult -> String)
-> ([SessionStatusResult] -> ShowS)
-> Show SessionStatusResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionStatusResult -> ShowS
showsPrec :: Int -> SessionStatusResult -> ShowS
$cshow :: SessionStatusResult -> String
show :: SessionStatusResult -> String
$cshowList :: [SessionStatusResult] -> ShowS
showList :: [SessionStatusResult] -> ShowS
Show, SessionStatusResult -> SessionStatusResult -> Bool
(SessionStatusResult -> SessionStatusResult -> Bool)
-> (SessionStatusResult -> SessionStatusResult -> Bool)
-> Eq SessionStatusResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionStatusResult -> SessionStatusResult -> Bool
== :: SessionStatusResult -> SessionStatusResult -> Bool
$c/= :: SessionStatusResult -> SessionStatusResult -> Bool
/= :: SessionStatusResult -> SessionStatusResult -> Bool
Eq, (forall x. SessionStatusResult -> Rep SessionStatusResult x)
-> (forall x. Rep SessionStatusResult x -> SessionStatusResult)
-> Generic SessionStatusResult
forall x. Rep SessionStatusResult x -> SessionStatusResult
forall x. SessionStatusResult -> Rep SessionStatusResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SessionStatusResult -> Rep SessionStatusResult x
from :: forall x. SessionStatusResult -> Rep SessionStatusResult x
$cto :: forall x. Rep SessionStatusResult x -> SessionStatusResult
to :: forall x. Rep SessionStatusResult x -> SessionStatusResult
Generic)
instance FromJSON SessionStatusResult
newtype SessionSubscribeResult = MkSessionSubscribeResult
{ SessionSubscribeResult -> SubscriptionId
subscription :: SubscriptionId
}
deriving (Int -> SessionSubscribeResult -> ShowS
[SessionSubscribeResult] -> ShowS
SessionSubscribeResult -> String
(Int -> SessionSubscribeResult -> ShowS)
-> (SessionSubscribeResult -> String)
-> ([SessionSubscribeResult] -> ShowS)
-> Show SessionSubscribeResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionSubscribeResult -> ShowS
showsPrec :: Int -> SessionSubscribeResult -> ShowS
$cshow :: SessionSubscribeResult -> String
show :: SessionSubscribeResult -> String
$cshowList :: [SessionSubscribeResult] -> ShowS
showList :: [SessionSubscribeResult] -> ShowS
Show, SessionSubscribeResult -> SessionSubscribeResult -> Bool
(SessionSubscribeResult -> SessionSubscribeResult -> Bool)
-> (SessionSubscribeResult -> SessionSubscribeResult -> Bool)
-> Eq SessionSubscribeResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionSubscribeResult -> SessionSubscribeResult -> Bool
== :: SessionSubscribeResult -> SessionSubscribeResult -> Bool
$c/= :: SessionSubscribeResult -> SessionSubscribeResult -> Bool
/= :: SessionSubscribeResult -> SessionSubscribeResult -> Bool
Eq, (forall x. SessionSubscribeResult -> Rep SessionSubscribeResult x)
-> (forall x.
Rep SessionSubscribeResult x -> SessionSubscribeResult)
-> Generic SessionSubscribeResult
forall x. Rep SessionSubscribeResult x -> SessionSubscribeResult
forall x. SessionSubscribeResult -> Rep SessionSubscribeResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SessionSubscribeResult -> Rep SessionSubscribeResult x
from :: forall x. SessionSubscribeResult -> Rep SessionSubscribeResult x
$cto :: forall x. Rep SessionSubscribeResult x -> SessionSubscribeResult
to :: forall x. Rep SessionSubscribeResult x -> SessionSubscribeResult
Generic)
instance FromJSON SessionSubscribeResult