4#include "rpc/common/Checkers.hpp"
5#include "rpc/common/Concepts.hpp"
6#include "rpc/common/Types.hpp"
7#include "util/UnsupportedType.hpp"
9#include <boost/json/array.hpp>
10#include <boost/json/value.hpp>
21using FieldSpecProcessor = std::function<
MaybeError(boost::json::value&)>;
23static FieldSpecProcessor
const kEMPTY_FIELD_PROCESSOR = [](boost::json::value&) ->
MaybeError {
27template <SomeProcessor... Processors>
28[[nodiscard]] FieldSpecProcessor
29makeFieldProcessor(std::string
const& key, Processors&&... procs)
31 return [key, ... proc = std::forward<Processors>(procs)](boost::json::value& j) ->
MaybeError {
32 std::optional<Status> firstFailure = std::nullopt;
38 [&j, &key, &firstFailure, req = &proc]() {
42 if constexpr (SomeRequirement<
decltype(*req)>) {
43 if (
auto const res = req->verify(j, key); not res)
44 firstFailure = res.error();
45 }
else if constexpr (SomeModifier<
decltype(*req)>) {
46 if (
auto const res = req->modify(j, key); not res)
47 firstFailure = res.error();
55 return std::unexpected{std::move(firstFailure).value()};
61using FieldChecker = std::function<check::Warnings(boost::json::value
const&)>;
63static FieldChecker
const kEMPTY_FIELD_CHECKER = [](boost::json::value
const&) -> check::Warnings {
67template <SomeCheck... Checks>
68[[nodiscard]] FieldChecker
69makeFieldChecker(std::string
const& key, Checks&&... checks)
73 std::forward<Checks>(checks)](boost::json::value
const& j) -> check::Warnings {
74 check::Warnings warnings;
77 [&j, &key, &warnings, req = &checks]() {
78 if (
auto res = req->check(j, key); res)
79 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:36
static constexpr bool Unsupported
used for compile time checking of unsupported types
Definition UnsupportedType.hpp:7