From 784996368b40071a66d433ac83a2900e0e4d6025 Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 4 Jul 2022 14:28:41 +0800 Subject: [PATCH] chore: move entities from flowy-folder-data-model to flowy-folder crate --- frontend/rust-lib/Cargo.lock | 1 + frontend/rust-lib/flowy-folder/Cargo.toml | 1 + .../flowy-folder}/src/entities/app.rs | 34 ++++-- .../flowy-folder}/src/entities/mod.rs | 1 + .../entities}/parser/app/app_color_style.rs | 0 .../src/entities}/parser/app/app_desc.rs | 1 + .../src/entities}/parser/app/app_id.rs | 0 .../src/entities}/parser/app/app_name.rs | 0 .../src/entities}/parser/app/mod.rs | 0 .../flowy-folder/src/entities}/parser/mod.rs | 0 .../src/entities}/parser/trash/mod.rs | 0 .../src/entities}/parser/trash/trash_id.rs | 2 + .../src/entities}/parser/view/mod.rs | 4 - .../src/entities}/parser/view/view_desc.rs | 0 .../src/entities}/parser/view/view_id.rs | 0 .../src/entities}/parser/view/view_name.rs | 0 .../entities}/parser/view/view_thumbnail.rs | 0 .../src/entities}/parser/workspace/mod.rs | 0 .../parser/workspace/workspace_desc.rs | 0 .../parser/workspace/workspace_id.rs | 0 .../parser/workspace/workspace_name.rs | 0 .../flowy-folder}/src/entities/trash.rs | 71 +++++++++++- .../flowy-folder}/src/entities/view.rs | 61 +++++++---- .../flowy-folder}/src/entities/view_info.rs | 0 .../flowy-folder}/src/entities/workspace.rs | 20 ++-- frontend/rust-lib/flowy-folder/src/lib.rs | 4 +- frontend/rust-lib/flowy-folder/src/manager.rs | 2 +- .../persistence/version_1/trash_sql.rs | 49 ++++----- .../persistence/version_1/view_sql.rs | 12 +-- .../src/services/trash/controller.rs | 2 +- .../src/services/view/controller.rs | 29 ++--- .../src/services/view/event_handler.rs | 4 +- .../src/services/workspace/controller.rs | 2 +- .../src/services/workspace/event_handler.rs | 10 +- .../tests/workspace/folder_test.rs | 2 +- .../flowy-folder/tests/workspace/script.rs | 16 +-- .../flowy-net/src/http_server/folder.rs | 2 +- .../flowy-net/src/local_server/server.rs | 10 +- .../flowy-sdk/src/deps_resolve/folder_deps.rs | 2 +- frontend/rust-lib/flowy-test/src/helper.rs | 2 +- shared-lib/flowy-folder-data-model/Flowy.toml | 2 - shared-lib/flowy-folder-data-model/build.rs | 5 - shared-lib/flowy-folder-data-model/src/lib.rs | 5 - .../src/parser/view/delta_data.rs | 10 -- .../src/parser/view/view_ext.rs | 16 --- .../src/revision/app_rev.rs | 32 ++---- .../src/revision/trash_rev.rs | 102 +++++++++++------- .../src/revision/view_rev.rs | 43 ++++---- .../src/revision/workspace_rev.rs | 19 +--- .../src/user_default.rs | 11 +- 50 files changed, 323 insertions(+), 266 deletions(-) rename {shared-lib/flowy-folder-data-model => frontend/rust-lib/flowy-folder}/src/entities/app.rs (84%) rename {shared-lib/flowy-folder-data-model => frontend/rust-lib/flowy-folder}/src/entities/mod.rs (93%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/app/app_color_style.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/app/app_desc.rs (94%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/app/app_id.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/app/app_name.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/app/mod.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/mod.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/trash/mod.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/trash/trash_id.rs (93%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/view/mod.rs (67%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/view/view_desc.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/view/view_id.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/view/view_name.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/view/view_thumbnail.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/workspace/mod.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/workspace/workspace_desc.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/workspace/workspace_id.rs (100%) rename {shared-lib/flowy-folder-data-model/src => frontend/rust-lib/flowy-folder/src/entities}/parser/workspace/workspace_name.rs (100%) rename {shared-lib/flowy-folder-data-model => frontend/rust-lib/flowy-folder}/src/entities/trash.rs (55%) rename {shared-lib/flowy-folder-data-model => frontend/rust-lib/flowy-folder}/src/entities/view.rs (84%) rename {shared-lib/flowy-folder-data-model => frontend/rust-lib/flowy-folder}/src/entities/view_info.rs (100%) rename {shared-lib/flowy-folder-data-model => frontend/rust-lib/flowy-folder}/src/entities/workspace.rs (83%) delete mode 100644 shared-lib/flowy-folder-data-model/Flowy.toml delete mode 100644 shared-lib/flowy-folder-data-model/build.rs delete mode 100644 shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs delete mode 100644 shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index fa89ab3137..b3916ec2ec 100644 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -904,6 +904,7 @@ dependencies = [ "strum_macros", "tokio", "tracing", + "unicode-segmentation", ] [[package]] diff --git a/frontend/rust-lib/flowy-folder/Cargo.toml b/frontend/rust-lib/flowy-folder/Cargo.toml index ddc6f1f586..de149a4d9b 100644 --- a/frontend/rust-lib/flowy-folder/Cargo.toml +++ b/frontend/rust-lib/flowy-folder/Cargo.toml @@ -34,6 +34,7 @@ serde = { version = "1.0", features = ["derive"] } tracing = { version = "0.1", features = ["log"] } bytes = { version = "1.0" } +unicode-segmentation = "1.8" [dev-dependencies] serde_json = "1.0" flowy-folder = { path = "../flowy-folder", features = ["flowy_unit_test"]} diff --git a/shared-lib/flowy-folder-data-model/src/entities/app.rs b/frontend/rust-lib/flowy-folder/src/entities/app.rs similarity index 84% rename from shared-lib/flowy-folder-data-model/src/entities/app.rs rename to frontend/rust-lib/flowy-folder/src/entities/app.rs index 87983320d2..1c705d5b0e 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/app.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/app.rs @@ -1,20 +1,16 @@ use crate::{ - entities::view::RepeatedView, - errors::ErrorCode, - impl_def_and_def_mut, - parser::{ + entities::parser::{ app::{AppColorStyle, AppIdentify, AppName}, workspace::WorkspaceIdentify, }, + entities::view::RepeatedView, + errors::ErrorCode, + impl_def_and_def_mut, }; use flowy_derive::ProtoBuf; -use nanoid::nanoid; - +use flowy_folder_data_model::revision::AppRevision; use std::convert::TryInto; -pub fn gen_app_id() -> String { - nanoid!(10) -} #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct App { #[pb(index = 1)] @@ -42,6 +38,20 @@ pub struct App { pub create_time: i64, } +impl std::convert::From for App { + fn from(app_serde: AppRevision) -> Self { + App { + id: app_serde.id, + workspace_id: app_serde.workspace_id, + name: app_serde.name, + desc: app_serde.desc, + belongings: app_serde.belongings.into(), + version: app_serde.version, + modified_time: app_serde.modified_time, + create_time: app_serde.create_time, + } + } +} #[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)] pub struct RepeatedApp { #[pb(index = 1)] @@ -50,6 +60,12 @@ pub struct RepeatedApp { impl_def_and_def_mut!(RepeatedApp, App); +impl std::convert::From> for RepeatedApp { + fn from(values: Vec) -> Self { + let items = values.into_iter().map(|value| value.into()).collect::>(); + RepeatedApp { items } + } +} #[derive(ProtoBuf, Default)] pub struct CreateAppPayload { #[pb(index = 1)] diff --git a/shared-lib/flowy-folder-data-model/src/entities/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/mod.rs similarity index 93% rename from shared-lib/flowy-folder-data-model/src/entities/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/mod.rs index ed6954739c..e75c8c13bd 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/mod.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/mod.rs @@ -1,4 +1,5 @@ pub mod app; +mod parser; pub mod trash; pub mod view; mod view_info; diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_color_style.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_color_style.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_color_style.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_color_style.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_desc.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_desc.rs similarity index 94% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_desc.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_desc.rs index 047542d809..7f8e64808b 100644 --- a/shared-lib/flowy-folder-data-model/src/parser/app/app_desc.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_desc.rs @@ -3,6 +3,7 @@ use unicode_segmentation::UnicodeSegmentation; pub struct AppDesc(pub String); impl AppDesc { + #[allow(dead_code)] pub fn parse(s: String) -> Result { if s.graphemes(true).count() > 1024 { return Err("Workspace description too long".to_string()); diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_id.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_id.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_name.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_name.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_name.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_name.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/trash/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/trash/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/trash/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/trash/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/trash/trash_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/trash/trash_id.rs similarity index 93% rename from shared-lib/flowy-folder-data-model/src/parser/trash/trash_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/trash/trash_id.rs index 3b1c0646b2..2b629e33ec 100644 --- a/shared-lib/flowy-folder-data-model/src/parser/trash/trash_id.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/parser/trash/trash_id.rs @@ -2,6 +2,7 @@ pub struct TrashIdentify(pub String); impl TrashIdentify { + #[allow(dead_code)] pub fn parse(s: String) -> Result { if s.trim().is_empty() { return Err("Trash id can not be empty or whitespace".to_string()); @@ -21,6 +22,7 @@ impl AsRef for TrashIdentify { pub struct TrashIds(pub Vec); impl TrashIds { + #[allow(dead_code)] pub fn parse(ids: Vec) -> Result { let mut trash_ids = vec![]; for id in ids { diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/mod.rs similarity index 67% rename from shared-lib/flowy-folder-data-model/src/parser/view/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/mod.rs index 39d7b2385a..399cc44c45 100644 --- a/shared-lib/flowy-folder-data-model/src/parser/view/mod.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/parser/view/mod.rs @@ -1,13 +1,9 @@ -mod delta_data; mod view_desc; -mod view_ext; mod view_id; mod view_name; mod view_thumbnail; -pub use delta_data::*; pub use view_desc::*; -pub use view_ext::*; pub use view_id::*; pub use view_name::*; pub use view_thumbnail::*; diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_desc.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_desc.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_desc.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_desc.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_id.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_id.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_name.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_name.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_name.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_name.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_thumbnail.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_thumbnail.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_thumbnail.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_thumbnail.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_desc.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_desc.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_desc.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_desc.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_id.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_id.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_name.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_name.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_name.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_name.rs diff --git a/shared-lib/flowy-folder-data-model/src/entities/trash.rs b/frontend/rust-lib/flowy-folder/src/entities/trash.rs similarity index 55% rename from shared-lib/flowy-folder-data-model/src/entities/trash.rs rename to frontend/rust-lib/flowy-folder/src/entities/trash.rs index 68b3d0a26e..c332dded18 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/trash.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/trash.rs @@ -1,6 +1,6 @@ use crate::impl_def_and_def_mut; -use crate::revision::TrashRevision; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_folder_data_model::revision::{TrashRevision, TrashTypeRevision}; use serde::{Deserialize, Serialize}; use std::fmt::Formatter; @@ -22,6 +22,29 @@ pub struct Trash { pub ty: TrashType, } +impl std::convert::From for Trash { + fn from(trash_rev: TrashRevision) -> Self { + Trash { + id: trash_rev.id, + name: trash_rev.name, + modified_time: trash_rev.modified_time, + create_time: trash_rev.create_time, + ty: trash_rev.ty.into(), + } + } +} + +impl std::convert::From for TrashRevision { + fn from(trash: Trash) -> Self { + TrashRevision { + id: trash.id, + name: trash.name, + modified_time: trash.modified_time, + create_time: trash.create_time, + ty: trash.ty.into(), + } + } +} #[derive(PartialEq, Debug, Default, ProtoBuf, Clone)] pub struct RepeatedTrash { #[pb(index = 1)] @@ -29,10 +52,16 @@ pub struct RepeatedTrash { } impl_def_and_def_mut!(RepeatedTrash, Trash); +impl std::convert::From> for RepeatedTrash { + fn from(trash_revs: Vec) -> Self { + let items: Vec = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect(); + RepeatedTrash { items } + } +} #[derive(Eq, PartialEq, Debug, ProtoBuf_Enum, Clone, Serialize, Deserialize)] pub enum TrashType { - Unknown = 0, + TrashUnknown = 0, TrashView = 1, TrashApp = 2, } @@ -42,7 +71,7 @@ impl std::convert::TryFrom for TrashType { fn try_from(value: i32) -> Result { match value { - 0 => Ok(TrashType::Unknown), + 0 => Ok(TrashType::TrashUnknown), 1 => Ok(TrashType::TrashView), 2 => Ok(TrashType::TrashApp), _ => Err(format!("Invalid trash type: {}", value)), @@ -50,9 +79,29 @@ impl std::convert::TryFrom for TrashType { } } +impl std::convert::From for TrashType { + fn from(rev: TrashTypeRevision) -> Self { + match rev { + TrashTypeRevision::Unknown => TrashType::TrashUnknown, + TrashTypeRevision::TrashView => TrashType::TrashView, + TrashTypeRevision::TrashApp => TrashType::TrashApp, + } + } +} + +impl std::convert::From for TrashTypeRevision { + fn from(rev: TrashType) -> Self { + match rev { + TrashType::TrashUnknown => TrashTypeRevision::Unknown, + TrashType::TrashView => TrashTypeRevision::TrashView, + TrashType::TrashApp => TrashTypeRevision::TrashApp, + } + } +} + impl std::default::Default for TrashType { fn default() -> Self { - TrashType::Unknown + TrashType::TrashUnknown } } @@ -96,7 +145,10 @@ impl std::convert::From> for RepeatedTrashId { fn from(trash: Vec) -> Self { let items = trash .into_iter() - .map(|t| TrashId { id: t.id, ty: t.ty }) + .map(|t| TrashId { + id: t.id, + ty: t.ty.into(), + }) .collect::>(); RepeatedTrashId { @@ -120,3 +172,12 @@ impl std::fmt::Display for TrashId { f.write_str(&format!("{:?}:{}", self.ty, self.id)) } } + +impl std::convert::From<&TrashRevision> for TrashId { + fn from(trash: &TrashRevision) -> Self { + TrashId { + id: trash.id.clone(), + ty: trash.ty.clone().into(), + } + } +} diff --git a/shared-lib/flowy-folder-data-model/src/entities/view.rs b/frontend/rust-lib/flowy-folder/src/entities/view.rs similarity index 84% rename from shared-lib/flowy-folder-data-model/src/entities/view.rs rename to frontend/rust-lib/flowy-folder/src/entities/view.rs index 445aa6544a..ca54ec8cff 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/view.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/view.rs @@ -1,20 +1,15 @@ use crate::{ - errors::ErrorCode, - impl_def_and_def_mut, - parser::{ + entities::parser::{ app::AppIdentify, view::{ViewDesc, ViewIdentify, ViewName, ViewThumbnail}, }, + errors::ErrorCode, + impl_def_and_def_mut, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; -use nanoid::nanoid; -use serde_repr::*; +use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewRevision}; use std::convert::TryInto; -pub fn gen_view_id() -> String { - nanoid!(10) -} - #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct View { #[pb(index = 1)] @@ -39,8 +34,21 @@ pub struct View { pub plugin_type: i32, } -#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone, Serialize_repr, Deserialize_repr)] -#[repr(u8)] +impl std::convert::From for View { + fn from(rev: ViewRevision) -> Self { + View { + id: rev.id, + belong_to_id: rev.belong_to_id, + name: rev.name, + data_type: rev.data_type.into(), + modified_time: rev.modified_time, + create_time: rev.create_time, + plugin_type: rev.plugin_type, + } + } +} + +#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)] pub enum ViewDataType { TextBlock = 0, Grid = 1, @@ -48,19 +56,24 @@ pub enum ViewDataType { impl std::default::Default for ViewDataType { fn default() -> Self { - ViewDataType::TextBlock + ViewDataTypeRevision::default().into() } } -impl std::convert::From for ViewDataType { - fn from(val: i32) -> Self { - match val { - 0 => ViewDataType::TextBlock, - 1 => ViewDataType::Grid, - _ => { - log::error!("Invalid view type: {}", val); - ViewDataType::TextBlock - } +impl std::convert::From for ViewDataType { + fn from(rev: ViewDataTypeRevision) -> Self { + match rev { + ViewDataTypeRevision::TextBlock => ViewDataType::TextBlock, + ViewDataTypeRevision::Grid => ViewDataType::Grid, + } + } +} + +impl std::convert::From for ViewDataTypeRevision { + fn from(ty: ViewDataType) -> Self { + match ty { + ViewDataType::TextBlock => ViewDataTypeRevision::TextBlock, + ViewDataType::Grid => ViewDataTypeRevision::Grid, } } } @@ -73,6 +86,12 @@ pub struct RepeatedView { impl_def_and_def_mut!(RepeatedView, View); +impl std::convert::From> for RepeatedView { + fn from(values: Vec) -> Self { + let items = values.into_iter().map(|value| value.into()).collect::>(); + RepeatedView { items } + } +} #[derive(Default, ProtoBuf)] pub struct RepeatedViewId { #[pb(index = 1)] diff --git a/shared-lib/flowy-folder-data-model/src/entities/view_info.rs b/frontend/rust-lib/flowy-folder/src/entities/view_info.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/entities/view_info.rs rename to frontend/rust-lib/flowy-folder/src/entities/view_info.rs diff --git a/shared-lib/flowy-folder-data-model/src/entities/workspace.rs b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs similarity index 83% rename from shared-lib/flowy-folder-data-model/src/entities/workspace.rs rename to frontend/rust-lib/flowy-folder/src/entities/workspace.rs index 66f11ab9b0..a9f61b50c8 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/workspace.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs @@ -1,17 +1,13 @@ use crate::{ + entities::parser::workspace::{WorkspaceDesc, WorkspaceIdentify, WorkspaceName}, entities::{app::RepeatedApp, view::View}, errors::*, impl_def_and_def_mut, - parser::workspace::{WorkspaceDesc, WorkspaceIdentify, WorkspaceName}, }; use flowy_derive::ProtoBuf; -use nanoid::nanoid; - +use flowy_folder_data_model::revision::WorkspaceRevision; use std::convert::TryInto; -pub fn gen_workspace_id() -> String { - nanoid!(10) -} #[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)] pub struct Workspace { #[pb(index = 1)] @@ -33,6 +29,18 @@ pub struct Workspace { pub create_time: i64, } +impl std::convert::From for Workspace { + fn from(workspace_serde: WorkspaceRevision) -> Self { + Workspace { + id: workspace_serde.id, + name: workspace_serde.name, + desc: workspace_serde.desc, + apps: workspace_serde.apps.into(), + modified_time: workspace_serde.modified_time, + create_time: workspace_serde.create_time, + } + } +} #[derive(PartialEq, Debug, Default, ProtoBuf)] pub struct RepeatedWorkspace { #[pb(index = 1)] diff --git a/frontend/rust-lib/flowy-folder/src/lib.rs b/frontend/rust-lib/flowy-folder/src/lib.rs index 0137664274..5b7e625b0c 100644 --- a/frontend/rust-lib/flowy-folder/src/lib.rs +++ b/frontend/rust-lib/flowy-folder/src/lib.rs @@ -1,4 +1,4 @@ -pub use flowy_folder_data_model::entities; +pub mod entities; pub mod event_map; pub mod services; @@ -14,8 +14,6 @@ pub mod protobuf; mod util; pub mod prelude { - pub use flowy_folder_data_model::entities::{app::*, trash::*, view::*, workspace::*}; - pub use crate::{errors::*, event_map::*}; } diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs index f2b871475d..b6555035d3 100644 --- a/frontend/rust-lib/flowy-folder/src/manager.rs +++ b/frontend/rust-lib/flowy-folder/src/manager.rs @@ -1,3 +1,4 @@ +use crate::entities::view::ViewDataType; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, entities::workspace::RepeatedWorkspace, @@ -10,7 +11,6 @@ use crate::{ }; use bytes::Bytes; use flowy_error::FlowyError; -use flowy_folder_data_model::entities::view::ViewDataType; use flowy_folder_data_model::user_default; use flowy_revision::disk::SQLiteTextBlockRevisionPersistence; use flowy_revision::{RevisionManager, RevisionPersistence, RevisionWebSocket}; diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs index c4f6fff365..2e69a4ba1c 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs @@ -1,14 +1,11 @@ -use crate::{ - entities::trash::{Trash, TrashType}, - errors::FlowyError, -}; +use crate::errors::FlowyError; use diesel::sql_types::Integer; use flowy_database::{ prelude::*, schema::{trash_table, trash_table::dsl}, SqliteConnection, }; -use flowy_folder_data_model::revision::TrashRevision; +use flowy_folder_data_model::revision::{TrashRevision, TrashTypeRevision}; pub struct TrashTableSql(); impl TrashTableSql { @@ -64,18 +61,18 @@ pub(crate) struct TrashTable { pub create_time: i64, pub ty: SqlTrashType, } -impl std::convert::From for Trash { - fn from(table: TrashTable) -> Self { - Trash { - id: table.id, - name: table.name, - modified_time: table.modified_time, - create_time: table.create_time, - ty: table.ty.into(), - } - } -} - +// impl std::convert::From for Trash { +// fn from(table: TrashTable) -> Self { +// Trash { +// id: table.id, +// name: table.name, +// modified_time: table.modified_time, +// create_time: table.create_time, +// ty: table.ty.into(), +// } +// } +// } +// impl std::convert::From for TrashRevision { fn from(trash: TrashTable) -> Self { TrashRevision { @@ -141,22 +138,22 @@ impl std::convert::From for SqlTrashType { impl_sql_integer_expression!(SqlTrashType); -impl std::convert::From for TrashType { +impl std::convert::From for TrashTypeRevision { fn from(ty: SqlTrashType) -> Self { match ty { - SqlTrashType::Unknown => TrashType::Unknown, - SqlTrashType::View => TrashType::TrashView, - SqlTrashType::App => TrashType::TrashApp, + SqlTrashType::Unknown => TrashTypeRevision::Unknown, + SqlTrashType::View => TrashTypeRevision::TrashView, + SqlTrashType::App => TrashTypeRevision::TrashApp, } } } -impl std::convert::From for SqlTrashType { - fn from(ty: TrashType) -> Self { +impl std::convert::From for SqlTrashType { + fn from(ty: TrashTypeRevision) -> Self { match ty { - TrashType::Unknown => SqlTrashType::Unknown, - TrashType::TrashView => SqlTrashType::View, - TrashType::TrashApp => SqlTrashType::App, + TrashTypeRevision::Unknown => SqlTrashType::Unknown, + TrashTypeRevision::TrashView => SqlTrashType::View, + TrashTypeRevision::TrashApp => SqlTrashType::App, } } } diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs index 08c96ac90c..ec1bbf38bf 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs @@ -1,7 +1,7 @@ use crate::{ entities::{ trash::{Trash, TrashType}, - view::{UpdateViewParams, ViewDataType}, + view::UpdateViewParams, }, errors::FlowyError, services::persistence::version_1::app_sql::AppTable, @@ -13,7 +13,7 @@ use flowy_database::{ SqliteConnection, }; -use flowy_folder_data_model::revision::ViewRevision; +use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewRevision}; use lib_infra::util::timestamp; pub struct ViewTableSql(); @@ -87,8 +87,8 @@ pub(crate) struct ViewTable { impl ViewTable { pub fn new(view_rev: ViewRevision) -> Self { let data_type = match view_rev.data_type { - ViewDataType::TextBlock => SqlViewDataType::Block, - ViewDataType::Grid => SqlViewDataType::Grid, + ViewDataTypeRevision::TextBlock => SqlViewDataType::Block, + ViewDataTypeRevision::Grid => SqlViewDataType::Grid, }; ViewTable { @@ -110,8 +110,8 @@ impl ViewTable { impl std::convert::From for ViewRevision { fn from(table: ViewTable) -> Self { let data_type = match table.view_type { - SqlViewDataType::Block => ViewDataType::TextBlock, - SqlViewDataType::Grid => ViewDataType::Grid, + SqlViewDataType::Block => ViewDataTypeRevision::TextBlock, + SqlViewDataType::Grid => ViewDataTypeRevision::Grid, }; ViewRevision { diff --git a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs index 5fe144e81f..134e8a0d84 100644 --- a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs @@ -51,7 +51,7 @@ impl TrashController { let identifier = TrashId { id: trash.id, - ty: trash.ty, + ty: trash.ty.into(), }; let _ = self.delete_trash_on_server(RepeatedTrashId { diff --git a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs index 1491373b20..d573b096f6 100644 --- a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs @@ -1,3 +1,5 @@ +pub use crate::entities::view::ViewDataType; +use crate::entities::ViewInfo; use crate::manager::{ViewDataProcessor, ViewDataProcessorMap}; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, @@ -14,9 +16,7 @@ use crate::{ }; use bytes::Bytes; use flowy_database::kv::KV; -use flowy_folder_data_model::entities::view::{gen_view_id, ViewDataType}; -use flowy_folder_data_model::entities::ViewInfo; -use flowy_folder_data_model::revision::ViewRevision; +use flowy_folder_data_model::revision::{gen_view_id, ViewRevision}; use flowy_sync::entities::text_block::TextBlockId; use futures::{FutureExt, StreamExt}; use std::{collections::HashSet, sync::Arc}; @@ -58,7 +58,7 @@ impl ViewController { &self, mut params: CreateViewParams, ) -> Result { - let processor = self.get_data_processor(¶ms.data_type)?; + let processor = self.get_data_processor(params.data_type.clone())?; let user_id = self.user.user_id()?; if params.data.is_empty() { let view_data = processor.create_default_view(&user_id, ¶ms.view_id).await?; @@ -88,7 +88,7 @@ impl ViewController { return Err(FlowyError::internal().context("The content of the view should not be empty")); } let user_id = self.user.user_id()?; - let processor = self.get_data_processor(&data_type)?; + let processor = self.get_data_processor(data_type)?; let _ = processor.create_container(&user_id, view_id, delta_data).await?; Ok(()) } @@ -140,7 +140,7 @@ impl ViewController { belong_to_id: view_rev.belong_to_id, name: view_rev.name, desc: view_rev.desc, - data_type: view_rev.data_type, + data_type: view_rev.data_type.into(), belongings: RepeatedView { items }, ext_data: view_rev.ext_data, }; @@ -209,14 +209,14 @@ impl ViewController { .begin_transaction(|transaction| transaction.read_view(view_id)) .await?; - let processor = self.get_data_processor(&view_rev.data_type)?; + let processor = self.get_data_processor(view_rev.data_type.clone())?; let delta_bytes = processor.get_delta_data(view_id).await?; let duplicate_params = CreateViewParams { belong_to_id: view_rev.belong_to_id.clone(), name: format!("{} (copy)", &view_rev.name), desc: view_rev.desc, thumbnail: view_rev.thumbnail, - data_type: view_rev.data_type, + data_type: view_rev.data_type.into(), data: delta_bytes.to_vec(), view_id: gen_view_id(), plugin_type: view_rev.plugin_type, @@ -360,12 +360,16 @@ impl ViewController { .persistence .begin_transaction(|transaction| transaction.read_view(view_id)) .await?; - self.get_data_processor(&view.data_type) + self.get_data_processor(view.data_type) } #[inline] - fn get_data_processor(&self, data_type: &ViewDataType) -> FlowyResult> { - match self.data_processors.get(data_type) { + fn get_data_processor>( + &self, + data_type: T, + ) -> FlowyResult> { + let data_type = data_type.into(); + match self.data_processors.get(&data_type) { None => Err(FlowyError::internal().context(format!( "Get data processor failed. Unknown view data type: {:?}", data_type @@ -429,7 +433,8 @@ async fn handle_trash_event( .await?; for view in views { - match get_data_processor(data_processors.clone(), &view.data_type) { + let data_type = view.data_type.clone().into(); + match get_data_processor(data_processors.clone(), &data_type) { Ok(processor) => { let _ = processor.close_container(&view.id).await?; } diff --git a/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs index cfacc23e0e..f970905f30 100644 --- a/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs @@ -1,3 +1,5 @@ +use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayload, MoveFolderItemType}; +use crate::entities::ViewInfo; use crate::manager::FolderManager; use crate::services::{notify_workspace_setting_did_change, AppController}; use crate::{ @@ -10,8 +12,6 @@ use crate::{ errors::FlowyError, services::{TrashController, ViewController}, }; -use flowy_folder_data_model::entities::view::{MoveFolderItemParams, MoveFolderItemPayload, MoveFolderItemType}; -use flowy_folder_data_model::entities::ViewInfo; use flowy_folder_data_model::revision::TrashRevision; use lib_dispatch::prelude::{data_result, AppData, Data, DataResult}; use std::{convert::TryInto, sync::Arc}; diff --git a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs index f1b4ab5289..9863cafdc5 100644 --- a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs @@ -1,3 +1,4 @@ +use crate::entities::workspace::*; use crate::manager::FolderManager; use crate::{ dart_notification::*, @@ -9,7 +10,6 @@ use crate::{ }, }; use flowy_database::kv::KV; -use flowy_folder_data_model::entities::workspace::*; use flowy_folder_data_model::revision::{AppRevision, WorkspaceRevision}; use std::sync::Arc; diff --git a/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs index 3760d06bf6..02fb37a12b 100644 --- a/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs @@ -1,14 +1,14 @@ +use crate::entities::{ + app::RepeatedApp, + view::View, + workspace::{CurrentWorkspaceSetting, RepeatedWorkspace, WorkspaceId, *}, +}; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, errors::FlowyError, manager::FolderManager, services::{get_current_workspace, read_local_workspace_apps, WorkspaceController}, }; -use flowy_folder_data_model::entities::{ - app::RepeatedApp, - view::View, - workspace::{CurrentWorkspaceSetting, RepeatedWorkspace, WorkspaceId, *}, -}; use lib_dispatch::prelude::{data_result, AppData, Data, DataResult}; use std::{convert::TryInto, sync::Arc}; diff --git a/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs b/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs index 9eaee19b61..86c3dc7478 100644 --- a/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs +++ b/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs @@ -1,6 +1,6 @@ use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest}; +use flowy_folder::entities::view::ViewDataType; use flowy_folder::entities::workspace::CreateWorkspacePayload; -use flowy_folder_data_model::entities::view::ViewDataType; use flowy_revision::disk::RevisionState; use flowy_test::{event_builder::*, FlowySDKTest}; diff --git a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs index 5d62e31d9e..b461730cf9 100644 --- a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs +++ b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs @@ -1,19 +1,19 @@ -use flowy_folder::event_map::FolderEvent::*; -use flowy_folder::{errors::ErrorCode, services::folder_editor::FolderEditor}; -use flowy_folder_data_model::entities::view::{RepeatedViewId, ViewId}; -use flowy_folder_data_model::entities::workspace::WorkspaceId; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::view::{RepeatedViewId, ViewId}; +use flowy_folder::entities::workspace::WorkspaceId; +use flowy_folder::entities::{ app::{App, RepeatedApp}, trash::Trash, view::{RepeatedView, View, ViewDataType}, workspace::Workspace, }; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::{ app::{AppId, CreateAppPayload, UpdateAppPayload}, trash::{RepeatedTrash, TrashId, TrashType}, view::{CreateViewPayload, UpdateViewPayload}, workspace::{CreateWorkspacePayload, RepeatedWorkspace}, }; +use flowy_folder::event_map::FolderEvent::*; +use flowy_folder::{errors::ErrorCode, services::folder_editor::FolderEditor}; use flowy_revision::disk::RevisionState; use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS; @@ -205,7 +205,7 @@ impl FolderTest { restore_view_from_trash(sdk, &self.view.id).await; } FolderScript::ReadTrash => { - let trash = read_trash(sdk).await; + let mut trash = read_trash(sdk).await; self.trash = trash.into_inner(); } FolderScript::DeleteAllTrash => { @@ -264,7 +264,7 @@ pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Wor pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option) -> Vec { let request = WorkspaceId { value: workspace_id }; - let repeated_workspace = FolderEventBuilder::new(sdk.clone()) + let mut repeated_workspace = FolderEventBuilder::new(sdk.clone()) .event(ReadWorkspaces) .payload(request.clone()) .async_send() diff --git a/frontend/rust-lib/flowy-net/src/http_server/folder.rs b/frontend/rust-lib/flowy-net/src/http_server/folder.rs index 9781ea727a..788f7fa462 100644 --- a/frontend/rust-lib/flowy-net/src/http_server/folder.rs +++ b/frontend/rust-lib/flowy-net/src/http_server/folder.rs @@ -3,7 +3,7 @@ use crate::{ request::{HttpRequestBuilder, ResponseMiddleware}, }; use flowy_error::FlowyError; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::{ trash::RepeatedTrashId, view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, diff --git a/frontend/rust-lib/flowy-net/src/local_server/server.rs b/frontend/rust-lib/flowy-net/src/local_server/server.rs index 79a9a1963b..ec7b9db0cd 100644 --- a/frontend/rust-lib/flowy-net/src/local_server/server.rs +++ b/frontend/rust-lib/flowy-net/src/local_server/server.rs @@ -252,15 +252,15 @@ impl RevisionUser for LocalRevisionUser { } } -use flowy_folder_data_model::entities::app::gen_app_id; -use flowy_folder_data_model::entities::workspace::gen_workspace_id; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::{ app::{AppId, CreateAppParams, UpdateAppParams}, trash::RepeatedTrashId, view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, }; -use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision}; +use flowy_folder_data_model::revision::{ + gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision, +}; use flowy_text_block::BlockCloudService; use flowy_user::event_map::UserCloudService; use flowy_user_data_model::entities::{ @@ -308,7 +308,7 @@ impl FolderCouldServiceV1 for LocalServer { belong_to_id: params.belong_to_id, name: params.name, desc: params.desc, - data_type: params.data_type, + data_type: params.data_type.into(), version: 0, belongings: vec![], modified_time: time, diff --git a/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs index f1257dc3ad..24bb71d89c 100644 --- a/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs +++ b/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs @@ -1,7 +1,7 @@ use bytes::Bytes; use flowy_database::ConnectionPool; +use flowy_folder::entities::ViewDataType; use flowy_folder::manager::{ViewDataProcessor, ViewDataProcessorMap}; -use flowy_folder::prelude::ViewDataType; use flowy_folder::{ errors::{internal_error, FlowyError}, event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser}, diff --git a/frontend/rust-lib/flowy-test/src/helper.rs b/frontend/rust-lib/flowy-test/src/helper.rs index 2bb9622914..efc4282386 100644 --- a/frontend/rust-lib/flowy-test/src/helper.rs +++ b/frontend/rust-lib/flowy-test/src/helper.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use flowy_folder::prelude::WorkspaceId; +use flowy_folder::entities::WorkspaceId; use flowy_folder::{ entities::{ app::*, diff --git a/shared-lib/flowy-folder-data-model/Flowy.toml b/shared-lib/flowy-folder-data-model/Flowy.toml deleted file mode 100644 index e98441c877..0000000000 --- a/shared-lib/flowy-folder-data-model/Flowy.toml +++ /dev/null @@ -1,2 +0,0 @@ -# Check out the FlowyConfig (located in flowy_toml.rs) for more details. -proto_input = ["src/entities",] diff --git a/shared-lib/flowy-folder-data-model/build.rs b/shared-lib/flowy-folder-data-model/build.rs deleted file mode 100644 index e897c3690d..0000000000 --- a/shared-lib/flowy-folder-data-model/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -use lib_infra::code_gen; - -fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); -} diff --git a/shared-lib/flowy-folder-data-model/src/lib.rs b/shared-lib/flowy-folder-data-model/src/lib.rs index e1f796b672..783eab5f75 100644 --- a/shared-lib/flowy-folder-data-model/src/lib.rs +++ b/shared-lib/flowy-folder-data-model/src/lib.rs @@ -1,11 +1,6 @@ -pub mod entities; -pub mod parser; - #[macro_use] mod macros; -// #[cfg(feature = "backend")] -pub mod protobuf; pub mod revision; pub mod user_default; diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs b/shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs deleted file mode 100644 index 00986383b7..0000000000 --- a/shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[derive(Debug)] -pub struct DeltaData(pub Vec); - -impl DeltaData { - pub fn parse(data: Vec) -> Result { - // let _ = Delta::from_bytes(data.clone()).map_err(|e| format!("{:?}", e))?; - - Ok(Self(data)) - } -} diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs b/shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs deleted file mode 100644 index 1bb48711bc..0000000000 --- a/shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs +++ /dev/null @@ -1,16 +0,0 @@ -use crate::errors::ErrorCode; - -#[derive(Debug)] -pub struct ViewExtensionData(pub String); - -impl ViewExtensionData { - pub fn parse(s: String) -> Result { - Ok(Self(s)) - } -} - -impl AsRef for ViewExtensionData { - fn as_ref(&self) -> &str { - &self.0 - } -} diff --git a/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs index 82b9af3812..015cb70427 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs @@ -1,8 +1,10 @@ -use crate::entities::app::App; -use crate::entities::{RepeatedApp, TrashType}; -use crate::revision::{TrashRevision, ViewRevision}; +use crate::revision::{TrashRevision, TrashTypeRevision, ViewRevision}; +use nanoid::nanoid; use serde::{Deserialize, Serialize}; +pub fn gen_app_id() -> String { + nanoid!(10) +} #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct AppRevision { pub id: String, @@ -22,21 +24,6 @@ pub struct AppRevision { pub create_time: i64, } -impl std::convert::From for App { - fn from(app_serde: AppRevision) -> Self { - App { - id: app_serde.id, - workspace_id: app_serde.workspace_id, - name: app_serde.name, - desc: app_serde.desc, - belongings: app_serde.belongings.into(), - version: app_serde.version, - modified_time: app_serde.modified_time, - create_time: app_serde.create_time, - } - } -} - impl std::convert::From for TrashRevision { fn from(app_rev: AppRevision) -> Self { TrashRevision { @@ -44,14 +31,7 @@ impl std::convert::From for TrashRevision { name: app_rev.name, modified_time: app_rev.modified_time, create_time: app_rev.create_time, - ty: TrashType::TrashApp, + ty: TrashTypeRevision::TrashApp, } } } - -impl std::convert::From> for RepeatedApp { - fn from(values: Vec) -> Self { - let items = values.into_iter().map(|value| value.into()).collect::>(); - RepeatedApp { items } - } -} diff --git a/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs index 08f3bb27a1..7a8c15511f 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs @@ -1,7 +1,7 @@ -use crate::entities::trash::{Trash, TrashType}; -use crate::entities::{RepeatedTrash, TrashId}; +use serde::de::Visitor; use serde::{Deserialize, Serialize}; - +use serde_repr::*; +use std::fmt; #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct TrashRevision { pub id: String, @@ -12,45 +12,73 @@ pub struct TrashRevision { pub create_time: i64, - pub ty: TrashType, + pub ty: TrashTypeRevision, } -impl std::convert::From> for RepeatedTrash { - fn from(trash_revs: Vec) -> Self { - let items: Vec = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect(); - RepeatedTrash { items } +#[derive(Eq, PartialEq, Debug, Clone, Serialize_repr)] +#[repr(u8)] +pub enum TrashTypeRevision { + Unknown = 0, + TrashView = 1, + TrashApp = 2, +} +impl<'de> serde::Deserialize<'de> for TrashTypeRevision { + fn deserialize(deserializer: D) -> core::result::Result + where + D: serde::Deserializer<'de>, + { + struct TrashTypeVisitor(); + + impl<'de> Visitor<'de> for TrashTypeVisitor { + type Value = TrashTypeRevision; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("struct Insert") + } + + fn visit_u8(self, v: u8) -> Result + where + E: serde::de::Error, + { + let ty = match v { + 0 => TrashTypeRevision::Unknown, + 1 => TrashTypeRevision::TrashView, + 2 => TrashTypeRevision::TrashApp, + _ => TrashTypeRevision::Unknown, + }; + + Ok(ty) + } + + fn visit_str(self, s: &str) -> Result + where + E: serde::de::Error, + { + let value = match s { + "Unknown" => TrashTypeRevision::Unknown, + "TrashView" => TrashTypeRevision::TrashView, + "TrashApp" => TrashTypeRevision::TrashApp, + _ => TrashTypeRevision::Unknown, + }; + Ok(value) + } + } + + deserializer.deserialize_any(TrashTypeVisitor()) + } +} +impl std::default::Default for TrashTypeRevision { + fn default() -> Self { + TrashTypeRevision::Unknown } } -impl std::convert::From for Trash { - fn from(trash_rev: TrashRevision) -> Self { - Trash { - id: trash_rev.id, - name: trash_rev.name, - modified_time: trash_rev.modified_time, - create_time: trash_rev.create_time, - ty: trash_rev.ty, - } - } -} - -impl std::convert::From for TrashRevision { - fn from(trash: Trash) -> Self { - TrashRevision { - id: trash.id, - name: trash.name, - modified_time: trash.modified_time, - create_time: trash.create_time, - ty: trash.ty, - } - } -} - -impl std::convert::From<&TrashRevision> for TrashId { - fn from(trash: &TrashRevision) -> Self { - TrashId { - id: trash.id.clone(), - ty: trash.ty.clone(), +impl std::convert::From for u8 { + fn from(rev: TrashTypeRevision) -> Self { + match rev { + TrashTypeRevision::Unknown => 0, + TrashTypeRevision::TrashView => 1, + TrashTypeRevision::TrashApp => 2, } } } diff --git a/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs index 72ab0079b5..7a81bbb191 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs @@ -1,8 +1,10 @@ -use crate::entities::view::{View, ViewDataType}; -use crate::entities::{RepeatedView, TrashType}; -use crate::revision::TrashRevision; +use crate::revision::{TrashRevision, TrashTypeRevision}; +use nanoid::nanoid; use serde::{Deserialize, Serialize}; - +use serde_repr::*; +pub fn gen_view_id() -> String { + nanoid!(10) +} #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct ViewRevision { pub id: String, @@ -14,7 +16,7 @@ pub struct ViewRevision { pub desc: String, #[serde(default)] - pub data_type: ViewDataType, + pub data_type: ViewDataTypeRevision, pub version: i64, @@ -35,20 +37,6 @@ pub struct ViewRevision { } const DEFAULT_PLUGIN_TYPE: fn() -> i32 = || 0; -impl std::convert::From for View { - fn from(view_serde: ViewRevision) -> Self { - View { - id: view_serde.id, - belong_to_id: view_serde.belong_to_id, - name: view_serde.name, - data_type: view_serde.data_type, - modified_time: view_serde.modified_time, - create_time: view_serde.create_time, - plugin_type: view_serde.plugin_type, - } - } -} - impl std::convert::From for TrashRevision { fn from(view_rev: ViewRevision) -> Self { TrashRevision { @@ -56,13 +44,20 @@ impl std::convert::From for TrashRevision { name: view_rev.name, modified_time: view_rev.modified_time, create_time: view_rev.create_time, - ty: TrashType::TrashView, + ty: TrashTypeRevision::TrashView, } } } -impl std::convert::From> for RepeatedView { - fn from(values: Vec) -> Self { - let items = values.into_iter().map(|value| value.into()).collect::>(); - RepeatedView { items } + +#[derive(Eq, PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)] +#[repr(u8)] +pub enum ViewDataTypeRevision { + TextBlock = 0, + Grid = 1, +} + +impl std::default::Default for ViewDataTypeRevision { + fn default() -> Self { + ViewDataTypeRevision::TextBlock } } diff --git a/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs index 5070041211..d975663931 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs @@ -1,7 +1,9 @@ -use crate::entities::workspace::Workspace; use crate::revision::AppRevision; +use nanoid::nanoid; use serde::{Deserialize, Serialize}; - +pub fn gen_workspace_id() -> String { + nanoid!(10) +} #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct WorkspaceRevision { pub id: String, @@ -16,16 +18,3 @@ pub struct WorkspaceRevision { pub create_time: i64, } - -impl std::convert::From for Workspace { - fn from(workspace_serde: WorkspaceRevision) -> Self { - Workspace { - id: workspace_serde.id, - name: workspace_serde.name, - desc: workspace_serde.desc, - apps: workspace_serde.apps.into(), - modified_time: workspace_serde.modified_time, - create_time: workspace_serde.create_time, - } - } -} diff --git a/shared-lib/flowy-folder-data-model/src/user_default.rs b/shared-lib/flowy-folder-data-model/src/user_default.rs index 7e8023067c..166bc32508 100644 --- a/shared-lib/flowy-folder-data-model/src/user_default.rs +++ b/shared-lib/flowy-folder-data-model/src/user_default.rs @@ -1,8 +1,6 @@ -use crate::entities::app::gen_app_id; -use crate::entities::view::gen_view_id; -use crate::entities::view::ViewDataType; -use crate::entities::workspace::gen_workspace_id; -use crate::revision::{AppRevision, ViewRevision, WorkspaceRevision}; +use crate::revision::{ + gen_app_id, gen_view_id, gen_workspace_id, AppRevision, ViewDataTypeRevision, ViewRevision, WorkspaceRevision, +}; use chrono::Utc; pub fn create_default_workspace() -> WorkspaceRevision { @@ -45,14 +43,13 @@ fn create_default_app(workspace_id: String, time: chrono::DateTime) -> AppR fn create_default_view(app_id: String, time: chrono::DateTime) -> ViewRevision { let view_id = gen_view_id(); let name = "Read me".to_string(); - let data_type = ViewDataType::TextBlock; ViewRevision { id: view_id, belong_to_id: app_id, name, desc: "".to_string(), - data_type, + data_type: ViewDataTypeRevision::TextBlock, version: 0, belongings: vec![], modified_time: time.timestamp(),