named-servant 0.0.2 → 0.1.1
raw patch · 3 files changed
+55/−24 lines, 3 filesdep ~nameddep ~servantPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: named, servant
API changes (from Hackage documentation)
- Servant.Record: instance (GHC.Generics.Generic a, Servant.Record.GHasLink (GHC.Generics.Rep a ()) sub) => Servant.Links.HasLink (Servant.Record.RecordParam a Servant.API.Sub.:> sub)
- Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 GHC.Types.Bool) ()) sub
- Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Links.HasLink (a Servant.API.Sub.:> sub), Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 (GHC.Maybe.Maybe a)) ()) sub
- Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Links.HasLink (a Servant.API.Sub.:> sub), Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 [a]) ()) sub
- Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Links.HasLink (a Servant.API.Sub.:> sub), Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 a) ()) sub
- Servant.Record: instance (Servant.Links.HasLink sub, Servant.Record.GHasLink (a ()) (Servant.Record.GParam (b ()) Servant.API.Sub.:> sub)) => Servant.Record.GHasLink ((GHC.Generics.:*:) a b ()) sub
- Servant.Record: instance (Servant.Record.GHasLink (a ()) sub, Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.C1 m a ()) sub
- Servant.Record: instance Servant.Record.GHasLink (c m2 ()) sub => Servant.Record.GHasLink (GHC.Generics.D1 m (c m2) ()) sub
- Servant.Record: instance Servant.Record.GHasLink a sub => Servant.Links.HasLink (Servant.Record.GParam a Servant.API.Sub.:> sub)
+ Servant.Record: instance (GHC.Generics.Generic a, Servant.Record.GHasLink (GHC.Generics.Rep a) sub) => Servant.Links.HasLink (Servant.Record.RecordParam a Servant.API.Sub.:> sub)
+ Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 GHC.Types.Bool)) sub
+ Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Links.HasLink (a Servant.API.Sub.:> sub), Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 (GHC.Maybe.Maybe a))) sub
+ Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Links.HasLink (a Servant.API.Sub.:> sub), Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 [a])) sub
+ Servant.Record: instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Links.HasLink (a Servant.API.Sub.:> sub), Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just sym) d1 d2 d3) (GHC.Generics.Rec0 a)) sub
+ Servant.Record: instance (Servant.Links.HasLink sub, Servant.Record.GHasLink a (Servant.Record.GParam (b ()) Servant.API.Sub.:> sub)) => Servant.Record.GHasLink (a GHC.Generics.:*: b) sub
+ Servant.Record: instance (Servant.Record.GHasLink a sub, Servant.Links.HasLink sub) => Servant.Record.GHasLink (GHC.Generics.C1 m a) sub
+ Servant.Record: instance Servant.Record.GHasLink a sub => Servant.Links.HasLink (Servant.Record.GParam (a ()) Servant.API.Sub.:> sub)
+ Servant.Record: instance Servant.Record.GHasLink c sub => Servant.Record.GHasLink (GHC.Generics.D1 m c) sub
+ Servant.Record: type family UnRecordParam (x :: *) :: *
Files
- named-servant.cabal +3/−3
- src/Servant/Named.hs +6/−4
- src/Servant/Record.hs +46/−17
named-servant.cabal view
@@ -1,7 +1,7 @@ cabal-version: 1.12 name: named-servant description: support named parameters in servant using the named package-version: 0.0.2+version: 0.1.1 maintainer: kristof@resonata.be copyright: Kristof Bastiaensen 2020 license: BSD3@@ -22,5 +22,5 @@ src build-depends: base >= 4.7 && < 5,- servant,- named+ servant >= 0.17 && < 0.18,+ named >= 0.3 && < 0.4
src/Servant/Named.hs view
@@ -14,6 +14,7 @@ import Data.Proxy import GHC.TypeLits import Data.Functor.Identity+import Data.Maybe import Named -- | Like `QueryParam'`, but instead of extracting a type @a@, it@@ -46,16 +47,17 @@ -- the query parameter string. type NamedQueryParam = NamedQueryParam' [Required, Strict] --- | Like `QueryParams`, but extracts a named type @named `:!` [a]@+-- | Like `QueryParams`, but extracts a named type @named `:?` [a]@ -- instead, where named corresponds to the query parameter string. data NamedQueryParams (sym :: Symbol) (a :: *) instance (KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (NamedQueryParams sym v :> sub) where- type MkLink (NamedQueryParams sym v :> sub) a = sym :! [v] -> MkLink sub a- toLink toA _ l (Arg params) =- toLink toA (Proxy :: Proxy (QueryParams sym v :> sub)) l params+ type MkLink (NamedQueryParams sym v :> sub) a = sym :? [v] -> MkLink sub a+ toLink toA _ l (ArgF params) =+ toLink toA (Proxy :: Proxy (QueryParams sym v :> sub)) l $+ fromMaybe [] params -- | Like `QueryFlag, but extracts a named type @named `:!` Bool@ -- instead, where named corresponds to the query parameter string.
src/Servant/Record.hs view
@@ -9,7 +9,7 @@ {-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE MultiParamTypeClasses #-}-module Servant.Record (RecordParam) where+module Servant.Record (RecordParam, UnRecordParam) where import Servant.API import Data.Proxy import GHC.TypeLits@@ -17,8 +17,38 @@ data RecordParam (a :: *) -instance (Generic a, GHasLink (Rep a ()) sub) =>- HasLink (RecordParam a :> sub)+type family ServantAppend x y where+ ServantAppend (a :> b) c = a :> ServantAppend b c+ ServantAppend a c = a :> c++-- | Type family to rewrite a RecordParam Api to a regular servant API.+-- Useful to define instances for classes that extract information from+-- the API type, such as Servant.Swagger, or servant-foreign.+--+-- Typical use:+-- +-- > instance SomeClass (UnRecordParam (RecordParam a :> api))) =>+-- > SomeClass (RecordParam a :> api) where+-- > someMethod _ =+-- > someMethod (Proxy :: Proxy (UnRecordParam (RecordParam a :> api))++type family UnRecordParam (x :: *) :: * where+ UnRecordParam (a :> b) = ServantAppend (UnRecordParam a) b+ UnRecordParam (RecordParam a) = UnRecordParam (Rep a ())+ UnRecordParam (D1 m c d) = UnRecordParam (c d)+ UnRecordParam ((a :*: b) d) = ServantAppend (UnRecordParam (a d))+ (UnRecordParam (b d))+ UnRecordParam (C1 m a d) = UnRecordParam (a d)+ UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) d) =+ QueryFlag sym+ UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) d) =+ QueryParams sym a+ UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) d) =+ QueryParam' [Optional, Strict] sym a+ UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) d) =+ QueryParam' [Required, Strict] sym a+ +instance (Generic a, GHasLink (Rep a) sub) => HasLink (RecordParam a :> sub) where type MkLink (RecordParam a :> sub) b = a -> MkLink sub b toLink toA _ l record =@@ -26,28 +56,28 @@ data GParam a -instance GHasLink a sub => HasLink (GParam a :> sub) where- type MkLink (GParam a :> sub) b = a -> MkLink sub b+instance GHasLink a sub => HasLink (GParam (a ()) :> sub) where+ type MkLink (GParam (a ()) :> sub) b = a () -> MkLink sub b toLink toA _ = gToLink toA (Proxy :: Proxy sub) {-# INLINE toLink #-} -class HasLink sub => GHasLink a sub where- gToLink :: (Link -> b) -> Proxy sub -> Link -> a -> MkLink sub b+class HasLink sub => GHasLink (a :: * -> *) sub where+ gToLink :: (Link -> b) -> Proxy sub -> Link -> a () -> MkLink sub b -instance GHasLink (c m2 ()) sub => GHasLink (D1 m (c m2) ()) sub where+instance GHasLink c sub => GHasLink (D1 m c) sub where gToLink toA _ l (M1 x) = gToLink toA (Proxy :: Proxy sub) l x {-# INLINE gToLink #-} instance ( HasLink sub- , GHasLink (a ()) (GParam (b ()) :> sub)+ , GHasLink a (GParam (b ()) :> sub) )- => GHasLink ((a :*: b) ()) sub where+ => GHasLink (a :*: b) sub where gToLink toA _ l (a :*: b) = gToLink toA (Proxy :: Proxy (GParam (b ()) :> sub)) l a b {-# INLINE gToLink #-} -instance (GHasLink (a ()) sub, HasLink sub) =>- GHasLink (C1 m a ()) sub where+instance (GHasLink a sub, HasLink sub) =>+ GHasLink (C1 m a) sub where gToLink toA _ l (M1 x) = gToLink toA (Proxy :: Proxy sub) l x {-# INLINE gToLink #-} @@ -55,7 +85,7 @@ ( KnownSymbol sym , HasLink sub ) =>- GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) ()) sub where+ GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool)) sub where gToLink toA _ l (M1 (K1 x)) = toLink toA (Proxy :: Proxy (QueryFlag sym :> sub)) l x {-# INLINE gToLink #-}@@ -65,7 +95,7 @@ , ToHttpApiData a , HasLink (a :> sub) , HasLink sub) =>- GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) ()) sub where+ GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a])) sub where gToLink toA _ l (M1 (K1 x)) = toLink toA (Proxy :: Proxy (QueryParams sym a :> sub)) l x {-# INLINE gToLink #-}@@ -75,7 +105,7 @@ , ToHttpApiData a , HasLink (a :> sub) , HasLink sub) =>- GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) ()) sub where+ GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a))) sub where gToLink toA _ l (M1 (K1 x)) = toLink toA (Proxy :: Proxy (QueryParam' '[Optional, Strict] sym a :> sub)) l x@@ -86,9 +116,8 @@ , ToHttpApiData a , HasLink (a :> sub) , HasLink sub) =>- GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) ()) sub where+ GHasLink (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a)) sub where gToLink toA _ l (M1 (K1 x)) = toLink toA (Proxy :: Proxy (QueryParam' '[Required, Strict] sym a :> sub)) l x {-# INLINE gToLink #-}-