|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
Per-*instance* constraints on a form field: the seam by which data that lives in a database row — not in a template parameter — reaches the framework-meaningful keys of a served schema, and is checked against a submitted value by the same declaration that served it. More...
#include <cstdint>#include <glaze/glaze.hpp>#include <optional>#include <string>#include <string_view>#include <vector>#include "../attributes.hpp"#include "../util/quantity.hpp"#include "../util/rational.hpp"#include "forms.hpp"Go to the source code of this file.
Classes | |
| struct | morph::forms::ConstraintViolation |
| One violation: which field, and which declared key it broke. More... | |
| struct | morph::forms::FieldConstraint |
| The per-instance constraint declared for one field of an action. More... | |
| class | morph::forms::InstanceConstraints |
| A set of per-field constraints sourced from one instance (a database row, a tenant record, a catalogue version) — the single declaration that both decorates a served schema and checks a submitted value. More... | |
Enumerations | |
| enum class | morph::forms::ConstraintViolationKind : std::uint8_t { BelowMinimum , AboveMaximum , PrecisionExceeded } |
| Which framework-meaningful key a submitted value fell foul of. More... | |
Functions | |
| std::string_view | morph::forms::violationKindName (ConstraintViolationKind kind) noexcept |
| A stable, machine-readable name for a violation kind — for log lines and model-level error messages. | |
| template<typename A> | |
| std::string | morph::forms::instanceSchemaJson (const InstanceConstraints &constraints) |
schemaJson<A>() decorated with constraints — the served form for one instance. | |
Per-*instance* constraints on a form field: the seam by which data that lives in a database row — not in a template parameter — reaches the framework-meaningful keys of a served schema, and is checked against a submitted value by the same declaration that served it.
schemaJson<A>() is a pure function of the compiled action type A: every key it emits is derived from A's members, so two rows that describe the same action differently — an analysis catalogue whose version 1 declares three decimal places and whose version 2 declares one — cannot be told apart by anything the framework enforces. Before this header the only way out was for the application to patch a second, app-private key beside the framework's (x-versionDecimalPlaces next to x-decimalPlaces) and re-implement the check by hand, which leaves a renderer with two keys for one concept and no way to know which to believe.
InstanceConstraints replaces that with one declaration that does both jobs:
Definition in file instance_constraints.hpp.
|
strong |
Which framework-meaningful key a submitted value fell foul of.
Definition at line 66 of file instance_constraints.hpp.
|
inlinenodiscardnoexcept |
A stable, machine-readable name for a violation kind — for log lines and model-level error messages.
| kind | The violation kind to name. |
Definition at line 94 of file instance_constraints.hpp.
|
nodiscard |
schemaJson<A>() decorated with constraints — the served form for one instance.
Not memoised: unlike schemaJson<A>() (one cached string per compiled type), the result varies per instance, so the caller caches it if it wants caching. The compiled half is still memoised inside schemaJson<A>(), so the per-call cost is the DOM round trip, not schema generation.
| A | Action type (a reflectable aggregate). |
| constraints | The instance's constraints. |
Definition at line 385 of file instance_constraints.hpp.