Skip to content

Commit

Permalink
codebase clean-up (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
tchoutri authored May 5, 2024
1 parent d33f626 commit 2af8e96
Show file tree
Hide file tree
Showing 28 changed files with 560 additions and 454 deletions.
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ packages:

tests: True
optimization: False

-- Development flags
package *
ghc-options: -fshow-hole-constraints -fhide-source-paths

-- reorder-goals: True

-- Print ticks so that doctest type querying is consistent across GHC versions.
Expand Down
185 changes: 115 additions & 70 deletions servant-client-core/servant-client-core.cabal
Original file line number Diff line number Diff line change
@@ -1,109 +1,154 @@
cabal-version: 2.2
name: servant-client-core
version: 0.20
cabal-version: 3.0
name: servant-client-core
version: 0.20
synopsis:
Core functionality and class for client function generation for servant APIs

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

homepage: http://docs.servant.dev/
bug-reports: http://github.com/haskell-servant/servant/issues
license: BSD-3-Clause
license-file: LICENSE
author: Servant Contributors
maintainer: haskell-servant-maintainers@googlegroups.com
copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors
build-type: Simple
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
homepage: http://docs.servant.dev/
bug-reports: http://github.com/haskell-servant/servant/issues
license: BSD-3-Clause
license-file: LICENSE
author: Servant Contributors
maintainer: haskell-servant-maintainers@googlegroups.com
copyright:
2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors

build-type: Simple
tested-with:
GHC ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.4 || ==9.8.2

extra-source-files:
CHANGELOG.md
README.md

source-repository head
type: git
location: http://github.com/haskell-servant/servant.git
type: git
location: http://github.com/haskell-servant/servant.git

common extensions
default-extensions:
AllowAmbiguousTypes
ConstraintKinds
DataKinds
DeriveAnyClass
DeriveDataTypeable
DeriveFunctor
DeriveGeneric
DerivingStrategies
DerivingVia
DuplicateRecordFields
ExplicitNamespaces
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
InstanceSigs
KindSignatures
LambdaCase
MultiParamTypeClasses
NoStarIsType
OverloadedLabels
OverloadedStrings
PackageImports
PolyKinds
RankNTypes
RecordWildCards
QuantifiedConstraints
ScopedTypeVariables
StrictData
TupleSections
TypeApplications
TypeFamilies
TypeOperators
UndecidableInstances
ViewPatterns

default-language: Haskell2010

common ghc-options
ghc-options:
-Wall -Wcompat -Widentities -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
-fhide-source-paths -Wno-unused-do-bind -fdicts-strict
-Wno-unticked-promoted-constructors -Werror=unused-imports
-Wunused-packages

library
import: extensions
import: ghc-options
exposed-modules:
Servant.Client.Core
Servant.Client.Free
Servant.Client.Generic
Servant.Client.Core.Reexport
Servant.Client.Core.Auth
Servant.Client.Core.BaseUrl
Servant.Client.Core.BasicAuth
Servant.Client.Core.ClientError
Servant.Client.Core.HasClient
Servant.Client.Core.Request
Servant.Client.Core.Response
Servant.Client.Core.RunClient
Servant.Client.Core
Servant.Client.Core.Auth
Servant.Client.Core.BaseUrl
Servant.Client.Core.BasicAuth
Servant.Client.Core.ClientError
Servant.Client.Core.HasClient
Servant.Client.Core.Reexport
Servant.Client.Core.Request
Servant.Client.Core.Response
Servant.Client.Core.RunClient
Servant.Client.Free
Servant.Client.Generic

other-modules:
Servant.Client.Core.Internal
other-modules: Servant.Client.Core.Internal

-- Bundled with GHC: Lower bound to not force re-installs
-- text and mtl are bundled starting with GHC-8.4
--
-- note: mtl lower bound is so low because of GHC-7.8
build-depends:
base >= 4.9 && < 4.20
, bytestring >= 0.10.8.1 && < 0.13
, constraints >= 0.2 && < 0.15
, containers >= 0.5.7.1 && < 0.7
, deepseq >= 1.4.2.0 && < 1.6
, text >= 1.2.3.0 && < 2.2
, template-haskell >= 2.11.1.0 && < 2.22

if !impl(ghc >= 8.2)
build-depends:
bifunctors >= 5.5.3 && < 5.7
, base >=4.9 && <4.20
, bytestring >=0.10.8.1 && <0.13
, constraints >=0.2 && <0.15
, containers >=0.5.7.1 && <0.7
, deepseq >=1.4.2.0 && <1.6
, template-haskell >=2.11.1.0 && <2.22
, text >=1.2.3.0 && <2.2

-- Servant dependencies
build-depends:
servant >= 0.20
build-depends: servant >=0.20

-- Other dependencies: Lower bound around what is in the latest Stackage LTS.
-- Here can be exceptions if we really need features from the newer versions.
build-depends:
aeson >= 1.4.1.0 && < 3
, base-compat >= 0.10.5 && < 0.14
, base64-bytestring >= 1.0.0.1 && < 1.3
, exceptions >= 0.10.0 && < 0.11
, free >= 5.1 && < 5.3
, http-media >= 0.7.1.3 && < 0.9
, http-types >= 0.12.2 && < 0.13
, network-uri >= 2.6.1.0 && < 2.7
, safe >= 0.3.17 && < 0.4
, sop-core >= 0.4.0.0 && < 0.6

hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall
, aeson >=1.4.1.0 && <3
, base-compat >=0.10.5 && <0.14
, base64-bytestring >=1.0.0.1 && <1.3
, exceptions >=0.10.0 && <0.11
, free >=5.1 && <5.3
, http-media >=0.7.1.3 && <0.9
, http-types >=0.12.2 && <0.13
, network-uri >=2.6.1.0 && <2.7
, safe >=0.3.17 && <0.4
, sop-core >=0.4.0.0 && <0.6

hs-source-dirs: src

test-suite spec
type: exitcode-stdio-1.0
ghc-options: -Wall
default-language: Haskell2010
hs-source-dirs: test
main-is: Spec.hs
import: extensions
import: ghc-options
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
other-modules:
Servant.Client.Core.Internal.BaseUrlSpec
Servant.Client.Core.RequestSpec
Servant.Client.Core.Internal.BaseUrlSpec
Servant.Client.Core.RequestSpec

-- Dependencies inherited from the library. No need to specify bounds.
build-depends:
base
, base
, base-compat
, servant-client-core

-- Additional dependencies
build-depends:
deepseq >= 1.4.2.0 && < 1.6
, hspec >= 2.6.0 && < 2.12
, QuickCheck >= 2.12.6.1 && < 2.15
, deepseq >=1.4.2.0 && <1.6
, hspec >=2.6.0 && <2.12
, QuickCheck >=2.12.6.1 && <2.15

build-tool-depends:
hspec-discover:hspec-discover >= 2.6.0 && <2.12
build-tool-depends: hspec-discover:hspec-discover >=2.6.0 && <2.12
5 changes: 3 additions & 2 deletions servant-client-core/src/Servant/Client/Core/Auth.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}

