servant-hateoas-0.3.4: HATEOAS extension for servant
Safe HaskellSafe-Inferred
LanguageGHC2021

Servant.Hateoas.Layer

Synopsis

Create

type family MkLayers api where ... Source #

Given an API, create a list of Layers that represents the HATEOAS structure of the API.

This is done by:

  1. Rewriting every (sym :: Symbol) :> b into Sym sym :> b so all subsets of the API have kind Type, see Symify.
  2. Normalizing the API to make every node-choice unambiguous, see Normalize.
  3. Creating all intermediate layers of the API and their immediate next layers, see GoLayers.
  4. Merging the immediate next layers of all layers that share the same API, see MergeLayers.

Equations

MkLayers api = MergeLayers (GoLayers (Normalize (Symify api)) '[]) '[] 

Type

Build

Merge

Utilities

type family GoLayers api stand where ... Source #

Creates all intermediate layers of the API and their immediate next layers.

This is done by traversing the API-Tree where in GoLayers api stand, api is the API seen below from stand.

Argument stand therefore also represents an API, but due to the right-associative nature of :> we model it as a list here, which can be turned into an API by folding it with :>, see MkPrefix.

Equations

GoLayers (a :<|> b) prefix = GoLayers a prefix ++ GoLayers b prefix 
GoLayers (Sym a :> b) prefix = '['Layer prefix '[Sym a] GetIntermediate] ++ GoLayers b (prefix ++ '[Sym a]) 
GoLayers (Capture' mods sym a :> b) prefix = '['Layer prefix '[Capture' mods sym a] GetIntermediate] ++ GoLayers b (prefix ++ '[Capture' mods sym a]) 
GoLayers (CaptureAll sym a :> b) prefix = '['Layer prefix '[CaptureAll sym a] GetIntermediate] ++ GoLayers b (prefix ++ '[CaptureAll sym a]) 
GoLayers (QueryParam' mods sym a :> b) prefix = '['Layer prefix '[QueryParam' mods sym a] GetIntermediate] ++ GoLayers b prefix 
GoLayers (QueryParams sym a :> b) prefix = '['Layer prefix '[QueryParams sym a] GetIntermediate] ++ GoLayers b prefix 
GoLayers (DeepQuery sym a :> b) prefix = '['Layer prefix '[DeepQuery sym a] GetIntermediate] ++ GoLayers b prefix 
GoLayers (QueryFlag sym :> b) prefix = '['Layer prefix '[QueryFlag sym] GetIntermediate] ++ GoLayers b prefix 
GoLayers (a :> b) prefix = GoLayers b (prefix ++ '[a]) 
GoLayers _ _ = '[] 

type family Normalize api where ... Source #

Rewrite the API pulling out every shared prefix between all branches of the API.

This results in a tree-structure where every path from the root of the API to every node or leaf is unique.

Equations

Normalize ((prefix :> a) :<|> (prefix :> b)) = Normalize (prefix :> (Normalize a :<|> Normalize b)) 
Normalize (a :<|> b) = Normalize a :<|> Normalize b 
Normalize ((prefix :> a) :> (prefix :> b)) = Normalize (prefix :> (Normalize a :> Normalize b)) 
Normalize (a :> b) = a :> Normalize b 
Normalize a = a