module Wire.API.Federation.HasNotificationEndpoint
( IsNotificationTag (..),
HasNotificationEndpoint (..),
HasFedPath,
HasVersionRange,
fedPath,
versionRange,
)
where
import Data.Kind
import Data.Proxy
import Data.Singletons
import GHC.TypeLits
import Imports
import Wire.API.Federation.Component
import Wire.API.Federation.Version
import Wire.API.Routes.Version (From, Until)
class IsNotificationTag k where
type NotificationComponent k = (c :: Component) | c -> k
class HasNotificationEndpoint t where
type Payload t = (p :: Type) | p -> t
type NotificationPath t :: Symbol
type NotificationVersionTag t :: Maybe Version
type NotificationVersionTag t = 'Nothing
type NotificationMods t :: [Type]
type NotificationMods t = '[]
type HasFedPath t = KnownSymbol (NotificationPath t)
type HasVersionRange t = MkVersionRange (NotificationMods t)
fedPath :: forall t. (HasFedPath t) => String
fedPath :: forall {k} (t :: k). HasFedPath t => String
fedPath = Proxy (NotificationPath t) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(NotificationPath t))
class MkVersionRange mods where
mkVersionRange :: VersionRange
instance MkVersionRange '[] where
mkVersionRange :: VersionRange
mkVersionRange = VersionRange
allVersions
instance
{-# OVERLAPPING #-}
(MkVersionRange mods, SingI v) =>
MkVersionRange (From (v :: Version) ': mods)
where
mkVersionRange :: VersionRange
mkVersionRange = forall (mods :: [*]). MkVersionRange mods => VersionRange
forall {k} (mods :: k). MkVersionRange mods => VersionRange
mkVersionRange @mods VersionRange -> VersionRange -> VersionRange
forall a. Semigroup a => a -> a -> a
<> Version -> VersionRange
rangeFromVersion (forall {k} (a :: k). (SingKind k, SingI a) => Demote k
forall (a :: Version).
(SingKind Version, SingI a) =>
Demote Version
demote @v)
instance
{-# OVERLAPPING #-}
(MkVersionRange mods, SingI v) =>
MkVersionRange (Until (v :: Version) ': mods)
where
mkVersionRange :: VersionRange
mkVersionRange = forall (mods :: [*]). MkVersionRange mods => VersionRange
forall {k} (mods :: k). MkVersionRange mods => VersionRange
mkVersionRange @mods VersionRange -> VersionRange -> VersionRange
forall a. Semigroup a => a -> a -> a
<> Version -> VersionRange
rangeUntilVersion (forall {k} (a :: k). (SingKind k, SingI a) => Demote k
forall (a :: Version).
(SingKind Version, SingI a) =>
Demote Version
demote @v)
instance {-# OVERLAPPABLE #-} (MkVersionRange mods) => MkVersionRange (m ': mods) where
mkVersionRange :: VersionRange
mkVersionRange = forall (mods :: [a]). MkVersionRange mods => VersionRange
forall {k} (mods :: k). MkVersionRange mods => VersionRange
mkVersionRange @mods
versionRange :: forall t. (HasVersionRange t) => VersionRange
versionRange :: forall {k} (t :: k). HasVersionRange t => VersionRange
versionRange = forall (mods :: [*]). MkVersionRange mods => VersionRange
forall {k} (mods :: k). MkVersionRange mods => VersionRange
mkVersionRange @(NotificationMods t)