Expand All @@ -10,6 +9,8 @@ module Servant.Client.Core.Auth (
mkAuthenticatedRequest,
) where

import Data.Kind (Type)

import Servant.Client.Core.Request
(Request)

Expand All @@ -18,7 +19,7 @@ import Servant.Client.Core.Request
-- to a request
--
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
type family AuthClientData a :: *
type family AuthClientData a :: Type

-- | For better type inference and to avoid usage of a data family, we newtype
-- wrap the combination of some 'AuthClientData' and a function to add authentication
Expand Down
9 changes: 3 additions & 6 deletions servant-client-core/src/Servant/Client/Core/BaseUrl.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE ViewPatterns #-}
module Servant.Client.Core.BaseUrl (
BaseUrl (..),
Scheme (..),
Expand All @@ -21,7 +18,7 @@ import Data.Aeson.Types
withText)
import Data.Data
(Data)
import Data.List
import qualified Data.List as List
import qualified Data.Text as T
import GHC.Generics
import Language.Haskell.TH.Syntax
Expand Down Expand Up @@ -91,7 +88,7 @@ showBaseUrl :: BaseUrl -> String
showBaseUrl (BaseUrl urlscheme host port path) =
schemeString ++ "//" ++ host ++ (portString </> path)
where
a </> b = if "/" `isPrefixOf` b || null b then a ++ b else a ++ '/':b
a </> b = if "/" `List.isPrefixOf` b || null b then a ++ b else a ++ '/':b
schemeString = case urlscheme of
Http -> "http:"
Https -> "https:"
Expand Down Expand Up @@ -128,7 +125,7 @@ parseBaseUrl s = case parseURI (removeTrailingSlash s) of
return (BaseUrl Https host port path)
Just (URI "https:" (Just (URIAuth "" host "")) path "" "") ->
return (BaseUrl Https host 443 path)
_ -> if "://" `isInfixOf` s
_ -> if "://" `List.isInfixOf` s
then throwM (InvalidBaseUrlException $ "Invalid base URL: " ++ s)
else parseBaseUrl ("http://" ++ s)
where
Expand Down
24 changes: 4 additions & 20 deletions servant-client-core/src/Servant/Client/Core/HasClient.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -Wno-missing-methods #-}
module Servant.Client.Core.HasClient (
clientIn,
HasClient (..),
Expand All @@ -32,7 +17,6 @@ import Control.Arrow
(left, (+++))
import Control.Monad
(unless)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import Data.Either
(partitionEithers)
Expand Down Expand Up @@ -81,7 +65,7 @@ import Servant.API
ReflectMethod (..),
StreamBody',
Verb,
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)
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)
import Servant.API.Generic
(GenericMode(..), ToServant, ToServantApi
, GenericServant, toServant, fromServant)
Expand Down Expand Up @@ -202,7 +186,7 @@ instance RunClient m => HasClient m EmptyAPI where
-- > getBook :: Text -> ClientM Book
-- > getBook = client myApi
-- > -- then you can just use "getBook" to query that endpoint
instance (KnownSymbol capture, ToHttpApiData a, HasClient m api)
instance (ToHttpApiData a, HasClient m api)
=> HasClient m (Capture' mods capture a :> api) where

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

type Client m (CaptureAll capture a :> sublayout) =
Expand Down
2 changes: 1 addition & 1 deletion servant-client-core/src/Servant/Client/Core/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Network.HTTP.Types
(Header, HeaderName, HttpVersion (..), Method, Query, QueryItem,
http11, methodGet, urlEncodeBuilder)
import Servant.API
(ToHttpApiData, toEncodedUrlPiece, toQueryParam, toHeader, SourceIO)
(ToHttpApiData, toQueryParam, toHeader, SourceIO)

import Servant.Client.Core.Internal (mediaTypeRnf)

Expand Down
Loading

0 comments on commit 2af8e96

Please sign in to comment.