23#include "rpc/common/Concepts.hpp"
24#include "rpc/common/Specs.hpp"
25#include "rpc/common/Types.hpp"
27#include <boost/json/value.hpp>
32#include <initializer_list>
44 std::vector<FieldSpec> specs_;
52 explicit Section(std::initializer_list<FieldSpec> specs) : specs_{specs}
64 verify(boost::json::value& value, std::string_view key)
const;
72 std::vector<FieldSpec> specs_;
81 ValidateArrayAt(std::size_t idx, std::initializer_list<FieldSpec> specs) : idx_{idx}, specs_{specs}
93 verify(boost::json::value& value, std::string_view key)
const;
100template <
typename Type>
108 explicit IfType(Requirements&&... requirements)
110 [... r = std::forward<Requirements>(requirements
111 )](boost::json::value& j, std::string_view key) ->
MaybeError {
112 std::optional<
Status> firstFailure = std::nullopt;
116 [&j, &key, &firstFailure, req = &r]() {
120 if (
auto const res = req->verify(j, key); not res)
121 firstFailure = res.error();
127 return Error{firstFailure.value()};
135 IfType(IfType
const&) =
default;
136 IfType(IfType&&) =
default;
146 verify(boost::json::value& value, std::string_view key)
const
148 if (not value.is_object() or not value.as_object().contains(key))
151 if (not rpc::validation::checkType<Type>(value.as_object().at(key)))
154 return processor_(value, key);
158 std::function<
MaybeError(boost::json::value&, std::string_view)> processor_;
164template <
typename RequirementOrModifierType>
167 RequirementOrModifierType reqOrModifier_;
179 : reqOrModifier_{std::move(reqOrModifier)}, error_{std::move(err)}
191 verify(boost::json::value
const& value, std::string_view key)
const
194 if (
auto const res = reqOrModifier_.verify(value, key); not res)
195 return Error{error_};
209 verify(boost::json::value& value, std::string_view key)
const
212 if (
auto const res = reqOrModifier_.verify(value, key); not res)
213 return Error{error_};
226 modify(boost::json::value& value, std::string_view key)
const
230 if (
auto const res = reqOrModifier_.modify(value, key); not res)
231 return Error{error_};
Specifies what a modifier used with rpc::FieldSpec must provide.
Definition Concepts.hpp:50
Specifies what a requirement used with rpc::FieldSpec must provide.
Definition Concepts.hpp:42
std::expected< void, Status > MaybeError
Return type used for Validators that can return error but don't have specific value to return.
Definition Types.hpp:55
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:75
A status returned from any RPC handler.
Definition Errors.hpp:82