{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE LambdaCase #-}
module MatrixBot.SharedTypes where
import Control.Lens (Lens')
import Data.Aeson
import Data.Aeson.Types (Parser, typeMismatch)
import Data.Proxy
import Data.String (IsString (..))
import Data.Text (Text)
import Data.Typeable
import Data.UUID (UUID)
import Data.UUID.V4 (nextRandom)
import Numeric.Natural
import Text.Printf (printf)
import qualified Data.Attoparsec.Text as AP
import Control.Monad.IO.Class
import Servant.API
import Control.Applicative ((<|>))
newtype Username = Username { Username -> Text
unUsername ∷ Text }
deriving stock (Username -> Username -> Bool
(Username -> Username -> Bool)
-> (Username -> Username -> Bool) -> Eq Username
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Username -> Username -> Bool
== :: Username -> Username -> Bool
$c/= :: Username -> Username -> Bool
/= :: Username -> Username -> Bool
Eq, Int -> Username -> ShowS
[Username] -> ShowS
Username -> String
(Int -> Username -> ShowS)
-> (Username -> String) -> ([Username] -> ShowS) -> Show Username
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Username -> ShowS
showsPrec :: Int -> Username -> ShowS
$cshow :: Username -> String
show :: Username -> String
$cshowList :: [Username] -> ShowS
showList :: [Username] -> ShowS
Show)
deriving newtype ([Username] -> Encoding
[Username] -> Value
Username -> Bool
Username -> Encoding
Username -> Value
(Username -> Value)
-> (Username -> Encoding)
-> ([Username] -> Value)
-> ([Username] -> Encoding)
-> (Username -> Bool)
-> ToJSON Username
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Username -> Value
toJSON :: Username -> Value
$ctoEncoding :: Username -> Encoding
toEncoding :: Username -> Encoding
$ctoJSONList :: [Username] -> Value
toJSONList :: [Username] -> Value
$ctoEncodingList :: [Username] -> Encoding
toEncodingList :: [Username] -> Encoding
$comitField :: Username -> Bool
omitField :: Username -> Bool
ToJSON, Maybe Username
Value -> Parser [Username]
Value -> Parser Username
(Value -> Parser Username)
-> (Value -> Parser [Username])
-> Maybe Username
-> FromJSON Username
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Username
parseJSON :: Value -> Parser Username
$cparseJSONList :: Value -> Parser [Username]
parseJSONList :: Value -> Parser [Username]
$comittedField :: Maybe Username
omittedField :: Maybe Username
FromJSON)
newtype Password = Password { Password -> Text
unPassword ∷ Text }
deriving stock (Password -> Password -> Bool
(Password -> Password -> Bool)
-> (Password -> Password -> Bool) -> Eq Password
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Password -> Password -> Bool
== :: Password -> Password -> Bool
$c/= :: Password -> Password -> Bool
/= :: Password -> Password -> Bool
Eq, Int -> Password -> ShowS
[Password] -> ShowS
Password -> String
(Int -> Password -> ShowS)
-> (Password -> String) -> ([Password] -> ShowS) -> Show Password
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Password -> ShowS
showsPrec :: Int -> Password -> ShowS
$cshow :: Password -> String
show :: Password -> String
$cshowList :: [Password] -> ShowS
showList :: [Password] -> ShowS
Show)
deriving newtype ([Password] -> Encoding
[Password] -> Value
Password -> Bool
Password -> Encoding
Password -> Value
(Password -> Value)
-> (Password -> Encoding)
-> ([Password] -> Value)
-> ([Password] -> Encoding)
-> (Password -> Bool)
-> ToJSON Password
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Password -> Value
toJSON :: Password -> Value
$ctoEncoding :: Password -> Encoding
toEncoding :: Password -> Encoding
$ctoJSONList :: [Password] -> Value
toJSONList :: [Password] -> Value
$ctoEncodingList :: [Password] -> Encoding
toEncodingList :: [Password] -> Encoding
$comitField :: Password -> Bool
omitField :: Password -> Bool
ToJSON, Maybe Password
Value -> Parser [Password]
Value -> Parser Password
(Value -> Parser Password)
-> (Value -> Parser [Password])
-> Maybe Password
-> FromJSON Password
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Password
parseJSON :: Value -> Parser Password
$cparseJSONList :: Value -> Parser [Password]
parseJSONList :: Value -> Parser [Password]
$comittedField :: Maybe Password
omittedField :: Maybe Password
FromJSON)
newtype AccessToken = AccessToken { AccessToken -> Text
unAccessToken ∷ Text }
deriving stock (AccessToken -> AccessToken -> Bool
(AccessToken -> AccessToken -> Bool)
-> (AccessToken -> AccessToken -> Bool) -> Eq AccessToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AccessToken -> AccessToken -> Bool
== :: AccessToken -> AccessToken -> Bool
$c/= :: AccessToken -> AccessToken -> Bool
/= :: AccessToken -> AccessToken -> Bool
Eq, Int -> AccessToken -> ShowS
[AccessToken] -> ShowS
AccessToken -> String
(Int -> AccessToken -> ShowS)
-> (AccessToken -> String)
-> ([AccessToken] -> ShowS)
-> Show AccessToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AccessToken -> ShowS
showsPrec :: Int -> AccessToken -> ShowS
$cshow :: AccessToken -> String
show :: AccessToken -> String
$cshowList :: [AccessToken] -> ShowS
showList :: [AccessToken] -> ShowS
Show)
deriving newtype ([AccessToken] -> Encoding
[AccessToken] -> Value
AccessToken -> Bool
AccessToken -> Encoding
AccessToken -> Value
(AccessToken -> Value)
-> (AccessToken -> Encoding)
-> ([AccessToken] -> Value)
-> ([AccessToken] -> Encoding)
-> (AccessToken -> Bool)
-> ToJSON AccessToken
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: AccessToken -> Value
toJSON :: AccessToken -> Value
$ctoEncoding :: AccessToken -> Encoding
toEncoding :: AccessToken -> Encoding
$ctoJSONList :: [AccessToken] -> Value
toJSONList :: [AccessToken] -> Value
$ctoEncodingList :: [AccessToken] -> Encoding
toEncodingList :: [AccessToken] -> Encoding
$comitField :: AccessToken -> Bool
omitField :: AccessToken -> Bool
ToJSON, Maybe AccessToken
Value -> Parser [AccessToken]
Value -> Parser AccessToken
(Value -> Parser AccessToken)
-> (Value -> Parser [AccessToken])
-> Maybe AccessToken
-> FromJSON AccessToken
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser AccessToken
parseJSON :: Value -> Parser AccessToken
$cparseJSONList :: Value -> Parser [AccessToken]
parseJSONList :: Value -> Parser [AccessToken]
$comittedField :: Maybe AccessToken
omittedField :: Maybe AccessToken
FromJSON)
newtype HomeServer = HomeServer { HomeServer -> Text
unHomeServer ∷ Text }
deriving stock (HomeServer -> HomeServer -> Bool
(HomeServer -> HomeServer -> Bool)
-> (HomeServer -> HomeServer -> Bool) -> Eq HomeServer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HomeServer -> HomeServer -> Bool
== :: HomeServer -> HomeServer -> Bool
$c/= :: HomeServer -> HomeServer -> Bool
/= :: HomeServer -> HomeServer -> Bool
Eq, Int -> HomeServer -> ShowS
[HomeServer] -> ShowS
HomeServer -> String
(Int -> HomeServer -> ShowS)
-> (HomeServer -> String)
-> ([HomeServer] -> ShowS)
-> Show HomeServer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HomeServer -> ShowS
showsPrec :: Int -> HomeServer -> ShowS
$cshow :: HomeServer -> String
show :: HomeServer -> String
$cshowList :: [HomeServer] -> ShowS
showList :: [HomeServer] -> ShowS
Show)
deriving newtype ([HomeServer] -> Encoding
[HomeServer] -> Value
HomeServer -> Bool
HomeServer -> Encoding
HomeServer -> Value
(HomeServer -> Value)
-> (HomeServer -> Encoding)
-> ([HomeServer] -> Value)
-> ([HomeServer] -> Encoding)
-> (HomeServer -> Bool)
-> ToJSON HomeServer
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: HomeServer -> Value
toJSON :: HomeServer -> Value
$ctoEncoding :: HomeServer -> Encoding
toEncoding :: HomeServer -> Encoding
$ctoJSONList :: [HomeServer] -> Value
toJSONList :: [HomeServer] -> Value
$ctoEncodingList :: [HomeServer] -> Encoding
toEncodingList :: [HomeServer] -> Encoding
$comitField :: HomeServer -> Bool
omitField :: HomeServer -> Bool
ToJSON, Maybe HomeServer
Value -> Parser [HomeServer]
Value -> Parser HomeServer
(Value -> Parser HomeServer)
-> (Value -> Parser [HomeServer])
-> Maybe HomeServer
-> FromJSON HomeServer
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser HomeServer
parseJSON :: Value -> Parser HomeServer
$cparseJSONList :: Value -> Parser [HomeServer]
parseJSONList :: Value -> Parser [HomeServer]
$comittedField :: Maybe HomeServer
omittedField :: Maybe HomeServer
FromJSON)
data Mxid = Mxid
{ Mxid -> Username
mxidUsername ∷ Username
, Mxid -> HomeServer
mxidHomeServer ∷ HomeServer
}
deriving stock (Mxid -> Mxid -> Bool
(Mxid -> Mxid -> Bool) -> (Mxid -> Mxid -> Bool) -> Eq Mxid
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Mxid -> Mxid -> Bool
== :: Mxid -> Mxid -> Bool
$c/= :: Mxid -> Mxid -> Bool
/= :: Mxid -> Mxid -> Bool
Eq, Int -> Mxid -> ShowS
[Mxid] -> ShowS
Mxid -> String
(Int -> Mxid -> ShowS)
-> (Mxid -> String) -> ([Mxid] -> ShowS) -> Show Mxid
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Mxid -> ShowS
showsPrec :: Int -> Mxid -> ShowS
$cshow :: Mxid -> String
show :: Mxid -> String
$cshowList :: [Mxid] -> ShowS
showList :: [Mxid] -> ShowS
Show, Typeable)
instance ToJSON Mxid where
toJSON :: Mxid -> Value
toJSON = Text -> Value
String (Text -> Value) -> (Mxid -> Text) -> Mxid -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mxid -> Text
printMxid
instance FromJSON Mxid where
parseJSON ∷ ∀a. (a ~ Mxid) ⇒ Value → Parser a
parseJSON :: forall a. (a ~ Mxid) => Value -> Parser a
parseJSON Value
jsonInput =
case Value
jsonInput of
String Text
x → (String -> Parser a)
-> (a -> Parser a) -> Either String a -> Parser a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> Parser a
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail a -> Parser a
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either String a -> Parser a) -> Either String a -> Parser a
forall a b. (a -> b) -> a -> b
$ Parser a -> Text -> Either String a
forall a. Parser a -> Text -> Either String a
AP.parseOnly Parser a
Parser Mxid
mxidParser Text
x
Value
_ → Parser a
failure
where
failure :: Parser a
failure = String -> Value -> Parser a
forall a. String -> Value -> Parser a
typeMismatch String
typeName Value
jsonInput
typeName :: String
typeName = TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String) -> (Proxy a -> TypeRep) -> Proxy a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy a -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy a -> String) -> Proxy a -> String
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a
instance ToHttpApiData Mxid where
toUrlPiece :: Mxid -> Text
toUrlPiece = Mxid -> Text
printMxid
mxidParser ∷ AP.Parser Mxid
mxidParser :: Parser Mxid
mxidParser = Username -> HomeServer -> Mxid
Mxid
(Username -> HomeServer -> Mxid)
-> Parser Text Username -> Parser Text (HomeServer -> Mxid)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Username) -> Parser Text Text -> Parser Text Username
forall a b. (a -> b) -> Parser Text a -> Parser Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Username
Username (Parser Text Text
"@" Parser Text Text -> Parser Text Text -> Parser Text Text
forall a b. Parser Text a -> Parser Text b -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> Bool) -> Parser Text Text
AP.takeTill (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':') Parser Text Text -> (Text -> Parser Text Text) -> Parser Text Text
forall a b. Parser Text a -> (a -> Parser Text b) -> Parser Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Text -> Parser Text Text
forall {a} {f :: * -> *}.
(Eq a, Monoid a, MonadFail f) =>
String -> a -> f a
failOnEmpty String
"username")
Parser Text (HomeServer -> Mxid)
-> Parser Text HomeServer -> Parser Mxid
forall a b. Parser Text (a -> b) -> Parser Text a -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> HomeServer) -> Parser Text Text -> Parser Text HomeServer
forall a b. (a -> b) -> Parser Text a -> Parser Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> HomeServer
HomeServer (Parser Text Text
":" Parser Text Text -> Parser Text Text -> Parser Text Text
forall a b. Parser Text a -> Parser Text b -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text Text
AP.takeText Parser Text Text -> (Text -> Parser Text Text) -> Parser Text Text
forall a b. Parser Text a -> (a -> Parser Text b) -> Parser Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Text -> Parser Text Text
forall {a} {f :: * -> *}.
(Eq a, Monoid a, MonadFail f) =>
String -> a -> f a
failOnEmpty String
"home server")
Parser Mxid -> Parser Text () -> Parser Mxid
forall a b. Parser Text a -> Parser Text b -> Parser Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text ()
forall t. Chunk t => Parser t ()
AP.endOfInput
where
failOnEmpty :: String -> a -> f a
failOnEmpty String
name a
x
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
forall a. Monoid a => a
mempty = a -> f a
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
| Bool
otherwise = String -> f a
forall a. String -> f a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> f a) -> String -> f a
forall a b. (a -> b) -> a -> b
$ String
"Empty " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
name
printMxid ∷ Mxid → Text
printMxid :: Mxid -> Text
printMxid Mxid
mxid = [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"@", Username -> Text
unUsername (Username -> Text) -> (Mxid -> Username) -> Mxid -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mxid -> Username
mxidUsername (Mxid -> Text) -> Mxid -> Text
forall a b. (a -> b) -> a -> b
$ Mxid
mxid
, Text
":", HomeServer -> Text
unHomeServer (HomeServer -> Text) -> (Mxid -> HomeServer) -> Mxid -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mxid -> HomeServer
mxidHomeServer (Mxid -> Text) -> Mxid -> Text
forall a b. (a -> b) -> a -> b
$ Mxid
mxid
]
data RoomId
= LocatedRoomId Text HomeServer
| ServerlessRoomId Text
deriving stock (RoomId -> RoomId -> Bool
(RoomId -> RoomId -> Bool)
-> (RoomId -> RoomId -> Bool) -> Eq RoomId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RoomId -> RoomId -> Bool
== :: RoomId -> RoomId -> Bool
$c/= :: RoomId -> RoomId -> Bool
/= :: RoomId -> RoomId -> Bool
Eq, Int -> RoomId -> ShowS
[RoomId] -> ShowS
RoomId -> String
(Int -> RoomId -> ShowS)
-> (RoomId -> String) -> ([RoomId] -> ShowS) -> Show RoomId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RoomId -> ShowS
showsPrec :: Int -> RoomId -> ShowS
$cshow :: RoomId -> String
show :: RoomId -> String
$cshowList :: [RoomId] -> ShowS
showList :: [RoomId] -> ShowS
Show, Typeable)
instance ToJSON RoomId where
toJSON :: RoomId -> Value
toJSON = Text -> Value
String (Text -> Value) -> (RoomId -> Text) -> RoomId -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RoomId -> Text
printRoomId
instance FromJSON RoomId where
parseJSON ∷ ∀a. (a ~ RoomId) ⇒ Value → Parser a
parseJSON :: forall a. (a ~ RoomId) => Value -> Parser a
parseJSON Value
jsonInput =
case Value
jsonInput of
String Text
x → (String -> Parser a)
-> (a -> Parser a) -> Either String a -> Parser a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> Parser a
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail a -> Parser a
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either String a -> Parser a) -> Either String a -> Parser a
forall a b. (a -> b) -> a -> b
$ Parser a -> Text -> Either String a
forall a. Parser a -> Text -> Either String a
AP.parseOnly Parser a
Parser RoomId
roomIdParser Text
x
Value
_ → Parser a
failure
where
failure :: Parser a
failure = String -> Value -> Parser a
forall a. String -> Value -> Parser a
typeMismatch String
typeName Value
jsonInput
typeName :: String
typeName = TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String) -> (Proxy a -> TypeRep) -> Proxy a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy a -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy a -> String) -> Proxy a -> String
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a
instance ToHttpApiData RoomId where
toUrlPiece :: RoomId -> Text
toUrlPiece = RoomId -> Text
printRoomId
roomIdParser ∷ AP.Parser RoomId
roomIdParser :: Parser RoomId
roomIdParser =
Parser RoomId
locatedRoomIdParser Parser RoomId -> Parser RoomId -> Parser RoomId
forall a. Parser Text a -> Parser Text a -> Parser Text a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser RoomId
serverlessRoomIdParser
where
locatedRoomIdParser :: Parser RoomId
locatedRoomIdParser =
Text -> HomeServer -> RoomId
LocatedRoomId
(Text -> HomeServer -> RoomId)
-> Parser Text Text -> Parser Text (HomeServer -> RoomId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Text Text
"!" Parser Text Text -> Parser Text Text -> Parser Text Text
forall a b. Parser Text a -> Parser Text b -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> Bool) -> Parser Text Text
AP.takeTill (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':') Parser Text Text -> (Text -> Parser Text Text) -> Parser Text Text
forall a b. Parser Text a -> (a -> Parser Text b) -> Parser Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Text -> Parser Text Text
forall {a} {f :: * -> *}.
(Eq a, Monoid a, MonadFail f) =>
String -> a -> f a
failOnEmpty String
"id")
Parser Text (HomeServer -> RoomId)
-> Parser Text HomeServer -> Parser RoomId
forall a b. Parser Text (a -> b) -> Parser Text a -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> HomeServer) -> Parser Text Text -> Parser Text HomeServer
forall a b. (a -> b) -> Parser Text a -> Parser Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> HomeServer
HomeServer (Parser Text Text
":" Parser Text Text -> Parser Text Text -> Parser Text Text
forall a b. Parser Text a -> Parser Text b -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text Text
AP.takeText Parser Text Text -> (Text -> Parser Text Text) -> Parser Text Text
forall a b. Parser Text a -> (a -> Parser Text b) -> Parser Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Text -> Parser Text Text
forall {a} {f :: * -> *}.
(Eq a, Monoid a, MonadFail f) =>
String -> a -> f a
failOnEmpty String
"home server")
Parser RoomId -> Parser Text () -> Parser RoomId
forall a b. Parser Text a -> Parser Text b -> Parser Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text ()
forall t. Chunk t => Parser t ()
AP.endOfInput
serverlessRoomIdParser :: Parser RoomId
serverlessRoomIdParser =
Text -> RoomId
ServerlessRoomId
(Text -> RoomId) -> Parser Text Text -> Parser RoomId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Text Text
"!" Parser Text Text -> Parser Text Text -> Parser Text Text
forall a b. Parser Text a -> Parser Text b -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> Bool) -> Parser Text Text
AP.takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'!') Parser Text Text -> (Text -> Parser Text Text) -> Parser Text Text
forall a b. Parser Text a -> (a -> Parser Text b) -> Parser Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Text -> Parser Text Text
forall {a} {f :: * -> *}.
(Eq a, Monoid a, MonadFail f) =>
String -> a -> f a
failOnEmpty String
">=12 room id")
Parser RoomId -> Parser Text () -> Parser RoomId
forall a b. Parser Text a -> Parser Text b -> Parser Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text ()
forall t. Chunk t => Parser t ()
AP.endOfInput
failOnEmpty :: String -> a -> f a
failOnEmpty String
name a
x
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
forall a. Monoid a => a
mempty = a -> f a
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
| Bool
otherwise = String -> f a
forall a. String -> f a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> f a) -> String -> f a
forall a b. (a -> b) -> a -> b
$ String
"Empty " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
name
printRoomId ∷ RoomId → Text
printRoomId :: RoomId -> Text
printRoomId = \case
LocatedRoomId Text
roomId HomeServer
homeServer →
[Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ Text
"!", Text
roomId
, Text
":", HomeServer -> Text
unHomeServer HomeServer
homeServer
]
ServerlessRoomId Text
roomId → Text
"!" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
roomId
newtype EventId = EventId { EventId -> Text
unEventId ∷ Text }
deriving stock (EventId -> EventId -> Bool
(EventId -> EventId -> Bool)
-> (EventId -> EventId -> Bool) -> Eq EventId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EventId -> EventId -> Bool
== :: EventId -> EventId -> Bool
$c/= :: EventId -> EventId -> Bool
/= :: EventId -> EventId -> Bool
Eq, Int -> EventId -> ShowS
[EventId] -> ShowS
EventId -> String
(Int -> EventId -> ShowS)
-> (EventId -> String) -> ([EventId] -> ShowS) -> Show EventId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EventId -> ShowS
showsPrec :: Int -> EventId -> ShowS
$cshow :: EventId -> String
show :: EventId -> String
$cshowList :: [EventId] -> ShowS
showList :: [EventId] -> ShowS
Show)
deriving newtype ([EventId] -> Encoding
[EventId] -> Value
EventId -> Bool
EventId -> Encoding
EventId -> Value
(EventId -> Value)
-> (EventId -> Encoding)
-> ([EventId] -> Value)
-> ([EventId] -> Encoding)
-> (EventId -> Bool)
-> ToJSON EventId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: EventId -> Value
toJSON :: EventId -> Value
$ctoEncoding :: EventId -> Encoding
toEncoding :: EventId -> Encoding
$ctoJSONList :: [EventId] -> Value
toJSONList :: [EventId] -> Value
$ctoEncodingList :: [EventId] -> Encoding
toEncodingList :: [EventId] -> Encoding
$comitField :: EventId -> Bool
omitField :: EventId -> Bool
ToJSON, Maybe EventId
Value -> Parser [EventId]
Value -> Parser EventId
(Value -> Parser EventId)
-> (Value -> Parser [EventId]) -> Maybe EventId -> FromJSON EventId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser EventId
parseJSON :: Value -> Parser EventId
$cparseJSONList :: Value -> Parser [EventId]
parseJSONList :: Value -> Parser [EventId]
$comittedField :: Maybe EventId
omittedField :: Maybe EventId
FromJSON)
newtype EventToken = EventToken { EventToken -> Text
unEventToken ∷ Text }
deriving stock (EventToken -> EventToken -> Bool
(EventToken -> EventToken -> Bool)
-> (EventToken -> EventToken -> Bool) -> Eq EventToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EventToken -> EventToken -> Bool
== :: EventToken -> EventToken -> Bool
$c/= :: EventToken -> EventToken -> Bool
/= :: EventToken -> EventToken -> Bool
Eq, Int -> EventToken -> ShowS
[EventToken] -> ShowS
EventToken -> String
(Int -> EventToken -> ShowS)
-> (EventToken -> String)
-> ([EventToken] -> ShowS)
-> Show EventToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EventToken -> ShowS
showsPrec :: Int -> EventToken -> ShowS
$cshow :: EventToken -> String
show :: EventToken -> String
$cshowList :: [EventToken] -> ShowS
showList :: [EventToken] -> ShowS
Show)
deriving newtype ([EventToken] -> Encoding
[EventToken] -> Value
EventToken -> Bool
EventToken -> Encoding
EventToken -> Value
(EventToken -> Value)
-> (EventToken -> Encoding)
-> ([EventToken] -> Value)
-> ([EventToken] -> Encoding)
-> (EventToken -> Bool)
-> ToJSON EventToken
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: EventToken -> Value
toJSON :: EventToken -> Value
$ctoEncoding :: EventToken -> Encoding
toEncoding :: EventToken -> Encoding
$ctoJSONList :: [EventToken] -> Value
toJSONList :: [EventToken] -> Value
$ctoEncodingList :: [EventToken] -> Encoding
toEncodingList :: [EventToken] -> Encoding
$comitField :: EventToken -> Bool
omitField :: EventToken -> Bool
ToJSON, Maybe EventToken
Value -> Parser [EventToken]
Value -> Parser EventToken
(Value -> Parser EventToken)
-> (Value -> Parser [EventToken])
-> Maybe EventToken
-> FromJSON EventToken
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser EventToken
parseJSON :: Value -> Parser EventToken
$cparseJSONList :: Value -> Parser [EventToken]
parseJSONList :: Value -> Parser [EventToken]
$comittedField :: Maybe EventToken
omittedField :: Maybe EventToken
FromJSON, EventToken -> ByteString
EventToken -> Builder
EventToken -> Text
(EventToken -> Text)
-> (EventToken -> Builder)
-> (EventToken -> ByteString)
-> (EventToken -> Text)
-> (EventToken -> Builder)
-> ToHttpApiData EventToken
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: EventToken -> Text
toUrlPiece :: EventToken -> Text
$ctoEncodedUrlPiece :: EventToken -> Builder
toEncodedUrlPiece :: EventToken -> Builder
$ctoHeader :: EventToken -> ByteString
toHeader :: EventToken -> ByteString
$ctoQueryParam :: EventToken -> Text
toQueryParam :: EventToken -> Text
$ctoEncodedQueryParam :: EventToken -> Builder
toEncodedQueryParam :: EventToken -> Builder
ToHttpApiData)
newtype TransactionId = TransactionId { TransactionId -> UUID
unTransactionId ∷ UUID }
deriving stock (TransactionId -> TransactionId -> Bool
(TransactionId -> TransactionId -> Bool)
-> (TransactionId -> TransactionId -> Bool) -> Eq TransactionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TransactionId -> TransactionId -> Bool
== :: TransactionId -> TransactionId -> Bool
$c/= :: TransactionId -> TransactionId -> Bool
/= :: TransactionId -> TransactionId -> Bool
Eq, Int -> TransactionId -> ShowS
[TransactionId] -> ShowS
TransactionId -> String
(Int -> TransactionId -> ShowS)
-> (TransactionId -> String)
-> ([TransactionId] -> ShowS)
-> Show TransactionId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TransactionId -> ShowS
showsPrec :: Int -> TransactionId -> ShowS
$cshow :: TransactionId -> String
show :: TransactionId -> String
$cshowList :: [TransactionId] -> ShowS
showList :: [TransactionId] -> ShowS
Show)
deriving newtype ([TransactionId] -> Encoding
[TransactionId] -> Value
TransactionId -> Bool
TransactionId -> Encoding
TransactionId -> Value
(TransactionId -> Value)
-> (TransactionId -> Encoding)
-> ([TransactionId] -> Value)
-> ([TransactionId] -> Encoding)
-> (TransactionId -> Bool)
-> ToJSON TransactionId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: TransactionId -> Value
toJSON :: TransactionId -> Value
$ctoEncoding :: TransactionId -> Encoding
toEncoding :: TransactionId -> Encoding
$ctoJSONList :: [TransactionId] -> Value
toJSONList :: [TransactionId] -> Value
$ctoEncodingList :: [TransactionId] -> Encoding
toEncodingList :: [TransactionId] -> Encoding
$comitField :: TransactionId -> Bool
omitField :: TransactionId -> Bool
ToJSON, Maybe TransactionId
Value -> Parser [TransactionId]
Value -> Parser TransactionId
(Value -> Parser TransactionId)
-> (Value -> Parser [TransactionId])
-> Maybe TransactionId
-> FromJSON TransactionId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser TransactionId
parseJSON :: Value -> Parser TransactionId
$cparseJSONList :: Value -> Parser [TransactionId]
parseJSONList :: Value -> Parser [TransactionId]
$comittedField :: Maybe TransactionId
omittedField :: Maybe TransactionId
FromJSON, TransactionId -> ByteString
TransactionId -> Builder
TransactionId -> Text
(TransactionId -> Text)
-> (TransactionId -> Builder)
-> (TransactionId -> ByteString)
-> (TransactionId -> Text)
-> (TransactionId -> Builder)
-> ToHttpApiData TransactionId
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: TransactionId -> Text
toUrlPiece :: TransactionId -> Text
$ctoEncodedUrlPiece :: TransactionId -> Builder
toEncodedUrlPiece :: TransactionId -> Builder
$ctoHeader :: TransactionId -> ByteString
toHeader :: TransactionId -> ByteString
$ctoQueryParam :: TransactionId -> Text
toQueryParam :: TransactionId -> Text
$ctoEncodedQueryParam :: TransactionId -> Builder
toEncodedQueryParam :: TransactionId -> Builder
ToHttpApiData)
genTransactionId ∷ MonadIO m ⇒ m TransactionId
genTransactionId :: forall (m :: * -> *). MonadIO m => m TransactionId
genTransactionId = UUID -> TransactionId
TransactionId (UUID -> TransactionId) -> m UUID -> m TransactionId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
newtype FilterId = FilterId { FilterId -> Text
unFilterId ∷ Text }
deriving stock (FilterId -> FilterId -> Bool
(FilterId -> FilterId -> Bool)
-> (FilterId -> FilterId -> Bool) -> Eq FilterId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FilterId -> FilterId -> Bool
== :: FilterId -> FilterId -> Bool
$c/= :: FilterId -> FilterId -> Bool
/= :: FilterId -> FilterId -> Bool
Eq, Int -> FilterId -> ShowS
[FilterId] -> ShowS
FilterId -> String
(Int -> FilterId -> ShowS)
-> (FilterId -> String) -> ([FilterId] -> ShowS) -> Show FilterId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FilterId -> ShowS
showsPrec :: Int -> FilterId -> ShowS
$cshow :: FilterId -> String
show :: FilterId -> String
$cshowList :: [FilterId] -> ShowS
showList :: [FilterId] -> ShowS
Show)
deriving newtype ([FilterId] -> Encoding
[FilterId] -> Value
FilterId -> Bool
FilterId -> Encoding
FilterId -> Value
(FilterId -> Value)
-> (FilterId -> Encoding)
-> ([FilterId] -> Value)
-> ([FilterId] -> Encoding)
-> (FilterId -> Bool)
-> ToJSON FilterId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: FilterId -> Value
toJSON :: FilterId -> Value
$ctoEncoding :: FilterId -> Encoding
toEncoding :: FilterId -> Encoding
$ctoJSONList :: [FilterId] -> Value
toJSONList :: [FilterId] -> Value
$ctoEncodingList :: [FilterId] -> Encoding
toEncodingList :: [FilterId] -> Encoding
$comitField :: FilterId -> Bool
omitField :: FilterId -> Bool
ToJSON, Maybe FilterId
Value -> Parser [FilterId]
Value -> Parser FilterId
(Value -> Parser FilterId)
-> (Value -> Parser [FilterId])
-> Maybe FilterId
-> FromJSON FilterId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser FilterId
parseJSON :: Value -> Parser FilterId
$cparseJSONList :: Value -> Parser [FilterId]
parseJSONList :: Value -> Parser [FilterId]
$comittedField :: Maybe FilterId
omittedField :: Maybe FilterId
FromJSON, FilterId -> ByteString
FilterId -> Builder
FilterId -> Text
(FilterId -> Text)
-> (FilterId -> Builder)
-> (FilterId -> ByteString)
-> (FilterId -> Text)
-> (FilterId -> Builder)
-> ToHttpApiData FilterId
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: FilterId -> Text
toUrlPiece :: FilterId -> Text
$ctoEncodedUrlPiece :: FilterId -> Builder
toEncodedUrlPiece :: FilterId -> Builder
$ctoHeader :: FilterId -> ByteString
toHeader :: FilterId -> ByteString
$ctoQueryParam :: FilterId -> Text
toQueryParam :: FilterId -> Text
$ctoEncodedQueryParam :: FilterId -> Builder
toEncodedQueryParam :: FilterId -> Builder
ToHttpApiData)
newtype Milliseconds = Milliseconds { Milliseconds -> Integer
unMilliseconds ∷ Integer }
deriving stock (Milliseconds -> Milliseconds -> Bool
(Milliseconds -> Milliseconds -> Bool)
-> (Milliseconds -> Milliseconds -> Bool) -> Eq Milliseconds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Milliseconds -> Milliseconds -> Bool
== :: Milliseconds -> Milliseconds -> Bool
$c/= :: Milliseconds -> Milliseconds -> Bool
/= :: Milliseconds -> Milliseconds -> Bool
Eq, Int -> Milliseconds -> ShowS
[Milliseconds] -> ShowS
Milliseconds -> String
(Int -> Milliseconds -> ShowS)
-> (Milliseconds -> String)
-> ([Milliseconds] -> ShowS)
-> Show Milliseconds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Milliseconds -> ShowS
showsPrec :: Int -> Milliseconds -> ShowS
$cshow :: Milliseconds -> String
show :: Milliseconds -> String
$cshowList :: [Milliseconds] -> ShowS
showList :: [Milliseconds] -> ShowS
Show)
deriving newtype ([Milliseconds] -> Encoding
[Milliseconds] -> Value
Milliseconds -> Bool
Milliseconds -> Encoding
Milliseconds -> Value
(Milliseconds -> Value)
-> (Milliseconds -> Encoding)
-> ([Milliseconds] -> Value)
-> ([Milliseconds] -> Encoding)
-> (Milliseconds -> Bool)
-> ToJSON Milliseconds
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Milliseconds -> Value
toJSON :: Milliseconds -> Value
$ctoEncoding :: Milliseconds -> Encoding
toEncoding :: Milliseconds -> Encoding
$ctoJSONList :: [Milliseconds] -> Value
toJSONList :: [Milliseconds] -> Value
$ctoEncodingList :: [Milliseconds] -> Encoding
toEncodingList :: [Milliseconds] -> Encoding
$comitField :: Milliseconds -> Bool
omitField :: Milliseconds -> Bool
ToJSON, Maybe Milliseconds
Value -> Parser [Milliseconds]
Value -> Parser Milliseconds
(Value -> Parser Milliseconds)
-> (Value -> Parser [Milliseconds])
-> Maybe Milliseconds
-> FromJSON Milliseconds
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Milliseconds
parseJSON :: Value -> Parser Milliseconds
$cparseJSONList :: Value -> Parser [Milliseconds]
parseJSONList :: Value -> Parser [Milliseconds]
$comittedField :: Maybe Milliseconds
omittedField :: Maybe Milliseconds
FromJSON, Milliseconds -> ByteString
Milliseconds -> Builder
Milliseconds -> Text
(Milliseconds -> Text)
-> (Milliseconds -> Builder)
-> (Milliseconds -> ByteString)
-> (Milliseconds -> Text)
-> (Milliseconds -> Builder)
-> ToHttpApiData Milliseconds
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: Milliseconds -> Text
toUrlPiece :: Milliseconds -> Text
$ctoEncodedUrlPiece :: Milliseconds -> Builder
toEncodedUrlPiece :: Milliseconds -> Builder
$ctoHeader :: Milliseconds -> ByteString
toHeader :: Milliseconds -> ByteString
$ctoQueryParam :: Milliseconds -> Text
toQueryParam :: Milliseconds -> Text
$ctoEncodedQueryParam :: Milliseconds -> Builder
toEncodedQueryParam :: Milliseconds -> Builder
ToHttpApiData)
newtype Seconds = Seconds { Seconds -> Integer
unSeconds ∷ Integer }
deriving stock (Seconds -> Seconds -> Bool
(Seconds -> Seconds -> Bool)
-> (Seconds -> Seconds -> Bool) -> Eq Seconds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Seconds -> Seconds -> Bool
== :: Seconds -> Seconds -> Bool
$c/= :: Seconds -> Seconds -> Bool
/= :: Seconds -> Seconds -> Bool
Eq, Int -> Seconds -> ShowS
[Seconds] -> ShowS
Seconds -> String
(Int -> Seconds -> ShowS)
-> (Seconds -> String) -> ([Seconds] -> ShowS) -> Show Seconds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Seconds -> ShowS
showsPrec :: Int -> Seconds -> ShowS
$cshow :: Seconds -> String
show :: Seconds -> String
$cshowList :: [Seconds] -> ShowS
showList :: [Seconds] -> ShowS
Show)
deriving newtype ([Seconds] -> Encoding
[Seconds] -> Value
Seconds -> Bool
Seconds -> Encoding
Seconds -> Value
(Seconds -> Value)
-> (Seconds -> Encoding)
-> ([Seconds] -> Value)
-> ([Seconds] -> Encoding)
-> (Seconds -> Bool)
-> ToJSON Seconds
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Seconds -> Value
toJSON :: Seconds -> Value
$ctoEncoding :: Seconds -> Encoding
toEncoding :: Seconds -> Encoding
$ctoJSONList :: [Seconds] -> Value
toJSONList :: [Seconds] -> Value
$ctoEncodingList :: [Seconds] -> Encoding
toEncodingList :: [Seconds] -> Encoding
$comitField :: Seconds -> Bool
omitField :: Seconds -> Bool
ToJSON, Maybe Seconds
Value -> Parser [Seconds]
Value -> Parser Seconds
(Value -> Parser Seconds)
-> (Value -> Parser [Seconds]) -> Maybe Seconds -> FromJSON Seconds
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Seconds
parseJSON :: Value -> Parser Seconds
$cparseJSONList :: Value -> Parser [Seconds]
parseJSONList :: Value -> Parser [Seconds]
$comittedField :: Maybe Seconds
omittedField :: Maybe Seconds
FromJSON)
newtype Microseconds = Microseconds { Microseconds -> Integer
unMicroseconds ∷ Integer }
deriving stock (Microseconds -> Microseconds -> Bool
(Microseconds -> Microseconds -> Bool)
-> (Microseconds -> Microseconds -> Bool) -> Eq Microseconds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Microseconds -> Microseconds -> Bool
== :: Microseconds -> Microseconds -> Bool
$c/= :: Microseconds -> Microseconds -> Bool
/= :: Microseconds -> Microseconds -> Bool
Eq, Int -> Microseconds -> ShowS
[Microseconds] -> ShowS
Microseconds -> String
(Int -> Microseconds -> ShowS)
-> (Microseconds -> String)
-> ([Microseconds] -> ShowS)
-> Show Microseconds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Microseconds -> ShowS
showsPrec :: Int -> Microseconds -> ShowS
$cshow :: Microseconds -> String
show :: Microseconds -> String
$cshowList :: [Microseconds] -> ShowS
showList :: [Microseconds] -> ShowS
Show)
deriving newtype ([Microseconds] -> Encoding
[Microseconds] -> Value
Microseconds -> Bool
Microseconds -> Encoding
Microseconds -> Value
(Microseconds -> Value)
-> (Microseconds -> Encoding)
-> ([Microseconds] -> Value)
-> ([Microseconds] -> Encoding)
-> (Microseconds -> Bool)
-> ToJSON Microseconds
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Microseconds -> Value
toJSON :: Microseconds -> Value
$ctoEncoding :: Microseconds -> Encoding
toEncoding :: Microseconds -> Encoding
$ctoJSONList :: [Microseconds] -> Value
toJSONList :: [Microseconds] -> Value
$ctoEncodingList :: [Microseconds] -> Encoding
toEncodingList :: [Microseconds] -> Encoding
$comitField :: Microseconds -> Bool
omitField :: Microseconds -> Bool
ToJSON, Maybe Microseconds
Value -> Parser [Microseconds]
Value -> Parser Microseconds
(Value -> Parser Microseconds)
-> (Value -> Parser [Microseconds])
-> Maybe Microseconds
-> FromJSON Microseconds
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Microseconds
parseJSON :: Value -> Parser Microseconds
$cparseJSONList :: Value -> Parser [Microseconds]
parseJSONList :: Value -> Parser [Microseconds]
$comittedField :: Maybe Microseconds
omittedField :: Maybe Microseconds
FromJSON)
secondsToMilliseconds ∷ Seconds → Milliseconds
secondsToMilliseconds :: Seconds -> Milliseconds
secondsToMilliseconds (Seconds Integer
x) = Integer -> Milliseconds
Milliseconds (Integer -> Milliseconds) -> Integer -> Milliseconds
forall a b. (a -> b) -> a -> b
$ Integer
x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
1_000
millisecondsToMicroseconds ∷ Milliseconds → Microseconds
millisecondsToMicroseconds :: Milliseconds -> Microseconds
millisecondsToMicroseconds (Milliseconds Integer
x) = Integer -> Microseconds
Microseconds (Integer -> Microseconds) -> Integer -> Microseconds
forall a b. (a -> b) -> a -> b
$ Integer
x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
1_000
secondsToMicroseconds ∷ Seconds → Microseconds
secondsToMicroseconds :: Seconds -> Microseconds
secondsToMicroseconds = Milliseconds -> Microseconds
millisecondsToMicroseconds (Milliseconds -> Microseconds)
-> (Seconds -> Milliseconds) -> Seconds -> Microseconds
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Seconds -> Milliseconds
secondsToMilliseconds
newtype RetryLimit = RetryLimit { RetryLimit -> Natural
unRetryLimit ∷ Natural }
deriving stock (RetryLimit -> RetryLimit -> Bool
(RetryLimit -> RetryLimit -> Bool)
-> (RetryLimit -> RetryLimit -> Bool) -> Eq RetryLimit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RetryLimit -> RetryLimit -> Bool
== :: RetryLimit -> RetryLimit -> Bool
$c/= :: RetryLimit -> RetryLimit -> Bool
/= :: RetryLimit -> RetryLimit -> Bool
Eq, Int -> RetryLimit -> ShowS
[RetryLimit] -> ShowS
RetryLimit -> String
(Int -> RetryLimit -> ShowS)
-> (RetryLimit -> String)
-> ([RetryLimit] -> ShowS)
-> Show RetryLimit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RetryLimit -> ShowS
showsPrec :: Int -> RetryLimit -> ShowS
$cshow :: RetryLimit -> String
show :: RetryLimit -> String
$cshowList :: [RetryLimit] -> ShowS
showList :: [RetryLimit] -> ShowS
Show)
deriving newtype ([RetryLimit] -> Encoding
[RetryLimit] -> Value
RetryLimit -> Bool
RetryLimit -> Encoding
RetryLimit -> Value
(RetryLimit -> Value)
-> (RetryLimit -> Encoding)
-> ([RetryLimit] -> Value)
-> ([RetryLimit] -> Encoding)
-> (RetryLimit -> Bool)
-> ToJSON RetryLimit
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: RetryLimit -> Value
toJSON :: RetryLimit -> Value
$ctoEncoding :: RetryLimit -> Encoding
toEncoding :: RetryLimit -> Encoding
$ctoJSONList :: [RetryLimit] -> Value
toJSONList :: [RetryLimit] -> Value
$ctoEncodingList :: [RetryLimit] -> Encoding
toEncodingList :: [RetryLimit] -> Encoding
$comitField :: RetryLimit -> Bool
omitField :: RetryLimit -> Bool
ToJSON, Maybe RetryLimit
Value -> Parser [RetryLimit]
Value -> Parser RetryLimit
(Value -> Parser RetryLimit)
-> (Value -> Parser [RetryLimit])
-> Maybe RetryLimit
-> FromJSON RetryLimit
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser RetryLimit
parseJSON :: Value -> Parser RetryLimit
$cparseJSONList :: Value -> Parser [RetryLimit]
parseJSONList :: Value -> Parser [RetryLimit]
$comittedField :: Maybe RetryLimit
omittedField :: Maybe RetryLimit
FromJSON)
newtype RetryDelay = RetryDelay { RetryDelay -> Microseconds
unRetryDelay ∷ Microseconds }
deriving stock (RetryDelay -> RetryDelay -> Bool
(RetryDelay -> RetryDelay -> Bool)
-> (RetryDelay -> RetryDelay -> Bool) -> Eq RetryDelay
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RetryDelay -> RetryDelay -> Bool
== :: RetryDelay -> RetryDelay -> Bool
$c/= :: RetryDelay -> RetryDelay -> Bool
/= :: RetryDelay -> RetryDelay -> Bool
Eq, Int -> RetryDelay -> ShowS
[RetryDelay] -> ShowS
RetryDelay -> String
(Int -> RetryDelay -> ShowS)
-> (RetryDelay -> String)
-> ([RetryDelay] -> ShowS)
-> Show RetryDelay
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RetryDelay -> ShowS
showsPrec :: Int -> RetryDelay -> ShowS
$cshow :: RetryDelay -> String
show :: RetryDelay -> String
$cshowList :: [RetryDelay] -> ShowS
showList :: [RetryDelay] -> ShowS
Show)
deriving newtype ([RetryDelay] -> Encoding
[RetryDelay] -> Value
RetryDelay -> Bool
RetryDelay -> Encoding
RetryDelay -> Value
(RetryDelay -> Value)
-> (RetryDelay -> Encoding)
-> ([RetryDelay] -> Value)
-> ([RetryDelay] -> Encoding)
-> (RetryDelay -> Bool)
-> ToJSON RetryDelay
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: RetryDelay -> Value
toJSON :: RetryDelay -> Value
$ctoEncoding :: RetryDelay -> Encoding
toEncoding :: RetryDelay -> Encoding
$ctoJSONList :: [RetryDelay] -> Value
toJSONList :: [RetryDelay] -> Value
$ctoEncodingList :: [RetryDelay] -> Encoding
toEncodingList :: [RetryDelay] -> Encoding
$comitField :: RetryDelay -> Bool
omitField :: RetryDelay -> Bool
ToJSON, Maybe RetryDelay
Value -> Parser [RetryDelay]
Value -> Parser RetryDelay
(Value -> Parser RetryDelay)
-> (Value -> Parser [RetryDelay])
-> Maybe RetryDelay
-> FromJSON RetryDelay
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser RetryDelay
parseJSON :: Value -> Parser RetryDelay
$cparseJSONList :: Value -> Parser [RetryDelay]
parseJSONList :: Value -> Parser [RetryDelay]
$comittedField :: Maybe RetryDelay
omittedField :: Maybe RetryDelay
FromJSON)
class HasRetryParams r where
retryLimit ∷ Lens' r RetryLimit
retryDelay ∷ Lens' r RetryDelay
printRetryDelaySeconds ∷ IsString s ⇒ RetryDelay → s
printRetryDelaySeconds :: forall s. IsString s => RetryDelay -> s
printRetryDelaySeconds
= String -> s
forall a. IsString a => String -> a
fromString
(String -> s) -> (RetryDelay -> String) -> RetryDelay -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Double -> String
forall r. PrintfType r => String -> r
printf String
"%.03f second(s)"
(Double -> String)
-> (RetryDelay -> Double) -> RetryDelay -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
1_000_000)
(Double -> Double)
-> (RetryDelay -> Double) -> RetryDelay -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral @Integer @Double
(Integer -> Double)
-> (RetryDelay -> Integer) -> RetryDelay -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Microseconds -> Integer
unMicroseconds
(Microseconds -> Integer)
-> (RetryDelay -> Microseconds) -> RetryDelay -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryDelay -> Microseconds
unRetryDelay
newtype EventsTimeout = EventsTimeout { EventsTimeout -> Seconds
unEventsTimeout ∷ Seconds }
deriving stock (EventsTimeout -> EventsTimeout -> Bool
(EventsTimeout -> EventsTimeout -> Bool)
-> (EventsTimeout -> EventsTimeout -> Bool) -> Eq EventsTimeout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EventsTimeout -> EventsTimeout -> Bool
== :: EventsTimeout -> EventsTimeout -> Bool
$c/= :: EventsTimeout -> EventsTimeout -> Bool
/= :: EventsTimeout -> EventsTimeout -> Bool
Eq, Int -> EventsTimeout -> ShowS
[EventsTimeout] -> ShowS
EventsTimeout -> String
(Int -> EventsTimeout -> ShowS)
-> (EventsTimeout -> String)
-> ([EventsTimeout] -> ShowS)
-> Show EventsTimeout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EventsTimeout -> ShowS
showsPrec :: Int -> EventsTimeout -> ShowS
$cshow :: EventsTimeout -> String
show :: EventsTimeout -> String
$cshowList :: [EventsTimeout] -> ShowS
showList :: [EventsTimeout] -> ShowS
Show)
deriving newtype ([EventsTimeout] -> Encoding
[EventsTimeout] -> Value
EventsTimeout -> Bool
EventsTimeout -> Encoding
EventsTimeout -> Value
(EventsTimeout -> Value)
-> (EventsTimeout -> Encoding)
-> ([EventsTimeout] -> Value)
-> ([EventsTimeout] -> Encoding)
-> (EventsTimeout -> Bool)
-> ToJSON EventsTimeout
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: EventsTimeout -> Value
toJSON :: EventsTimeout -> Value
$ctoEncoding :: EventsTimeout -> Encoding
toEncoding :: EventsTimeout -> Encoding
$ctoJSONList :: [EventsTimeout] -> Value
toJSONList :: [EventsTimeout] -> Value
$ctoEncodingList :: [EventsTimeout] -> Encoding
toEncodingList :: [EventsTimeout] -> Encoding
$comitField :: EventsTimeout -> Bool
omitField :: EventsTimeout -> Bool
ToJSON, Maybe EventsTimeout
Value -> Parser [EventsTimeout]
Value -> Parser EventsTimeout
(Value -> Parser EventsTimeout)
-> (Value -> Parser [EventsTimeout])
-> Maybe EventsTimeout
-> FromJSON EventsTimeout
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser EventsTimeout
parseJSON :: Value -> Parser EventsTimeout
$cparseJSONList :: Value -> Parser [EventsTimeout]
parseJSONList :: Value -> Parser [EventsTimeout]
$comittedField :: Maybe EventsTimeout
omittedField :: Maybe EventsTimeout
FromJSON)