mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Extract protobuf structs from flowy-sync crate (#1425)
* refactor: extract data model from flowy-sync crate * chore: rename lib-infra features
This commit is contained in:
parent
7f6ad504fd
commit
882d5535e6
36
frontend/rust-lib/Cargo.lock
generated
36
frontend/rust-lib/Cargo.lock
generated
@ -861,6 +861,7 @@ dependencies = [
|
||||
"flowy-derive",
|
||||
"flowy-document",
|
||||
"flowy-error",
|
||||
"flowy-http-model",
|
||||
"flowy-revision",
|
||||
"flowy-sync",
|
||||
"flowy-test",
|
||||
@ -927,6 +928,7 @@ dependencies = [
|
||||
"flowy-document",
|
||||
"flowy-error",
|
||||
"flowy-folder",
|
||||
"flowy-http-model",
|
||||
"flowy-revision",
|
||||
"flowy-sync",
|
||||
"flowy-test",
|
||||
@ -965,6 +967,7 @@ dependencies = [
|
||||
"flowy-derive",
|
||||
"flowy-error",
|
||||
"flowy-grid",
|
||||
"flowy-http-model",
|
||||
"flowy-revision",
|
||||
"flowy-sync",
|
||||
"flowy-test",
|
||||
@ -991,6 +994,17 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-http-model"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"flowy-derive",
|
||||
"lib-infra",
|
||||
"md5",
|
||||
"protobuf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-net"
|
||||
version = "0.1.0"
|
||||
@ -1004,6 +1018,7 @@ dependencies = [
|
||||
"flowy-document",
|
||||
"flowy-error",
|
||||
"flowy-folder",
|
||||
"flowy-http-model",
|
||||
"flowy-sync",
|
||||
"flowy-user",
|
||||
"folder-rev-model",
|
||||
@ -1016,7 +1031,7 @@ dependencies = [
|
||||
"lib-ws",
|
||||
"log",
|
||||
"nanoid",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"protobuf",
|
||||
"reqwest",
|
||||
"serde",
|
||||
@ -1036,8 +1051,8 @@ dependencies = [
|
||||
"bytes",
|
||||
"dashmap",
|
||||
"flowy-error",
|
||||
"flowy-http-model",
|
||||
"flowy-revision",
|
||||
"flowy-sync",
|
||||
"futures-util",
|
||||
"lib-infra",
|
||||
"lib-ws",
|
||||
@ -1055,29 +1070,22 @@ dependencies = [
|
||||
name = "flowy-sdk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bytes",
|
||||
"claim 0.5.0",
|
||||
"color-eyre",
|
||||
"flowy-database",
|
||||
"flowy-document",
|
||||
"flowy-folder",
|
||||
"flowy-grid",
|
||||
"flowy-http-model",
|
||||
"flowy-net",
|
||||
"flowy-revision",
|
||||
"flowy-sync",
|
||||
"flowy-user",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"grid-rev-model",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
"lib-log",
|
||||
"lib-ws",
|
||||
"log",
|
||||
"parking_lot 0.11.2",
|
||||
"protobuf",
|
||||
"serde",
|
||||
"parking_lot 0.12.1",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
@ -1092,13 +1100,13 @@ dependencies = [
|
||||
"dashmap",
|
||||
"dissimilar",
|
||||
"flowy-derive",
|
||||
"flowy-http-model",
|
||||
"folder-rev-model",
|
||||
"futures",
|
||||
"grid-rev-model",
|
||||
"lib-infra",
|
||||
"lib-ot",
|
||||
"log",
|
||||
"md5",
|
||||
"parking_lot 0.12.1",
|
||||
"protobuf",
|
||||
"serde",
|
||||
@ -1164,7 +1172,7 @@ dependencies = [
|
||||
"log",
|
||||
"nanoid",
|
||||
"once_cell",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"protobuf",
|
||||
"quickcheck",
|
||||
"quickcheck_macros",
|
||||
@ -1809,7 +1817,7 @@ dependencies = [
|
||||
"futures-util",
|
||||
"lib-infra",
|
||||
"log",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"paste",
|
||||
"pin-project",
|
||||
"protobuf",
|
||||
|
@ -38,6 +38,5 @@ openssl_vendored = ["flowy-sdk/openssl_vendored"]
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = [
|
||||
"protobuf_file_gen",
|
||||
"dart",
|
||||
] }
|
||||
|
@ -19,4 +19,4 @@ lib-dispatch = {path = "../lib-dispatch" }
|
||||
dart = ["lib-infra/dart"]
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
|
@ -8,6 +8,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync"}
|
||||
flowy-http-model = { path = "../../../shared-lib/flowy-http-model"}
|
||||
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||
lib-ot = { path = "../../../shared-lib/lib-ot" }
|
||||
lib-ws = { path = "../../../shared-lib/lib-ws" }
|
||||
@ -51,7 +52,7 @@ criterion = "0.3"
|
||||
rand = "0.8.5"
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen", "proto_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = [ "proto_gen"] }
|
||||
|
||||
[features]
|
||||
sync = []
|
||||
|
@ -1,7 +1,7 @@
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::{RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use lib_ot::core::{Extension, NodeDataBuilder, NodeOperation, NodeTree, NodeTreeContext, Selection, Transaction};
|
||||
use lib_ot::text_delta::DeltaTextOperationBuilder;
|
||||
|
||||
|
@ -6,8 +6,8 @@ use crate::{DocumentEditor, DocumentUser};
|
||||
use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_http_model::ws_data::ServerRevisionWSData;
|
||||
use flowy_revision::{RevisionCloudService, RevisionManager};
|
||||
use flowy_sync::entities::ws_data::ServerRevisionWSData;
|
||||
use lib_infra::future::FutureResult;
|
||||
use lib_ot::core::Transaction;
|
||||
use lib_ws::WSConnectState;
|
||||
|
@ -3,8 +3,8 @@ use crate::DocumentUser;
|
||||
use async_stream::stream;
|
||||
use bytes::Bytes;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_http_model::revision::{RevId, Revision};
|
||||
use flowy_revision::RevisionManager;
|
||||
use flowy_sync::entities::revision::{RevId, Revision};
|
||||
use futures::stream::StreamExt;
|
||||
use lib_ot::core::Transaction;
|
||||
|
||||
|
@ -16,7 +16,7 @@ pub mod errors {
|
||||
pub const TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS: u64 = 1000;
|
||||
|
||||
use crate::errors::FlowyError;
|
||||
use flowy_sync::entities::document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams};
|
||||
use flowy_http_model::document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
pub trait DocumentCloudService: Send + Sync {
|
||||
|
@ -8,13 +8,13 @@ use bytes::Bytes;
|
||||
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_http_model::{document::DocumentIdPB, revision::Revision, ws_data::ServerRevisionWSData};
|
||||
use flowy_revision::{
|
||||
RevisionCloudService, RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket,
|
||||
SQLiteRevisionSnapshotPersistence,
|
||||
};
|
||||
use flowy_sync::client_document::initial_delta_document_content;
|
||||
use flowy_sync::entities::{document::DocumentIdPB, revision::Revision, ws_data::ServerRevisionWSData};
|
||||
use flowy_sync::util::md5;
|
||||
use lib_infra::future::FutureResult;
|
||||
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
|
||||
use lib_ws::WSConnectState;
|
||||
@ -307,7 +307,7 @@ impl RevisionCloudService for DocumentRevisionCloudService {
|
||||
match server.fetch_document(&token, params).await? {
|
||||
None => Err(FlowyError::record_not_found().context("Remote doesn't have this document")),
|
||||
Some(payload) => {
|
||||
let bytes = Bytes::from(payload.content.clone());
|
||||
let bytes = Bytes::from(payload.data.clone());
|
||||
let doc_md5 = md5(&bytes);
|
||||
let revision = Revision::new(&payload.doc_id, payload.base_rev_id, payload.rev_id, bytes, doc_md5);
|
||||
Ok(vec![revision])
|
||||
|
@ -5,16 +5,14 @@ use crate::{errors::FlowyError, DocumentEditor, DocumentUser};
|
||||
use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{internal_error, FlowyResult};
|
||||
use flowy_http_model::document::DocumentPayloadPB;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::ws_data::ServerRevisionWSData;
|
||||
use flowy_revision::{
|
||||
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
|
||||
RevisionWebSocket,
|
||||
};
|
||||
use flowy_sync::entities::ws_data::ServerRevisionWSData;
|
||||
use flowy_sync::{
|
||||
entities::{document::DocumentPayloadPB, revision::Revision},
|
||||
errors::CollaborateResult,
|
||||
util::make_operations_from_revisions,
|
||||
};
|
||||
use flowy_sync::{errors::CollaborateResult, util::make_operations_from_revisions};
|
||||
use lib_infra::future::FutureResult;
|
||||
use lib_ot::core::{AttributeEntry, AttributeHashMap};
|
||||
use lib_ot::{
|
||||
@ -47,7 +45,7 @@ impl DeltaDocumentEditor {
|
||||
let document = rev_manager
|
||||
.initialize::<DeltaDocumentRevisionSerde>(Some(cloud_service))
|
||||
.await?;
|
||||
let operations = DeltaTextOperations::from_bytes(&document.content)?;
|
||||
let operations = DeltaTextOperations::from_bytes(&document.data)?;
|
||||
let rev_manager = Arc::new(rev_manager);
|
||||
let doc_id = doc_id.to_string();
|
||||
let user_id = user.user_id()?;
|
||||
@ -255,7 +253,7 @@ impl RevisionObjectDeserializer for DeltaDocumentRevisionSerde {
|
||||
|
||||
Result::<DocumentPayloadPB, FlowyError>::Ok(DocumentPayloadPB {
|
||||
doc_id: object_id.to_owned(),
|
||||
content: delta.json_str(),
|
||||
data: delta.json_bytes().to_vec(),
|
||||
rev_id,
|
||||
base_rev_id,
|
||||
})
|
||||
|
@ -3,10 +3,10 @@ use crate::DocumentUser;
|
||||
use async_stream::stream;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_http_model::revision::{RevId, Revision};
|
||||
use flowy_revision::{RevisionMD5, RevisionManager, TransformOperations};
|
||||
use flowy_sync::{
|
||||
client_document::{history::UndoResult, ClientDocument},
|
||||
entities::revision::{RevId, Revision},
|
||||
errors::CollaborateError,
|
||||
};
|
||||
use futures::stream::StreamExt;
|
||||
|
@ -3,16 +3,13 @@ use crate::TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS;
|
||||
use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_revision::*;
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use flowy_sync::{
|
||||
entities::{
|
||||
revision::RevisionRange,
|
||||
ws_data::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSDataType},
|
||||
},
|
||||
errors::CollaborateResult,
|
||||
use flowy_http_model::{
|
||||
revision::{Revision, RevisionRange},
|
||||
ws_data::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSDataType},
|
||||
};
|
||||
use flowy_revision::*;
|
||||
use flowy_sync::errors::CollaborateResult;
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use lib_infra::future::{BoxResultFuture, FutureResult};
|
||||
use lib_ot::text_delta::DeltaTextOperations;
|
||||
use lib_ws::WSConnectState;
|
||||
|
@ -4,9 +4,10 @@ use crate::DocumentDatabase;
|
||||
use bytes::Bytes;
|
||||
use flowy_database::kv::KV;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_revision::disk::{RevisionDiskCache, SyncRecord};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::util::{make_operations_from_revisions, md5};
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use std::sync::Arc;
|
||||
|
||||
const V1_MIGRATION: &str = "DOCUMENT_V1_MIGRATION";
|
||||
|
@ -7,11 +7,11 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
use flowy_http_model::{
|
||||
revision::{Revision, RevisionRange},
|
||||
util::md5,
|
||||
};
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -7,11 +7,11 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
use flowy_http_model::{
|
||||
revision::{Revision, RevisionRange},
|
||||
util::md5,
|
||||
};
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SQLiteDocumentRevisionPersistence {
|
||||
|
@ -30,4 +30,4 @@ db = ["flowy-database", "lib-sqlite", "r2d2"]
|
||||
dart = ["flowy-error-code/dart", "lib-infra/dart"]
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
|
@ -8,6 +8,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
folder-rev-model = { path = "../../../shared-lib/folder-rev-model" }
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync" }
|
||||
flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
|
||||
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||
lib-ot = { path = "../../../shared-lib/lib-ot" }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||
@ -41,7 +42,7 @@ flowy-folder = { path = "../flowy-folder", features = ["flowy_unit_test"]}
|
||||
flowy-test = { path = "../flowy-test" }
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen", "proto_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = [ "proto_gen"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -18,12 +18,13 @@ use flowy_revision::{
|
||||
RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket,
|
||||
SQLiteRevisionSnapshotPersistence,
|
||||
};
|
||||
use flowy_sync::{client_folder::FolderPad, entities::ws_data::ServerRevisionWSData};
|
||||
use folder_rev_model::user_default;
|
||||
use lazy_static::lazy_static;
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
use crate::services::persistence::rev_sqlite::SQLiteFolderRevisionPersistence;
|
||||
use flowy_http_model::ws_data::ServerRevisionWSData;
|
||||
use flowy_sync::client_folder::FolderPad;
|
||||
use std::{collections::HashMap, convert::TryInto, fmt::Formatter, sync::Arc};
|
||||
use tokio::sync::RwLock as TokioRwLock;
|
||||
lazy_static! {
|
||||
|
@ -1,18 +1,16 @@
|
||||
use crate::manager::FolderId;
|
||||
use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::ws_data::ServerRevisionWSData;
|
||||
use flowy_revision::{
|
||||
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
|
||||
RevisionWebSocket,
|
||||
};
|
||||
use flowy_sync::client_folder::{FolderChangeset, FolderPad};
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use flowy_sync::{
|
||||
client_folder::{FolderChangeset, FolderPad},
|
||||
entities::{revision::Revision, ws_data::ServerRevisionWSData},
|
||||
};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
use flowy_database::ConnectionPool;
|
||||
use lib_ot::core::EmptyAttributes;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
|
@ -6,15 +6,15 @@ use crate::{
|
||||
use bytes::Bytes;
|
||||
use flowy_database::kv::KV;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::reset::{RevisionResettable, RevisionStructReset};
|
||||
use flowy_sync::client_folder::make_folder_rev_json_str;
|
||||
use flowy_sync::client_folder::FolderPad;
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::server_folder::FolderOperationsBuilder;
|
||||
use folder_rev_model::{AppRevision, FolderRevision, ViewRevision, WorkspaceRevision};
|
||||
|
||||
use crate::services::persistence::rev_sqlite::SQLiteFolderRevisionPersistence;
|
||||
use flowy_sync::util::md5;
|
||||
use flowy_http_model::util::md5;
|
||||
use std::sync::Arc;
|
||||
|
||||
const V1_MIGRATION: &str = "FOLDER_V1_MIGRATION";
|
||||
|
@ -10,8 +10,9 @@ use crate::{
|
||||
};
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::disk::{RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{client_folder::FolderPad, entities::revision::Revision};
|
||||
use flowy_sync::client_folder::FolderPad;
|
||||
use folder_rev_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
||||
|
||||
use crate::services::persistence::rev_sqlite::SQLiteFolderRevisionPersistence;
|
||||
|
@ -7,12 +7,9 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
util::md5,
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SQLiteFolderRevisionPersistence {
|
||||
|
@ -16,7 +16,7 @@ use crate::{
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use flowy_database::kv::KV;
|
||||
use flowy_sync::entities::document::DocumentIdPB;
|
||||
use flowy_http_model::document::DocumentIdPB;
|
||||
use folder_rev_model::{gen_view_id, ViewRevision};
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
|
@ -2,17 +2,12 @@ use crate::services::FOLDER_SYNC_INTERVAL_IN_MILLIS;
|
||||
use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::ws_data::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSDataType};
|
||||
use flowy_revision::*;
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::client_folder::FolderPad;
|
||||
use flowy_sync::server_folder::FolderOperations;
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use flowy_sync::{
|
||||
client_folder::FolderPad,
|
||||
entities::{
|
||||
revision::RevisionRange,
|
||||
ws_data::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSDataType},
|
||||
},
|
||||
};
|
||||
use lib_infra::future::{BoxResultFuture, FutureResult};
|
||||
use lib_ot::core::OperationTransform;
|
||||
use parking_lot::RwLock;
|
||||
|
@ -16,9 +16,9 @@ use flowy_folder::entities::{
|
||||
use flowy_folder::event_map::FolderEvent::*;
|
||||
use flowy_folder::{errors::ErrorCode, services::folder_editor::FolderEditor};
|
||||
|
||||
use flowy_http_model::document::DocumentPayloadPB;
|
||||
use flowy_revision::disk::RevisionState;
|
||||
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
||||
use flowy_sync::entities::document::DocumentPayloadPB;
|
||||
use flowy_test::{event_builder::*, FlowySDKTest};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tokio::time::sleep;
|
||||
|
@ -15,6 +15,7 @@ lib-ot = { path = "../../../shared-lib/lib-ot" }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||
grid-rev-model = { path = "../../../shared-lib/grid-rev-model" }
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync" }
|
||||
flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
|
||||
flowy-database = { path = "../flowy-database" }
|
||||
|
||||
strum = "0.21"
|
||||
@ -47,7 +48,7 @@ flowy-test = { path = "../flowy-test" }
|
||||
flowy-grid = { path = "../flowy-grid", features = ["flowy_unit_test"]}
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen", "proto_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
|
||||
|
||||
|
||||
[features]
|
||||
|
@ -12,12 +12,12 @@ use bytes::Bytes;
|
||||
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::{
|
||||
RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket,
|
||||
SQLiteRevisionSnapshotPersistence,
|
||||
};
|
||||
use flowy_sync::client_grid::{make_grid_block_operations, make_grid_operations, make_grid_view_operations};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use grid_rev_model::{BuildGridContext, GridRevision, GridViewRevision};
|
||||
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::entities::RowPB;
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::{
|
||||
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
|
||||
};
|
||||
use flowy_sync::client_grid::{GridBlockRevisionChangeset, GridBlockRevisionPad};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use grid_rev_model::{CellRevision, GridBlockRevision, RowChangeset, RowRevision};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
@ -15,11 +15,11 @@ use crate::services::persistence::block_index::BlockIndexCache;
|
||||
use crate::services::row::{make_grid_blocks, make_rows_from_row_revs, GridBlockSnapshot, RowRevisionBuilder};
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::{
|
||||
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
|
||||
};
|
||||
use flowy_sync::client_grid::{GridRevisionChangeset, GridRevisionPad, JsonDeserializer};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::errors::{CollaborateError, CollaborateResult};
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use grid_rev_model::*;
|
||||
|
@ -14,11 +14,11 @@ use crate::services::group::{
|
||||
use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_revision::{
|
||||
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
|
||||
};
|
||||
use flowy_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::util::make_operations_from_revisions;
|
||||
use grid_rev_model::{
|
||||
gen_grid_filter_id, FieldRevision, FieldTypeRevision, FilterConfigurationRevision, GroupConfigurationRevision,
|
||||
|
@ -1,15 +1,14 @@
|
||||
use crate::manager::GridUser;
|
||||
use crate::services::persistence::rev_sqlite::SQLiteGridRevisionPersistence;
|
||||
use crate::services::persistence::GridDatabase;
|
||||
use bytes::Bytes;
|
||||
use flowy_database::kv::KV;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_revision::reset::{RevisionResettable, RevisionStructReset};
|
||||
use flowy_sync::client_grid::{make_grid_rev_json_str, GridOperationsBuilder, GridRevisionPad};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::util::md5;
|
||||
use grid_rev_model::GridRevision;
|
||||
|
||||
use crate::services::persistence::rev_sqlite::SQLiteGridRevisionPersistence;
|
||||
use std::sync::Arc;
|
||||
|
||||
const V1_MIGRATION: &str = "GRID_V1_MIGRATION";
|
||||
|
@ -7,11 +7,9 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
util::md5,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SQLiteGridBlockRevisionPersistence {
|
||||
|
@ -7,11 +7,9 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
util::md5,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SQLiteGridRevisionPersistence {
|
||||
|
@ -7,11 +7,9 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::util::md5;
|
||||
use flowy_revision::disk::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
util::md5,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SQLiteGridViewRevisionPersistence {
|
||||
|
@ -10,6 +10,7 @@ lib-dispatch = { path = "../lib-dispatch" }
|
||||
flowy-error = { path = "../flowy-error", features = ["collaboration", "http_server"] }
|
||||
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync"}
|
||||
flowy-http-model = { path = "../../../shared-lib/flowy-http-model"}
|
||||
folder-rev-model = { path = "../../../shared-lib/folder-rev-model"}
|
||||
flowy-folder = { path = "../flowy-folder" }
|
||||
flowy-user = { path = "../flowy-user" }
|
||||
@ -43,9 +44,8 @@ http_server = []
|
||||
dart = [
|
||||
"lib-infra/dart",
|
||||
"flowy-user/dart",
|
||||
"flowy-sync/dart",
|
||||
"flowy-error/dart",
|
||||
]
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
|
@ -4,7 +4,7 @@ use crate::{
|
||||
};
|
||||
use flowy_document::DocumentCloudService;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_sync::entities::document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams};
|
||||
use flowy_http_model::document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams};
|
||||
use http_flowy::response::FlowyResponse;
|
||||
use lazy_static::lazy_static;
|
||||
use lib_infra::future::FutureResult;
|
||||
|
@ -1,6 +1,7 @@
|
||||
use flowy_sync::entities::revision::{RepeatedRevision, Revision};
|
||||
use flowy_http_model::document::DocumentPayloadPB;
|
||||
use flowy_http_model::folder::FolderInfo;
|
||||
use flowy_http_model::revision::{RepeatedRevision, Revision};
|
||||
use flowy_sync::{
|
||||
entities::{document::DocumentPayloadPB, folder::FolderInfo},
|
||||
errors::CollaborateError,
|
||||
server_document::*,
|
||||
server_folder::FolderCloudPersistence,
|
||||
|
@ -4,12 +4,7 @@ use bytes::Bytes;
|
||||
use flowy_error::{internal_error, FlowyError};
|
||||
use flowy_folder::event_map::FolderCouldServiceV1;
|
||||
use flowy_sync::{
|
||||
entities::{
|
||||
document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams},
|
||||
ws_data::{ClientRevisionWSData, ClientRevisionWSDataType},
|
||||
},
|
||||
errors::CollaborateError,
|
||||
protobuf::ClientRevisionWSData as ClientRevisionWSDataPB,
|
||||
server_document::ServerDocumentManager,
|
||||
server_folder::ServerFolderManager,
|
||||
synchronizer::{RevisionSyncResponse, RevisionUser},
|
||||
@ -258,6 +253,9 @@ use flowy_folder::entities::{
|
||||
view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
|
||||
};
|
||||
use flowy_http_model::document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams};
|
||||
use flowy_http_model::protobuf::ClientRevisionWSData as ClientRevisionWSDataPB;
|
||||
use flowy_http_model::ws_data::{ClientRevisionWSData, ClientRevisionWSDataType};
|
||||
use flowy_user::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync" }
|
||||
flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
|
||||
lib-ws = { path = "../../../shared-lib/lib-ws" }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||
flowy-error = { path = "../flowy-error" }
|
||||
|
@ -1,5 +1,5 @@
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::revision::{RevId, Revision, RevisionRange};
|
||||
use flowy_http_model::revision::{RevId, Revision, RevisionRange};
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -2,7 +2,7 @@ use crate::disk::SyncRecord;
|
||||
use crate::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
||||
use dashmap::DashMap;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::revision::RevisionRange;
|
||||
use flowy_http_model::revision::RevisionRange;
|
||||
use std::{borrow::Cow, sync::Arc, time::Duration};
|
||||
use tokio::{sync::RwLock, task::JoinHandle};
|
||||
|
||||
|
@ -2,7 +2,7 @@ use crate::disk::{RevisionDiskCache, SyncRecord};
|
||||
use crate::{RevisionLoader, RevisionPersistence, RevisionPersistenceConfiguration};
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{RevisionMD5, RevisionManager};
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::{
|
||||
use flowy_http_model::{
|
||||
revision::{RepeatedRevision, Revision, RevisionRange},
|
||||
ws_data::ServerRevisionWSDataType,
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ use flowy_database::{
|
||||
ConnectionPool,
|
||||
};
|
||||
use flowy_error::{internal_error, FlowyResult};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct SQLiteRevisionHistoryPersistence {
|
||||
|
@ -2,7 +2,7 @@ use crate::{RevisionCompactor, RevisionHistory};
|
||||
use async_stream::stream;
|
||||
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use futures_util::future::BoxFuture;
|
||||
use futures_util::stream::StreamExt;
|
||||
use futures_util::FutureExt;
|
||||
|
@ -2,11 +2,11 @@ use crate::disk::RevisionState;
|
||||
use crate::{RevisionPersistence, RevisionSnapshotDiskCache, RevisionSnapshotManager, WSDataProviderDataSource};
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::{
|
||||
entities::revision::{Revision, RevisionRange},
|
||||
util::{md5, pair_rev_id_from_revisions, RevIdCounter},
|
||||
};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::util::md5;
|
||||
use lib_infra::future::FutureResult;
|
||||
use std::sync::atomic::AtomicI64;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait RevisionCloudService: Send + Sync {
|
||||
@ -349,3 +349,39 @@ impl PartialEq<Self> for RevisionMD5 {
|
||||
}
|
||||
|
||||
impl std::cmp::Eq for RevisionMD5 {}
|
||||
|
||||
fn pair_rev_id_from_revisions(revisions: &[Revision]) -> (i64, i64) {
|
||||
let mut rev_id = 0;
|
||||
revisions.iter().for_each(|revision| {
|
||||
if rev_id < revision.rev_id {
|
||||
rev_id = revision.rev_id;
|
||||
}
|
||||
});
|
||||
|
||||
if rev_id > 0 {
|
||||
(rev_id - 1, rev_id)
|
||||
} else {
|
||||
(0, rev_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RevIdCounter(pub AtomicI64);
|
||||
|
||||
impl RevIdCounter {
|
||||
pub fn new(n: i64) -> Self {
|
||||
Self(AtomicI64::new(n))
|
||||
}
|
||||
|
||||
pub fn next_id(&self) -> i64 {
|
||||
let _ = self.0.fetch_add(1, SeqCst);
|
||||
self.value()
|
||||
}
|
||||
pub fn value(&self) -> i64 {
|
||||
self.0.load(SeqCst)
|
||||
}
|
||||
|
||||
pub fn set(&self, n: i64) {
|
||||
let _ = self.0.fetch_update(SeqCst, SeqCst, |_| Some(n));
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use crate::disk::{RevisionState, SyncRecord};
|
||||
use crate::memory::RevisionMemoryCache;
|
||||
use crate::RevisionMergeable;
|
||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use std::collections::VecDeque;
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
use tokio::sync::RwLock;
|
||||
|
@ -2,7 +2,7 @@ use crate::ConflictRevisionSink;
|
||||
use async_stream::stream;
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::entities::{
|
||||
use flowy_http_model::{
|
||||
revision::{RevId, Revision, RevisionRange},
|
||||
ws_data::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSData, ServerRevisionWSDataType},
|
||||
};
|
||||
|
@ -7,8 +7,8 @@ use flowy_revision::{
|
||||
REVISION_WRITE_INTERVAL_IN_MILLIS,
|
||||
};
|
||||
|
||||
use flowy_sync::entities::revision::{Revision, RevisionRange};
|
||||
use flowy_sync::util::md5;
|
||||
use flowy_http_model::revision::{Revision, RevisionRange};
|
||||
use flowy_http_model::util::md5;
|
||||
use nanoid::nanoid;
|
||||
use parking_lot::RwLock;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -18,25 +18,15 @@ flowy-document = { path = "../flowy-document", default-features = false }
|
||||
flowy-revision = { path = "../flowy-revision" }
|
||||
|
||||
tracing = { version = "0.1" }
|
||||
log = "0.4.14"
|
||||
futures-core = { version = "0.3", default-features = false }
|
||||
color-eyre = { version = "0.5", default-features = false }
|
||||
bytes = "1.0"
|
||||
tokio = { version = "1", features = ["rt"] }
|
||||
parking_lot = "0.12.1"
|
||||
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync" }
|
||||
flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
|
||||
lib-ws = { path = "../../../shared-lib/lib-ws" }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
bincode = { version = "1.3" }
|
||||
protobuf = { version = "2.24.1" }
|
||||
claim = "0.5.0"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
futures-util = "0.3.15"
|
||||
|
||||
[features]
|
||||
http_sync = ["flowy-folder/cloud_sync", "flowy-document/cloud_sync"]
|
||||
native_sync = ["flowy-folder/cloud_sync", "flowy-document/cloud_sync"]
|
||||
@ -45,7 +35,6 @@ dart = [
|
||||
"flowy-user/dart",
|
||||
"flowy-net/dart",
|
||||
"flowy-folder/dart",
|
||||
"flowy-sync/dart",
|
||||
"flowy-grid/dart",
|
||||
"flowy-document/dart",
|
||||
]
|
||||
|
@ -4,12 +4,12 @@ use flowy_document::{
|
||||
errors::{internal_error, FlowyError},
|
||||
DocumentCloudService, DocumentConfig, DocumentDatabase, DocumentManager, DocumentUser,
|
||||
};
|
||||
use flowy_http_model::ws_data::ClientRevisionWSData;
|
||||
use flowy_net::ClientServerConfiguration;
|
||||
use flowy_net::{
|
||||
http_server::document::DocumentCloudServiceImpl, local_server::LocalServer, ws::connection::FlowyWebSocketConnect,
|
||||
};
|
||||
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
|
||||
use flowy_sync::entities::ws_data::ClientRevisionWSData;
|
||||
use flowy_user::services::UserSession;
|
||||
use futures_core::future::BoxFuture;
|
||||
use lib_infra::future::BoxResultFuture;
|
||||
|
@ -12,13 +12,13 @@ use flowy_folder::{
|
||||
use flowy_grid::entities::GridLayout;
|
||||
use flowy_grid::manager::{make_grid_view_data, GridManager};
|
||||
use flowy_grid::util::{make_default_board, make_default_grid};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::ws_data::ClientRevisionWSData;
|
||||
use flowy_net::ClientServerConfiguration;
|
||||
use flowy_net::{
|
||||
http_server::folder::FolderHttpCloudService, local_server::LocalServer, ws::connection::FlowyWebSocketConnect,
|
||||
};
|
||||
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::entities::ws_data::ClientRevisionWSData;
|
||||
use flowy_user::services::UserSession;
|
||||
use futures_core::future::BoxFuture;
|
||||
use grid_rev_model::BuildGridContext;
|
||||
|
@ -3,9 +3,9 @@ use bytes::Bytes;
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_grid::manager::{GridManager, GridUser};
|
||||
use flowy_grid::services::persistence::GridDatabase;
|
||||
use flowy_http_model::ws_data::ClientRevisionWSData;
|
||||
use flowy_net::ws::connection::FlowyWebSocketConnect;
|
||||
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
|
||||
use flowy_sync::entities::ws_data::ClientRevisionWSData;
|
||||
use flowy_user::services::UserSession;
|
||||
use futures_core::future::BoxFuture;
|
||||
use lib_infra::future::BoxResultFuture;
|
||||
|
@ -295,7 +295,7 @@ async fn _listen_user_status(
|
||||
|
||||
match result().await {
|
||||
Ok(_) => {}
|
||||
Err(e) => log::error!("{}", e),
|
||||
Err(e) => tracing::error!("{}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,4 @@ rand = "0.8.5"
|
||||
dart = ["lib-infra/dart"]
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen"] }
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
|
65
shared-lib/Cargo.lock
generated
65
shared-lib/Cargo.lock
generated
@ -403,6 +403,17 @@ dependencies = [
|
||||
"protobuf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-http-model"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"flowy-derive",
|
||||
"lib-infra",
|
||||
"md5",
|
||||
"protobuf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-sync"
|
||||
version = "0.1.0"
|
||||
@ -413,19 +424,19 @@ dependencies = [
|
||||
"dashmap",
|
||||
"dissimilar",
|
||||
"flowy-derive",
|
||||
"flowy-http-model",
|
||||
"folder-rev-model",
|
||||
"futures",
|
||||
"grid-rev-model",
|
||||
"lib-infra",
|
||||
"lib-ot",
|
||||
"log",
|
||||
"md5",
|
||||
"parking_lot 0.12.1",
|
||||
"protobuf",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum 0.21.0",
|
||||
"strum_macros 0.21.1",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"url",
|
||||
@ -447,8 +458,8 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"strum 0.24.1",
|
||||
"strum_macros 0.24.3",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -637,7 +648,6 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -655,12 +665,6 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@ -821,8 +825,8 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"strum 0.21.0",
|
||||
"strum_macros 0.21.1",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
@ -842,12 +846,12 @@ dependencies = [
|
||||
"futures-util",
|
||||
"lib-infra",
|
||||
"log",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"paste",
|
||||
"pin-project",
|
||||
"protobuf",
|
||||
"strum 0.21.0",
|
||||
"strum_macros 0.21.1",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"tracing",
|
||||
@ -1498,12 +1502,6 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
@ -1658,37 +1656,18 @@ version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.24.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.21.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec"
|
||||
dependencies = [
|
||||
"heck 0.3.3",
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.24.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
|
||||
dependencies = [
|
||||
"heck 0.4.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.81"
|
||||
|
@ -2,6 +2,7 @@
|
||||
members = [
|
||||
"folder-rev-model",
|
||||
"flowy-sync",
|
||||
"flowy-http-model",
|
||||
"lib-ot",
|
||||
"lib-ws",
|
||||
"lib-infra",
|
||||
|
@ -11,7 +11,7 @@ protobuf = {version = "2.18.0"}
|
||||
derive_more = {version = "0.99", features = ["display"]}
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../lib-infra", features = ["protobuf_file_gen"] }
|
||||
lib-infra = { path = "../lib-infra", features = ["proto_gen"] }
|
||||
|
||||
[features]
|
||||
dart = ["lib-infra/dart"]
|
17
shared-lib/flowy-http-model/Cargo.toml
Normal file
17
shared-lib/flowy-http-model/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "flowy-http-model"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bytes = "1.0"
|
||||
lib-infra = { path = "../lib-infra" }
|
||||
flowy-derive = { path = "../flowy-derive" }
|
||||
protobuf = {version = "2.18.0"}
|
||||
md5 = "0.7.0"
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../lib-infra", features = ["proto_gen"] }
|
||||
|
@ -1,9 +1,5 @@
|
||||
use crate::{
|
||||
entities::revision::{RepeatedRevision, Revision},
|
||||
errors::CollaborateError,
|
||||
};
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use flowy_derive::ProtoBuf;
|
||||
use lib_ot::text_delta::DeltaTextOperations;
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct CreateDocumentParams {
|
||||
@ -20,7 +16,7 @@ pub struct DocumentPayloadPB {
|
||||
pub doc_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub content: String,
|
||||
pub data: Vec<u8>,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub rev_id: i64,
|
||||
@ -30,20 +26,16 @@ pub struct DocumentPayloadPB {
|
||||
}
|
||||
|
||||
impl std::convert::TryFrom<Revision> for DocumentPayloadPB {
|
||||
type Error = CollaborateError;
|
||||
type Error = String;
|
||||
|
||||
fn try_from(revision: Revision) -> Result<Self, Self::Error> {
|
||||
if !revision.is_initial() {
|
||||
return Err(CollaborateError::revision_conflict()
|
||||
.context("Revision's rev_id should be 0 when creating the document"));
|
||||
return Err("Revision's rev_id should be 0 when creating the document".to_string());
|
||||
}
|
||||
|
||||
let delta = DeltaTextOperations::from_bytes(&revision.bytes)?;
|
||||
let doc_json = delta.json_str();
|
||||
|
||||
Ok(DocumentPayloadPB {
|
||||
doc_id: revision.object_id,
|
||||
content: doc_json,
|
||||
data: revision.bytes,
|
||||
rev_id: revision.rev_id,
|
||||
base_rev_id: revision.base_rev_id,
|
||||
})
|
@ -1,5 +1,4 @@
|
||||
pub mod document;
|
||||
pub mod folder;
|
||||
pub mod parser;
|
||||
pub mod revision;
|
||||
pub mod ws_data;
|
@ -3,8 +3,6 @@ use bytes::Bytes;
|
||||
use flowy_derive::ProtoBuf;
|
||||
use std::{convert::TryFrom, fmt::Formatter, ops::RangeInclusive};
|
||||
|
||||
pub type RevisionObject = lib_ot::text_delta::DeltaTextOperations;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Default, ProtoBuf)]
|
||||
pub struct Revision {
|
||||
#[pb(index = 1)]
|
||||
@ -73,14 +71,6 @@ impl std::fmt::Debug for Revision {
|
||||
let _ = f.write_fmt(format_args!("object_id {}, ", self.object_id))?;
|
||||
let _ = f.write_fmt(format_args!("base_rev_id {}, ", self.base_rev_id))?;
|
||||
let _ = f.write_fmt(format_args!("rev_id {}, ", self.rev_id))?;
|
||||
match RevisionObject::from_bytes(&self.bytes) {
|
||||
Ok(object) => {
|
||||
let _ = f.write_fmt(format_args!("object {:?}", object.json_str()))?;
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = f.write_fmt(format_args!("object {:?}", e))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
use crate::{
|
||||
entities::revision::{RepeatedRevision, RevId, Revision, RevisionRange},
|
||||
errors::CollaborateError,
|
||||
};
|
||||
use crate::entities::revision::{RepeatedRevision, RevId, Revision, RevisionRange};
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Debug, Clone, ProtoBuf_Enum, Eq, PartialEq, Hash)]
|
||||
pub enum ClientRevisionWSDataType {
|
||||
@ -12,16 +9,16 @@ pub enum ClientRevisionWSDataType {
|
||||
ClientPing = 1,
|
||||
}
|
||||
|
||||
impl ClientRevisionWSDataType {
|
||||
pub fn data<T>(&self, bytes: Bytes) -> Result<T, CollaborateError>
|
||||
where
|
||||
T: TryFrom<Bytes, Error = CollaborateError>,
|
||||
{
|
||||
T::try_from(bytes)
|
||||
}
|
||||
}
|
||||
// impl ClientRevisionWSDataType {
|
||||
// pub fn data<T>(&self, bytes: Bytes) -> Result<T, String>
|
||||
// where
|
||||
// T: TryFrom<Bytes, Error = String>,
|
||||
// {
|
||||
// T::try_from(bytes)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl std::default::Default for ClientRevisionWSDataType {
|
||||
impl Default for ClientRevisionWSDataType {
|
||||
fn default() -> Self {
|
||||
ClientRevisionWSDataType::ClientPushRev
|
||||
}
|
||||
@ -39,7 +36,7 @@ pub struct ClientRevisionWSData {
|
||||
pub revisions: RepeatedRevision,
|
||||
|
||||
#[pb(index = 4)]
|
||||
data_id: String,
|
||||
pub data_id: String,
|
||||
}
|
||||
|
||||
impl ClientRevisionWSData {
|
||||
@ -79,7 +76,7 @@ pub enum ServerRevisionWSDataType {
|
||||
UserConnect = 3,
|
||||
}
|
||||
|
||||
impl std::default::Default for ServerRevisionWSDataType {
|
||||
impl Default for ServerRevisionWSDataType {
|
||||
fn default() -> Self {
|
||||
ServerRevisionWSDataType::ServerPushRev
|
||||
}
|
6
shared-lib/flowy-http-model/src/lib.rs
Normal file
6
shared-lib/flowy-http-model/src/lib.rs
Normal file
@ -0,0 +1,6 @@
|
||||
pub mod util;
|
||||
|
||||
pub mod protobuf;
|
||||
|
||||
mod entities;
|
||||
pub use entities::*;
|
5
shared-lib/flowy-http-model/src/util.rs
Normal file
5
shared-lib/flowy-http-model/src/util.rs
Normal file
@ -0,0 +1,5 @@
|
||||
#[inline]
|
||||
pub fn md5<T: AsRef<[u8]>>(data: T) -> String {
|
||||
let md5 = format!("{:x}", md5::compute(data));
|
||||
md5
|
||||
}
|
@ -11,10 +11,10 @@ lib-infra = { path = "../lib-infra" }
|
||||
flowy-derive = { path = "../flowy-derive" }
|
||||
folder-rev-model = { path = "../folder-rev-model" }
|
||||
grid-rev-model = { path = "../grid-rev-model" }
|
||||
flowy-http-model= { path = "../flowy-http-model" }
|
||||
protobuf = {version = "2.18.0"}
|
||||
bytes = "1.0"
|
||||
log = "0.4.14"
|
||||
md5 = "0.7.0"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||
serde_json = {version = "1.0"}
|
||||
@ -28,9 +28,3 @@ parking_lot = "0.12.1"
|
||||
dashmap = "5"
|
||||
futures = "0.3.15"
|
||||
async-stream = "0.3.2"
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../lib-infra", features = ["protobuf_file_gen"] }
|
||||
|
||||
[features]
|
||||
dart = ["lib-infra/dart"]
|
@ -1,4 +1,3 @@
|
||||
use crate::util::md5;
|
||||
use crate::{
|
||||
client_document::{
|
||||
history::{History, UndoResult},
|
||||
@ -7,6 +6,7 @@ use crate::{
|
||||
errors::CollaborateError,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use flowy_http_model::util::md5;
|
||||
use lib_ot::text_delta::DeltaTextOperationBuilder;
|
||||
use lib_ot::{core::*, text_delta::DeltaTextOperations};
|
||||
use tokio::sync::mpsc;
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::util::make_operations_from_revisions;
|
||||
use crate::{
|
||||
client_folder::{default_folder_operations, FolderPad},
|
||||
entities::revision::Revision,
|
||||
errors::CollaborateResult,
|
||||
};
|
||||
|
||||
use crate::server_folder::FolderOperations;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use folder_rev_model::{TrashRevision, WorkspaceRevision};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
use crate::errors::internal_error;
|
||||
use crate::server_folder::{FolderOperations, FolderOperationsBuilder};
|
||||
use crate::util::{cal_diff, md5};
|
||||
use crate::util::cal_diff;
|
||||
use crate::{
|
||||
client_folder::builder::FolderPadBuilder,
|
||||
entities::revision::Revision,
|
||||
errors::{CollaborateError, CollaborateResult},
|
||||
};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::util::md5;
|
||||
use folder_rev_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
||||
use lib_infra::util::move_vec_element;
|
||||
use lib_ot::core::*;
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::errors::{CollaborateError, CollaborateResult};
|
||||
use crate::util::{cal_diff, make_operations_from_revisions, md5};
|
||||
use crate::util::{cal_diff, make_operations_from_revisions};
|
||||
use flowy_http_model::revision::{RepeatedRevision, Revision};
|
||||
use flowy_http_model::util::md5;
|
||||
use grid_rev_model::{gen_block_id, gen_row_id, CellRevision, GridBlockRevision, RowChangeset, RowRevision};
|
||||
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
||||
use std::borrow::Cow;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
||||
use crate::util::{cal_diff, make_operations_from_revisions, md5};
|
||||
|
||||
use crate::util::{cal_diff, make_operations_from_revisions};
|
||||
use flowy_http_model::revision::{RepeatedRevision, Revision};
|
||||
use flowy_http_model::util::md5;
|
||||
use grid_rev_model::{
|
||||
gen_block_id, gen_grid_id, FieldRevision, FieldTypeRevision, GridBlockMetaRevision, GridBlockMetaRevisionChangeset,
|
||||
GridRevision,
|
||||
@ -10,6 +10,7 @@ use lib_infra::util::move_vec_element;
|
||||
use lib_ot::core::{DeltaOperationBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type GridOperations = DeltaOperations<EmptyAttributes>;
|
||||
pub type GridOperationsBuilder = DeltaOperationBuilder<EmptyAttributes>;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::entities::revision::Revision;
|
||||
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
||||
use crate::util::{cal_diff, make_operations_from_revisions, md5};
|
||||
use crate::util::{cal_diff, make_operations_from_revisions};
|
||||
use flowy_http_model::revision::Revision;
|
||||
use flowy_http_model::util::md5;
|
||||
use grid_rev_model::{
|
||||
FieldRevision, FieldTypeRevision, FilterConfigurationRevision, FilterConfigurationsByFieldId, GridViewRevision,
|
||||
GroupConfigurationRevision, GroupConfigurationsByFieldId, LayoutRevision,
|
||||
|
@ -1,18 +0,0 @@
|
||||
#[derive(Debug)]
|
||||
pub struct DocumentIdentify(pub String);
|
||||
|
||||
impl DocumentIdentify {
|
||||
pub fn parse(s: String) -> Result<DocumentIdentify, String> {
|
||||
if s.trim().is_empty() {
|
||||
return Err("Doc id can not be empty or whitespace".to_string());
|
||||
}
|
||||
|
||||
Ok(Self(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for DocumentIdentify {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
mod doc_id;
|
||||
|
||||
pub use doc_id::*;
|
@ -1,9 +1,7 @@
|
||||
pub mod client_document;
|
||||
pub mod client_folder;
|
||||
pub mod client_grid;
|
||||
pub mod entities;
|
||||
pub mod errors;
|
||||
pub mod protobuf;
|
||||
pub mod server_document;
|
||||
pub mod server_folder;
|
||||
pub mod synchronizer;
|
||||
|
@ -1,14 +1,15 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::{
|
||||
entities::{document::DocumentPayloadPB, ws_data::ServerRevisionWSDataBuilder},
|
||||
errors::{internal_error, CollaborateError, CollaborateResult},
|
||||
protobuf::ClientRevisionWSData,
|
||||
server_document::document_pad::ServerDocument,
|
||||
synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionSynchronizer, RevisionUser},
|
||||
util::rev_id_from_str,
|
||||
};
|
||||
use async_stream::stream;
|
||||
use dashmap::DashMap;
|
||||
use flowy_http_model::document::DocumentPayloadPB;
|
||||
use flowy_http_model::protobuf::ClientRevisionWSData;
|
||||
use flowy_http_model::revision::{RepeatedRevision, Revision};
|
||||
use flowy_http_model::ws_data::ServerRevisionWSDataBuilder;
|
||||
use futures::stream::StreamExt;
|
||||
use lib_infra::future::BoxResultFuture;
|
||||
use lib_ot::core::AttributeHashMap;
|
||||
@ -216,7 +217,7 @@ impl OpenDocumentHandler {
|
||||
let (sender, receiver) = mpsc::channel(1000);
|
||||
let users = DashMap::new();
|
||||
|
||||
let operations = DeltaTextOperations::from_bytes(&doc.content)?;
|
||||
let operations = DeltaTextOperations::from_bytes(&doc.data)?;
|
||||
let sync_object = ServerDocument::from_operations(&doc_id, operations);
|
||||
let synchronizer = Arc::new(DocumentRevisionSynchronizer::new(doc.rev_id, sync_object, persistence));
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::server_folder::folder_pad::{FolderOperations, FolderRevisionSynchronizer};
|
||||
use crate::{
|
||||
entities::{folder::FolderInfo, ws_data::ServerRevisionWSDataBuilder},
|
||||
errors::{internal_error, CollaborateError, CollaborateResult},
|
||||
protobuf::ClientRevisionWSData,
|
||||
server_folder::folder_pad::ServerFolder,
|
||||
synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionUser},
|
||||
util::rev_id_from_str,
|
||||
};
|
||||
use async_stream::stream;
|
||||
use flowy_http_model::folder::FolderInfo;
|
||||
use flowy_http_model::protobuf::ClientRevisionWSData;
|
||||
use flowy_http_model::revision::{RepeatedRevision, Revision};
|
||||
use flowy_http_model::ws_data::ServerRevisionWSDataBuilder;
|
||||
use futures::stream::StreamExt;
|
||||
use lib_infra::future::BoxResultFuture;
|
||||
use std::{collections::HashMap, fmt::Debug, sync::Arc};
|
||||
|
@ -1,13 +1,6 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::{
|
||||
entities::{
|
||||
revision::RevisionRange,
|
||||
ws_data::{ServerRevisionWSData, ServerRevisionWSDataBuilder},
|
||||
},
|
||||
errors::CollaborateError,
|
||||
protobuf::Revision as RevisionPB,
|
||||
util::*,
|
||||
};
|
||||
use crate::{errors::CollaborateError, util::*};
|
||||
use flowy_http_model::revision::{RepeatedRevision, Revision, RevisionRange};
|
||||
use flowy_http_model::ws_data::{ServerRevisionWSData, ServerRevisionWSDataBuilder};
|
||||
use lib_infra::future::BoxResultFuture;
|
||||
use lib_ot::core::{DeltaOperations, OperationAttributes};
|
||||
use parking_lot::RwLock;
|
||||
@ -207,7 +200,7 @@ where
|
||||
#[tracing::instrument(level = "debug", skip(self, revision))]
|
||||
fn transform_revision(
|
||||
&self,
|
||||
revision: &RevisionPB,
|
||||
revision: &flowy_http_model::protobuf::Revision,
|
||||
) -> Result<(RevisionOperations<Attribute>, RevisionOperations<Attribute>), CollaborateError> {
|
||||
let client_operations = RevisionOperations::<Attribute>::from_bytes(&revision.bytes)?;
|
||||
let result = self.object.read().transform(&client_operations)?;
|
||||
|
@ -1,20 +1,16 @@
|
||||
use crate::errors::{CollaborateError, CollaborateResult};
|
||||
use crate::server_folder::FolderOperations;
|
||||
use crate::{
|
||||
entities::{
|
||||
document::DocumentPayloadPB,
|
||||
folder::FolderInfo,
|
||||
revision::{RepeatedRevision, Revision},
|
||||
},
|
||||
errors::{CollaborateError, CollaborateResult},
|
||||
};
|
||||
use dissimilar::Chunk;
|
||||
use flowy_http_model::document::DocumentPayloadPB;
|
||||
use flowy_http_model::folder::FolderInfo;
|
||||
use flowy_http_model::revision::RepeatedRevision;
|
||||
use flowy_http_model::revision::Revision;
|
||||
use lib_ot::core::{DeltaOperationBuilder, OTString, OperationAttributes};
|
||||
use lib_ot::{
|
||||
core::{DeltaOperations, OperationTransform, NEW_LINE, WHITESPACE},
|
||||
text_delta::DeltaTextOperations,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::sync::atomic::{AtomicI64, Ordering::SeqCst};
|
||||
|
||||
#[inline]
|
||||
pub fn find_newline(s: &str) -> Option<usize> {
|
||||
@ -36,33 +32,6 @@ pub fn contain_newline(s: &str) -> bool {
|
||||
s.contains(NEW_LINE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn md5<T: AsRef<[u8]>>(data: T) -> String {
|
||||
let md5 = format!("{:x}", md5::compute(data));
|
||||
md5
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RevIdCounter(pub AtomicI64);
|
||||
|
||||
impl RevIdCounter {
|
||||
pub fn new(n: i64) -> Self {
|
||||
Self(AtomicI64::new(n))
|
||||
}
|
||||
|
||||
pub fn next_id(&self) -> i64 {
|
||||
let _ = self.0.fetch_add(1, SeqCst);
|
||||
self.value()
|
||||
}
|
||||
pub fn value(&self) -> i64 {
|
||||
self.0.load(SeqCst)
|
||||
}
|
||||
|
||||
pub fn set(&self, n: i64) {
|
||||
let _ = self.0.fetch_update(SeqCst, SeqCst, |_| Some(n));
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(revisions), err)]
|
||||
pub fn make_operations_from_revisions<T>(revisions: Vec<Revision>) -> CollaborateResult<DeltaOperations<T>>
|
||||
where
|
||||
@ -99,21 +68,6 @@ pub fn pair_rev_id_from_revision_pbs(revisions: &[Revision]) -> (i64, i64) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pair_rev_id_from_revisions(revisions: &[Revision]) -> (i64, i64) {
|
||||
let mut rev_id = 0;
|
||||
revisions.iter().for_each(|revision| {
|
||||
if rev_id < revision.rev_id {
|
||||
rev_id = revision.rev_id;
|
||||
}
|
||||
});
|
||||
|
||||
if rev_id > 0 {
|
||||
(rev_id - 1, rev_id)
|
||||
} else {
|
||||
(0, rev_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn make_folder_from_revisions_pb(
|
||||
folder_id: &str,
|
||||
@ -171,11 +125,9 @@ pub fn make_document_from_revision_pbs(
|
||||
delta = delta.compose(&new_delta)?;
|
||||
}
|
||||
|
||||
let text = delta.json_str();
|
||||
|
||||
Ok(Some(DocumentPayloadPB {
|
||||
doc_id: doc_id.to_owned(),
|
||||
content: text,
|
||||
data: delta.json_bytes().to_vec(),
|
||||
rev_id,
|
||||
base_rev_id,
|
||||
}))
|
||||
|
@ -45,8 +45,11 @@ proto_gen = [
|
||||
"phf",
|
||||
"walkdir",
|
||||
"console",
|
||||
"toml"
|
||||
"toml",
|
||||
"cmd_lib",
|
||||
"protoc-rust",
|
||||
"walkdir",
|
||||
"protoc-bin-vendored",
|
||||
]
|
||||
protobuf_file_gen = ["cmd_lib", "protoc-rust", "walkdir", "protoc-bin-vendored",]
|
||||
dart_event = ["walkdir", "flowy-ast", "tera", "syn"]
|
||||
dart = ["proto_gen", "dart_event"]
|
@ -1,13 +1,13 @@
|
||||
#[cfg(feature = "protobuf_file_gen")]
|
||||
#[cfg(feature = "proto_gen")]
|
||||
pub mod protobuf_file;
|
||||
|
||||
#[cfg(feature = "dart_event")]
|
||||
pub mod dart_event;
|
||||
|
||||
#[cfg(any(feature = "protobuf_file_gen", feature = "dart_event"))]
|
||||
#[cfg(any(feature = "proto_gen", feature = "dart_event"))]
|
||||
mod flowy_toml;
|
||||
|
||||
#[cfg(any(feature = "protobuf_file_gen", feature = "dart_event"))]
|
||||
#[cfg(any(feature = "proto_gen", feature = "dart_event"))]
|
||||
pub mod util;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
|
@ -28,7 +28,7 @@ parking_lot = "0.12.1"
|
||||
dashmap = "5"
|
||||
|
||||
[build-dependencies]
|
||||
lib-infra = { path = "../lib-infra", features = ["protobuf_file_gen"] }
|
||||
lib-infra = { path = "../lib-infra", features = ["proto_gen"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = {version = "1", features = ["full"]}
|
||||
|
Loading…
Reference in New Issue
Block a user