Skip to content

Commit

Permalink
Merge pull request #89 from fizruk/prepare-0.4
Browse files Browse the repository at this point in the history
Prepare 0.4
  • Loading branch information
phadej authored Nov 13, 2018
2 parents 283c747 + 6454ed0 commit f7876c3
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 166 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ before_cache:

matrix:
include:
- compiler: "ghc-8.6.1"
- compiler: "ghc-8.6.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.1], sources: [hvr-ghc]}}
- compiler: "ghc-8.4.3"
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.2], sources: [hvr-ghc]}}
- compiler: "ghc-8.4.4"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.3], sources: [hvr-ghc]}}
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}}
- compiler: "ghc-8.2.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}}
Expand Down Expand Up @@ -93,8 +93,8 @@ install:
# any command which exits with a non-zero exit code causes the build to fail.
script:
# test that source-distributions can be generated
- (cd "." && cabal sdist)
- mv "."/dist/http-api-data-*.tar.gz ${DISTDIR}/
- cabal new-sdist all
- mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
- cd ${DISTDIR} || false
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
- "printf 'packages: http-api-data-*/*.cabal\\n' > cabal.project"
Expand All @@ -113,7 +113,6 @@ script:
- (cd http-api-data-* && cabal check)

# haddock
- rm -rf ./dist-newstyle
- if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi

# Build without installed constraints for packages in global-db
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.4
---

* `NominalDiffTime` instances preserve precision (roundtrip)
* Add `Semigroup.Min`, `Max`, `First`, `Last` instances
* Add `Tagged b a` instances

0.3.10
---

Expand Down
29 changes: 19 additions & 10 deletions http-api-data.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >= 1.10
name: http-api-data
version: 0.3.10
version: 0.4

