diff --git a/dump/src/reader/compat/mod.rs b/dump/src/reader/compat/mod.rs index 08fa97cc1..291035d0e 100644 --- a/dump/src/reader/compat/mod.rs +++ b/dump/src/reader/compat/mod.rs @@ -2,6 +2,7 @@ // pub mod v3; // pub mod v4; +// pub mod v4_to_v5; pub mod v5_to_v6; pub struct Compat { diff --git a/dump/src/reader/compat/v5_to_v6.rs b/dump/src/reader/compat/v5_to_v6.rs index b502ea169..7c085a224 100644 --- a/dump/src/reader/compat/v5_to_v6.rs +++ b/dump/src/reader/compat/v5_to_v6.rs @@ -1,5 +1,3 @@ -use std::fs::File; - use crate::reader::{v5, v6, DumpReader, IndexReader}; use crate::Result; @@ -44,52 +42,52 @@ impl DumpReader for CompatV5ToV6 { ) -> Box)>> + '_> { Box::new(self.from.tasks().map(|task| { task.map(|(task, content_file)| { - let task_view: v5::TaskView = task.into(); + let task_view: v5::tasks::TaskView = task.into(); let task = v6::Task { uid: task_view.uid, index_uid: task_view.index_uid, status: match task_view.status { - v5::TaskStatus::Enqueued => v6::Status::Enqueued, - v5::TaskStatus::Processing => v6::Status::Enqueued, - v5::TaskStatus::Succeeded => v6::Status::Succeeded, - v5::TaskStatus::Failed => v6::Status::Failed, + v5::Status::Enqueued => v6::Status::Enqueued, + v5::Status::Processing => v6::Status::Enqueued, + v5::Status::Succeeded => v6::Status::Succeeded, + v5::Status::Failed => v6::Status::Failed, }, kind: match task_view.task_type { - v5::TaskType::IndexCreation => v6::Kind::IndexCreation, - v5::TaskType::IndexUpdate => v6::Kind::IndexUpdate, - v5::TaskType::IndexDeletion => v6::Kind::IndexDeletion, + v5::Kind::IndexCreation => v6::Kind::IndexCreation, + v5::Kind::IndexUpdate => v6::Kind::IndexUpdate, + v5::Kind::IndexDeletion => v6::Kind::IndexDeletion, // TODO: this is a `DocumentAdditionOrUpdate` but we still don't have this type in the `TaskView`. - v5::TaskType::DocumentAdditionOrUpdate => v6::Kind::DocumentAddition, - v5::TaskType::DocumentDeletion => v6::Kind::DocumentDeletion, - v5::TaskType::SettingsUpdate => v6::Kind::Settings, - v5::TaskType::DumpCreation => v6::Kind::DumpExport, + v5::Kind::DocumentAdditionOrUpdate => v6::Kind::DocumentAddition, + v5::Kind::DocumentDeletion => v6::Kind::DocumentDeletion, + v5::Kind::SettingsUpdate => v6::Kind::Settings, + v5::Kind::DumpCreation => v6::Kind::DumpExport, }, details: task_view.details.map(|details| match details { - v5::TaskDetails::DocumentAddition { + v5::Details::DocumentAddition { received_documents, indexed_documents, } => v6::Details::DocumentAddition { received_documents: received_documents as u64, indexed_documents: indexed_documents.map_or(0, |i| i as u64), }, - v5::TaskDetails::Settings { settings } => v6::Details::Settings { + v5::Details::Settings { settings } => v6::Details::Settings { settings: settings.into(), }, - v5::TaskDetails::IndexInfo { primary_key } => { + v5::Details::IndexInfo { primary_key } => { v6::Details::IndexInfo { primary_key } } - v5::TaskDetails::DocumentDeletion { + v5::Details::DocumentDeletion { received_document_ids, deleted_documents, } => v6::Details::DocumentDeletion { received_document_ids, deleted_documents, }, - v5::TaskDetails::ClearAll { deleted_documents } => { + v5::Details::ClearAll { deleted_documents } => { v6::Details::ClearAll { deleted_documents } } - v5::TaskDetails::Dump { dump_uid } => v6::Details::Dump { dump_uid }, + v5::Details::Dump { dump_uid } => v6::Details::Dump { dump_uid }, }), error: task_view.error.map(|e| e.into()), duration: task_view.duration, diff --git a/dump/src/reader/v4/mod.rs b/dump/src/reader/v4/mod.rs index 95cb916c4..e58b711f7 100644 --- a/dump/src/reader/v4/mod.rs +++ b/dump/src/reader/v4/mod.rs @@ -16,17 +16,38 @@ mod tasks; use crate::{IndexMetadata, Result, Version}; -use self::{ - keys::Key, - meta::{DumpMeta, IndexUuid}, - settings::{Checked, Settings}, - tasks::Task, -}; +use self::meta::{DumpMeta, IndexUuid}; use super::{/* compat::v4_to_v5::CompatV4ToV5, */ DumpReader, IndexReader}; pub type Document = serde_json::Map; +pub type Settings = settings::Settings; +pub type Checked = settings::Checked; +pub type Unchecked = settings::Unchecked; + +pub type Task = tasks::Task; pub type UpdateFile = File; +pub type Key = keys::Key; + +// ===== Other types to clarify the code of the compat module +// everything related to the tasks +pub type Status = tasks::TaskStatus; +pub type Kind = tasks::TaskType; +pub type Details = tasks::TaskDetails; + +// everything related to the settings +pub type Setting = settings::Setting; +pub type TypoTolerance = settings::TypoSettings; +pub type MinWordSizeForTypos = settings::MinWordSizeTyposSetting; + +// everything related to the api keys +pub type Action = keys::Action; +pub type StarOr = meta::StarOr; +pub type IndexUid = meta::IndexUid; + +// everything related to the errors +pub type ResponseError = tasks::ResponseError; +pub type Code = meilisearch_types::error::Code; #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] diff --git a/dump/src/reader/v4/tasks.rs b/dump/src/reader/v4/tasks.rs index c6f31c9a8..5d2e519c0 100644 --- a/dump/src/reader/v4/tasks.rs +++ b/dump/src/reader/v4/tasks.rs @@ -52,7 +52,7 @@ pub enum TaskContent { #[cfg_attr(test, derive(serde::Serialize))] #[cfg_attr(test, serde(untagged))] #[allow(clippy::large_enum_variant)] -enum TaskDetails { +pub enum TaskDetails { #[cfg_attr(test, serde(rename_all = "camelCase"))] DocumentAddition { received_documents: usize, @@ -77,7 +77,7 @@ enum TaskDetails { #[derive(Debug)] #[cfg_attr(test, derive(serde::Serialize))] #[cfg_attr(test, serde(rename_all = "camelCase"))] -enum TaskStatus { +pub enum TaskStatus { Enqueued, Processing, Succeeded, @@ -87,7 +87,7 @@ enum TaskStatus { #[derive(Debug)] #[cfg_attr(test, derive(serde::Serialize))] #[cfg_attr(test, serde(rename_all = "camelCase"))] -enum TaskType { +pub enum TaskType { IndexCreation, IndexUpdate, IndexDeletion, diff --git a/dump/src/reader/v5/mod.rs b/dump/src/reader/v5/mod.rs index 5f50cee7e..252eda4a6 100644 --- a/dump/src/reader/v5/mod.rs +++ b/dump/src/reader/v5/mod.rs @@ -47,18 +47,41 @@ use crate::{IndexMetadata, Result, Version}; use super::{compat::v5_to_v6::CompatV5ToV6, DumpReader, IndexReader}; -mod keys; -mod meta; -mod settings; -mod tasks; - -pub use keys::*; -pub use meta::*; -pub use settings::*; -pub use tasks::*; +pub mod keys; +pub mod meta; +pub mod settings; +pub mod tasks; pub type Document = serde_json::Map; +pub type Settings = settings::Settings; +pub type Checked = settings::Checked; +pub type Unchecked = settings::Unchecked; + +pub type Task = tasks::Task; pub type UpdateFile = File; +pub type Key = keys::Key; + +// ===== Other types to clarify the code of the compat module +// everything related to the tasks +pub type Status = tasks::TaskStatus; +pub type Kind = tasks::TaskType; +pub type Details = tasks::TaskDetails; + +// everything related to the settings +pub type Setting = settings::Setting; +pub type TypoTolerance = settings::TypoSettings; +pub type MinWordSizeForTypos = settings::MinWordSizeTyposSetting; +pub type FacetingSettings = settings::FacetingSettings; +pub type PaginationSettings = settings::PaginationSettings; + +// everything related to the api keys +pub type Action = keys::Action; +pub type StarOr = meta::StarOr; +pub type IndexUid = meta::IndexUid; + +// everything related to the errors +pub type ResponseError = tasks::ResponseError; +pub type Code = meilisearch_types::error::Code; #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -75,7 +98,7 @@ pub struct V5Reader { metadata: Metadata, tasks: BufReader, keys: BufReader, - index_uuid: Vec, + index_uuid: Vec, } impl V5Reader { @@ -168,7 +191,7 @@ pub struct V5IndexReader { impl V5IndexReader { pub fn new(name: String, path: &Path) -> Result { let meta = File::open(path.join("meta.json"))?; - let meta: DumpMeta = serde_json::from_reader(meta)?; + let meta: meta::DumpMeta = serde_json::from_reader(meta)?; let metadata = IndexMetadata { uid: name,