Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Servant.Subscriber
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 where ...
- class HasLink (endpoint :: k)
- type family IsValidEndpoint endpoint :: Constraint where ...
- type family IsSubscribable endpoint api :: Constraint where ...
- data Proxy (t :: k)
- type family MkLink (endpoint :: k) a
- 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 #
Constructors
DeleteEvent | |
ModifyEvent |
type family IsElem endpoint api 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 ... ...
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
).
Equations
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 sa (Fragment 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.
Minimal complete definition
Instances
HasLink EmptyAPI | |
HasLink Raw | |
HasLink RawM | |
(TypeError (NoInstanceFor (HasLink api)) :: Constraint) => HasLink (api :: k) | |
(HasLink (ToServantApi routes), forall a. GLink routes a, ErrorIfNoGeneric routes) => HasLink (NamedRoutes routes :: Type) | |
Defined in Servant.Links Associated Types type MkLink (NamedRoutes routes) a # Methods toLink :: (Link -> a) -> Proxy (NamedRoutes routes) -> Link -> MkLink (NamedRoutes routes) a # | |
(HasLink a, HasLink b) => HasLink (a :<|> b :: Type) | |
HasLink (NoContentVerb m :: Type) | |
Defined in Servant.Links Associated Types type MkLink (NoContentVerb m) a # Methods toLink :: (Link -> a) -> Proxy (NoContentVerb m) -> Link -> MkLink (NoContentVerb m) a # | |
(TypeError (PartialApplication (HasLink :: Type -> Constraint) arr) :: Constraint) => HasLink (arr :> sub :: Type) | |
(KnownSymbol sym, HasLink sub) => HasLink (sym :> sub :: Type) | |
HasLink sub => HasLink (HttpVersion :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (HttpVersion :> sub) a # Methods toLink :: (Link -> a) -> Proxy (HttpVersion :> sub) -> Link -> MkLink (HttpVersion :> sub) a # | |
HasLink sub => HasLink (BasicAuth realm a :> sub :: Type) | |
(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub :: Type) | |
(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (CaptureAll sym v :> sub) a # Methods toLink :: (Link -> a) -> Proxy (CaptureAll sym v :> sub) -> Link -> MkLink (CaptureAll sym v :> sub) a # | |
HasLink sub => HasLink (Description s :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (Description s :> sub) a # Methods toLink :: (Link -> a) -> Proxy (Description s :> sub) -> Link -> MkLink (Description s :> sub) a # | |
HasLink sub => HasLink (Summary s :> sub :: Type) | |
HasLink sub => HasLink (AuthProtect tag :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (AuthProtect tag :> sub) a # Methods toLink :: (Link -> a) -> Proxy (AuthProtect tag :> sub) -> Link -> MkLink (AuthProtect tag :> sub) a # | |
(HasLink sub, ToHttpApiData v) => HasLink (Fragment v :> sub :: Type) | |
HasLink sub => HasLink (Header' mods sym a :> sub :: Type) | |
HasLink sub => HasLink (IsSecure :> sub :: Type) | |
(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub :: Type) | |
(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (QueryParam' mods sym v :> sub) a # Methods toLink :: (Link -> a) -> Proxy (QueryParam' mods sym v :> sub) -> Link -> MkLink (QueryParam' mods sym v :> sub) a # | |
(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (QueryParams sym v :> sub) a # Methods toLink :: (Link -> a) -> Proxy (QueryParams sym v :> sub) -> Link -> MkLink (QueryParams sym v :> sub) a # | |
HasLink sub => HasLink (RemoteHost :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (RemoteHost :> sub) a # Methods toLink :: (Link -> a) -> Proxy (RemoteHost :> sub) -> Link -> MkLink (RemoteHost :> sub) a # | |
HasLink sub => HasLink (ReqBody' mods ct a :> sub :: Type) | |
HasLink sub => HasLink (StreamBody' mods framing ct a :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (StreamBody' mods framing ct a :> sub) a # Methods toLink :: (Link -> a0) -> Proxy (StreamBody' mods framing ct a :> sub) -> Link -> MkLink (StreamBody' mods framing ct a :> sub) a0 # | |
HasLink sub => HasLink (WithResource res :> sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (WithResource res :> sub) a # Methods toLink :: (Link -> a) -> Proxy (WithResource res :> sub) -> Link -> MkLink (WithResource res :> sub) a # | |
HasLink sub => HasLink (Subscribable :> sub :: Type) Source # | |
Defined in Servant.Subscriber.Subscribable Associated Types type MkLink (Subscribable :> sub) a # Methods toLink :: (Link -> a) -> Proxy (Subscribable :> sub) -> Link -> MkLink (Subscribable :> sub) a # | |
HasLink sub => HasLink (Vault :> sub :: Type) | |
(TypeError (NoInstanceForSub (HasLink :: Type -> Constraint) ty) :: Constraint) => HasLink (ty :> sub :: Type) | |
HasLink (UVerb m ct a :: Type) | |
HasLink sub => HasLink (WithNamedContext name context sub :: Type) | |
Defined in Servant.Links Associated Types type MkLink (WithNamedContext name context sub) a # Methods toLink :: (Link -> a) -> Proxy (WithNamedContext name context sub) -> Link -> MkLink (WithNamedContext name context sub) a # | |
HasLink (Verb m s ct a :: Type) | |
HasLink (Stream m status fr ct a :: Type) | |
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 |
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
idiom.undefined
:: a
>>>
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) | |
FoldableWithIndex Void (Proxy :: Type -> Type) | |
Defined in WithIndex | |
FunctorWithIndex Void (Proxy :: Type -> Type) | |
TraversableWithIndex Void (Proxy :: Type -> Type) | |
Representable (Proxy :: Type -> Type) | |
FromJSON1 (Proxy :: Type -> Type) | |
ToJSON1 (Proxy :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON Methods 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 # | |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> 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 # | |
Contravariant (Proxy :: Type -> Type) | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
FromJSON (Proxy a) | |
ToJSON (Proxy a) | |
Defined in Data.Aeson.Types.ToJSON | |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Ix (Proxy s) | Since: base-4.7.0.0 |
Defined in Data.Proxy | |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
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 #
Instances
type MkLink EmptyAPI a | |
Defined in Servant.Links | |
type MkLink Raw a | |
Defined in Servant.Links | |
type MkLink RawM a | |
Defined in Servant.Links | |
type MkLink (NamedRoutes routes :: Type) a | |
Defined in Servant.Links | |
type MkLink (a :<|> b :: Type) r | |
type MkLink (NoContentVerb m :: Type) r | |
Defined in Servant.Links | |
type MkLink (arr :> sub :: Type) _1 | |
Defined in Servant.Links type MkLink (arr :> sub :: Type) _1 = TypeError (PartialApplication (HasLink :: Type -> Constraint) arr) :: Type | |
type MkLink (sym :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (HttpVersion :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (BasicAuth realm a :> sub :: Type) r | |
type MkLink (Capture' mods sym v :> sub :: Type) a | |
type MkLink (CaptureAll sym v :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Description s :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Summary s :> sub :: Type) a | |
type MkLink (AuthProtect tag :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Fragment v :> sub :: Type) a | |
type MkLink (Header' mods sym a :> sub :: Type) r | |
type MkLink (IsSecure :> sub :: Type) a | |
type MkLink (QueryFlag sym :> sub :: Type) a | |
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 (RemoteHost :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (ReqBody' mods ct a :> sub :: Type) r | |
type MkLink (StreamBody' mods framing ct a :> sub :: Type) r | |
Defined in Servant.Links | |
type MkLink (WithResource res :> sub :: Type) a | |
Defined in Servant.Links | |
type MkLink (Subscribable :> sub :: Type) a Source # | |
Defined in Servant.Subscriber.Subscribable | |
type MkLink (Vault :> sub :: Type) a | |
type MkLink (UVerb m ct a :: Type) r | |
Defined in Servant.Links | |
type MkLink (WithNamedContext name context 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://[email protected]:42/ghc?query#frag
the components are:
Instances
Data URI | |
Defined in Network.URI Methods 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 :: forall r r'. (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 # | |
Generic URI | |
Show URI | |
NFData URI | |
Defined in Network.URI | |
Eq URI | |
Ord URI | |
Lift URI | |
type Rep URI | |
Defined in Network.URI type Rep URI = D1 ('MetaData "URI" "Network.URI" "network-uri-2.6.4.2-2luLZOiNoEm5gsgG4EwCZj" '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.