{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Database.Bolt.Connection.Type where

import           Database.Bolt.Value.Type hiding (unpack)

import           Control.DeepSeq                 (NFData(..), rwhnf)
import           Control.Exception               (Exception (..), SomeException, handle)
import           Control.Monad.Trans             (MonadTrans (..), MonadIO (..))
import           Control.Monad.Reader            (MonadReader (..), ReaderT)
import           Control.Monad.Except            (MonadError (..), ExceptT (..))

import           Data.Default                    (Default (..))
import           Data.Map.Strict                 (Map)
import           Data.Monoid                     ()
import           Data.Text                       (Text, unpack)
import           Data.Word                       (Word16, Word32)
import           GHC.Stack                       (HasCallStack, callStack, prettyCallStack)
import           Network.Connection              (Connection)


-- |Error obtained from BOLT server
data ResponseError = KnownResponseFailure Text Text
                   | UnknownResponseFailure
  deriving (ResponseError -> ResponseError -> Bool
(ResponseError -> ResponseError -> Bool)
-> (ResponseError -> ResponseError -> Bool) -> Eq ResponseError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResponseError -> ResponseError -> Bool
$c/= :: ResponseError -> ResponseError -> Bool
== :: ResponseError -> ResponseError -> Bool
$c== :: ResponseError -> ResponseError -> Bool
Eq, Eq ResponseError
Eq ResponseError
-> (ResponseError -> ResponseError -> Ordering)
-> (ResponseError -> ResponseError -> Bool)
-> (ResponseError -> ResponseError -> Bool)
-> (ResponseError -> ResponseError -> Bool)
-> (ResponseError -> ResponseError -> Bool)
-> (ResponseError -> ResponseError -> ResponseError)
-> (ResponseError -> ResponseError -> ResponseError)
-> Ord ResponseError
ResponseError -> ResponseError -> Bool
ResponseError -> ResponseError -> Ordering
ResponseError -> ResponseError -> ResponseError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResponseError -> ResponseError -> ResponseError
$cmin :: ResponseError -> ResponseError -> ResponseError
max :: ResponseError -> ResponseError -> ResponseError
$cmax :: ResponseError -> ResponseError -> ResponseError
>= :: ResponseError -> ResponseError -> Bool
$c>= :: ResponseError -> ResponseError -> Bool
> :: ResponseError -> ResponseError -> Bool
$c> :: ResponseError -> ResponseError -> Bool
<= :: ResponseError -> ResponseError -> Bool
$c<= :: ResponseError -> ResponseError -> Bool
< :: ResponseError -> ResponseError -> Bool
$c< :: ResponseError -> ResponseError -> Bool
compare :: ResponseError -> ResponseError -> Ordering
$ccompare :: ResponseError -> ResponseError -> Ordering
$cp1Ord :: Eq ResponseError
Ord)

instance Show ResponseError where
  show :: ResponseError -> String
show (KnownResponseFailure Text
tpe Text
msg) = Text -> String
unpack Text
tpe String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
": " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
unpack Text
msg
  show ResponseError
UnknownResponseFailure         = String
"Unknown response error"

-- |Error that can appear during 'BoltActionT' manipulations
data BoltError = UnsupportedServerVersion
               | AuthentificationFailed
               | ResetFailed
               | CannotReadChunk
               | WrongMessageFormat UnpackError
               | NoStructureInResponse
               | ResponseError ResponseError
               | RecordHasNoKey Text
               | NonHasboltError SomeException
               | HasCallStack => TimeOut

instance Show BoltError where
  show :: BoltError -> String
show BoltError
UnsupportedServerVersion = String
"Cannot connect: unsupported server version"
  show BoltError
AuthentificationFailed   = String
"Cannot connect: authentification failed"
  show BoltError
ResetFailed              = String
"Cannot reset current pipe: recieved failure from server"
  show BoltError
CannotReadChunk          = String
"Cannot fetch: chunk read failed"
  show (WrongMessageFormat UnpackError
msg) = String
"Cannot fetch: wrong message format (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> UnpackError -> String
forall a. Show a => a -> String
show UnpackError
msg String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
  show BoltError
NoStructureInResponse    = String
"Cannot fetch: no structure in response"
  show (ResponseError ResponseError
re)       = ResponseError -> String
forall a. Show a => a -> String
show ResponseError
re
  show (RecordHasNoKey Text
key)     = String
"Cannot unpack record: key '" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
unpack Text
key String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"' is not presented"
  show (NonHasboltError SomeException
msg)    = String
"User error: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> SomeException -> String
forall a. Show a => a -> String
show SomeException
msg
  show BoltError
TimeOut                  = String
"Operation timeout\n" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> CallStack -> String
prettyCallStack CallStack
HasCallStack => CallStack
callStack

instance Exception BoltError

-- |Monad Transformer to do all BOLT actions in
newtype BoltActionT m a = BoltActionT { BoltActionT m a -> ReaderT Pipe (ExceptT BoltError m) a
runBoltActionT :: ReaderT Pipe (ExceptT BoltError m) a }
  deriving (a -> BoltActionT m b -> BoltActionT m a
(a -> b) -> BoltActionT m a -> BoltActionT m b
(forall a b. (a -> b) -> BoltActionT m a -> BoltActionT m b)
-> (forall a b. a -> BoltActionT m b -> BoltActionT m a)
-> Functor (BoltActionT m)
forall a b. a -> BoltActionT m b -> BoltActionT m a
forall a b. (a -> b) -> BoltActionT m a -> BoltActionT m b
forall (m :: * -> *) a b.
Functor m =>
a -> BoltActionT m b -> BoltActionT m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> BoltActionT m a -> BoltActionT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> BoltActionT m b -> BoltActionT m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> BoltActionT m b -> BoltActionT m a
fmap :: (a -> b) -> BoltActionT m a -> BoltActionT m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> BoltActionT m a -> BoltActionT m b
Functor, Functor (BoltActionT m)
a -> BoltActionT m a
Functor (BoltActionT m)
-> (forall a. a -> BoltActionT m a)
-> (forall a b.
    BoltActionT m (a -> b) -> BoltActionT m a -> BoltActionT m b)
-> (forall a b c.
    (a -> b -> c)
    -> BoltActionT m a -> BoltActionT m b -> BoltActionT m c)
-> (forall a b.
    BoltActionT m a -> BoltActionT m b -> BoltActionT m b)
-> (forall a b.
    BoltActionT m a -> BoltActionT m b -> BoltActionT m a)
-> Applicative (BoltActionT m)
BoltActionT m a -> BoltActionT m b -> BoltActionT m b
BoltActionT m a -> BoltActionT m b -> BoltActionT m a
BoltActionT m (a -> b) -> BoltActionT m a -> BoltActionT m b
(a -> b -> c)
-> BoltActionT m a -> BoltActionT m b -> BoltActionT m c
forall a. a -> BoltActionT m a
forall a b. BoltActionT m a -> BoltActionT m b -> BoltActionT m a
forall a b. BoltActionT m a -> BoltActionT m b -> BoltActionT m b
forall a b.
BoltActionT m (a -> b) -> BoltActionT m a -> BoltActionT m b
forall a b c.
(a -> b -> c)
-> BoltActionT m a -> BoltActionT m b -> BoltActionT m c
forall (m :: * -> *). Monad m => Functor (BoltActionT m)
forall (m :: * -> *) a. Monad m => a -> BoltActionT m a
forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> BoltActionT m b -> BoltActionT m a
forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> BoltActionT m b -> BoltActionT m b
forall (m :: * -> *) a b.
Monad m =>
BoltActionT m (a -> b) -> BoltActionT m a -> BoltActionT m b
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> BoltActionT m a -> BoltActionT m b -> BoltActionT m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: BoltActionT m a -> BoltActionT m b -> BoltActionT m a
$c<* :: forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> BoltActionT m b -> BoltActionT m a
*> :: BoltActionT m a -> BoltActionT m b -> BoltActionT m b
$c*> :: forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> BoltActionT m b -> BoltActionT m b
liftA2 :: (a -> b -> c)
-> BoltActionT m a -> BoltActionT m b -> BoltActionT m c
$cliftA2 :: forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> BoltActionT m a -> BoltActionT m b -> BoltActionT m c
<*> :: BoltActionT m (a -> b) -> BoltActionT m a -> BoltActionT m b
$c<*> :: forall (m :: * -> *) a b.
Monad m =>
BoltActionT m (a -> b) -> BoltActionT m a -> BoltActionT m b
pure :: a -> BoltActionT m a
$cpure :: forall (m :: * -> *) a. Monad m => a -> BoltActionT m a
$cp1Applicative :: forall (m :: * -> *). Monad m => Functor (BoltActionT m)
Applicative, Applicative (BoltActionT m)
a -> BoltActionT m a
Applicative (BoltActionT m)
-> (forall a b.
    BoltActionT m a -> (a -> BoltActionT m b) -> BoltActionT m b)
-> (forall a b.
    BoltActionT m a -> BoltActionT m b -> BoltActionT m b)
-> (forall a. a -> BoltActionT m a)
-> Monad (BoltActionT m)
BoltActionT m a -> (a -> BoltActionT m b) -> BoltActionT m b
BoltActionT m a -> BoltActionT m b -> BoltActionT m b
forall a. a -> BoltActionT m a
forall a b. BoltActionT m a -> BoltActionT m b -> BoltActionT m b
forall a b.
BoltActionT m a -> (a -> BoltActionT m b) -> BoltActionT m b
forall (m :: * -> *). Monad m => Applicative (BoltActionT m)
forall (m :: * -> *) a. Monad m => a -> BoltActionT m a
forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> BoltActionT m b -> BoltActionT m b
forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> (a -> BoltActionT m b) -> BoltActionT m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> BoltActionT m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> BoltActionT m a
>> :: BoltActionT m a -> BoltActionT m b -> BoltActionT m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> BoltActionT m b -> BoltActionT m b
>>= :: BoltActionT m a -> (a -> BoltActionT m b) -> BoltActionT m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
BoltActionT m a -> (a -> BoltActionT m b) -> BoltActionT m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (BoltActionT m)
Monad, MonadError BoltError, MonadReader Pipe)

instance MonadTrans BoltActionT where
  lift :: m a -> BoltActionT m a
lift = ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a
forall (m :: * -> *) a.
ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a
BoltActionT (ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a)
-> (m a -> ReaderT Pipe (ExceptT BoltError m) a)
-> m a
-> BoltActionT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT BoltError m a -> ReaderT Pipe (ExceptT BoltError m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ExceptT BoltError m a -> ReaderT Pipe (ExceptT BoltError m) a)
-> (m a -> ExceptT BoltError m a)
-> m a
-> ReaderT Pipe (ExceptT BoltError m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> ExceptT BoltError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift

instance MonadIO m => MonadIO (BoltActionT m) where
  liftIO :: IO a -> BoltActionT m a
liftIO = ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a
forall (m :: * -> *) a.
ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a
BoltActionT (ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a)
-> (IO a -> ReaderT Pipe (ExceptT BoltError m) a)
-> IO a
-> BoltActionT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT BoltError m a -> ReaderT Pipe (ExceptT BoltError m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ExceptT BoltError m a -> ReaderT Pipe (ExceptT BoltError m) a)
-> (IO a -> ExceptT BoltError m a)
-> IO a
-> ReaderT Pipe (ExceptT BoltError m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either BoltError a) -> ExceptT BoltError m a
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (m (Either BoltError a) -> ExceptT BoltError m a)
-> (IO a -> m (Either BoltError a))
-> IO a
-> ExceptT BoltError m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either BoltError a) -> m (Either BoltError a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either BoltError a) -> m (Either BoltError a))
-> (IO a -> IO (Either BoltError a))
-> IO a
-> m (Either BoltError a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SomeException -> IO (Either BoltError a))
-> IO (Either BoltError a) -> IO (Either BoltError a)
forall e a. Exception e => (e -> IO a) -> IO a -> IO a
handle (Either BoltError a -> IO (Either BoltError a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either BoltError a -> IO (Either BoltError a))
-> (SomeException -> Either BoltError a)
-> SomeException
-> IO (Either BoltError a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BoltError -> Either BoltError a
forall a b. a -> Either a b
Left (BoltError -> Either BoltError a)
-> (SomeException -> BoltError)
-> SomeException
-> Either BoltError a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeException -> BoltError
NonHasboltError) (IO (Either BoltError a) -> IO (Either BoltError a))
-> (IO a -> IO (Either BoltError a))
-> IO a
-> IO (Either BoltError a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Either BoltError a) -> IO a -> IO (Either BoltError a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Either BoltError a
forall a b. b -> Either a b
Right

liftE :: Monad m => ExceptT BoltError m a -> BoltActionT m a
liftE :: ExceptT BoltError m a -> BoltActionT m a
liftE = ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a
forall (m :: * -> *) a.
ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a
BoltActionT (ReaderT Pipe (ExceptT BoltError m) a -> BoltActionT m a)
-> (ExceptT BoltError m a -> ReaderT Pipe (ExceptT BoltError m) a)
-> ExceptT BoltError m a
-> BoltActionT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT BoltError m a -> ReaderT Pipe (ExceptT BoltError m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift

-- |Configuration of driver connection
data BoltCfg = BoltCfg { BoltCfg -> Word32
magic         :: Word32  -- ^'6060B017' value
                       , BoltCfg -> Word32
version       :: Word32  -- ^Major version number (e.g. '00000104' for 4.1)
                       , BoltCfg -> Text
userAgent     :: Text    -- ^Driver user agent
                       , BoltCfg -> Word16
maxChunkSize  :: Word16  -- ^Maximum chunk size of request
                       , BoltCfg -> Int
socketTimeout :: Int     -- ^Driver socket timeout in seconds
                       , BoltCfg -> String
host          :: String  -- ^Neo4j server hostname
                       , BoltCfg -> Int
port          :: Int     -- ^Neo4j server port
                       , BoltCfg -> Text
authType      :: Text    -- ^Neo4j auth schema
                       , BoltCfg -> Text
user          :: Text    -- ^Neo4j user
                       , BoltCfg -> Text
password      :: Text    -- ^Neo4j password
                       , BoltCfg -> Bool
secure        :: Bool    -- ^Use TLS or not
                       }
  deriving (BoltCfg -> BoltCfg -> Bool
(BoltCfg -> BoltCfg -> Bool)
-> (BoltCfg -> BoltCfg -> Bool) -> Eq BoltCfg
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoltCfg -> BoltCfg -> Bool
$c/= :: BoltCfg -> BoltCfg -> Bool
== :: BoltCfg -> BoltCfg -> Bool
$c== :: BoltCfg -> BoltCfg -> Bool
Eq, Int -> BoltCfg -> ShowS
[BoltCfg] -> ShowS
BoltCfg -> String
(Int -> BoltCfg -> ShowS)
-> (BoltCfg -> String) -> ([BoltCfg] -> ShowS) -> Show BoltCfg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoltCfg] -> ShowS
$cshowList :: [BoltCfg] -> ShowS
show :: BoltCfg -> String
$cshow :: BoltCfg -> String
showsPrec :: Int -> BoltCfg -> ShowS
$cshowsPrec :: Int -> BoltCfg -> ShowS
Show, ReadPrec [BoltCfg]
ReadPrec BoltCfg
Int -> ReadS BoltCfg
ReadS [BoltCfg]
(Int -> ReadS BoltCfg)
-> ReadS [BoltCfg]
-> ReadPrec BoltCfg
-> ReadPrec [BoltCfg]
-> Read BoltCfg
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BoltCfg]
$creadListPrec :: ReadPrec [BoltCfg]
readPrec :: ReadPrec BoltCfg
$creadPrec :: ReadPrec BoltCfg
readList :: ReadS [BoltCfg]
$creadList :: ReadS [BoltCfg]
readsPrec :: Int -> ReadS BoltCfg
$creadsPrec :: Int -> ReadS BoltCfg
Read)

instance Default BoltCfg where
  def :: BoltCfg
def = BoltCfg :: Word32
-> Word32
-> Text
-> Word16
-> Int
-> String
-> Int
-> Text
-> Text
-> Text
-> Bool
-> BoltCfg
BoltCfg { magic :: Word32
magic         = Word32
1616949271
                , version :: Word32
version       = Word32
3
                , userAgent :: Text
userAgent     = Text
"hasbolt/1.5"
                , maxChunkSize :: Word16
maxChunkSize  = Word16
65535
                , socketTimeout :: Int
socketTimeout = Int
5
                , host :: String
host          = String
"127.0.0.1"
                , port :: Int
port          = Int
7687
                , authType :: Text
authType      = Text
"basic"
                , user :: Text
user          = Text
""
                , password :: Text
password      = Text
""
                , secure :: Bool
secure        = Bool
False
                }

data ConnectionWithTimeout
  = ConnectionWithTimeout
      { ConnectionWithTimeout -> Connection
cwtConnection  :: !Connection
      , ConnectionWithTimeout -> Int
cwtTimeoutUsec :: !Int
        -- ^ Timeout in microseconds
      }

data Pipe = Pipe { Pipe -> ConnectionWithTimeout
connection   :: ConnectionWithTimeout -- ^Driver connection socket
                 , Pipe -> Word16
mcs          :: Word16                -- ^Driver maximum chunk size of request
                 , Pipe -> Word32
pipe_version :: Word32                -- ^Connection version 0000mnMJ
                 }

instance NFData Pipe where
  rnf :: Pipe -> ()
rnf = Pipe -> ()
forall a. a -> ()
rwhnf

data AuthToken = AuthToken { AuthToken -> Text
scheme      :: Text
                           , AuthToken -> Text
principal   :: Text
                           , AuthToken -> Text
credentials :: Text
                           }
  deriving (AuthToken -> AuthToken -> Bool
(AuthToken -> AuthToken -> Bool)
-> (AuthToken -> AuthToken -> Bool) -> Eq AuthToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthToken -> AuthToken -> Bool
$c/= :: AuthToken -> AuthToken -> Bool
== :: AuthToken -> AuthToken -> Bool
$c== :: AuthToken -> AuthToken -> Bool
Eq, Int -> AuthToken -> ShowS
[AuthToken] -> ShowS
AuthToken -> String
(Int -> AuthToken -> ShowS)
-> (AuthToken -> String)
-> ([AuthToken] -> ShowS)
-> Show AuthToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthToken] -> ShowS
$cshowList :: [AuthToken] -> ShowS
show :: AuthToken -> String
$cshow :: AuthToken -> String
showsPrec :: Int -> AuthToken -> ShowS
$cshowsPrec :: Int -> AuthToken -> ShowS
Show)

