| Copyright | (c) 2024 |
|---|---|
| License | BSD3 |
| Maintainer | maintainer@example.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | GHC2021 |
Hindsight.Store.Parsing
Contents
Description
This module provides core event parsing utilities used by all event store backends to convert stored events into properly typed event envelopes. These utilities handle version-aware parsing and envelope creation.
These utilities are shared across Memory, Filesystem, and PostgreSQL backends for consistent event parsing and envelope construction.
Synopsis
- parseEventPayload :: forall (event :: Symbol). Event event => Proxy event -> Value -> Integer -> Maybe (CurrentPayloadType event)
- parseStoredEventToEnvelope :: forall (event :: Symbol) backend. Event event => Proxy event -> EventId -> StreamId -> Cursor backend -> StreamVersion -> Maybe CorrelationId -> UTCTime -> Value -> Integer -> Maybe (EventEnvelope event backend)
- createEventEnvelope :: forall (event :: Symbol) backend. EventId -> StreamId -> Cursor backend -> StreamVersion -> Maybe CorrelationId -> UTCTime -> CurrentPayloadType event -> EventEnvelope event backend
Event Processing Utilities
Arguments
| :: forall (event :: Symbol). Event event | |
| => Proxy event | Proxy for the event type |
| -> Value | JSON payload from storage |
| -> Integer | Event payload version |
| -> Maybe (CurrentPayloadType event) | Parsed and upgraded payload, or Nothing if parsing fails |
Parse event payload from JSON using the event's parse map with proper version handling
This function implements correct version-aware parsing: 1. Uses the stored event version to select the appropriate parser 2. The parser automatically migrates to the latest version via MigrateVersion 3. Returns the current version payload type
parseStoredEventToEnvelope Source #
Arguments
| :: forall (event :: Symbol) backend. Event event | |
| => Proxy event | Proxy for the event type |
| -> EventId | Unique event identifier |
| -> StreamId | Stream this event belongs to |
| -> Cursor backend | Global position in event store |
| -> StreamVersion | Local version within the stream |
| -> Maybe CorrelationId | Optional correlation identifier |
| -> UTCTime | Event creation timestamp |
| -> Value | Raw JSON payload from storage |
| -> Integer | Event payload version (from eventVersion field) |
| -> Maybe (EventEnvelope event backend) | Parsed envelope, or Nothing if parsing fails |
Parse stored event data into an event envelope
This function handles the database → envelope conversion with proper version handling: 1. Takes raw event data from storage (JSON + version + metadata) 2. Uses the stored version to parse at the correct version 3. Automatically upgrades to the latest version 4. Creates a properly typed event envelope
Arguments
| :: forall (event :: Symbol) backend. EventId | Unique event identifier |
| -> StreamId | Stream this event belongs to |
| -> Cursor backend | Global position in event store |
| -> StreamVersion | Local version within the stream |
| -> Maybe CorrelationId | Optional correlation identifier |
| -> UTCTime | Event creation timestamp |
| -> CurrentPayloadType event | Parsed event payload at latest version |
| -> EventEnvelope event backend | Complete event envelope with metadata |
Create event envelope from parsed payload and metadata
This unified function creates consistent event envelopes across both projection systems.