Implement declarative payloads. #300
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add the logic to automatically package values as a bundle that is formally named. Such a bundle remembers its type, can be validated and provides the facilities allowing its serialisation and deserialisation.
In terms of utility, such a construct allows us to capture a particular grouping of values that belong together and is intended as infrastructure for cases where indirect calling is necessary e.g. programmatic accesss to a JSON API where a client and a server API must exchange strucrured data.
The conditions needed to declare a payload "valid" live with its definition thus any set of values can be immediately tested for validity. The code used to perform the checks is is the existing validation functions, thus there is an upwards path for adoption in existing code.
Use this as the mechanism by which payloads are checked for validity. As part of declaring a bundle definition the expected positional arguments are declared so implement basic length checks that catch missing positional arguments which were required. Each argument itself is also tested aganst an optional validity function which can be specified at the point of definition.
Raise uniform payload exceptions when validation fails. Further, upon failure the exception produced can be serialised directly to JSON with useful messages about the failures that occurred, making it a useful both for the case of generating detailed user-facing reports on the command line as well as potentially reporting errors against fields with UIs.