hindsight-core
Copyright(c) 2024
LicenseBSD3
Maintainermaintainer@example.com
Stabilityexperimental
Safe HaskellNone
LanguageGHC2021

Hindsight.Store.Parsing

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

Event Processing Utilities

parseEventPayload Source #

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

createEventEnvelope Source #

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.