-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fully-featured JSON-RPC 2.0 library -- @package json-rpc @version 0.3.0.2 module Network.JsonRpc type JsonRpcT = ReaderT Session -- | Create JSON-RPC session around ByteString conduits from transport -- layer. When context exits, session stops existing. runJsonRpcT :: (FromRequest q, ToJSON r) => Ver -> Respond q IO r -> Sink ByteString IO () -> Source IO ByteString -> JsonRpcT IO a -> IO a -- | Returns Right Nothing if could not parse response. Run output in STM -- monad. STM will block until response arrives. sendRequest :: (ToJSON q, ToRequest q, FromResponse r, MonadIO m) => q -> JsonRpcT m (STM (Either ErrorObj (Maybe r))) -- | Send notification. Run output in STM monad. Will not block. sendNotif :: (ToJSON no, ToNotif no, Monad m) => no -> JsonRpcT m (STM ()) -- | Receive notifications from peer. Returns Nothing if incoming channel -- is closed and empty. Result is Right Nothing if it failed to parse -- notification. Run output in STM monad. Will not block. receiveNotif :: (Monad m, FromNotif n) => JsonRpcT m (STM (Maybe (Either ErrorObj (Maybe n)))) -- | TCP client transport for JSON-RPC. jsonRpcTcpClient :: (FromRequest q, ToJSON r) => Ver -> ClientSettings -> Respond q IO r -> JsonRpcT IO a -> IO a -- | Respond function for systems that do not reply to requests, as usual -- in clients. dummyRespond :: Monad m => Respond () m () -- | TCP server transport for JSON-RPC. jsonRpcTcpServer :: (FromRequest q, ToJSON r) => Ver -> ServerSettings -> Respond q IO r -> JsonRpcT IO () -> IO () -- | Dummy server for servers not expecting client to send notifications, -- that is most cases. dummySrv :: MonadIO m => JsonRpcT m () data Request Request :: !Ver -> !Method -> !Value -> !Id -> Request getReqVer :: Request -> !Ver getReqMethod :: Request -> !Method getReqParams :: Request -> !Value getReqId :: Request -> !Id class FromRequest q parseParams :: FromRequest q => Method -> Maybe (Value -> Parser q) fromRequest :: FromRequest q => Request -> Maybe q class ToRequest q requestMethod :: ToRequest q => q -> Method buildRequest :: (ToJSON q, ToRequest q) => Ver -> q -> Id -> Request data Response Response :: !Ver -> !Value -> !Id -> Response getResVer :: Response -> !Ver getResult :: Response -> !Value getResId :: Response -> !Id class FromResponse r parseResult :: FromResponse r => Method -> Maybe (Value -> Parser r) fromResponse :: FromResponse r => Method -> Response -> Maybe r type Respond q m r = q -> m (Either ErrorObj r) buildResponse :: (Monad m, FromRequest q, ToJSON r) => Respond q m r -> Request -> m (Either RpcError Response) data Notif Notif :: !Ver -> !Method -> !Value -> Notif getNotifVer :: Notif -> !Ver getNotifMethod :: Notif -> !Method getNotifParams :: Notif -> !Value class FromNotif n parseNotif :: FromNotif n => Method -> Maybe (Value -> Parser n) fromNotif :: FromNotif n => Notif -> Maybe n class ToNotif n notifMethod :: ToNotif n => n -> Method buildNotif :: (ToJSON n, ToNotif n) => Ver -> n -> Notif data RpcError RpcError :: !Ver -> !ErrorObj -> !Id -> RpcError getErrVer :: RpcError -> !Ver getErrObj :: RpcError -> !ErrorObj getErrId :: RpcError -> !Id data ErrorObj ErrorObj :: !String -> !Int -> !Value -> ErrorObj getErrMsg :: ErrorObj -> !String getErrCode :: ErrorObj -> !Int getErrData :: ErrorObj -> !Value ErrorVal :: !Value -> ErrorObj getErrData :: ErrorObj -> !Value fromError :: ErrorObj -> String -- | Parse error. errorParse :: Value -> ErrorObj -- | Invalid request. errorInvalid :: Value -> ErrorObj -- | Invalid params. errorParams :: Value -> ErrorObj -- | Method not found. errorMethod :: Method -> ErrorObj -- | Id not recognized. errorId :: Id -> ErrorObj data Message MsgRequest :: !Request -> Message getMsgRequest :: Message -> !Request MsgResponse :: !Response -> Message getMsgResponse :: Message -> !Response MsgNotif :: !Notif -> Message getMsgNotif :: Message -> !Notif MsgError :: !RpcError -> Message getMsgError :: Message -> !RpcError type Method = Text data Id IdInt :: !Int -> Id getIdInt :: Id -> !Int IdTxt :: !Text -> Id getIdTxt :: Id -> !Text IdNull :: Id data Ver -- | JSON-RPC 1.0 V1 :: Ver -- | JSON-RPC 2.0 V2 :: Ver