data Response = ResponseSuccess { Response -> Map Text Value
succMap   :: Map Text Value }
              | ResponseRecord  { Response -> [Value]
recsList  :: [Value] }
              | ResponseIgnored { Response -> Map Text Value
ignoreMap :: Map Text Value }
              | ResponseFailure { Response -> Map Text Value
failMap   :: Map Text Value }
  deriving (Response -> Response -> Bool
(Response -> Response -> Bool)
-> (Response -> Response -> Bool) -> Eq Response
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Response -> Response -> Bool
$c/= :: Response -> Response -> Bool
== :: Response -> Response -> Bool
$c== :: Response -> Response -> Bool
Eq, Int -> Response -> ShowS
[Response] -> ShowS
Response -> String
(Int -> Response -> ShowS)
-> (Response -> String) -> ([Response] -> ShowS) -> Show Response
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Response] -> ShowS
$cshowList :: [Response] -> ShowS
show :: Response -> String
$cshow :: Response -> String
showsPrec :: Int -> Response -> ShowS
$cshowsPrec :: Int -> Response -> ShowS
Show)

data Request = RequestInit  { Request -> Text
agent   :: Text
                            , Request -> AuthToken
token   :: AuthToken
                            , Request -> Bool
isHello :: Bool
                            }
             | RequestRun   { Request -> Text
statement  :: Text
                            , Request -> Map Text Value
parameters :: Map Text Value
                            }
             | RequestRunV3 { statement  :: Text
                            , parameters :: Map Text Value
                            , Request -> Map Text Value
extra      :: Map Text Value
                            }
             | RequestAckFailure
             | RequestReset
             | RequestDiscardAll
             | RequestPullAll
             | RequestGoodbye
  deriving (Request -> Request -> Bool
(Request -> Request -> Bool)
-> (Request -> Request -> Bool) -> Eq Request
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Request -> Request -> Bool
$c/= :: Request -> Request -> Bool
== :: Request -> Request -> Bool
$c== :: Request -> Request -> Bool
Eq, Int -> Request -> ShowS
[Request] -> ShowS
Request -> String
(Int -> Request -> ShowS)
-> (Request -> String) -> ([Request] -> ShowS) -> Show Request
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Request] -> ShowS
$cshowList :: [Request] -> ShowS
show :: Request -> String
$cshow :: Request -> String
showsPrec :: Int -> Request -> ShowS
$cshowsPrec :: Int -> Request -> ShowS
Show)