#pragma once #include "option.h" #include #include "json.hpp" #include "tsl/htrie_map.h" #include "field.h" enum index_operation_t { CREATE, UPSERT, UPDATE, EMPLACE, DELETE }; enum class DIRTY_VALUES { REJECT = 1, DROP = 2, COERCE_OR_REJECT = 3, COERCE_OR_DROP = 4, }; class validator_t { public: static Option validate_index_in_memory(nlohmann::json &document, uint32_t seq_id, const std::string & default_sorting_field, const tsl::htrie_map & search_schema, const index_operation_t op, const std::string& fallback_field_type, const DIRTY_VALUES& dirty_values); static Option coerce_element(const field& a_field, nlohmann::json& document, nlohmann::json& doc_ele, const std::string& fallback_field_type, const DIRTY_VALUES& dirty_values); static Option coerce_string(const DIRTY_VALUES& dirty_values, const std::string& fallback_field_type, const field& a_field, nlohmann::json &document, const std::string &field_name, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); static Option coerce_int32_t(const DIRTY_VALUES& dirty_values, const field& a_field, nlohmann::json &document, const std::string &field_name, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); static Option coerce_int64_t(const DIRTY_VALUES& dirty_values, const field& a_field, nlohmann::json &document, const std::string &field_name, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); static Option coerce_float(const DIRTY_VALUES& dirty_values, const field& a_field, nlohmann::json &document, const std::string &field_name, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); static Option coerce_bool(const DIRTY_VALUES& dirty_values, const field& a_field, nlohmann::json &document, const std::string &field_name, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); static Option coerce_geopoint(const DIRTY_VALUES& dirty_values, const field& a_field, nlohmann::json &document, const std::string &field_name, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); };