synopsis: Converting to/from HTTP API data like URL pieces, headers and query parameters.
category: Web
Expand All @@ -22,13 +22,14 @@ extra-source-files:
test/*.hs
CHANGELOG.md
README.md

tested-with:
GHC==7.8.4,
GHC==7.10.3,
GHC==8.0.2,
GHC==8.2.2,
GHC==8.4.3,
GHC==8.6.1
GHC==8.4.4,
GHC==8.6.2

custom-setup
setup-depends:
Expand All @@ -55,14 +56,21 @@ library
-- other-dependencies
build-depends:
attoparsec >= 0.13.2.2 && < 0.14
, attoparsec-iso8601 >= 1.0.0.0 && < 1.1
, attoparsec-iso8601 >= 1.0.1.0 && < 1.1
, base-compat >= 0.10.5 && < 0.11
, cookie >= 0.4.3 && < 0.4.5
, hashable >= 1.2.7.0 && < 1.3
, http-types >= 0.12.1 && < 0.13
, http-types >= 0.12.2 && < 0.13
, tagged >= 0.8.5 && < 0.9
, time-locale-compat >= 0.1.1.5 && < 0.2
, unordered-containers >= 0.2.9.0 && < 0.3
, uuid-types >= 1.0.3 && <1.1

if !impl(ghc >= 7.10)
build-depends:
nats >= 1.1.2 && < 1.2,
void >= 0.7.2 && < 0.8

if !impl(ghc >= 8.0)
build-depends: semigroups >= 0.18.5 && < 0.19

Expand All @@ -88,21 +96,22 @@ test-suite spec
hs-source-dirs: test
ghc-options: -Wall
default-language: Haskell2010
build-tool-depends: hspec-discover:hspec-discover >= 2.5.5 && <2.6
build-tool-depends: hspec-discover:hspec-discover >= 2.6.0 && <2.7
-- inherited depndencies
build-depends:
base
, base-compat
, bytestring
, unordered-containers
, cookie
, http-api-data
, nats
, text
, time
, bytestring
, unordered-containers
, uuid-types
, cookie

build-depends: HUnit >= 1.6.0.0 && <1.7
, hspec >= 2.5.5 && <2.6
, hspec >= 2.6.0 && <2.7
, QuickCheck >= 2.11.3 && <2.13
, quickcheck-instances >= 0.3.19 && <0.4

Expand Down
67 changes: 36 additions & 31 deletions src/Web/Internal/FormUrlEncoded.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,46 @@
#include "overlapping-compat.h"
module Web.Internal.FormUrlEncoded where

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
import Data.Traversable
#endif

import Prelude ()
import Prelude.Compat

import Control.Arrow ((***))
import Control.Monad ((<=<))
import Data.ByteString.Builder (shortByteString, toLazyByteString)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.Char8 as BSL8
import Data.Coerce (coerce)
import qualified Data.Foldable as F
import Data.Hashable (Hashable)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Int
import Data.Int (Int16, Int32, Int64, Int8)
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.List (intersperse, sortBy)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Monoid
import Data.Monoid (All (..), Any (..), Dual (..),
Product (..), Sum (..))
import Data.Ord (comparing)
import Data.Proxy (Proxy (..))
import Data.Semigroup (Semigroup (..))
import qualified Data.Semigroup as Semi

import Data.Tagged (Tagged (..))
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Text.Encoding as Text
import qualified Data.Text.Encoding as Text
import Data.Text.Encoding.Error (lenientDecode)
import qualified Data.Text.Lazy as Lazy

import Data.Proxy
import Data.Time
import Data.Word

#if MIN_VERSION_base(4,8,0)
import Data.Void
import Numeric.Natural
#endif

import Data.Time (Day, LocalTime, NominalDiffTime,
UTCTime, ZonedTime)
import Data.Void (Void)
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.Exts (Constraint, IsList (..))
import GHC.Generics
import GHC.TypeLits
import Network.HTTP.Types.URI (urlDecode, urlEncodeBuilder)

import Numeric.Natural (Natural)
import Web.Internal.HttpApiData

-- $setup
Expand Down Expand Up @@ -124,14 +119,19 @@ instance ToFormKey Lazy.Text where toFormKey = toQueryParam
instance ToFormKey All where toFormKey = toQueryParam
instance ToFormKey Any where toFormKey = toQueryParam

instance ToFormKey a => ToFormKey (Dual a) where toFormKey = toFormKey . getDual
instance ToFormKey a => ToFormKey (Sum a) where toFormKey = toFormKey . getSum
instance ToFormKey a => ToFormKey (Product a) where toFormKey = toFormKey . getProduct
instance ToFormKey a => ToFormKey (Dual a) where toFormKey = coerce (toFormKey :: a -> Text)
instance ToFormKey a => ToFormKey (Sum a) where toFormKey = coerce (toFormKey :: a -> Text)
instance ToFormKey a => ToFormKey (Product a) where toFormKey = coerce (toFormKey :: a -> Text)

instance ToFormKey a => ToFormKey (Semi.Min a) where toFormKey = coerce (toFormKey :: a -> Text)
instance ToFormKey a => ToFormKey (Semi.Max a) where toFormKey = coerce (toFormKey :: a -> Text)
instance ToFormKey a => ToFormKey (Semi.First a) where toFormKey = coerce (toFormKey :: a -> Text)
instance ToFormKey a => ToFormKey (Semi.Last a) where toFormKey = coerce (toFormKey :: a -> Text)

instance ToFormKey a => ToFormKey (Tagged b a) where toFormKey = coerce (toFormKey :: a -> Text)

#if MIN_VERSION_base(4,8,0)
instance ToFormKey Void where toFormKey = toQueryParam
instance ToFormKey Natural where toFormKey = toQueryParam
#endif

-- | Typeclass for types that can be parsed from keys of a 'Form'. This is the reverse of 'ToFormKey'.
class FromFormKey k where
Expand Down Expand Up @@ -171,20 +171,25 @@ instance FromFormKey Lazy.Text where parseFormKey = parseQueryParam
instance FromFormKey All where parseFormKey = parseQueryParam
instance FromFormKey Any where parseFormKey = parseQueryParam

instance FromFormKey a => FromFormKey (Dual a) where parseFormKey = fmap Dual . parseFormKey
instance FromFormKey a => FromFormKey (Sum a) where parseFormKey = fmap Sum . parseFormKey
instance FromFormKey a => FromFormKey (Product a) where parseFormKey = fmap Product . parseFormKey
instance FromFormKey a => FromFormKey (Dual a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)
instance FromFormKey a => FromFormKey (Sum a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)
instance FromFormKey a => FromFormKey (Product a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)

instance FromFormKey a => FromFormKey (Semi.Min a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)
instance FromFormKey a => FromFormKey (Semi.Max a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)
instance FromFormKey a => FromFormKey (Semi.First a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)
instance FromFormKey a => FromFormKey (Semi.Last a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)

instance FromFormKey a => FromFormKey (Tagged b a) where parseFormKey = coerce (parseFormKey :: Text -> Either Text a)

#if MIN_VERSION_base(4,8,0)
instance FromFormKey Void where parseFormKey = parseQueryParam
instance FromFormKey Natural where parseFormKey = parseQueryParam
#endif

-- | The contents of a form, not yet URL-encoded.
--
-- 'Form' can be URL-encoded with 'urlEncodeForm' and URL-decoded with 'urlDecodeForm'.
newtype Form = Form { unForm :: HashMap Text [Text] }
deriving (Eq, Read, Generic, Semi.Semigroup, Monoid)
deriving (Eq, Read, Generic, Semigroup, Monoid)

instance Show Form where
showsPrec d form = showParen (d > 10) $
Expand Down
Loading

0 comments on commit f7876c3

Please sign in to comment.