mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 05:08:43 +08:00
67 lines
3.2 KiB
C++
67 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include "option.h"
|
|
#include <cctype>
|
|
#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<uint32_t> validate_index_in_memory(nlohmann::json &document, uint32_t seq_id,
|
|
const std::string & default_sorting_field,
|
|
const tsl::htrie_map<char, field> & search_schema,
|
|
const index_operation_t op,
|
|
const std::string& fallback_field_type,
|
|
const DIRTY_VALUES& dirty_values);
|
|
|
|
|
|
static Option<uint32_t> 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<uint32_t> 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<uint32_t> 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<uint32_t> 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<uint32_t> 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<uint32_t> 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<uint32_t> 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);
|
|
|
|
}; |