#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 tsl::htrie_map & embedding_fields, const index_operation_t op, const bool is_update, 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& lat, nlohmann::json& lng, nlohmann::json::iterator& array_iter, bool is_array, bool& array_ele_erased); static Option validate_embed_fields(const nlohmann::json& document, const tsl::htrie_map& embedding_fields, const tsl::htrie_map & search_schema, const bool& error_if_field_not_found); };