| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.Subscriber
- notify :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint -> URI) -> STM ()
- makeSubscriber :: Path -> LogRunner -> STM (Subscriber api)
- serveSubscriber :: forall api. HasServer api '[] => Subscriber api -> Server api -> Application
- data Subscriber api
- data Event
- type family IsElem endpoint api :: Constraint where ...
- class HasLink k endpoint where
- type family IsValidEndpoint endpoint :: Constraint where ...
- type family IsSubscribable endpoint api :: Constraint where ...
- data Proxy k t :: forall k. k -> *
- type family MkLink k (endpoint :: k) :: *
- data URI :: *
- data STM a :: * -> *
Documentation
notify :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint -> URI) -> STM () Source #
Notify the subscriber about a changed resource. You have to provide a typesafe link to the changed resource. Only Symbols and Captures are allowed in this link.
You need to provide a proxy to the API too. This is needed to check that the endpoint is valid
and points to a Subscribable resource.
One piece is still missing - we have to fill out captures, that's what the getLink parameter is for: You will typicall provide a lamda there providing needed parameters.
TODO: Example!
makeSubscriber :: Path -> LogRunner -> STM (Subscriber api) Source #
serveSubscriber :: forall api. HasServer api '[] => Subscriber api -> Server api -> Application Source #
data Subscriber api Source #
type family IsElem endpoint api :: Constraint where ... #
Closed type family, check if endpoint is within api.
Uses if it exhausts all other options.IsElem'
>>>ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))OK
>>>ok (Proxy :: Proxy (IsElem ("bye" :> Get '[JSON] Int) SampleAPI))... ... Could not deduce... ...
An endpoint is considered within an api even if it is missing combinators that don't affect the URL:
>>>ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))OK
>>>ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (ReqBody '[JSON] Bool :> Get '[JSON] Int)))OK
- N.B.:*
IsElem a bcan be seen as capturing the notion of whether the URL represented byawould match the URL represented byb, *not* whether a request represented byamatches the endpoints servingb(for the latter, useIsIn).
Equations
| IsElem e ((:<|>) sa sb) = Or (IsElem e sa) (IsElem e sb) | |
| IsElem ((:>) * k e sa) ((:>) * k e sb) = IsElem sa sb | |
| IsElem sa ((:>) * * (Header sym x) sb) = IsElem sa sb | |
| IsElem sa ((:>) * * (ReqBody k y x) sb) = IsElem sa sb | |
| IsElem ((:>) * * (CaptureAll k z y) sa) ((:>) * * (CaptureAll k x y) sb) = IsElem sa sb | |
| IsElem ((:>) * * (Capture k z y) sa) ((:>) * * (Capture k x y) sb) = IsElem sa sb | |
| IsElem sa ((:>) * * (QueryParam k x y) sb) = IsElem sa sb | |
| IsElem sa ((:>) * * (QueryParams k x y) sb) = IsElem sa sb | |
| IsElem sa ((:>) * * (QueryFlag x) sb) = IsElem sa sb | |
| IsElem (Verb k k1 m s ct typ) (Verb k k1 m s ct' typ) = IsSubList * ct ct' | |
| IsElem e e = () | |
| IsElem e a = IsElem' e a |
Construct a toLink for an endpoint.
Minimal complete definition
Instances
| HasLink * Raw | |
| HasLink * sub => HasLink * ((:>) * * Subscribable sub) # | |
| (KnownSymbol sym, HasLink k sub) => HasLink * ((:>) k Symbol sym sub) | |
| (KnownSymbol sym, ToHttpApiData v, HasLink k sub) => HasLink * ((:>) k * (QueryParam * sym v) sub) | |
| (KnownSymbol sym, ToHttpApiData v, HasLink k sub) => HasLink * ((:>) k * (QueryParams * sym v) sub) | |
| (KnownSymbol sym, HasLink k sub) => HasLink * ((:>) k * (QueryFlag sym) sub) | |
| HasLink k1 sub => HasLink * ((:>) k1 * (ReqBody k ct a) sub) | |
| (ToHttpApiData v, HasLink k sub) => HasLink * ((:>) k * (Capture * sym v) sub) | |
| (ToHttpApiData v, HasLink k sub) => HasLink * ((:>) k * (CaptureAll * sym v) sub) | |
| HasLink k sub => HasLink * ((:>) k * (Header sym a) sub) | |
| HasLink k sub => HasLink * ((:>) k * RemoteHost sub) | |
| HasLink k sub => HasLink * ((:>) k * (BasicAuth realm a) sub) | |
| HasLink * (Verb k k1 m s ct a) | |
type family IsValidEndpoint endpoint :: Constraint where ... Source #
A valid endpoint may only contain Symbols and captures & for convenince Subscribable:
Equations
| IsValidEndpoint ((sym :: Symbol) :> sub) = IsValidEndpoint sub | |
| IsValidEndpoint (Capture z y :> sub) = IsValidEndpoint sub | |
| IsValidEndpoint (Subscribable :> sub) = IsValidEndpoint sub | |
| IsValidEndpoint (Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) (a :: *)) = () |
type family IsSubscribable endpoint api :: Constraint where ... Source #
Equations
| IsSubscribable sa (Subscribable :> sb) = () | |
| IsSubscribable e (sa :<|> sb) = Or (IsSubscribable e sa) (IsSubscribable e sb) | |
| IsSubscribable ((sym :: Symbol) :> sa) (sym :> sb) = IsSubscribable sa sb | |
| IsSubscribable (e :> sa) (e :> sb) = IsSubscribable sa sb | |
| IsSubscribable sa (Header sym x :> sb) = IsSubscribable sa sb | |
| IsSubscribable sa (ReqBody y x :> sb) = IsSubscribable sa sb | |
| IsSubscribable (Capture z y :> sa) (Capture x y :> sb) = IsSubscribable sa sb | |
| IsSubscribable sa (QueryParam x y :> sb) = IsSubscribable sa sb | |
| IsSubscribable sa (QueryParams x y :> sb) = IsSubscribable sa sb | |
| IsSubscribable sa (QueryFlag x :> sb) = IsSubscribable sa sb | |
| IsSubscribable e a = IsSubscribable' e a |
data Proxy k t :: forall k. k -> * #
A concrete, poly-kinded proxy type
Instances
| Monad (Proxy *) | |
| Functor (Proxy *) | |
| Applicative (Proxy *) | |
| Foldable (Proxy *) | |
| Traversable (Proxy *) | |
| Generic1 (Proxy *) | |
| Contravariant (Proxy *) | |
| Representable (Proxy *) | |
| ToJSON1 (Proxy *) | |
| FromJSON1 (Proxy *) | |
| Alternative (Proxy *) | |
| MonadPlus (Proxy *) | |
| Bounded (Proxy k s) | |
| Enum (Proxy k s) | |
| Eq (Proxy k s) | |
| Ord (Proxy k s) | |
| Read (Proxy k s) | |
| Show (Proxy k s) | |
| Ix (Proxy k s) | |
| Generic (Proxy k t) | |
| Semigroup (Proxy k s) | |
| Monoid (Proxy k s) | |
| ToJSON (Proxy k a) | |
| FromJSON (Proxy k a) | |
| type Rep1 (Proxy *) | |
| type Rep (Proxy *) | |
| type Rep (Proxy k t) | |
type family MkLink k (endpoint :: k) :: * #
Instances
| type MkLink * Raw | |
| type MkLink * ((:>) * * Subscribable sub) # | |
| type MkLink * ((:>) k * (BasicAuth realm a) sub) | |
| type MkLink * ((:>) k * RemoteHost sub) | |
| type MkLink * ((:>) k * (Header sym a) sub) | |
| type MkLink * ((:>) k * (CaptureAll * sym v) sub) | |
| type MkLink * ((:>) k * (Capture * sym v) sub) | |
| type MkLink * ((:>) k * (ReqBody k1 ct a) sub) | |
| type MkLink * ((:>) k * (QueryFlag sym) sub) | |
| type MkLink * ((:>) k * (QueryParams * sym v) sub) | |
| type MkLink * ((:>) k * (QueryParam * sym v) sub) | |
| type MkLink * ((:>) k Symbol sym sub) | |
| type MkLink * (Verb k k1 m s ct a) | |
Represents a general universal resource identifier using its component parts.
For example, for the URI
foo://anonymous@www.haskell.org:42/ghc?query#frag
the components are: