Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- notify :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint Link -> 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 (endpoint :: k)
- type family IsValidEndpoint endpoint :: Constraint where ...
- type family IsSubscribable endpoint api :: Constraint where ...
- data Proxy (t :: k) :: forall k. k -> Type
- type family MkLink (endpoint :: k) a :: Type
- 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 Link -> 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 b
can be seen as capturing the notion of whether the URL represented bya
would match the URL represented byb
, *not* whether a request represented bya
matches the endpoints servingb
(for the latter, useIsIn
).
IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb) | |
IsElem (e :> sa) (e :> sb) = IsElem sa sb | |
IsElem sa (Header 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 m s ct typ) (Verb m s ct' typ) = IsSubList ct ct' | |
IsElem e e = () | |
IsElem e a = IsElem' e a |
class HasLink (endpoint :: k) #
Construct a toLink for an endpoint.
Instances
type family IsValidEndpoint endpoint :: Constraint where ... Source #
A valid endpoint may only contain Symbols and captures & for convenince Subscribable:
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 #
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 (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
FunctorWithIndex Void (Proxy :: Type -> Type) | |
FoldableWithIndex Void (Proxy :: Type -> Type) | |
TraversableWithIndex Void (Proxy :: Type -> Type) | |
Defined in Control.Lens.Indexed itraverse :: Applicative f => (Void -> a -> f b) -> Proxy a -> f (Proxy b) # itraversed :: IndexedTraversal Void (Proxy a) (Proxy b) a b # | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Contravariant (Proxy :: Type -> Type) | |
Representable (Proxy :: Type -> Type) | |
ToJSON1 (Proxy :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
FromJSON1 (Proxy :: Type -> Type) | |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
ToJSON (Proxy a) | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON (Proxy a) | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy :: Type -> Type) | |
type Rep (Proxy t) | Since: base-4.6.0.0 |
type family MkLink (endpoint :: k) a :: Type #
Instances
type MkLink Raw a | |
Defined in Servant.Links | |
type MkLink EmptyAPI a | |
Defined in Servant.Links | |
type MkLink (NoContentVerb m :: Type) r | |
Defined in Servant.Links | |
type MkLink (a :<|> b :: Type) r | |
type MkLink (WithNamedContext name context sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (HttpVersion :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (StreamBody' mods framing ct a :> sub :: Type) r | |
Defined in Servant.Links | |
type MkLink (ReqBody' mods ct a :> sub :: Type) r | |
type MkLink (RemoteHost :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (QueryParam' mods sym v :> sub :: Type) a | |
Defined in Servant.Links type MkLink (QueryParam' mods sym v :> sub :: Type) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub a | |
type MkLink (QueryParams sym v :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (QueryFlag sym :> sub :: Type) a | |
type MkLink (Header' mods sym a :> sub :: Type) r | |
type MkLink (IsSecure :> sub :: Type) a | |
type MkLink (AuthProtect tag :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Summary s :> sub :: Type) a | |
type MkLink (Description s :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Capture' mods sym v :> sub :: Type) a | |
type MkLink (CaptureAll sym v :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (BasicAuth realm a :> sub :: Type) r | |
type MkLink (Vault :> sub :: Type) a | |
type MkLink (Subscribable :> sub :: Type) a Source # | |
Defined in Servant.Subscriber.Subscribable | |
type MkLink (sym :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Verb m s ct a :: Type) r | |
Defined in Servant.Links | |
type MkLink (Stream m status fr ct a :: Type) r | |
Defined in Servant.Links |
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:
Instances
Eq URI | |
Data URI | |
Defined in Network.URI gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> URI -> c URI # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c URI # dataTypeOf :: URI -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c URI) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c URI) # gmapT :: (forall b. Data b => b -> b) -> URI -> URI # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r # gmapQ :: (forall d. Data d => d -> u) -> URI -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> URI -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> URI -> m URI # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI # | |
Ord URI | |
Show URI | |
Generic URI | |
Lift URI | |
NFData URI | |
Defined in Network.URI | |
type Rep URI | |
Defined in Network.URI type Rep URI = D1 (MetaData "URI" "Network.URI" "network-uri-2.6.3.0-7wWtlPtRMwKC5NlLG0iH6F" False) (C1 (MetaCons "URI" PrefixI True) ((S1 (MetaSel (Just "uriScheme") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: S1 (MetaSel (Just "uriAuthority") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe URIAuth))) :*: (S1 (MetaSel (Just "uriPath") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: (S1 (MetaSel (Just "uriQuery") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: S1 (MetaSel (Just "uriFragment") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String))))) |
A monad supporting atomic memory transactions.
Instances
Monad STM | Since: base-4.3.0.0 |
Functor STM | Since: base-4.3.0.0 |
Applicative STM | Since: base-4.8.0.0 |
Alternative STM | Since: base-4.8.0.0 |
MonadPlus STM | Since: base-4.3.0.0 |
MonadBase STM STM | |
Defined in Control.Monad.Base | |
MonadBaseControl STM STM | |
MArray TArray e STM | |
Defined in Control.Concurrent.STM.TArray getBounds :: Ix i => TArray i e -> STM (i, i) # getNumElements :: Ix i => TArray i e -> STM Int newArray :: Ix i => (i, i) -> e -> STM (TArray i e) # newArray_ :: Ix i => (i, i) -> STM (TArray i e) # unsafeNewArray_ :: Ix i => (i, i) -> STM (TArray i e) unsafeRead :: Ix i => TArray i e -> Int -> STM e unsafeWrite :: Ix i => TArray i e -> Int -> e -> STM () | |
type StM STM a | |
Defined in Control.Monad.Trans.Control |