packages feed

servant-matrix-param (empty) → 0.1

raw patch · 9 files changed

+199/−0 lines, 9 filesdep +basedep +doctestdep +hspecsetup-changed

Dependencies added: base, doctest, hspec, servant, servant-aeson-specs, servant-matrix-param

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2016 Sönke Hahn++Permission is hereby granted, free of charge, to any person obtaining a copy of+this software and associated documentation files (the "Software"), to deal in+the Software without restriction, including without limitation the rights to+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies+of the Software, and to permit persons to whom the Software is furnished to do+so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
+ servant-matrix-param.cabal view
@@ -0,0 +1,65 @@+name:           servant-matrix-param+version:        0.1+synopsis:       Matrix parameter combinator for servant+description:    Matrix parameter combinator for servant+category:       Web+maintainer:     soenkehahn@gmail.com+license:        MIT+license-file:   LICENSE++build-type:     Simple+cabal-version:  >= 1.10++source-repository head+  type: git+  location: https://github.com/plow-technologies/servant-matrix-param++flag with-servant-aeson-specs+  description: support for servant-aeson-specs+  manual: True+  default: False++library+  default-language: Haskell2010+  ghc-options: -Wall+  hs-source-dirs:+      src+  build-depends:+      base < 5+    , servant == 0.5+  exposed-modules:+      Servant.MatrixParam+  if flag(with-servant-aeson-specs)+    build-depends:+        servant-aeson-specs == 0.2.* || == 0.3.*+    exposed-modules:+        Servant.MatrixParam.AesonSpecs++test-suite spec+  default-language: Haskell2010+  ghc-options: -Wall+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  hs-source-dirs:+      test+  build-depends:+      base < 5+    , hspec+    , servant == 0.5+    , servant-aeson-specs+    , servant-matrix-param+  other-modules:+      Servant.MatrixParam.AesonSpecsSpec+      Servant.MatrixParamSpec++test-suite doctest+  default-language: Haskell2010+  ghc-options: -Wall+  type: exitcode-stdio-1.0+  main-is: Doctest.hs+  hs-source-dirs:+      test+  build-depends:+      base < 5+    , servant == 0.5+    , doctest
+ src/Servant/MatrixParam.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE DataKinds          #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE PolyKinds          #-}++module Servant.MatrixParam (MatrixFlag, MatrixParam, MatrixParams) where++import           Data.Typeable (Typeable)+import           GHC.TypeLits  (Symbol)+-- | Lookup the value associated to the @sym@ matrix string parameter+-- and try to extract it as a value of type @a@.+--+-- Example:+--+-- >>> -- /books;author=<author name>+-- >>> type MyApi = "books" :> MatrixParam "author" Text :> Get '[JSON] [Book]+data MatrixParam (sym :: Symbol) a+    deriving (Typeable)++-- | Lookup the values associated to the @sym@ matrix string parameter+-- and try to extract it as a value of type @[a]@. This is typically+-- meant to support matrix string parameters of the form+-- @param[]=val1;param[]=val2@ and so on. Note that servant doesn't actually+-- require the @[]@s and will fetch the values just fine with+-- @param=val1;param=val2@, too.+--+-- Example:+--+-- >>> -- /books;authors[]=<author1>;authors[]=<author2>;...+-- >>> type MyApi = "books" :> MatrixParams "authors" Text :> Get '[JSON] [Book]+data MatrixParams (sym :: Symbol) a+    deriving (Typeable)++-- | Lookup a potentially value-less matrix string parameter+-- with boolean semantics. If the param @sym@ is there without any value,+-- or if it's there with value "true" or "1", it's interpreted as 'True'.+-- Otherwise, it's interpreted as 'False'.+--+-- Example:+--+-- >>> -- /books;published+-- >>> type MyApi = "books" :> MatrixFlag "published" :> Get '[JSON] [Book]+data MatrixFlag (sym :: Symbol)+    deriving (Typeable)+++-- $setup+-- >>> import Servant.API+-- >>> import Data.Aeson+-- >>> import Data.Text+-- >>> data Book+-- >>> instance ToJSON Book where { toJSON = undefined }
+ src/Servant/MatrixParam/AesonSpecs.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeOperators #-}++{-# OPTIONS_GHC -fno-warn-orphans #-}++module Servant.MatrixParam.AesonSpecs where++import           Data.Proxy+import           Servant.API+import           Servant.Aeson.Internal++import           Servant.MatrixParam++instance HasGenericSpecs api => HasGenericSpecs (MatrixParam name a :> api) where+  collectRoundtripSpecs Proxy = collectRoundtripSpecs (Proxy :: Proxy api)
+ test/Doctest.hs view
@@ -0,0 +1,10 @@++import Test.DocTest++main :: IO ()+main = doctest $+  "src/Servant/MatrixParam.hs" :+  "-isrc" :+  "-XDataKinds" :+  "-XTypeOperators" :+  []
+ test/Servant/MatrixParam/AesonSpecsSpec.hs view
@@ -0,0 +1,23 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}++module Servant.MatrixParam.AesonSpecsSpec where++import           Data.Typeable+import           Servant.API+import           Servant.Aeson.GenericSpecs+import           Test.Hspec++import           Servant.MatrixParam+import           Servant.MatrixParam.AesonSpecs ()++spec :: Spec+spec = do+  it "has an instance for HasGenericSpecs" $ do+    usedTypes matrixParamApi `shouldBe` [boolRep]++matrixParamApi :: Proxy (MatrixParam "foo" String :> Get '[JSON] Bool)+matrixParamApi = Proxy++boolRep :: TypeRep+boolRep = typeRep (Proxy :: Proxy Bool)
+ test/Servant/MatrixParamSpec.hs view
@@ -0,0 +1,9 @@++module Servant.MatrixParamSpec where++import           Test.Hspec++import           Servant.MatrixParam ()++spec :: Spec+spec = return ()
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}