morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
changes.hpp File Reference
#include <algorithm>
#include <glaze/glaze.hpp>
#include <optional>
#include <string>
#include <string_view>
#include <typeindex>
#include <utility>
#include <vector>
#include "change_types.hpp"
#include "effects.hpp"

Go to the source code of this file.

Typedefs

using morph::effects::detail::ResultJson = glz::generic_u64
 The JSON tree a result is parsed into. It keeps integers exact, so a 64-bit key is copied as written.

Functions

void morph::effects::detail::collectKey (ResultJson const &value, std::string_view keyField, std::vector< glz::raw_json > &out)
 Appends the key of one record value to out.
void morph::effects::detail::collectKeysAtLeaf (ResultJson const &value, std::string_view keyField, std::vector< glz::raw_json > &out)
 Appends the keys of the records held at a value that the path has reached.
void morph::effects::detail::collectKeysAtPath (ResultJson const &value, std::string_view path, std::string_view keyField, std::vector< glz::raw_json > &out)
 Walks the remaining path segments from value, then collects the keys found there.
void morph::effects::detail::addRecordChange (Changes &changes, std::string const &record, std::optional< std::vector< glz::raw_json > > keys)
 Adds a change for a record, merging with one already there.
void morph::effects::detail::addDerivedChanges (Resolved const &resolved, std::string const &source, Changes &changes)
 Adds a whole-type change for every record derived, directly or through others, from source.
void morph::effects::detail::addInstanceChange (Changes &changes, InstanceChange const &ranOn)
 Adds the change an execute's instance makes, unless it is already there.
void morph::effects::detail::addUpdatesChange (Resolved const &resolved, std::string_view actionId, std::string const &record, ResultJson const *parsed, Changes &changes)
 Adds the change an updates<R> effect makes: the keys of the R rows found in the result.
Changes morph::effects::detail::deriveChangesFrom (Resolved const &resolved, std::string_view actionId, std::string_view resultJson, InstanceChange const &ranOn)
 See morph::effects::deriveChanges, over given registries.
Changes morph::effects::deriveChanges (std::string_view actionId, std::string_view resultJson, InstanceChange const &ranOn)
 The changes a successful execute made, from the action's declared effects and its result.

Detailed Description

Deriving an execute's changes from the action's declared effects and its result.

Definition in file changes.hpp.

Typedef Documentation

◆ ResultJson

using morph::effects::detail::ResultJson = glz::generic_u64

The JSON tree a result is parsed into. It keeps integers exact, so a 64-bit key is copied as written.

Definition at line 24 of file changes.hpp.

Function Documentation

◆ collectKey()

void morph::effects::detail::collectKey ( ResultJson const & value,
std::string_view keyField,
std::vector< glz::raw_json > & out )
inline

Appends the key of one record value to out.

Parameters
valueA JSON value expected to be one record.
keyFieldThe record's key member.
outWhere to append the key's raw JSON.

Definition at line 30 of file changes.hpp.

◆ collectKeysAtLeaf()

void morph::effects::detail::collectKeysAtLeaf ( ResultJson const & value,
std::string_view keyField,
std::vector< glz::raw_json > & out )
inline

Appends the keys of the records held at a value that the path has reached.

An object is one record when it has the key member, and otherwise a map whose values are records.

Parameters
valueThe value at the end of a path.
keyFieldThe record's key member.
outWhere to append.

Definition at line 51 of file changes.hpp.

◆ collectKeysAtPath()

void morph::effects::detail::collectKeysAtPath ( ResultJson const & value,
std::string_view path,
std::string_view keyField,
std::vector< glz::raw_json > & out )
inline

Walks the remaining path segments from value, then collects the keys found there.

A vector or optional adds no segment, so an array is entered without consuming one. A map adds none either, so an object that lacks the next segment is searched through its values.

Parameters
valueThe current value.
pathThe dot-joined member names; "" is the value itself.
keyFieldThe record's key member.
outWhere to append.

Definition at line 77 of file changes.hpp.

◆ addRecordChange()

void morph::effects::detail::addRecordChange ( Changes & changes,
std::string const & record,
std::optional< std::vector< glz::raw_json > > keys )
inline

Adds a change for a record, merging with one already there.

A whole-type change absorbs keys, and keys are not repeated.

Parameters
changesThe changes so far.
recordThe record's wire name.
keysThe changed keys, or nullopt for the whole type.

Definition at line 111 of file changes.hpp.

◆ addDerivedChanges()

void morph::effects::detail::addDerivedChanges ( Resolved const & resolved,
std::string const & source,
Changes & changes )
inline

Adds a whole-type change for every record derived, directly or through others, from source.

Parameters
resolvedThe resolved registries.
sourceA changed record's wire name.
changesWhere to add.

Definition at line 137 of file changes.hpp.

◆ addInstanceChange()

void morph::effects::detail::addInstanceChange ( Changes & changes,
InstanceChange const & ranOn )
inline

Adds the change an execute's instance makes, unless it is already there.

Parameters
changesWhere to add.
ranOnThe instance the action ran on.

Definition at line 161 of file changes.hpp.

◆ addUpdatesChange()

void morph::effects::detail::addUpdatesChange ( Resolved const & resolved,
std::string_view actionId,
std::string const & record,
ResultJson const * parsed,
Changes & changes )
inline

Adds the change an updates<R> effect makes: the keys of the R rows found in the result.

A result that does not parse, or a record without a key, cannot name rows: the whole type is reported, which over-notifies but never misses.

Parameters
resolvedThe resolved registries.
actionIdThe action's id.
recordThe updated record's wire name.
parsedThe parsed result, or nullptr when it did not parse.
changesWhere to add.

Definition at line 179 of file changes.hpp.

◆ deriveChangesFrom()

Changes morph::effects::detail::deriveChangesFrom ( Resolved const & resolved,
std::string_view actionId,
std::string_view resultJson,
InstanceChange const & ranOn )
inlinenodiscard

See morph::effects::deriveChanges, over given registries.

Parameters
resolvedThe resolved registries.
actionIdThe action's id.
resultJsonThe action's result as JSON.
ranOnThe instance the action ran on.
Returns
The changes.

Definition at line 205 of file changes.hpp.

◆ deriveChanges()

Changes morph::effects::deriveChanges ( std::string_view actionId,
std::string_view resultJson,
InstanceChange const & ranOn )
inlinenodiscard

The changes a successful execute made, from the action's declared effects and its result.

updates<R> gives the keys of the R rows found in the result, changes<R> the whole type, and both also every record derived from R, directly or through others, as a whole-type change. changesInstance gives ranOn. An action that declared nothing, or only none, gives no changes.

Parameters
actionIdThe action's id.
resultJsonThe action's result as JSON.
ranOnThe instance the action ran on.
Returns
The changes; empty for a reader.
Exceptions
morph::model::EffectsRegistrationErrorwhen the registered configuration is invalid.

Definition at line 265 of file changes.hpp.