From b4237b1986990cd115356c7de12f638e02393d6a Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 13 Nov 2021 11:11:24 +0800 Subject: [PATCH] [rust]: extract flowy-document-infra --- .../doc.pb.dart | 0 .../doc.pbenum.dart | 0 .../doc.pbjson.dart | 0 .../doc.pbserver.dart | 0 .../flowy-document-infra/protobuf.dart | 3 + .../revision.pb.dart | 0 .../revision.pbenum.dart | 0 .../revision.pbjson.dart | 0 .../revision.pbserver.dart | 0 .../lib/protobuf/flowy-document/event.pb.dart | 11 -- .../protobuf/flowy-document/event.pbenum.dart | 30 ----- .../protobuf/flowy-document/event.pbjson.dart | 23 ---- .../flowy-document/event.pbserver.dart | 9 -- .../lib/protobuf/flowy-document/protobuf.dart | 3 - backend/Cargo.toml | 1 + backend/src/entities/doc.rs | 2 +- backend/src/service/doc/crud.rs | 2 +- backend/src/service/doc/doc.rs | 2 +- backend/src/service/doc/edit/edit_actor.rs | 2 +- backend/src/service/doc/edit/edit_doc.rs | 2 +- backend/src/service/doc/edit/open_handle.rs | 2 +- backend/src/service/doc/router.rs | 2 +- backend/src/service/doc/ws_actor.rs | 3 +- backend/src/service/user/user_default.rs | 2 +- backend/src/service/view/view.rs | 2 +- backend/tests/api/doc.rs | 2 +- backend/tests/document/helper.rs | 16 +-- backend/tests/helper.rs | 10 +- rust-lib/Cargo.toml | 1 + .../src/derive_cache/derive_cache.rs | 20 ++-- rust-lib/flowy-document-infra/Cargo.toml | 14 +++ rust-lib/flowy-document-infra/Flowy.toml | 3 + .../src/READ_ME.json | 0 .../src/document_default.rs | 23 ++++ .../src/entities/doc/doc.rs | 5 +- .../src/entities/doc/mod.rs | 0 .../src/entities/doc/parser/doc_id.rs | 0 .../src/entities/doc/parser/mod.rs | 0 .../src/entities/doc/revision.rs | 4 +- .../flowy-document-infra/src/entities/mod.rs | 1 + rust-lib/flowy-document-infra/src/lib.rs | 4 + .../flowy-document-infra/src/protobuf/mod.rs | 4 + .../src/protobuf/model/doc.rs | 100 ++++++++-------- .../src/protobuf/model/mod.rs | 7 ++ .../src/protobuf/model/revision.rs | 76 ++++++------ .../src/protobuf/proto/doc.proto | 1 - .../src/protobuf/proto/revision.proto | 1 - .../src}/util.rs | 2 +- rust-lib/flowy-document/Cargo.toml | 2 +- rust-lib/flowy-document/src/entities/mod.rs | 1 - rust-lib/flowy-document/src/entities/ws/ws.rs | 6 +- rust-lib/flowy-document/src/lib.rs | 7 -- rust-lib/flowy-document/src/module.rs | 4 +- .../src/protobuf/model/event.rs | 108 ------------------ .../flowy-document/src/protobuf/model/mod.rs | 9 -- .../flowy-document/src/protobuf/model/ws.rs | 44 +++---- .../src/protobuf/proto/event.proto | 8 -- .../src/protobuf/proto/ws.proto | 1 - rust-lib/flowy-document/src/services/cache.rs | 2 +- .../src/services/doc/doc_controller.rs | 3 +- .../src/services/doc/document/document.rs | 24 +--- .../src/services/doc/edit/doc_actor.rs | 65 +++++++++-- .../src/services/doc/edit/edit_doc.rs | 18 ++- .../src/services/doc/edit/message.rs | 59 ---------- .../src/services/doc/edit/mod.rs | 3 +- .../src/services/doc/edit/model.rs | 7 +- .../delete/preserve_line_format_merge.rs | 4 +- .../services/doc/extensions/format/helper.rs | 2 +- .../extensions/format/resolve_block_format.rs | 7 +- .../format/resolve_inline_format.rs | 7 +- .../doc/extensions/insert/auto_exit_block.rs | 4 +- .../doc/extensions/insert/auto_format.rs | 7 +- .../insert/preserve_block_format.rs | 3 +- .../insert/preserve_inline_format.rs | 7 +- .../insert/reset_format_on_new_line.rs | 4 +- .../flowy-document/src/services/doc/mod.rs | 8 +- .../src/services/doc/revision/manager.rs | 7 +- .../src/services/doc/revision/model.rs | 3 +- .../src/services/doc/revision/persistence.rs | 15 +-- rust-lib/flowy-document/src/services/mod.rs | 1 - .../flowy-document/src/services/server/mod.rs | 6 +- .../src/services/server/server_api.rs | 7 +- .../src/services/server/server_api_mock.rs | 6 +- .../src/sql_tables/doc/rev_sql.rs | 2 +- .../src/sql_tables/doc/rev_table.rs | 8 +- .../src/deps_resolve/document_deps.rs | 8 +- rust-lib/flowy-sdk/src/lib.rs | 2 +- rust-lib/flowy-test/Cargo.toml | 1 + rust-lib/flowy-test/src/workspace.rs | 2 +- rust-lib/flowy-workspace-infra/Cargo.toml | 2 +- .../src/entities/view/view_create.rs | 2 +- .../src/entities/view/view_query.rs | 2 +- rust-lib/flowy-workspace/Cargo.toml | 3 +- .../src/handlers/view_handler.rs | 2 +- .../src/services/view_controller.rs | 12 +- 95 files changed, 344 insertions(+), 566 deletions(-) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/doc.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/doc.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/doc.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/doc.pbserver.dart (100%) create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/protobuf.dart rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/revision.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/revision.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/revision.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/revision.pbserver.dart (100%) delete mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pb.dart delete mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbenum.dart delete mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbjson.dart delete mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbserver.dart create mode 100644 rust-lib/flowy-document-infra/Cargo.toml create mode 100644 rust-lib/flowy-document-infra/Flowy.toml rename rust-lib/{flowy-document => flowy-document-infra}/src/READ_ME.json (100%) create mode 100644 rust-lib/flowy-document-infra/src/document_default.rs rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/doc/doc.rs (94%) rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/doc/mod.rs (100%) rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/doc/parser/doc_id.rs (100%) rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/doc/parser/mod.rs (100%) rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/doc/revision.rs (98%) create mode 100644 rust-lib/flowy-document-infra/src/entities/mod.rs create mode 100644 rust-lib/flowy-document-infra/src/lib.rs create mode 100644 rust-lib/flowy-document-infra/src/protobuf/mod.rs rename rust-lib/{flowy-document => flowy-document-infra}/src/protobuf/model/doc.rs (92%) create mode 100644 rust-lib/flowy-document-infra/src/protobuf/model/mod.rs rename rust-lib/{flowy-document => flowy-document-infra}/src/protobuf/model/revision.rs (90%) rename rust-lib/{flowy-document => flowy-document-infra}/src/protobuf/proto/doc.proto (99%) rename rust-lib/{flowy-document => flowy-document-infra}/src/protobuf/proto/revision.proto (99%) rename rust-lib/{flowy-document/src/services => flowy-document-infra/src}/util.rs (95%) delete mode 100644 rust-lib/flowy-document/src/protobuf/model/event.rs delete mode 100644 rust-lib/flowy-document/src/protobuf/proto/event.proto delete mode 100644 rust-lib/flowy-document/src/services/doc/edit/message.rs diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/doc.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/protobuf.dart new file mode 100644 index 0000000000..15e066c852 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/protobuf.dart @@ -0,0 +1,3 @@ +// Auto-generated, do not edit +export './revision.pb.dart'; +export './doc.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/revision.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/revision.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pb.dart deleted file mode 100644 index e8db14dba5..0000000000 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pb.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// -// Generated code. Do not modify. -// source: event.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields - -import 'dart:core' as $core; - -export 'event.pbenum.dart'; - diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbenum.dart deleted file mode 100644 index b334b7d981..0000000000 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbenum.dart +++ /dev/null @@ -1,30 +0,0 @@ -/// -// Generated code. Do not modify. -// source: event.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields - -// ignore_for_file: UNDEFINED_SHOWN_NAME -import 'dart:core' as $core; -import 'package:protobuf/protobuf.dart' as $pb; - -class EditorEvent extends $pb.ProtobufEnum { - static const EditorEvent CreateDoc = EditorEvent._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateDoc'); - static const EditorEvent UpdateDoc = EditorEvent._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateDoc'); - static const EditorEvent ReadDoc = EditorEvent._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ReadDoc'); - static const EditorEvent DeleteDoc = EditorEvent._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DeleteDoc'); - - static const $core.List values = [ - CreateDoc, - UpdateDoc, - ReadDoc, - DeleteDoc, - ]; - - static final $core.Map<$core.int, EditorEvent> _byValue = $pb.ProtobufEnum.initByValue(values); - static EditorEvent? valueOf($core.int value) => _byValue[value]; - - const EditorEvent._($core.int v, $core.String n) : super(v, n); -} - diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbjson.dart deleted file mode 100644 index 310caa4f04..0000000000 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbjson.dart +++ /dev/null @@ -1,23 +0,0 @@ -/// -// Generated code. Do not modify. -// source: event.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package - -import 'dart:core' as $core; -import 'dart:convert' as $convert; -import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use editorEventDescriptor instead') -const EditorEvent$json = const { - '1': 'EditorEvent', - '2': const [ - const {'1': 'CreateDoc', '2': 0}, - const {'1': 'UpdateDoc', '2': 1}, - const {'1': 'ReadDoc', '2': 2}, - const {'1': 'DeleteDoc', '2': 3}, - ], -}; - -/// Descriptor for `EditorEvent`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List editorEventDescriptor = $convert.base64Decode('CgtFZGl0b3JFdmVudBINCglDcmVhdGVEb2MQABINCglVcGRhdGVEb2MQARILCgdSZWFkRG9jEAISDQoJRGVsZXRlRG9jEAM='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbserver.dart deleted file mode 100644 index 534f858805..0000000000 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbserver.dart +++ /dev/null @@ -1,9 +0,0 @@ -/// -// Generated code. Do not modify. -// source: event.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package - -export 'event.pb.dart'; - diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/protobuf.dart index 79780212c2..55db94945e 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/protobuf.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/protobuf.dart @@ -2,6 +2,3 @@ export './ws.pb.dart'; export './observable.pb.dart'; export './errors.pb.dart'; -export './revision.pb.dart'; -export './event.pb.dart'; -export './doc.pb.dart'; diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 470313731b..92733666b4 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -62,6 +62,7 @@ async-stream = "0.3.2" flowy-user-infra = { path = "../rust-lib/flowy-user-infra" } flowy-workspace-infra = { path = "../rust-lib/flowy-workspace-infra" } +flowy-document-infra = { path = "../rust-lib/flowy-document-infra" } flowy-document = { path = "../rust-lib/flowy-document" } flowy-ws = { path = "../rust-lib/flowy-ws" } flowy-ot = { path = "../rust-lib/flowy-ot" } diff --git a/backend/src/entities/doc.rs b/backend/src/entities/doc.rs index a105626e4b..741d290e5e 100644 --- a/backend/src/entities/doc.rs +++ b/backend/src/entities/doc.rs @@ -1,4 +1,4 @@ -use flowy_document::protobuf::Doc; +use flowy_document_infra::protobuf::Doc; pub(crate) const DOC_TABLE: &'static str = "doc_table"; diff --git a/backend/src/service/doc/crud.rs b/backend/src/service/doc/crud.rs index 41f54741cf..ad504667ae 100644 --- a/backend/src/service/doc/crud.rs +++ b/backend/src/service/doc/crud.rs @@ -3,7 +3,7 @@ use crate::{ sqlx_ext::{map_sqlx_error, DBTransaction, SqlBuilder}, }; use anyhow::Context; -use flowy_document::protobuf::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}; +use flowy_document_infra::protobuf::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}; use flowy_net::errors::ServerError; use sqlx::{postgres::PgArguments, PgPool, Postgres}; use uuid::Uuid; diff --git a/backend/src/service/doc/doc.rs b/backend/src/service/doc/doc.rs index a1d92ecb03..84cd3708b6 100644 --- a/backend/src/service/doc/doc.rs +++ b/backend/src/service/doc/doc.rs @@ -8,7 +8,7 @@ use crate::service::{ }; use actix_web::web::Data; use dashmap::DashMap; -use flowy_document::protobuf::DocIdentifier; +use flowy_document_infra::protobuf::DocIdentifier; use flowy_net::errors::{internal_error, ServerError}; use sqlx::PgPool; use std::sync::Arc; diff --git a/backend/src/service/doc/edit/edit_actor.rs b/backend/src/service/doc/edit/edit_actor.rs index b19ddbf2b9..86f6197b39 100644 --- a/backend/src/service/doc/edit/edit_actor.rs +++ b/backend/src/service/doc/edit/edit_actor.rs @@ -4,7 +4,7 @@ use crate::service::{ }; use actix_web::web::Data; use async_stream::stream; -use flowy_document::protobuf::{Doc, Revision}; +use flowy_document_infra::protobuf::{Doc, Revision}; use flowy_net::errors::{internal_error, Result as DocResult, ServerError}; use futures::stream::StreamExt; use sqlx::PgPool; diff --git a/backend/src/service/doc/edit/edit_doc.rs b/backend/src/service/doc/edit/edit_doc.rs index f606364af1..a2a241e780 100644 --- a/backend/src/service/doc/edit/edit_doc.rs +++ b/backend/src/service/doc/edit/edit_doc.rs @@ -10,9 +10,9 @@ use bytes::Bytes; use dashmap::DashMap; use flowy_document::{ entities::ws::{WsDataType, WsDocumentData}, - protobuf::{Doc, RevId, RevType, Revision, RevisionRange, UpdateDocParams}, services::doc::Document, }; +use flowy_document_infra::protobuf::{Doc, RevId, RevType, Revision, RevisionRange, UpdateDocParams}; use flowy_net::errors::{internal_error, ServerError}; use flowy_ot::core::{Delta, OperationTransformable}; use flowy_ws::WsMessage; diff --git a/backend/src/service/doc/edit/open_handle.rs b/backend/src/service/doc/edit/open_handle.rs index 4439dacade..b97d97d346 100644 --- a/backend/src/service/doc/edit/open_handle.rs +++ b/backend/src/service/doc/edit/open_handle.rs @@ -3,7 +3,7 @@ use crate::service::{ ws::{entities::Socket, WsUser}, }; use actix_web::web::Data; -use flowy_document::protobuf::{Doc, Revision}; +use flowy_document_infra::protobuf::{Doc, Revision}; use flowy_net::errors::{internal_error, Result as DocResult, ServerError}; use sqlx::PgPool; use std::sync::Arc; diff --git a/backend/src/service/doc/router.rs b/backend/src/service/doc/router.rs index 1f70af1412..ce30e466b2 100644 --- a/backend/src/service/doc/router.rs +++ b/backend/src/service/doc/router.rs @@ -7,7 +7,7 @@ use actix_web::{ HttpResponse, }; use anyhow::Context; -use flowy_document::protobuf::{CreateDocParams, DocIdentifier, UpdateDocParams}; +use flowy_document_infra::protobuf::{CreateDocParams, DocIdentifier, UpdateDocParams}; use flowy_net::{errors::ServerError, response::FlowyResponse}; use sqlx::PgPool; diff --git a/backend/src/service/doc/ws_actor.rs b/backend/src/service/doc/ws_actor.rs index fdd815204e..b2755ab9f4 100644 --- a/backend/src/service/doc/ws_actor.rs +++ b/backend/src/service/doc/ws_actor.rs @@ -6,7 +6,8 @@ use crate::service::{ use actix_rt::task::spawn_blocking; use actix_web::web::Data; use async_stream::stream; -use flowy_document::protobuf::{NewDocUser, Revision, WsDataType, WsDocumentData}; +use flowy_document::protobuf::{WsDataType, WsDocumentData}; +use flowy_document_infra::protobuf::{NewDocUser, Revision}; use flowy_net::errors::{internal_error, Result as DocResult, ServerError}; use futures::stream::StreamExt; use sqlx::PgPool; diff --git a/backend/src/service/user/user_default.rs b/backend/src/service/user/user_default.rs index 457aa4563f..3628d9e32a 100644 --- a/backend/src/service/user/user_default.rs +++ b/backend/src/service/user/user_default.rs @@ -8,7 +8,7 @@ use crate::{ use crate::service::view::{create_view_with_args, sql_builder::NewViewSqlBuilder}; use chrono::Utc; -use flowy_document::services::doc::doc_initial_string; +use flowy_document_infra::document_default::doc_initial_string; use flowy_net::errors::ServerError; use flowy_workspace_infra::protobuf::Workspace; use std::convert::TryInto; diff --git a/backend/src/service/view/view.rs b/backend/src/service/view/view.rs index ff7f4fb9db..0440c10fd8 100644 --- a/backend/src/service/view/view.rs +++ b/backend/src/service/view/view.rs @@ -9,7 +9,7 @@ use crate::{ sqlx_ext::{map_sqlx_error, DBTransaction, SqlBuilder}, }; use chrono::Utc; -use flowy_document::protobuf::CreateDocParams; +use flowy_document_infra::protobuf::CreateDocParams; use flowy_net::errors::{invalid_params, ServerError}; use flowy_workspace_infra::{ parser::{ diff --git a/backend/tests/api/doc.rs b/backend/tests/api/doc.rs index 380f6bdee8..c979fa016f 100644 --- a/backend/tests/api/doc.rs +++ b/backend/tests/api/doc.rs @@ -1,5 +1,5 @@ use crate::helper::ViewTest; -use flowy_document::entities::doc::DocIdentifier; +use flowy_document_infra::entities::doc::DocIdentifier; use flowy_workspace_infra::entities::view::ViewIdentifiers; #[actix_rt::test] diff --git a/backend/tests/document/helper.rs b/backend/tests/document/helper.rs index 4000ee183c..e1d15de586 100644 --- a/backend/tests/document/helper.rs +++ b/backend/tests/document/helper.rs @@ -1,20 +1,16 @@ -use std::sync::Arc; - use actix_web::web::Data; -use futures_util::{stream, stream::StreamExt}; -use sqlx::PgPool; -use tokio::time::{sleep, Duration}; - use backend::service::doc::{crud::update_doc, doc::DocManager}; -use flowy_document::{entities::doc::DocIdentifier, services::doc::edit::ClientEditDoc as ClientEditDocContext}; +use flowy_document::services::doc::ClientEditDoc as ClientEditDocContext; use flowy_net::config::ServerConfig; use flowy_test::{workspace::ViewTest, FlowyTest}; use flowy_user::services::user::UserSession; - +use futures_util::{stream, stream::StreamExt}; +use sqlx::PgPool; +use std::sync::Arc; +use tokio::time::{sleep, Duration}; // use crate::helper::*; use crate::helper::{spawn_server, TestServer}; -use flowy_document::protobuf::UpdateDocParams; - +use flowy_document_infra::{entities::doc::DocIdentifier, protobuf::UpdateDocParams}; use flowy_ot::core::{Attribute, Delta, Interval}; use parking_lot::RwLock; diff --git a/backend/tests/helper.rs b/backend/tests/helper.rs index b1fd0e4538..9a242a32a8 100644 --- a/backend/tests/helper.rs +++ b/backend/tests/helper.rs @@ -1,15 +1,11 @@ use backend::{ - application::{get_connection_pool, Application}, + application::{get_connection_pool, init_app_context, Application}, config::{get_configuration, DatabaseSettings}, context::AppContext, }; - -use backend::application::init_app_context; use flowy_backend_api::{user_request::*, workspace_request::*}; -use flowy_document::{ - entities::doc::{Doc, DocIdentifier}, - prelude::*, -}; +use flowy_document::services::server::read_doc_request; +use flowy_document_infra::entities::doc::{Doc, DocIdentifier}; use flowy_net::errors::ServerError; use flowy_user_infra::entities::*; use flowy_workspace_infra::entities::prelude::*; diff --git a/rust-lib/Cargo.toml b/rust-lib/Cargo.toml index 1b32790a68..95e6511e74 100644 --- a/rust-lib/Cargo.toml +++ b/rust-lib/Cargo.toml @@ -16,6 +16,7 @@ members = [ "flowy-workspace-infra", "flowy-dart-notify", "flowy-document", + "flowy-document-infra", "flowy-ot", "flowy-net", "flowy-ws", diff --git a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs index 7c1e61b458..a418579065 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -48,6 +48,15 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "RepeatedView" | "ExportRequest" | "ExportData" + | "CreateDocParams" + | "Doc" + | "UpdateDocParams" + | "DocDelta" + | "NewDocUser" + | "DocIdentifier" + | "RevId" + | "Revision" + | "RevisionRange" | "KeyValue" | "WorkspaceError" | "WsError" @@ -62,15 +71,6 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "UserProfile" | "UpdateUserRequest" | "UpdateUserParams" - | "CreateDocParams" - | "Doc" - | "UpdateDocParams" - | "DocDelta" - | "NewDocUser" - | "DocIdentifier" - | "RevId" - | "Revision" - | "RevisionRange" | "WsDocumentData" | "DocError" | "FFIRequest" @@ -82,10 +82,10 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "ViewType" | "ExportType" | "ErrorCode" + | "RevType" | "WorkspaceEvent" | "WorkspaceNotification" | "WsModule" - | "RevType" | "WsDataType" | "DocObservable" | "FFIStatusCode" diff --git a/rust-lib/flowy-document-infra/Cargo.toml b/rust-lib/flowy-document-infra/Cargo.toml new file mode 100644 index 0000000000..d54831abcb --- /dev/null +++ b/rust-lib/flowy-document-infra/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "flowy-document-infra" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +flowy-ot = { path = "../flowy-ot" } +flowy-derive = { path = "../flowy-derive" } +protobuf = {version = "2.18.0"} +bytes = "1.0" +log = "0.4.14" +md5 = "0.7.0" \ No newline at end of file diff --git a/rust-lib/flowy-document-infra/Flowy.toml b/rust-lib/flowy-document-infra/Flowy.toml new file mode 100644 index 0000000000..33b1c193f2 --- /dev/null +++ b/rust-lib/flowy-document-infra/Flowy.toml @@ -0,0 +1,3 @@ + +proto_crates = ["src/entities"] +event_files = [] \ No newline at end of file diff --git a/rust-lib/flowy-document/src/READ_ME.json b/rust-lib/flowy-document-infra/src/READ_ME.json similarity index 100% rename from rust-lib/flowy-document/src/READ_ME.json rename to rust-lib/flowy-document-infra/src/READ_ME.json diff --git a/rust-lib/flowy-document-infra/src/document_default.rs b/rust-lib/flowy-document-infra/src/document_default.rs new file mode 100644 index 0000000000..15cb43003e --- /dev/null +++ b/rust-lib/flowy-document-infra/src/document_default.rs @@ -0,0 +1,23 @@ +use flowy_ot::core::{Delta, DeltaBuilder}; + +#[allow(dead_code)] +#[inline] +pub fn doc_initial_delta() -> Delta { DeltaBuilder::new().insert("\n").build() } +#[allow(dead_code)] +#[inline] +pub fn doc_initial_string() -> String { doc_initial_delta().to_json() } +#[allow(dead_code)] +#[inline] +pub fn doc_initial_bytes() -> Vec { doc_initial_string().into_bytes() } + +#[cfg(test)] +mod tests { + use flowy_ot::core::Delta; + + #[test] + fn load_read_me() { + let json = include_str!("READ_ME.json"); + let delta = Delta::from_json(json).unwrap(); + assert_eq!(delta.to_json(), json); + } +} diff --git a/rust-lib/flowy-document/src/entities/doc/doc.rs b/rust-lib/flowy-document-infra/src/entities/doc/doc.rs similarity index 94% rename from rust-lib/flowy-document/src/entities/doc/doc.rs rename to rust-lib/flowy-document-infra/src/entities/doc/doc.rs index 545417648d..e077222ddd 100644 --- a/rust-lib/flowy-document/src/entities/doc/doc.rs +++ b/rust-lib/flowy-document-infra/src/entities/doc/doc.rs @@ -1,6 +1,5 @@ -use crate::errors::DocResult; use flowy_derive::ProtoBuf; -use flowy_ot::core::Delta; +use flowy_ot::{core::Delta, errors::OTError}; #[derive(ProtoBuf, Default, Debug, Clone)] pub struct CreateDocParams { @@ -36,7 +35,7 @@ pub struct Doc { } impl Doc { - pub fn delta(&self) -> DocResult { + pub fn delta(&self) -> Result { let delta = Delta::from_bytes(&self.data)?; Ok(delta) } diff --git a/rust-lib/flowy-document/src/entities/doc/mod.rs b/rust-lib/flowy-document-infra/src/entities/doc/mod.rs similarity index 100% rename from rust-lib/flowy-document/src/entities/doc/mod.rs rename to rust-lib/flowy-document-infra/src/entities/doc/mod.rs diff --git a/rust-lib/flowy-document/src/entities/doc/parser/doc_id.rs b/rust-lib/flowy-document-infra/src/entities/doc/parser/doc_id.rs similarity index 100% rename from rust-lib/flowy-document/src/entities/doc/parser/doc_id.rs rename to rust-lib/flowy-document-infra/src/entities/doc/parser/doc_id.rs diff --git a/rust-lib/flowy-document/src/entities/doc/parser/mod.rs b/rust-lib/flowy-document-infra/src/entities/doc/parser/mod.rs similarity index 100% rename from rust-lib/flowy-document/src/entities/doc/parser/mod.rs rename to rust-lib/flowy-document-infra/src/entities/doc/parser/mod.rs diff --git a/rust-lib/flowy-document/src/entities/doc/revision.rs b/rust-lib/flowy-document-infra/src/entities/doc/revision.rs similarity index 98% rename from rust-lib/flowy-document/src/entities/doc/revision.rs rename to rust-lib/flowy-document-infra/src/entities/doc/revision.rs index cb83ca13f4..c347b57f4e 100644 --- a/rust-lib/flowy-document/src/entities/doc/revision.rs +++ b/rust-lib/flowy-document-infra/src/entities/doc/revision.rs @@ -1,6 +1,4 @@ -use crate::services::util::md5; - -use crate::entities::doc::Doc; +use crate::{entities::doc::Doc, util::md5}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_ot::core::Delta; use std::{fmt::Formatter, ops::RangeInclusive}; diff --git a/rust-lib/flowy-document-infra/src/entities/mod.rs b/rust-lib/flowy-document-infra/src/entities/mod.rs new file mode 100644 index 0000000000..dc16bd593b --- /dev/null +++ b/rust-lib/flowy-document-infra/src/entities/mod.rs @@ -0,0 +1 @@ +pub mod doc; diff --git a/rust-lib/flowy-document-infra/src/lib.rs b/rust-lib/flowy-document-infra/src/lib.rs new file mode 100644 index 0000000000..7a76152d96 --- /dev/null +++ b/rust-lib/flowy-document-infra/src/lib.rs @@ -0,0 +1,4 @@ +pub mod document_default; +pub mod entities; +pub mod protobuf; +pub mod util; diff --git a/rust-lib/flowy-document-infra/src/protobuf/mod.rs b/rust-lib/flowy-document-infra/src/protobuf/mod.rs new file mode 100644 index 0000000000..2480f62fbe --- /dev/null +++ b/rust-lib/flowy-document-infra/src/protobuf/mod.rs @@ -0,0 +1,4 @@ + +mod model; +pub use model::*; + \ No newline at end of file diff --git a/rust-lib/flowy-document/src/protobuf/model/doc.rs b/rust-lib/flowy-document-infra/src/protobuf/model/doc.rs similarity index 92% rename from rust-lib/flowy-document/src/protobuf/model/doc.rs rename to rust-lib/flowy-document-infra/src/protobuf/model/doc.rs index 9144834129..3ae789d62c 100644 --- a/rust-lib/flowy-document/src/protobuf/model/doc.rs +++ b/rust-lib/flowy-document-infra/src/protobuf/model/doc.rs @@ -1340,56 +1340,56 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x17\n\x07user_id\x18\x01\x20\x01(\tR\x06userId\x12\x15\n\x06rev_id\x18\ \x02\x20\x01(\x03R\x05revId\x12\x15\n\x06doc_id\x18\x03\x20\x01(\tR\x05d\ ocId\"&\n\rDocIdentifier\x12\x15\n\x06doc_id\x18\x01\x20\x01(\tR\x05docI\ - dJ\xdb\x07\n\x06\x12\x04\0\0\x1c\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\ - \n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\ - \x17\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\ - \x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\ - \x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\x04\x04\0\x02\x01\ - \x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\ - \x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\ - \x01\x03\x12\x03\x04\x12\x13\n\n\n\x02\x04\x01\x12\x04\x06\0\x0b\x01\n\n\ - \n\x03\x04\x01\x01\x12\x03\x06\x08\x0b\n\x0b\n\x04\x04\x01\x02\0\x12\x03\ - \x07\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x07\x04\n\n\x0c\n\x05\ - \x04\x01\x02\0\x01\x12\x03\x07\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\ - \x03\x07\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x08\x04\x14\n\x0c\n\ - \x05\x04\x01\x02\x01\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\x01\ - \x01\x12\x03\x08\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x08\x12\ - \x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\t\x04\x15\n\x0c\n\x05\x04\x01\ - \x02\x02\x05\x12\x03\t\x04\t\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\t\n\ - \x10\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\t\x13\x14\n\x0b\n\x04\x04\ - \x01\x02\x03\x12\x03\n\x04\x1a\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\n\ - \x04\t\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\n\n\x15\n\x0c\n\x05\x04\ - \x01\x02\x03\x03\x12\x03\n\x18\x19\n\n\n\x02\x04\x02\x12\x04\x0c\0\x10\ - \x01\n\n\n\x03\x04\x02\x01\x12\x03\x0c\x08\x17\n\x0b\n\x04\x04\x02\x02\0\ - \x12\x03\r\x04\x16\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\x04\n\n\x0c\n\ - \x05\x04\x02\x02\0\x01\x12\x03\r\x0b\x11\n\x0c\n\x05\x04\x02\x02\0\x03\ - \x12\x03\r\x14\x15\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0e\x04\x14\n\x0c\ - \n\x05\x04\x02\x02\x01\x05\x12\x03\x0e\x04\n\n\x0c\n\x05\x04\x02\x02\x01\ - \x01\x12\x03\x0e\x0b\x0f\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x0e\x12\ - \x13\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x0f\x04\x15\n\x0c\n\x05\x04\x02\ - \x02\x02\x05\x12\x03\x0f\x04\t\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\x03\ - \x0f\n\x10\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0f\x13\x14\n\n\n\x02\ - \x04\x03\x12\x04\x11\0\x14\x01\n\n\n\x03\x04\x03\x01\x12\x03\x11\x08\x10\ - \n\x0b\n\x04\x04\x03\x02\0\x12\x03\x12\x04\x16\n\x0c\n\x05\x04\x03\x02\0\ - \x05\x12\x03\x12\x04\n\n\x0c\n\x05\x04\x03\x02\0\x01\x12\x03\x12\x0b\x11\ - \n\x0c\n\x05\x04\x03\x02\0\x03\x12\x03\x12\x14\x15\n\x0b\n\x04\x04\x03\ - \x02\x01\x12\x03\x13\x04\x14\n\x0c\n\x05\x04\x03\x02\x01\x05\x12\x03\x13\ - \x04\n\n\x0c\n\x05\x04\x03\x02\x01\x01\x12\x03\x13\x0b\x0f\n\x0c\n\x05\ - \x04\x03\x02\x01\x03\x12\x03\x13\x12\x13\n\n\n\x02\x04\x04\x12\x04\x15\0\ - \x19\x01\n\n\n\x03\x04\x04\x01\x12\x03\x15\x08\x12\n\x0b\n\x04\x04\x04\ - \x02\0\x12\x03\x16\x04\x17\n\x0c\n\x05\x04\x04\x02\0\x05\x12\x03\x16\x04\ - \n\n\x0c\n\x05\x04\x04\x02\0\x01\x12\x03\x16\x0b\x12\n\x0c\n\x05\x04\x04\ - \x02\0\x03\x12\x03\x16\x15\x16\n\x0b\n\x04\x04\x04\x02\x01\x12\x03\x17\ - \x04\x15\n\x0c\n\x05\x04\x04\x02\x01\x05\x12\x03\x17\x04\t\n\x0c\n\x05\ - \x04\x04\x02\x01\x01\x12\x03\x17\n\x10\n\x0c\n\x05\x04\x04\x02\x01\x03\ - \x12\x03\x17\x13\x14\n\x0b\n\x04\x04\x04\x02\x02\x12\x03\x18\x04\x16\n\ - \x0c\n\x05\x04\x04\x02\x02\x05\x12\x03\x18\x04\n\n\x0c\n\x05\x04\x04\x02\ - \x02\x01\x12\x03\x18\x0b\x11\n\x0c\n\x05\x04\x04\x02\x02\x03\x12\x03\x18\ - \x14\x15\n\n\n\x02\x04\x05\x12\x04\x1a\0\x1c\x01\n\n\n\x03\x04\x05\x01\ - \x12\x03\x1a\x08\x15\n\x0b\n\x04\x04\x05\x02\0\x12\x03\x1b\x04\x16\n\x0c\ - \n\x05\x04\x05\x02\0\x05\x12\x03\x1b\x04\n\n\x0c\n\x05\x04\x05\x02\0\x01\ - \x12\x03\x1b\x0b\x11\n\x0c\n\x05\x04\x05\x02\0\x03\x12\x03\x1b\x14\x15b\ - \x06proto3\ + dJ\xdb\x07\n\x06\x12\x04\0\0\x1b\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\ + \n\x02\x04\0\x12\x04\x01\0\x04\x01\n\n\n\x03\x04\0\x01\x12\x03\x01\x08\ + \x17\n\x0b\n\x04\x04\0\x02\0\x12\x03\x02\x04\x12\n\x0c\n\x05\x04\0\x02\0\ + \x05\x12\x03\x02\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x02\x0b\r\n\ + \x0c\n\x05\x04\0\x02\0\x03\x12\x03\x02\x10\x11\n\x0b\n\x04\x04\0\x02\x01\ + \x12\x03\x03\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x03\x04\n\n\ + \x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x03\x0b\x0f\n\x0c\n\x05\x04\0\x02\ + \x01\x03\x12\x03\x03\x12\x13\n\n\n\x02\x04\x01\x12\x04\x05\0\n\x01\n\n\n\ + \x03\x04\x01\x01\x12\x03\x05\x08\x0b\n\x0b\n\x04\x04\x01\x02\0\x12\x03\ + \x06\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x06\x04\n\n\x0c\n\x05\ + \x04\x01\x02\0\x01\x12\x03\x06\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\ + \x03\x06\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x07\x04\x14\n\x0c\n\ + \x05\x04\x01\x02\x01\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\x01\x02\x01\ + \x01\x12\x03\x07\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x07\x12\ + \x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x08\x04\x15\n\x0c\n\x05\x04\x01\ + \x02\x02\x05\x12\x03\x08\x04\t\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\ + \x08\n\x10\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\x08\x13\x14\n\x0b\n\ + \x04\x04\x01\x02\x03\x12\x03\t\x04\x1a\n\x0c\n\x05\x04\x01\x02\x03\x05\ + \x12\x03\t\x04\t\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\t\n\x15\n\x0c\n\ + \x05\x04\x01\x02\x03\x03\x12\x03\t\x18\x19\n\n\n\x02\x04\x02\x12\x04\x0b\ + \0\x0f\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0b\x08\x17\n\x0b\n\x04\x04\x02\ + \x02\0\x12\x03\x0c\x04\x16\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x0c\x04\ + \n\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0c\x0b\x11\n\x0c\n\x05\x04\x02\ + \x02\0\x03\x12\x03\x0c\x14\x15\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\r\x04\ + \x14\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\r\x04\n\n\x0c\n\x05\x04\x02\ + \x02\x01\x01\x12\x03\r\x0b\x0f\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\r\ + \x12\x13\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x0e\x04\x15\n\x0c\n\x05\x04\ + \x02\x02\x02\x05\x12\x03\x0e\x04\t\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\ + \x03\x0e\n\x10\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0e\x13\x14\n\n\n\ + \x02\x04\x03\x12\x04\x10\0\x13\x01\n\n\n\x03\x04\x03\x01\x12\x03\x10\x08\ + \x10\n\x0b\n\x04\x04\x03\x02\0\x12\x03\x11\x04\x16\n\x0c\n\x05\x04\x03\ + \x02\0\x05\x12\x03\x11\x04\n\n\x0c\n\x05\x04\x03\x02\0\x01\x12\x03\x11\ + \x0b\x11\n\x0c\n\x05\x04\x03\x02\0\x03\x12\x03\x11\x14\x15\n\x0b\n\x04\ + \x04\x03\x02\x01\x12\x03\x12\x04\x14\n\x0c\n\x05\x04\x03\x02\x01\x05\x12\ + \x03\x12\x04\n\n\x0c\n\x05\x04\x03\x02\x01\x01\x12\x03\x12\x0b\x0f\n\x0c\ + \n\x05\x04\x03\x02\x01\x03\x12\x03\x12\x12\x13\n\n\n\x02\x04\x04\x12\x04\ + \x14\0\x18\x01\n\n\n\x03\x04\x04\x01\x12\x03\x14\x08\x12\n\x0b\n\x04\x04\ + \x04\x02\0\x12\x03\x15\x04\x17\n\x0c\n\x05\x04\x04\x02\0\x05\x12\x03\x15\ + \x04\n\n\x0c\n\x05\x04\x04\x02\0\x01\x12\x03\x15\x0b\x12\n\x0c\n\x05\x04\ + \x04\x02\0\x03\x12\x03\x15\x15\x16\n\x0b\n\x04\x04\x04\x02\x01\x12\x03\ + \x16\x04\x15\n\x0c\n\x05\x04\x04\x02\x01\x05\x12\x03\x16\x04\t\n\x0c\n\ + \x05\x04\x04\x02\x01\x01\x12\x03\x16\n\x10\n\x0c\n\x05\x04\x04\x02\x01\ + \x03\x12\x03\x16\x13\x14\n\x0b\n\x04\x04\x04\x02\x02\x12\x03\x17\x04\x16\ + \n\x0c\n\x05\x04\x04\x02\x02\x05\x12\x03\x17\x04\n\n\x0c\n\x05\x04\x04\ + \x02\x02\x01\x12\x03\x17\x0b\x11\n\x0c\n\x05\x04\x04\x02\x02\x03\x12\x03\ + \x17\x14\x15\n\n\n\x02\x04\x05\x12\x04\x19\0\x1b\x01\n\n\n\x03\x04\x05\ + \x01\x12\x03\x19\x08\x15\n\x0b\n\x04\x04\x05\x02\0\x12\x03\x1a\x04\x16\n\ + \x0c\n\x05\x04\x05\x02\0\x05\x12\x03\x1a\x04\n\n\x0c\n\x05\x04\x05\x02\0\ + \x01\x12\x03\x1a\x0b\x11\n\x0c\n\x05\x04\x05\x02\0\x03\x12\x03\x1a\x14\ + \x15b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-document-infra/src/protobuf/model/mod.rs b/rust-lib/flowy-document-infra/src/protobuf/model/mod.rs new file mode 100644 index 0000000000..1ffa511c1d --- /dev/null +++ b/rust-lib/flowy-document-infra/src/protobuf/model/mod.rs @@ -0,0 +1,7 @@ +// Auto-generated, do not edit + +mod revision; +pub use revision::*; + +mod doc; +pub use doc::*; diff --git a/rust-lib/flowy-document/src/protobuf/model/revision.rs b/rust-lib/flowy-document-infra/src/protobuf/model/revision.rs similarity index 90% rename from rust-lib/flowy-document/src/protobuf/model/revision.rs rename to rust-lib/flowy-document-infra/src/protobuf/model/revision.rs index 83bd5e7ad0..f1ff4fbc42 100644 --- a/rust-lib/flowy-document/src/protobuf/model/revision.rs +++ b/rust-lib/flowy-document-infra/src/protobuf/model/revision.rs @@ -808,44 +808,44 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \n\rRevisionRange\x12\x15\n\x06doc_id\x18\x01\x20\x01(\tR\x05docId\x12\ \x14\n\x05start\x18\x02\x20\x01(\x03R\x05start\x12\x10\n\x03end\x18\x03\ \x20\x01(\x03R\x03end*\x20\n\x07RevType\x12\t\n\x05Local\x10\0\x12\n\n\ - \x06Remote\x10\x01J\xea\x05\n\x06\x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\ - \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x04\x01\n\n\n\x03\x04\0\ - \x01\x12\x03\x02\x08\r\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x14\n\x0c\ - \n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\t\n\x0c\n\x05\x04\0\x02\0\x01\x12\ - \x03\x03\n\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\x13\n\n\n\x02\ - \x04\x01\x12\x04\x05\0\x0c\x01\n\n\n\x03\x04\x01\x01\x12\x03\x05\x08\x10\ - \n\x0b\n\x04\x04\x01\x02\0\x12\x03\x06\x04\x1a\n\x0c\n\x05\x04\x01\x02\0\ - \x05\x12\x03\x06\x04\t\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x06\n\x15\n\ - \x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x06\x18\x19\n\x0b\n\x04\x04\x01\x02\ - \x01\x12\x03\x07\x04\x15\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x07\x04\ - \t\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x07\n\x10\n\x0c\n\x05\x04\x01\ - \x02\x01\x03\x12\x03\x07\x13\x14\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x08\ - \x04\x19\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\x08\x04\t\n\x0c\n\x05\ - \x04\x01\x02\x02\x01\x12\x03\x08\n\x14\n\x0c\n\x05\x04\x01\x02\x02\x03\ - \x12\x03\x08\x17\x18\n\x0b\n\x04\x04\x01\x02\x03\x12\x03\t\x04\x13\n\x0c\ - \n\x05\x04\x01\x02\x03\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x03\ - \x01\x12\x03\t\x0b\x0e\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\t\x11\x12\ - \n\x0b\n\x04\x04\x01\x02\x04\x12\x03\n\x04\x16\n\x0c\n\x05\x04\x01\x02\ - \x04\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x04\x01\x12\x03\n\x0b\ - \x11\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\n\x14\x15\n\x0b\n\x04\x04\ - \x01\x02\x05\x12\x03\x0b\x04\x13\n\x0c\n\x05\x04\x01\x02\x05\x06\x12\x03\ - \x0b\x04\x0b\n\x0c\n\x05\x04\x01\x02\x05\x01\x12\x03\x0b\x0c\x0e\n\x0c\n\ - \x05\x04\x01\x02\x05\x03\x12\x03\x0b\x11\x12\n\n\n\x02\x04\x02\x12\x04\r\ - \0\x11\x01\n\n\n\x03\x04\x02\x01\x12\x03\r\x08\x15\n\x0b\n\x04\x04\x02\ - \x02\0\x12\x03\x0e\x04\x16\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x0e\x04\ - \n\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0e\x0b\x11\n\x0c\n\x05\x04\x02\ - \x02\0\x03\x12\x03\x0e\x14\x15\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0f\ - \x04\x14\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\x0f\x04\t\n\x0c\n\x05\ - \x04\x02\x02\x01\x01\x12\x03\x0f\n\x0f\n\x0c\n\x05\x04\x02\x02\x01\x03\ - \x12\x03\x0f\x12\x13\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x10\x04\x12\n\ - \x0c\n\x05\x04\x02\x02\x02\x05\x12\x03\x10\x04\t\n\x0c\n\x05\x04\x02\x02\ - \x02\x01\x12\x03\x10\n\r\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x10\x10\ - \x11\n\n\n\x02\x05\0\x12\x04\x12\0\x15\x01\n\n\n\x03\x05\0\x01\x12\x03\ - \x12\x05\x0c\n\x0b\n\x04\x05\0\x02\0\x12\x03\x13\x04\x0e\n\x0c\n\x05\x05\ - \0\x02\0\x01\x12\x03\x13\x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x13\ - \x0c\r\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x14\x04\x0f\n\x0c\n\x05\x05\0\ - \x02\x01\x01\x12\x03\x14\x04\n\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x14\ - \r\x0eb\x06proto3\ + \x06Remote\x10\x01J\xea\x05\n\x06\x12\x04\0\0\x14\x01\n\x08\n\x01\x0c\ + \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x01\0\x03\x01\n\n\n\x03\x04\0\ + \x01\x12\x03\x01\x08\r\n\x0b\n\x04\x04\0\x02\0\x12\x03\x02\x04\x14\n\x0c\ + \n\x05\x04\0\x02\0\x05\x12\x03\x02\x04\t\n\x0c\n\x05\x04\0\x02\0\x01\x12\ + \x03\x02\n\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x02\x12\x13\n\n\n\x02\ + \x04\x01\x12\x04\x04\0\x0b\x01\n\n\n\x03\x04\x01\x01\x12\x03\x04\x08\x10\ + \n\x0b\n\x04\x04\x01\x02\0\x12\x03\x05\x04\x1a\n\x0c\n\x05\x04\x01\x02\0\ + \x05\x12\x03\x05\x04\t\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x05\n\x15\n\ + \x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x05\x18\x19\n\x0b\n\x04\x04\x01\x02\ + \x01\x12\x03\x06\x04\x15\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x06\x04\ + \t\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x06\n\x10\n\x0c\n\x05\x04\x01\ + \x02\x01\x03\x12\x03\x06\x13\x14\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x07\ + \x04\x19\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\x07\x04\t\n\x0c\n\x05\ + \x04\x01\x02\x02\x01\x12\x03\x07\n\x14\n\x0c\n\x05\x04\x01\x02\x02\x03\ + \x12\x03\x07\x17\x18\n\x0b\n\x04\x04\x01\x02\x03\x12\x03\x08\x04\x13\n\ + \x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\ + \x03\x01\x12\x03\x08\x0b\x0e\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x08\ + \x11\x12\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\t\x04\x16\n\x0c\n\x05\x04\ + \x01\x02\x04\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x04\x01\x12\x03\ + \t\x0b\x11\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\t\x14\x15\n\x0b\n\x04\ + \x04\x01\x02\x05\x12\x03\n\x04\x13\n\x0c\n\x05\x04\x01\x02\x05\x06\x12\ + \x03\n\x04\x0b\n\x0c\n\x05\x04\x01\x02\x05\x01\x12\x03\n\x0c\x0e\n\x0c\n\ + \x05\x04\x01\x02\x05\x03\x12\x03\n\x11\x12\n\n\n\x02\x04\x02\x12\x04\x0c\ + \0\x10\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0c\x08\x15\n\x0b\n\x04\x04\x02\ + \x02\0\x12\x03\r\x04\x16\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\x04\n\n\ + \x0c\n\x05\x04\x02\x02\0\x01\x12\x03\r\x0b\x11\n\x0c\n\x05\x04\x02\x02\0\ + \x03\x12\x03\r\x14\x15\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0e\x04\x14\n\ + \x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\x0e\x04\t\n\x0c\n\x05\x04\x02\x02\ + \x01\x01\x12\x03\x0e\n\x0f\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x0e\ + \x12\x13\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x0f\x04\x12\n\x0c\n\x05\x04\ + \x02\x02\x02\x05\x12\x03\x0f\x04\t\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\ + \x03\x0f\n\r\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0f\x10\x11\n\n\n\ + \x02\x05\0\x12\x04\x11\0\x14\x01\n\n\n\x03\x05\0\x01\x12\x03\x11\x05\x0c\ + \n\x0b\n\x04\x05\0\x02\0\x12\x03\x12\x04\x0e\n\x0c\n\x05\x05\0\x02\0\x01\ + \x12\x03\x12\x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x12\x0c\r\n\x0b\n\ + \x04\x05\0\x02\x01\x12\x03\x13\x04\x0f\n\x0c\n\x05\x05\0\x02\x01\x01\x12\ + \x03\x13\x04\n\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x13\r\x0eb\x06proto\ + 3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-document/src/protobuf/proto/doc.proto b/rust-lib/flowy-document-infra/src/protobuf/proto/doc.proto similarity index 99% rename from rust-lib/flowy-document/src/protobuf/proto/doc.proto rename to rust-lib/flowy-document-infra/src/protobuf/proto/doc.proto index c7c8ea2c8a..6146091f6b 100644 --- a/rust-lib/flowy-document/src/protobuf/proto/doc.proto +++ b/rust-lib/flowy-document-infra/src/protobuf/proto/doc.proto @@ -1,5 +1,4 @@ syntax = "proto3"; - message CreateDocParams { string id = 1; string data = 2; diff --git a/rust-lib/flowy-document/src/protobuf/proto/revision.proto b/rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto similarity index 99% rename from rust-lib/flowy-document/src/protobuf/proto/revision.proto rename to rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto index 44a3137bc1..dce0443d8d 100644 --- a/rust-lib/flowy-document/src/protobuf/proto/revision.proto +++ b/rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto @@ -1,5 +1,4 @@ syntax = "proto3"; - message RevId { int64 value = 1; } diff --git a/rust-lib/flowy-document/src/services/util.rs b/rust-lib/flowy-document-infra/src/util.rs similarity index 95% rename from rust-lib/flowy-document/src/services/util.rs rename to rust-lib/flowy-document-infra/src/util.rs index d20ac48cea..9336832175 100644 --- a/rust-lib/flowy-document/src/services/util.rs +++ b/rust-lib/flowy-document-infra/src/util.rs @@ -25,7 +25,7 @@ pub fn md5>(data: T) -> String { } #[derive(Debug)] -pub(crate) struct RevIdCounter(pub AtomicI64); +pub struct RevIdCounter(pub AtomicI64); impl RevIdCounter { pub fn new(n: i64) -> Self { Self(AtomicI64::new(n)) } diff --git a/rust-lib/flowy-document/Cargo.toml b/rust-lib/flowy-document/Cargo.toml index e02c25af0c..0f9b76879c 100644 --- a/rust-lib/flowy-document/Cargo.toml +++ b/rust-lib/flowy-document/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +flowy-document-infra = { path = "../flowy-document-infra" } derive_more = {version = "0.99", features = ["display"]} flowy-dispatch = { path = "../flowy-dispatch" } flowy-derive = { path = "../flowy-derive" } @@ -37,7 +38,6 @@ serde = { version = "1.0", features = ["derive"] } serde_json = {version = "1.0"} chrono = "0.4.19" futures-core = { version = "0.3", default-features = false } -md5 = "0.7.0" byteorder = {version = "1.3.4"} async-stream = "0.3.2" futures = "0.3.15" diff --git a/rust-lib/flowy-document/src/entities/mod.rs b/rust-lib/flowy-document/src/entities/mod.rs index a9963c22fa..6757c99679 100644 --- a/rust-lib/flowy-document/src/entities/mod.rs +++ b/rust-lib/flowy-document/src/entities/mod.rs @@ -1,2 +1 @@ -pub mod doc; pub mod ws; diff --git a/rust-lib/flowy-document/src/entities/ws/ws.rs b/rust-lib/flowy-document/src/entities/ws/ws.rs index 582818d5ae..894b85f815 100644 --- a/rust-lib/flowy-document/src/entities/ws/ws.rs +++ b/rust-lib/flowy-document/src/entities/ws/ws.rs @@ -1,9 +1,7 @@ -use crate::{ - entities::doc::{NewDocUser, Revision}, - errors::DocError, -}; +use crate::errors::DocError; use bytes::Bytes; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_document_infra::entities::doc::{NewDocUser, Revision}; use flowy_ws::{WsMessage, WsModule}; use std::convert::{TryFrom, TryInto}; diff --git a/rust-lib/flowy-document/src/lib.rs b/rust-lib/flowy-document/src/lib.rs index 73594c434c..01f2a9c66b 100644 --- a/rust-lib/flowy-document/src/lib.rs +++ b/rust-lib/flowy-document/src/lib.rs @@ -10,10 +10,3 @@ mod sql_tables; #[macro_use] extern crate flowy_database; - -pub mod prelude { - pub use crate::{ - module::*, - services::{server::*, ws::*}, - }; -} diff --git a/rust-lib/flowy-document/src/module.rs b/rust-lib/flowy-document/src/module.rs index 01606d18bc..5974b0e6e9 100644 --- a/rust-lib/flowy-document/src/module.rs +++ b/rust-lib/flowy-document/src/module.rs @@ -1,13 +1,13 @@ use crate::{ - entities::doc::{DocDelta, DocIdentifier}, errors::DocError, services::{ - doc::{doc_controller::DocController, edit::ClientEditDoc}, + doc::{doc_controller::DocController, ClientEditDoc}, server::construct_doc_server, ws::WsDocumentManager, }, }; use flowy_database::ConnectionPool; +use flowy_document_infra::entities::doc::{DocDelta, DocIdentifier}; use flowy_net::config::ServerConfig; use std::sync::Arc; diff --git a/rust-lib/flowy-document/src/protobuf/model/event.rs b/rust-lib/flowy-document/src/protobuf/model/event.rs deleted file mode 100644 index 2f87ae59c9..0000000000 --- a/rust-lib/flowy-document/src/protobuf/model/event.rs +++ /dev/null @@ -1,108 +0,0 @@ -// This file is generated by rust-protobuf 2.22.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![allow(unused_attributes)] -#![cfg_attr(rustfmt, rustfmt::skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `event.proto` - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum EditorEvent { - CreateDoc = 0, - UpdateDoc = 1, - ReadDoc = 2, - DeleteDoc = 3, -} - -impl ::protobuf::ProtobufEnum for EditorEvent { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(EditorEvent::CreateDoc), - 1 => ::std::option::Option::Some(EditorEvent::UpdateDoc), - 2 => ::std::option::Option::Some(EditorEvent::ReadDoc), - 3 => ::std::option::Option::Some(EditorEvent::DeleteDoc), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [EditorEvent] = &[ - EditorEvent::CreateDoc, - EditorEvent::UpdateDoc, - EditorEvent::ReadDoc, - EditorEvent::DeleteDoc, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("EditorEvent", file_descriptor_proto()) - }) - } -} - -impl ::std::marker::Copy for EditorEvent { -} - -impl ::std::default::Default for EditorEvent { - fn default() -> Self { - EditorEvent::CreateDoc - } -} - -impl ::protobuf::reflect::ProtobufValue for EditorEvent { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0bevent.proto*G\n\x0bEditorEvent\x12\r\n\tCreateDoc\x10\0\x12\r\n\tU\ - pdateDoc\x10\x01\x12\x0b\n\x07ReadDoc\x10\x02\x12\r\n\tDeleteDoc\x10\x03\ - J\xce\x01\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\ - \n\x02\x05\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\ - \x10\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x05\0\x02\0\ - \x01\x12\x03\x03\x04\r\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x10\x11\n\ - \x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x12\n\x0c\n\x05\x05\0\x02\x01\ - \x01\x12\x03\x04\x04\r\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\x10\x11\ - \n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x10\n\x0c\n\x05\x05\0\x02\x02\ - \x01\x12\x03\x05\x04\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x05\x0e\ - \x0f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\x04\x12\n\x0c\n\x05\x05\0\x02\ - \x03\x01\x12\x03\x06\x04\r\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\x06\x10\ - \x11b\x06proto3\ -"; - -static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) -} diff --git a/rust-lib/flowy-document/src/protobuf/model/mod.rs b/rust-lib/flowy-document/src/protobuf/model/mod.rs index eb8e589277..bd807559e2 100644 --- a/rust-lib/flowy-document/src/protobuf/model/mod.rs +++ b/rust-lib/flowy-document/src/protobuf/model/mod.rs @@ -8,12 +8,3 @@ pub use observable::*; mod errors; pub use errors::*; - -mod revision; -pub use revision::*; - -mod event; -pub use event::*; - -mod doc; -pub use doc::*; diff --git a/rust-lib/flowy-document/src/protobuf/model/ws.rs b/rust-lib/flowy-document/src/protobuf/model/ws.rs index 8e9387f84e..0b1041993a 100644 --- a/rust-lib/flowy-document/src/protobuf/model/ws.rs +++ b/rust-lib/flowy-document/src/protobuf/model/ws.rs @@ -320,28 +320,28 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x02ty\x12\x12\n\x04data\x18\x03\x20\x01(\x0cR\x04data*O\n\nWsDataType\ \x12\t\n\x05Acked\x10\0\x12\x0b\n\x07PushRev\x10\x01\x12\x0b\n\x07PullRe\ v\x10\x02\x12\x0c\n\x08Conflict\x10\x03\x12\x0e\n\nNewDocUser\x10\x04J\ - \xb4\x03\n\x06\x12\x04\0\0\r\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\ - \x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x16\ - \n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\ - \x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x11\n\x0c\ - \n\x05\x04\0\x02\0\x03\x12\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\ - \x03\x04\x04\x16\n\x0c\n\x05\x04\0\x02\x01\x06\x12\x03\x04\x04\x0e\n\x0c\ - \n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0f\x11\n\x0c\n\x05\x04\0\x02\x01\ - \x03\x12\x03\x04\x14\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x13\n\ - \x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\t\n\x0c\n\x05\x04\0\x02\x02\ - \x01\x12\x03\x05\n\x0e\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x11\x12\ - \n\n\n\x02\x05\0\x12\x04\x07\0\r\x01\n\n\n\x03\x05\0\x01\x12\x03\x07\x05\ - \x0f\n\x0b\n\x04\x05\0\x02\0\x12\x03\x08\x04\x0e\n\x0c\n\x05\x05\0\x02\0\ - \x01\x12\x03\x08\x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x08\x0c\r\n\ - \x0b\n\x04\x05\0\x02\x01\x12\x03\t\x04\x10\n\x0c\n\x05\x05\0\x02\x01\x01\ - \x12\x03\t\x04\x0b\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\t\x0e\x0f\n\x0b\ - \n\x04\x05\0\x02\x02\x12\x03\n\x04\x10\n\x0c\n\x05\x05\0\x02\x02\x01\x12\ - \x03\n\x04\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\n\x0e\x0f\n\x0b\n\ - \x04\x05\0\x02\x03\x12\x03\x0b\x04\x11\n\x0c\n\x05\x05\0\x02\x03\x01\x12\ - \x03\x0b\x04\x0c\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\x0b\x0f\x10\n\x0b\ - \n\x04\x05\0\x02\x04\x12\x03\x0c\x04\x13\n\x0c\n\x05\x05\0\x02\x04\x01\ - \x12\x03\x0c\x04\x0e\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0c\x11\x12b\ - \x06proto3\ + \xb4\x03\n\x06\x12\x04\0\0\x0c\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\ + \x02\x04\0\x12\x04\x01\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x01\x08\x16\ + \n\x0b\n\x04\x04\0\x02\0\x12\x03\x02\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\ + \x12\x03\x02\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x02\x0b\x11\n\x0c\ + \n\x05\x04\0\x02\0\x03\x12\x03\x02\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\ + \x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\x01\x06\x12\x03\x03\x04\x0e\n\x0c\ + \n\x05\x04\0\x02\x01\x01\x12\x03\x03\x0f\x11\n\x0c\n\x05\x04\0\x02\x01\ + \x03\x12\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x04\x04\x13\n\ + \x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x04\x04\t\n\x0c\n\x05\x04\0\x02\x02\ + \x01\x12\x03\x04\n\x0e\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x04\x11\x12\ + \n\n\n\x02\x05\0\x12\x04\x06\0\x0c\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\ + \x05\x0f\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x0e\n\x0c\n\x05\x05\0\ + \x02\0\x01\x12\x03\x07\x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0c\ + \r\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x10\n\x0c\n\x05\x05\0\x02\ + \x01\x01\x12\x03\x08\x04\x0b\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\ + \x0e\x0f\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x10\n\x0c\n\x05\x05\0\ + \x02\x02\x01\x12\x03\t\x04\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\ + \x0e\x0f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x11\n\x0c\n\x05\x05\0\ + \x02\x03\x01\x12\x03\n\x04\x0c\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\ + \x0f\x10\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x13\n\x0c\n\x05\x05\0\ + \x02\x04\x01\x12\x03\x0b\x04\x0e\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\ + \x0b\x11\x12b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-document/src/protobuf/proto/event.proto b/rust-lib/flowy-document/src/protobuf/proto/event.proto deleted file mode 100644 index 80ac2f2d71..0000000000 --- a/rust-lib/flowy-document/src/protobuf/proto/event.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -enum EditorEvent { - CreateDoc = 0; - UpdateDoc = 1; - ReadDoc = 2; - DeleteDoc = 3; -} diff --git a/rust-lib/flowy-document/src/protobuf/proto/ws.proto b/rust-lib/flowy-document/src/protobuf/proto/ws.proto index 4c7865fd1b..f6ea1bf329 100644 --- a/rust-lib/flowy-document/src/protobuf/proto/ws.proto +++ b/rust-lib/flowy-document/src/protobuf/proto/ws.proto @@ -1,5 +1,4 @@ syntax = "proto3"; - message WsDocumentData { string doc_id = 1; WsDataType ty = 2; diff --git a/rust-lib/flowy-document/src/services/cache.rs b/rust-lib/flowy-document/src/services/cache.rs index 65429ed6b8..6c60196c84 100644 --- a/rust-lib/flowy-document/src/services/cache.rs +++ b/rust-lib/flowy-document/src/services/cache.rs @@ -4,7 +4,7 @@ use dashmap::DashMap; use crate::{ errors::DocError, - services::doc::edit::{ClientEditDoc, DocId}, + services::doc::{ClientEditDoc, DocId}, }; pub(crate) struct DocCache { diff --git a/rust-lib/flowy-document/src/services/doc/doc_controller.rs b/rust-lib/flowy-document/src/services/doc/doc_controller.rs index 54355a1d7f..bdb17745b6 100644 --- a/rust-lib/flowy-document/src/services/doc/doc_controller.rs +++ b/rust-lib/flowy-document/src/services/doc/doc_controller.rs @@ -1,5 +1,4 @@ use crate::{ - entities::doc::{Doc, DocDelta, DocIdentifier}, errors::{DocError, DocResult}, module::DocumentUser, services::{ @@ -14,9 +13,9 @@ use crate::{ }; use bytes::Bytes; use flowy_database::ConnectionPool; +use flowy_document_infra::entities::doc::{Doc, DocDelta, DocIdentifier}; use flowy_infra::future::{wrap_future, FnFuture, ResultFuture}; use std::sync::Arc; - use tokio::time::{interval, Duration}; pub(crate) struct DocController { diff --git a/rust-lib/flowy-document/src/services/doc/document/document.rs b/rust-lib/flowy-document/src/services/doc/document/document.rs index 5bdc2d6882..bf9a48f74c 100644 --- a/rust-lib/flowy-document/src/services/doc/document/document.rs +++ b/rust-lib/flowy-document/src/services/doc/document/document.rs @@ -2,7 +2,7 @@ use crate::{ errors::DocError, services::doc::{view::View, History, UndoResult, RECORD_THRESHOLD}, }; - +use flowy_document_infra::document_default::doc_initial_delta; use flowy_ot::core::*; use tokio::sync::mpsc; @@ -15,16 +15,6 @@ impl CustomDocument for PlainDoc { fn init_delta() -> Delta { Delta::new() } } -#[allow(dead_code)] -#[inline] -pub fn doc_initial_delta() -> Delta { DeltaBuilder::new().insert("\n").build() } -#[allow(dead_code)] -#[inline] -pub fn doc_initial_string() -> String { doc_initial_delta().to_json() } -#[allow(dead_code)] -#[inline] -pub fn doc_initial_bytes() -> Vec { doc_initial_string().into_bytes() } - pub struct FlowyDoc(); impl CustomDocument for FlowyDoc { fn init_delta() -> Delta { doc_initial_delta() } @@ -218,15 +208,3 @@ pub fn trim(delta: &mut Delta) { } } } - -#[cfg(test)] -mod tests { - use flowy_ot::core::Delta; - - #[test] - fn load_read_me() { - let json = include_str!("../../../READ_ME.json"); - let delta = Delta::from_json(json).unwrap(); - assert_eq!(delta.to_json(), json); - } -} diff --git a/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs b/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs index 09616b645a..a9fe63212f 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs @@ -1,16 +1,14 @@ use crate::{ - entities::doc::{RevId, Revision}, errors::DocResult, - services::doc::{ - edit::message::{DocumentMsg, TransformDeltas}, - Document, - }, + services::doc::{Document, UndoResult}, }; use async_stream::stream; -use flowy_ot::core::{Delta, OperationTransformable}; +use bytes::Bytes; +use flowy_document_infra::entities::doc::{RevId, Revision}; +use flowy_ot::core::{Attribute, Delta, Interval, OperationTransformable}; use futures::stream::StreamExt; use std::{convert::TryFrom, sync::Arc}; -use tokio::sync::{mpsc, RwLock}; +use tokio::sync::{mpsc, oneshot, RwLock}; pub struct DocumentActor { doc_id: String, @@ -139,3 +137,56 @@ impl DocumentActor { // }); // Ok(()) // } + +pub type Ret = oneshot::Sender>; +pub enum DocumentMsg { + Delta { + delta: Delta, + ret: Ret<()>, + }, + RemoteRevision { + bytes: Bytes, + ret: Ret, + }, + Insert { + index: usize, + data: String, + ret: Ret, + }, + Delete { + interval: Interval, + ret: Ret, + }, + Format { + interval: Interval, + attribute: Attribute, + ret: Ret, + }, + + Replace { + interval: Interval, + data: String, + ret: Ret, + }, + CanUndo { + ret: oneshot::Sender, + }, + CanRedo { + ret: oneshot::Sender, + }, + Undo { + ret: Ret, + }, + Redo { + ret: Ret, + }, + Doc { + ret: Ret, + }, +} + +pub struct TransformDeltas { + pub client_prime: Delta, + pub server_prime: Delta, + pub server_rev_id: RevId, +} diff --git a/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs b/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs index ee95e7773e..0d57ee8f70 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs @@ -1,18 +1,15 @@ use crate::{ - entities::{ - doc::{DocDelta, RevId, RevType, Revision, RevisionRange}, - ws::{WsDataType, WsDocumentData}, - }, + entities::ws::{WsDataType, WsDocumentData}, errors::{internal_error, DocError, DocResult}, module::DocumentUser, services::{ doc::{ - edit::{ - doc_actor::DocumentActor, - message::{DocumentMsg, TransformDeltas}, - model::OpenDocAction, - }, - revision::{RevisionManager, RevisionServer}, + DocumentActor, + DocumentMsg, + OpenDocAction, + RevisionManager, + RevisionServer, + TransformDeltas, UndoResult, }, ws::{DocumentWebSocket, WsDocumentHandler}, @@ -20,6 +17,7 @@ use crate::{ }; use bytes::Bytes; use flowy_database::ConnectionPool; +use flowy_document_infra::entities::doc::{DocDelta, RevId, RevType, Revision, RevisionRange}; use flowy_infra::retry::{ExponentialBackoff, Retry}; use flowy_ot::core::{Attribute, Delta, Interval}; use flowy_ws::WsState; diff --git a/rust-lib/flowy-document/src/services/doc/edit/message.rs b/rust-lib/flowy-document/src/services/doc/edit/message.rs deleted file mode 100644 index 004062b641..0000000000 --- a/rust-lib/flowy-document/src/services/doc/edit/message.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::{errors::DocResult, services::doc::UndoResult}; -use flowy_ot::core::{Attribute, Delta, Interval}; - -use crate::entities::doc::RevId; -use bytes::Bytes; -use tokio::sync::oneshot; - -pub type Ret = oneshot::Sender>; -pub enum DocumentMsg { - Delta { - delta: Delta, - ret: Ret<()>, - }, - RemoteRevision { - bytes: Bytes, - ret: Ret, - }, - Insert { - index: usize, - data: String, - ret: Ret, - }, - Delete { - interval: Interval, - ret: Ret, - }, - Format { - interval: Interval, - attribute: Attribute, - ret: Ret, - }, - - Replace { - interval: Interval, - data: String, - ret: Ret, - }, - CanUndo { - ret: oneshot::Sender, - }, - CanRedo { - ret: oneshot::Sender, - }, - Undo { - ret: Ret, - }, - Redo { - ret: Ret, - }, - Doc { - ret: Ret, - }, -} - -pub struct TransformDeltas { - pub client_prime: Delta, - pub server_prime: Delta, - pub server_rev_id: RevId, -} diff --git a/rust-lib/flowy-document/src/services/doc/edit/mod.rs b/rust-lib/flowy-document/src/services/doc/edit/mod.rs index fcfc991daa..1bb0e5f25e 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/mod.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/mod.rs @@ -1,6 +1,7 @@ mod doc_actor; mod edit_doc; -mod message; mod model; +pub(crate) use doc_actor::*; pub use edit_doc::*; +pub(crate) use model::*; diff --git a/rust-lib/flowy-document/src/services/doc/edit/model.rs b/rust-lib/flowy-document/src/services/doc/edit/model.rs index c869c37a4b..5f002fa078 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/model.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/model.rs @@ -1,8 +1,5 @@ -use crate::{ - entities::doc::{NewDocUser, RevId}, - errors::DocError, - services::ws::DocumentWebSocket, -}; +use crate::{errors::DocError, services::ws::DocumentWebSocket}; +use flowy_document_infra::entities::doc::{NewDocUser, RevId}; use flowy_infra::retry::Action; use futures::future::BoxFuture; use std::{future, sync::Arc}; diff --git a/rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs b/rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs index c6b5870eec..c538af0f1d 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs @@ -1,7 +1,7 @@ +use crate::services::doc::extensions::DeleteExt; +use flowy_document_infra::util::is_newline; use flowy_ot::core::{plain_attributes, CharMetric, Delta, DeltaBuilder, DeltaIter, Interval, NEW_LINE}; -use crate::services::{doc::extensions::DeleteExt, util::is_newline}; - pub struct PreserveLineFormatOnMerge {} impl DeleteExt for PreserveLineFormatOnMerge { fn ext_name(&self) -> &str { "PreserveLineFormatOnMerge" } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs b/rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs index 04521719a9..27650f5ba5 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs @@ -1,4 +1,4 @@ -use crate::services::util::find_newline; +use flowy_document_infra::util::find_newline; use flowy_ot::core::{plain_attributes, Attribute, AttributeScope, Delta, Operation}; pub(crate) fn line_break(op: &Operation, attribute: &Attribute, scope: AttributeScope) -> Delta { diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs b/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs index 8fe61df8b6..d0eeca57aa 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs @@ -1,10 +1,7 @@ +use crate::services::doc::extensions::{format::helper::line_break, FormatExt}; +use flowy_document_infra::util::find_newline; use flowy_ot::core::{plain_attributes, Attribute, AttributeScope, Delta, DeltaBuilder, DeltaIter, Interval}; -use crate::services::{ - doc::extensions::{format::helper::line_break, FormatExt}, - util::find_newline, -}; - pub struct ResolveBlockFormat {} impl FormatExt for ResolveBlockFormat { fn ext_name(&self) -> &str { std::any::type_name::() } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs b/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs index 6e5f2d0c75..3f97d5956a 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs @@ -1,10 +1,7 @@ +use crate::services::doc::extensions::{format::helper::line_break, FormatExt}; +use flowy_document_infra::util::find_newline; use flowy_ot::core::{Attribute, AttributeScope, Delta, DeltaBuilder, DeltaIter, Interval}; -use crate::services::{ - doc::extensions::{format::helper::line_break, FormatExt}, - util::find_newline, -}; - pub struct ResolveInlineFormat {} impl FormatExt for ResolveInlineFormat { fn ext_name(&self) -> &str { std::any::type_name::() } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs b/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs index fdee1bb939..71fa518937 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs @@ -1,7 +1,7 @@ +use crate::services::doc::extensions::InsertExt; +use flowy_document_infra::util::is_newline; use flowy_ot::core::{attributes_except_header, is_empty_line_at_index, AttributeKey, Delta, DeltaBuilder, DeltaIter}; -use crate::services::{doc::extensions::InsertExt, util::is_newline}; - pub struct AutoExitBlock {} impl InsertExt for AutoExitBlock { diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs b/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs index 6216d092d8..ebddc864c5 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs @@ -1,10 +1,9 @@ +use crate::services::doc::extensions::InsertExt; +use flowy_document_infra::util::is_whitespace; +use flowy_ot::core::{count_utf16_code_units, plain_attributes, Attribute, Attributes, Delta, DeltaBuilder, DeltaIter}; use std::cmp::min; use url::Url; -use flowy_ot::core::{count_utf16_code_units, plain_attributes, Attribute, Attributes, Delta, DeltaBuilder, DeltaIter}; - -use crate::services::{doc::extensions::InsertExt, util::is_whitespace}; - pub struct AutoFormatExt {} impl InsertExt for AutoFormatExt { fn ext_name(&self) -> &str { std::any::type_name::() } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs b/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs index 36fda6f3a4..0daf191520 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs @@ -10,7 +10,8 @@ use flowy_ot::core::{ NEW_LINE, }; -use crate::services::{doc::extensions::InsertExt, util::is_newline}; +use crate::services::doc::extensions::InsertExt; +use flowy_document_infra::util::is_newline; pub struct PreserveBlockFormatOnInsert {} impl InsertExt for PreserveBlockFormatOnInsert { diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs b/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs index bf8e5da0a2..b5e6cd881d 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs @@ -1,10 +1,7 @@ +use crate::services::doc::extensions::InsertExt; +use flowy_document_infra::util::{contain_newline, is_newline}; use flowy_ot::core::{plain_attributes, AttributeKey, Delta, DeltaBuilder, DeltaIter, OpNewline, NEW_LINE}; -use crate::services::{ - doc::extensions::InsertExt, - util::{contain_newline, is_newline}, -}; - pub struct PreserveInlineFormat {} impl InsertExt for PreserveInlineFormat { fn ext_name(&self) -> &str { std::any::type_name::() } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs b/rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs index 1550c0611d..e29fb96c39 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs +++ b/rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs @@ -1,7 +1,7 @@ +use crate::services::doc::extensions::InsertExt; +use flowy_document_infra::util::is_newline; use flowy_ot::core::{AttributeKey, Attributes, CharMetric, Delta, DeltaBuilder, DeltaIter, NEW_LINE}; -use crate::services::{doc::extensions::InsertExt, util::is_newline}; - pub struct ResetLineFormatOnNewLine {} impl InsertExt for ResetLineFormatOnNewLine { fn ext_name(&self) -> &str { std::any::type_name::() } diff --git a/rust-lib/flowy-document/src/services/doc/mod.rs b/rust-lib/flowy-document/src/services/doc/mod.rs index 022f9b28e9..5fbed23e7f 100644 --- a/rust-lib/flowy-document/src/services/doc/mod.rs +++ b/rust-lib/flowy-document/src/services/doc/mod.rs @@ -7,6 +7,10 @@ mod history; mod view; pub(crate) mod doc_controller; -pub mod edit; -pub mod extensions; +mod edit; +mod extensions; mod revision; + +pub use edit::*; + +pub(crate) use revision::*; diff --git a/rust-lib/flowy-document/src/services/doc/revision/manager.rs b/rust-lib/flowy-document/src/services/doc/revision/manager.rs index 455313c615..790b11cccf 100644 --- a/rust-lib/flowy-document/src/services/doc/revision/manager.rs +++ b/rust-lib/flowy-document/src/services/doc/revision/manager.rs @@ -1,9 +1,12 @@ use crate::{ - entities::doc::{Doc, RevId, RevType, Revision, RevisionRange}, errors::{DocError, DocResult}, - services::{doc::revision::RevisionStore, util::RevIdCounter}, + services::doc::revision::RevisionStore, }; use flowy_database::ConnectionPool; +use flowy_document_infra::{ + entities::doc::{Doc, RevId, RevType, Revision, RevisionRange}, + util::RevIdCounter, +}; use flowy_infra::future::ResultFuture; use flowy_ot::core::{Delta, OperationTransformable}; use std::sync::Arc; diff --git a/rust-lib/flowy-document/src/services/doc/revision/model.rs b/rust-lib/flowy-document/src/services/doc/revision/model.rs index 136f833248..9b64c6e534 100644 --- a/rust-lib/flowy-document/src/services/doc/revision/model.rs +++ b/rust-lib/flowy-document/src/services/doc/revision/model.rs @@ -1,10 +1,9 @@ use crate::{ - entities::doc::{Revision, RevisionRange}, errors::{internal_error, DocError, DocResult}, sql_tables::{RevState, RevTableSql}, }; - use flowy_database::ConnectionPool; +use flowy_document_infra::entities::doc::{Revision, RevisionRange}; use flowy_infra::future::ResultFuture; use std::sync::Arc; diff --git a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs index 528ce21618..47b2662523 100644 --- a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs +++ b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs @@ -1,5 +1,4 @@ use crate::{ - entities::doc::{revision_from_doc, Doc, RevId, RevType, Revision, RevisionRange}, errors::{internal_error, DocError, DocResult}, services::doc::revision::{model::*, RevisionServer}, sql_tables::RevState, @@ -7,6 +6,7 @@ use crate::{ use async_stream::stream; use dashmap::DashMap; use flowy_database::{ConnectionPool, SqliteConnection}; +use flowy_document_infra::entities::doc::{revision_from_doc, Doc, RevId, RevType, Revision, RevisionRange}; use flowy_infra::future::ResultFuture; use flowy_ot::core::{Delta, Operation, OperationTransformable}; use futures::stream::StreamExt; @@ -190,13 +190,7 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc) -> DocRes let base_rev_id: RevId = revisions.last().unwrap().base_rev_id.into(); let rev_id: RevId = revisions.last().unwrap().rev_id.into(); let mut delta = Delta::new(); - let mut pre_rev_id = 0; for (_, revision) in revisions.into_iter().enumerate() { - pre_rev_id = revision.rev_id; - - #[cfg(debug_assertions)] - validate_rev_id(pre_rev_id, revision.rev_id); - match Delta::from_bytes(revision.delta_data) { Ok(local_delta) => { delta = delta.compose(&local_delta)?; @@ -231,13 +225,6 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc) -> DocRes .map_err(internal_error)? } -#[cfg(debug_assertions)] -fn validate_rev_id(current: i64, next: i64) { - if current >= next { - log::error!("The next revision id should be greater than the previous"); - } -} - #[cfg(debug_assertions)] fn validate_delta(doc_id: &str, persistence: Arc, conn: &SqliteConnection, delta: &Delta) { if delta.ops.last().is_none() { diff --git a/rust-lib/flowy-document/src/services/mod.rs b/rust-lib/flowy-document/src/services/mod.rs index 323a1c9fd6..c26732203a 100644 --- a/rust-lib/flowy-document/src/services/mod.rs +++ b/rust-lib/flowy-document/src/services/mod.rs @@ -1,5 +1,4 @@ mod cache; pub mod doc; pub mod server; -pub(crate) mod util; pub mod ws; diff --git a/rust-lib/flowy-document/src/services/server/mod.rs b/rust-lib/flowy-document/src/services/server/mod.rs index cd0d12fd7b..e4cee182b5 100644 --- a/rust-lib/flowy-document/src/services/server/mod.rs +++ b/rust-lib/flowy-document/src/services/server/mod.rs @@ -4,10 +4,8 @@ mod server_api_mock; pub use server_api::*; // TODO: ignore mock files in production -use crate::{ - entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}, - errors::DocError, -}; +use crate::errors::DocError; +use flowy_document_infra::entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}; use flowy_infra::future::ResultFuture; use flowy_net::config::ServerConfig; pub use server_api_mock::*; diff --git a/rust-lib/flowy-document/src/services/server/server_api.rs b/rust-lib/flowy-document/src/services/server/server_api.rs index 5517bce745..7bc023b0e2 100644 --- a/rust-lib/flowy-document/src/services/server/server_api.rs +++ b/rust-lib/flowy-document/src/services/server/server_api.rs @@ -1,8 +1,5 @@ -use crate::{ - entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}, - errors::DocError, - services::server::DocumentServerAPI, -}; +use crate::{errors::DocError, services::server::DocumentServerAPI}; +use flowy_document_infra::entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}; use flowy_infra::future::ResultFuture; use flowy_net::{config::*, request::HttpRequestBuilder}; diff --git a/rust-lib/flowy-document/src/services/server/server_api_mock.rs b/rust-lib/flowy-document/src/services/server/server_api_mock.rs index 58c57b1732..b999e19218 100644 --- a/rust-lib/flowy-document/src/services/server/server_api_mock.rs +++ b/rust-lib/flowy-document/src/services/server/server_api_mock.rs @@ -1,7 +1,7 @@ -use crate::{ +use crate::{errors::DocError, services::server::DocumentServerAPI}; +use flowy_document_infra::{ + document_default::doc_initial_string, entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}, - errors::DocError, - services::{doc::doc_initial_string, server::DocumentServerAPI}, }; use flowy_infra::future::ResultFuture; diff --git a/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs b/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs index cefb4dd63a..cc5d15a463 100644 --- a/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs +++ b/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs @@ -1,10 +1,10 @@ use crate::{ - entities::doc::{Revision, RevisionRange}, errors::DocError, sql_tables::{doc::RevTable, RevChangeset, RevState, RevTableType}, }; use diesel::update; use flowy_database::{insert_or_ignore_into, prelude::*, schema::rev_table::dsl, SqliteConnection}; +use flowy_document_infra::entities::doc::{Revision, RevisionRange}; pub struct RevTableSql {} diff --git a/rust-lib/flowy-document/src/sql_tables/doc/rev_table.rs b/rust-lib/flowy-document/src/sql_tables/doc/rev_table.rs index 0bee16913b..accba9b458 100644 --- a/rust-lib/flowy-document/src/sql_tables/doc/rev_table.rs +++ b/rust-lib/flowy-document/src/sql_tables/doc/rev_table.rs @@ -1,9 +1,9 @@ -use crate::{ - entities::doc::{RevId, RevType, Revision}, - services::util::md5, -}; use diesel::sql_types::Integer; use flowy_database::schema::rev_table; +use flowy_document_infra::{ + entities::doc::{RevId, RevType, Revision}, + util::md5, +}; #[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)] #[table_name = "rev_table"] diff --git a/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs b/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs index 71c95981c0..5a826c408a 100644 --- a/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs +++ b/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs @@ -1,14 +1,14 @@ use bytes::Bytes; use flowy_document::{ - errors::DocError, + entities::ws::WsDocumentData, + errors::{internal_error, DocError}, module::DocumentUser, - prelude::{DocumentWebSocket, WsDocumentManager}, + services::ws::WsStateReceiver, }; - -use flowy_document::{entities::ws::WsDocumentData, errors::internal_error, services::ws::WsStateReceiver}; use flowy_user::{errors::ErrorCode, services::user::UserSession}; use flowy_ws::{WsMessage, WsMessageHandler, WsModule}; +use flowy_document::services::ws::{DocumentWebSocket, WsDocumentManager}; use flowy_user::errors::UserError; use std::{path::Path, sync::Arc}; diff --git a/rust-lib/flowy-sdk/src/lib.rs b/rust-lib/flowy-sdk/src/lib.rs index 029fcc3fc1..59a5360884 100644 --- a/rust-lib/flowy-sdk/src/lib.rs +++ b/rust-lib/flowy-sdk/src/lib.rs @@ -4,7 +4,7 @@ pub mod module; use crate::deps_resolve::WorkspaceDepsResolver; use flowy_dispatch::prelude::*; -use flowy_document::prelude::FlowyDocument; +use flowy_document::module::FlowyDocument; use flowy_net::config::ServerConfig; use flowy_user::services::user::{UserSession, UserSessionBuilder, UserStatus}; use flowy_workspace::{errors::WorkspaceError, prelude::WorkspaceController}; diff --git a/rust-lib/flowy-test/Cargo.toml b/rust-lib/flowy-test/Cargo.toml index 4494c5815e..ed8b589fbd 100644 --- a/rust-lib/flowy-test/Cargo.toml +++ b/rust-lib/flowy-test/Cargo.toml @@ -12,6 +12,7 @@ flowy-user = { path = "../flowy-user"} flowy-workspace = { path = "../flowy-workspace", default-features = false} flowy-infra = { path = "../flowy-infra"} flowy-document = { path = "../flowy-document"} +flowy-document-infra = { path = "../flowy-document-infra"} flowy-net = { path = "../flowy-net"} serde = { version = "1.0", features = ["derive"] } diff --git a/rust-lib/flowy-test/src/workspace.rs b/rust-lib/flowy-test/src/workspace.rs index 85a196d7b9..bf171acb61 100644 --- a/rust-lib/flowy-test/src/workspace.rs +++ b/rust-lib/flowy-test/src/workspace.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use flowy_document::entities::doc::Doc; +use flowy_document_infra::entities::doc::Doc; use flowy_workspace::{ entities::{ app::*, diff --git a/rust-lib/flowy-workspace-infra/Cargo.toml b/rust-lib/flowy-workspace-infra/Cargo.toml index 3e432384ae..d8c8459ae1 100644 --- a/rust-lib/flowy-workspace-infra/Cargo.toml +++ b/rust-lib/flowy-workspace-infra/Cargo.toml @@ -14,7 +14,7 @@ strum = "0.21" strum_macros = "0.21" derive_more = {version = "0.99", features = ["display"]} log = "0.4.14" -flowy-document = { path = "../flowy-document" } +flowy-document-infra = { path = "../flowy-document-infra" } uuid = { version = "0.8", features = ["serde", "v4"] } chrono = { version = "0.4" } diff --git a/rust-lib/flowy-workspace-infra/src/entities/view/view_create.rs b/rust-lib/flowy-workspace-infra/src/entities/view/view_create.rs index 2e08d7b23e..e66092de1c 100644 --- a/rust-lib/flowy-workspace-infra/src/entities/view/view_create.rs +++ b/rust-lib/flowy-workspace-infra/src/entities/view/view_create.rs @@ -8,7 +8,7 @@ use crate::{ }, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; -use flowy_document::services::doc::doc_initial_string; +use flowy_document_infra::document_default::doc_initial_string; use std::convert::TryInto; #[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)] diff --git a/rust-lib/flowy-workspace-infra/src/entities/view/view_query.rs b/rust-lib/flowy-workspace-infra/src/entities/view/view_query.rs index cd686d53e5..3bd0c16ee0 100644 --- a/rust-lib/flowy-workspace-infra/src/entities/view/view_query.rs +++ b/rust-lib/flowy-workspace-infra/src/entities/view/view_query.rs @@ -1,6 +1,6 @@ use crate::{errors::ErrorCode, parser::view::ViewId}; use flowy_derive::ProtoBuf; -use flowy_document::entities::doc::DocIdentifier; +use flowy_document_infra::entities::doc::DocIdentifier; use std::convert::TryInto; #[derive(Default, ProtoBuf)] diff --git a/rust-lib/flowy-workspace/Cargo.toml b/rust-lib/flowy-workspace/Cargo.toml index b55b556ab6..0aa724653d 100644 --- a/rust-lib/flowy-workspace/Cargo.toml +++ b/rust-lib/flowy-workspace/Cargo.toml @@ -7,13 +7,14 @@ edition = "2018" [dependencies] flowy-workspace-infra = { path = "../flowy-workspace-infra" } +flowy-document-infra = { path = "../flowy-document-infra" } +flowy-document = { path = "../flowy-document" } flowy-dispatch = { path = "../flowy-dispatch" } flowy-derive = { path = "../flowy-derive" } flowy-database = { path = "../flowy-database" } flowy-sqlite = { path = "../flowy-sqlite" } flowy-infra = { path = "../flowy-infra" } flowy-dart-notify = { path = "../flowy-dart-notify" } -flowy-document = { path = "../flowy-document" } flowy-ot = { path = "../flowy-ot" } flowy-net = { path = "../flowy-net", features = ["flowy_request"] } flowy-backend-api = { path = "../flowy-backend-api"} diff --git a/rust-lib/flowy-workspace/src/handlers/view_handler.rs b/rust-lib/flowy-workspace/src/handlers/view_handler.rs index 71e89864c7..1bfeea3f3d 100644 --- a/rust-lib/flowy-workspace/src/handlers/view_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/view_handler.rs @@ -16,7 +16,7 @@ use crate::{ services::{TrashCan, ViewController}, }; use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit}; -use flowy_document::entities::doc::DocDelta; +use flowy_document_infra::entities::doc::DocDelta; use flowy_workspace_infra::entities::share::{ExportData, ExportParams, ExportRequest}; use std::{convert::TryInto, sync::Arc}; diff --git a/rust-lib/flowy-workspace/src/services/view_controller.rs b/rust-lib/flowy-workspace/src/services/view_controller.rs index a9aedfd5da..8213f09bbf 100644 --- a/rust-lib/flowy-workspace/src/services/view_controller.rs +++ b/rust-lib/flowy-workspace/src/services/view_controller.rs @@ -1,12 +1,7 @@ -use std::{collections::HashSet, sync::Arc}; - -use futures::{FutureExt, StreamExt}; - use flowy_database::SqliteConnection; -use flowy_document::{ - entities::doc::{DocDelta, DocIdentifier}, - module::FlowyDocument, -}; +use flowy_document_infra::entities::doc::{DocDelta, DocIdentifier}; +use futures::{FutureExt, StreamExt}; +use std::{collections::HashSet, sync::Arc}; use crate::{ entities::{ @@ -19,6 +14,7 @@ use crate::{ services::{server::Server, TrashCan, TrashEvent}, sql_tables::view::{ViewTable, ViewTableChangeset, ViewTableSql}, }; +use flowy_document::module::FlowyDocument; use flowy_infra::kv::KV; use flowy_workspace_infra::entities::share::{ExportData, ExportParams};