| Copyright | (c) 2024 |
|---|---|
| License | BSD3 |
| Maintainer | maintainer@example.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | GHC2021 |
Hindsight.Projection.Matching
Contents
Description
PostgreSQL-based projection handlers. Used by both sync and async projections to update read models stored in PostgreSQL, regardless of event store backend.
Synopsis
- type ProjectionHandler (event :: Symbol) backend = EventEnvelope event backend -> Transaction ()
- data ProjectionHandlers (ts :: [Symbol]) backend where
- (:->) :: forall (event :: Symbol) backend (ts1 :: [Symbol]). (Event event, Typeable (ProjectionHandler event backend)) => (Proxy event, ProjectionHandler event backend) -> ProjectionHandlers ts1 backend -> ProjectionHandlers (event ': ts1) backend
- ProjectionEnd :: forall backend. ProjectionHandlers ('[] :: [Symbol]) backend
- data SomeProjectionHandler backend = Event event => SomeProjectionHandler (Proxy event) (ProjectionHandler event backend)
- extractMatchingHandlers :: forall (event :: Symbol) (ts :: [Symbol]) backend. Event event => ProjectionHandlers ts backend -> Proxy event -> [ProjectionHandler event backend]
- handlersForEventName :: forall (ts :: [Symbol]) backend. Text -> ProjectionHandlers ts backend -> [SomeProjectionHandler backend]
Projection Types
type ProjectionHandler (event :: Symbol) backend = EventEnvelope event backend -> Transaction () Source #
A projection handler for a specific event type
data ProjectionHandlers (ts :: [Symbol]) backend where Source #
A type-indexed list of projection handlers
Constructors
| (:->) :: forall (event :: Symbol) backend (ts1 :: [Symbol]). (Event event, Typeable (ProjectionHandler event backend)) => (Proxy event, ProjectionHandler event backend) -> ProjectionHandlers ts1 backend -> ProjectionHandlers (event ': ts1) backend infixr 5 | |
| ProjectionEnd :: forall backend. ProjectionHandlers ('[] :: [Symbol]) backend |
data SomeProjectionHandler backend Source #
Existential wrapper for projection handlers of unknown event types
Used when working with handlers but the event type is not known at compile time.
Constructors
| Event event => SomeProjectionHandler (Proxy event) (ProjectionHandler event backend) |
Handler Matching
Two different matching strategies for different use cases:
extractMatchingHandlers: Use when you have a typed envelope at compile timehandlersForEventName: Use when you only have an event name at runtime
extractMatchingHandlers Source #
Arguments
| :: forall (event :: Symbol) (ts :: [Symbol]) backend. Event event | |
| => ProjectionHandlers ts backend | All available handlers |
| -> Proxy event | Event type to match |
| -> [ProjectionHandler event backend] | Matching handlers with correct type |
Extract handlers that match a specific event type (compile-time matching)
Use this when you have a typed 'EventEnvelope event backend' and need to find handlers that can process it. Returns handlers with the correct type signature.
This function is needed for sync projections during real-time event insertion,
where the event type is known at compile time but the handler list is
existentially quantified (due to storage in SyncProjectionRegistry).
The type casting is safe because event names uniquely identify event types.
Arguments
| :: forall (ts :: [Symbol]) backend. Text | Event name from stored event |
| -> ProjectionHandlers ts backend | All available handlers |
| -> [SomeProjectionHandler backend] | Only handlers that match the event name |
Find all handlers that match a specific event name (runtime matching)
Use this when you only have an event name from a stored event (as Text)
and need to find matching handlers. Returns existentially wrapped handlers
that preserve their original event types.
This function is needed for sync projection catch-up, where events are read from the database and their types are not known at compile time. Each handler remains wrapped with its specific event type, allowing type-safe envelope construction via parsing.
No type casting is needed because handlers retain their existential wrappers.