{-# LANGUAGE UndecidableInstances #-}
module Servant.Hateoas.Layer.Build
(
ReplaceHandler,
BuildLayerLinks(..),
)
where
import Servant
import Servant.API.ContentTypes
import Servant.Hateoas.Resource
import Servant.Hateoas.RelationLink
import Servant.Hateoas.Layer.Type
import Servant.Hateoas.Internal.Sym
import Servant.Hateoas.Internal.Polyvariadic
import Data.Kind
import Control.Monad.IO.Class
import GHC.TypeLits
type family ReplaceHandler server replacement where
ReplaceHandler (a :<|> b) replacement = ReplaceHandler a replacement :<|> ReplaceHandler b replacement
ReplaceHandler (a -> b) replacement = a -> ReplaceHandler b replacement
ReplaceHandler _ replacement = replacement
type BuildLayerLinks :: Layer -> (Type -> Type) -> Constraint
class BuildLayerLinks l m where
buildLayerLinks :: MonadIO m => Proxy l -> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
instance
( api ~ MkPrefix apiCs verb
, HasLink api, IsElem api api
, mkSelf ~ MkLink api Link
, PolyvariadicComp mkSelf (IsFun mkSelf)
, Return mkSelf (IsFun mkSelf) ~ Link
, Replace mkSelf [(String, ResourceLink)] (IsFun mkSelf) ~ ReplaceHandler (ServerT api m) [(String, ResourceLink)]
) => BuildLayerLinks ('Layer apiCs '[] verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs '[] verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs '[] verb) m) [(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs '[] verb)
_ Proxy m
_ = (forall (f :: * -> *) a. Applicative f => a -> f a
pure @[] ((String, ResourceLink) -> [(String, ResourceLink)])
-> (Link -> (String, ResourceLink))
-> Link
-> [(String, ResourceLink)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
"self", ) (ResourceLink -> (String, ResourceLink))
-> (Link -> ResourceLink) -> Link -> (String, ResourceLink)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> ResourceLink
CompleteLink) (Return mkSelf (IsFun mkSelf) -> [(String, ResourceLink)])
-> mkSelf -> Replace mkSelf [(String, ResourceLink)] (IsFun mkSelf)
forall f (b :: Bool) r.
(PolyvariadicComp f b, IsFun f ~ b) =>
(Return f b -> r) -> f -> Replace f r b
... mkSelf
MkLink api Link
mkSelf
where
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
instance
( c ~ MkPrefix (apiCs ++ '[Sym sym]) verb
, HasLink c, IsElem c c
, mkLink ~ MkLink c Link
, KnownSymbol sym
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT (MkPrefix apiCs verb) m) [(String, ResourceLink)])
, PolyvariadicComp2 mkLink buildLinksFun (IsFun mkLink)
, Return2 mkLink buildLinksFun (IsFun mkLink) ~ (Link, [(String, ResourceLink)])
, Replace2 mkLink buildLinksFun [(String, ResourceLink)] (IsFun mkLink) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (Sym sym ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (Sym sym : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (Sym sym : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (Sym sym : cs) verb)
_ Proxy m
m = (Return2 mkLink buildLinksFun (IsFun buildLinksFun)
-> [(String, ResourceLink)])
-> mkLink
-> buildLinksFun
-> Replace2
mkLink buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun)
forall r.
(Return2 mkLink buildLinksFun (IsFun buildLinksFun) -> r)
-> mkLink
-> buildLinksFun
-> Replace2 mkLink buildLinksFun r (IsFun buildLinksFun)
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
l, [(String, ResourceLink)]
ls) -> (Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym), Link -> ResourceLink
CompleteLink Link
l) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) mkLink
MkLink c Link
mkLink buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
mkLink :: MkLink c Link
mkLink = Proxy c -> Proxy c -> MkLink c Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @c)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
instance
( verb ~ Verb method status cts a
, AllMime cts, ReflectMethod method
, api ~ MkPrefix apiCs verb
, KnownSymbol sym
, HasRelationLink (MkPrefix '[Capture' mods sym x] verb)
, IsElem api api, HasLink api
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT api m) [(String, ResourceLink)])
, PolyvariadicComp2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun)
, Return2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun) ~ (Link, [(String, ResourceLink)])
, Replace2 (MkLink api Link) buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (Capture' mods sym x ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (Capture' mods sym x : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (Capture' mods sym x : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (Capture' mods sym x : cs) verb)
_ Proxy m
m = (Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> [(String, ResourceLink)])
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link)
buildLinksFun
[(String, ResourceLink)]
(IsFun (MkLink api Link))
forall r.
(Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> r)
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link) buildLinksFun r (IsFun (MkLink api Link))
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
self, [(String, ResourceLink)]
ls) -> (String
relName, Link -> ResourceLink
mkTemplatedNext Link
self) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) MkLink api Link
mkSelf buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
relName :: String
relName = Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym)
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
child :: RelationLink
child = Proxy (Capture' mods sym x :> Verb method status cts a)
-> RelationLink
forall {k} (endpoint :: k).
HasRelationLink endpoint =>
Proxy endpoint -> RelationLink
toRelationLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MkPrefix '[Capture' mods sym x] verb))
mkTemplatedNext :: Link -> ResourceLink
mkTemplatedNext = RelationLink -> ResourceLink
TemplateLink
(RelationLink -> ResourceLink)
-> (Link -> RelationLink) -> Link -> ResourceLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RelationLink
rl -> RelationLink
rl { _path = _path rl `appendPath` _path child, _templated = True })
(RelationLink -> RelationLink)
-> (Link -> RelationLink) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MediaType] -> StdMethod -> URI -> RelationLink
fromURI (Proxy cts -> [MediaType]
forall (list :: [*]). AllMime list => Proxy list -> [MediaType]
allMime (Proxy cts -> [MediaType]) -> Proxy cts -> [MediaType]
forall a b. (a -> b) -> a -> b
$ forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @cts) (Proxy method -> StdMethod
forall {k} (method :: k).
ReflectMethod method =>
Proxy method -> StdMethod
reflectStdMethod (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @method))
(URI -> RelationLink) -> (Link -> URI) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> URI
linkURI
instance
( verb ~ Verb method status cts a
, AllMime cts, ReflectMethod method
, api ~ MkPrefix apiCs verb
, KnownSymbol sym
, HasRelationLink (MkPrefix '[CaptureAll sym x] verb)
, IsElem api api, HasLink api
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT api m) [(String, ResourceLink)])
, PolyvariadicComp2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun)
, Return2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun) ~ (Link, [(String, ResourceLink)])
, Replace2 (MkLink api Link) buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (CaptureAll sym x ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (CaptureAll sym x : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (CaptureAll sym x : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (CaptureAll sym x : cs) verb)
_ Proxy m
m = (Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> [(String, ResourceLink)])
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link)
buildLinksFun
[(String, ResourceLink)]
(IsFun (MkLink api Link))
forall r.
(Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> r)
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link) buildLinksFun r (IsFun (MkLink api Link))
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
self, [(String, ResourceLink)]
ls) -> (String
relName, Link -> ResourceLink
mkTemplatedNext Link
self) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) MkLink api Link
mkSelf buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
relName :: String
relName = Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym)
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
child :: RelationLink
child = Proxy (CaptureAll sym x :> Verb method status cts a)
-> RelationLink
forall {k} (endpoint :: k).
HasRelationLink endpoint =>
Proxy endpoint -> RelationLink
toRelationLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MkPrefix '[CaptureAll sym x] verb))
mkTemplatedNext :: Link -> ResourceLink
mkTemplatedNext = RelationLink -> ResourceLink
TemplateLink
(RelationLink -> ResourceLink)
-> (Link -> RelationLink) -> Link -> ResourceLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RelationLink
rl -> RelationLink
rl { _path = _path rl `appendPath` _path child, _templated = True })
(RelationLink -> RelationLink)
-> (Link -> RelationLink) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MediaType] -> StdMethod -> URI -> RelationLink
fromURI (Proxy cts -> [MediaType]
forall (list :: [*]). AllMime list => Proxy list -> [MediaType]
allMime (Proxy cts -> [MediaType]) -> Proxy cts -> [MediaType]
forall a b. (a -> b) -> a -> b
$ forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @cts) (Proxy method -> StdMethod
forall {k} (method :: k).
ReflectMethod method =>
Proxy method -> StdMethod
reflectStdMethod (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @method))
(URI -> RelationLink) -> (Link -> URI) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> URI
linkURI
instance
( verb ~ Verb method status cts a
, AllMime cts, ReflectMethod method
, api ~ MkPrefix apiCs verb
, KnownSymbol sym
, HasRelationLink (MkPrefix '[QueryParam' mods sym x] verb)
, IsElem api api, HasLink api
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT api m) [(String, ResourceLink)])
, PolyvariadicComp2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun)
, Return2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun) ~ (Link, [(String, ResourceLink)])
, Replace2 (MkLink api Link) buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (QueryParam' mods sym x ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (QueryParam' mods sym x : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (QueryParam' mods sym x : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (QueryParam' mods sym x : cs) verb)
_ Proxy m
m = (Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> [(String, ResourceLink)])
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link)
buildLinksFun
[(String, ResourceLink)]
(IsFun (MkLink api Link))
forall r.
(Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> r)
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link) buildLinksFun r (IsFun (MkLink api Link))
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
self, [(String, ResourceLink)]
ls) -> (String
relName, Link -> ResourceLink
mkTemplatedNext Link
self) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) MkLink api Link
mkSelf buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
relName :: String
relName = Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym)
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
child :: RelationLink
child = Proxy (QueryParam' mods sym x :> Verb method status cts a)
-> RelationLink
forall {k} (endpoint :: k).
HasRelationLink endpoint =>
Proxy endpoint -> RelationLink
toRelationLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MkPrefix '[QueryParam' mods sym x] verb))
mkTemplatedNext :: Link -> ResourceLink
mkTemplatedNext = RelationLink -> ResourceLink
TemplateLink
(RelationLink -> ResourceLink)
-> (Link -> RelationLink) -> Link -> ResourceLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RelationLink
rl -> RelationLink
rl { _params = _params rl ++ _params child, _templated = True })
(RelationLink -> RelationLink)
-> (Link -> RelationLink) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MediaType] -> StdMethod -> URI -> RelationLink
fromURI (Proxy cts -> [MediaType]
forall (list :: [*]). AllMime list => Proxy list -> [MediaType]
allMime (Proxy cts -> [MediaType]) -> Proxy cts -> [MediaType]
forall a b. (a -> b) -> a -> b
$ forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @cts) (Proxy method -> StdMethod
forall {k} (method :: k).
ReflectMethod method =>
Proxy method -> StdMethod
reflectStdMethod (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @method))
(URI -> RelationLink) -> (Link -> URI) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> URI
linkURI
instance
( verb ~ Verb method status cts a
, AllMime cts, ReflectMethod method
, api ~ MkPrefix apiCs verb
, KnownSymbol sym
, HasRelationLink (MkPrefix '[QueryParams sym x] verb)
, IsElem api api, HasLink api
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT api m) [(String, ResourceLink)])
, PolyvariadicComp2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun)
, Return2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun) ~ (Link, [(String, ResourceLink)])
, Replace2 (MkLink api Link) buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (QueryParams sym x ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (QueryParams sym x : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (QueryParams sym x : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (QueryParams sym x : cs) verb)
_ Proxy m
m = (Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> [(String, ResourceLink)])
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link)
buildLinksFun
[(String, ResourceLink)]
(IsFun (MkLink api Link))
forall r.
(Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> r)
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link) buildLinksFun r (IsFun (MkLink api Link))
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
self, [(String, ResourceLink)]
ls) -> (String
relName, Link -> ResourceLink
mkTemplatedNext Link
self) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) MkLink api Link
mkSelf buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
relName :: String
relName = Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym)
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
child :: RelationLink
child = Proxy (QueryParams sym x :> Verb method status cts a)
-> RelationLink
forall {k} (endpoint :: k).
HasRelationLink endpoint =>
Proxy endpoint -> RelationLink
toRelationLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MkPrefix '[QueryParams sym x] verb))
mkTemplatedNext :: Link -> ResourceLink
mkTemplatedNext = RelationLink -> ResourceLink
TemplateLink
(RelationLink -> ResourceLink)
-> (Link -> RelationLink) -> Link -> ResourceLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RelationLink
rl -> RelationLink
rl { _params = _params rl ++ _params child, _templated = True })
(RelationLink -> RelationLink)
-> (Link -> RelationLink) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MediaType] -> StdMethod -> URI -> RelationLink
fromURI (Proxy cts -> [MediaType]
forall (list :: [*]). AllMime list => Proxy list -> [MediaType]
allMime (Proxy cts -> [MediaType]) -> Proxy cts -> [MediaType]
forall a b. (a -> b) -> a -> b
$ forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @cts) (Proxy method -> StdMethod
forall {k} (method :: k).
ReflectMethod method =>
Proxy method -> StdMethod
reflectStdMethod (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @method))
(URI -> RelationLink) -> (Link -> URI) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> URI
linkURI
instance
( verb ~ Verb method status cts a
, AllMime cts, ReflectMethod method
, api ~ MkPrefix apiCs verb
, KnownSymbol sym
, HasRelationLink (MkPrefix '[DeepQuery sym x] verb)
, IsElem api api, HasLink api
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT api m) [(String, ResourceLink)])
, PolyvariadicComp2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun)
, Return2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun) ~ (Link, [(String, ResourceLink)])
, Replace2 (MkLink api Link) buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (DeepQuery sym x ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (DeepQuery sym x : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (DeepQuery sym x : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (DeepQuery sym x : cs) verb)
_ Proxy m
m = (Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> [(String, ResourceLink)])
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link)
buildLinksFun
[(String, ResourceLink)]
(IsFun (MkLink api Link))
forall r.
(Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> r)
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link) buildLinksFun r (IsFun (MkLink api Link))
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
self, [(String, ResourceLink)]
ls) -> (String
relName, Link -> ResourceLink
mkTemplatedNext Link
self) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) MkLink api Link
mkSelf buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
relName :: String
relName = Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym)
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
child :: RelationLink
child = Proxy (DeepQuery sym x :> Verb method status cts a) -> RelationLink
forall {k} (endpoint :: k).
HasRelationLink endpoint =>
Proxy endpoint -> RelationLink
toRelationLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MkPrefix '[DeepQuery sym x] verb))
mkTemplatedNext :: Link -> ResourceLink
mkTemplatedNext = RelationLink -> ResourceLink
TemplateLink
(RelationLink -> ResourceLink)
-> (Link -> RelationLink) -> Link -> ResourceLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RelationLink
rl -> RelationLink
rl { _params = _params rl ++ _params child, _templated = True })
(RelationLink -> RelationLink)
-> (Link -> RelationLink) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MediaType] -> StdMethod -> URI -> RelationLink
fromURI (Proxy cts -> [MediaType]
forall (list :: [*]). AllMime list => Proxy list -> [MediaType]
allMime (Proxy cts -> [MediaType]) -> Proxy cts -> [MediaType]
forall a b. (a -> b) -> a -> b
$ forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @cts) (Proxy method -> StdMethod
forall {k} (method :: k).
ReflectMethod method =>
Proxy method -> StdMethod
reflectStdMethod (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @method))
(URI -> RelationLink) -> (Link -> URI) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> URI
linkURI
instance
( verb ~ Verb method status cts a
, AllMime cts, ReflectMethod method
, api ~ MkPrefix apiCs verb
, KnownSymbol sym
, HasRelationLink (MkPrefix '[QueryFlag sym] verb)
, IsElem api api, HasLink api
, BuildLayerLinks ('Layer apiCs cs verb) m
, buildLinksFun ~ (ReplaceHandler (ServerT api m) [(String, ResourceLink)])
, PolyvariadicComp2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun)
, Return2 (MkLink api Link) buildLinksFun (IsFun buildLinksFun) ~ (Link, [(String, ResourceLink)])
, Replace2 (MkLink api Link) buildLinksFun [(String, ResourceLink)] (IsFun buildLinksFun) ~ buildLinksFun
) => BuildLayerLinks ('Layer apiCs (QueryFlag sym ': cs) verb) m where
buildLayerLinks :: MonadIO m =>
Proxy ('Layer apiCs (QueryFlag sym : cs) verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs (QueryFlag sym : cs) verb) m)
[(String, ResourceLink)]
buildLayerLinks Proxy ('Layer apiCs (QueryFlag sym : cs) verb)
_ Proxy m
m = (Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> [(String, ResourceLink)])
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link)
buildLinksFun
[(String, ResourceLink)]
(IsFun (MkLink api Link))
forall r.
(Return2 (MkLink api Link) buildLinksFun (IsFun (MkLink api Link))
-> r)
-> MkLink api Link
-> buildLinksFun
-> Replace2
(MkLink api Link) buildLinksFun r (IsFun (MkLink api Link))
forall f g (b :: Bool) r.
PolyvariadicComp2 f g b =>
(Return2 f g b -> r) -> f -> g -> Replace2 f g r b
pcomp2 (\(Link
self, [(String, ResourceLink)]
ls) -> (String
relName, Link -> ResourceLink
mkTemplatedNext Link
self) (String, ResourceLink)
-> [(String, ResourceLink)] -> [(String, ResourceLink)]
forall a. a -> [a] -> [a]
: [(String, ResourceLink)]
ls) MkLink api Link
mkSelf buildLinksFun
ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks
where
relName :: String
relName = Proxy sym -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @sym)
mkSelf :: MkLink api Link
mkSelf = Proxy api -> Proxy api -> MkLink api Link
forall endpoint api.
(IsElem endpoint api, HasLink endpoint) =>
Proxy api -> Proxy endpoint -> MkLink endpoint Link
safeLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @api)
mkLinks :: ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
mkLinks = Proxy ('Layer apiCs cs verb)
-> Proxy m
-> ReplaceHandler
(ServerT ('Layer apiCs cs verb) m) [(String, ResourceLink)]
forall (l :: Layer) (m :: * -> *).
(BuildLayerLinks l m, MonadIO m) =>
Proxy l
-> Proxy m -> ReplaceHandler (ServerT l m) [(String, ResourceLink)]
buildLayerLinks (forall {k} (t :: k). Proxy t
forall (t :: Layer). Proxy t
Proxy @('Layer apiCs cs verb)) Proxy m
m
child :: RelationLink
child = Proxy (QueryFlag sym :> Verb method status cts a) -> RelationLink
forall {k} (endpoint :: k).
HasRelationLink endpoint =>
Proxy endpoint -> RelationLink
toRelationLink (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MkPrefix '[QueryFlag sym] verb))
mkTemplatedNext :: Link -> ResourceLink
mkTemplatedNext = RelationLink -> ResourceLink
TemplateLink
(RelationLink -> ResourceLink)
-> (Link -> RelationLink) -> Link -> ResourceLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RelationLink
rl -> RelationLink
rl { _params = _params rl ++ _params child, _templated = True })
(RelationLink -> RelationLink)
-> (Link -> RelationLink) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MediaType] -> StdMethod -> URI -> RelationLink
fromURI (Proxy cts -> [MediaType]
forall (list :: [*]). AllMime list => Proxy list -> [MediaType]
allMime (Proxy cts -> [MediaType]) -> Proxy cts -> [MediaType]
forall a b. (a -> b) -> a -> b
$ forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @cts) (Proxy method -> StdMethod
forall {k} (method :: k).
ReflectMethod method =>
Proxy method -> StdMethod
reflectStdMethod (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @method))
(URI -> RelationLink) -> (Link -> URI) -> Link -> RelationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Link -> URI
linkURI