diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index ff8d5900..114a4a31 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -1,538 +1,538 @@ -/* - Copyright <2018-2023> - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ -#ifndef REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ -#define REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ - -namespace repertory { -template class atomic final { -public: - atomic() : mtx_(std::make_shared()) {} - - atomic(const atomic &at_data) - : data_(static_cast(at_data)), - mtx_(std::make_shared()) {} - - atomic(data_t data) - : data_(std::move(data)), mtx_(std::make_shared()) {} - - atomic(atomic &&) = default; - - ~atomic() = default; - -private: - data_t data_; - std::shared_ptr mtx_; - -public: - auto operator=(const atomic &at_data) -> atomic & { - if (&at_data == this) { - return *this; - } - - mutex_lock lock(*mtx_); - static_cast(at_data) == data_; - return *this; - } - - auto operator=(atomic &&) -> atomic & = default; - - auto operator=(const data_t &data) -> atomic & { - if (&data == &data_) { - return *this; - } - - mutex_lock lock(*mtx_); - data_ = data; - return *this; - } - - [[nodiscard]] auto operator==(const atomic &at_data) const -> bool { - if (&at_data == this) { - return true; - } - - mutex_lock lock(*mtx_); - return static_cast(at_data) == data_; - } - - [[nodiscard]] auto operator==(const data_t &data) const -> bool { - if (&data == &data_) { - return true; - } - - mutex_lock lock(*mtx_); - return data == data_; - } - - [[nodiscard]] auto operator!=(const atomic &at_data) const -> bool { - if (&at_data == this) { - return false; - } - - mutex_lock lock(*mtx_); - return static_cast(at_data) != data_; - } - - [[nodiscard]] auto operator!=(const data_t &data) const -> bool { - if (&data == &data_) { - return false; - } - - mutex_lock lock(*mtx_); - return data != data_; - } - - [[nodiscard]] operator data_t() const { - mutex_lock lock(*mtx_); - return data_; - } -}; - -inline constexpr const auto max_time{ - std::numeric_limits::max(), -}; - -inline constexpr const std::string META_ACCESSED{"accessed"}; -inline constexpr const std::string META_ATTRIBUTES{"attributes"}; -inline constexpr const std::string META_BACKUP{"backup"}; -inline constexpr const std::string META_CHANGED{"changed"}; -inline constexpr const std::string META_CREATION{"creation"}; -inline constexpr const std::string META_DIRECTORY{"directory"}; -inline constexpr const std::string META_GID{"gid"}; -inline constexpr const std::string META_KEY{"key"}; -inline constexpr const std::string META_MODE{"mode"}; -inline constexpr const std::string META_MODIFIED{"modified"}; -inline constexpr const std::string META_OSXFLAGS{"flags"}; -inline constexpr const std::string META_PINNED{"pinned"}; -inline constexpr const std::string META_SIZE{"size"}; -inline constexpr const std::string META_SOURCE{"source"}; -inline constexpr const std::string META_UID{"uid"}; -inline constexpr const std::string META_WRITTEN{"written"}; - -inline constexpr const std::array META_USED_NAMES = { - META_ACCESSED, META_ATTRIBUTES, META_BACKUP, META_CHANGED, - META_CREATION, META_DIRECTORY, META_GID, META_KEY, - META_MODE, META_MODIFIED, META_OSXFLAGS, META_PINNED, - META_SIZE, META_SOURCE, META_UID, META_WRITTEN, -}; - -using api_meta_map = std::map; - -enum class api_error { - success = 0, - access_denied, - bad_address, - buffer_overflow, - buffer_too_small, - comm_error, - decryption_error, - directory_end_of_files, - directory_exists, - directory_not_empty, - directory_not_found, - download_failed, - download_incomplete, - download_stopped, - empty_ring_buffer_chunk_size, - empty_ring_buffer_size, - error, - file_in_use, - file_size_mismatch, - incompatible_version, - invalid_handle, - invalid_operation, - invalid_ring_buffer_multiple, - invalid_ring_buffer_size, - invalid_version, - item_exists, - item_not_found, - more_data, - no_disk_space, - not_implemented, - not_supported, - os_error, - out_of_memory, - permission_denied, - upload_failed, - xattr_buffer_small, - xattr_exists, - xattr_not_found, - xattr_too_big, - ERROR_COUNT -}; - -[[nodiscard]] auto api_error_from_string(std::string_view str) -> api_error; - -[[nodiscard]] auto api_error_to_string(const api_error &error) - -> const std::string &; - -enum class database_type { - rocksdb, - sqlite, -}; -[[nodiscard]] auto -database_type_from_string(std::string type, - database_type default_type = database_type::rocksdb) - -> database_type; - -[[nodiscard]] auto database_type_to_string(const database_type &type) - -> std::string; - -enum class download_type { - direct, - fallback, - ring_buffer, -}; -[[nodiscard]] auto -download_type_from_string(std::string type, - download_type default_type = download_type::fallback) - -> download_type; - -[[nodiscard]] auto download_type_to_string(const download_type &type) - -> std::string; - -enum class exit_code : std::int32_t { - success, - communication_error = -1, - file_creation_failed = -2, - incompatible_version = -3, - invalid_syntax = -4, - lock_failed = -5, - mount_active = -6, - mount_result = -7, - not_mounted = -8, - startup_exception = -9, - failed_to_get_mount_state = -10, - export_failed = -11, - import_failed = -12, - option_not_found = -13, - invalid_provider_type = -14, - set_option_not_found = -15, - pin_failed = -16, - unpin_failed = -17, - init_failed = -18, -}; - -enum http_error_codes : std::int32_t { - ok = 200, - multiple_choices = 300, - not_found = 404, -}; - -enum class lock_result { - success, - locked, - failure, -}; - -enum class provider_type : std::size_t { - sia, - remote, - s3, - encrypt, - unknown, -}; - -#if defined(_WIN32) -struct open_file_data final { - PVOID directory_buffer{nullptr}; -}; -#else -using open_file_data = int; -#endif - -struct api_file final { - std::string api_path; - std::string api_parent; - std::uint64_t accessed_date{}; - std::uint64_t changed_date{}; - std::uint64_t creation_date{}; - std::uint64_t file_size{}; - std::string key; - std::uint64_t modified_date{}; - std::string source_path; -}; - -struct directory_item final { - std::string api_path; - std::string api_parent; - bool directory{false}; - std::uint64_t size{}; - api_meta_map meta; - bool resolved{false}; -}; - -struct encrypt_config final { - std::string encryption_token; - std::string path; - - auto operator==(const encrypt_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return encryption_token == cfg.encryption_token && path == cfg.path; - } - - return true; - } - - auto operator!=(const encrypt_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return not(cfg == *this); - } - - return false; - } -}; - -struct filesystem_item final { - std::string api_path; - std::string api_parent; - bool directory{false}; - std::uint64_t size{}; - std::string source_path; -}; - -struct host_config final { - std::string agent_string; - std::string api_password; - std::string api_user; - std::uint16_t api_port; - std::string host_name_or_ip{"localhost"}; - std::string path; - std::string protocol{"http"}; - std::uint32_t timeout_ms{60000U}; - - auto operator==(const host_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return agent_string == cfg.agent_string && - api_password == cfg.api_password && api_user == cfg.api_user && - api_port == cfg.api_port && - host_name_or_ip == cfg.host_name_or_ip && path == cfg.path && - protocol == cfg.protocol && timeout_ms == cfg.timeout_ms; - } - - return true; - } - - auto operator!=(const host_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return not(cfg == *this); - } - - return false; - } -}; - -struct s3_config final { - std::string access_key; - std::string bucket; - std::string encryption_token; - std::string region{"any"}; - std::string secret_key; - std::uint32_t timeout_ms{60000U}; - std::string url; - bool use_path_style{false}; - bool use_region_in_url{false}; - - auto operator==(const s3_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return access_key == cfg.access_key && bucket == cfg.bucket && - encryption_token == cfg.encryption_token && region == cfg.region && - secret_key == cfg.secret_key && timeout_ms == cfg.timeout_ms && - url == cfg.url && use_path_style == cfg.use_path_style && - use_region_in_url == cfg.use_region_in_url; - } - - return true; - } - - auto operator!=(const s3_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return not(cfg == *this); - } - - return false; - } -}; - -struct sia_config final { - std::string bucket; - - auto operator==(const sia_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return bucket == cfg.bucket; - } - - return true; - } - - auto operator!=(const sia_config &cfg) const noexcept -> bool { - if (&cfg != this) { - return not(cfg == *this); - } - - return false; - } -}; - -using api_file_list = std::vector; -using api_file_provider_callback = std::function; -using api_item_added_callback = std::function; -using directory_item_list = std::vector; -using meta_provider_callback = std::function; -} // namespace repertory - -NLOHMANN_JSON_NAMESPACE_BEGIN -template <> struct adl_serializer { - static void to_json(json &data, const repertory::directory_item &value) { - data = { - {"ApiParent", value.api_parent}, - {"ApiPath", value.api_path}, - {"Directory", value.directory}, - {"Meta", value.meta}, - {"Size", value.size}, - }; - } - - static void from_json(const json &data, repertory::directory_item &value) { - data.at("ApiParent").get_to(value.api_parent); - data.at("ApiPath").get_to(value.api_path); - data.at("Directory").get_to(value.directory); - data.at("Meta").get_to(value.meta); - data.at("Size").get_to(value.size); - } -}; - -template <> struct adl_serializer { - static void to_json(json &data, const repertory::encrypt_config &value) { - data = { - {"EncryptionToken", value.encryption_token}, - {"Path", value.path}, - }; - } - - static void from_json(const json &data, repertory::encrypt_config &value) { - data.at("EncryptionToken").get_to(value.encryption_token); - data.at("Path").get_to(value.path); - } -}; - -template <> struct adl_serializer { - static void to_json(json &data, const repertory::host_config &value) { - data = { - {"AgentString", value.agent_string}, - {"ApiPassword", value.api_password}, - {"ApiPort", value.api_port}, - {"ApiUser", value.api_user}, - {"HostNameOrIp", value.host_name_or_ip}, - {"Path", value.path}, - {"Protocol", value.protocol}, - {"TimeoutMs", value.timeout_ms}, - }; - } - - static void from_json(const json &data, repertory::host_config &value) { - data.at("AgentString").get_to(value.agent_string); - data.at("ApiPassword").get_to(value.api_password); - data.at("ApiPort").get_to(value.api_port); - data.at("AuthUser").get_to(value.api_user); - data.at("HostNameOrIp").get_to(value.host_name_or_ip); - data.at("Path").get_to(value.path); - data.at("Protocol").get_to(value.protocol); - data.at("TimeoutMs").get_to(value.timeout_ms); - } -}; - -template <> struct adl_serializer { - static void to_json(json &data, const repertory::s3_config &value) { - data = { - {"AccessKey", value.access_key}, - {"Bucket", value.bucket}, - {"EncryptionToken", value.encryption_token}, - {"Region", value.region}, - {"SecretKey", value.secret_key}, - {"TimeoutMs", value.timeout_ms}, - {"URL", value.url}, - {"UsePathStyle", value.use_path_style}, - {"UseRegionInURL", value.use_region_in_url}, - }; - } - - static void from_json(const json &data, repertory::s3_config &value) { - data.at("AccessKey").get_to(value.access_key); - data.at("Bucket").get_to(value.bucket); - data.at("EncryptionToken").get_to(value.encryption_token); - data.at("Region").get_to(value.region); - data.at("SecretKey").get_to(value.secret_key); - data.at("TimeoutMs").get_to(value.timeout_ms); - data.at("URL").get_to(value.url); - data.at("UsePathStyle").get_to(value.use_path_style); - data.at("UseRegionInURL").get_to(value.use_region_in_url); - } -}; - -template <> struct adl_serializer { - static void to_json(json &data, const repertory::sia_config &value) { - data = { - {"Bucket", value.bucket}, - }; - } - - static void from_json(const json &data, repertory::sia_config &value) { - data.at("Bucket").get_to(value.bucket); - } -}; - -template struct adl_serializer> { - static void to_json(json &data, const repertory::atomic &value) { - data = static_cast(value); - } - - static void from_json(const json &data, repertory::atomic &value) { - value = data.get(); - } -}; - -template -struct adl_serializer> { - static void to_json(json &data, const std::atomic &value) { - data = value.load(); - } - - static void from_json(const json &data, std::atomic &value) { - value.store(data.get()); - } -}; - -template <> struct adl_serializer> { - static void to_json(json &data, - const std::atomic &value) { - data = repertory::database_type_to_string(value.load()); - } - - static void from_json(const json &data, - std::atomic &value) { - value.store(repertory::database_type_from_string(data.get())); - } -}; -NLOHMANN_JSON_NAMESPACE_END - -#endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ +/* + Copyright <2018-2023> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#ifndef REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ +#define REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ + +namespace repertory { +template class atomic final { +public: + atomic() : mtx_(std::make_shared()) {} + + atomic(const atomic &at_data) + : data_(static_cast(at_data)), + mtx_(std::make_shared()) {} + + atomic(data_t data) + : data_(std::move(data)), mtx_(std::make_shared()) {} + + atomic(atomic &&) = default; + + ~atomic() = default; + +private: + data_t data_; + std::shared_ptr mtx_; + +public: + auto operator=(const atomic &at_data) -> atomic & { + if (&at_data == this) { + return *this; + } + + mutex_lock lock(*mtx_); + static_cast(at_data) == data_; + return *this; + } + + auto operator=(atomic &&) -> atomic & = default; + + auto operator=(const data_t &data) -> atomic & { + if (&data == &data_) { + return *this; + } + + mutex_lock lock(*mtx_); + data_ = data; + return *this; + } + + [[nodiscard]] auto operator==(const atomic &at_data) const -> bool { + if (&at_data == this) { + return true; + } + + mutex_lock lock(*mtx_); + return static_cast(at_data) == data_; + } + + [[nodiscard]] auto operator==(const data_t &data) const -> bool { + if (&data == &data_) { + return true; + } + + mutex_lock lock(*mtx_); + return data == data_; + } + + [[nodiscard]] auto operator!=(const atomic &at_data) const -> bool { + if (&at_data == this) { + return false; + } + + mutex_lock lock(*mtx_); + return static_cast(at_data) != data_; + } + + [[nodiscard]] auto operator!=(const data_t &data) const -> bool { + if (&data == &data_) { + return false; + } + + mutex_lock lock(*mtx_); + return data != data_; + } + + [[nodiscard]] operator data_t() const { + mutex_lock lock(*mtx_); + return data_; + } +}; + +inline constexpr const auto max_time{ + std::numeric_limits::max(), +}; + +inline constexpr const std::string META_ACCESSED{"accessed"}; +inline constexpr const std::string META_ATTRIBUTES{"attributes"}; +inline constexpr const std::string META_BACKUP{"backup"}; +inline constexpr const std::string META_CHANGED{"changed"}; +inline constexpr const std::string META_CREATION{"creation"}; +inline constexpr const std::string META_DIRECTORY{"directory"}; +inline constexpr const std::string META_GID{"gid"}; +inline constexpr const std::string META_KEY{"key"}; +inline constexpr const std::string META_MODE{"mode"}; +inline constexpr const std::string META_MODIFIED{"modified"}; +inline constexpr const std::string META_OSXFLAGS{"flags"}; +inline constexpr const std::string META_PINNED{"pinned"}; +inline constexpr const std::string META_SIZE{"size"}; +inline constexpr const std::string META_SOURCE{"source"}; +inline constexpr const std::string META_UID{"uid"}; +inline constexpr const std::string META_WRITTEN{"written"}; + +inline constexpr const std::array META_USED_NAMES = { + META_ACCESSED, META_ATTRIBUTES, META_BACKUP, META_CHANGED, + META_CREATION, META_DIRECTORY, META_GID, META_KEY, + META_MODE, META_MODIFIED, META_OSXFLAGS, META_PINNED, + META_SIZE, META_SOURCE, META_UID, META_WRITTEN, +}; + +using api_meta_map = std::map; + +enum class api_error { + success = 0, + access_denied, + bad_address, + buffer_overflow, + buffer_too_small, + comm_error, + decryption_error, + directory_end_of_files, + directory_exists, + directory_not_empty, + directory_not_found, + download_failed, + download_incomplete, + download_stopped, + empty_ring_buffer_chunk_size, + empty_ring_buffer_size, + error, + file_in_use, + file_size_mismatch, + incompatible_version, + invalid_handle, + invalid_operation, + invalid_ring_buffer_multiple, + invalid_ring_buffer_size, + invalid_version, + item_exists, + item_not_found, + more_data, + no_disk_space, + not_implemented, + not_supported, + os_error, + out_of_memory, + permission_denied, + upload_failed, + xattr_buffer_small, + xattr_exists, + xattr_not_found, + xattr_too_big, + ERROR_COUNT +}; + +[[nodiscard]] auto api_error_from_string(std::string_view str) -> api_error; + +[[nodiscard]] auto api_error_to_string(const api_error &error) + -> const std::string &; + +enum class database_type { + rocksdb, + sqlite, +}; +[[nodiscard]] auto +database_type_from_string(std::string type, + database_type default_type = database_type::rocksdb) + -> database_type; + +[[nodiscard]] auto database_type_to_string(const database_type &type) + -> std::string; + +enum class download_type { + direct, + fallback, + ring_buffer, +}; +[[nodiscard]] auto +download_type_from_string(std::string type, + download_type default_type = download_type::fallback) + -> download_type; + +[[nodiscard]] auto download_type_to_string(const download_type &type) + -> std::string; + +enum class exit_code : std::int32_t { + success = 0, + communication_error = -1, + file_creation_failed = -2, + incompatible_version = -3, + invalid_syntax = -4, + lock_failed = -5, + mount_active = -6, + mount_result = -7, + not_mounted = -8, + startup_exception = -9, + failed_to_get_mount_state = -10, + export_failed = -11, + import_failed = -12, + option_not_found = -13, + invalid_provider_type = -14, + set_option_not_found = -15, + pin_failed = -16, + unpin_failed = -17, + init_failed = -18, +}; + +enum http_error_codes : std::int32_t { + ok = 200, + multiple_choices = 300, + not_found = 404, +}; + +enum class lock_result { + success, + locked, + failure, +}; + +enum class provider_type : std::size_t { + sia, + remote, + s3, + encrypt, + unknown, +}; + +#if defined(_WIN32) +struct open_file_data final { + PVOID directory_buffer{nullptr}; +}; +#else +using open_file_data = int; +#endif + +struct api_file final { + std::string api_path; + std::string api_parent; + std::uint64_t accessed_date{}; + std::uint64_t changed_date{}; + std::uint64_t creation_date{}; + std::uint64_t file_size{}; + std::string key; + std::uint64_t modified_date{}; + std::string source_path; +}; + +struct directory_item final { + std::string api_path; + std::string api_parent; + bool directory{false}; + std::uint64_t size{}; + api_meta_map meta; + bool resolved{false}; +}; + +struct encrypt_config final { + std::string encryption_token; + std::string path; + + auto operator==(const encrypt_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return encryption_token == cfg.encryption_token && path == cfg.path; + } + + return true; + } + + auto operator!=(const encrypt_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return not(cfg == *this); + } + + return false; + } +}; + +struct filesystem_item final { + std::string api_path; + std::string api_parent; + bool directory{false}; + std::uint64_t size{}; + std::string source_path; +}; + +struct host_config final { + std::string agent_string; + std::string api_password; + std::string api_user; + std::uint16_t api_port; + std::string host_name_or_ip{"localhost"}; + std::string path; + std::string protocol{"http"}; + std::uint32_t timeout_ms{60000U}; + + auto operator==(const host_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return agent_string == cfg.agent_string && + api_password == cfg.api_password && api_user == cfg.api_user && + api_port == cfg.api_port && + host_name_or_ip == cfg.host_name_or_ip && path == cfg.path && + protocol == cfg.protocol && timeout_ms == cfg.timeout_ms; + } + + return true; + } + + auto operator!=(const host_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return not(cfg == *this); + } + + return false; + } +}; + +struct s3_config final { + std::string access_key; + std::string bucket; + std::string encryption_token; + std::string region{"any"}; + std::string secret_key; + std::uint32_t timeout_ms{60000U}; + std::string url; + bool use_path_style{false}; + bool use_region_in_url{false}; + + auto operator==(const s3_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return access_key == cfg.access_key && bucket == cfg.bucket && + encryption_token == cfg.encryption_token && region == cfg.region && + secret_key == cfg.secret_key && timeout_ms == cfg.timeout_ms && + url == cfg.url && use_path_style == cfg.use_path_style && + use_region_in_url == cfg.use_region_in_url; + } + + return true; + } + + auto operator!=(const s3_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return not(cfg == *this); + } + + return false; + } +}; + +struct sia_config final { + std::string bucket; + + auto operator==(const sia_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return bucket == cfg.bucket; + } + + return true; + } + + auto operator!=(const sia_config &cfg) const noexcept -> bool { + if (&cfg != this) { + return not(cfg == *this); + } + + return false; + } +}; + +using api_file_list = std::vector; +using api_file_provider_callback = std::function; +using api_item_added_callback = std::function; +using directory_item_list = std::vector; +using meta_provider_callback = std::function; +} // namespace repertory + +NLOHMANN_JSON_NAMESPACE_BEGIN +template <> struct adl_serializer { + static void to_json(json &data, const repertory::directory_item &value) { + data = { + {"ApiParent", value.api_parent}, + {"ApiPath", value.api_path}, + {"Directory", value.directory}, + {"Meta", value.meta}, + {"Size", value.size}, + }; + } + + static void from_json(const json &data, repertory::directory_item &value) { + data.at("ApiParent").get_to(value.api_parent); + data.at("ApiPath").get_to(value.api_path); + data.at("Directory").get_to(value.directory); + data.at("Meta").get_to(value.meta); + data.at("Size").get_to(value.size); + } +}; + +template <> struct adl_serializer { + static void to_json(json &data, const repertory::encrypt_config &value) { + data = { + {"EncryptionToken", value.encryption_token}, + {"Path", value.path}, + }; + } + + static void from_json(const json &data, repertory::encrypt_config &value) { + data.at("EncryptionToken").get_to(value.encryption_token); + data.at("Path").get_to(value.path); + } +}; + +template <> struct adl_serializer { + static void to_json(json &data, const repertory::host_config &value) { + data = { + {"AgentString", value.agent_string}, + {"ApiPassword", value.api_password}, + {"ApiPort", value.api_port}, + {"ApiUser", value.api_user}, + {"HostNameOrIp", value.host_name_or_ip}, + {"Path", value.path}, + {"Protocol", value.protocol}, + {"TimeoutMs", value.timeout_ms}, + }; + } + + static void from_json(const json &data, repertory::host_config &value) { + data.at("AgentString").get_to(value.agent_string); + data.at("ApiPassword").get_to(value.api_password); + data.at("ApiPort").get_to(value.api_port); + data.at("AuthUser").get_to(value.api_user); + data.at("HostNameOrIp").get_to(value.host_name_or_ip); + data.at("Path").get_to(value.path); + data.at("Protocol").get_to(value.protocol); + data.at("TimeoutMs").get_to(value.timeout_ms); + } +}; + +template <> struct adl_serializer { + static void to_json(json &data, const repertory::s3_config &value) { + data = { + {"AccessKey", value.access_key}, + {"Bucket", value.bucket}, + {"EncryptionToken", value.encryption_token}, + {"Region", value.region}, + {"SecretKey", value.secret_key}, + {"TimeoutMs", value.timeout_ms}, + {"URL", value.url}, + {"UsePathStyle", value.use_path_style}, + {"UseRegionInURL", value.use_region_in_url}, + }; + } + + static void from_json(const json &data, repertory::s3_config &value) { + data.at("AccessKey").get_to(value.access_key); + data.at("Bucket").get_to(value.bucket); + data.at("EncryptionToken").get_to(value.encryption_token); + data.at("Region").get_to(value.region); + data.at("SecretKey").get_to(value.secret_key); + data.at("TimeoutMs").get_to(value.timeout_ms); + data.at("URL").get_to(value.url); + data.at("UsePathStyle").get_to(value.use_path_style); + data.at("UseRegionInURL").get_to(value.use_region_in_url); + } +}; + +template <> struct adl_serializer { + static void to_json(json &data, const repertory::sia_config &value) { + data = { + {"Bucket", value.bucket}, + }; + } + + static void from_json(const json &data, repertory::sia_config &value) { + data.at("Bucket").get_to(value.bucket); + } +}; + +template struct adl_serializer> { + static void to_json(json &data, const repertory::atomic &value) { + data = static_cast(value); + } + + static void from_json(const json &data, repertory::atomic &value) { + value = data.get(); + } +}; + +template +struct adl_serializer> { + static void to_json(json &data, const std::atomic &value) { + data = value.load(); + } + + static void from_json(const json &data, std::atomic &value) { + value.store(data.get()); + } +}; + +template <> struct adl_serializer> { + static void to_json(json &data, + const std::atomic &value) { + data = repertory::database_type_to_string(value.load()); + } + + static void from_json(const json &data, + std::atomic &value) { + value.store(repertory::database_type_from_string(data.get())); + } +}; +NLOHMANN_JSON_NAMESPACE_END + +#endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_