23#include "rpc/common/Checkers.hpp"
24#include "rpc/common/Concepts.hpp"
25#include "rpc/common/Types.hpp"
26#include "util/UnsupportedType.hpp"
28#include <boost/json/array.hpp>
29#include <boost/json/value.hpp>
40using FieldSpecProcessor = std::function<
MaybeError(boost::json::value&)>;
42static FieldSpecProcessor
const kEMPTY_FIELD_PROCESSOR = [](boost::json::value&) ->
MaybeError {
return {}; };
44template <SomeProcessor... Processors>
45[[nodiscard]] FieldSpecProcessor
46makeFieldProcessor(std::string
const& key, Processors&&... procs)
48 return [key, ... proc = std::forward<Processors>(procs)](boost::json::value& j) ->
MaybeError {
49 std::optional<Status> firstFailure = std::nullopt;
54 [&j, &key, &firstFailure, req = &proc]() {
58 if constexpr (SomeRequirement<
decltype(*req)>) {
59 if (
auto const res = req->verify(j, key); not res)
60 firstFailure = res.error();
61 }
else if constexpr (SomeModifier<
decltype(*req)>) {
62 if (
auto const res = req->modify(j, key); not res)
63 firstFailure = res.error();
72 return std::unexpected{std::move(firstFailure).value()};
78using FieldChecker = std::function<check::Warnings(boost::json::value
const&)>;
80static FieldChecker
const kEMPTY_FIELD_CHECKER = [](boost::json::value
const&) -> check::Warnings {
return {}; };
82template <SomeCheck... Checks>
83[[nodiscard]] FieldChecker
84makeFieldChecker(std::string
const& key, Checks&&... checks)
86 return [key, ... checks = std::forward<Checks>(checks)](boost::json::value
const& j) -> check::Warnings {
87 check::Warnings warnings;
90 [&j, &key, &warnings, req = &checks]() {
91 if (
auto res = req->check(j, key); res)
92 warnings.push_back(std::move(res).value());
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
static constexpr bool Unsupported
used for compile time checking of unsupported types
Definition UnsupportedType.hpp:26