mu-rpc-0.5.0.1: Protocol-independent declaration of services and servers.
Safe HaskellNone
LanguageHaskell2010

Mu.Rpc

Description

This module defines a type-level language to describe RPC-like microservices independently of the transport and protocol.

Synopsis

Documentation

type Package' = Package Symbol Symbol Symbol (TypeRef Symbol) Source #

Packages whose names are given by type-level strings.

data Package serviceName methodName argName tyRef Source #

A package is a set of services.

Constructors

Package (Maybe serviceName) [Service serviceName methodName argName tyRef] 

type Service' = Service Symbol Symbol Symbol (TypeRef Symbol) Source #

Services whose names are given by type-level strings.

data Service serviceName methodName argName tyRef Source #

A service is a set of methods.

Constructors

Service serviceName [Method serviceName methodName argName tyRef] 
OneOf serviceName [serviceName] 

type Object = 'Service Source #

An object is a set of fields, in GraphQL lingo.

type Union = 'OneOf Source #

A union is one of the objects.

type Method' = Method Symbol Symbol Symbol (TypeRef Symbol) Source #

Methods whose names are given by type-level strings.

data Method serviceName methodName argName tyRef Source #

A method is defined by its name, arguments, and return type.

Constructors

Method methodName [Argument serviceName argName tyRef] (Return serviceName tyRef) 

type ObjectField = 'Method Source #

A field in an object takes some input objects, and returns a value or some other object, in GraphQL lingo.

type family LookupService (ss :: [Service snm mnm anm tr]) (s :: snm) :: Service snm mnm anm tr where ... Source #

Look up a service in a package definition using its name.

Equations

