module Rest.Schema
(
withListing
, noListing
, singleton
, named
, static
, single
, singleBy
, singleRead
, listing
, listingBy
, listingRead
, unnamedSingle
, unnamedSingleRead
, unnamedListing
, unnamedListingRead
, Schema (..)
, Step (..)
, Cardinality (..)
, Getter (..)
, Id (..)
, Endpoint
) where
import Rest.Dictionary (Ident (..))
import Rest.Info (Info)
withListing :: mid -> Step sid mid aid -> Schema sid mid aid
withListing mid = Schema (Just (Many mid))
noListing :: Step sid mid aid -> Schema sid mid aid
noListing = Schema Nothing
singleton :: sid -> Step sid mid aid -> Schema sid mid aid
singleton sid = Schema (Just (Single sid))
named :: [(String, Endpoint sid mid aid)] -> Step sid mid aid
named = Named
static :: aid -> Endpoint sid mid aid
static = Left
single :: sid -> Endpoint sid mid aid
single = Right . Single . Singleton
singleBy :: (String -> sid) -> Endpoint sid mid aid
singleBy = singleIdent StringId
singleRead :: (Show a, Read a, Info a) => (a -> sid) -> Endpoint sid mid aid
singleRead = singleIdent ReadId
singleIdent :: Ident a -> (a -> sid) -> Endpoint sid mid aid
singleIdent ident = Right . Single . By . Id ident
listing :: mid -> Endpoint sid mid aid
listing = Right . Many . Singleton
listingBy :: (String -> mid) -> Endpoint sid mid aid
listingBy = listingIdent StringId
listingRead :: (Show a, Read a, Info a) => (a -> mid) -> Endpoint sid mid aid
listingRead = listingIdent ReadId
listingIdent :: Ident a -> (a -> mid) -> Endpoint sid mid aid
listingIdent ident = Right . Many . By . Id ident
unnamedSingle :: (String -> sid) -> Step sid mid aid
unnamedSingle = unnamedSingleIdent StringId
unnamedSingleRead :: (Show a, Read a, Info a) => (a -> sid) -> Step sid mid aid
unnamedSingleRead = unnamedSingleIdent ReadId
unnamedSingleIdent :: Ident a -> (a -> sid) -> Step sid mid aid
unnamedSingleIdent ident = Unnamed . Single . Id ident
unnamedListing :: (String -> mid) -> Step sid mid aid
unnamedListing = unnamedListingIdent StringId
unnamedListingRead :: (Show a, Read a, Info a) => (a -> mid) -> Step sid mid aid
unnamedListingRead = unnamedListingIdent ReadId
unnamedListingIdent :: Ident a -> (a -> mid) -> Step sid mid aid
unnamedListingIdent ident = Unnamed . Many . Id ident
data Schema sid mid aid = Schema (Maybe (Cardinality sid mid)) (Step sid mid aid)
data Step sid mid aid = Named [(String, Endpoint sid mid aid)]
| Unnamed (Cardinality (Id sid) (Id mid))
data Cardinality s m = Single s
| Many m
data Getter id = Singleton id | By (Id id)
data Id id = forall a. Id (Ident a) (a -> id)
type Endpoint sid mid aid = Either aid (Cardinality (Getter sid) (Getter mid))