| 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 :: k) where
- type family IsValidEndpoint endpoint :: Constraint where ...
- type family IsSubscribable endpoint api :: Constraint where ...
- data Proxy k (t :: k) :: 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 () #
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) #
serveSubscriber :: forall api. HasServer api '[] => Subscriber api -> Server api -> Application #
data Subscriber api #
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 k sym x) sb) = IsElem sa sb | |
| IsElem sa ((:>) * (ReqBody y x) sb) = IsElem sa sb | |
| IsElem ((:>) * (CaptureAll z y) sa) ((:>) * (CaptureAll x y) sb) = IsElem sa sb | |
| IsElem ((:>) * (Capture z y) sa) ((:>) * (Capture x y) sb) = IsElem sa sb | |
| IsElem sa ((:>) * (QueryParam x y) sb) = IsElem sa sb | |
| IsElem sa ((:>) * (QueryParams x y) sb) = IsElem sa sb | |
| IsElem sa ((:>) * (QueryFlag x) sb) = IsElem sa sb | |
| IsElem (Verb k1 m s ct typ) (Verb k1 m s ct' typ) = IsSubList * ct ct' | |
| IsElem e e = () | |
| IsElem e a = IsElem' e a |
class HasLink k (endpoint :: k) #
Construct a toLink for an endpoint.
Minimal complete definition
Instances
type family IsValidEndpoint endpoint :: Constraint where ... #
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 ... #
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 :: k) :: forall k. k -> * #
A concrete, poly-kinded proxy type
Instances
| Generic1 k (Proxy k) | |
| Monad (Proxy *) | Since: 4.7.0.0 |
| Functor (Proxy *) | Since: 4.7.0.0 |
| Applicative (Proxy *) | Since: 4.7.0.0 |
| Foldable (Proxy *) | Since: 4.7.0.0 |
| Traversable (Proxy *) | Since: 4.7.0.0 |
| Representable (Proxy *) | |
| ToJSON1 (Proxy *) | |
| FromJSON1 (Proxy *) | |
| Alternative (Proxy *) | Since: 4.9.0.0 |
| MonadPlus (Proxy *) | Since: 4.9.0.0 |
| Hashable1 (Proxy *) | |
| Bounded (Proxy k t) | |
| Enum (Proxy k s) | Since: 4.7.0.0 |
| Eq (Proxy k s) | Since: 4.7.0.0 |
| Ord (Proxy k s) | Since: 4.7.0.0 |
| Read (Proxy k s) | Since: 4.7.0.0 |
| Show (Proxy k s) | Since: 4.7.0.0 |
| Ix (Proxy k s) | Since: 4.7.0.0 |
| Generic (Proxy k t) | |
| Semigroup (Proxy k s) | Since: 4.9.0.0 |
| Monoid (Proxy k s) | Since: 4.7.0.0 |
| Hashable (Proxy k a) | |
| ToJSON (Proxy k a) | |
| FromJSON (Proxy k a) | |
| type Rep1 k (Proxy k) | |
| type Rep (Proxy *) | |
| type Rep (Proxy k t) | |
type family MkLink k (endpoint :: k) :: * #
Instances
| type MkLink * Raw | |
| type MkLink * EmptyAPI | |
| type MkLink * ((:<|>) a b) | |
| type MkLink * (WithNamedContext name context sub) | |
| type MkLink * ((:>) * HttpVersion sub) | |
| type MkLink * ((:>) * (ReqBody' mods ct a) sub) | |
| type MkLink * ((:>) * RemoteHost sub) | |
| type MkLink * ((:>) * (QueryParam' mods sym v) sub) | |
| type MkLink * ((:>) * (QueryParams sym v) sub) | |
| type MkLink * ((:>) * (QueryFlag sym) sub) | |
| type MkLink * ((:>) * (Header' k mods sym a) sub) | |
| type MkLink * ((:>) * IsSecure sub) | |
| type MkLink * ((:>) * (AuthProtect k tag) sub) | |
| type MkLink * ((:>) * (Summary s) sub) | |
| type MkLink * ((:>) * (Description s) sub) | |
| type MkLink * ((:>) * (Capture' mods sym v) sub) | |
| type MkLink * ((:>) * (CaptureAll sym v) sub) | |
| type MkLink * ((:>) * (BasicAuth realm a) sub) | |
| type MkLink * ((:>) * Vault sub) | |
| type MkLink * ((:>) * Subscribable sub) # | |
| type MkLink * ((:>) Symbol sym sub) | |
| type MkLink * (Verb k1 m s ct a) | |
| type MkLink * (Stream k1 m fr 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: