Skip to content

Commit 2af8e96

Browse files
authored
codebase clean-up (#1730)
1 parent d33f626 commit 2af8e96

File tree

28 files changed

+560
-454
lines changed

28 files changed

+560
-454
lines changed

cabal.project

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ packages:
5454

5555
tests: True
5656
optimization: False
57+
58+
-- Development flags
59+
package *
60+
ghc-options: -fshow-hole-constraints -fhide-source-paths
61+
5762
-- reorder-goals: True
5863

5964
-- Print ticks so that doctest type querying is consistent across GHC versions.
+115-70
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,154 @@
1-
cabal-version: 2.2
2-
name: servant-client-core
3-
version: 0.20
1+
cabal-version: 3.0
2+
name: servant-client-core
3+
version: 0.20
4+
synopsis:
5+
Core functionality and class for client function generation for servant APIs
46

5-
synopsis: Core functionality and class for client function generation for servant APIs
6-
category: Servant, Web
7+
category: Servant, Web
78
description:
89
This library provides backend-agnostic generation of client functions. For
910
more information, see the README.
1011

11-
homepage: http://docs.servant.dev/
12-
bug-reports: http://github.com/haskell-servant/servant/issues
13-
license: BSD-3-Clause
14-
license-file: LICENSE
15-
author: Servant Contributors
16-
maintainer: [email protected]
17-
copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors
18-
build-type: Simple
19-
tested-with: GHC ==8.10.7, GHC ==9.0.2, GHC ==9.2.8, GHC ==9.4.8, GHC ==9.6.4, GHC ==9.8.2
12+
homepage: http://docs.servant.dev/
13+
bug-reports: http://github.com/haskell-servant/servant/issues
14+
license: BSD-3-Clause
15+
license-file: LICENSE
16+
author: Servant Contributors
17+
maintainer: [email protected]
18+
copyright:
19+
2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors
20+
21+
build-type: Simple
22+
tested-with:
23+
GHC ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.4 || ==9.8.2
2024

2125
extra-source-files:
2226
CHANGELOG.md
2327
README.md
2428

2529
source-repository head
26-
type: git
27-
location: http://github.com/haskell-servant/servant.git
30+
type: git
31+
location: http://github.com/haskell-servant/servant.git
32+
33+
common extensions
34+
default-extensions:
35+
AllowAmbiguousTypes
36+
ConstraintKinds
37+
DataKinds
38+
DeriveAnyClass
39+
DeriveDataTypeable
40+
DeriveFunctor
41+
DeriveGeneric
42+
DerivingStrategies
43+
DerivingVia
44+
DuplicateRecordFields
45+
ExplicitNamespaces
46+
FlexibleContexts
47+
FlexibleInstances
48+
FunctionalDependencies
49+
GADTs
50+
InstanceSigs
51+
KindSignatures
52+
LambdaCase
53+
MultiParamTypeClasses
54+
NoStarIsType
55+
OverloadedLabels
56+
OverloadedStrings
57+
PackageImports
58+
PolyKinds
59+
RankNTypes
60+
RecordWildCards
61+
QuantifiedConstraints
62+
ScopedTypeVariables
63+
StrictData
64+
TupleSections
65+
TypeApplications
66+
TypeFamilies
67+
TypeOperators
68+
UndecidableInstances
69+
ViewPatterns
70+
71+
default-language: Haskell2010
72+
73+
common ghc-options
74+
ghc-options:
75+
-Wall -Wcompat -Widentities -Wincomplete-record-updates
76+
-Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
77+
-fhide-source-paths -Wno-unused-do-bind -fdicts-strict
78+
-Wno-unticked-promoted-constructors -Werror=unused-imports
79+
-Wunused-packages
2880

2981
library
82+
import: extensions
83+
import: ghc-options
3084
exposed-modules:
31-
Servant.Client.Core
32-
Servant.Client.Free
33-
Servant.Client.Generic
34-
Servant.Client.Core.Reexport
35-
Servant.Client.Core.Auth
36-
Servant.Client.Core.BaseUrl
37-
Servant.Client.Core.BasicAuth
38-
Servant.Client.Core.ClientError
39-
Servant.Client.Core.HasClient
40-
Servant.Client.Core.Request
41-
Servant.Client.Core.Response
42-
Servant.Client.Core.RunClient
85+
Servant.Client.Core
86+
Servant.Client.Core.Auth
87+
Servant.Client.Core.BaseUrl
88+
Servant.Client.Core.BasicAuth
89+
Servant.Client.Core.ClientError
90+
Servant.Client.Core.HasClient
91+
Servant.Client.Core.Reexport
92+
Servant.Client.Core.Request
93+
Servant.Client.Core.Response
94+
Servant.Client.Core.RunClient
95+
Servant.Client.Free
96+
Servant.Client.Generic
4397

44-
other-modules:
45-
Servant.Client.Core.Internal
98+
other-modules: Servant.Client.Core.Internal
4699

47100
-- Bundled with GHC: Lower bound to not force re-installs
48101
-- text and mtl are bundled starting with GHC-8.4
49102
--
50103
-- note: mtl lower bound is so low because of GHC-7.8
51104
build-depends:
52-
base >= 4.9 && < 4.20
53-
, bytestring >= 0.10.8.1 && < 0.13
54-
, constraints >= 0.2 && < 0.15
55-
, containers >= 0.5.7.1 && < 0.7
56-
, deepseq >= 1.4.2.0 && < 1.6
57-
, text >= 1.2.3.0 && < 2.2
58-
, template-haskell >= 2.11.1.0 && < 2.22
59-
60-
if !impl(ghc >= 8.2)
61-
build-depends:
62-
bifunctors >= 5.5.3 && < 5.7
105+
, base >=4.9 && <4.20
106+
, bytestring >=0.10.8.1 && <0.13
107+
, constraints >=0.2 && <0.15
108+
, containers >=0.5.7.1 && <0.7
109+
, deepseq >=1.4.2.0 && <1.6
110+
, template-haskell >=2.11.1.0 && <2.22
111+
, text >=1.2.3.0 && <2.2
63112

64113
-- Servant dependencies
65-
build-depends:
66-
servant >= 0.20
114+
build-depends: servant >=0.20
67115

68116
-- Other dependencies: Lower bound around what is in the latest Stackage LTS.
69117
-- Here can be exceptions if we really need features from the newer versions.
70118
build-depends:
71-
aeson >= 1.4.1.0 && < 3
72-
, base-compat >= 0.10.5 && < 0.14
73-
, base64-bytestring >= 1.0.0.1 && < 1.3
74-
, exceptions >= 0.10.0 && < 0.11
75-
, free >= 5.1 && < 5.3
76-
, http-media >= 0.7.1.3 && < 0.9
77-
, http-types >= 0.12.2 && < 0.13
78-
, network-uri >= 2.6.1.0 && < 2.7
79-
, safe >= 0.3.17 && < 0.4
80-
, sop-core >= 0.4.0.0 && < 0.6
81-
82-
hs-source-dirs: src
83-
default-language: Haskell2010
84-
ghc-options: -Wall
119+
, aeson >=1.4.1.0 && <3
120+
, base-compat >=0.10.5 && <0.14
121+
, base64-bytestring >=1.0.0.1 && <1.3
122+
, exceptions >=0.10.0 && <0.11
123+
, free >=5.1 && <5.3
124+
, http-media >=0.7.1.3 && <0.9
125+
, http-types >=0.12.2 && <0.13
126+
, network-uri >=2.6.1.0 && <2.7
127+
, safe >=0.3.17 && <0.4
128+
, sop-core >=0.4.0.0 && <0.6
129+
130+
hs-source-dirs: src
85131

86132
test-suite spec
87-
type: exitcode-stdio-1.0
88-
ghc-options: -Wall
89-
default-language: Haskell2010
90-
hs-source-dirs: test
91-
main-is: Spec.hs
133+
import: extensions
134+
import: ghc-options
135+
type: exitcode-stdio-1.0
136+
hs-source-dirs: test
137+
main-is: Spec.hs
92138
other-modules:
93-
Servant.Client.Core.Internal.BaseUrlSpec
94-
Servant.Client.Core.RequestSpec
139+
Servant.Client.Core.Internal.BaseUrlSpec
140+
Servant.Client.Core.RequestSpec
95141

96142
-- Dependencies inherited from the library. No need to specify bounds.
97143
build-depends:
98-
base
144+
, base
99145
, base-compat
100146
, servant-client-core
101147

102148
-- Additional dependencies
103149
build-depends:
104-
deepseq >= 1.4.2.0 && < 1.6
105-
, hspec >= 2.6.0 && < 2.12
106-
, QuickCheck >= 2.12.6.1 && < 2.15
150+
, deepseq >=1.4.2.0 && <1.6
151+
, hspec >=2.6.0 && <2.12
152+
, QuickCheck >=2.12.6.1 && <2.15
107153

108-
build-tool-depends:
109-
hspec-discover:hspec-discover >= 2.6.0 && <2.12
154+
build-tool-depends: hspec-discover:hspec-discover >=2.6.0 && <2.12

servant-client-core/src/Servant/Client/Core/Auth.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE OverloadedStrings #-}
21
{-# LANGUAGE TypeFamilies #-}
32
{-# LANGUAGE TypeSynonymInstances #-}
43

@@ -10,6 +9,8 @@ module Servant.Client.Core.Auth (
109
mkAuthenticatedRequest,
1110
) where
1211

12+
import Data.Kind (Type)
13+
1314
import Servant.Client.Core.Request
1415
(Request)
1516

@@ -18,7 +19,7 @@ import Servant.Client.Core.Request
1819
-- to a request
1920
--
2021
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
21-
type family AuthClientData a :: *
22+
type family AuthClientData a :: Type
2223

2324
-- | For better type inference and to avoid usage of a data family, we newtype
2425
-- wrap the combination of some 'AuthClientData' and a function to add authentication

servant-client-core/src/Servant/Client/Core/BaseUrl.hs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
{-# LANGUAGE DeriveDataTypeable #-}
2-
{-# LANGUAGE DeriveGeneric #-}
31
{-# LANGUAGE DeriveLift #-}
4-
{-# LANGUAGE ViewPatterns #-}
52
module Servant.Client.Core.BaseUrl (
63
BaseUrl (..),
74
Scheme (..),
@@ -21,7 +18,7 @@ import Data.Aeson.Types
2118
withText)
2219
import Data.Data
2320
(Data)
24-
import Data.List
21+
import qualified Data.List as List
2522
import qualified Data.Text as T
2623
import GHC.Generics
2724
import Language.Haskell.TH.Syntax
@@ -91,7 +88,7 @@ showBaseUrl :: BaseUrl -> String
9188
showBaseUrl (BaseUrl urlscheme host port path) =
9289
schemeString ++ "//" ++ host ++ (portString </> path)
9390
where
94-
a </> b = if "/" `isPrefixOf` b || null b then a ++ b else a ++ '/':b
91+
a </> b = if "/" `List.isPrefixOf` b || null b then a ++ b else a ++ '/':b
9592
schemeString = case urlscheme of
9693
Http -> "http:"
9794
Https -> "https:"
@@ -128,7 +125,7 @@ parseBaseUrl s = case parseURI (removeTrailingSlash s) of
128125
return (BaseUrl Https host port path)
129126
Just (URI "https:" (Just (URIAuth "" host "")) path "" "") ->
130127
return (BaseUrl Https host 443 path)
131-
_ -> if "://" `isInfixOf` s
128+
_ -> if "://" `List.isInfixOf` s
132129
then throwM (InvalidBaseUrlException $ "Invalid base URL: " ++ s)
133130
else parseBaseUrl ("http://" ++ s)
134131
where

servant-client-core/src/Servant/Client/Core/HasClient.hs

+4-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
{-# LANGUAGE ConstraintKinds #-}
2-
{-# LANGUAGE DataKinds #-}
3-
{-# LANGUAGE FlexibleContexts #-}
4-
{-# LANGUAGE FlexibleInstances #-}
5-
{-# LANGUAGE InstanceSigs #-}
6-
{-# LANGUAGE MultiParamTypeClasses #-}
7-
{-# LANGUAGE OverloadedStrings #-}
8-
{-# LANGUAGE PolyKinds #-}
9-
{-# LANGUAGE QuantifiedConstraints #-}
10-
{-# LANGUAGE RankNTypes #-}
11-
{-# LANGUAGE ScopedTypeVariables #-}
12-
{-# LANGUAGE TypeApplications #-}
13-
{-# LANGUAGE TypeFamilies #-}
14-
{-# LANGUAGE TypeOperators #-}
15-
{-# LANGUAGE UndecidableInstances #-}
16-
1+
{-# OPTIONS_GHC -Wno-missing-methods #-}
172
module Servant.Client.Core.HasClient (
183
clientIn,
194
HasClient (..),
@@ -32,7 +17,6 @@ import Control.Arrow
3217
(left, (+++))
3318
import Control.Monad
3419
(unless)
35-
import qualified Data.ByteString as BS
3620
import qualified Data.ByteString.Lazy as BL
3721
import Data.Either
3822
(partitionEithers)
@@ -81,7 +65,7 @@ import Servant.API
8165
ReflectMethod (..),
8266
StreamBody',
8367
Verb,
84-
getResponse, AuthProtect, BasicAuth, BasicAuthData, Capture', CaptureAll, DeepQuery, Description, Fragment, FramingRender (..), FramingUnrender (..), Header', Headers (..), HttpVersion, MimeRender (mimeRender), NoContent (NoContent), QueryFlag, QueryParam', QueryParams, QueryString, Raw, RawM, RemoteHost, ReqBody', SBoolI, Stream, Summary, ToHttpApiData, ToSourceIO (..), Vault, WithNamedContext, WithResource, WithStatus (..), contentType, getHeadersHList, toEncodedUrlPiece, toUrlPiece, NamedRoutes)
68+
getResponse, AuthProtect, BasicAuth, BasicAuthData, Capture', CaptureAll, DeepQuery, Description, Fragment, FramingRender (..), FramingUnrender (..), Header', Headers (..), HttpVersion, MimeRender (mimeRender), NoContent (NoContent), QueryFlag, QueryParam', QueryParams, QueryString, Raw, RawM, RemoteHost, ReqBody', SBoolI, Stream, Summary, ToHttpApiData, ToSourceIO (..), Vault, WithNamedContext, WithResource, WithStatus (..), contentType, getHeadersHList, toEncodedUrlPiece, NamedRoutes)
8569
import Servant.API.Generic
8670
(GenericMode(..), ToServant, ToServantApi
8771
, GenericServant, toServant, fromServant)
@@ -202,7 +186,7 @@ instance RunClient m => HasClient m EmptyAPI where
202186
-- > getBook :: Text -> ClientM Book
203187
-- > getBook = client myApi
204188
-- > -- then you can just use "getBook" to query that endpoint
205-
instance (KnownSymbol capture, ToHttpApiData a, HasClient m api)
189+
instance (ToHttpApiData a, HasClient m api)
206190
=> HasClient m (Capture' mods capture a :> api) where
207191

208192
type Client m (Capture' mods capture a :> api) =
@@ -237,7 +221,7 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m api)
237221
-- > getSourceFile :: [Text] -> ClientM SourceFile
238222
-- > getSourceFile = client myApi
239223
-- > -- then you can use "getSourceFile" to query that endpoint
240-
instance (KnownSymbol capture, ToHttpApiData a, HasClient m sublayout)
224+
instance (ToHttpApiData a, HasClient m sublayout)
241225
=> HasClient m (CaptureAll capture a :> sublayout) where
242226

243227
type Client m (CaptureAll capture a :> sublayout) =

servant-client-core/src/Servant/Client/Core/Request.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import Network.HTTP.Types
5454
(Header, HeaderName, HttpVersion (..), Method, Query, QueryItem,
5555
http11, methodGet, urlEncodeBuilder)
5656
import Servant.API
57-
(ToHttpApiData, toEncodedUrlPiece, toQueryParam, toHeader, SourceIO)
57+
(ToHttpApiData, toQueryParam, toHeader, SourceIO)
5858

5959
import Servant.Client.Core.Internal (mediaTypeRnf)
6060

0 commit comments

Comments
 (0)