Remove servant-cassava, moved to own repository
This commit is contained in:
parent
ea36656dcd
commit
5a3b944067
10 changed files with 0 additions and 193 deletions
|
@ -1,30 +0,0 @@
|
|||
Copyright (c) 2015-2016, Servant Contributors
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* 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.
|
||||
|
||||
* Neither the name of Julian K. Arni nor the names of other
|
||||
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
|
||||
OWNER 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.
|
|
@ -1,2 +0,0 @@
|
|||
import Distribution.Simple
|
||||
main = defaultMain
|
|
@ -1,8 +0,0 @@
|
|||
#if __GLASGOW_HASKELL__ >= 710
|
||||
#define OVERLAPPABLE_ {-# OVERLAPPABLE #-}
|
||||
#define OVERLAPPING_ {-# OVERLAPPING #-}
|
||||
#else
|
||||
{-# LANGUAGE OverlappingInstances #-}
|
||||
#define OVERLAPPABLE_
|
||||
#define OVERLAPPING_
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
-- Initial servant-cassava.cabal generated by cabal init. For further
|
||||
-- documentation, see http://haskell.org/cabal/users-guide/
|
||||
|
||||
name: servant-cassava
|
||||
version: 0.7.1
|
||||
synopsis: Servant CSV content-type for cassava
|
||||
-- description:
|
||||
homepage: http://haskell-servant.readthedocs.org/
|
||||
license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Servant Contributors
|
||||
maintainer: haskell-servant-maintainers@googlegroups.com
|
||||
copyright: 2015-2016 Servant Contributors
|
||||
-- category:
|
||||
build-type: Simple
|
||||
extra-source-files: include/*.h
|
||||
cabal-version: >=1.10
|
||||
|
||||
library
|
||||
exposed-modules: Servant.CSV.Cassava
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base >=4.6 && <5
|
||||
, cassava >0.4 && <0.5
|
||||
, servant == 0.7.*
|
||||
, http-media
|
||||
, vector
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
include-dirs: include
|
||||
ghc-options: -Wall
|
|
@ -1,115 +0,0 @@
|
|||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
|
||||
-- | A @CSV@ empty datatype with `MimeRender` and `MimeUnrender` instances for
|
||||
-- @cassava@'s encoding and decoding classes.
|
||||
--
|
||||
-- >>> type Eg = Get '[(CSV', MyEncodeOptions)] [(Int, String)]
|
||||
--
|
||||
-- Default encoding and decoding options are also provided, along with the
|
||||
-- @CSV@ type synonym that uses them.
|
||||
--
|
||||
-- >>> type EgDefault = Get '[CSV] [(Int, String)]
|
||||
module Servant.CSV.Cassava where
|
||||
|
||||
#if !MIN_VERSION_base(4,8,0)
|
||||
import Control.Applicative ((<$>))
|
||||
#endif
|
||||
import Data.Csv
|
||||
import Data.Proxy (Proxy (..))
|
||||
import Data.Typeable (Typeable)
|
||||
import Data.Vector (Vector, toList)
|
||||
import GHC.Generics (Generic)
|
||||
import qualified Network.HTTP.Media as M
|
||||
import Servant.API (Accept (..), MimeRender (..),
|
||||
MimeUnrender (..))
|
||||
|
||||
data CSV' deriving (Typeable, Generic)
|
||||
|
||||
type CSV = (CSV', DefaultDecodeOpts)
|
||||
|
||||
-- | @text/csv;charset=utf-8@
|
||||
instance Accept (CSV', a) where
|
||||
contentType _ = "text" M.// "csv" M./: ("charset", "utf-8")
|
||||
|
||||
-- * Encoding
|
||||
|
||||
-- ** Instances
|
||||
|
||||
-- | Encode with 'encodeByNameWith'. The 'Header' param is used for determining
|
||||
-- the order of headers and fields.
|
||||
instance ( ToNamedRecord a, EncodeOpts opt
|
||||
) => MimeRender (CSV', opt) (Header, [a]) where
|
||||
mimeRender _ (hdr, vals) = encodeByNameWith (encodeOpts p) hdr vals
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- | Encode with 'encodeDefaultOrderedByNameWith'
|
||||
instance ( DefaultOrdered a, ToNamedRecord a, EncodeOpts opt
|
||||
) => MimeRender (CSV', opt) [a] where
|
||||
mimeRender _ = encodeDefaultOrderedByNameWith (encodeOpts p)
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- | Encode with 'encodeByNameWith'. The 'Header' param is used for determining
|
||||
-- the order of headers and fields.
|
||||
instance ( ToNamedRecord a, EncodeOpts opt
|
||||
) => MimeRender (CSV', opt) (Header, Vector a) where
|
||||
mimeRender _ (hdr, vals) = encodeByNameWith (encodeOpts p) hdr (toList vals)
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- | Encode with 'encodeDefaultOrderedByNameWith'
|
||||
instance ( DefaultOrdered a, ToNamedRecord a, EncodeOpts opt
|
||||
) => MimeRender (CSV', opt) (Vector a) where
|
||||
mimeRender _ = encodeDefaultOrderedByNameWith (encodeOpts p) . toList
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- ** Encode Options
|
||||
|
||||
class EncodeOpts a where
|
||||
encodeOpts :: Proxy a -> EncodeOptions
|
||||
|
||||
data DefaultEncodeOpts deriving (Typeable, Generic)
|
||||
|
||||
instance EncodeOpts DefaultEncodeOpts where
|
||||
encodeOpts _ = defaultEncodeOptions
|
||||
|
||||
-- * Decoding
|
||||
|
||||
-- ** Instances
|
||||
|
||||
-- | Decode with 'decodeByNameWith'
|
||||
instance ( FromNamedRecord a, DecodeOpts opt
|
||||
) => MimeUnrender (CSV', opt) (Header, [a]) where
|
||||
mimeUnrender _ bs = fmap toList <$> decodeByNameWith (decodeOpts p) bs
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- | Decode with 'decodeWith'. Assumes data has headers, which are stripped.
|
||||
instance ( FromRecord a, DecodeOpts opt
|
||||
) => MimeUnrender (CSV', opt) [a] where
|
||||
mimeUnrender _ bs = toList <$> decodeWith (decodeOpts p) HasHeader bs
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
instance ( FromNamedRecord a, DecodeOpts opt
|
||||
) => MimeUnrender (CSV', opt) (Header, Vector a) where
|
||||
mimeUnrender _ = decodeByNameWith (decodeOpts p)
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- | Decode with 'decodeWith'. Assumes data has headers, which are stripped.
|
||||
instance ( FromRecord a, DecodeOpts opt
|
||||
) => MimeUnrender (CSV', opt) (Vector a) where
|
||||
mimeUnrender _ = decodeWith (decodeOpts p) HasHeader
|
||||
where p = Proxy :: Proxy opt
|
||||
|
||||
-- ** Decode Options
|
||||
|
||||
class DecodeOpts a where
|
||||
decodeOpts :: Proxy a -> DecodeOptions
|
||||
|
||||
data DefaultDecodeOpts deriving (Typeable, Generic)
|
||||
|
||||
instance DecodeOpts DefaultDecodeOpts where
|
||||
decodeOpts _ = defaultDecodeOptions
|
|
@ -1,3 +0,0 @@
|
|||
dependencies:
|
||||
- name: servant
|
||||
path: ../servant
|
|
@ -1,7 +1,6 @@
|
|||
servant
|
||||
servant-server
|
||||
servant-client
|
||||
servant-cassava
|
||||
servant-docs
|
||||
servant-foreign
|
||||
servant-js
|
||||
|
|
|
@ -2,7 +2,6 @@ flags: {}
|
|||
packages:
|
||||
- servant/
|
||||
- servant-blaze/
|
||||
- servant-cassava/
|
||||
- servant-client/
|
||||
- servant-docs/
|
||||
- servant-foreign/
|
||||
|
|
|
@ -4,7 +4,6 @@ flags:
|
|||
packages:
|
||||
- servant/
|
||||
- servant-blaze/
|
||||
- servant-cassava/
|
||||
- servant-client/
|
||||
- servant-docs/
|
||||
- servant-foreign/
|
||||
|
|
|
@ -4,7 +4,6 @@ flags:
|
|||
packages:
|
||||
- servant/
|
||||
- servant-blaze/
|
||||
- servant-cassava/
|
||||
- servant-client/
|
||||
- servant-docs/
|
||||
- servant-foreign/
|
||||
|
|
Loading…
Reference in a new issue