packages feed

servant-jsonrpc 1.0.0 → 1.0.1

raw patch · 4 files changed

+72/−7 lines, 4 files

Files

+ LICENSE view
@@ -0,0 +1,28 @@+Copyright 2020 Bitnomial, Inc.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++1. Redistributions of source code must retain the above copyright+notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+notice, this list of conditions and the following disclaimer in the+documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its+contributors may be used to endorse or promote products derived from+this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
changelog.md view
@@ -1,3 +1,7 @@+# 1.1.0++Adds standard error codes to the library.+ # 1.0.0  First release
servant-jsonrpc.cabal view
@@ -1,7 +1,7 @@ cabal-version:       2.4  name:                servant-jsonrpc-version:             1.0.0+version:             1.0.1 author:              Ian Shipman <ics@gambolingpangolin.com> maintainer:          Ian Shipman <ics@gambolingpangolin.com> @@ -12,8 +12,10 @@     used in concert with servant to compose type level API specifications for     JSON-RPC endpoints. -homepage:            https://github.com/GambolingPangolin/servant-jsonrpc-license:             ISC+homepage:            https://github.com/bitnomial/servant-jsonrpc+license:             BSD-3-Clause+license-file:        LICENSE+copyright:           Bitnomial, Inc. (c) 2020 category:            Web build-type:          Simple @@ -21,7 +23,7 @@  source-repository head   type:     git-  location: https://github.com/GambolingPangolin/servant-jsonrpc.git+  location: https://github.com/bitnomial/servant-jsonrpc.git  library   default-language:    Haskell2010
src/Servant/JsonRpc.hs view
@@ -22,7 +22,8 @@ module Servant.JsonRpc     (     -- * API specification types-      JsonRpc+      RawJsonRpc+    , JsonRpc     , JsonRpcNotification      -- * JSON-RPC messages@@ -30,6 +31,13 @@     , JsonRpcResponse (..)     , JsonRpcErr (..) +    -- ** Standard error codes+    , parseErrorCode+    , invalidRequestCode+    , methodNotFoundCode+    , invalidParamsCode+    , internalErrorCode+     -- * Type rewriting     , JsonRpcEndpoint     ) where@@ -102,6 +110,26 @@     } deriving (Eq, Show)  +parseErrorCode :: Int+parseErrorCode = -32700+++invalidRequestCode :: Int+invalidRequestCode = -32600+++methodNotFoundCode :: Int+methodNotFoundCode = -32601+++invalidParamsCode :: Int+invalidParamsCode = -32602+++internalErrorCode :: Int+internalErrorCode = -32603++ instance (FromJSON e, FromJSON r) => FromJSON (JsonRpcResponse e r) where     parseJSON = withObject "Response" $ \obj -> do         ix      <- obj .:  "id"@@ -139,14 +167,17 @@         object [ "jsonrpc" .= ("2.0" :: String)                , "id"      .= ix                , "error"   .= detail-                ]           where          detail = object [ "code"    .= c                          , "message" .= msg                          , "data"    .= err-                           ]+                         ]+++-- | A JSON RPC server handles any number of methods.  Represent this at the type level using this type.+data RawJsonRpc api   -- | JSON-RPC endpoints which respond with a result