packages feed

rest-core 0.31.1 → 0.32

raw patch · 6 files changed

+32/−17 lines, 6 filesdep ~json-schemadep ~text

Dependency ranges changed: json-schema, text

Files

CHANGELOG.md view
@@ -1,5 +1,13 @@ # Changelog +## 0.32++* Add `addHeader` dictionary combinator, to extend instead of replace+  the header dictionaries. For this, a constructor `TwoHeaders` was+  added to `Header`.+* Relax the types of `mkListing` and `mkOrderedListing` to allow+  parameters and headers.+ ### 0.31.1  * Expose `Rest.Driver.Routing.splitUriString`.
rest-core.cabal view
@@ -1,5 +1,5 @@ name:                rest-core-version:             0.31.1+version:             0.32 description:         Rest API library. synopsis:            Rest API library. maintainer:          code@silk.co@@ -39,7 +39,7 @@     Rest.Schema   build-depends:       base >= 4.5 && < 4.8-    , aeson >= 0.7 && < 0.8+    , aeson >= 0.7 && < 0.9     , aeson-utils == 0.2.*     , bytestring >= 0.9 && < 0.11     , either >= 3.4 && < 4.4
src/Rest/Dictionary/Combinators.hs view
@@ -39,6 +39,7 @@   -- ** Header dictionaries    , mkHeader+  , addHeader    -- ** Parameter dictionaries @@ -61,10 +62,15 @@ import Rest.Dictionary.Types import Rest.Info --- | Add custom sub-dictionary for recognizing headers.+-- | Set custom sub-dictionary for recognizing headers.  mkHeader :: Header h -> Dict x p i o e -> Dict h p i o e mkHeader = L.set headers++-- | Add custom sub-dictionary for recognizing headers.++addHeader :: Header h -> Dict h' p i o e -> Dict (h, h') p i o e+addHeader = L.modify headers . TwoHeaders  -- | Set custom sub-dictionary for recognizing parameters. 
src/Rest/Dictionary/Types.hs view
@@ -85,18 +85,20 @@ -- for generating documentation. The second field is a custom parser that can -- fail with a `DataError` or can produce a some value. When explicitly not -- interested in the headers we can use `NoHeader`.------ Todo: allow multiple parsers for different headers instead of combining them--- into one parser + use `Info` class to enfore some documention about the--- parsed type.  data Header h where-  NoHeader ::                                                       Header ()-  Header   :: [String] -> ([Maybe String] -> Either DataError h) -> Header h+  NoHeader    ::                                                       Header ()+  Header      :: [String] -> ([Maybe String] -> Either DataError h) -> Header h+  TwoHeaders  :: Header h -> Header k                               -> Header (h,k)  instance Show (Header h) where-  showsPrec _ NoHeader      = showString "NoHeader"-  showsPrec n (Header hs _) = showParen (n > 9) (showString "Header " . showsPrec 10 hs)+  showsPrec _ NoHeader         = showString "NoHeader"+  showsPrec n (Header hs _)    = showParen (n > 9) (showString "Header " . showsPrec 10 hs)+  showsPrec n (TwoHeaders h k) = showParen (n > 9) ( showString "TwoHeaders "+                                                   . showsPrec 10 h+                                                   . showString " "+                                                   . showsPrec 10 k+                                                   )  -- | The explicit dictionary `Parameter` describes how to translate the request -- parameters to some Haskell value. The first field in the `Header`@@ -104,10 +106,6 @@ -- validation and for generating documentation. The second field is a custom -- parser that can fail with a `DataError` or can produce a some value. When -- explicitly not interested in the parameters we can use `NoParam`.------ Todo: allow multiple parsers for different parameters instead of combining--- them into one parser + use `Info` class to enfore some documention about the--- parsed type.  data Param p where   NoParam   ::                                                       Param ()
src/Rest/Driver/Perform.hs view
@@ -190,6 +190,7 @@ headers :: Rest m => Header h -> ErrorT DataError m h headers NoHeader      = return () headers (Header xs h) = mapM getHeader xs >>= either throwError return . h+headers (TwoHeaders h1 h2) = (,) <$> headers h1 <*> headers h2  parameters :: Rest m => Param p -> ErrorT DataError m p parameters NoParam      = return ()
src/Rest/Handler.hs view
@@ -96,10 +96,11 @@ data Range = Range { offset :: Int, count :: Int }  -- | Smart constructor for creating a list handler.+-- Restricts the type of the 'Input' dictionary to 'None'  mkListing   :: Monad m-  => Modifier () () () o e+  => Modifier h p () o e   -> (Range -> ErrorT (Reason e) m [o])   -> ListHandler m mkListing d a = mkGenHandler (mkPar range . d) (a . param)@@ -122,10 +123,11 @@                             }  -- | Create a list handler that accepts ordering information.+-- Restricts the type of the 'Input' dictionary to 'None'  mkOrderedListing   :: Monad m-  => Modifier () () () o e+  => Modifier h p () o e   -> ((Range, Maybe String, Maybe String) -> ErrorT (Reason e) m [o])   -> ListHandler m mkOrderedListing d a = mkGenHandler (mkPar orderedRange . d) (a . param)