morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::journal::PayloadMigrationRegistry Class Reference

Registry of payload migrations, keyed by (actionType, fromSchema). More...

#include <journal.hpp>

Public Types

using Migration = std::function<std::string(std::string_view)>
 Rewrites one recorded payload JSON into the current shape.

Public Member Functions

void add (std::string_view actionType, std::string_view fromSchema, Migration migration)
 Registers migration for entries of actionType stamped with fromSchema. Replaces any migration already registered for that exact pair.
const Migration * find (std::string_view actionType, std::string_view fromSchema) const
 Looks up the migration for (actionType, fromSchema).
void clear ()
 Removes every registered migration.
std::size_t size () const noexcept
 Returns how many migrations are registered.

Detailed Description

Registry of payload migrations, keyed by (actionType, fromSchema).

The escape hatch that makes "refuse on mismatch" a livable contract rather than a one-way door. A migration is a pure function over the recorded payload JSON: given the bytes an older build wrote, return the bytes this build's ActionTraits<A>::fromJson should see. Reconstruction applies it in memory only — the journal on disk is never rewritten, so the recorded history stays exactly what was recorded and the migration stays reviewable as code.

Thread safety
None, matching morph::model::detail::ActionDispatcher: register every migration during start-up, before any replay() can run.
migrations.add("setState", oldFingerprint, [](std::string_view payload) {
// rename "state" -> "stateCode"
return rewriteKey(payload, "state", "stateCode");
});
auto holder = morph::journal::replay("Sample", log.entries(), registry, dispatcher, migrations);
Registry of payload migrations, keyed by (actionType, fromSchema).
Definition journal.hpp:107
void add(std::string_view actionType, std::string_view fromSchema, Migration migration)
Registers migration for entries of actionType stamped with fromSchema. Replaces any migration already...
Definition journal.hpp:118

Definition at line 107 of file journal.hpp.

Member Typedef Documentation

◆ Migration

using morph::journal::PayloadMigrationRegistry::Migration = std::function<std::string(std::string_view)>

Rewrites one recorded payload JSON into the current shape.

Definition at line 110 of file journal.hpp.

Member Function Documentation

◆ add()

void morph::journal::PayloadMigrationRegistry::add ( std::string_view actionType,
std::string_view fromSchema,
Migration migration )
inline

Registers migration for entries of actionType stamped with fromSchema. Replaces any migration already registered for that exact pair.

Parameters
actionTypeLogEntry::actionType the migration applies to.
fromSchemaLogEntry::schema value the migration reads.
migrationPayload rewriter.

Definition at line 118 of file journal.hpp.

◆ find()

const Migration * morph::journal::PayloadMigrationRegistry::find ( std::string_view actionType,
std::string_view fromSchema ) const
inlinenodiscard

Looks up the migration for (actionType, fromSchema).

Returns a pointer into the registry, valid until the entry is replaced or the registry is destroyed (std::unordered_map does not invalidate references to surviving elements on rehash).

Parameters
actionTypeLogEntry::actionType to match.
fromSchemaLogEntry::schema to match.
Returns
Pointer to the migration, or nullptr if none is registered — into this registry, so valid only for as long as it is.

Definition at line 131 of file journal.hpp.

◆ clear()

void morph::journal::PayloadMigrationRegistry::clear ( )
inline

Removes every registered migration.

Definition at line 138 of file journal.hpp.

◆ size()

std::size_t morph::journal::PayloadMigrationRegistry::size ( ) const
inlinenodiscardnoexcept

Returns how many migrations are registered.

Returns
The registration count.

Definition at line 142 of file journal.hpp.


The documentation for this class was generated from the following file: