|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
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...
#include <instance_constraints.hpp>
Public Member Functions | |
| InstanceConstraints & | declare (FieldConstraint constraint) |
| Declares (or replaces, by field name) one field's constraint. | |
| const FieldConstraint * | forField (std::string_view field) const noexcept |
The constraint declared for field, if any. | |
| bool | empty () const noexcept |
| Whether nothing has been declared. | |
| const std::vector< FieldConstraint > & | fields () const noexcept |
| Every declared constraint, in declaration order. | |
| std::string | decorate (std::string schema) const |
Rewrites schema so the framework's own keys carry this instance's values. | |
| std::vector< ConstraintViolation > | checkValue (std::string_view field, const math::Rational &value) const |
Checks one exact value against the constraint declared for field. | |
| template<typename A> | |
| std::vector< ConstraintViolation > | checkAction (const A &action) const |
Checks every constrained Quantity member of action. | |
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.
Definition at line 197 of file instance_constraints.hpp.
|
inline |
Declares (or replaces, by field name) one field's constraint.
| constraint | The constraint to record. |
Definition at line 203 of file instance_constraints.hpp.
|
inlinenodiscardnoexcept |
The constraint declared for field, if any.
| field | The wire (JSON) field name to look up. |
Definition at line 219 of file instance_constraints.hpp.
|
inlinenodiscardnoexcept |
Whether nothing has been declared.
Definition at line 230 of file instance_constraints.hpp.
|
inlinenodiscardnoexcept |
Every declared constraint, in declaration order.
Definition at line 235 of file instance_constraints.hpp.
|
inlinenodiscard |
Rewrites schema so the framework's own keys carry this instance's values.
For each declared field that the schema actually has a property for: x-decimalPlaces is overwritten with the declared precision (when one is declared), and x-minimum / x-maximum are added as {"num","den","dp"} nodes. The document then carries x-instanceConstraints: the array of field names whose keys came from instance data, which is how a renderer (and a reviewer) tells a decorated schema from the compiled one.
Never throws and never mangles: a schema that is not readable JSON is returned verbatim, and a constraint naming a field the schema has no property for is skipped — the same "an author's declaration mistake is
not worth a crash" rule mergeSchemaExtras follows.
| schema | The compiled schema text, typically schemaJson<A>(). |
Definition at line 254 of file instance_constraints.hpp.
|
inlinenodiscard |
Checks one exact value against the constraint declared for field.
The value-level entry point, for a model whose stored value is derived from the payload rather than taken from it verbatim (a reading multiplied by a dilution factor, a total recomputed from line items): the constraint governs the value the model is about to store, which is not a member of the action at all.
| field | The wire (JSON) field name the value belongs to. |
| value | The exact value to check. |
Definition at line 313 of file instance_constraints.hpp.
|
inlinenodiscard |
Checks every constrained Quantity member of action.
Walks the action's reflected members in declaration order and runs checkValue for each engaged Quantity whose wire name carries a constraint. An empty Quantity is skipped (emptiness is required's business, not a bound's), as is any member that is not a Quantity — bounds and decimal precision are exact-value concepts, and Quantity is the only field type morph forms carry an exact value in. A no-op for an action type glaze cannot reflect.
| A | Action type (a reflectable aggregate). |
| action | The decoded action to check. |
Definition at line 346 of file instance_constraints.hpp.