From 7c6062604948f87ffa3266e0b8a277b3b0b78b9a Mon Sep 17 00:00:00 2001 From: appflowy Date: Fri, 19 Nov 2021 12:18:46 +0800 Subject: [PATCH] [rust]: refactor flowy-document crate --- .../flowy-document-infra/protobuf.dart | 1 + .../ws.pb.dart | 0 .../ws.pbenum.dart | 0 .../ws.pbjson.dart | 0 .../ws.pbserver.dart | 0 .../protobuf/flowy-document/errors.pb.dart | 2 +- .../flowy-document/errors.pbenum.dart | 14 +-- .../flowy-document/errors.pbjson.dart | 10 +- .../lib/protobuf/flowy-document/protobuf.dart | 1 - backend/Cargo.toml | 1 - backend/src/service/doc/edit/edit_doc.rs | 25 ++--- backend/src/service/doc/ws_actor.rs | 3 +- backend/src/service/ws/entities/message.rs | 16 +++ rust-lib/dart-ffi/Cargo.toml | 4 +- .../src/derive_cache/derive_cache.rs | 4 +- rust-lib/flowy-document-infra/Cargo.toml | 9 +- .../src/core}/data.rs | 0 .../src/core}/document.rs | 35 +++--- .../core}/extensions/delete/default_delete.rs | 2 +- .../src/core}/extensions/delete/mod.rs | 0 .../delete/preserve_line_format_merge.rs | 3 +- .../extensions/format/format_at_position.rs | 0 .../src/core}/extensions/format/helper.rs | 2 +- .../src/core}/extensions/format/mod.rs | 0 .../extensions/format/resolve_block_format.rs | 6 +- .../format/resolve_inline_format.rs | 6 +- .../extensions/insert/auto_exit_block.rs | 3 +- .../core}/extensions/insert/auto_format.rs | 3 +- .../core}/extensions/insert/default_insert.rs | 2 +- .../src/core}/extensions/insert/mod.rs | 2 +- .../insert/preserve_block_format.rs | 4 +- .../insert/preserve_inline_format.rs | 6 +- .../insert/reset_format_on_new_line.rs | 3 +- .../src/core}/extensions/mod.rs | 0 .../src/core}/history.rs | 0 .../src/core}/mod.rs | 5 +- .../src/core}/view.rs | 5 +- .../flowy-document-infra/src/entities/mod.rs | 1 + .../src/entities/ws/mod.rs | 0 .../src/entities/ws/ws.rs | 22 ++-- rust-lib/flowy-document-infra/src/errors.rs | 65 ++++++++++++ rust-lib/flowy-document-infra/src/lib.rs | 2 + .../src/protobuf/model/doc.rs | 100 +++++++++--------- .../src/protobuf/model/mod.rs | 3 + .../src/protobuf/model/revision.rs | 76 ++++++------- .../src/protobuf/model/ws.rs | 44 ++++---- .../src/protobuf/proto/doc.proto | 1 + .../src/protobuf/proto/revision.proto | 1 + .../src/protobuf/proto/ws.proto | 1 + rust-lib/flowy-document/Flowy.toml | 2 +- rust-lib/flowy-document/src/entities/mod.rs | 1 - rust-lib/flowy-document/src/errors.rs | 27 ++--- rust-lib/flowy-document/src/lib.rs | 1 - .../src/protobuf/model/errors.rs | 74 +++++-------- .../flowy-document/src/protobuf/model/mod.rs | 3 - .../src/protobuf/proto/errors.proto | 8 +- .../src/services/doc/document/selection.rs | 1 - .../src/services/doc/edit/doc_actor.rs | 32 ++---- .../src/services/doc/edit/edit_doc.rs | 51 ++++----- .../flowy-document/src/services/doc/mod.rs | 12 +-- .../src/services/ws/ws_manager.rs | 4 +- rust-lib/flowy-sdk/Cargo.toml | 1 + .../src/deps_resolve/document_deps.rs | 22 ++-- 63 files changed, 367 insertions(+), 365 deletions(-) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/ws.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/ws.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/ws.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-document => flowy-document-infra}/ws.pbserver.dart (100%) rename rust-lib/{flowy-document/src/services/doc/document => flowy-document-infra/src/core}/data.rs (100%) rename rust-lib/{flowy-document/src/services/doc/document => flowy-document-infra/src/core}/document.rs (89%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/delete/default_delete.rs (89%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/delete/mod.rs (100%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/delete/preserve_line_format_merge.rs (95%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/format/format_at_position.rs (100%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/format/helper.rs (96%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/format/mod.rs (100%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/format/resolve_block_format.rs (93%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/format/resolve_inline_format.rs (90%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/auto_exit_block.rs (94%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/auto_format.rs (96%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/default_insert.rs (96%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/mod.rs (94%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/preserve_block_format.rs (96%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/preserve_inline_format.rs (96%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/insert/reset_format_on_new_line.rs (92%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/extensions/mod.rs (100%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/history.rs (100%) rename rust-lib/{flowy-document/src/services/doc/document => flowy-document-infra/src/core}/mod.rs (51%) rename rust-lib/{flowy-document/src/services/doc => flowy-document-infra/src/core}/view.rs (97%) rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/ws/mod.rs (100%) rename rust-lib/{flowy-document => flowy-document-infra}/src/entities/ws/ws.rs (72%) create mode 100644 rust-lib/flowy-document-infra/src/errors.rs rename rust-lib/{flowy-document => flowy-document-infra}/src/protobuf/model/ws.rs (87%) rename rust-lib/{flowy-document => flowy-document-infra}/src/protobuf/proto/ws.proto (99%) delete mode 100644 rust-lib/flowy-document/src/entities/mod.rs delete mode 100644 rust-lib/flowy-document/src/services/doc/document/selection.rs 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 index 15e066c852..7626c5708b 100644 --- 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 @@ -1,3 +1,4 @@ // Auto-generated, do not edit +export './ws.pb.dart'; export './revision.pb.dart'; export './doc.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/ws.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document-infra/ws.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart index 21b6a811cf..fbb5affe8e 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart @@ -15,7 +15,7 @@ export 'errors.pbenum.dart'; class DocError extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'DocError', createEmptyInstance: create) - ..e(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: ErrorCode.DocIdInvalid, valueOf: ErrorCode.valueOf, enumValues: ErrorCode.values) + ..e(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: ErrorCode.WsConnectError, valueOf: ErrorCode.valueOf, enumValues: ErrorCode.values) ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg') ..hasRequiredFields = false ; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart index ac35cb0b03..5db0e70b47 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart @@ -10,23 +10,15 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; class ErrorCode extends $pb.ProtobufEnum { - static const ErrorCode DocIdInvalid = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocIdInvalid'); + static const ErrorCode WsConnectError = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WsConnectError'); static const ErrorCode DocNotfound = ErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocNotfound'); - static const ErrorCode WsConnectError = ErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WsConnectError'); - static const ErrorCode UndoFail = ErrorCode._(200, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UndoFail'); - static const ErrorCode RedoFail = ErrorCode._(201, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'RedoFail'); - static const ErrorCode OutOfBound = ErrorCode._(202, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'OutOfBound'); - static const ErrorCode DuplicateRevision = ErrorCode._(400, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DuplicateRevision'); + static const ErrorCode DuplicateRevision = ErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DuplicateRevision'); static const ErrorCode UserUnauthorized = ErrorCode._(999, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); static const ErrorCode InternalError = ErrorCode._(1000, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'InternalError'); static const $core.List values = [ - DocIdInvalid, - DocNotfound, WsConnectError, - UndoFail, - RedoFail, - OutOfBound, + DocNotfound, DuplicateRevision, UserUnauthorized, InternalError, diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart index 0af67ef178..d52fcf0bbd 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart @@ -12,20 +12,16 @@ import 'dart:typed_data' as $typed_data; const ErrorCode$json = const { '1': 'ErrorCode', '2': const [ - const {'1': 'DocIdInvalid', '2': 0}, + const {'1': 'WsConnectError', '2': 0}, const {'1': 'DocNotfound', '2': 1}, - const {'1': 'WsConnectError', '2': 10}, - const {'1': 'UndoFail', '2': 200}, - const {'1': 'RedoFail', '2': 201}, - const {'1': 'OutOfBound', '2': 202}, - const {'1': 'DuplicateRevision', '2': 400}, + const {'1': 'DuplicateRevision', '2': 2}, const {'1': 'UserUnauthorized', '2': 999}, const {'1': 'InternalError', '2': 1000}, ], }; /// Descriptor for `ErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSEAoMRG9jSWRJbnZhbGlkEAASDwoLRG9jTm90Zm91bmQQARISCg5Xc0Nvbm5lY3RFcnJvchAKEg0KCFVuZG9GYWlsEMgBEg0KCFJlZG9GYWlsEMkBEg8KCk91dE9mQm91bmQQygESFgoRRHVwbGljYXRlUmV2aXNpb24QkAMSFQoQVXNlclVuYXV0aG9yaXplZBDnBxISCg1JbnRlcm5hbEVycm9yEOgH'); +final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSEgoOV3NDb25uZWN0RXJyb3IQABIPCgtEb2NOb3Rmb3VuZBABEhUKEUR1cGxpY2F0ZVJldmlzaW9uEAISFQoQVXNlclVuYXV0aG9yaXplZBDnBxISCg1JbnRlcm5hbEVycm9yEOgH'); @$core.Deprecated('Use docErrorDescriptor instead') const DocError$json = const { '1': 'DocError', 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 55db94945e..463cec0dc3 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 @@ -1,4 +1,3 @@ // Auto-generated, do not edit -export './ws.pb.dart'; export './observable.pb.dart'; export './errors.pb.dart'; diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 92733666b4..a08fbf7622 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -63,7 +63,6 @@ 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" } flowy-net = { path = "../rust-lib/flowy-net", features = ["http_server"] } diff --git a/backend/src/service/doc/edit/edit_doc.rs b/backend/src/service/doc/edit/edit_doc.rs index a2a241e780..9ea2606354 100644 --- a/backend/src/service/doc/edit/edit_doc.rs +++ b/backend/src/service/doc/edit/edit_doc.rs @@ -1,27 +1,22 @@ use crate::service::{ doc::{edit::edit_actor::EditUser, update_doc}, util::md5, - ws::WsMessageAdaptor, + ws::{entities::Socket, WsMessageAdaptor}, }; use actix_web::web::Data; - -use crate::service::ws::entities::Socket; -use bytes::Bytes; use dashmap::DashMap; -use flowy_document::{ +use flowy_document_infra::{ + core::Document, entities::ws::{WsDataType, WsDocumentData}, - services::doc::Document, + protobuf::{Doc, RevId, RevType, Revision, RevisionRange, UpdateDocParams}, }; -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; use parking_lot::RwLock; use protobuf::Message; use sqlx::PgPool; use std::{ cmp::Ordering, - convert::TryInto, sync::{ atomic::{AtomicI64, Ordering::SeqCst}, Arc, @@ -213,7 +208,7 @@ fn mk_push_message(doc_id: &str, revision: Revision) -> WsMessageAdaptor { ty: WsDataType::PushRev, data: bytes, }; - mk_ws_message(data) + data.into() } #[tracing::instrument(level = "debug", skip(socket, doc_id), err)] @@ -236,7 +231,7 @@ fn mk_pull_message(doc_id: &str, from_rev_id: i64, to_rev_id: i64) -> WsMessageA ty: WsDataType::PullRev, data: bytes, }; - mk_ws_message(data) + data.into() } #[tracing::instrument(level = "debug", skip(socket, revision), err)] @@ -259,13 +254,7 @@ fn mk_acked_message(revision: &Revision) -> WsMessageAdaptor { data, }; - mk_ws_message(data) -} - -fn mk_ws_message>(data: T) -> WsMessageAdaptor { - let msg: WsMessage = data.into(); - let bytes: Bytes = msg.try_into().unwrap(); - WsMessageAdaptor(bytes) + data.into() } #[inline] diff --git a/backend/src/service/doc/ws_actor.rs b/backend/src/service/doc/ws_actor.rs index b2755ab9f4..64f38f4582 100644 --- a/backend/src/service/doc/ws_actor.rs +++ b/backend/src/service/doc/ws_actor.rs @@ -6,8 +6,7 @@ use crate::service::{ use actix_rt::task::spawn_blocking; use actix_web::web::Data; use async_stream::stream; -use flowy_document::protobuf::{WsDataType, WsDocumentData}; -use flowy_document_infra::protobuf::{NewDocUser, Revision}; +use flowy_document_infra::protobuf::{NewDocUser, Revision, WsDataType, WsDocumentData}; use flowy_net::errors::{internal_error, Result as DocResult, ServerError}; use futures::stream::StreamExt; use sqlx::PgPool; diff --git a/backend/src/service/ws/entities/message.rs b/backend/src/service/ws/entities/message.rs index 65c1da0910..d91910a0a6 100644 --- a/backend/src/service/ws/entities/message.rs +++ b/backend/src/service/ws/entities/message.rs @@ -1,5 +1,8 @@ use actix::Message; use bytes::Bytes; +use flowy_document_infra::entities::ws::WsDocumentData; +use flowy_ws::{WsMessage, WsModule}; +use std::convert::TryInto; #[derive(Debug, Message, Clone)] #[rtype(result = "()")] @@ -10,3 +13,16 @@ impl std::ops::Deref for WsMessageAdaptor { fn deref(&self) -> &Self::Target { &self.0 } } + +impl std::convert::From for WsMessageAdaptor { + fn from(data: WsDocumentData) -> Self { + let bytes: Bytes = data.try_into().unwrap(); + let msg = WsMessage { + module: WsModule::Doc, + data: bytes.to_vec(), + }; + + let bytes: Bytes = msg.try_into().unwrap(); + WsMessageAdaptor(bytes) + } +} diff --git a/rust-lib/dart-ffi/Cargo.toml b/rust-lib/dart-ffi/Cargo.toml index 0bcc31f605..773ae957ef 100644 --- a/rust-lib/dart-ffi/Cargo.toml +++ b/rust-lib/dart-ffi/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" [lib] name = "dart_ffi" # this value will change depending on the target os -# default staticlib -crate-type = ["staticlib"] +# default cdylib +crate-type = ["cdylib"] [dependencies] 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 a418579065..90e8b746d1 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -57,6 +57,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "RevId" | "Revision" | "RevisionRange" + | "WsDocumentData" | "KeyValue" | "WorkspaceError" | "WsError" @@ -71,7 +72,6 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "UserProfile" | "UpdateUserRequest" | "UpdateUserParams" - | "WsDocumentData" | "DocError" | "FFIRequest" | "FFIResponse" @@ -83,10 +83,10 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "ExportType" | "ErrorCode" | "RevType" + | "WsDataType" | "WorkspaceEvent" | "WorkspaceNotification" | "WsModule" - | "WsDataType" | "DocObservable" | "FFIStatusCode" | "UserEvent" diff --git a/rust-lib/flowy-document-infra/Cargo.toml b/rust-lib/flowy-document-infra/Cargo.toml index d54831abcb..3b232a56cc 100644 --- a/rust-lib/flowy-document-infra/Cargo.toml +++ b/rust-lib/flowy-document-infra/Cargo.toml @@ -11,4 +11,11 @@ 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 +md5 = "0.7.0" +tokio = {version = "1", features = ["sync"]} +serde = { version = "1.0", features = ["derive"] } +tracing = { version = "0.1", features = ["log"] } +url = "2.2" +strum = "0.21" +strum_macros = "0.21" +chrono = "0.4.19" \ No newline at end of file diff --git a/rust-lib/flowy-document/src/services/doc/document/data.rs b/rust-lib/flowy-document-infra/src/core/data.rs similarity index 100% rename from rust-lib/flowy-document/src/services/doc/document/data.rs rename to rust-lib/flowy-document-infra/src/core/data.rs diff --git a/rust-lib/flowy-document/src/services/doc/document/document.rs b/rust-lib/flowy-document-infra/src/core/document.rs similarity index 89% rename from rust-lib/flowy-document/src/services/doc/document/document.rs rename to rust-lib/flowy-document-infra/src/core/document.rs index 1df8df75e8..fbc99c015f 100644 --- a/rust-lib/flowy-document/src/services/doc/document/document.rs +++ b/rust-lib/flowy-document-infra/src/core/document.rs @@ -1,8 +1,11 @@ use crate::{ - errors::DocError, - services::doc::{view::View, History, UndoResult, RECORD_THRESHOLD}, + core::{ + history::{History, UndoResult}, + view::{View, RECORD_THRESHOLD}, + }, + errors::DocumentError, + user_default::doc_initial_delta, }; -use flowy_document_infra::user_default::doc_initial_delta; use flowy_ot::core::*; use tokio::sync::mpsc; @@ -41,7 +44,7 @@ impl Document { } } - pub fn from_json(json: &str) -> Result { + pub fn from_json(json: &str) -> Result { let delta = Delta::from_json(json)?; Ok(Self::from_delta(delta)) } @@ -67,7 +70,7 @@ impl Document { } } - pub fn compose_delta(&mut self, mut delta: Delta) -> Result<(), DocError> { + pub fn compose_delta(&mut self, mut delta: Delta) -> Result<(), DocumentError> { trim(&mut delta); tracing::trace!("{} compose {}", &self.delta.to_json(), delta.to_json()); let mut composed_delta = self.delta.compose(&delta)?; @@ -97,7 +100,7 @@ impl Document { Ok(()) } - pub fn insert(&mut self, index: usize, data: T) -> Result { + pub fn insert(&mut self, index: usize, data: T) -> Result { let interval = Interval::new(index, index); let _ = validate_interval(&self.delta, &interval)?; @@ -108,7 +111,7 @@ impl Document { Ok(delta) } - pub fn delete(&mut self, interval: Interval) -> Result { + pub fn delete(&mut self, interval: Interval) -> Result { let _ = validate_interval(&self.delta, &interval)?; debug_assert_eq!(interval.is_empty(), false); let delete = self.view.delete(&self.delta, interval)?; @@ -119,7 +122,7 @@ impl Document { Ok(delete) } - pub fn format(&mut self, interval: Interval, attribute: Attribute) -> Result { + pub fn format(&mut self, interval: Interval, attribute: Attribute) -> Result { let _ = validate_interval(&self.delta, &interval)?; tracing::trace!("format with {} at {}", attribute, interval); let format_delta = self.view.format(&self.delta, attribute.clone(), interval).unwrap(); @@ -129,7 +132,7 @@ impl Document { Ok(format_delta) } - pub fn replace(&mut self, interval: Interval, data: T) -> Result { + pub fn replace(&mut self, interval: Interval, data: T) -> Result { let _ = validate_interval(&self.delta, &interval)?; let mut delta = Delta::default(); let text = data.to_string(); @@ -151,9 +154,9 @@ impl Document { pub fn can_redo(&self) -> bool { self.history.can_redo() } - pub fn undo(&mut self) -> Result { + pub fn undo(&mut self) -> Result { match self.history.undo() { - None => Err(DocError::undo().context("Undo stack is empty")), + None => Err(DocumentError::undo().context("Undo stack is empty")), Some(undo_delta) => { let (new_delta, inverted_delta) = self.invert(&undo_delta)?; let result = UndoResult::success(new_delta.target_len as usize); @@ -165,9 +168,9 @@ impl Document { } } - pub fn redo(&mut self) -> Result { + pub fn redo(&mut self) -> Result { match self.history.redo() { - None => Err(DocError::redo()), + None => Err(DocumentError::redo()), Some(redo_delta) => { let (new_delta, inverted_delta) = self.invert(&redo_delta)?; let result = UndoResult::success(new_delta.target_len as usize); @@ -181,7 +184,7 @@ impl Document { } impl Document { - fn invert(&self, delta: &Delta) -> Result<(Delta, Delta), DocError> { + fn invert(&self, delta: &Delta) -> Result<(Delta, Delta), DocumentError> { // c = a.compose(b) // d = b.invert(a) // a = c.compose(d) @@ -192,10 +195,10 @@ impl Document { } } -fn validate_interval(delta: &Delta, interval: &Interval) -> Result<(), DocError> { +fn validate_interval(delta: &Delta, interval: &Interval) -> Result<(), DocumentError> { if delta.target_len < interval.end { log::error!("{:?} out of bounds. should 0..{}", interval, delta.target_len); - return Err(DocError::out_of_bound()); + return Err(DocumentError::out_of_bound()); } Ok(()) } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/delete/default_delete.rs b/rust-lib/flowy-document-infra/src/core/extensions/delete/default_delete.rs similarity index 89% rename from rust-lib/flowy-document/src/services/doc/extensions/delete/default_delete.rs rename to rust-lib/flowy-document-infra/src/core/extensions/delete/default_delete.rs index 3e70893383..2afe1b268a 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/delete/default_delete.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/delete/default_delete.rs @@ -1,4 +1,4 @@ -use crate::services::doc::extensions::DeleteExt; +use crate::core::extensions::DeleteExt; use flowy_ot::core::{Delta, DeltaBuilder, Interval}; pub struct DefaultDelete {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/delete/mod.rs b/rust-lib/flowy-document-infra/src/core/extensions/delete/mod.rs similarity index 100% rename from rust-lib/flowy-document/src/services/doc/extensions/delete/mod.rs rename to rust-lib/flowy-document-infra/src/core/extensions/delete/mod.rs diff --git a/rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs b/rust-lib/flowy-document-infra/src/core/extensions/delete/preserve_line_format_merge.rs similarity index 95% rename from rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs rename to rust-lib/flowy-document-infra/src/core/extensions/delete/preserve_line_format_merge.rs index c538af0f1d..b5a1a7f5d1 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/delete/preserve_line_format_merge.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/delete/preserve_line_format_merge.rs @@ -1,5 +1,4 @@ -use crate::services::doc::extensions::DeleteExt; -use flowy_document_infra::util::is_newline; +use crate::{core::extensions::DeleteExt, util::is_newline}; use flowy_ot::core::{plain_attributes, CharMetric, Delta, DeltaBuilder, DeltaIter, Interval, NEW_LINE}; pub struct PreserveLineFormatOnMerge {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/format_at_position.rs b/rust-lib/flowy-document-infra/src/core/extensions/format/format_at_position.rs similarity index 100% rename from rust-lib/flowy-document/src/services/doc/extensions/format/format_at_position.rs rename to rust-lib/flowy-document-infra/src/core/extensions/format/format_at_position.rs diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs b/rust-lib/flowy-document-infra/src/core/extensions/format/helper.rs similarity index 96% rename from rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs rename to rust-lib/flowy-document-infra/src/core/extensions/format/helper.rs index 27650f5ba5..b99901cabb 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/format/helper.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/format/helper.rs @@ -1,4 +1,4 @@ -use flowy_document_infra::util::find_newline; +use crate::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/mod.rs b/rust-lib/flowy-document-infra/src/core/extensions/format/mod.rs similarity index 100% rename from rust-lib/flowy-document/src/services/doc/extensions/format/mod.rs rename to rust-lib/flowy-document-infra/src/core/extensions/format/mod.rs diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs b/rust-lib/flowy-document-infra/src/core/extensions/format/resolve_block_format.rs similarity index 93% rename from rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs rename to rust-lib/flowy-document-infra/src/core/extensions/format/resolve_block_format.rs index d0eeca57aa..316fed1cfb 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_block_format.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/format/resolve_block_format.rs @@ -1,5 +1,7 @@ -use crate::services::doc::extensions::{format::helper::line_break, FormatExt}; -use flowy_document_infra::util::find_newline; +use crate::{ + core::extensions::{format::helper::line_break, FormatExt}, + util::find_newline, +}; use flowy_ot::core::{plain_attributes, Attribute, AttributeScope, Delta, DeltaBuilder, DeltaIter, Interval}; pub struct ResolveBlockFormat {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs b/rust-lib/flowy-document-infra/src/core/extensions/format/resolve_inline_format.rs similarity index 90% rename from rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs rename to rust-lib/flowy-document-infra/src/core/extensions/format/resolve_inline_format.rs index 3f97d5956a..957a4b2504 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/format/resolve_inline_format.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/format/resolve_inline_format.rs @@ -1,5 +1,7 @@ -use crate::services::doc::extensions::{format::helper::line_break, FormatExt}; -use flowy_document_infra::util::find_newline; +use crate::{ + core::extensions::{format::helper::line_break, FormatExt}, + util::find_newline, +}; use flowy_ot::core::{Attribute, AttributeScope, Delta, DeltaBuilder, DeltaIter, Interval}; pub struct ResolveInlineFormat {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/auto_exit_block.rs similarity index 94% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/auto_exit_block.rs index 71fa518937..6573585bcc 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_exit_block.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/auto_exit_block.rs @@ -1,5 +1,4 @@ -use crate::services::doc::extensions::InsertExt; -use flowy_document_infra::util::is_newline; +use crate::{core::extensions::InsertExt, util::is_newline}; use flowy_ot::core::{attributes_except_header, is_empty_line_at_index, AttributeKey, Delta, DeltaBuilder, DeltaIter}; pub struct AutoExitBlock {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/auto_format.rs similarity index 96% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/auto_format.rs index ebddc864c5..1aa2fcf61d 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/auto_format.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/auto_format.rs @@ -1,5 +1,4 @@ -use crate::services::doc::extensions::InsertExt; -use flowy_document_infra::util::is_whitespace; +use crate::{core::extensions::InsertExt, 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; diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/default_insert.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/default_insert.rs similarity index 96% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/default_insert.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/default_insert.rs index 3638ffd5fb..0d0d732a2c 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/default_insert.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/default_insert.rs @@ -1,4 +1,4 @@ -use crate::services::doc::extensions::InsertExt; +use crate::core::extensions::InsertExt; use flowy_ot::core::{AttributeKey, Attributes, Delta, DeltaBuilder, DeltaIter, NEW_LINE}; pub struct DefaultInsertAttribute {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/mod.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/mod.rs similarity index 94% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/mod.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/mod.rs index e796ba8e97..88e57dde4f 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/mod.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/mod.rs @@ -1,4 +1,4 @@ -use crate::services::doc::extensions::InsertExt; +use crate::core::extensions::InsertExt; pub use auto_exit_block::*; pub use auto_format::*; pub use default_insert::*; diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/preserve_block_format.rs similarity index 96% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/preserve_block_format.rs index 0daf191520..f6dafbdd08 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_block_format.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/preserve_block_format.rs @@ -1,3 +1,4 @@ +use crate::{core::extensions::InsertExt, util::is_newline}; use flowy_ot::core::{ attributes_except_header, plain_attributes, @@ -10,9 +11,6 @@ use flowy_ot::core::{ NEW_LINE, }; -use crate::services::doc::extensions::InsertExt; -use flowy_document_infra::util::is_newline; - pub struct PreserveBlockFormatOnInsert {} impl InsertExt for PreserveBlockFormatOnInsert { fn ext_name(&self) -> &str { std::any::type_name::() } diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/preserve_inline_format.rs similarity index 96% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/preserve_inline_format.rs index b5e6cd881d..8d7b4124d4 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/preserve_inline_format.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/preserve_inline_format.rs @@ -1,5 +1,7 @@ -use crate::services::doc::extensions::InsertExt; -use flowy_document_infra::util::{contain_newline, is_newline}; +use crate::{ + core::extensions::InsertExt, + util::{contain_newline, is_newline}, +}; use flowy_ot::core::{plain_attributes, AttributeKey, Delta, DeltaBuilder, DeltaIter, OpNewline, NEW_LINE}; pub struct PreserveInlineFormat {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs b/rust-lib/flowy-document-infra/src/core/extensions/insert/reset_format_on_new_line.rs similarity index 92% rename from rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs rename to rust-lib/flowy-document-infra/src/core/extensions/insert/reset_format_on_new_line.rs index e29fb96c39..24a86dc770 100644 --- a/rust-lib/flowy-document/src/services/doc/extensions/insert/reset_format_on_new_line.rs +++ b/rust-lib/flowy-document-infra/src/core/extensions/insert/reset_format_on_new_line.rs @@ -1,5 +1,4 @@ -use crate::services::doc::extensions::InsertExt; -use flowy_document_infra::util::is_newline; +use crate::{core::extensions::InsertExt, util::is_newline}; use flowy_ot::core::{AttributeKey, Attributes, CharMetric, Delta, DeltaBuilder, DeltaIter, NEW_LINE}; pub struct ResetLineFormatOnNewLine {} diff --git a/rust-lib/flowy-document/src/services/doc/extensions/mod.rs b/rust-lib/flowy-document-infra/src/core/extensions/mod.rs similarity index 100% rename from rust-lib/flowy-document/src/services/doc/extensions/mod.rs rename to rust-lib/flowy-document-infra/src/core/extensions/mod.rs diff --git a/rust-lib/flowy-document/src/services/doc/history.rs b/rust-lib/flowy-document-infra/src/core/history.rs similarity index 100% rename from rust-lib/flowy-document/src/services/doc/history.rs rename to rust-lib/flowy-document-infra/src/core/history.rs diff --git a/rust-lib/flowy-document/src/services/doc/document/mod.rs b/rust-lib/flowy-document-infra/src/core/mod.rs similarity index 51% rename from rust-lib/flowy-document/src/services/doc/document/mod.rs rename to rust-lib/flowy-document-infra/src/core/mod.rs index 81129f8a5e..5fe385095d 100644 --- a/rust-lib/flowy-document/src/services/doc/document/mod.rs +++ b/rust-lib/flowy-document-infra/src/core/mod.rs @@ -1,6 +1,7 @@ mod data; mod document; -mod selection; +mod extensions; +pub mod history; +mod view; -pub use data::*; pub use document::*; diff --git a/rust-lib/flowy-document/src/services/doc/view.rs b/rust-lib/flowy-document-infra/src/core/view.rs similarity index 97% rename from rust-lib/flowy-document/src/services/doc/view.rs rename to rust-lib/flowy-document-infra/src/core/view.rs index 3ca445bf97..4a1b0fed1b 100644 --- a/rust-lib/flowy-document/src/services/doc/view.rs +++ b/rust-lib/flowy-document-infra/src/core/view.rs @@ -1,7 +1,6 @@ -use super::extensions::*; -use crate::services::doc::trim; +use crate::core::extensions::*; use flowy_ot::{ - core::{Attribute, Delta, Interval}, + core::{trim, Attribute, Delta, Interval}, errors::{ErrorBuilder, OTError, OTErrorCode}, }; diff --git a/rust-lib/flowy-document-infra/src/entities/mod.rs b/rust-lib/flowy-document-infra/src/entities/mod.rs index dc16bd593b..a9963c22fa 100644 --- a/rust-lib/flowy-document-infra/src/entities/mod.rs +++ b/rust-lib/flowy-document-infra/src/entities/mod.rs @@ -1 +1,2 @@ pub mod doc; +pub mod ws; diff --git a/rust-lib/flowy-document/src/entities/ws/mod.rs b/rust-lib/flowy-document-infra/src/entities/ws/mod.rs similarity index 100% rename from rust-lib/flowy-document/src/entities/ws/mod.rs rename to rust-lib/flowy-document-infra/src/entities/ws/mod.rs diff --git a/rust-lib/flowy-document/src/entities/ws/ws.rs b/rust-lib/flowy-document-infra/src/entities/ws/ws.rs similarity index 72% rename from rust-lib/flowy-document/src/entities/ws/ws.rs rename to rust-lib/flowy-document-infra/src/entities/ws/ws.rs index 894b85f815..b332a0f79c 100644 --- a/rust-lib/flowy-document/src/entities/ws/ws.rs +++ b/rust-lib/flowy-document-infra/src/entities/ws/ws.rs @@ -1,8 +1,9 @@ -use crate::errors::DocError; +use crate::{ + entities::doc::{NewDocUser, Revision}, + errors::DocumentError, +}; 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}; #[derive(Debug, Clone, ProtoBuf_Enum, Eq, PartialEq, Hash)] @@ -15,9 +16,9 @@ pub enum WsDataType { } impl WsDataType { - pub fn data(&self, bytes: Bytes) -> Result + pub fn data(&self, bytes: Bytes) -> Result where - T: TryFrom, + T: TryFrom, { T::try_from(bytes) } @@ -63,14 +64,3 @@ impl std::convert::From for WsDocumentData { } } } - -impl std::convert::Into for WsDocumentData { - fn into(self) -> WsMessage { - let bytes: Bytes = self.try_into().unwrap(); - let msg = WsMessage { - module: WsModule::Doc, - data: bytes.to_vec(), - }; - msg - } -} diff --git a/rust-lib/flowy-document-infra/src/errors.rs b/rust-lib/flowy-document-infra/src/errors.rs new file mode 100644 index 0000000000..4c60302e9f --- /dev/null +++ b/rust-lib/flowy-document-infra/src/errors.rs @@ -0,0 +1,65 @@ +use std::{fmt, fmt::Debug}; +use strum_macros::Display; + +macro_rules! static_doc_error { + ($name:ident, $status:expr) => { + #[allow(non_snake_case, missing_docs)] + pub fn $name() -> DocumentError { + DocumentError { + code: $status, + msg: format!("{}", $status), + } + } + }; +} + +pub type DocumentResult = std::result::Result; + +#[derive(Debug, Clone)] +pub struct DocumentError { + pub code: ErrorCode, + pub msg: String, +} + +impl DocumentError { + fn new(code: ErrorCode, msg: &str) -> Self { + Self { + code, + msg: msg.to_owned(), + } + } + + pub fn context(mut self, error: T) -> Self { + self.msg = format!("{:?}", error); + self + } + + static_doc_error!(internal, ErrorCode::InternalError); + static_doc_error!(undo, ErrorCode::UndoFail); + static_doc_error!(redo, ErrorCode::RedoFail); + static_doc_error!(out_of_bound, ErrorCode::OutOfBound); +} + +impl fmt::Display for DocumentError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}: {}", &self.code, &self.msg) } +} + +#[derive(Debug, Clone, Display, PartialEq, Eq)] +pub enum ErrorCode { + DocIdInvalid = 0, + DocNotfound = 1, + UndoFail = 200, + RedoFail = 201, + OutOfBound = 202, + InternalError = 1000, +} + +impl std::convert::From for DocumentError { + fn from(error: flowy_ot::errors::OTError) -> Self { + DocumentError::new(ErrorCode::InternalError, "").context(error) + } +} + +impl std::convert::From for DocumentError { + fn from(e: protobuf::ProtobufError) -> Self { DocumentError::internal().context(e) } +} diff --git a/rust-lib/flowy-document-infra/src/lib.rs b/rust-lib/flowy-document-infra/src/lib.rs index 2ed4beec28..bc082bbaa5 100644 --- a/rust-lib/flowy-document-infra/src/lib.rs +++ b/rust-lib/flowy-document-infra/src/lib.rs @@ -1,4 +1,6 @@ +pub mod core; pub mod entities; +pub mod errors; pub mod protobuf; pub mod user_default; pub mod util; diff --git a/rust-lib/flowy-document-infra/src/protobuf/model/doc.rs b/rust-lib/flowy-document-infra/src/protobuf/model/doc.rs index 3ae789d62c..9144834129 100644 --- a/rust-lib/flowy-document-infra/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\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\ + 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\ "; 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 index 1ffa511c1d..35930ca067 100644 --- a/rust-lib/flowy-document-infra/src/protobuf/model/mod.rs +++ b/rust-lib/flowy-document-infra/src/protobuf/model/mod.rs @@ -1,5 +1,8 @@ // Auto-generated, do not edit +mod ws; +pub use ws::*; + mod revision; pub use revision::*; diff --git a/rust-lib/flowy-document-infra/src/protobuf/model/revision.rs b/rust-lib/flowy-document-infra/src/protobuf/model/revision.rs index f1ff4fbc42..83bd5e7ad0 100644 --- a/rust-lib/flowy-document-infra/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\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\ + \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\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-document/src/protobuf/model/ws.rs b/rust-lib/flowy-document-infra/src/protobuf/model/ws.rs similarity index 87% rename from rust-lib/flowy-document/src/protobuf/model/ws.rs rename to rust-lib/flowy-document-infra/src/protobuf/model/ws.rs index 0b1041993a..8e9387f84e 100644 --- a/rust-lib/flowy-document/src/protobuf/model/ws.rs +++ b/rust-lib/flowy-document-infra/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\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\ + \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\ "; 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/proto/doc.proto b/rust-lib/flowy-document-infra/src/protobuf/proto/doc.proto index 6146091f6b..c7c8ea2c8a 100644 --- a/rust-lib/flowy-document-infra/src/protobuf/proto/doc.proto +++ b/rust-lib/flowy-document-infra/src/protobuf/proto/doc.proto @@ -1,4 +1,5 @@ syntax = "proto3"; + message CreateDocParams { string id = 1; string data = 2; diff --git a/rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto b/rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto index dce0443d8d..44a3137bc1 100644 --- a/rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto +++ b/rust-lib/flowy-document-infra/src/protobuf/proto/revision.proto @@ -1,4 +1,5 @@ syntax = "proto3"; + message RevId { int64 value = 1; } diff --git a/rust-lib/flowy-document/src/protobuf/proto/ws.proto b/rust-lib/flowy-document-infra/src/protobuf/proto/ws.proto similarity index 99% rename from rust-lib/flowy-document/src/protobuf/proto/ws.proto rename to rust-lib/flowy-document-infra/src/protobuf/proto/ws.proto index f6ea1bf329..4c7865fd1b 100644 --- a/rust-lib/flowy-document/src/protobuf/proto/ws.proto +++ b/rust-lib/flowy-document-infra/src/protobuf/proto/ws.proto @@ -1,4 +1,5 @@ syntax = "proto3"; + message WsDocumentData { string doc_id = 1; WsDataType ty = 2; diff --git a/rust-lib/flowy-document/Flowy.toml b/rust-lib/flowy-document/Flowy.toml index a80b9508a5..d55cb31ce9 100644 --- a/rust-lib/flowy-document/Flowy.toml +++ b/rust-lib/flowy-document/Flowy.toml @@ -1,3 +1,3 @@ -proto_crates = ["src/entities", "src/event.rs", "src/errors.rs", "src/notify"] +proto_crates = ["src/event.rs", "src/errors.rs", "src/notify"] event_files = [] \ No newline at end of file diff --git a/rust-lib/flowy-document/src/entities/mod.rs b/rust-lib/flowy-document/src/entities/mod.rs deleted file mode 100644 index 6757c99679..0000000000 --- a/rust-lib/flowy-document/src/entities/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod ws; diff --git a/rust-lib/flowy-document/src/errors.rs b/rust-lib/flowy-document/src/errors.rs index 9adcdb7777..1465f87586 100644 --- a/rust-lib/flowy-document/src/errors.rs +++ b/rust-lib/flowy-document/src/errors.rs @@ -43,14 +43,10 @@ impl DocError { pub fn is_record_not_found(&self) -> bool { self.code == ErrorCode::DocNotfound } - static_doc_error!(id_invalid, ErrorCode::DocIdInvalid); static_doc_error!(internal, ErrorCode::InternalError); - static_doc_error!(record_not_found, ErrorCode::DocNotfound); static_doc_error!(unauthorized, ErrorCode::UserUnauthorized); static_doc_error!(ws, ErrorCode::WsConnectError); - static_doc_error!(undo, ErrorCode::UndoFail); - static_doc_error!(redo, ErrorCode::RedoFail); - static_doc_error!(out_of_bound, ErrorCode::OutOfBound); + static_doc_error!(record_not_found, ErrorCode::DocNotfound); static_doc_error!(duplicate_rev, ErrorCode::DuplicateRevision); } @@ -63,25 +59,14 @@ where #[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] pub enum ErrorCode { - #[display(fmt = "DocIdInvalid")] - DocIdInvalid = 0, + #[display(fmt = "Document websocket error")] + WsConnectError = 0, #[display(fmt = "DocNotfound")] DocNotfound = 1, - #[display(fmt = "Document websocket error")] - WsConnectError = 10, - - #[display(fmt = "Undo failed")] - UndoFail = 200, - #[display(fmt = "Redo failed")] - RedoFail = 201, - - #[display(fmt = "Interval out of bound")] - OutOfBound = 202, - #[display(fmt = "Duplicate revision")] - DuplicateRevision = 400, + DuplicateRevision = 2, #[display(fmt = "UserUnauthorized")] UserUnauthorized = 999, @@ -107,6 +92,10 @@ impl std::convert::From for DocError { fn from(error: flowy_ot::errors::OTError) -> Self { DocError::internal().context(error) } } +impl std::convert::From for DocError { + fn from(error: flowy_document_infra::errors::DocumentError) -> Self { DocError::internal().context(error) } +} + impl std::convert::From for DocError { fn from(error: std::io::Error) -> Self { DocError::internal().context(error) } } diff --git a/rust-lib/flowy-document/src/lib.rs b/rust-lib/flowy-document/src/lib.rs index 01f2a9c66b..def8347dcb 100644 --- a/rust-lib/flowy-document/src/lib.rs +++ b/rust-lib/flowy-document/src/lib.rs @@ -1,6 +1,5 @@ #![feature(vecdeque_binary_search)] -pub mod entities; pub mod errors; pub mod module; mod notify; diff --git a/rust-lib/flowy-document/src/protobuf/model/errors.rs b/rust-lib/flowy-document/src/protobuf/model/errors.rs index c66ce5628b..368ebbb92d 100644 --- a/rust-lib/flowy-document/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-document/src/protobuf/model/errors.rs @@ -51,7 +51,7 @@ impl DocError { self.code } pub fn clear_code(&mut self) { - self.code = ErrorCode::DocIdInvalid; + self.code = ErrorCode::WsConnectError; } // Param is passed by value, moved @@ -113,7 +113,7 @@ impl ::protobuf::Message for DocError { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if self.code != ErrorCode::DocIdInvalid { + if self.code != ErrorCode::WsConnectError { my_size += ::protobuf::rt::enum_size(1, self.code); } if !self.msg.is_empty() { @@ -125,7 +125,7 @@ impl ::protobuf::Message for DocError { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.code != ErrorCode::DocIdInvalid { + if self.code != ErrorCode::WsConnectError { os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?; } if !self.msg.is_empty() { @@ -195,7 +195,7 @@ impl ::protobuf::Message for DocError { impl ::protobuf::Clear for DocError { fn clear(&mut self) { - self.code = ErrorCode::DocIdInvalid; + self.code = ErrorCode::WsConnectError; self.msg.clear(); self.unknown_fields.clear(); } @@ -215,13 +215,9 @@ impl ::protobuf::reflect::ProtobufValue for DocError { #[derive(Clone,PartialEq,Eq,Debug,Hash)] pub enum ErrorCode { - DocIdInvalid = 0, + WsConnectError = 0, DocNotfound = 1, - WsConnectError = 10, - UndoFail = 200, - RedoFail = 201, - OutOfBound = 202, - DuplicateRevision = 400, + DuplicateRevision = 2, UserUnauthorized = 999, InternalError = 1000, } @@ -233,13 +229,9 @@ impl ::protobuf::ProtobufEnum for ErrorCode { fn from_i32(value: i32) -> ::std::option::Option { match value { - 0 => ::std::option::Option::Some(ErrorCode::DocIdInvalid), + 0 => ::std::option::Option::Some(ErrorCode::WsConnectError), 1 => ::std::option::Option::Some(ErrorCode::DocNotfound), - 10 => ::std::option::Option::Some(ErrorCode::WsConnectError), - 200 => ::std::option::Option::Some(ErrorCode::UndoFail), - 201 => ::std::option::Option::Some(ErrorCode::RedoFail), - 202 => ::std::option::Option::Some(ErrorCode::OutOfBound), - 400 => ::std::option::Option::Some(ErrorCode::DuplicateRevision), + 2 => ::std::option::Option::Some(ErrorCode::DuplicateRevision), 999 => ::std::option::Option::Some(ErrorCode::UserUnauthorized), 1000 => ::std::option::Option::Some(ErrorCode::InternalError), _ => ::std::option::Option::None @@ -248,12 +240,8 @@ impl ::protobuf::ProtobufEnum for ErrorCode { fn values() -> &'static [Self] { static values: &'static [ErrorCode] = &[ - ErrorCode::DocIdInvalid, - ErrorCode::DocNotfound, ErrorCode::WsConnectError, - ErrorCode::UndoFail, - ErrorCode::RedoFail, - ErrorCode::OutOfBound, + ErrorCode::DocNotfound, ErrorCode::DuplicateRevision, ErrorCode::UserUnauthorized, ErrorCode::InternalError, @@ -274,7 +262,7 @@ impl ::std::marker::Copy for ErrorCode { impl ::std::default::Default for ErrorCode { fn default() -> Self { - ErrorCode::DocIdInvalid + ErrorCode::WsConnectError } } @@ -286,39 +274,29 @@ impl ::protobuf::reflect::ProtobufValue for ErrorCode { static file_descriptor_proto_data: &'static [u8] = b"\ \n\x0cerrors.proto\"<\n\x08DocError\x12\x1e\n\x04code\x18\x01\x20\x01(\ - \x0e2\n.ErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\ - \xb4\x01\n\tErrorCode\x12\x10\n\x0cDocIdInvalid\x10\0\x12\x0f\n\x0bDocNo\ - tfound\x10\x01\x12\x12\n\x0eWsConnectError\x10\n\x12\r\n\x08UndoFail\x10\ - \xc8\x01\x12\r\n\x08RedoFail\x10\xc9\x01\x12\x0f\n\nOutOfBound\x10\xca\ - \x01\x12\x16\n\x11DuplicateRevision\x10\x90\x03\x12\x15\n\x10UserUnautho\ - rized\x10\xe7\x07\x12\x12\n\rInternalError\x10\xe8\x07J\xa1\x04\n\x06\ - \x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\ + \x0e2\n.ErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*r\ + \n\tErrorCode\x12\x12\n\x0eWsConnectError\x10\0\x12\x0f\n\x0bDocNotfound\ + \x10\x01\x12\x15\n\x11DuplicateRevision\x10\x02\x12\x15\n\x10UserUnautho\ + rized\x10\xe7\x07\x12\x12\n\rInternalError\x10\xe8\x07J\xfd\x02\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\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x10\n\x0b\n\x04\ \x04\0\x02\0\x12\x03\x03\x04\x17\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\ \x04\r\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0e\x12\n\x0c\n\x05\x04\0\ \x02\0\x03\x12\x03\x03\x15\x16\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\ \x13\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\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ - \x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x10\x01\n\n\n\x03\x05\0\x01\ - \x12\x03\x06\x05\x0e\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x15\n\x0c\n\ - \x05\x05\0\x02\0\x01\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x02\x12\ - \x03\x07\x13\x14\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x14\n\x0c\n\ + \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\x0e\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x17\n\x0c\n\ + \x05\x05\0\x02\0\x01\x12\x03\x07\x04\x12\n\x0c\n\x05\x05\0\x02\0\x02\x12\ + \x03\x07\x15\x16\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x14\n\x0c\n\ \x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x0f\n\x0c\n\x05\x05\0\x02\x01\x02\ - \x12\x03\x08\x12\x13\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x18\n\x0c\n\ - \x05\x05\0\x02\x02\x01\x12\x03\t\x04\x12\n\x0c\n\x05\x05\0\x02\x02\x02\ - \x12\x03\t\x15\x17\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x13\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\x12\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\x0c\n\x0c\n\x05\x05\0\x02\x04\x02\ - \x12\x03\x0b\x0f\x12\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\x15\n\x0c\ - \n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x0e\n\x0c\n\x05\x05\0\x02\x05\ - \x02\x12\x03\x0c\x11\x14\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x1c\n\ - \x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x15\n\x0c\n\x05\x05\0\x02\x06\ - \x02\x12\x03\r\x18\x1b\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1b\n\ - \x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x14\n\x0c\n\x05\x05\0\x02\ - \x07\x02\x12\x03\x0e\x17\x1a\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\ - \x19\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x11\n\x0c\n\x05\x05\0\ - \x02\x08\x02\x12\x03\x0f\x14\x18b\x06proto3\ + \x12\x03\x08\x12\x13\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x1a\n\x0c\n\ + \x05\x05\0\x02\x02\x01\x12\x03\t\x04\x15\n\x0c\n\x05\x05\0\x02\x02\x02\ + \x12\x03\t\x18\x19\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1b\n\x0c\n\ + \x05\x05\0\x02\x03\x01\x12\x03\n\x04\x14\n\x0c\n\x05\x05\0\x02\x03\x02\ + \x12\x03\n\x17\x1a\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x19\n\x0c\n\ + \x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x11\n\x0c\n\x05\x05\0\x02\x04\x02\ + \x12\x03\x0b\x14\x18b\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/model/mod.rs b/rust-lib/flowy-document/src/protobuf/model/mod.rs index bd807559e2..2dba0cd565 100644 --- a/rust-lib/flowy-document/src/protobuf/model/mod.rs +++ b/rust-lib/flowy-document/src/protobuf/model/mod.rs @@ -1,8 +1,5 @@ // Auto-generated, do not edit -mod ws; -pub use ws::*; - mod observable; pub use observable::*; diff --git a/rust-lib/flowy-document/src/protobuf/proto/errors.proto b/rust-lib/flowy-document/src/protobuf/proto/errors.proto index 3732cb3073..4712cc16a7 100644 --- a/rust-lib/flowy-document/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-document/src/protobuf/proto/errors.proto @@ -5,13 +5,9 @@ message DocError { string msg = 2; } enum ErrorCode { - DocIdInvalid = 0; + WsConnectError = 0; DocNotfound = 1; - WsConnectError = 10; - UndoFail = 200; - RedoFail = 201; - OutOfBound = 202; - DuplicateRevision = 400; + DuplicateRevision = 2; UserUnauthorized = 999; InternalError = 1000; } diff --git a/rust-lib/flowy-document/src/services/doc/document/selection.rs b/rust-lib/flowy-document/src/services/doc/document/selection.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/rust-lib/flowy-document/src/services/doc/document/selection.rs +++ /dev/null @@ -1 +0,0 @@ - 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 a9fe63212f..e267f522e2 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,10 +1,10 @@ -use crate::{ - errors::DocResult, - services::doc::{Document, UndoResult}, -}; use async_stream::stream; use bytes::Bytes; -use flowy_document_infra::entities::doc::{RevId, Revision}; +use flowy_document_infra::{ + core::{history::UndoResult, Document}, + entities::doc::{RevId, Revision}, + errors::DocumentError, +}; use flowy_ot::core::{Attribute, Delta, Interval, OperationTransformable}; use futures::stream::StreamExt; use std::{convert::TryFrom, sync::Arc}; @@ -46,7 +46,7 @@ impl DocumentActor { .await; } - async fn handle_message(&self, msg: DocumentMsg) -> DocResult<()> { + async fn handle_message(&self, msg: DocumentMsg) -> Result<(), DocumentError> { match msg { DocumentMsg::Delta { delta, ret } => { let result = self.composed_delta(delta).await; @@ -107,7 +107,7 @@ impl DocumentActor { } #[tracing::instrument(level = "debug", skip(self, delta), fields(compose_result), err)] - async fn composed_delta(&self, delta: Delta) -> DocResult<()> { + async fn composed_delta(&self, delta: Delta) -> Result<(), DocumentError> { // tracing::debug!("{:?} thread handle_message", thread::current(),); let mut document = self.document.write().await; tracing::Span::current().record( @@ -122,23 +122,7 @@ impl DocumentActor { } } -// #[tracing::instrument(level = "debug", skip(self, params), err)] -// fn update_doc_on_server(&self, params: UpdateDocParams) -> Result<(), -// DocError> { let token = self.user.token()?; -// let server = self.server.clone(); -// tokio::spawn(async move { -// match server.update_doc(&token, params).await { -// Ok(_) => {}, -// Err(e) => { -// // TODO: retry? -// log::error!("Update doc failed: {}", e); -// }, -// } -// }); -// Ok(()) -// } - -pub type Ret = oneshot::Sender>; +pub type Ret = oneshot::Sender>; pub enum DocumentMsg { Delta { delta: Delta, 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 0d57ee8f70..f067f821cf 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,23 +1,21 @@ use crate::{ - entities::ws::{WsDataType, WsDocumentData}, errors::{internal_error, DocError, DocResult}, module::DocumentUser, services::{ - doc::{ - DocumentActor, - DocumentMsg, - OpenDocAction, - RevisionManager, - RevisionServer, - TransformDeltas, - UndoResult, - }, + doc::{DocumentActor, DocumentMsg, OpenDocAction, RevisionManager, RevisionServer, TransformDeltas}, ws::{DocumentWebSocket, WsDocumentHandler}, }, }; use bytes::Bytes; use flowy_database::ConnectionPool; -use flowy_document_infra::entities::doc::{DocDelta, RevId, RevType, Revision, RevisionRange}; +use flowy_document_infra::{ + core::history::UndoResult, + entities::{ + doc::{DocDelta, RevId, RevType, Revision, RevisionRange}, + ws::{WsDataType, WsDocumentData}, + }, + errors::DocumentResult, +}; use flowy_infra::retry::{ExponentialBackoff, Retry}; use flowy_ot::core::{Attribute, Delta, Interval}; use flowy_ws::WsState; @@ -62,7 +60,7 @@ impl ClientEditDoc { } pub async fn insert(&self, index: usize, data: T) -> Result<(), DocError> { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Insert { index, data: data.to_string(), @@ -75,7 +73,7 @@ impl ClientEditDoc { } pub async fn delete(&self, interval: Interval) -> Result<(), DocError> { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Delete { interval, ret }; let _ = self.document.send(msg); let delta = rx.await.map_err(internal_error)??; @@ -84,7 +82,7 @@ impl ClientEditDoc { } pub async fn format(&self, interval: Interval, attribute: Attribute) -> Result<(), DocError> { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Format { interval, attribute, @@ -97,7 +95,7 @@ impl ClientEditDoc { } pub async fn replace(&mut self, interval: Interval, data: T) -> Result<(), DocError> { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Replace { interval, data: data.to_string(), @@ -124,21 +122,23 @@ impl ClientEditDoc { } pub async fn undo(&self) -> Result { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Undo { ret }; let _ = self.document.send(msg); - rx.await.map_err(internal_error)? + let r = rx.await.map_err(internal_error)??; + Ok(r) } pub async fn redo(&self) -> Result { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Redo { ret }; let _ = self.document.send(msg); - rx.await.map_err(internal_error)? + let r = rx.await.map_err(internal_error)??; + Ok(r) } pub async fn delta(&self) -> DocResult { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Doc { ret }; let _ = self.document.send(msg); let data = rx.await.map_err(internal_error)??; @@ -161,7 +161,7 @@ impl ClientEditDoc { #[tracing::instrument(level = "debug", skip(self, data), err)] pub(crate) async fn composing_local_delta(&self, data: Bytes) -> Result<(), DocError> { let delta = Delta::from_bytes(&data)?; - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Delta { delta: delta.clone(), ret, @@ -175,10 +175,11 @@ impl ClientEditDoc { #[cfg(feature = "flowy_test")] pub async fn doc_json(&self) -> DocResult { - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Doc { ret }; let _ = self.document.send(msg); - rx.await.map_err(internal_error)? + let s = rx.await.map_err(internal_error)??; + Ok(s) } #[tracing::instrument(level = "debug", skip(self))] @@ -201,7 +202,7 @@ impl ClientEditDoc { #[tracing::instrument(level = "debug", skip(self))] async fn handle_push_rev(&self, bytes: Bytes) -> DocResult<()> { // Transform the revision - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let _ = self.document.send(DocumentMsg::RemoteRevision { bytes, ret }); let TransformDeltas { client_prime, @@ -215,7 +216,7 @@ impl ClientEditDoc { } // compose delta - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); let msg = DocumentMsg::Delta { delta: client_prime.clone(), ret, diff --git a/rust-lib/flowy-document/src/services/doc/mod.rs b/rust-lib/flowy-document/src/services/doc/mod.rs index 5fbed23e7f..31583599f1 100644 --- a/rust-lib/flowy-document/src/services/doc/mod.rs +++ b/rust-lib/flowy-document/src/services/doc/mod.rs @@ -1,16 +1,6 @@ -pub use document::*; -pub use history::*; -pub use view::*; - -mod document; -mod history; -mod view; - -pub(crate) mod doc_controller; mod edit; -mod extensions; mod revision; +pub(crate) mod doc_controller; pub use edit::*; - pub(crate) use revision::*; diff --git a/rust-lib/flowy-document/src/services/ws/ws_manager.rs b/rust-lib/flowy-document/src/services/ws/ws_manager.rs index 197e5e87af..61a3a81027 100644 --- a/rust-lib/flowy-document/src/services/ws/ws_manager.rs +++ b/rust-lib/flowy-document/src/services/ws/ws_manager.rs @@ -1,7 +1,7 @@ -use crate::{entities::ws::WsDocumentData, errors::DocError}; +use crate::errors::DocError; use bytes::Bytes; - use dashmap::DashMap; +use flowy_document_infra::entities::ws::WsDocumentData; use flowy_ws::WsState; use std::{convert::TryInto, sync::Arc}; diff --git a/rust-lib/flowy-sdk/Cargo.toml b/rust-lib/flowy-sdk/Cargo.toml index 5607f23867..27b7520fd7 100644 --- a/rust-lib/flowy-sdk/Cargo.toml +++ b/rust-lib/flowy-sdk/Cargo.toml @@ -13,6 +13,7 @@ flowy-infra = { path = "../flowy-infra" } flowy-workspace = { path = "../flowy-workspace", default-features = false } flowy-database = { path = "../flowy-database" } flowy-document = { path = "../flowy-document" } +flowy-document-infra = { path = "../flowy-document-infra" } flowy-ws = { path = "../flowy-ws" } flowy-net = { path = "../flowy-net" } tracing = { version = "0.1" } 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 cee1a8dd38..5c3a16ce48 100644 --- a/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs +++ b/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs @@ -1,17 +1,17 @@ use bytes::Bytes; +use flowy_database::ConnectionPool; use flowy_document::{ - entities::ws::WsDocumentData, errors::{internal_error, DocError}, module::DocumentUser, - services::ws::WsStateReceiver, + services::ws::{DocumentWebSocket, WsDocumentManager, WsStateReceiver}, +}; +use flowy_document_infra::entities::ws::WsDocumentData; +use flowy_user::{ + errors::{ErrorCode, UserError}, + services::user::UserSession, }; -use flowy_user::{errors::ErrorCode, services::user::UserSession}; use flowy_ws::{WsMessage, WsMessageHandler, WsModule}; - -use flowy_database::ConnectionPool; -use flowy_document::services::ws::{DocumentWebSocket, WsDocumentManager}; -use flowy_user::errors::UserError; -use std::{path::Path, sync::Arc}; +use std::{convert::TryInto, path::Path, sync::Arc}; pub struct DocumentDepsResolver { user_session: Arc, @@ -75,7 +75,11 @@ struct WsSenderImpl { impl DocumentWebSocket for WsSenderImpl { fn send(&self, data: WsDocumentData) -> Result<(), DocError> { if cfg!(feature = "http_server") { - let msg: WsMessage = data.into(); + let bytes: Bytes = data.try_into().unwrap(); + let msg = WsMessage { + module: WsModule::Doc, + data: bytes.to_vec(), + }; let sender = self.user.ws_controller.sender().map_err(internal_error)?; sender.send_msg(msg).map_err(internal_error)?; }