-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fully-featured JSON-RPC 2.0 library -- @package json-rpc @version 0.2.0.2 module Network.JsonRpc -- | Conduits of sending and receiving JSON-RPC messages. type AppConduits qo no ro qi ni ri m = (Source m (IncomingMsg qo qi ni ri), Sink (Message qo no ro) m ()) -- | Incoming messages. Responses and corresponding requests go together. -- IncomingError is for problems decoding incoming messages. These -- should be sent to the remote party. data IncomingMsg qo qi ni ri IncomingMsg :: !(Message qi ni ri) -> !(Maybe (Request qo)) -> IncomingMsg qo qi ni ri incomingMsg :: IncomingMsg qo qi ni ri -> !(Message qi ni ri) matchingReq :: IncomingMsg qo qi ni ri -> !(Maybe (Request qo)) IncomingError :: !ErrorObj -> IncomingMsg qo qi ni ri incomingError :: IncomingMsg qo qi ni ri -> !ErrorObj runConduits :: (FromRequest qi, FromNotif ni, FromResponse ri, ToJSON qo, ToJSON no, ToJSON ro) => Ver -> Bool -> Sink ByteString IO () -> Source IO ByteString -> (AppConduits qo no ro qi ni ri IO -> IO a) -> IO a tcpClient :: (FromRequest qi, FromNotif ni, FromResponse ri, ToJSON qo, ToJSON no, ToJSON ro) => Ver -> Bool -> ClientSettings -> (AppConduits qo no ro qi ni ri IO -> IO a) -> IO a tcpServer :: (FromRequest qi, FromNotif ni, FromResponse ri, ToJSON qo, ToJSON no, ToJSON ro) => Ver -> ServerSettings -> (AppConduits qo no ro qi ni ri IO -> IO ()) -> IO () -- | Send requests and get responses (or errors). -- -- Example: -- --
--   tcpClient V2 True (clientSettings 31337 "127.0.0.1") (query V2 [TimeReq])
--   
query :: (ToJSON qo, ToRequest qo, FromResponse ri) => Ver -> [qo] -> AppConduits qo () () () () ri IO -> IO [IncomingMsg qo () () ri] -- | JSON-RPC session mutable data. data Session qo Session :: TVar Id -> TVar (SentRequests qo) -> TQueue Bool -> Session qo -- | Last generated id lastId :: Session qo -> TVar Id -- | Map of ids to requests sentRequests :: Session qo -> TVar (SentRequests qo) -- | For each sent request, write a False, when sink closes, write a True isLast :: Session qo -> TQueue Bool -- | Map of ids to sent requests. type SentRequests qo = HashMap Id (Request qo) -- | Initialize JSON-RPC session. initSession :: STM (Session qo) -- | Conduit that serializes JSON documents for sending to the network. encodeConduit :: (ToJSON a, Monad m) => Conduit a m ByteString -- | Conduit for outgoing JSON-RPC messages. Adds an id to requests whose -- id is IdNull. Tracks all sent requests to match corresponding -- responses. msgConduit :: MonadIO m => Bool -> Session qo -> Conduit (Message qo no ro) m (Message qo no ro) -- | Conduit to decode incoming JSON-RPC messages. An error in the decoding -- operation will output an IncomingError, which should be relayed -- to the remote party. decodeConduit :: (FromRequest qi, FromNotif ni, FromResponse ri, MonadIO m) => Ver -> Bool -> Session qo -> Conduit ByteString m (IncomingMsg qo qi ni ri) data Request q Request :: !Ver -> !Method -> !q -> !Id -> Request q getReqVer :: Request q -> !Ver getReqMethod :: Request q -> !Method getReqParams :: Request q -> !q getReqId :: Request q -> !Id -- | Class for data that can be received in JSON-RPC requests. class FromRequest q paramsParser :: FromRequest q => Method -> Maybe (Value -> Parser q) -- | Parse JSON-RPC request. parseRequest :: FromRequest q => Value -> Parser (Either ErrorObj (Request q)) -- | Class for data that can be sent as JSON-RPC requests. Define a method -- name for each request. class ToRequest q requestMethod :: ToRequest q => q -> Method buildRequest :: ToRequest q => Ver -> q -> Request q -- | JSON-RPC response data type data Response r Response :: !Ver -> !r -> !Id -> Response r -- | Version getResVer :: Response r -> !Ver -- | Result getResult :: Response r -> !r -- | Id getResId :: Response r -> !Id -- | Class for data that can be received inside JSON-RPC responses. class FromResponse r parseResult :: FromResponse r => Method -> Value -> Parser r -- | Parse JSON-RPC response. parseResponse :: FromResponse r => Request q -> Value -> Parser (Either ErrorObj (Response r)) -- | Class for JSON-RPC notifications. data Notif n Notif :: !Ver -> !Method -> !n -> Notif n -- | Version getNotifVer :: Notif n -> !Ver -- | Method getNotifMethod :: Notif n -> !Method -- | Params getNotifParams :: Notif n -> !n -- | Class for data that can be received in JSON-RPC notifications. class FromNotif n notifParamsParser :: FromNotif n => Method -> Maybe (Value -> Parser n) -- | Parse notifications. parseNotif :: FromNotif n => Value -> Parser (Either ErrorObj (Notif n)) class ToNotif n notifMethod :: ToNotif n => n -> Method -- | Build notifications. buildNotif :: ToNotif n => Ver -> n -> Notif n -- | JSON-RPC errors. data ErrorObj ErrorObj :: !Ver -> !String -> !Int -> !Value -> !Id -> ErrorObj -- | Version getErrVer :: ErrorObj -> !Ver -- | Message getErrMsg :: ErrorObj -> !String -- | Error code (2.0) getErrCode :: ErrorObj -> !Int -- | Error data (2.0) getErrData :: ErrorObj -> !Value -- | Error id getErrId :: ErrorObj -> !Id -- | Parse error. errorParse :: Ver -> Value -> ErrorObj -- | Invalid request. errorInvalid :: Ver -> Value -> ErrorObj -- | Invalid params. errorParams :: Ver -> Value -> Id -> ErrorObj -- | Method not found. errorMethod :: Ver -> Method -> Id -> ErrorObj -- | Id not recognized. errorId :: Ver -> Id -> ErrorObj -- | Class for any JSON-RPC message. data Message q n r MsgRequest :: !(Request q) -> Message q n r getMsgRequest :: Message q n r -> !(Request q) MsgNotif :: !(Notif n) -> Message q n r getMsgNotif :: Message q n r -> !(Notif n) MsgResponse :: !(Response r) -> Message q n r getMsgResponse :: Message q n r -> !(Response r) MsgError :: !ErrorObj -> Message q n r getMsgError :: Message q n r -> !ErrorObj -- | JSON-RPC methods in requests and notifications. type Method = Text -- | JSON-RPC message id. data Id IdInt :: !Int -> Id getIdInt :: Id -> !Int IdTxt :: !Text -> Id getIdTxt :: Id -> !Text IdNull :: Id -- | JSON-RPC version data Ver -- | JSON-RPC 1.0 V1 :: Ver -- | JSON-RPC 2.0 V2 :: Ver