LookupService '[] s = TypeError ('Text "could not find method " :<>: 'ShowType s) 
LookupService ('Service s ms ': ss) s = 'Service s ms 
LookupService ('OneOf s ms ': ss) s = 'OneOf s ms 
LookupService (other ': ss) s = LookupService ss s 

type family LookupMethod (s :: [Method snm mnm anm tr]) (m :: mnm) :: Method snm mnm anm tr where ... Source #

Look up a method in a service definition using its name.

Equations

LookupMethod '[] m = TypeError ('Text "could not find method " :<>: 'ShowType m) 
LookupMethod ('Method m args r ': ms) m = 'Method m args r 
LookupMethod (other ': ms) m = LookupMethod ms m 

data TypeRef serviceName where Source #

Defines a reference to a type, either primitive or coming from the schema. TypeRefs are used to define arguments and result types.

Constructors

PrimitiveRef :: Type -> TypeRef serviceName

A primitive type.

ObjectRef :: serviceName -> TypeRef serviceName

Chain with another service.

SchemaRef :: Schema typeName fieldName -> typeName -> TypeRef serviceName

Point to schema.

RegistryRef :: Registry -> Type -> Nat -> TypeRef serviceName

Registry subject, type to convert to, and preferred serialization version

THRef :: Type -> TypeRef serviceName

To be used only during TH generation!

ListRef :: TypeRef serviceName -> TypeRef serviceName

Represents a list of values.

OptionalRef :: TypeRef serviceName -> TypeRef serviceName

Represents a possibly-missing value.

Instances

Instances details
(MonadError ServerError m, handler ~ m ()) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetNothing :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy 'RetNothing -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, ToRef chn ref v, handler ~ (ConduitT v Void m () -> m ())) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetStream ref :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy ('RetStream ref) -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, ToRef chn ref v, handler ~ m v) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetSingle ref :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy ('RetSingle ref) -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, ToRef chn eref e, ToRef chn vref v, handler ~ m (Either e v)) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetThrows eref vref :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy ('RetThrows eref vref) -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, FromRef chn ref t, Handles chn args ret m h, handler ~ (ConduitT () t m () -> h)) => Handles (chn :: ServiceChain serviceName) (('ArgStream aname ref :: Argument serviceName anm (TypeRef serviceName)) ': args :: [Argument serviceName anm (TypeRef serviceName)]) (ret :: Return serviceName (TypeRef serviceName)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy ('ArgStream aname ref ': args) -> Proxy ret -> (forall a. m a -> m a) -> handler -> handler

(FromRef chn ref t, Handles chn args ret m h, handler ~ (t -> h)) => Handles (chn :: ServiceChain serviceName) (('ArgSingle aname ref :: Argument serviceName anm (TypeRef serviceName)) ': args :: [Argument serviceName anm (TypeRef serviceName)]) (ret :: Return serviceName (TypeRef serviceName)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy ('ArgSingle aname ref ': args) -> Proxy ret -> (forall a. m a -> m a) -> handler -> handler

Show (TypeRef s) Source # 
Instance details

Defined in Mu.Rpc

Methods

showsPrec :: Int -> TypeRef s -> ShowS #

show :: TypeRef s -> String #

showList :: [TypeRef s] -> ShowS #

(KnownMaySymbol pname, ReflectServices ss, ReflectService s, ReflectMethod m) => ReflectRpcInfo ('Package pname ss) s m Source # 
Instance details

Defined in Mu.Rpc

Methods

reflectRpcInfo :: Proxy ('Package pname ss) -> Proxy s -> Proxy m -> RequestHeaders -> i -> RpcInfo i Source #

type Argument' = Argument Symbol Symbol (TypeRef Symbol) Source #

Arguments whose names are given by type-level strings.

data Argument serviceName argName tyRef where Source #

Defines the way in which arguments are handled.

Constructors

ArgSingle :: Maybe argName -> tyRef -> Argument serviceName argName tyRef

Use a single value.

ArgStream :: Maybe argName -> tyRef -> Argument serviceName argName tyRef

Consume a stream of values.

Instances

Instances details
(MonadError ServerError m, handler ~ m ()) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetNothing :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy 'RetNothing -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, ToRef chn ref v, handler ~ (ConduitT v Void m () -> m ())) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetStream ref :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy ('RetStream ref) -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, ToRef chn ref v, handler ~ m v) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetSingle ref :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy ('RetSingle ref) -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, ToRef chn eref e, ToRef chn vref v, handler ~ m (Either e v)) => Handles (chn :: ServiceChain snm) ('[] :: [Argument snm anm (TypeRef snm)]) ('RetThrows eref vref :: Return snm (TypeRef snm)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy '[] -> Proxy ('RetThrows eref vref) -> (forall a. m a -> m a) -> handler -> handler

(MonadError ServerError m, FromRef chn ref t, Handles chn args ret m h, handler ~ (ConduitT () t m () -> h)) => Handles (chn :: ServiceChain serviceName) (('ArgStream aname ref :: Argument serviceName anm (TypeRef serviceName)) ': args :: [Argument serviceName anm (TypeRef serviceName)]) (ret :: Return serviceName (TypeRef serviceName)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy ('ArgStream aname ref ': args) -> Proxy ret -> (forall a. m a -> m a) -> handler -> handler

(FromRef chn ref t, Handles chn args ret m h, handler ~ (t -> h)) => Handles (chn :: ServiceChain serviceName) (('ArgSingle aname ref :: Argument serviceName anm (TypeRef serviceName)) ': args :: [Argument serviceName anm (TypeRef serviceName)]) (ret :: Return serviceName (TypeRef serviceName)) m handler Source # 
Instance details

Defined in Mu.Server

Methods

wrapHandler :: Proxy '(chn, m) -> Proxy ('ArgSingle aname ref ': args) -> Proxy ret -> (forall a. m a -> m a) -> handler -> handler

data Return serviceName tyRef where Source #

Defines the different possibilities for returning information from a method.

Constructors

RetNothing :: Return serviceName tyRef

Fire and forget.

RetSingle :: tyRef -> Return serviceName tyRef

Return a single value.

RetStream :: tyRef -> Return serviceName tyRef

Return a stream of values.

RetThrows :: tyRef -> tyRef -> Return serviceName tyRef

Return a value or an error.

data TyInfo Source #

Instances

Instances details
Eq TyInfo Source # 
Instance details

Defined in Mu.Rpc

Methods

(==) :: TyInfo -> TyInfo -> Bool #

(/=) :: TyInfo -> TyInfo -> Bool #

Show TyInfo Source # 
Instance details

Defined in Mu.Rpc

data RpcInfo i Source #

Reflection

Instances

Instances details
Show (RpcInfo i) Source # 
Instance details

Defined in Mu.Rpc

Methods

showsPrec :: Int -> RpcInfo i -> ShowS #

show :: RpcInfo i -> String #

showList :: [RpcInfo i] -> ShowS #

class ReflectRpcInfo (p :: Package') (s :: Service') (m :: Method') where Source #

Methods

reflectRpcInfo :: Proxy p -> Proxy s -> Proxy m -> RequestHeaders -> i -> RpcInfo i Source #

Instances

Instances details
(KnownMaySymbol pname, ReflectServices ss, ReflectService s, ReflectMethod m) => ReflectRpcInfo ('Package pname ss) s m Source # 
Instance details

Defined in Mu.Rpc

Methods

reflectRpcInfo :: Proxy ('Package pname ss) -> Proxy s -> Proxy m -> RequestHeaders -> i -> RpcInfo i Source #