Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

Feat/http server adapt (#1754)

Nathan.fooo0d8adaa921d6
diff --git a/frontend/app_flowy/lib/core/network_monitor.dart b/frontend/app_flowy/lib/core/network_monitor.dart
index a354dc68f8..259bb47e4d 100644
--- a/frontend/app_flowy/lib/core/network_monitor.dart
+++ b/frontend/app_flowy/lib/core/network_monitor.dart
@@ -35,21 +35,21 @@ class NetworkListener {
final networkType = () {
switch (result) {
case ConnectivityResult.wifi:
- return NetworkType.Wifi;
+ return NetworkTypePB.Wifi;
case ConnectivityResult.ethernet:
- return NetworkType.Ethernet;
+ return NetworkTypePB.Ethernet;
case ConnectivityResult.mobile:
- return NetworkType.Cell;
+ return NetworkTypePB.Cell;
case ConnectivityResult.bluetooth:
- return NetworkType.Bluetooth;
+ return NetworkTypePB.Bluetooth;
case ConnectivityResult.vpn:
- return NetworkType.VPN;
+ return NetworkTypePB.VPN;
case ConnectivityResult.none:
- return NetworkType.UnknownNetworkType;
+ return NetworkTypePB.Unknown;
}
}();
Log.info("Network type: $networkType");
- final state = NetworkState.create()..ty = networkType;
+ final state = NetworkStatePB.create()..ty = networkType;
NetworkEventUpdateNetworkType(state).send().then((result) {
result.fold(
(l) {},
diff --git a/frontend/app_flowy/lib/user/presentation/splash_screen.dart b/frontend/app_flowy/lib/user/presentation/splash_screen.dart
index b2ad1c8332..6ff452adce 100644
--- a/frontend/app_flowy/lib/user/presentation/splash_screen.dart
+++ b/frontend/app_flowy/lib/user/presentation/splash_screen.dart
@@ -1,6 +1,5 @@
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/code.pb.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -76,7 +75,6 @@ class SplashScreen extends StatelessWidget {
},
(error) async {
Log.error(error);
- assert(error.code == ErrorCode.RecordNotFound.value);
getIt<SplashRoute>().pushWelcomeScreen(context, userProfile);
},
);
diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lock
index 134f37a60b..2dc791c391 100644
--- a/frontend/appflowy_tauri/src-tauri/Cargo.lock
+++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock
@@ -37,16 +37,6 @@ dependencies = [
"memchr",
]
-[[package]]
-name = "allo-isolate"
-version = "0.1.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ed55848be9f41d44c79df6045b680a74a78bc579e0813f7f196cd7928e22fb1"
-dependencies = [
- "atomic",
- "pin-project",
-]
-
[[package]]
name = "alloc-no-stdlib"
version = "2.0.4"
@@ -169,32 +159,12 @@ dependencies = [
"system-deps 6.0.3",
]
-[[package]]
-name = "atomic"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c"
-dependencies = [
- "autocfg",
-]
-
[[package]]
name = "atomic_refcell"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "857253367827bd9d0fd973f0ef15506a96e79e41b0ad7aa691203a4e3214f6c8"
-[[package]]
-name = "atty"
-version = "0.2.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
-dependencies = [
- "hermit-abi 0.1.19",
- "libc",
- "winapi",
-]
-
[[package]]
name = "autocfg"
version = "1.1.0"
@@ -379,12 +349,6 @@ dependencies = [
"syn",
]
-[[package]]
-name = "bytecount"
-version = "0.6.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c"
-
[[package]]
name = "bytemuck"
version = "1.12.3"
@@ -999,6 +963,15 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd5f0c7e4bd266b8ab2550e6238d2e74977c23c15536ac7be45e9c95e2e3fbbb"
+[[package]]
+name = "document-model"
+version = "0.1.0"
+dependencies = [
+ "revision-model",
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "dtoa"
version = "0.4.8"
@@ -1053,19 +1026,6 @@ dependencies = [
"cfg-if",
]
-[[package]]
-name = "env_logger"
-version = "0.8.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
-dependencies = [
- "atty",
- "humantime",
- "log",
- "regex",
- "termcolor",
-]
-
[[package]]
name = "error-chain"
version = "0.12.0"
@@ -1096,6 +1056,16 @@ dependencies = [
"regex",
]
+[[package]]
+name = "fancy-regex"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2"
+dependencies = [
+ "bit-set",
+ "regex",
+]
+
[[package]]
name = "fastrand"
version = "1.8.0"
@@ -1146,13 +1116,63 @@ dependencies = [
"syn",
]
+[[package]]
+name = "flowy-client-network-config"
+version = "0.1.0"
+dependencies = [
+ "config",
+ "serde",
+ "serde-aux",
+ "serde_json",
+]
+
+[[package]]
+name = "flowy-client-sync"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "chrono",
+ "dissimilar",
+ "document-model",
+ "flowy-derive",
+ "flowy-sync",
+ "folder-model",
+ "grid-model",
+ "lib-infra",
+ "lib-ot",
+ "parking_lot",
+ "revision-model",
+ "serde",
+ "serde_json",
+ "strum",
+ "strum_macros",
+ "tokio",
+ "tracing",
+ "url",
+]
+
+[[package]]
+name = "flowy-client-ws"
+version = "0.1.0"
+dependencies = [
+ "futures-util",
+ "lib-infra",
+ "lib-ws",
+ "parking_lot",
+ "serde",
+ "serde_repr",
+ "thiserror",
+ "tokio",
+ "tracing",
+]
+
[[package]]
name = "flowy-codegen"
version = "0.1.0"
dependencies = [
"cmd_lib",
"console",
- "fancy-regex",
+ "fancy-regex 0.10.0",
"flowy-ast",
"itertools",
"lazy_static",
@@ -1175,24 +1195,27 @@ name = "flowy-core"
version = "0.1.0"
dependencies = [
"bytes",
+ "flowy-client-ws",
"flowy-database",
"flowy-document",
+ "flowy-error",
"flowy-folder",
"flowy-grid",
- "flowy-http-model",
"flowy-net",
"flowy-revision",
"flowy-task",
"flowy-user",
"futures-core",
- "grid-rev-model",
+ "grid-model",
"lib-dispatch",
"lib-infra",
"lib-log",
"lib-ws",
"parking_lot",
+ "revision-model",
"tokio",
"tracing",
+ "ws-model",
]
[[package]]
@@ -1235,32 +1258,32 @@ dependencies = [
"dashmap",
"diesel",
"diesel_derives",
+ "document-model",
+ "flowy-client-sync",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error",
- "flowy-http-model",
"flowy-notification",
"flowy-revision",
"flowy-revision-persistence",
- "flowy-sync",
"futures",
"futures-util",
"lib-dispatch",
"lib-infra",
"lib-ot",
"lib-ws",
- "log",
"md5",
"protobuf",
+ "revision-model",
"serde",
"serde_json",
"strum",
"strum_macros",
"tokio",
"tracing",
- "unicode-segmentation",
"url",
+ "ws-model",
]
[[package]]
@@ -1269,15 +1292,17 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bytes",
+ "flowy-client-sync",
+ "flowy-client-ws",
"flowy-codegen",
"flowy-database",
"flowy-derive",
- "flowy-sync",
- "http-flowy",
+ "http-error-code",
"lib-dispatch",
"lib-ot",
"protobuf",
"r2d2",
+ "reqwest",
"serde_json",
"thiserror",
]
@@ -1289,17 +1314,16 @@ dependencies = [
"bytes",
"diesel",
"diesel_derives",
+ "flowy-client-sync",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-document",
"flowy-error",
- "flowy-http-model",
"flowy-notification",
"flowy-revision",
"flowy-revision-persistence",
- "flowy-sync",
- "folder-rev-model",
+ "folder-model",
"futures",
"lazy_static",
"lib-dispatch",
@@ -1309,6 +1333,7 @@ dependencies = [
"parking_lot",
"pin-project",
"protobuf",
+ "revision-model",
"serde",
"serde_json",
"strum",
@@ -1316,6 +1341,7 @@ dependencies = [
"tokio",
"tracing",
"unicode-segmentation",
+ "ws-model",
]
[[package]]
@@ -1330,19 +1356,18 @@ dependencies = [
"crossbeam-utils",
"dashmap",
"diesel",
- "fancy-regex",
+ "fancy-regex 0.10.0",
+ "flowy-client-sync",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error",
- "flowy-http-model",
"flowy-notification",
"flowy-revision",
"flowy-revision-persistence",
- "flowy-sync",
"flowy-task",
"futures",
- "grid-rev-model",
+ "grid-model",
"indexmap",
"lazy_static",
"lib-dispatch",
@@ -1353,6 +1378,7 @@ dependencies = [
"protobuf",
"rayon",
"regex",
+ "revision-model",
"rust_decimal",
"rusty-money",
"serde",
@@ -1365,17 +1391,6 @@ dependencies = [
"url",
]
-[[package]]
-name = "flowy-http-model"
-version = "0.1.0"
-dependencies = [
- "bytes",
- "md5",
- "serde",
- "serde_json",
- "serde_repr",
-]
-
[[package]]
name = "flowy-net"
version = "0.1.0"
@@ -1385,41 +1400,46 @@ dependencies = [
"bytes",
"config",
"dashmap",
+ "document-model",
+ "flowy-client-network-config",
+ "flowy-client-sync",
+ "flowy-client-ws",
"flowy-codegen",
"flowy-derive",
"flowy-document",
"flowy-error",
"flowy-folder",
- "flowy-http-model",
+ "flowy-server-sync",
"flowy-sync",
"flowy-user",
- "folder-rev-model",
+ "folder-model",
"futures-util",
- "http-flowy",
"hyper",
"lazy_static",
"lib-dispatch",
"lib-infra",
"lib-ws",
- "log",
"nanoid",
"parking_lot",
"protobuf",
"reqwest",
+ "revision-model",
"serde",
"serde-aux",
"serde_json",
"strum",
"strum_macros",
+ "thiserror",
"tokio",
"tracing",
+ "user-model",
+ "ws-model",
]
[[package]]
name = "flowy-notification"
version = "0.1.0"
dependencies = [
- "allo-isolate",
"bytes",
"flowy-codegen",
"flowy-derive",
@@ -1438,18 +1458,19 @@ dependencies = [
"bytes",
"dashmap",
"flowy-error",
- "flowy-http-model",
"flowy-revision-persistence",
"futures",
"futures-util",
"lib-infra",
"lib-ws",
+ "revision-model",
"serde",
"serde_json",
"strum",
"strum_macros",
"tokio",
"tracing",
+ "ws-model",
]
[[package]]
@@ -1457,35 +1478,46 @@ name = "flowy-revision-persistence"
version = "0.1.0"
dependencies = [
"flowy-error",
- "flowy-http-model",
+ "revision-model",
]
[[package]]
-name = "flowy-sync"
+name = "flowy-server-sync"
version = "0.1.0"
dependencies = [
"async-stream",
"bytes",
- "chrono",
"dashmap",
- "dissimilar",
- "flowy-derive",
- "flowy-http-model",
- "folder-rev-model",
+ "document-model",
+ "flowy-sync",
+ "folder-model",
"futures",
- "grid-rev-model",
"lib-infra",
"lib-ot",
"log",
+ "revision-model",
+ "serde",
+ "tokio",
+ "tracing",
+ "ws-model",
+]
+
+[[package]]
+name = "flowy-sync"
+version = "0.1.0"
+dependencies = [
+ "document-model",
+ "folder-model",
+ "lib-infra",
+ "lib-ot",
"parking_lot",
- "protobuf",
+ "revision-model",
"serde",
- "serde_json",
"strum",
"strum_macros",
"tokio",
"tracing",
- "url",
+ "ws-model",
]
[[package]]
@@ -1506,7 +1538,6 @@ dependencies = [
"bytes",
"diesel",
"diesel_derives",
- "fancy-regex",
"flowy-codegen",
"flowy-database",
"flowy-derive",
@@ -1525,8 +1556,7 @@ dependencies = [
"strum_macros",
"tokio",
"tracing",
- "unicode-segmentation",
- "validator",
+ "user-model",
]
[[package]]
@@ -1536,17 +1566,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
-name = "folder-rev-model"
+name = "folder-model"
version = "0.1.0"
dependencies = [
- "bytes",
"chrono",
"nanoid",
"serde",
- "serde_json",
"serde_repr",
- "strum",
- "strum_macros",
]
[[package]]
@@ -1931,7 +1957,7 @@ dependencies = [
]
[[package]]
-name = "grid-rev-model"
+name = "grid-model"
version = "0.1.0"
dependencies = [
"bytes",
@@ -2049,15 +2075,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
-[[package]]
-name = "hermit-abi"
-version = "0.1.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "hermit-abi"
version = "0.2.6"
@@ -2104,21 +2121,13 @@ dependencies = [
]
[[package]]
-name = "http-flowy"
+name = "http-error-code"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Server#3012acce300024dda8819d8507c9105af84cd909"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Server?branch=refactor/appflowy_server#1ccd296de8530760d92652dbd9f38f27178059b6"
dependencies = [
- "anyhow",
- "bytes",
- "derive_more",
- "hyper",
- "protobuf",
- "reqwest",
"serde",
- "serde_json",
"serde_repr",
"thiserror",
- "uuid 0.8.2",
]
[[package]]
@@ -2145,12 +2154,6 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
-[[package]]
-name = "humantime"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
-
[[package]]
name = "hyper"
version = "0.14.23"
@@ -2441,24 +2444,19 @@ version = "0.1.0"
dependencies = [
"bincode",
"bytes",
- "dashmap",
"derivative",
"dyn-clone",
- "env_logger",
"futures",
"futures-channel",
"futures-core",
"futures-util",
- "lazy_static",
"log",
"nanoid",
- "paste",
"pin-project",
"protobuf",
"serde",
"serde_json",
"serde_repr",
- "serde_with",
"thread-id",
"tokio",
"tracing",
@@ -2472,6 +2470,7 @@ dependencies = [
"bytes",
"chrono",
"futures-core",
+ "md5",
"pin-project",
"rand 0.8.5",
"tokio",
@@ -2490,7 +2489,6 @@ dependencies = [
"tracing-appender",
"tracing-bunyan-formatter",
"tracing-core",
- "tracing-futures",
"tracing-log",
"tracing-subscriber 0.2.25",
]
@@ -2499,23 +2497,16 @@ dependencies = [
name = "lib-ot"
version = "0.1.0"
dependencies = [
- "anyhow",
- "bytecount",
"bytes",
- "dashmap",
- "derive_more",
"indexmap",
"indextree",
"lazy_static",
"log",
- "md5",
"serde",
"serde_json",
- "serde_repr",
"strum",
"strum_macros",
"thiserror",
- "tokio",
"tracing",
]
@@ -2532,13 +2523,11 @@ dependencies = [
"lib-infra",
"log",
"parking_lot",
- "paste",
"pin-project",
"protobuf",
"serde",
"serde_json",
"serde_repr",
- "strum",
"strum_macros",
"tokio",
"tokio-tungstenite",
@@ -2876,7 +2865,7 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
- "hermit-abi 0.2.6",
+ "hermit-abi",
"libc",
]
@@ -3758,6 +3747,16 @@ dependencies = [
"winreg",
]
+[[package]]
+name = "revision-model"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "md5",
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "rkyv"
version = "0.7.39"
@@ -4865,16 +4864,6 @@ dependencies = [
"valuable",
]
-[[package]]
-name = "tracing-futures"
-version = "0.2.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
-dependencies = [
- "pin-project",
- "tracing",
-]
-
[[package]]
name = "tracing-log"
version = "0.1.3"
@@ -5086,6 +5075,20 @@ dependencies = [
"serde",
]
+[[package]]
+name = "user-model"
+version = "0.1.0"
+dependencies = [
+ "fancy-regex 0.11.0",
+ "lazy_static",
+ "serde",
+ "serde_repr",
+ "thiserror",
+ "tracing",
+ "unicode-segmentation",
+ "validator",
+]
+
[[package]]
name = "utf-8"
version = "0.7.6"
@@ -5097,9 +5100,6 @@ name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
-dependencies = [
- "getrandom 0.2.8",
-]
[[package]]
name = "uuid"
@@ -5112,9 +5112,9 @@ dependencies = [
[[package]]
name = "validator"
-version = "0.15.0"
+version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f07b0a1390e01c0fc35ebb26b28ced33c9a3808f7f9fbe94d3cc01e233bfeed5"
+checksum = "32ad5bf234c7d3ad1042e5252b7eddb2c4669ee23f32c7dd0e9b7705f07ef591"
dependencies = [
"idna 0.2.3",
"lazy_static",
@@ -5586,6 +5586,17 @@ dependencies = [
"windows-implement",
]
+[[package]]
+name = "ws-model"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "revision-model",
+ "serde",
+ "serde_json",
+ "serde_repr",
+]
+
[[package]]
name = "x11"
version = "2.20.1"
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index fd11ff7f9f..915d9cdb89 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -310,12 +310,6 @@ dependencies = [
"syn",
]
-[[package]]
-name = "bytecount"
-version = "0.6.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c"
-
[[package]]
name = "byteorder"
version = "1.4.3"
@@ -386,15 +380,6 @@ dependencies = [
"phf_codegen",
]
-[[package]]
-name = "claim"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "68ad37958d55b29a7088909368968d2fe876a24c203f8441195130f3b15194b9"
-dependencies = [
- "autocfg",
-]
-
[[package]]
name = "claim"
version = "0.5.0"
@@ -676,41 +661,6 @@ dependencies = [
"syn",
]
-[[package]]
-name = "darling"
-version = "0.13.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
-dependencies = [
- "darling_core",
- "darling_macro",
-]
-
-[[package]]
-name = "darling_core"
-version = "0.13.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
-dependencies = [
- "fnv",
- "ident_case",
- "proc-macro2",
- "quote",
- "strsim",
- "syn",
-]
-
-[[package]]
-name = "darling_macro"
-version = "0.13.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
-dependencies = [
- "darling_core",
- "quote",
- "syn",
-]
-
[[package]]
name = "dart-ffi"
version = "0.1.0"
@@ -719,7 +669,6 @@ dependencies = [
"byteorder",
"bytes",
"crossbeam-utils",
- "ffi-support",
"flowy-codegen",
"flowy-core",
"flowy-derive",
@@ -832,6 +781,15 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd5f0c7e4bd266b8ab2550e6238d2e74977c23c15536ac7be45e9c95e2e3fbbb"
+[[package]]
+name = "document-model"
+version = "0.1.0"
+dependencies = [
+ "revision-model",
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "dyn-clone"
version = "1.0.10"
@@ -865,11 +823,8 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
dependencies = [
- "atty",
- "humantime",
"log",
"regex",
- "termcolor",
]
[[package]]
@@ -922,22 +877,22 @@ dependencies = [
]
[[package]]
-name = "fastrand"
-version = "1.8.0"
+name = "fancy-regex"
+version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
+checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2"
dependencies = [
- "instant",
+ "bit-set",
+ "regex",
]
[[package]]
-name = "ffi-support"
-version = "0.4.4"
+name = "fastrand"
+version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "27838c6815cfe9de2d3aeb145ffd19e565f577414b33f3bdbf42fe040e9e0ff6"
+checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
- "lazy_static",
- "log",
+ "instant",
]
[[package]]
@@ -949,13 +904,63 @@ dependencies = [
"syn",
]
+[[package]]
+name = "flowy-client-network-config"
+version = "0.1.0"
+dependencies = [
+ "config",
+ "serde",
+ "serde-aux",
+ "serde_json",
+]
+
+[[package]]
+name = "flowy-client-sync"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "chrono",
+ "dissimilar",
+ "document-model",
+ "flowy-derive",
+ "flowy-sync",
+ "folder-model",
+ "grid-model",
+ "lib-infra",
+ "lib-ot",
+ "parking_lot 0.12.1",
+ "revision-model",
+ "serde",
+ "serde_json",
+ "strum",
+ "strum_macros",
+ "tokio",
+ "tracing",
+ "url",
+]
+
+[[package]]
+name = "flowy-client-ws"
+version = "0.1.0"
+dependencies = [
+ "futures-util",
+ "lib-infra",
+ "lib-ws",
+ "parking_lot 0.12.1",
+ "serde",
+ "serde_repr",
+ "thiserror",
+ "tokio",
+ "tracing",
+]
+
[[package]]
name = "flowy-codegen"
version = "0.1.0"
dependencies = [
"cmd_lib",
"console",
- "fancy-regex",
+ "fancy-regex 0.10.0",
"flowy-ast",
"itertools",
"lazy_static",
@@ -978,24 +983,27 @@ name = "flowy-core"
version = "0.1.0"
dependencies = [
"bytes",
+ "flowy-client-ws",
"flowy-database",
"flowy-document",
+ "flowy-error",
"flowy-folder",
"flowy-grid",
- "flowy-http-model",
"flowy-net",
"flowy-revision",
"flowy-task",
"flowy-user",
"futures-core",
- "grid-rev-model",
+ "grid-model",
"lib-dispatch",
"lib-infra",
"lib-log",
"lib-ws",
"parking_lot 0.12.1",
+ "revision-model",
"tokio",
"tracing",
+ "ws-model",
]
[[package]]
@@ -1046,16 +1054,16 @@ dependencies = [
"derive_more",
"diesel",
"diesel_derives",
+ "document-model",
+ "flowy-client-sync",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-document",
"flowy-error",
- "flowy-http-model",
"flowy-notification",
"flowy-revision",
"flowy-revision-persistence",
- "flowy-sync",
"flowy-test",
"futures",
"futures-util",
@@ -1063,10 +1071,10 @@ dependencies = [
"lib-infra",
"lib-ot",
"lib-ws",
- "log",
"md5",
"protobuf",
"rand 0.8.5",
+ "revision-model",
"serde",
"serde_json",
"strum",
@@ -1076,6 +1084,7 @@ dependencies = [
"tracing-subscriber",
"unicode-segmentation",
"url",
+ "ws-model",
]
[[package]]
@@ -1084,17 +1093,22 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bytes",
+ "flowy-client-sync",
+ "flowy-client-ws",
"flowy-codegen",
"flowy-database",
"flowy-derive",
- "flowy-sync",
- "http-flowy",
+ "http-error-code",
"lib-dispatch",
"lib-ot",
"protobuf",
"r2d2",
+ "reqwest",
+ "serde",
"serde_json",
+ "serde_repr",
"thiserror",
+ "user-model",
]
[[package]]
@@ -1104,19 +1118,18 @@ dependencies = [
"bytes",
"diesel",
"diesel_derives",
+ "flowy-client-sync",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-document",
"flowy-error",
"flowy-folder",
- "flowy-http-model",
"flowy-notification",
"flowy-revision",
"flowy-revision-persistence",
- "flowy-sync",
"flowy-test",
- "folder-rev-model",
+ "folder-model",
"futures",
"lazy_static",
"lib-dispatch",
@@ -1126,6 +1139,7 @@ dependencies = [
"parking_lot 0.12.1",
"pin-project",
"protobuf",
+ "revision-model",
"serde",
"serde_json",
"strum",
@@ -1133,6 +1147,7 @@ dependencies = [
"tokio",
"tracing",
"unicode-segmentation",
+ "ws-model",
]
[[package]]
@@ -1147,21 +1162,20 @@ dependencies = [
"crossbeam-utils",
"dashmap",
"diesel",
- "fancy-regex",
+ "fancy-regex 0.10.0",
+ "flowy-client-sync",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error",
"flowy-grid",
- "flowy-http-model",
"flowy-notification",
"flowy-revision",
"flowy-revision-persistence",
- "flowy-sync",
"flowy-task",
"flowy-test",
"futures",
- "grid-rev-model",
+ "grid-model",
"indexmap",
"lazy_static",
"lib-dispatch",
@@ -1172,6 +1186,7 @@ dependencies = [
"protobuf",
"rayon",
"regex",
+ "revision-model",
"rust_decimal",
"rusty-money",
"serde",
@@ -1184,17 +1199,6 @@ dependencies = [
"url",
]
-[[package]]
-name = "flowy-http-model"
-version = "0.1.0"
-dependencies = [
- "bytes",
- "md5",
- "serde",
- "serde_json",
- "serde_repr",
-]
-
[[package]]
name = "flowy-net"
version = "0.1.0"
@@ -1204,41 +1208,46 @@ dependencies = [
"bytes",
"config",
"dashmap",
+ "document-model",
+ "flowy-client-network-config",
+ "flowy-client-sync",
+ "flowy-client-ws",
"flowy-codegen",
"flowy-derive",
"flowy-document",
"flowy-error",
"flowy-folder",
- "flowy-http-model",
+ "flowy-server-sync",
"flowy-sync",
"flowy-user",
- "folder-rev-model",
+ "folder-model",
"futures-util",
- "http-flowy",
"hyper",
"lazy_static",
"lib-dispatch",
"lib-infra",
"lib-ws",
- "log",
"nanoid",
"parking_lot 0.12.1",
"protobuf",
"reqwest",
+ "revision-model",
"serde",
"serde-aux",
"serde_json",
"strum",
"strum_macros",
+ "thiserror",
"tokio",
"tracing",
+ "user-model",
+ "ws-model",
]
[[package]]
name = "flowy-notification"
version = "0.1.0"
dependencies = [
- "allo-isolate",
"bytes",
"flowy-codegen",
"flowy-derive",
@@ -1257,7 +1266,6 @@ dependencies = [
"bytes",
"dashmap",
"flowy-error",
- "flowy-http-model",
"flowy-revision",
"flowy-revision-persistence",
"futures",
@@ -1266,12 +1274,14 @@ dependencies = [
"lib-ws",
"nanoid",
"parking_lot 0.12.1",
+ "revision-model",
"serde",
"serde_json",
"strum",
"strum_macros",
"tokio",
"tracing",
+ "ws-model",
]
[[package]]
@@ -1279,35 +1289,46 @@ name = "flowy-revision-persistence"
version = "0.1.0"
dependencies = [
"flowy-error",
- "flowy-http-model",
+ "revision-model",
]
[[package]]
-name = "flowy-sync"
+name = "flowy-server-sync"
version = "0.1.0"
dependencies = [
"async-stream",
"bytes",
- "chrono",
"dashmap",
- "dissimilar",
- "flowy-derive",
- "flowy-http-model",
- "folder-rev-model",
+ "document-model",
+ "flowy-sync",
+ "folder-model",
"futures",
- "grid-rev-model",
"lib-infra",
"lib-ot",
"log",
+ "revision-model",
+ "serde",
+ "tokio",
+ "tracing",
+ "ws-model",
+]
+
+[[package]]
+name = "flowy-sync"
+version = "0.1.0"
+dependencies = [
+ "document-model",
+ "folder-model",
+ "lib-infra",
+ "lib-ot",
"parking_lot 0.12.1",
- "protobuf",
+ "revision-model",
"serde",
- "serde_json",
"strum",
"strum_macros",
"tokio",
"tracing",
- "url",
+ "ws-model",
]
[[package]]
@@ -1327,16 +1348,14 @@ dependencies = [
name = "flowy-test"
version = "0.1.0"
dependencies = [
- "bincode",
"bytes",
- "claim 0.4.0",
- "claim 0.5.0",
+ "claim",
"fake",
+ "flowy-client-sync",
"flowy-core",
"flowy-document",
"flowy-folder",
"flowy-net",
- "flowy-sync",
"flowy-user",
"futures",
"futures-util",
@@ -1360,18 +1379,14 @@ name = "flowy-user"
version = "0.1.0"
dependencies = [
"bytes",
- "claim 0.4.0",
"diesel",
"diesel_derives",
- "fake",
- "fancy-regex",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error",
"flowy-notification",
"flowy-test",
- "futures",
"lazy_static",
"lib-dispatch",
"lib-infra",
@@ -1380,19 +1395,13 @@ dependencies = [
"once_cell",
"parking_lot 0.12.1",
"protobuf",
- "quickcheck",
- "quickcheck_macros",
- "rand 0.8.5",
- "rand_core 0.6.4",
"serde",
"serde_json",
- "serial_test",
"strum",
"strum_macros",
"tokio",
"tracing",
- "unicode-segmentation",
- "validator",
+ "user-model",
]
[[package]]
@@ -1402,17 +1411,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
-name = "folder-rev-model"
+name = "folder-model"
version = "0.1.0"
dependencies = [
- "bytes",
"chrono",
"nanoid",
"serde",
- "serde_json",
"serde_repr",
- "strum",
- "strum_macros",
]
[[package]]
@@ -1607,7 +1612,7 @@ dependencies = [
]
[[package]]
-name = "grid-rev-model"
+name = "grid-model"
version = "0.1.0"
dependencies = [
"bytes",
@@ -1711,21 +1716,13 @@ dependencies = [
]
[[package]]
-name = "http-flowy"
+name = "http-error-code"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Server#3012acce300024dda8819d8507c9105af84cd909"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Server?branch=refactor/appflowy_server#1ccd296de8530760d92652dbd9f38f27178059b6"
dependencies = [
- "anyhow",
- "bytes",
- "derive_more",
- "hyper",
- "protobuf",
- "reqwest",
"serde",
- "serde_json",
"serde_repr",
"thiserror",
- "uuid",
]
[[package]]
@@ -1746,12 +1743,6 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
-[[package]]
-name = "humantime"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
-
[[package]]
name = "hyper"
version = "0.14.23"
@@ -1813,12 +1804,6 @@ dependencies = [
"cxx-build",
]
-[[package]]
-name = "ident_case"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
-
[[package]]
name = "idna"
version = "0.2.3"
@@ -1950,24 +1935,19 @@ version = "0.1.0"
dependencies = [
"bincode",
"bytes",
- "dashmap",
"derivative",
"dyn-clone",
- "env_logger",
"futures",
"futures-channel",
"futures-core",
"futures-util",
- "lazy_static",
"log",
"nanoid",
- "paste",
"pin-project",
"protobuf",
"serde",
"serde_json",
"serde_repr",
- "serde_with",
"thread-id",
"tokio",
"tracing",
@@ -1981,6 +1961,7 @@ dependencies = [
"bytes",
"chrono",
"futures-core",
+ "md5",
"pin-project",
"rand 0.8.5",
"tokio",
@@ -1999,7 +1980,6 @@ dependencies = [
"tracing-appender",
"tracing-bunyan-formatter",
"tracing-core",
- "tracing-futures",
"tracing-log",
"tracing-subscriber",
]
@@ -2008,23 +1988,16 @@ dependencies = [
name = "lib-ot"
version = "0.1.0"
dependencies = [
- "anyhow",
- "bytecount",
"bytes",
- "dashmap",
- "derive_more",
"indexmap",
"indextree",
"lazy_static",
"log",
- "md5",
"serde",
"serde_json",
- "serde_repr",
"strum",
"strum_macros",
"thiserror",
- "tokio",
"tracing",
]
@@ -2041,13 +2014,11 @@ dependencies = [
"lib-infra",
"log",
"parking_lot 0.12.1",
- "paste",
"pin-project",
"protobuf",
"serde",
"serde_json",
"serde_repr",
- "strum",
"strum_macros",
"tokio",
"tokio-tungstenite",
@@ -2411,12 +2382,6 @@ dependencies = [
"regex",
]
-[[package]]
-name = "paste"
-version = "1.0.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
-
[[package]]
name = "percent-encoding"
version = "2.2.0"
@@ -3018,6 +2983,16 @@ dependencies = [
"winreg",
]
+[[package]]
+name = "revision-model"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "md5",
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "rkyv"
version = "0.7.39"
@@ -3251,28 +3226,6 @@ dependencies = [
"serde",
]
-[[package]]
-name = "serde_with"
-version = "1.14.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff"
-dependencies = [
- "serde",
- "serde_with_macros",
-]
-
-[[package]]
-name = "serde_with_macros"
-version = "1.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082"
-dependencies = [
- "darling",
- "proc-macro2",
- "quote",
- "syn",
-]
-
[[package]]
name = "serial_test"
version = "0.5.1"
@@ -3389,12 +3342,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
-[[package]]
-name = "strsim"
-version = "0.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
-
[[package]]
name = "strum"
version = "0.21.0"
@@ -3709,16 +3656,6 @@ dependencies = [
"valuable",
]
-[[package]]
-name = "tracing-futures"
-version = "0.2.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
-dependencies = [
- "pin-project",
- "tracing",
-]
-
[[package]]
name = "tracing-log"
version = "0.1.3"
@@ -3917,26 +3854,31 @@ dependencies = [
"percent-encoding",
]
+[[package]]
+name = "user-model"
+version = "0.1.0"
+dependencies = [
+ "fancy-regex 0.11.0",
+ "lazy_static",
+ "serde",
+ "serde_repr",
+ "thiserror",
+ "tracing",
+ "unicode-segmentation",
+ "validator",
+]
+
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
-[[package]]
-name = "uuid"
-version = "0.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
-dependencies = [
- "getrandom 0.2.8",
-]
-
[[package]]
name = "validator"
-version = "0.15.0"
+version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f07b0a1390e01c0fc35ebb26b28ced33c9a3808f7f9fbe94d3cc01e233bfeed5"
+checksum = "32ad5bf234c7d3ad1042e5252b7eddb2c4669ee23f32c7dd0e9b7705f07ef591"
dependencies = [
"idna 0.2.3",
"lazy_static",
@@ -4188,6 +4130,17 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "ws-model"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "revision-model",
+ "serde",
+ "serde_json",
+ "serde_repr",
+]
+
[[package]]
name = "yaml-rust"
version = "0.4.5"
diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml
index 3cf9db4ebe..95ca94fe20 100644
--- a/frontend/rust-lib/Cargo.toml
+++ b/frontend/rust-lib/Cargo.toml
@@ -16,7 +16,7 @@ members = [
"flowy-revision-persistence",
"flowy-grid",
"flowy-task",
- "flowy-sync",
+ "flowy-client-sync",
"flowy-derive",
"flowy-ast",
"flowy-codegen",
diff --git a/frontend/rust-lib/dart-ffi/Cargo.toml b/frontend/rust-lib/dart-ffi/Cargo.toml
index ce861d718a..550cfb7eb0 100644
--- a/frontend/rust-lib/dart-ffi/Cargo.toml
+++ b/frontend/rust-lib/dart-ffi/Cargo.toml
@@ -14,7 +14,6 @@ crate-type = ["staticlib"]
[dependencies]
allo-isolate = { version = "^0.1", features = ["catch-unwind"] }
byteorder = { version = "1.3.4" }
-ffi-support = { version = "0.4.2" }
protobuf = { version = "2.20.0" }
tokio = { version = "1", features = ["rt", "rt-multi-thread"] }
log = "0.4.14"
diff --git a/frontend/rust-lib/flowy-sync/Cargo.toml b/frontend/rust-lib/flowy-client-sync/Cargo.toml
similarity index 65%
rename from frontend/rust-lib/flowy-sync/Cargo.toml
rename to frontend/rust-lib/flowy-client-sync/Cargo.toml
index 442dc2b1c4..abd436bf0f 100644
--- a/frontend/rust-lib/flowy-sync/Cargo.toml
+++ b/frontend/rust-lib/flowy-client-sync/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "flowy-sync"
+name = "flowy-client-sync"
version = "0.1.0"
edition = "2018"
@@ -9,12 +9,12 @@ edition = "2018"
lib-ot = { path = "../../../shared-lib/lib-ot" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
flowy-derive = { path = "../flowy-derive" }
-folder-rev-model = { path = "../../../shared-lib/folder-rev-model" }
-grid-rev-model = { path = "../../../shared-lib/grid-rev-model" }
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
-protobuf = {version = "2.18.0"}
+folder-model = { path = "../../../shared-lib/folder-model" }
+grid-model = { path = "../../../shared-lib/grid-model" }
+revision-model = { path = "../../../shared-lib/revision-model" }
+document-model = { path = "../../../shared-lib/document-model" }
+flowy-sync = { path = "../../../shared-lib/flowy-sync" }
bytes = "1.0"
-log = "0.4.14"
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = {version = "1.0"}
@@ -25,6 +25,3 @@ strum = "0.21"
strum_macros = "0.21"
chrono = "0.4.19"
parking_lot = "0.12.1"
-dashmap = "5"
-futures = "0.3.15"
-async-stream = "0.3.2"
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/document_pad.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/document_pad.rs
similarity index 86%
rename from frontend/rust-lib/flowy-sync/src/client_document/document_pad.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/document_pad.rs
index 1b2bf19c39..efd8c2e926 100644
--- a/frontend/rust-lib/flowy-sync/src/client_document/document_pad.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_document/document_pad.rs
@@ -3,10 +3,10 @@ use crate::{
history::{History, UndoResult},
view::{ViewExtensions, RECORD_THRESHOLD},
},
- errors::CollaborateError,
+ errors::SyncError,
};
use bytes::Bytes;
-use flowy_http_model::util::md5;
+use lib_infra::util::md5;
use lib_ot::text_delta::DeltaTextOperationBuilder;
use lib_ot::{core::*, text_delta::DeltaTextOperations};
use tokio::sync::mpsc;
@@ -57,7 +57,7 @@ impl ClientDocument {
}
}
- pub fn from_json(json: &str) -> Result<Self, CollaborateError> {
+ pub fn from_json(json: &str) -> Result<Self, SyncError> {
let operations = DeltaTextOperations::from_json(json)?;
Ok(Self::from_operations(operations))
}
@@ -99,7 +99,7 @@ impl ClientDocument {
}
}
- pub fn compose_operations(&mut self, operations: DeltaTextOperations) -> Result<(), CollaborateError> {
+ pub fn compose_operations(&mut self, operations: DeltaTextOperations) -> Result<(), SyncError> {
tracing::trace!("{} compose {}", &self.operations.json_str(), operations.json_str());
let composed_operations = self.operations.compose(&operations)?;
let mut undo_operations = operations.invert(&self.operations);
@@ -125,7 +125,7 @@ impl ClientDocument {
Ok(())
}
- pub fn insert<T: ToString>(&mut self, index: usize, data: T) -> Result<DeltaTextOperations, CollaborateError> {
+ pub fn insert<T: ToString>(&mut self, index: usize, data: T) -> Result<DeltaTextOperations, SyncError> {
let text = data.to_string();
let interval = Interval::new(index, index);
validate_interval(&self.operations, &interval)?;
@@ -134,7 +134,7 @@ impl ClientDocument {
Ok(operations)
}
- pub fn delete(&mut self, interval: Interval) -> Result<DeltaTextOperations, CollaborateError> {
+ pub fn delete(&mut self, interval: Interval) -> Result<DeltaTextOperations, SyncError> {
validate_interval(&self.operations, &interval)?;
debug_assert!(!interval.is_empty());
let operations = self.view.delete(&self.operations, interval)?;
@@ -144,11 +144,7 @@ impl ClientDocument {
Ok(operations)
}
- pub fn format(
- &mut self,
- interval: Interval,
- attribute: AttributeEntry,
- ) -> Result<DeltaTextOperations, CollaborateError> {
+ pub fn format(&mut self, interval: Interval, attribute: AttributeEntry) -> Result<DeltaTextOperations, SyncError> {
validate_interval(&self.operations, &interval)?;
tracing::trace!("format {} with {:?}", interval, attribute);
let operations = self.view.format(&self.operations, attribute, interval).unwrap();
@@ -156,11 +152,7 @@ impl ClientDocument {
Ok(operations)
}
- pub fn replace<T: ToString>(
- &mut self,
- interval: Interval,
- data: T,
- ) -> Result<DeltaTextOperations, CollaborateError> {
+ pub fn replace<T: ToString>(&mut self, interval: Interval, data: T) -> Result<DeltaTextOperations, SyncError> {
validate_interval(&self.operations, &interval)?;
let mut operations = DeltaTextOperations::default();
let text = data.to_string();
@@ -185,9 +177,9 @@ impl ClientDocument {
self.history.can_redo()
}
- pub fn undo(&mut self) -> Result<UndoResult, CollaborateError> {
+ pub fn undo(&mut self) -> Result<UndoResult, SyncError> {
match self.history.undo() {
- None => Err(CollaborateError::undo().context("Undo stack is empty")),
+ None => Err(SyncError::undo().context("Undo stack is empty")),
Some(undo_operations) => {
let (new_operations, inverted_operations) = self.invert(&undo_operations)?;
self.set_operations(new_operations);
@@ -199,9 +191,9 @@ impl ClientDocument {
}
}
- pub fn redo(&mut self) -> Result<UndoResult, CollaborateError> {
+ pub fn redo(&mut self) -> Result<UndoResult, SyncError> {
match self.history.redo() {
- None => Err(CollaborateError::redo()),
+ None => Err(SyncError::redo()),
Some(redo_operations) => {
let (new_operations, inverted_operations) = self.invert(&redo_operations)?;
self.set_operations(new_operations);
@@ -223,7 +215,7 @@ impl ClientDocument {
fn invert(
&self,
operations: &DeltaTextOperations,
- ) -> Result<(DeltaTextOperations, DeltaTextOperations), CollaborateError> {
+ ) -> Result<(DeltaTextOperations, DeltaTextOperations), SyncError> {
// c = a.compose(b)
// d = b.invert(a)
// a = c.compose(d)
@@ -233,14 +225,14 @@ impl ClientDocument {
}
}
-fn validate_interval(operations: &DeltaTextOperations, interval: &Interval) -> Result<(), CollaborateError> {
+fn validate_interval(operations: &DeltaTextOperations, interval: &Interval) -> Result<(), SyncError> {
if operations.utf16_target_len < interval.end {
- log::error!(
+ tracing::error!(
"{:?} out of bounds. should 0..{}",
interval,
operations.utf16_target_len
);
- return Err(CollaborateError::out_of_bound());
+ return Err(SyncError::out_of_bound());
}
Ok(())
}
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/default_delete.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/default_delete.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/default_delete.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/default_delete.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/preserve_line_format_merge.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/preserve_line_format_merge.rs
similarity index 95%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/preserve_line_format_merge.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/preserve_line_format_merge.rs
index 2cf75187c3..4511a4a48f 100644
--- a/frontend/rust-lib/flowy-sync/src/client_document/extensions/delete/preserve_line_format_merge.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/delete/preserve_line_format_merge.rs
@@ -32,7 +32,7 @@ impl DeleteExt for PreserveLineFormatOnMerge {
while iter.has_next() {
match iter.next() {
- None => log::error!("op must be not None when has_next() return true"),
+ None => tracing::error!("op must be not None when has_next() return true"),
Some(op) => {
//
match op.get_data().find(NEW_LINE) {
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/format/format_at_position.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/format_at_position.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/format/format_at_position.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/format_at_position.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/format/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/format/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/format/resolve_block_format.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/resolve_block_format.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/format/resolve_block_format.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/resolve_block_format.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/format/resolve_inline_format.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/resolve_inline_format.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/format/resolve_inline_format.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/format/resolve_inline_format.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/helper.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/helper.rs
similarity index 88%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/helper.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/helper.rs
index 4ecb23dcf6..a1c571bc4b 100644
--- a/frontend/rust-lib/flowy-sync/src/client_document/extensions/helper.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/helper.rs
@@ -23,7 +23,7 @@ pub(crate) fn line_break(
new_delta.retain(1, attribute.clone().into());
}
_ => {
- log::error!("Unsupported parser line break for {:?}", scope);
+ tracing::error!("Unsupported parser line break for {:?}", scope);
}
}
@@ -35,7 +35,7 @@ pub(crate) fn line_break(
match scope {
AttributeScope::Inline => new_delta.retain(end - start, attribute.clone().into()),
AttributeScope::Block => new_delta.retain(end - start, empty_attributes()),
- _ => log::error!("Unsupported parser line break for {:?}", scope),
+ _ => tracing::error!("Unsupported parser line break for {:?}", scope),
}
}
new_delta
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/auto_exit_block.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/auto_exit_block.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/auto_exit_block.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/auto_exit_block.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/auto_format.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/auto_format.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/auto_format.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/auto_format.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/default_insert.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/default_insert.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/default_insert.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/default_insert.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/preserve_block_format.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/preserve_block_format.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/preserve_block_format.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/preserve_block_format.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/preserve_inline_format.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/preserve_inline_format.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/preserve_inline_format.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/preserve_inline_format.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/extensions/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/extensions/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/extensions/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/extensions/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/history.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/history.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/history.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/history.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_document/view.rs b/frontend/rust-lib/flowy-client-sync/src/client_document/view.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_document/view.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_document/view.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/builder.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/builder.rs
similarity index 77%
rename from frontend/rust-lib/flowy-sync/src/client_folder/builder.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/builder.rs
index 5098960d64..4cb97a696d 100644
--- a/frontend/rust-lib/flowy-sync/src/client_folder/builder.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_folder/builder.rs
@@ -1,12 +1,11 @@
-use crate::util::make_operations_from_revisions;
+use crate::client_folder::FolderOperations;
use crate::{
client_folder::{default_folder_operations, FolderPad},
- errors::CollaborateResult,
+ errors::SyncResult,
};
-
-use crate::server_folder::FolderOperations;
-use flowy_http_model::revision::Revision;
-use folder_rev_model::{TrashRevision, WorkspaceRevision};
+use flowy_sync::util::make_operations_from_revisions;
+use folder_model::{TrashRevision, WorkspaceRevision};
+use revision_model::Revision;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
@@ -35,7 +34,7 @@ impl FolderPadBuilder {
self
}
- pub(crate) fn build_with_revisions(self, revisions: Vec<Revision>) -> CollaborateResult<FolderPad> {
+ pub(crate) fn build_with_revisions(self, revisions: Vec<Revision>) -> SyncResult<FolderPad> {
let mut operations: FolderOperations = make_operations_from_revisions(revisions)?;
if operations.is_empty() {
operations = default_folder_operations();
@@ -44,7 +43,7 @@ impl FolderPadBuilder {
}
#[allow(dead_code)]
- pub(crate) fn build(self) -> CollaborateResult<FolderPad> {
+ pub(crate) fn build(self) -> SyncResult<FolderPad> {
FolderPad::new(self.workspaces, self.trash)
}
}
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/folder_node.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/folder_node.rs
similarity index 94%
rename from frontend/rust-lib/flowy-sync/src/client_folder/folder_node.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/folder_node.rs
index c52ac01e42..7083c5b17c 100644
--- a/frontend/rust-lib/flowy-sync/src/client_folder/folder_node.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_folder/folder_node.rs
@@ -1,6 +1,6 @@
use crate::client_folder::trash_node::TrashNode;
use crate::client_folder::workspace_node::WorkspaceNode;
-use crate::errors::{CollaborateError, CollaborateResult};
+use crate::errors::{SyncError, SyncResult};
use flowy_derive::Node;
use lib_ot::core::NodeTree;
use lib_ot::core::*;
@@ -78,11 +78,11 @@ impl FolderNodePad {
self.workspaces.push(workspace);
}
- pub fn to_json(&self, pretty: bool) -> CollaborateResult<String> {
+ pub fn to_json(&self, pretty: bool) -> SyncResult<String> {
self.tree
.read()
.to_json(pretty)
- .map_err(|e| CollaborateError::serde().context(e))
+ .map_err(|e| SyncError::serde().context(e))
}
}
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/folder_pad.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/folder_pad.rs
similarity index 88%
rename from frontend/rust-lib/flowy-sync/src/client_folder/folder_pad.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/folder_pad.rs
index ae5a421e5a..5716375996 100644
--- a/frontend/rust-lib/flowy-sync/src/client_folder/folder_pad.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_folder/folder_pad.rs
@@ -1,18 +1,20 @@
-use crate::errors::internal_error;
-use crate::server_folder::{FolderOperations, FolderOperationsBuilder};
+use crate::errors::internal_sync_error;
use crate::util::cal_diff;
use crate::{
client_folder::builder::FolderPadBuilder,
- errors::{CollaborateError, CollaborateResult},
+ errors::{SyncError, SyncResult},
};
-use flowy_http_model::revision::Revision;
-use flowy_http_model::util::md5;
-use folder_rev_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use folder_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use lib_infra::util::md5;
use lib_infra::util::move_vec_element;
use lib_ot::core::*;
+use revision_model::Revision;
use serde::Deserialize;
use std::sync::Arc;
+pub type FolderOperations = DeltaOperations<EmptyAttributes>;
+pub type FolderOperationsBuilder = DeltaOperationBuilder<EmptyAttributes>;
+
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct FolderPad {
folder_rev: FolderRevision,
@@ -20,7 +22,7 @@ pub struct FolderPad {
}
impl FolderPad {
- pub fn new(workspaces: Vec<WorkspaceRevision>, trash: Vec<TrashRevision>) -> CollaborateResult<Self> {
+ pub fn new(workspaces: Vec<WorkspaceRevision>, trash: Vec<TrashRevision>) -> SyncResult<Self> {
let folder_rev = FolderRevision {
workspaces: workspaces.into_iter().map(Arc::new).collect(),
trash: trash.into_iter().map(Arc::new).collect(),
@@ -28,25 +30,25 @@ impl FolderPad {
Self::from_folder_rev(folder_rev)
}
- pub fn from_folder_rev(folder_rev: FolderRevision) -> CollaborateResult<Self> {
+ pub fn from_folder_rev(folder_rev: FolderRevision) -> SyncResult<Self> {
let json = serde_json::to_string(&folder_rev)
- .map_err(|e| CollaborateError::internal().context(format!("Serialize to folder json str failed: {}", e)))?;
+ .map_err(|e| SyncError::internal().context(format!("Serialize to folder json str failed: {}", e)))?;
let operations = FolderOperationsBuilder::new().insert(&json).build();
Ok(Self { folder_rev, operations })
}
- pub fn from_revisions(revisions: Vec<Revision>) -> CollaborateResult<Self> {
+ pub fn from_revisions(revisions: Vec<Revision>) -> SyncResult<Self> {
FolderPadBuilder::new().build_with_revisions(revisions)
}
- pub fn from_operations(operations: FolderOperations) -> CollaborateResult<Self> {
+ pub fn from_operations(operations: FolderOperations) -> SyncResult<Self> {
let content = operations.content()?;
let mut deserializer = serde_json::Deserializer::from_reader(content.as_bytes());
let folder_rev = FolderRevision::deserialize(&mut deserializer).map_err(|e| {
tracing::error!("Deserialize folder from {} failed", content);
- CollaborateError::internal().context(format!("Deserialize operations to folder failed: {}", e))
+ SyncError::internal().context(format!("Deserialize operations to folder failed: {}", e))
})?;
Ok(Self { folder_rev, operations })
@@ -56,7 +58,7 @@ impl FolderPad {
&self.operations
}
- pub fn reset_folder(&mut self, operations: FolderOperations) -> CollaborateResult<String> {
+ pub fn reset_folder(&mut self, operations: FolderOperations) -> SyncResult<String> {
let folder = FolderPad::from_operations(operations)?;
self.folder_rev = folder.folder_rev;
self.operations = folder.operations;
@@ -64,7 +66,7 @@ impl FolderPad {
Ok(self.folder_md5())
}
- pub fn compose_remote_operations(&mut self, operations: FolderOperations) -> CollaborateResult<String> {
+ pub fn compose_remote_operations(&mut self, operations: FolderOperations) -> SyncResult<String> {
let composed_operations = self.operations.compose(&operations)?;
self.reset_folder(composed_operations)
}
@@ -74,7 +76,7 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self, workspace_rev), fields(workspace_name=%workspace_rev.name), err)]
- pub fn create_workspace(&mut self, workspace_rev: WorkspaceRevision) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn create_workspace(&mut self, workspace_rev: WorkspaceRevision) -> SyncResult<Option<FolderChangeset>> {
let workspace = Arc::new(workspace_rev);
if self.folder_rev.workspaces.contains(&workspace) {
tracing::warn!("[RootFolder]: Duplicate workspace");
@@ -92,7 +94,7 @@ impl FolderPad {
workspace_id: &str,
name: Option<String>,
desc: Option<String>,
- ) -> CollaborateResult<Option<FolderChangeset>> {
+ ) -> SyncResult<Option<FolderChangeset>> {
self.with_workspace(workspace_id, |workspace| {
if let Some(name) = name {
workspace.name = name;
@@ -105,7 +107,7 @@ impl FolderPad {
})
}
- pub fn read_workspaces(&self, workspace_id: Option<String>) -> CollaborateResult<Vec<WorkspaceRevision>> {
+ pub fn read_workspaces(&self, workspace_id: Option<String>) -> SyncResult<Vec<WorkspaceRevision>> {
match workspace_id {
None => {
let workspaces = self
@@ -125,15 +127,14 @@ impl FolderPad {
{
Ok(vec![workspace.as_ref().clone()])
} else {
- Err(CollaborateError::record_not_found()
- .context(format!("Can't find workspace with id {}", workspace_id)))
+ Err(SyncError::record_not_found().context(format!("Can't find workspace with id {}", workspace_id)))
}
}
}
}
#[tracing::instrument(level = "trace", skip(self), err)]
- pub fn delete_workspace(&mut self, workspace_id: &str) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn delete_workspace(&mut self, workspace_id: &str) -> SyncResult<Option<FolderChangeset>> {
self.modify_workspaces(|workspaces| {
workspaces.retain(|w| w.id != workspace_id);
Ok(Some(()))
@@ -141,7 +142,7 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self), fields(app_name=%app_rev.name), err)]
- pub fn create_app(&mut self, app_rev: AppRevision) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn create_app(&mut self, app_rev: AppRevision) -> SyncResult<Option<FolderChangeset>> {
let workspace_id = app_rev.workspace_id.clone();
self.with_workspace(&workspace_id, move |workspace| {
if workspace.apps.contains(&app_rev) {
@@ -153,13 +154,13 @@ impl FolderPad {
})
}
- pub fn read_app(&self, app_id: &str) -> CollaborateResult<AppRevision> {
+ pub fn read_app(&self, app_id: &str) -> SyncResult<AppRevision> {
for workspace in &self.folder_rev.workspaces {
if let Some(app) = workspace.apps.iter().find(|app| app.id == app_id) {
return Ok(app.clone());
}
}
- Err(CollaborateError::record_not_found().context(format!("Can't find app with id {}", app_id)))
+ Err(SyncError::record_not_found().context(format!("Can't find app with id {}", app_id)))
}
pub fn update_app(
@@ -167,7 +168,7 @@ impl FolderPad {
app_id: &str,
name: Option<String>,
desc: Option<String>,
- ) -> CollaborateResult<Option<FolderChangeset>> {
+ ) -> SyncResult<Option<FolderChangeset>> {
self.with_app(app_id, move |app| {
if let Some(name) = name {
app.name = name;
@@ -181,7 +182,7 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self), err)]
- pub fn delete_app(&mut self, app_id: &str) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn delete_app(&mut self, app_id: &str) -> SyncResult<Option<FolderChangeset>> {
let app = self.read_app(app_id)?;
self.with_workspace(&app.workspace_id, |workspace| {
workspace.apps.retain(|app| app.id != app_id);
@@ -190,10 +191,12 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self), err)]
- pub fn move_app(&mut self, app_id: &str, from: usize, to: usize) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn move_app(&mut self, app_id: &str, from: usize, to: usize) -> SyncResult<Option<FolderChangeset>> {
let app = self.read_app(app_id)?;
self.with_workspace(&app.workspace_id, |workspace| {
- match move_vec_element(&mut workspace.apps, |app| app.id == app_id, from, to).map_err(internal_error)? {
+ match move_vec_element(&mut workspace.apps, |app| app.id == app_id, from, to)
+ .map_err(internal_sync_error)?
+ {
true => Ok(Some(())),
false => Ok(None),
}
@@ -201,7 +204,7 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self), fields(view_name=%view_rev.name), err)]
- pub fn create_view(&mut self, view_rev: ViewRevision) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn create_view(&mut self, view_rev: ViewRevision) -> SyncResult<Option<FolderChangeset>> {
let app_id = view_rev.app_id.clone();
self.with_app(&app_id, move |app| {
if app.belongings.contains(&view_rev) {
@@ -213,7 +216,7 @@ impl FolderPad {
})
}
- pub fn read_view(&self, view_id: &str) -> CollaborateResult<ViewRevision> {
+ pub fn read_view(&self, view_id: &str) -> SyncResult<ViewRevision> {
for workspace in &self.folder_rev.workspaces {
for app in &(*workspace.apps) {
if let Some(view) = app.belongings.iter().find(|b| b.id == view_id) {
@@ -221,10 +224,10 @@ impl FolderPad {
}
}
}
- Err(CollaborateError::record_not_found().context(format!("Can't find view with id {}", view_id)))
+ Err(SyncError::record_not_found().context(format!("Can't find view with id {}", view_id)))
}
- pub fn read_views(&self, belong_to_id: &str) -> CollaborateResult<Vec<ViewRevision>> {
+ pub fn read_views(&self, belong_to_id: &str) -> SyncResult<Vec<ViewRevision>> {
for workspace in &self.folder_rev.workspaces {
for app in &(*workspace.apps) {
if app.id == belong_to_id {
@@ -241,7 +244,7 @@ impl FolderPad {
name: Option<String>,
desc: Option<String>,
modified_time: i64,
- ) -> CollaborateResult<Option<FolderChangeset>> {
+ ) -> SyncResult<Option<FolderChangeset>> {
let view = self.read_view(view_id)?;
self.with_view(&view.app_id, view_id, |view| {
if let Some(name) = name {
@@ -258,7 +261,7 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self), err)]
- pub fn delete_view(&mut self, app_id: &str, view_id: &str) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn delete_view(&mut self, app_id: &str, view_id: &str) -> SyncResult<Option<FolderChangeset>> {
self.with_app(app_id, |app| {
app.belongings.retain(|view| view.id != view_id);
Ok(Some(()))
@@ -266,17 +269,19 @@ impl FolderPad {
}
#[tracing::instrument(level = "trace", skip(self), err)]
- pub fn move_view(&mut self, view_id: &str, from: usize, to: usize) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn move_view(&mut self, view_id: &str, from: usize, to: usize) -> SyncResult<Option<FolderChangeset>> {
let view = self.read_view(view_id)?;
self.with_app(&view.app_id, |app| {
- match move_vec_element(&mut app.belongings, |view| view.id == view_id, from, to).map_err(internal_error)? {
+ match move_vec_element(&mut app.belongings, |view| view.id == view_id, from, to)
+ .map_err(internal_sync_error)?
+ {
true => Ok(Some(())),
false => Ok(None),
}
})
}
- pub fn create_trash(&mut self, trash: Vec<TrashRevision>) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn create_trash(&mut self, trash: Vec<TrashRevision>) -> SyncResult<Option<FolderChangeset>> {
self.with_trash(|t| {
let mut new_trash = trash.into_iter().map(Arc::new).collect::<Vec<Arc<TrashRevision>>>();
t.append(&mut new_trash);
@@ -285,7 +290,7 @@ impl FolderPad {
})
}
- pub fn read_trash(&self, trash_id: Option<String>) -> CollaborateResult<Vec<TrashRevision>> {
+ pub fn read_trash(&self, trash_id: Option<String>) -> SyncResult<Vec<TrashRevision>> {
match trash_id {
None => Ok(self
.folder_rev
@@ -300,7 +305,7 @@ impl FolderPad {
}
}
- pub fn delete_trash(&mut self, trash_ids: Option<Vec<String>>) -> CollaborateResult<Option<FolderChangeset>> {
+ pub fn delete_trash(&mut self, trash_ids: Option<Vec<String>>) -> SyncResult<Option<FolderChangeset>> {
match trash_ids {
None => self.with_trash(|trash| {
trash.clear();
@@ -317,21 +322,21 @@ impl FolderPad {
md5(&self.operations.json_bytes())
}
- pub fn to_json(&self) -> CollaborateResult<String> {
+ pub fn to_json(&self) -> SyncResult<String> {
make_folder_rev_json_str(&self.folder_rev)
}
}
-pub fn make_folder_rev_json_str(folder_rev: &FolderRevision) -> CollaborateResult<String> {
+pub fn make_folder_rev_json_str(folder_rev: &FolderRevision) -> SyncResult<String> {
let json = serde_json::to_string(folder_rev)
- .map_err(|err| internal_error(format!("Serialize folder to json str failed. {:?}", err)))?;
+ .map_err(|err| internal_sync_error(format!("Serialize folder to json str failed. {:?}", err)))?;
Ok(json)
}
impl FolderPad {
- fn modify_workspaces<F>(&mut self, f: F) -> CollaborateResult<Option<FolderChangeset>>
+ fn modify_workspaces<F>(&mut self, f: F) -> SyncResult<Option<FolderChangeset>>
where
- F: FnOnce(&mut Vec<Arc<WorkspaceRevision>>) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut Vec<Arc<WorkspaceRevision>>) -> SyncResult<Option<()>>,
{
let cloned_self = self.clone();
match f(&mut self.folder_rev.workspaces)? {
@@ -353,9 +358,9 @@ impl FolderPad {
}
}
- fn with_workspace<F>(&mut self, workspace_id: &str, f: F) -> CollaborateResult<Option<FolderChangeset>>
+ fn with_workspace<F>(&mut self, workspace_id: &str, f: F) -> SyncResult<Option<FolderChangeset>>
where
- F: FnOnce(&mut WorkspaceRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut WorkspaceRevision) -> SyncResult<Option<()>>,
{
self.modify_workspaces(|workspaces| {
if let Some(workspace) = workspaces.iter_mut().find(|workspace| workspace_id == workspace.id) {
@@ -367,9 +372,9 @@ impl FolderPad {
})
}
- fn with_trash<F>(&mut self, f: F) -> CollaborateResult<Option<FolderChangeset>>
+ fn with_trash<F>(&mut self, f: F) -> SyncResult<Option<FolderChangeset>>
where
- F: FnOnce(&mut Vec<Arc<TrashRevision>>) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut Vec<Arc<TrashRevision>>) -> SyncResult<Option<()>>,
{
let cloned_self = self.clone();
match f(&mut self.folder_rev.trash)? {
@@ -391,9 +396,9 @@ impl FolderPad {
}
}
- fn with_app<F>(&mut self, app_id: &str, f: F) -> CollaborateResult<Option<FolderChangeset>>
+ fn with_app<F>(&mut self, app_id: &str, f: F) -> SyncResult<Option<FolderChangeset>>
where
- F: FnOnce(&mut AppRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut AppRevision) -> SyncResult<Option<()>>,
{
let workspace_id = match self
.folder_rev
@@ -414,9 +419,9 @@ impl FolderPad {
})
}
- fn with_view<F>(&mut self, belong_to_id: &str, view_id: &str, f: F) -> CollaborateResult<Option<FolderChangeset>>
+ fn with_view<F>(&mut self, belong_to_id: &str, view_id: &str, f: F) -> SyncResult<Option<FolderChangeset>>
where
- F: FnOnce(&mut ViewRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut ViewRevision) -> SyncResult<Option<()>>,
{
self.with_app(belong_to_id, |app| {
match app.belongings.iter_mut().find(|view| view_id == view.id) {
@@ -436,7 +441,7 @@ pub fn default_folder_operations() -> FolderOperations {
.build()
}
-pub fn initial_folder_operations(folder_pad: &FolderPad) -> CollaborateResult<FolderOperations> {
+pub fn initial_folder_operations(folder_pad: &FolderPad) -> SyncResult<FolderOperations> {
let json = folder_pad.to_json()?;
let operations = FolderOperationsBuilder::new().insert(&json).build();
Ok(operations)
@@ -452,9 +457,9 @@ pub struct FolderChangeset {
mod tests {
#![allow(clippy::all)]
use crate::client_folder::folder_pad::FolderPad;
- use crate::server_folder::{FolderOperations, FolderOperationsBuilder};
+ use crate::client_folder::{FolderOperations, FolderOperationsBuilder};
use chrono::Utc;
- use folder_rev_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+ use folder_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
use lib_ot::core::OperationTransform;
use serde::Deserialize;
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_folder/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/trash_node.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/trash_node.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_folder/trash_node.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/trash_node.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/util.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/util.rs
similarity index 96%
rename from frontend/rust-lib/flowy-sync/src/client_folder/util.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/util.rs
index bc1a10c563..bb0e136b1c 100644
--- a/frontend/rust-lib/flowy-sync/src/client_folder/util.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_folder/util.rs
@@ -1,5 +1,5 @@
use crate::client_folder::AtomicNodeTree;
-use crate::errors::CollaborateResult;
+use crate::errors::SyncResult;
use lib_ot::core::{AttributeHashMap, AttributeValue, Changeset, NodeId, NodeOperation};
use std::sync::Arc;
@@ -15,7 +15,7 @@ pub fn set_attributes_str_value(
node_id: &NodeId,
key: &str,
value: String,
-) -> CollaborateResult<()> {
+) -> SyncResult<()> {
let old_attributes = match get_attributes(tree.clone(), node_id) {
None => AttributeHashMap::new(),
Some(attributes) => attributes,
diff --git a/frontend/rust-lib/flowy-sync/src/client_folder/workspace_node.rs b/frontend/rust-lib/flowy-client-sync/src/client_folder/workspace_node.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_folder/workspace_node.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_folder/workspace_node.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_grid/block_revision_pad.rs b/frontend/rust-lib/flowy-client-sync/src/client_grid/block_revision_pad.rs
similarity index 88%
rename from frontend/rust-lib/flowy-sync/src/client_grid/block_revision_pad.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_grid/block_revision_pad.rs
index a2b70de239..47522bacd3 100644
--- a/frontend/rust-lib/flowy-sync/src/client_grid/block_revision_pad.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_grid/block_revision_pad.rs
@@ -1,9 +1,10 @@
-use crate::errors::{CollaborateError, CollaborateResult};
-use crate::util::{cal_diff, make_operations_from_revisions};
-use flowy_http_model::revision::Revision;
-use flowy_http_model::util::md5;
-use grid_rev_model::{gen_block_id, gen_row_id, CellRevision, GridBlockRevision, RowChangeset, RowRevision};
+use crate::errors::{SyncError, SyncResult};
+use crate::util::cal_diff;
+use flowy_sync::util::make_operations_from_revisions;
+use grid_model::{gen_block_id, gen_row_id, CellRevision, GridBlockRevision, RowChangeset, RowRevision};
+use lib_infra::util::md5;
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
+use revision_model::Revision;
use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::Arc;
@@ -44,12 +45,12 @@ impl GridBlockRevisionPad {
}
}
- pub fn from_operations(operations: GridBlockOperations) -> CollaborateResult<Self> {
+ pub fn from_operations(operations: GridBlockOperations) -> SyncResult<Self> {
let s = operations.content()?;
let revision: GridBlockRevision = serde_json::from_str(&s).map_err(|e| {
let msg = format!("Deserialize operations to GridBlockRevision failed: {}", e);
tracing::error!("{}", s);
- CollaborateError::internal().context(msg)
+ SyncError::internal().context(msg)
})?;
Ok(Self {
block: revision,
@@ -57,7 +58,7 @@ impl GridBlockRevisionPad {
})
}
- pub fn from_revisions(_grid_id: &str, revisions: Vec<Revision>) -> CollaborateResult<Self> {
+ pub fn from_revisions(_grid_id: &str, revisions: Vec<Revision>) -> SyncResult<Self> {
let operations: GridBlockOperations = make_operations_from_revisions(revisions)?;
Self::from_operations(operations)
}
@@ -67,7 +68,7 @@ impl GridBlockRevisionPad {
&mut self,
row: RowRevision,
start_row_id: Option<String>,
- ) -> CollaborateResult<Option<GridBlockRevisionChangeset>> {
+ ) -> SyncResult<Option<GridBlockRevisionChangeset>> {
self.modify(|rows| {
if let Some(start_row_id) = start_row_id {
if !start_row_id.is_empty() {
@@ -83,10 +84,7 @@ impl GridBlockRevisionPad {
})
}
- pub fn delete_rows(
- &mut self,
- row_ids: Vec<Cow<'_, String>>,
- ) -> CollaborateResult<Option<GridBlockRevisionChangeset>> {
+ pub fn delete_rows(&mut self, row_ids: Vec<Cow<'_, String>>) -> SyncResult<Option<GridBlockRevisionChangeset>> {
self.modify(|rows| {
rows.retain(|row| !row_ids.contains(&Cow::Borrowed(&row.id)));
Ok(Some(()))
@@ -102,7 +100,7 @@ impl GridBlockRevisionPad {
None
}
- pub fn get_row_revs<T>(&self, row_ids: Option<Vec<Cow<'_, T>>>) -> CollaborateResult<Vec<Arc<RowRevision>>>
+ pub fn get_row_revs<T>(&self, row_ids: Option<Vec<Cow<'_, T>>>) -> SyncResult<Vec<Arc<RowRevision>>>
where
T: AsRef<str> + ToOwned + ?Sized,
{
@@ -137,7 +135,7 @@ impl GridBlockRevisionPad {
&self,
field_id: &str,
row_ids: Option<Vec<Cow<'_, String>>>,
- ) -> CollaborateResult<Vec<CellRevision>> {
+ ) -> SyncResult<Vec<CellRevision>> {
let rows = self.get_row_revs(row_ids)?;
let cell_revs = rows
.iter()
@@ -157,7 +155,7 @@ impl GridBlockRevisionPad {
self.block.rows.iter().position(|row| row.id == row_id)
}
- pub fn update_row(&mut self, changeset: RowChangeset) -> CollaborateResult<Option<GridBlockRevisionChangeset>> {
+ pub fn update_row(&mut self, changeset: RowChangeset) -> SyncResult<Option<GridBlockRevisionChangeset>> {
let row_id = changeset.row_id.clone();
self.modify_row(&row_id, |row| {
let mut is_changed = None;
@@ -182,18 +180,13 @@ impl GridBlockRevisionPad {
})
}
- pub fn move_row(
- &mut self,
- row_id: &str,
- from: usize,
- to: usize,
- ) -> CollaborateResult<Option<GridBlockRevisionChangeset>> {
+ pub fn move_row(&mut self, row_id: &str, from: usize, to: usize) -> SyncResult<Option<GridBlockRevisionChangeset>> {
self.modify(|row_revs| {
if let Some(position) = row_revs.iter().position(|row_rev| row_rev.id == row_id) {
debug_assert_eq!(from, position);
let row_rev = row_revs.remove(position);
if to > row_revs.len() {
- Err(CollaborateError::out_of_bound())
+ Err(SyncError::out_of_bound())
} else {
row_revs.insert(to, row_rev);
Ok(Some(()))
@@ -204,9 +197,9 @@ impl GridBlockRevisionPad {
})
}
- pub fn modify<F>(&mut self, f: F) -> CollaborateResult<Option<GridBlockRevisionChangeset>>
+ pub fn modify<F>(&mut self, f: F) -> SyncResult<Option<GridBlockRevisionChangeset>>
where
- F: for<'a> FnOnce(&'a mut Vec<Arc<RowRevision>>) -> CollaborateResult<Option<()>>,
+ F: for<'a> FnOnce(&'a mut Vec<Arc<RowRevision>>) -> SyncResult<Option<()>>,
{
let cloned_self = self.clone();
match f(&mut self.block.rows)? {
@@ -229,9 +222,9 @@ impl GridBlockRevisionPad {
}
}
- fn modify_row<F>(&mut self, row_id: &str, f: F) -> CollaborateResult<Option<GridBlockRevisionChangeset>>
+ fn modify_row<F>(&mut self, row_id: &str, f: F) -> SyncResult<Option<GridBlockRevisionChangeset>>
where
- F: FnOnce(&mut RowRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut RowRevision) -> SyncResult<Option<()>>,
{
self.modify(|rows| {
if let Some(row_rev) = rows.iter_mut().find(|row_rev| row_id == row_rev.id) {
@@ -243,9 +236,9 @@ impl GridBlockRevisionPad {
})
}
- pub fn revision_json(&self) -> CollaborateResult<String> {
+ pub fn revision_json(&self) -> SyncResult<String> {
serde_json::to_string(&self.block)
- .map_err(|e| CollaborateError::internal().context(format!("serial block to json failed: {}", e)))
+ .map_err(|e| SyncError::internal().context(format!("serial block to json failed: {}", e)))
}
pub fn operations_json_str(&self) -> String {
@@ -289,7 +282,7 @@ impl std::default::Default for GridBlockRevisionPad {
#[cfg(test)]
mod tests {
use crate::client_grid::{GridBlockOperations, GridBlockRevisionPad};
- use grid_rev_model::{RowChangeset, RowRevision};
+ use grid_model::{RowChangeset, RowRevision};
use std::borrow::Cow;
diff --git a/frontend/rust-lib/flowy-sync/src/client_grid/grid_builder.rs b/frontend/rust-lib/flowy-client-sync/src/client_grid/grid_builder.rs
similarity index 87%
rename from frontend/rust-lib/flowy-sync/src/client_grid/grid_builder.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_grid/grid_builder.rs
index 31ac7dfa50..e0bfea5e88 100644
--- a/frontend/rust-lib/flowy-sync/src/client_grid/grid_builder.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_grid/grid_builder.rs
@@ -1,5 +1,5 @@
-use crate::errors::{CollaborateError, CollaborateResult};
-use grid_rev_model::{BuildGridContext, FieldRevision, GridBlockMetaRevision, GridBlockRevision, RowRevision};
+use crate::errors::{SyncError, SyncResult};
+use grid_model::{BuildGridContext, FieldRevision, GridBlockMetaRevision, GridBlockRevision, RowRevision};
use std::sync::Arc;
pub struct GridBuilder {
@@ -57,13 +57,13 @@ impl GridBuilder {
}
#[allow(dead_code)]
-fn check_rows(fields: &[FieldRevision], rows: &[RowRevision]) -> CollaborateResult<()> {
+fn check_rows(fields: &[FieldRevision], rows: &[RowRevision]) -> SyncResult<()> {
let field_ids = fields.iter().map(|field| &field.id).collect::<Vec<&String>>();
for row in rows {
let cell_field_ids = row.cells.keys().into_iter().collect::<Vec<&String>>();
if cell_field_ids != field_ids {
let msg = format!("{:?} contains invalid cells", row);
- return Err(CollaborateError::internal().context(msg));
+ return Err(SyncError::internal().context(msg));
}
}
Ok(())
diff --git a/frontend/rust-lib/flowy-sync/src/client_grid/grid_revision_pad.rs b/frontend/rust-lib/flowy-client-sync/src/client_grid/grid_revision_pad.rs
similarity index 85%
rename from frontend/rust-lib/flowy-sync/src/client_grid/grid_revision_pad.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_grid/grid_revision_pad.rs
index 189b663808..96dc9db3d2 100644
--- a/frontend/rust-lib/flowy-sync/src/client_grid/grid_revision_pad.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_grid/grid_revision_pad.rs
@@ -1,13 +1,14 @@
-use crate::errors::{internal_error, CollaborateError, CollaborateResult};
-use crate::util::{cal_diff, make_operations_from_revisions};
-use flowy_http_model::revision::Revision;
-use flowy_http_model::util::md5;
-use grid_rev_model::{
+use crate::errors::{internal_sync_error, SyncError, SyncResult};
+use crate::util::cal_diff;
+use flowy_sync::util::make_operations_from_revisions;
+use grid_model::{
gen_block_id, gen_grid_id, FieldRevision, FieldTypeRevision, GridBlockMetaRevision, GridBlockMetaRevisionChangeset,
GridRevision,
};
+use lib_infra::util::md5;
use lib_infra::util::move_vec_element;
use lib_ot::core::{DeltaOperationBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
+use revision_model::Revision;
use std::collections::HashMap;
use std::sync::Arc;
@@ -21,7 +22,7 @@ pub struct GridRevisionPad {
}
pub trait JsonDeserializer {
- fn deserialize(&self, type_option_data: Vec<u8>) -> CollaborateResult<String>;
+ fn deserialize(&self, type_option_data: Vec<u8>) -> SyncResult<String>;
}
impl GridRevisionPad {
@@ -50,12 +51,12 @@ impl GridRevisionPad {
(fields, blocks)
}
- pub fn from_operations(operations: GridOperations) -> CollaborateResult<Self> {
+ pub fn from_operations(operations: GridOperations) -> SyncResult<Self> {
let content = operations.content()?;
let grid: GridRevision = serde_json::from_str(&content).map_err(|e| {
let msg = format!("Deserialize operations to grid failed: {}", e);
tracing::error!("{}", msg);
- CollaborateError::internal().context(msg)
+ SyncError::internal().context(msg)
})?;
Ok(Self {
@@ -64,7 +65,7 @@ impl GridRevisionPad {
})
}
- pub fn from_revisions(revisions: Vec<Revision>) -> CollaborateResult<Self> {
+ pub fn from_revisions(revisions: Vec<Revision>) -> SyncResult<Self> {
let operations: GridOperations = make_operations_from_revisions(revisions)?;
Self::from_operations(operations)
}
@@ -74,7 +75,7 @@ impl GridRevisionPad {
&mut self,
new_field_rev: FieldRevision,
start_field_id: Option<String>,
- ) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ ) -> SyncResult<Option<GridRevisionChangeset>> {
self.modify_grid(|grid_meta| {
// Check if the field exists or not
if grid_meta
@@ -99,13 +100,13 @@ impl GridRevisionPad {
})
}
- pub fn delete_field_rev(&mut self, field_id: &str) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ pub fn delete_field_rev(&mut self, field_id: &str) -> SyncResult<Option<GridRevisionChangeset>> {
self.modify_grid(
|grid_meta| match grid_meta.fields.iter().position(|field| field.id == field_id) {
None => Ok(None),
Some(index) => {
if grid_meta.fields[index].is_primary {
- Err(CollaborateError::can_not_delete_primary_field())
+ Err(SyncError::can_not_delete_primary_field())
} else {
grid_meta.fields.remove(index);
Ok(Some(()))
@@ -119,7 +120,7 @@ impl GridRevisionPad {
&mut self,
field_id: &str,
duplicated_field_id: &str,
- ) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ ) -> SyncResult<Option<GridRevisionChangeset>> {
self.modify_grid(
|grid_meta| match grid_meta.fields.iter().position(|field| field.id == field_id) {
None => Ok(None),
@@ -150,7 +151,7 @@ impl GridRevisionPad {
new_field_type: T,
make_default_type_option: DT,
type_option_transform: TT,
- ) -> CollaborateResult<Option<GridRevisionChangeset>>
+ ) -> SyncResult<Option<GridRevisionChangeset>>
where
DT: FnOnce() -> String,
TT: FnOnce(FieldTypeRevision, Option<String>, String) -> String,
@@ -194,10 +195,7 @@ impl GridRevisionPad {
})
}
- pub fn replace_field_rev(
- &mut self,
- field_rev: Arc<FieldRevision>,
- ) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ pub fn replace_field_rev(&mut self, field_rev: Arc<FieldRevision>) -> SyncResult<Option<GridRevisionChangeset>> {
self.modify_grid(
|grid_meta| match grid_meta.fields.iter().position(|field| field.id == field_rev.id) {
None => Ok(None),
@@ -215,7 +213,7 @@ impl GridRevisionPad {
field_id: &str,
from_index: usize,
to_index: usize,
- ) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ ) -> SyncResult<Option<GridRevisionChangeset>> {
self.modify_grid(|grid_meta| {
match move_vec_element(
&mut grid_meta.fields,
@@ -223,7 +221,7 @@ impl GridRevisionPad {
from_index,
to_index,
)
- .map_err(internal_error)?
+ .map_err(internal_sync_error)?
{
true => Ok(Some(())),
false => Ok(None),
@@ -243,7 +241,7 @@ impl GridRevisionPad {
.find(|(_, field)| field.id == field_id)
}
- pub fn get_field_revs(&self, field_ids: Option<Vec<String>>) -> CollaborateResult<Vec<Arc<FieldRevision>>> {
+ pub fn get_field_revs(&self, field_ids: Option<Vec<String>>) -> SyncResult<Vec<Arc<FieldRevision>>> {
match field_ids {
None => Ok(self.grid_rev.fields.clone()),
Some(field_ids) => {
@@ -269,10 +267,7 @@ impl GridRevisionPad {
}
}
- pub fn create_block_meta_rev(
- &mut self,
- block: GridBlockMetaRevision,
- ) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ pub fn create_block_meta_rev(&mut self, block: GridBlockMetaRevision) -> SyncResult<Option<GridRevisionChangeset>> {
self.modify_grid(|grid_meta| {
if grid_meta.blocks.iter().any(|b| b.block_id == block.block_id) {
tracing::warn!("Duplicate grid block");
@@ -285,7 +280,7 @@ impl GridRevisionPad {
&& last_block.len() > block.start_row_index
{
let msg = "GridBlock's start_row_index should be greater than the last_block's start_row_index and its len".to_string();
- return Err(CollaborateError::internal().context(msg))
+ return Err(SyncError::internal().context(msg))
}
grid_meta.blocks.push(Arc::new(block));
}
@@ -302,7 +297,7 @@ impl GridRevisionPad {
pub fn update_block_rev(
&mut self,
changeset: GridBlockMetaRevisionChangeset,
- ) -> CollaborateResult<Option<GridRevisionChangeset>> {
+ ) -> SyncResult<Option<GridRevisionChangeset>> {
let block_id = changeset.block_id.clone();
self.modify_block(&block_id, |block| {
let mut is_changed = None;
@@ -333,9 +328,9 @@ impl GridRevisionPad {
&self.grid_rev.fields
}
- fn modify_grid<F>(&mut self, f: F) -> CollaborateResult<Option<GridRevisionChangeset>>
+ fn modify_grid<F>(&mut self, f: F) -> SyncResult<Option<GridRevisionChangeset>>
where
- F: FnOnce(&mut GridRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut GridRevision) -> SyncResult<Option<()>>,
{
let cloned_grid = self.grid_rev.clone();
match f(Arc::make_mut(&mut self.grid_rev))? {
@@ -357,9 +352,9 @@ impl GridRevisionPad {
}
}
- fn modify_block<F>(&mut self, block_id: &str, f: F) -> CollaborateResult<Option<GridRevisionChangeset>>
+ fn modify_block<F>(&mut self, block_id: &str, f: F) -> SyncResult<Option<GridRevisionChangeset>>
where
- F: FnOnce(&mut GridBlockMetaRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut GridBlockMetaRevision) -> SyncResult<Option<()>>,
{
self.modify_grid(
|grid_rev| match grid_rev.blocks.iter().position(|block| block.block_id == block_id) {
@@ -375,9 +370,9 @@ impl GridRevisionPad {
)
}
- pub fn modify_field<F>(&mut self, field_id: &str, f: F) -> CollaborateResult<Option<GridRevisionChangeset>>
+ pub fn modify_field<F>(&mut self, field_id: &str, f: F) -> SyncResult<Option<GridRevisionChangeset>>
where
- F: FnOnce(&mut FieldRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut FieldRevision) -> SyncResult<Option<()>>,
{
self.modify_grid(
|grid_rev| match grid_rev.fields.iter().position(|field| field.id == field_id) {
@@ -393,14 +388,14 @@ impl GridRevisionPad {
)
}
- pub fn json_str(&self) -> CollaborateResult<String> {
+ pub fn json_str(&self) -> SyncResult<String> {
make_grid_rev_json_str(&self.grid_rev)
}
}
-pub fn make_grid_rev_json_str(grid_revision: &GridRevision) -> CollaborateResult<String> {
+pub fn make_grid_rev_json_str(grid_revision: &GridRevision) -> SyncResult<String> {
let json = serde_json::to_string(grid_revision)
- .map_err(|err| internal_error(format!("Serialize grid to json str failed. {:?}", err)))?;
+ .map_err(|err| internal_sync_error(format!("Serialize grid to json str failed. {:?}", err)))?;
Ok(json)
}
diff --git a/frontend/rust-lib/flowy-sync/src/client_grid/mod.rs b/frontend/rust-lib/flowy-client-sync/src/client_grid/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/client_grid/mod.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_grid/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/client_grid/view_revision_pad.rs b/frontend/rust-lib/flowy-client-sync/src/client_grid/view_revision_pad.rs
similarity index 87%
rename from frontend/rust-lib/flowy-sync/src/client_grid/view_revision_pad.rs
rename to frontend/rust-lib/flowy-client-sync/src/client_grid/view_revision_pad.rs
index f672da6f93..f43154c447 100644
--- a/frontend/rust-lib/flowy-sync/src/client_grid/view_revision_pad.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/client_grid/view_revision_pad.rs
@@ -1,12 +1,13 @@
-use crate::errors::{internal_error, CollaborateError, CollaborateResult};
-use crate::util::{cal_diff, make_operations_from_revisions};
-use flowy_http_model::revision::Revision;
-use flowy_http_model::util::md5;
-use grid_rev_model::{
+use crate::errors::{internal_sync_error, SyncError, SyncResult};
+use crate::util::cal_diff;
+use flowy_sync::util::make_operations_from_revisions;
+use grid_model::{
FieldRevision, FieldTypeRevision, FilterRevision, GridViewRevision, GroupConfigurationRevision, LayoutRevision,
SortRevision,
};
+use lib_infra::util::md5;
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
+use revision_model::Revision;
use std::sync::Arc;
pub type GridViewOperations = DeltaOperations<EmptyAttributes>;
@@ -36,7 +37,7 @@ impl GridViewRevisionPad {
Self { view, operations }
}
- pub fn from_operations(view_id: &str, operations: GridViewOperations) -> CollaborateResult<Self> {
+ pub fn from_operations(view_id: &str, operations: GridViewOperations) -> SyncResult<Self> {
if operations.is_empty() {
return Ok(GridViewRevisionPad::new(
view_id.to_owned(),
@@ -48,7 +49,7 @@ impl GridViewRevisionPad {
let view: GridViewRevision = serde_json::from_str(&s).map_err(|e| {
let msg = format!("Deserialize operations to GridViewRevision failed: {}", e);
tracing::error!("parsing json: {}", s);
- CollaborateError::internal().context(msg)
+ SyncError::internal().context(msg)
})?;
Ok(Self {
view: Arc::new(view),
@@ -56,7 +57,7 @@ impl GridViewRevisionPad {
})
}
- pub fn from_revisions(view_id: &str, revisions: Vec<Revision>) -> CollaborateResult<Self> {
+ pub fn from_revisions(view_id: &str, revisions: Vec<Revision>) -> SyncResult<Self> {
let operations: GridViewOperations = make_operations_from_revisions(revisions)?;
Self::from_operations(view_id, operations)
}
@@ -75,7 +76,7 @@ impl GridViewRevisionPad {
field_id: &str,
field_type: &FieldTypeRevision,
group_configuration_rev: GroupConfigurationRevision,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
// Only save one group
view.groups.clear();
@@ -96,7 +97,7 @@ impl GridViewRevisionPad {
field_type: &FieldTypeRevision,
configuration_id: &str,
mut_configuration_fn: F,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| match view.groups.get_mut_objects(field_id, field_type) {
None => Ok(None),
Some(configurations_revs) => {
@@ -116,7 +117,7 @@ impl GridViewRevisionPad {
group_id: &str,
field_id: &str,
field_type: &FieldTypeRevision,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
if let Some(groups) = view.groups.get_mut_objects(field_id, field_type) {
groups.retain(|group| group.id != group_id);
@@ -150,7 +151,7 @@ impl GridViewRevisionPad {
&mut self,
field_id: &str,
sort_rev: SortRevision,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
let field_type = sort_rev.field_type;
view.sorts.add_object(field_id, &field_type, sort_rev);
@@ -162,7 +163,7 @@ impl GridViewRevisionPad {
&mut self,
field_id: &str,
sort_rev: SortRevision,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
if let Some(sort) = view
.sorts
@@ -182,7 +183,7 @@ impl GridViewRevisionPad {
sort_id: &str,
field_id: &str,
field_type: T,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
let field_type = field_type.into();
self.modify(|view| {
if let Some(sorts) = view.sorts.get_mut_objects(field_id, &field_type) {
@@ -194,7 +195,7 @@ impl GridViewRevisionPad {
})
}
- pub fn delete_all_sorts(&mut self) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ pub fn delete_all_sorts(&mut self) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
view.sorts.clear();
Ok(Some(()))
@@ -224,7 +225,7 @@ impl GridViewRevisionPad {
&mut self,
field_id: &str,
filter_rev: FilterRevision,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
let field_type = filter_rev.field_type;
view.filters.add_object(field_id, &field_type, filter_rev);
@@ -236,7 +237,7 @@ impl GridViewRevisionPad {
&mut self,
field_id: &str,
filter_rev: FilterRevision,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
self.modify(|view| {
if let Some(filter) = view
.filters
@@ -257,7 +258,7 @@ impl GridViewRevisionPad {
filter_id: &str,
field_id: &str,
field_type: T,
- ) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
+ ) -> SyncResult<Option<GridViewRevisionChangeset>> {
let field_type = field_type.into();
self.modify(|view| {
if let Some(filters) = view.filters.get_mut_objects(field_id, &field_type) {
@@ -269,7 +270,7 @@ impl GridViewRevisionPad {
})
}
- pub fn json_str(&self) -> CollaborateResult<String> {
+ pub fn json_str(&self) -> SyncResult<String> {
make_grid_view_rev_json_str(&self.view)
}
@@ -277,9 +278,9 @@ impl GridViewRevisionPad {
self.layout.clone()
}
- fn modify<F>(&mut self, f: F) -> CollaborateResult<Option<GridViewRevisionChangeset>>
+ fn modify<F>(&mut self, f: F) -> SyncResult<Option<GridViewRevisionChangeset>>
where
- F: FnOnce(&mut GridViewRevision) -> CollaborateResult<Option<()>>,
+ F: FnOnce(&mut GridViewRevision) -> SyncResult<Option<()>>,
{
let cloned_view = self.view.clone();
match f(Arc::make_mut(&mut self.view))? {
@@ -306,9 +307,9 @@ pub struct GridViewRevisionChangeset {
pub md5: String,
}
-pub fn make_grid_view_rev_json_str(grid_revision: &GridViewRevision) -> CollaborateResult<String> {
+pub fn make_grid_view_rev_json_str(grid_revision: &GridViewRevision) -> SyncResult<String> {
let json = serde_json::to_string(grid_revision)
- .map_err(|err| internal_error(format!("Serialize grid view to json str failed. {:?}", err)))?;
+ .map_err(|err| internal_sync_error(format!("Serialize grid view to json str failed. {:?}", err)))?;
Ok(json)
}
diff --git a/frontend/rust-lib/flowy-sync/src/lib.rs b/frontend/rust-lib/flowy-client-sync/src/lib.rs
similarity index 60%
rename from frontend/rust-lib/flowy-sync/src/lib.rs
rename to frontend/rust-lib/flowy-client-sync/src/lib.rs
index a6235d0080..bd7bb2d9aa 100644
--- a/frontend/rust-lib/flowy-sync/src/lib.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/lib.rs
@@ -1,10 +1,10 @@
pub mod client_document;
pub mod client_folder;
pub mod client_grid;
-pub mod errors;
-pub mod server_document;
-pub mod server_folder;
-pub mod synchronizer;
+pub mod errors {
+ pub use flowy_sync::errors::*;
+}
pub mod util;
+pub use flowy_sync::util::*;
pub use lib_ot::text_delta::DeltaTextOperations;
diff --git a/frontend/rust-lib/flowy-sync/src/util.rs b/frontend/rust-lib/flowy-client-sync/src/util.rs
similarity index 54%
rename from frontend/rust-lib/flowy-sync/src/util.rs
rename to frontend/rust-lib/flowy-client-sync/src/util.rs
index de4c7560ea..f063db7698 100644
--- a/frontend/rust-lib/flowy-sync/src/util.rs
+++ b/frontend/rust-lib/flowy-client-sync/src/util.rs
@@ -1,14 +1,12 @@
-use crate::errors::{CollaborateError, CollaborateResult};
-use crate::server_folder::FolderOperations;
+use crate::errors::SyncError;
use dissimilar::Chunk;
-use flowy_http_model::document::DocumentPayload;
-use flowy_http_model::folder::FolderInfo;
-use flowy_http_model::revision::Revision;
+use document_model::document::DocumentInfo;
use lib_ot::core::{DeltaOperationBuilder, OTString, OperationAttributes};
use lib_ot::{
core::{DeltaOperations, OperationTransform, NEW_LINE, WHITESPACE},
text_delta::DeltaTextOperations,
};
+use revision_model::Revision;
use serde::de::DeserializeOwned;
#[inline]
@@ -31,26 +29,6 @@ pub fn contain_newline(s: &str) -> bool {
s.contains(NEW_LINE)
}
-#[tracing::instrument(level = "trace", skip(revisions), err)]
-pub fn make_operations_from_revisions<T>(revisions: Vec<Revision>) -> CollaborateResult<DeltaOperations<T>>
-where
- T: OperationAttributes + DeserializeOwned + OperationAttributes + serde::Serialize,
-{
- let mut new_operations = DeltaOperations::<T>::new();
- for revision in revisions {
- if revision.bytes.is_empty() {
- return Err(CollaborateError::unexpected_empty_revision().context("Unexpected Empty revision"));
- }
- let operations = DeltaOperations::<T>::from_bytes(revision.bytes).map_err(|e| {
- let err_msg = format!("Deserialize revision failed: {:?}", e);
- CollaborateError::internal().context(err_msg)
- })?;
-
- new_operations = new_operations.compose(&operations)?;
- }
- Ok(new_operations)
-}
-
pub fn recover_operation_from_revisions<T>(
revisions: Vec<Revision>,
validator: impl Fn(&DeltaOperations<T>) -> bool,
@@ -82,57 +60,11 @@ where
}
}
-pub fn pair_rev_id_from_revision_pbs(revisions: &[Revision]) -> (i64, i64) {
- let mut rev_id = 0;
- revisions.iter().for_each(|revision| {
- if rev_id < revision.rev_id {
- rev_id = revision.rev_id;
- }
- });
-
- if rev_id > 0 {
- (rev_id - 1, rev_id)
- } else {
- (0, rev_id)
- }
-}
-
-#[inline]
-pub fn make_folder_from_revisions_pb(
- folder_id: &str,
- revisions: Vec<Revision>,
-) -> Result<Option<FolderInfo>, CollaborateError> {
- if revisions.is_empty() {
- return Ok(None);
- }
-
- let mut folder_delta = FolderOperations::new();
- let mut base_rev_id = 0;
- let mut rev_id = 0;
- for revision in revisions {
- base_rev_id = revision.base_rev_id;
- rev_id = revision.rev_id;
- if revision.bytes.is_empty() {
- tracing::warn!("revision delta_data is empty");
- }
- let delta = FolderOperations::from_bytes(revision.bytes)?;
- folder_delta = folder_delta.compose(&delta)?;
- }
-
- let text = folder_delta.json_str();
- Ok(Some(FolderInfo {
- folder_id: folder_id.to_string(),
- text,
- rev_id,
- base_rev_id,
- }))
-}
-
#[inline]
-pub fn make_document_from_revision_pbs(
+pub fn make_document_info_from_revisions(
doc_id: &str,
revisions: Vec<Revision>,
-) -> Result<Option<DocumentPayload>, CollaborateError> {
+) -> Result<Option<DocumentInfo>, SyncError> {
if revisions.is_empty() {
return Ok(None);
}
@@ -152,7 +84,7 @@ pub fn make_document_from_revision_pbs(
delta = delta.compose(&new_delta)?;
}
- Ok(Some(DocumentPayload {
+ Ok(Some(DocumentInfo {
doc_id: doc_id.to_owned(),
data: delta.json_bytes().to_vec(),
rev_id,
@@ -161,11 +93,11 @@ pub fn make_document_from_revision_pbs(
}
#[inline]
-pub fn rev_id_from_str(s: &str) -> Result<i64, CollaborateError> {
+pub fn rev_id_from_str(s: &str) -> Result<i64, SyncError> {
let rev_id = s
.to_owned()
.parse::<i64>()
- .map_err(|e| CollaborateError::internal().context(format!("Parse rev_id from {} failed. {}", s, e)))?;
+ .map_err(|e| SyncError::internal().context(format!("Parse rev_id from {} failed. {}", s, e)))?;
Ok(rev_id)
}
diff --git a/frontend/rust-lib/flowy-sync/tests/client_folder/folder_test.rs b/frontend/rust-lib/flowy-client-sync/tests/client_folder/folder_test.rs
similarity index 96%
rename from frontend/rust-lib/flowy-sync/tests/client_folder/folder_test.rs
rename to frontend/rust-lib/flowy-client-sync/tests/client_folder/folder_test.rs
index 90ce6b7c5f..a386922319 100644
--- a/frontend/rust-lib/flowy-sync/tests/client_folder/folder_test.rs
+++ b/frontend/rust-lib/flowy-client-sync/tests/client_folder/folder_test.rs
@@ -1,4 +1,4 @@
-use flowy_sync::client_folder::{FolderNodePad, WorkspaceNode};
+use flowy_client_sync::client_folder::{FolderNodePad, WorkspaceNode};
#[test]
fn client_folder_create_default_folder_test() {
diff --git a/frontend/rust-lib/flowy-sync/tests/client_folder/mod.rs b/frontend/rust-lib/flowy-client-sync/tests/client_folder/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/tests/client_folder/mod.rs
rename to frontend/rust-lib/flowy-client-sync/tests/client_folder/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/tests/client_folder/script.rs b/frontend/rust-lib/flowy-client-sync/tests/client_folder/script.rs
similarity index 97%
rename from frontend/rust-lib/flowy-sync/tests/client_folder/script.rs
rename to frontend/rust-lib/flowy-client-sync/tests/client_folder/script.rs
index 18bd40ae33..ab98f589af 100644
--- a/frontend/rust-lib/flowy-sync/tests/client_folder/script.rs
+++ b/frontend/rust-lib/flowy-client-sync/tests/client_folder/script.rs
@@ -1,5 +1,5 @@
-use flowy_sync::client_folder::{AppNode, FolderNodePad, WorkspaceNode};
-use folder_rev_model::AppRevision;
+use flowy_client_sync::client_folder::{AppNode, FolderNodePad, WorkspaceNode};
+use folder_model::AppRevision;
use lib_ot::core::Path;
pub enum FolderNodePadScript {
diff --git a/frontend/rust-lib/flowy-sync/tests/client_folder/workspace_test.rs b/frontend/rust-lib/flowy-client-sync/tests/client_folder/workspace_test.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/tests/client_folder/workspace_test.rs
rename to frontend/rust-lib/flowy-client-sync/tests/client_folder/workspace_test.rs
diff --git a/frontend/rust-lib/flowy-sync/tests/main.rs b/frontend/rust-lib/flowy-client-sync/tests/main.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/tests/main.rs
rename to frontend/rust-lib/flowy-client-sync/tests/main.rs
diff --git a/frontend/rust-lib/flowy-core/Cargo.toml b/frontend/rust-lib/flowy-core/Cargo.toml
index d96b95b6fa..536f85760e 100644
--- a/frontend/rust-lib/flowy-core/Cargo.toml
+++ b/frontend/rust-lib/flowy-core/Cargo.toml
@@ -12,10 +12,12 @@ flowy-user = { path = "../flowy-user" }
flowy-net = { path = "../flowy-net" }
flowy-folder = { path = "../flowy-folder", default-features = false }
flowy-grid = { path = "../flowy-grid", default-features = false }
-grid-rev-model = { path = "../../../shared-lib/grid-rev-model" }
+grid-model = { path = "../../../shared-lib/grid-model" }
+flowy-client-ws = { path = "../../../shared-lib/flowy-client-ws" }
flowy-database = { path = "../flowy-database", optional = true }
flowy-document = { path = "../flowy-document", default-features = false }
flowy-revision = { path = "../flowy-revision" }
+flowy-error = { path = "../flowy-error", features = ["adaptor_ws"] }
flowy-task = { path = "../flowy-task" }
tracing = { version = "0.1", features = ["log"] }
@@ -24,7 +26,8 @@ bytes = "1.0"
tokio = { version = "1", features = ["rt"] }
parking_lot = "0.12.1"
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
+revision-model = { path = "../../../shared-lib/revision-model" }
+ws-model = { path = "../../../shared-lib/ws-model" }
lib-ws = { path = "../../../shared-lib/lib-ws" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/document_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/document_deps.rs
index cf9565e3dd..b141e8749e 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/document_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/document_deps.rs
@@ -1,20 +1,19 @@
use bytes::Bytes;
+use flowy_client_ws::FlowyWebSocketConnect;
use flowy_database::ConnectionPool;
use flowy_document::{
errors::{internal_error, FlowyError},
DocumentCloudService, DocumentConfig, DocumentDatabase, DocumentManager, DocumentUser,
};
-use flowy_http_model::ws_data::ClientRevisionWSData;
use flowy_net::ClientServerConfiguration;
-use flowy_net::{
- http_server::document::DocumentCloudServiceImpl, local_server::LocalServer, ws::connection::FlowyWebSocketConnect,
-};
+use flowy_net::{http_server::document::DocumentCloudServiceImpl, local_server::LocalServer};
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
use flowy_user::services::UserSession;
use futures_core::future::BoxFuture;
use lib_infra::future::BoxResultFuture;
use lib_ws::{WSChannel, WSMessageReceiver, WebSocketRawMessage};
use std::{convert::TryInto, path::Path, sync::Arc};
+use ws_model::ws_revision::ClientRevisionWSData;
pub struct DocumentDepsResolver();
impl DocumentDepsResolver {
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
index 9ec27cf0ca..6add727d07 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
@@ -1,6 +1,7 @@
use bytes::Bytes;
use flowy_database::ConnectionPool;
+use flowy_client_ws::FlowyWebSocketConnect;
use flowy_document::DocumentManager;
use flowy_folder::entities::{ViewDataFormatPB, ViewLayoutTypePB, ViewPB};
use flowy_folder::manager::{ViewDataProcessor, ViewDataProcessorMap};
@@ -12,21 +13,19 @@ use flowy_folder::{
use flowy_grid::entities::GridLayout;
use flowy_grid::manager::{make_grid_view_data, GridManager};
use flowy_grid::util::{make_default_board, make_default_calendar, make_default_grid};
-use flowy_http_model::revision::Revision;
-use flowy_http_model::ws_data::ClientRevisionWSData;
use flowy_net::ClientServerConfiguration;
-use flowy_net::{
- http_server::folder::FolderHttpCloudService, local_server::LocalServer, ws::connection::FlowyWebSocketConnect,
-};
+use flowy_net::{http_server::folder::FolderHttpCloudService, local_server::LocalServer};
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
use flowy_user::services::UserSession;
use futures_core::future::BoxFuture;
-use grid_rev_model::BuildGridContext;
+use grid_model::BuildGridContext;
use lib_infra::future::{BoxResultFuture, FutureResult};
use lib_ws::{WSChannel, WSMessageReceiver, WebSocketRawMessage};
+use revision_model::Revision;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::{convert::TryInto, sync::Arc};
+use ws_model::ws_revision::ClientRevisionWSData;
pub struct FolderDepsResolver();
impl FolderDepsResolver {
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/grid_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/grid_deps.rs
index d4266918e4..9ce2046785 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/grid_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/grid_deps.rs
@@ -1,10 +1,9 @@
use crate::FlowyError;
use bytes::Bytes;
+use flowy_client_ws::FlowyWebSocketConnect;
use flowy_database::ConnectionPool;
use flowy_grid::manager::{GridManager, GridUser};
use flowy_grid::services::persistence::GridDatabase;
-use flowy_http_model::ws_data::ClientRevisionWSData;
-use flowy_net::ws::connection::FlowyWebSocketConnect;
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
use flowy_task::TaskDispatcher;
use flowy_user::services::UserSession;
@@ -14,6 +13,7 @@ use lib_ws::{WSChannel, WebSocketRawMessage};
use std::convert::TryInto;
use std::sync::Arc;
use tokio::sync::RwLock;
+use ws_model::ws_revision::ClientRevisionWSData;
pub struct GridDepsResolver();
diff --git a/frontend/rust-lib/flowy-core/src/lib.rs b/frontend/rust-lib/flowy-core/src/lib.rs
index dde86d0a4e..dc52d6dd93 100644
--- a/frontend/rust-lib/flowy-core/src/lib.rs
+++ b/frontend/rust-lib/flowy-core/src/lib.rs
@@ -4,17 +4,14 @@ pub use flowy_net::get_client_server_configuration;
use crate::deps_resolve::*;
+use flowy_client_ws::{listen_on_websocket, FlowyWebSocketConnect, NetworkType};
use flowy_document::entities::DocumentVersionPB;
use flowy_document::{DocumentConfig, DocumentManager};
use flowy_folder::entities::ViewDataFormatPB;
use flowy_folder::{errors::FlowyError, manager::FolderManager};
use flowy_grid::manager::GridManager;
+use flowy_net::local_server::LocalServer;
use flowy_net::ClientServerConfiguration;
-use flowy_net::{
- entities::NetworkType,
- local_server::LocalServer,
- ws::connection::{listen_on_websocket, FlowyWebSocketConnect},
-};
use flowy_task::{TaskDispatcher, TaskRunner};
use flowy_user::services::{notifier::UserStatus, UserSession, UserSessionConfig};
use lib_dispatch::prelude::*;
diff --git a/frontend/rust-lib/flowy-core/src/module.rs b/frontend/rust-lib/flowy-core/src/module.rs
index 74bc4cfca6..789cef0b2d 100644
--- a/frontend/rust-lib/flowy-core/src/module.rs
+++ b/frontend/rust-lib/flowy-core/src/module.rs
@@ -1,7 +1,7 @@
+use flowy_client_ws::FlowyWebSocketConnect;
use flowy_document::DocumentManager;
use flowy_folder::manager::FolderManager;
use flowy_grid::manager::GridManager;
-use flowy_net::ws::connection::FlowyWebSocketConnect;
use flowy_user::services::UserSession;
use lib_dispatch::prelude::AFPlugin;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-document/Cargo.toml b/frontend/rust-lib/flowy-document/Cargo.toml
index 34ff05647b..7a070fc2da 100644
--- a/frontend/rust-lib/flowy-document/Cargo.toml
+++ b/frontend/rust-lib/flowy-document/Cargo.toml
@@ -7,8 +7,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-flowy-sync = { path = "../flowy-sync"}
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model"}
+flowy-client-sync = { path = "../flowy-client-sync"}
+revision-model = { path = "../../../shared-lib/revision-model"}
+document-model = { path = "../../../shared-lib/document-model"}
+ws-model = { path = "../../../shared-lib/ws-model"}
flowy-derive = { path = "../flowy-derive" }
lib-ot = { path = "../../../shared-lib/lib-ot" }
lib-ws = { path = "../../../shared-lib/lib-ws" }
@@ -18,14 +20,12 @@ lib-dispatch = { path = "../lib-dispatch" }
flowy-database = { path = "../flowy-database", optional = true }
flowy-revision = { path = "../flowy-revision" }
flowy-revision-persistence = { path = "../flowy-revision-persistence" }
-flowy-error = { path = "../flowy-error", features = ["collaboration", "ot", "http_server", "serde", "db"] }
+flowy-error = { path = "../flowy-error", features = ["adaptor_sync", "adaptor_ot", "adaptor_serde", "adaptor_database", "adaptor_dispatch"] }
flowy-notification = { path = "../flowy-notification" }
diesel = {version = "1.4.8", features = ["sqlite"]}
diesel_derives = {version = "1.4.1", features = ["sqlite"]}
protobuf = {version = "2.18.0"}
-unicode-segmentation = "1.8"
-log = "0.4.14"
tokio = {version = "1", features = ["sync"]}
tracing = { version = "0.1", features = ["log"] }
@@ -47,6 +47,7 @@ flowy-test = { path = "../flowy-test" }
flowy-document = { path = "../flowy-document", features = ["flowy_unit_test"]}
derive_more = {version = "0.99", features = ["display"]}
tracing-subscriber = "0.2.0"
+unicode-segmentation = "1.8"
color-eyre = { version = "0.5", default-features = false }
criterion = "0.3"
diff --git a/frontend/rust-lib/flowy-document/src/editor/document.rs b/frontend/rust-lib/flowy-document/src/editor/document.rs
index 026bbb3f27..280d96110a 100644
--- a/frontend/rust-lib/flowy-document/src/editor/document.rs
+++ b/frontend/rust-lib/flowy-document/src/editor/document.rs
@@ -1,9 +1,9 @@
use bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision::{RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer};
use lib_ot::core::{Extension, NodeDataBuilder, NodeOperation, NodeTree, NodeTreeContext, Selection, Transaction};
use lib_ot::text_delta::DeltaTextOperationBuilder;
+use revision_model::Revision;
#[derive(Debug)]
pub struct Document {
diff --git a/frontend/rust-lib/flowy-document/src/editor/editor.rs b/frontend/rust-lib/flowy-document/src/editor/editor.rs
index 79e1f94580..904b558b51 100644
--- a/frontend/rust-lib/flowy-document/src/editor/editor.rs
+++ b/frontend/rust-lib/flowy-document/src/editor/editor.rs
@@ -6,7 +6,6 @@ use crate::{DocumentEditor, DocumentUser};
use bytes::Bytes;
use flowy_database::ConnectionPool;
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::ws_data::ServerRevisionWSData;
use flowy_revision::{RevisionCloudService, RevisionManager};
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
@@ -15,6 +14,7 @@ use lib_ws::WSConnectState;
use std::any::Any;
use std::sync::Arc;
use tokio::sync::{mpsc, oneshot};
+use ws_model::ws_revision::ServerRevisionWSData;
pub struct AppFlowyDocumentEditor {
#[allow(dead_code)]
diff --git a/frontend/rust-lib/flowy-document/src/entities.rs b/frontend/rust-lib/flowy-document/src/entities.rs
index ecbf24bb5e..00f89d6511 100644
--- a/frontend/rust-lib/flowy-document/src/entities.rs
+++ b/frontend/rust-lib/flowy-document/src/entities.rs
@@ -22,7 +22,7 @@ impl From<i32> for ExportType {
1 => ExportType::Markdown,
2 => ExportType::Link,
_ => {
- log::error!("Invalid export type: {}", val);
+ tracing::error!("Invalid export type: {}", val);
ExportType::Text
}
}
diff --git a/frontend/rust-lib/flowy-document/src/lib.rs b/frontend/rust-lib/flowy-document/src/lib.rs
index e0067bf083..986af3354f 100644
--- a/frontend/rust-lib/flowy-document/src/lib.rs
+++ b/frontend/rust-lib/flowy-document/src/lib.rs
@@ -16,13 +16,13 @@ pub mod errors {
pub const TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS: u64 = 1000;
use crate::errors::FlowyError;
-use flowy_http_model::document::{CreateDocumentParams, DocumentId, DocumentPayload, ResetDocumentParams};
+use document_model::document::{CreateDocumentParams, DocumentId, DocumentInfo, ResetDocumentParams};
use lib_infra::future::FutureResult;
pub trait DocumentCloudService: Send + Sync {
fn create_document(&self, token: &str, params: CreateDocumentParams) -> FutureResult<(), FlowyError>;
- fn fetch_document(&self, token: &str, params: DocumentId) -> FutureResult<Option<DocumentPayload>, FlowyError>;
+ fn fetch_document(&self, token: &str, params: DocumentId) -> FutureResult<Option<DocumentInfo>, FlowyError>;
fn update_document_content(&self, token: &str, params: ResetDocumentParams) -> FutureResult<(), FlowyError>;
}
diff --git a/frontend/rust-lib/flowy-document/src/manager.rs b/frontend/rust-lib/flowy-document/src/manager.rs
index edb6000427..2327151081 100644
--- a/frontend/rust-lib/flowy-document/src/manager.rs
+++ b/frontend/rust-lib/flowy-document/src/manager.rs
@@ -8,24 +8,25 @@ use crate::services::rev_sqlite::{
use crate::services::DocumentPersistence;
use crate::{errors::FlowyError, DocumentCloudService};
use bytes::Bytes;
+use document_model::document::DocumentId;
+use flowy_client_sync::client_document::initial_delta_document_content;
use flowy_database::ConnectionPool;
use flowy_error::FlowyResult;
-use flowy_http_model::util::md5;
-use flowy_http_model::ws_data::ServerRevisionWSData;
-use flowy_http_model::{document::DocumentId, revision::Revision};
use flowy_revision::{
PhantomSnapshotPersistence, RevisionCloudService, RevisionManager, RevisionPersistence,
RevisionPersistenceConfiguration, RevisionWebSocket,
};
-use flowy_sync::client_document::initial_delta_document_content;
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
+use lib_infra::util::md5;
use lib_ws::WSConnectState;
+use revision_model::Revision;
use std::any::Any;
use std::convert::TryFrom;
use std::sync::Arc;
use tokio::sync::RwLock;
+use ws_model::ws_revision::ServerRevisionWSData;
pub trait DocumentUser: Send + Sync {
fn user_dir(&self) -> Result<String, FlowyError>;
diff --git a/frontend/rust-lib/flowy-document/src/old_editor/editor.rs b/frontend/rust-lib/flowy-document/src/old_editor/editor.rs
index 1e16239c5f..0a102c5e08 100644
--- a/frontend/rust-lib/flowy-document/src/old_editor/editor.rs
+++ b/frontend/rust-lib/flowy-document/src/old_editor/editor.rs
@@ -4,16 +4,15 @@
use crate::old_editor::queue::{EditDocumentQueue, EditorCommand, EditorCommandSender};
use crate::{errors::FlowyError, DocumentEditor, DocumentUser};
use bytes::Bytes;
+use document_model::document::DocumentInfo;
+use flowy_client_sync::errors::SyncResult;
+use flowy_client_sync::make_operations_from_revisions;
use flowy_database::ConnectionPool;
use flowy_error::{internal_error, FlowyResult};
-use flowy_http_model::document::DocumentPayload;
-use flowy_http_model::revision::Revision;
-use flowy_http_model::ws_data::ServerRevisionWSData;
use flowy_revision::{
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
RevisionWebSocket,
};
-use flowy_sync::{errors::CollaborateResult, util::make_operations_from_revisions};
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use lib_ot::core::{AttributeEntry, AttributeHashMap};
@@ -22,9 +21,11 @@ use lib_ot::{
text_delta::DeltaTextOperations,
};
use lib_ws::WSConnectState;
+use revision_model::Revision;
use std::any::Any;
use std::sync::Arc;
use tokio::sync::{mpsc, oneshot};
+use ws_model::ws_revision::ServerRevisionWSData;
pub struct DeltaDocumentEditor {
pub doc_id: String,
@@ -73,7 +74,7 @@ impl DeltaDocumentEditor {
}
pub async fn insert<T: ToString>(&self, index: usize, data: T) -> Result<(), FlowyError> {
- let (ret, rx) = oneshot::channel::<CollaborateResult<()>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<()>>();
let msg = EditorCommand::Insert {
index,
data: data.to_string(),
@@ -85,7 +86,7 @@ impl DeltaDocumentEditor {
}
pub async fn delete(&self, interval: Interval) -> Result<(), FlowyError> {
- let (ret, rx) = oneshot::channel::<CollaborateResult<()>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<()>>();
let msg = EditorCommand::Delete { interval, ret };
let _ = self.edit_cmd_tx.send(msg).await;
rx.await.map_err(internal_error)??;
@@ -93,7 +94,7 @@ impl DeltaDocumentEditor {
}
pub async fn format(&self, interval: Interval, attribute: AttributeEntry) -> Result<(), FlowyError> {
- let (ret, rx) = oneshot::channel::<CollaborateResult<()>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<()>>();
let msg = EditorCommand::Format {
interval,
attribute,
@@ -105,7 +106,7 @@ impl DeltaDocumentEditor {
}
pub async fn replace<T: ToString>(&self, interval: Interval, data: T) -> Result<(), FlowyError> {
- let (ret, rx) = oneshot::channel::<CollaborateResult<()>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<()>>();
let msg = EditorCommand::Replace {
interval,
data: data.to_string(),
@@ -155,7 +156,7 @@ impl DocumentEditor for Arc<DeltaDocumentEditor> {
}
fn export(&self) -> FutureResult<String, FlowyError> {
- let (ret, rx) = oneshot::channel::<CollaborateResult<String>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<String>>();
let msg = EditorCommand::GetOperationsString { ret };
let edit_cmd_tx = self.edit_cmd_tx.clone();
FutureResult::new(async move {
@@ -190,7 +191,7 @@ impl DocumentEditor for Arc<DeltaDocumentEditor> {
let edit_cmd_tx = self.edit_cmd_tx.clone();
FutureResult::new(async move {
let operations = DeltaTextOperations::from_bytes(&data)?;
- let (ret, rx) = oneshot::channel::<CollaborateResult<()>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<()>>();
let msg = EditorCommand::ComposeLocalOperations { operations, ret };
let _ = edit_cmd_tx.send(msg).await;
@@ -233,7 +234,7 @@ fn spawn_edit_queue(
#[cfg(feature = "flowy_unit_test")]
impl DeltaDocumentEditor {
pub async fn document_operations(&self) -> FlowyResult<DeltaTextOperations> {
- let (ret, rx) = oneshot::channel::<CollaborateResult<DeltaTextOperations>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<DeltaTextOperations>>();
let msg = EditorCommand::GetOperations { ret };
let _ = self.edit_cmd_tx.send(msg).await;
let delta = rx.await.map_err(internal_error)??;
@@ -247,14 +248,14 @@ impl DeltaDocumentEditor {
pub struct DeltaDocumentRevisionSerde();
impl RevisionObjectDeserializer for DeltaDocumentRevisionSerde {
- type Output = DocumentPayload;
+ type Output = DocumentInfo;
fn deserialize_revisions(object_id: &str, revisions: Vec<Revision>) -> FlowyResult<Self::Output> {
let (base_rev_id, rev_id) = revisions.last().unwrap().pair_rev_id();
let mut delta = make_operations_from_revisions(revisions)?;
correct_delta(&mut delta);
- Result::<DocumentPayload, FlowyError>::Ok(DocumentPayload {
+ Result::<DocumentInfo, FlowyError>::Ok(DocumentInfo {
doc_id: object_id.to_owned(),
data: delta.json_bytes().to_vec(),
rev_id,
diff --git a/frontend/rust-lib/flowy-document/src/old_editor/queue.rs b/frontend/rust-lib/flowy-document/src/old_editor/queue.rs
index 54ad9c8098..e3a00da739 100644
--- a/frontend/rust-lib/flowy-document/src/old_editor/queue.rs
+++ b/frontend/rust-lib/flowy-document/src/old_editor/queue.rs
@@ -1,13 +1,13 @@
use crate::old_editor::web_socket::DeltaDocumentResolveOperations;
use crate::DocumentUser;
use async_stream::stream;
+use flowy_client_sync::{
+ client_document::{history::UndoResult, ClientDocument},
+ errors::SyncError,
+};
use flowy_database::ConnectionPool;
use flowy_error::FlowyError;
use flowy_revision::{RevisionMD5, RevisionManager, TransformOperations};
-use flowy_sync::{
- client_document::{history::UndoResult, ClientDocument},
- errors::CollaborateError,
-};
use futures::stream::StreamExt;
use lib_ot::core::AttributeEntry;
use lib_ot::{
@@ -104,7 +104,7 @@ impl EditDocumentQueue {
server_operations = Some(DeltaDocumentResolveOperations(s_prime));
}
drop(read_guard);
- Ok::<TextTransformOperations, CollaborateError>(TransformOperations {
+ Ok::<TextTransformOperations, SyncError>(TransformOperations {
client_operations: DeltaDocumentResolveOperations(client_operations),
server_operations,
})
@@ -185,7 +185,7 @@ impl EditDocumentQueue {
pub type TextTransformOperations = TransformOperations<DeltaDocumentResolveOperations>;
pub(crate) type EditorCommandSender = Sender<EditorCommand>;
pub(crate) type EditorCommandReceiver = Receiver<EditorCommand>;
-pub(crate) type Ret<T> = oneshot::Sender<Result<T, CollaborateError>>;
+pub(crate) type Ret<T> = oneshot::Sender<Result<T, SyncError>>;
pub(crate) enum EditorCommand {
ComposeLocalOperations {
diff --git a/frontend/rust-lib/flowy-document/src/old_editor/web_socket.rs b/frontend/rust-lib/flowy-document/src/old_editor/web_socket.rs
index 67f686e863..fa3e2600d6 100644
--- a/frontend/rust-lib/flowy-document/src/old_editor/web_socket.rs
+++ b/frontend/rust-lib/flowy-document/src/old_editor/web_socket.rs
@@ -1,18 +1,18 @@
use crate::old_editor::queue::{EditorCommand, EditorCommandSender, TextTransformOperations};
use crate::TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS;
use bytes::Bytes;
+use flowy_client_sync::errors::SyncResult;
+use flowy_client_sync::make_operations_from_revisions;
use flowy_database::ConnectionPool;
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::ws_data::{ClientRevisionWSData, NewDocumentUser};
use flowy_revision::*;
-use flowy_sync::errors::CollaborateResult;
-use flowy_sync::util::make_operations_from_revisions;
use lib_infra::future::{BoxResultFuture, FutureResult};
use lib_ot::text_delta::DeltaTextOperations;
use lib_ws::WSConnectState;
+use revision_model::{Revision, RevisionRange};
use std::{sync::Arc, time::Duration};
use tokio::sync::{broadcast, oneshot};
+use ws_model::ws_revision::{ClientRevisionWSData, NewDocumentUser};
#[derive(Clone)]
pub struct DeltaDocumentResolveOperations(pub DeltaTextOperations);
@@ -156,7 +156,7 @@ impl ConflictResolver<DeltaDocumentResolveOperations> for DocumentConflictResolv
let tx = self.edit_cmd_tx.clone();
let operations = operations.into_inner();
Box::pin(async move {
- let (ret, rx) = oneshot::channel::<CollaborateResult<TextTransformOperations>>();
+ let (ret, rx) = oneshot::channel::<SyncResult<TextTransformOperations>>();
tx.send(EditorCommand::TransformOperations { operations, ret })
.await
.map_err(internal_error)?;
diff --git a/frontend/rust-lib/flowy-document/src/services/migration.rs b/frontend/rust-lib/flowy-document/src/services/migration.rs
index 9d04cc25e2..7a32855ff8 100644
--- a/frontend/rust-lib/flowy-document/src/services/migration.rs
+++ b/frontend/rust-lib/flowy-document/src/services/migration.rs
@@ -2,12 +2,12 @@ use crate::services::delta_migration::DeltaRevisionMigration;
use crate::services::rev_sqlite::{DeltaRevisionSql, SQLiteDocumentRevisionPersistence};
use crate::DocumentDatabase;
use bytes::Bytes;
+use flowy_client_sync::make_operations_from_revisions;
use flowy_database::kv::KV;
use flowy_error::FlowyResult;
-use flowy_http_model::revision::Revision;
-use flowy_http_model::util::md5;
use flowy_revision_persistence::{RevisionDiskCache, SyncRecord};
-use flowy_sync::util::make_operations_from_revisions;
+use lib_infra::util::md5;
+use revision_model::Revision;
use std::sync::Arc;
const V1_MIGRATION: &str = "DOCUMENT_V1_MIGRATION";
diff --git a/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v0.rs b/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v0.rs
index 2f6fb65d3d..081f4a262c 100644
--- a/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v0.rs
+++ b/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v0.rs
@@ -7,11 +7,9 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::{
- revision::{Revision, RevisionRange},
- util::md5,
-};
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::collections::HashMap;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v1.rs b/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v1.rs
index 561a1763b8..fece8356fc 100644
--- a/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v1.rs
+++ b/frontend/rust-lib/flowy-document/src/services/persistence/rev_sqlite/document_rev_sqlite_v1.rs
@@ -7,11 +7,9 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::{
- revision::{Revision, RevisionRange},
- util::md5,
-};
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::sync::Arc;
pub struct SQLiteDocumentRevisionPersistence {
diff --git a/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs b/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs
index f17f8dad15..a60254a7c9 100644
--- a/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs
+++ b/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs
@@ -1,6 +1,6 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
use crate::editor::{TestBuilder, TestOp::*};
-use flowy_sync::client_document::{NewlineDocument, EmptyDocument};
+use flowy_client_sync::client_document::{NewlineDocument, EmptyDocument};
use lib_ot::core::{Interval, OperationTransform, NEW_LINE, WHITESPACE, OTString};
use unicode_segmentation::UnicodeSegmentation;
use lib_ot::text_delta::DeltaTextOperations;
diff --git a/frontend/rust-lib/flowy-document/tests/editor/mod.rs b/frontend/rust-lib/flowy-document/tests/editor/mod.rs
index f33cfb8057..0bdab884b5 100644
--- a/frontend/rust-lib/flowy-document/tests/editor/mod.rs
+++ b/frontend/rust-lib/flowy-document/tests/editor/mod.rs
@@ -5,7 +5,7 @@ mod serde_test;
mod undo_redo_test;
use derive_more::Display;
-use flowy_sync::client_document::{ClientDocument, InitialDocument};
+use flowy_client_sync::client_document::{ClientDocument, InitialDocument};
use lib_ot::{
core::*,
text_delta::{BuildInTextAttribute, DeltaTextOperations},
@@ -242,8 +242,8 @@ impl TestBuilder {
let target_prime: DeltaTextOperations = serde_json::from_str(&prime_json).unwrap();
if expected_prime != target_prime {
- log::error!("✅ expect prime: {}", expected,);
- log::error!("❌ receive prime: {}", prime_json);
+ tracing::error!("✅ expect prime: {}", expected,);
+ tracing::error!("❌ receive prime: {}", prime_json);
}
assert_eq!(target_prime, expected_prime);
}
diff --git a/frontend/rust-lib/flowy-document/tests/editor/op_test.rs b/frontend/rust-lib/flowy-document/tests/editor/op_test.rs
index d1cec0c7f0..c7a900d586 100644
--- a/frontend/rust-lib/flowy-document/tests/editor/op_test.rs
+++ b/frontend/rust-lib/flowy-document/tests/editor/op_test.rs
@@ -1,6 +1,6 @@
#![allow(clippy::all)]
use crate::editor::{Rng, TestBuilder, TestOp::*};
-use flowy_sync::client_document::{EmptyDocument, NewlineDocument};
+use flowy_client_sync::client_document::{EmptyDocument, NewlineDocument};
use lib_ot::text_delta::DeltaTextOperationBuilder;
use lib_ot::{core::Interval, core::*, text_delta::DeltaTextOperations};
diff --git a/frontend/rust-lib/flowy-document/tests/editor/serde_test.rs b/frontend/rust-lib/flowy-document/tests/editor/serde_test.rs
index 9941424dc7..9341f7222a 100644
--- a/frontend/rust-lib/flowy-document/tests/editor/serde_test.rs
+++ b/frontend/rust-lib/flowy-document/tests/editor/serde_test.rs
@@ -1,4 +1,4 @@
-use flowy_sync::client_document::{ClientDocument, EmptyDocument};
+use flowy_client_sync::client_document::{ClientDocument, EmptyDocument};
use lib_ot::text_delta::DeltaTextOperation;
use lib_ot::{
core::*,
diff --git a/frontend/rust-lib/flowy-document/tests/editor/undo_redo_test.rs b/frontend/rust-lib/flowy-document/tests/editor/undo_redo_test.rs
index 94be66f1b9..d188daea37 100644
--- a/frontend/rust-lib/flowy-document/tests/editor/undo_redo_test.rs
+++ b/frontend/rust-lib/flowy-document/tests/editor/undo_redo_test.rs
@@ -1,5 +1,5 @@
use crate::editor::{TestBuilder, TestOp::*};
-use flowy_sync::client_document::{EmptyDocument, NewlineDocument, RECORD_THRESHOLD};
+use flowy_client_sync::client_document::{EmptyDocument, NewlineDocument, RECORD_THRESHOLD};
use lib_ot::core::{Interval, NEW_LINE, WHITESPACE};
#[test]
diff --git a/frontend/rust-lib/flowy-error/Cargo.toml b/frontend/rust-lib/flowy-error/Cargo.toml
index 2d547cc23a..9da2e3daca 100644
--- a/frontend/rust-lib/flowy-error/Cargo.toml
+++ b/frontend/rust-lib/flowy-error/Cargo.toml
@@ -7,26 +7,34 @@ edition = "2018"
[dependencies]
flowy-derive = { path = "../flowy-derive" }
-lib-dispatch = { path = "../lib-dispatch" }
protobuf = {version = "2.20.0"}
bytes = "1.0"
anyhow = "1.0"
thiserror = "1.0"
-
-flowy-sync = { path = "../flowy-sync", optional = true}
+flowy-client-sync = { path = "../flowy-client-sync", optional = true}
+lib-dispatch = { path = "../lib-dispatch", optional = true }
lib-ot = { path = "../../../shared-lib/lib-ot", optional = true}
+user-model = { path = "../../../shared-lib/user-model", optional = true}
+flowy-client-ws = { path = "../../../shared-lib/flowy-client-ws", optional = true }
serde_json = {version = "1.0", optional = true}
-http-flowy = { git = "https://github.com/AppFlowy-IO/AppFlowy-Server", optional = true}
+serde_repr = { version = "0.1" }
+serde = "1.0"
+reqwest = { version = "0.11", optional = true }
+http-error-code = { git = "https://github.com/AppFlowy-IO/AppFlowy-Server", branch = "refactor/appflowy_server", optional = true }
flowy-database = { path = "../flowy-database", optional = true}
r2d2 = { version = "0.8", optional = true}
[features]
-collaboration = ["flowy-sync"]
-ot = ["lib-ot"]
-serde = ["serde_json"]
-http_server = ["http-flowy"]
-db = ["flowy-database", "r2d2"]
+adaptor_sync = ["flowy-client-sync"]
+adaptor_ot = ["lib-ot"]
+adaptor_dispatch = ["lib-dispatch"]
+adaptor_serde = ["serde_json"]
+adaptor_reqwest = ["reqwest"]
+adaptor_database = ["flowy-database", "r2d2"]
+adaptor_ws= ["flowy-client-ws"]
+adaptor_user= ["user-model"]
+adaptor_server_error = ["http-error-code"]
dart = ["flowy-codegen/dart"]
ts = ["flowy-codegen/ts"]
diff --git a/frontend/rust-lib/flowy-error/src/code.rs b/frontend/rust-lib/flowy-error/src/code.rs
index f3e07b2948..c306dfdc53 100644
--- a/frontend/rust-lib/flowy-error/src/code.rs
+++ b/frontend/rust-lib/flowy-error/src/code.rs
@@ -1,7 +1,9 @@
use flowy_derive::ProtoBuf_Enum;
+use serde_repr::*;
use thiserror::Error;
-#[derive(Debug, Clone, PartialEq, Eq, Error, ProtoBuf_Enum)]
+#[derive(Debug, Clone, PartialEq, Eq, Error, Serialize_repr, Deserialize_repr, ProtoBuf_Enum)]
+#[repr(u8)]
pub enum ErrorCode {
#[error("Internal error")]
Internal = 0,
@@ -92,6 +94,7 @@ pub enum ErrorCode {
#[error("user id is empty or whitespace")]
UserIdInvalid = 30,
+
#[error("User not exist")]
UserNotExist = 31,
@@ -160,6 +163,27 @@ pub enum ErrorCode {
#[error("Sort id is empty")]
SortIdIsEmpty = 53,
+
+ #[error("Connect refused")]
+ ConnectRefused = 54,
+
+ #[error("Connection timeout")]
+ ConnectTimeout = 55,
+
+ #[error("Connection closed")]
+ ConnectClose = 56,
+
+ #[error("Connection canceled")]
+ ConnectCancel = 57,
+
+ #[error("Sql error")]
+ SqlError = 58,
+
+ #[error("Http request error")]
+ HttpError = 59,
+
+ #[error("Payload should not be empty")]
+ UnexpectedEmptyPayload = 60,
}
impl ErrorCode {
diff --git a/frontend/rust-lib/flowy-error/src/errors.rs b/frontend/rust-lib/flowy-error/src/errors.rs
index fe1a3d4a25..74739bb705 100644
--- a/frontend/rust-lib/flowy-error/src/errors.rs
+++ b/frontend/rust-lib/flowy-error/src/errors.rs
@@ -1,9 +1,7 @@
-use crate::ErrorCode;
+use crate::code::ErrorCode;
use anyhow::Result;
-use bytes::Bytes;
use flowy_derive::ProtoBuf;
-use lib_dispatch::prelude::{AFPluginEventResponse, ResponseBuilder};
-use std::{convert::TryInto, fmt::Debug};
+use std::fmt::Debug;
use thiserror::Error;
pub type FlowyResult<T> = anyhow::Result<T, FlowyError>;
@@ -39,6 +37,10 @@ impl FlowyError {
self
}
+ pub fn is_record_not_found(&self) -> bool {
+ self.code == ErrorCode::RecordNotFound.value()
+ }
+
static_flowy_error!(internal, ErrorCode::Internal);
static_flowy_error!(record_not_found, ErrorCode::RecordNotFound);
static_flowy_error!(workspace_name, ErrorCode::WorkspaceNameInvalid);
@@ -72,6 +74,8 @@ impl FlowyError {
static_flowy_error!(out_of_bounds, ErrorCode::OutOfBounds);
static_flowy_error!(serde, ErrorCode::Serde);
static_flowy_error!(field_record_not_found, ErrorCode::FieldRecordNotFound);
+ static_flowy_error!(payload_none, ErrorCode::UnexpectedEmptyPayload);
+ static_flowy_error!(http, ErrorCode::HttpError);
}
impl std::convert::From<ErrorCode> for FlowyError {
@@ -90,22 +94,6 @@ where
FlowyError::internal().context(e)
}
-// Not needed because of thiserror derive macro
-/* impl fmt::Display for FlowyError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{:?}: {}", &self.code, &self.msg)
- }
-}
- */
-impl lib_dispatch::Error for FlowyError {
- fn as_response(&self) -> AFPluginEventResponse {
- let bytes: Bytes = self.clone().try_into().unwrap();
-
- println!("Serialize FlowyError: {:?} to event response", self);
- ResponseBuilder::Err().data(bytes).build()
- }
-}
-
impl std::convert::From<std::io::Error> for FlowyError {
fn from(error: std::io::Error) -> Self {
FlowyError::internal().context(error)
@@ -117,5 +105,3 @@ impl std::convert::From<protobuf::ProtobufError> for FlowyError {
FlowyError::internal().context(e)
}
}
-
-//impl std::error::Error for FlowyError {}
diff --git a/frontend/rust-lib/flowy-error/src/ext/dispatch.rs b/frontend/rust-lib/flowy-error/src/ext/dispatch.rs
new file mode 100644
index 0000000000..0f9c61dfed
--- /dev/null
+++ b/frontend/rust-lib/flowy-error/src/ext/dispatch.rs
@@ -0,0 +1,12 @@
+use crate::FlowyError;
+use bytes::Bytes;
+use lib_dispatch::prelude::{AFPluginEventResponse, ResponseBuilder};
+use std::convert::TryInto;
+impl lib_dispatch::Error for FlowyError {
+ fn as_response(&self) -> AFPluginEventResponse {
+ let bytes: Bytes = self.clone().try_into().unwrap();
+
+ println!("Serialize FlowyError: {:?} to event response", self);
+ ResponseBuilder::Err().data(bytes).build()
+ }
+}
diff --git a/frontend/rust-lib/flowy-error/src/ext/http_server.rs b/frontend/rust-lib/flowy-error/src/ext/http_server.rs
index be791d4af5..32f57b1de4 100644
--- a/frontend/rust-lib/flowy-error/src/ext/http_server.rs
+++ b/frontend/rust-lib/flowy-error/src/ext/http_server.rs
@@ -1,21 +1,16 @@
-use crate::{ErrorCode, FlowyError};
-use http_flowy::errors::{ErrorCode as ServerErrorCode, ServerError};
+use crate::code::ErrorCode;
+use http_error_code::ErrorCode as ServerErrorCode;
-impl std::convert::From<ServerError> for FlowyError {
- fn from(error: ServerError) -> Self {
- let code = server_error_to_flowy_error(error.code);
- FlowyError::new(code, &error.msg)
- }
-}
-
-fn server_error_to_flowy_error(code: ServerErrorCode) -> ErrorCode {
- match code {
- ServerErrorCode::UserUnauthorized => ErrorCode::UserUnauthorized,
- ServerErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
- ServerErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
- ServerErrorCode::ConnectRefused | ServerErrorCode::ConnectTimeout | ServerErrorCode::ConnectClose => {
- ErrorCode::HttpServerConnectError
+impl std::convert::From<ServerErrorCode> for ErrorCode {
+ fn from(code: ServerErrorCode) -> Self {
+ match code {
+ ServerErrorCode::UserUnauthorized => ErrorCode::UserUnauthorized,
+ ServerErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
+ ServerErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
+ ServerErrorCode::ConnectRefused | ServerErrorCode::ConnectTimeout | ServerErrorCode::ConnectClose => {
+ ErrorCode::HttpServerConnectError
+ }
+ _ => ErrorCode::Internal,
}
- _ => ErrorCode::Internal,
}
}
diff --git a/frontend/rust-lib/flowy-error/src/ext/mod.rs b/frontend/rust-lib/flowy-error/src/ext/mod.rs
index 6468d6777a..89a7000b63 100644
--- a/frontend/rust-lib/flowy-error/src/ext/mod.rs
+++ b/frontend/rust-lib/flowy-error/src/ext/mod.rs
@@ -1,27 +1,26 @@
-#[cfg(feature = "collaboration")]
-mod collaborate;
-#[cfg(feature = "collaboration")]
-pub use collaborate::*;
-
-//
-#[cfg(feature = "ot")]
-mod ot;
-#[cfg(feature = "ot")]
-pub use ot::*;
-
-//
-#[cfg(feature = "serde")]
-mod serde;
-#[cfg(feature = "serde")]
-pub use serde::*;
-
-//
-#[cfg(feature = "http_server")]
-mod http_server;
-#[cfg(feature = "http_server")]
-pub use http_server::*;
-
-#[cfg(feature = "db")]
-mod database;
-#[cfg(feature = "db")]
-pub use database::*;
+#[cfg(feature = "adaptor_sync")]
+pub mod sync;
+
+#[cfg(feature = "adaptor_ot")]
+pub mod ot;
+
+#[cfg(feature = "adaptor_serde")]
+pub mod serde;
+
+#[cfg(feature = "adaptor_dispatch")]
+pub mod dispatch;
+
+#[cfg(feature = "adaptor_reqwest")]
+pub mod reqwest;
+
+#[cfg(feature = "adaptor_database")]
+pub mod database;
+
+#[cfg(feature = "adaptor_ws")]
+pub mod ws;
+
+#[cfg(feature = "adaptor_user")]
+pub mod user;
+
+#[cfg(feature = "adaptor_server_error")]
+pub mod http_server;
diff --git a/frontend/rust-lib/flowy-error/src/ext/reqwest.rs b/frontend/rust-lib/flowy-error/src/ext/reqwest.rs
new file mode 100644
index 0000000000..e573e9b98c
--- /dev/null
+++ b/frontend/rust-lib/flowy-error/src/ext/reqwest.rs
@@ -0,0 +1,8 @@
+use crate::FlowyError;
+use reqwest::Error;
+
+impl std::convert::From<reqwest::Error> for FlowyError {
+ fn from(error: Error) -> Self {
+ FlowyError::connection().context(error)
+ }
+}
diff --git a/frontend/rust-lib/flowy-error/src/ext/serde.rs b/frontend/rust-lib/flowy-error/src/ext/serde.rs
index 2d25aab10d..e8a158f1bb 100644
--- a/frontend/rust-lib/flowy-error/src/ext/serde.rs
+++ b/frontend/rust-lib/flowy-error/src/ext/serde.rs
@@ -2,6 +2,6 @@ use crate::FlowyError;
impl std::convert::From<serde_json::Error> for FlowyError {
fn from(error: serde_json::Error) -> Self {
- FlowyError::internal().context(error)
+ FlowyError::serde().context(error)
}
}
diff --git a/frontend/rust-lib/flowy-error/src/ext/collaborate.rs b/frontend/rust-lib/flowy-error/src/ext/sync.rs
similarity index 58%
rename from frontend/rust-lib/flowy-error/src/ext/collaborate.rs
rename to frontend/rust-lib/flowy-error/src/ext/sync.rs
index f93b2b7bc3..a1f233e1f2 100644
--- a/frontend/rust-lib/flowy-error/src/ext/collaborate.rs
+++ b/frontend/rust-lib/flowy-error/src/ext/sync.rs
@@ -1,9 +1,9 @@
use crate::FlowyError;
-use flowy_sync::errors::ErrorCode;
+use flowy_client_sync::errors::ErrorCode;
-impl std::convert::From<flowy_sync::errors::CollaborateError> for FlowyError {
- fn from(error: flowy_sync::errors::CollaborateError) -> Self {
+impl std::convert::From<flowy_client_sync::errors::SyncError> for FlowyError {
+ fn from(error: flowy_client_sync::errors::SyncError) -> Self {
match error.code {
ErrorCode::RecordNotFound => FlowyError::record_not_found().context(error.msg),
_ => FlowyError::internal().context(error.msg),
diff --git a/frontend/rust-lib/flowy-error/src/ext/user.rs b/frontend/rust-lib/flowy-error/src/ext/user.rs
new file mode 100644
index 0000000000..bef8f9a28f
--- /dev/null
+++ b/frontend/rust-lib/flowy-error/src/ext/user.rs
@@ -0,0 +1,23 @@
+use crate::code::ErrorCode;
+use user_model::errors::UserErrorCode;
+
+impl std::convert::From<UserErrorCode> for ErrorCode {
+ fn from(code: UserErrorCode) -> Self {
+ match code {
+ UserErrorCode::Internal => ErrorCode::Internal,
+ UserErrorCode::WorkspaceIdInvalid => ErrorCode::WorkspaceIdInvalid,
+ UserErrorCode::EmailIsEmpty => ErrorCode::EmailIsEmpty,
+ UserErrorCode::EmailFormatInvalid => ErrorCode::EmailFormatInvalid,
+ UserErrorCode::UserIdInvalid => ErrorCode::UserIdInvalid,
+ UserErrorCode::UserNameContainForbiddenCharacters => ErrorCode::UserNameContainForbiddenCharacters,
+ UserErrorCode::UserNameIsEmpty => ErrorCode::UserNameIsEmpty,
+ UserErrorCode::UserNotExist => ErrorCode::UserNotExist,
+ UserErrorCode::PasswordIsEmpty => ErrorCode::PasswordIsEmpty,
+ UserErrorCode::PasswordTooLong => ErrorCode::PasswordTooLong,
+ UserErrorCode::PasswordContainsForbidCharacters => ErrorCode::PasswordContainsForbidCharacters,
+ UserErrorCode::PasswordFormatInvalid => ErrorCode::PasswordFormatInvalid,
+ UserErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
+ UserErrorCode::UserNameTooLong => ErrorCode::UserNameTooLong,
+ }
+ }
+}
diff --git a/frontend/rust-lib/flowy-error/src/ext/ws.rs b/frontend/rust-lib/flowy-error/src/ext/ws.rs
new file mode 100644
index 0000000000..f877ad1763
--- /dev/null
+++ b/frontend/rust-lib/flowy-error/src/ext/ws.rs
@@ -0,0 +1,10 @@
+use crate::FlowyError;
+use flowy_client_ws::WSErrorCode;
+
+impl std::convert::From<WSErrorCode> for FlowyError {
+ fn from(code: WSErrorCode) -> Self {
+ match code {
+ WSErrorCode::Internal => FlowyError::internal().context(code),
+ }
+ }
+}
diff --git a/frontend/rust-lib/flowy-error/src/lib.rs b/frontend/rust-lib/flowy-error/src/lib.rs
index 08dd533e09..e0cbb86d8f 100644
--- a/frontend/rust-lib/flowy-error/src/lib.rs
+++ b/frontend/rust-lib/flowy-error/src/lib.rs
@@ -1,4 +1,4 @@
-mod code;
+pub mod code;
mod errors;
mod ext;
pub mod protobuf;
diff --git a/frontend/rust-lib/flowy-folder/Cargo.toml b/frontend/rust-lib/flowy-folder/Cargo.toml
index f8ccd76421..61fa2079a3 100644
--- a/frontend/rust-lib/flowy-folder/Cargo.toml
+++ b/frontend/rust-lib/flowy-folder/Cargo.toml
@@ -6,16 +6,17 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-folder-rev-model = { path = "../../../shared-lib/folder-rev-model" }
-flowy-sync = { path = "../flowy-sync"}
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
+folder-model = { path = "../../../shared-lib/folder-model" }
+flowy-client-sync = { path = "../flowy-client-sync"}
+revision-model = { path = "../../../shared-lib/revision-model" }
+ws-model = { path = "../../../shared-lib/ws-model" }
flowy-derive = { path = "../flowy-derive" }
lib-ot = { path = "../../../shared-lib/lib-ot" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
flowy-document = { path = "../flowy-document" }
flowy-database = { path = "../flowy-database", optional = true }
-flowy-error = { path = "../flowy-error", features = ["db", "http_server"]}
+flowy-error = { path = "../flowy-error", features = ["adaptor_database", "adaptor_dispatch"]}
flowy-notification = { path = "../flowy-notification" }
lib-dispatch = { path = "../lib-dispatch" }
flowy-revision = { path = "../flowy-revision" }
diff --git a/frontend/rust-lib/flowy-folder/src/entities/app.rs b/frontend/rust-lib/flowy-folder/src/entities/app.rs
index 9b4e0ae7ee..203feb9a4e 100644
--- a/frontend/rust-lib/flowy-folder/src/entities/app.rs
+++ b/frontend/rust-lib/flowy-folder/src/entities/app.rs
@@ -8,7 +8,7 @@ use crate::{
impl_def_and_def_mut,
};
use flowy_derive::ProtoBuf;
-use folder_rev_model::AppRevision;
+use folder_model::AppRevision;
use std::convert::TryInto;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
diff --git a/frontend/rust-lib/flowy-folder/src/entities/trash.rs b/frontend/rust-lib/flowy-folder/src/entities/trash.rs
index 70d9a64f1a..1846e180f8 100644
--- a/frontend/rust-lib/flowy-folder/src/entities/trash.rs
+++ b/frontend/rust-lib/flowy-folder/src/entities/trash.rs
@@ -1,6 +1,6 @@
use crate::impl_def_and_def_mut;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
-use folder_rev_model::{TrashRevision, TrashTypeRevision};
+use folder_model::{TrashRevision, TrashTypeRevision};
use serde::{Deserialize, Serialize};
use std::fmt::Formatter;
diff --git a/frontend/rust-lib/flowy-folder/src/entities/view.rs b/frontend/rust-lib/flowy-folder/src/entities/view.rs
index 510bfb0925..129f4964bd 100644
--- a/frontend/rust-lib/flowy-folder/src/entities/view.rs
+++ b/frontend/rust-lib/flowy-folder/src/entities/view.rs
@@ -7,7 +7,7 @@ use crate::{
impl_def_and_def_mut,
};
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
-use folder_rev_model::{gen_view_id, ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
+use folder_model::{gen_view_id, ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
use std::convert::TryInto;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
diff --git a/frontend/rust-lib/flowy-folder/src/entities/workspace.rs b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs
index aa45c9e332..63abfd2af3 100644
--- a/frontend/rust-lib/flowy-folder/src/entities/workspace.rs
+++ b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs
@@ -5,7 +5,7 @@ use crate::{
impl_def_and_def_mut,
};
use flowy_derive::ProtoBuf;
-use folder_rev_model::WorkspaceRevision;
+use folder_model::WorkspaceRevision;
use std::convert::TryInto;
#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
diff --git a/frontend/rust-lib/flowy-folder/src/event_map.rs b/frontend/rust-lib/flowy-folder/src/event_map.rs
index 2751a69e87..f6addb6eb4 100644
--- a/frontend/rust-lib/flowy-folder/src/event_map.rs
+++ b/frontend/rust-lib/flowy-folder/src/event_map.rs
@@ -11,7 +11,7 @@ use crate::{
};
use flowy_database::{ConnectionPool, DBConnection};
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
-use folder_rev_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use folder_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
use lib_dispatch::prelude::*;
use lib_infra::future::FutureResult;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs
index 5ad315a32a..fd1c216d91 100644
--- a/frontend/rust-lib/flowy-folder/src/manager.rs
+++ b/frontend/rust-lib/flowy-folder/src/manager.rs
@@ -15,7 +15,7 @@ use bytes::Bytes;
use flowy_document::editor::initial_read_me;
use flowy_error::FlowyError;
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket};
-use folder_rev_model::user_default;
+use folder_model::user_default;
use lazy_static::lazy_static;
use lib_infra::future::FutureResult;
@@ -23,11 +23,11 @@ use crate::services::clear_current_workspace;
use crate::services::persistence::rev_sqlite::{
SQLiteFolderRevisionPersistence, SQLiteFolderRevisionSnapshotPersistence,
};
-use flowy_http_model::ws_data::ServerRevisionWSData;
-use flowy_sync::client_folder::FolderPad;
+use flowy_client_sync::client_folder::FolderPad;
use std::convert::TryFrom;
use std::{collections::HashMap, fmt::Formatter, sync::Arc};
use tokio::sync::RwLock as TokioRwLock;
+use ws_model::ws_revision::ServerRevisionWSData;
lazy_static! {
static ref INIT_FOLDER_FLAG: TokioRwLock<HashMap<String, bool>> = TokioRwLock::new(HashMap::new());
}
diff --git a/frontend/rust-lib/flowy-folder/src/services/app/controller.rs b/frontend/rust-lib/flowy-folder/src/services/app/controller.rs
index 305bf5138b..99de1838d9 100644
--- a/frontend/rust-lib/flowy-folder/src/services/app/controller.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/app/controller.rs
@@ -12,7 +12,7 @@ use crate::{
},
};
-use folder_rev_model::AppRevision;
+use folder_model::AppRevision;
use futures::{FutureExt, StreamExt};
use std::{collections::HashSet, sync::Arc};
diff --git a/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs
index ff70beb9b7..f8aebbaadf 100644
--- a/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs
@@ -3,7 +3,7 @@ use crate::{
errors::FlowyError,
services::{AppController, TrashController, ViewController},
};
-use folder_rev_model::TrashRevision;
+use folder_model::TrashRevision;
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
use std::{convert::TryInto, sync::Arc};
diff --git a/frontend/rust-lib/flowy-folder/src/services/folder_editor.rs b/frontend/rust-lib/flowy-folder/src/services/folder_editor.rs
index 4743996cf3..605e349fee 100644
--- a/frontend/rust-lib/flowy-folder/src/services/folder_editor.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/folder_editor.rs
@@ -1,20 +1,20 @@
use crate::manager::FolderId;
use bytes::Bytes;
+use flowy_client_sync::client_folder::{FolderChangeset, FolderOperations, FolderPad};
+use flowy_client_sync::make_operations_from_revisions;
+use flowy_client_sync::util::recover_operation_from_revisions;
use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
-use flowy_http_model::ws_data::ServerRevisionWSData;
use flowy_revision::{
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
RevisionWebSocket,
};
-use flowy_sync::client_folder::{FolderChangeset, FolderPad};
-use flowy_sync::server_folder::FolderOperations;
-use flowy_sync::util::{make_operations_from_revisions, recover_operation_from_revisions};
use lib_infra::future::FutureResult;
use lib_ot::core::EmptyAttributes;
use parking_lot::RwLock;
+use revision_model::Revision;
use std::sync::Arc;
+use ws_model::ws_revision::ServerRevisionWSData;
pub struct FolderEditor {
#[allow(dead_code)]
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/migration.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/migration.rs
index dde3f16702..fbe4ee1226 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/migration.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/migration.rs
@@ -4,17 +4,16 @@ use crate::{
services::persistence::{AppTableSql, TrashTableSql, ViewTableSql, WorkspaceTableSql},
};
use bytes::Bytes;
+use flowy_client_sync::client_folder::FolderPad;
+use flowy_client_sync::client_folder::{make_folder_rev_json_str, FolderOperationsBuilder};
use flowy_database::kv::KV;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision::reset::{RevisionResettable, RevisionStructReset};
-use flowy_sync::client_folder::make_folder_rev_json_str;
-use flowy_sync::client_folder::FolderPad;
-use flowy_sync::server_folder::FolderOperationsBuilder;
-use folder_rev_model::{AppRevision, FolderRevision, ViewRevision, WorkspaceRevision};
+use folder_model::{AppRevision, FolderRevision, ViewRevision, WorkspaceRevision};
+use revision_model::Revision;
use crate::services::persistence::rev_sqlite::SQLiteFolderRevisionPersistence;
-use flowy_http_model::util::md5;
+use lib_infra::util::md5;
use std::sync::Arc;
const V1_MIGRATION: &str = "FOLDER_V1_MIGRATION";
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs
index b68bf27fe8..6f6dcac005 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs
@@ -9,13 +9,12 @@ use crate::{
manager::FolderId,
services::{folder_editor::FolderEditor, persistence::migration::FolderMigration},
};
+use flowy_client_sync::client_folder::{FolderOperationsBuilder, FolderPad};
use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision_persistence::{RevisionDiskCache, RevisionState, SyncRecord};
-use flowy_sync::client_folder::FolderPad;
-use flowy_sync::server_folder::FolderOperationsBuilder;
-use folder_rev_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use folder_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use revision_model::Revision;
use std::sync::Arc;
use tokio::sync::RwLock;
pub use version_1::{app_sql::*, trash_sql::*, v1_impl::V1Transaction, view_sql::*, workspace_sql::*};
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/rev_sqlite/folder_rev_sqlite.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/rev_sqlite/folder_rev_sqlite.rs
index 0ca3167ed2..3f3ceb2608 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/rev_sqlite/folder_rev_sqlite.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/rev_sqlite/folder_rev_sqlite.rs
@@ -7,9 +7,9 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::util::md5;
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::sync::Arc;
pub struct SQLiteFolderRevisionPersistence {
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs
index 3853ef46df..e8d8a510ea 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs
@@ -8,7 +8,7 @@ use flowy_database::{
schema::{app_table, app_table::dsl},
SqliteConnection,
};
-use folder_rev_model::AppRevision;
+use folder_model::AppRevision;
pub struct AppTableSql();
impl AppTableSql {
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs
index c9d04c0404..5833f3ce08 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs
@@ -5,7 +5,7 @@ use flowy_database::{
schema::{trash_table, trash_table::dsl},
SqliteConnection,
};
-use folder_rev_model::{TrashRevision, TrashTypeRevision};
+use folder_model::{TrashRevision, TrashTypeRevision};
pub struct TrashTableSql();
impl TrashTableSql {
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs
index b9dd9809d5..099cdc2cca 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs
@@ -8,7 +8,7 @@ use crate::services::persistence::{
};
use flowy_database::DBConnection;
use flowy_error::FlowyResult;
-use folder_rev_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use folder_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
/// V1Transaction is deprecated since version 0.0.2 version
pub struct V1Transaction<'a>(pub &'a DBConnection);
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs
index 29f0303b5d..0131b0f9fa 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs
@@ -13,7 +13,7 @@ use flowy_database::{
SqliteConnection,
};
-use folder_rev_model::{ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
+use folder_model::{ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
use lib_infra::util::timestamp;
pub struct ViewTableSql();
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/workspace_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/workspace_sql.rs
index b857fdcfaf..1ed62ff433 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/workspace_sql.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/workspace_sql.rs
@@ -4,7 +4,7 @@ use flowy_database::{
prelude::*,
schema::{workspace_table, workspace_table::dsl},
};
-use folder_rev_model::WorkspaceRevision;
+use folder_model::WorkspaceRevision;
pub(crate) struct WorkspaceTableSql();
impl WorkspaceTableSql {
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_2/v2_impl.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_2/v2_impl.rs
index 14ef18f5c6..57f3b75ea4 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_2/v2_impl.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_2/v2_impl.rs
@@ -3,7 +3,7 @@ use crate::services::{
persistence::{AppChangeset, FolderPersistenceTransaction, ViewChangeset, WorkspaceChangeset},
};
use flowy_error::{FlowyError, FlowyResult};
-use folder_rev_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
+use folder_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
use std::sync::Arc;
impl FolderPersistenceTransaction for FolderEditor {
diff --git a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs
index f8b40b6156..a90209d516 100644
--- a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs
@@ -6,7 +6,7 @@ use crate::{
services::persistence::{FolderPersistence, FolderPersistenceTransaction},
};
-use folder_rev_model::TrashRevision;
+use folder_model::TrashRevision;
use std::{fmt::Formatter, sync::Arc};
use tokio::sync::{broadcast, mpsc};
diff --git a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs
index 8d35dbae98..b80a50c0e6 100644
--- a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs
@@ -16,8 +16,7 @@ use crate::{
};
use bytes::Bytes;
use flowy_database::kv::KV;
-use flowy_http_model::document::DocumentId;
-use folder_rev_model::{gen_view_id, ViewRevision};
+use folder_model::{gen_view_id, ViewRevision};
use futures::{FutureExt, StreamExt};
use std::{collections::HashSet, sync::Arc};
@@ -199,9 +198,8 @@ impl ViewController {
Ok(())
}
- #[tracing::instrument(level = "debug", skip(self,params), fields(doc_id = %params.value), err)]
- pub(crate) async fn move_view_to_trash(&self, params: DocumentId) -> Result<(), FlowyError> {
- let view_id = params.value;
+ #[tracing::instrument(level = "debug", skip(self), err)]
+ pub(crate) async fn move_view_to_trash(&self, view_id: &str) -> Result<(), FlowyError> {
if let Some(latest_view_id) = KV::get_str(LATEST_VIEW_ID) {
if latest_view_id == view_id {
let _ = KV::remove(LATEST_VIEW_ID);
@@ -219,7 +217,7 @@ impl ViewController {
.position(|view| view.id == view_id)
.map(|index| index as i32);
Ok(DeletedViewPB {
- view_id: view_id.clone(),
+ view_id: view_id.to_owned(),
index,
})
})
diff --git a/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs
index 94b2335f9f..a1dabf6cb1 100644
--- a/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs
@@ -13,7 +13,7 @@ use crate::{
errors::FlowyError,
services::{TrashController, ViewController},
};
-use folder_rev_model::TrashRevision;
+use folder_model::TrashRevision;
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
use std::{convert::TryInto, sync::Arc};
@@ -62,7 +62,7 @@ pub(crate) async fn delete_view_handler(
) -> Result<(), FlowyError> {
let params: RepeatedViewIdPB = data.into_inner();
for view_id in &params.items {
- let _ = view_controller.move_view_to_trash(view_id.into()).await;
+ let _ = view_controller.move_view_to_trash(&view_id).await;
}
let trash = view_controller
diff --git a/frontend/rust-lib/flowy-folder/src/services/web_socket.rs b/frontend/rust-lib/flowy-folder/src/services/web_socket.rs
index 6eb168d732..eac9e81e7b 100644
--- a/frontend/rust-lib/flowy-folder/src/services/web_socket.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/web_socket.rs
@@ -1,17 +1,16 @@
use crate::services::FOLDER_SYNC_INTERVAL_IN_MILLIS;
use bytes::Bytes;
+use flowy_client_sync::client_folder::{FolderOperations, FolderPad};
+use flowy_client_sync::make_operations_from_revisions;
use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::ws_data::{ClientRevisionWSData, NewDocumentUser};
use flowy_revision::*;
-use flowy_sync::client_folder::FolderPad;
-use flowy_sync::server_folder::FolderOperations;
-use flowy_sync::util::make_operations_from_revisions;
use lib_infra::future::{BoxResultFuture, FutureResult};
use lib_ot::core::OperationTransform;
use parking_lot::RwLock;
+use revision_model::{Revision, RevisionRange};
use std::{sync::Arc, time::Duration};
+use ws_model::ws_revision::{ClientRevisionWSData, NewDocumentUser};
#[derive(Clone)]
pub struct FolderResolveOperations(pub FolderOperations);
diff --git a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs
index 5f4b393521..ef17d0166b 100644
--- a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs
@@ -10,7 +10,7 @@ use crate::{
},
};
use flowy_database::kv::KV;
-use folder_rev_model::{AppRevision, WorkspaceRevision};
+use folder_model::{AppRevision, WorkspaceRevision};
use std::sync::Arc;
pub struct WorkspaceController {
diff --git a/frontend/rust-lib/flowy-grid/Cargo.toml b/frontend/rust-lib/flowy-grid/Cargo.toml
index 2d2017c734..9d5db23553 100644
--- a/frontend/rust-lib/flowy-grid/Cargo.toml
+++ b/frontend/rust-lib/flowy-grid/Cargo.toml
@@ -11,13 +11,13 @@ flowy-notification = { path = "../flowy-notification" }
flowy-revision = { path = "../flowy-revision" }
flowy-revision-persistence = { path = "../flowy-revision-persistence" }
flowy-task= { path = "../flowy-task" }
-flowy-error = { path = "../flowy-error", features = ["db"]}
+flowy-error = { path = "../flowy-error", features = ["adaptor_database", "adaptor_dispatch"]}
flowy-derive = { path = "../flowy-derive" }
lib-ot = { path = "../../../shared-lib/lib-ot" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
-grid-rev-model = { path = "../../../shared-lib/grid-rev-model" }
-flowy-sync = { path = "../flowy-sync"}
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
+grid-model = { path = "../../../shared-lib/grid-model" }
+flowy-client-sync = { path = "../flowy-client-sync"}
+revision-model = { path = "../../../shared-lib/revision-model" }
flowy-database = { path = "../flowy-database", optional = true }
anyhow = "1.0"
diff --git a/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs
index 256e7ce5b1..e0ed5b9458 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs
@@ -2,7 +2,7 @@ use crate::entities::parser::NotEmptyStr;
use crate::entities::FieldType;
use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode;
-use grid_rev_model::{CellRevision, RowChangeset};
+use grid_model::{CellRevision, RowChangeset};
use std::collections::HashMap;
#[derive(ProtoBuf, Default)]
diff --git a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs
index 5e54701551..b36c09c0c1 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs
@@ -1,6 +1,6 @@
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::{FieldRevision, FieldTypeRevision};
+use grid_model::{FieldRevision, FieldTypeRevision};
use serde_repr::*;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs
index b7a30ce1af..2bf847ffb0 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs
@@ -1,7 +1,7 @@
use crate::services::filter::FromFilterString;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::FilterRevision;
+use grid_model::FilterRevision;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct CheckboxFilterPB {
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs
index 91b902eb46..1e7fe95500 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs
@@ -1,7 +1,7 @@
use crate::services::filter::FromFilterString;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::FilterRevision;
+use grid_model::FilterRevision;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct ChecklistFilterPB {
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs
index cdf40b9f8a..950dfb1f1c 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs
@@ -1,7 +1,7 @@
use crate::services::filter::FromFilterString;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::FilterRevision;
+use grid_model::FilterRevision;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs
index b8ad9a0da4..357a2600da 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs
@@ -1,7 +1,7 @@
use crate::services::filter::FromFilterString;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::FilterRevision;
+use grid_model::FilterRevision;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct NumberFilterPB {
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs
index 75ddcb34a7..88838dcbb2 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs
@@ -2,7 +2,7 @@ use crate::services::field::SelectOptionIds;
use crate::services::filter::FromFilterString;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::FilterRevision;
+use grid_model::FilterRevision;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct SelectOptionFilterPB {
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs
index 079efa426a..c5755734ef 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs
@@ -1,7 +1,7 @@
use crate::services::filter::FromFilterString;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::FilterRevision;
+use grid_model::FilterRevision;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct TextFilterPB {
diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs
index fcd3c4fca6..bbf9747d8c 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs
@@ -8,7 +8,7 @@ use crate::services::filter::FilterType;
use bytes::Bytes;
use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode;
-use grid_rev_model::{FieldRevision, FieldTypeRevision, FilterRevision};
+use grid_model::{FieldRevision, FieldTypeRevision, FilterRevision};
use std::convert::TryInto;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/entities/group_entities/configuration.rs b/frontend/rust-lib/flowy-grid/src/entities/group_entities/configuration.rs
index c3b08af328..28ab331798 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/group_entities/configuration.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/group_entities/configuration.rs
@@ -1,5 +1,5 @@
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
-use grid_rev_model::{GroupRevision, SelectOptionGroupConfigurationRevision};
+use grid_model::{GroupRevision, SelectOptionGroupConfigurationRevision};
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct UrlGroupConfigurationPB {
diff --git a/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs b/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs
index 7a09581979..a05d9de1ef 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs
@@ -3,7 +3,7 @@ use crate::entities::{CreateRowParams, FieldType, GridLayout, RowPB};
use crate::services::group::Group;
use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode;
-use grid_rev_model::{FieldTypeRevision, GroupConfigurationRevision};
+use grid_model::{FieldTypeRevision, GroupConfigurationRevision};
use std::convert::TryInto;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs
index 9b52aad506..64d92e2818 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs
@@ -2,7 +2,7 @@ use crate::entities::parser::NotEmptyStr;
use crate::entities::GridLayout;
use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode;
-use grid_rev_model::RowRevision;
+use grid_model::RowRevision;
use std::sync::Arc;
/// [RowPB] Describes a row. Has the id of the parent Block. Has the metadata of the row.
diff --git a/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs
index f2a9f92218..8d4d4fad1b 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs
@@ -6,7 +6,7 @@ use crate::entities::{
};
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::LayoutRevision;
+use grid_model::LayoutRevision;
use std::convert::TryInto;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
diff --git a/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs
index 9a9dc33251..af1774a3f9 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs
@@ -5,7 +5,7 @@ use std::sync::Arc;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode;
-use grid_rev_model::{FieldTypeRevision, SortCondition, SortRevision};
+use grid_model::{FieldTypeRevision, SortCondition, SortRevision};
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct SortPB {
diff --git a/frontend/rust-lib/flowy-grid/src/event_handler.rs b/frontend/rust-lib/flowy-grid/src/event_handler.rs
index 59c7e45a6a..f553de447f 100644
--- a/frontend/rust-lib/flowy-grid/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-grid/src/event_handler.rs
@@ -9,7 +9,7 @@ use crate::services::field::{
};
use crate::services::row::make_row_from_row_rev;
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
-use grid_rev_model::FieldRevision;
+use grid_model::FieldRevision;
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/manager.rs b/frontend/rust-lib/flowy-grid/src/manager.rs
index 99ade3bfa3..94e185e9f5 100644
--- a/frontend/rust-lib/flowy-grid/src/manager.rs
+++ b/frontend/rust-lib/flowy-grid/src/manager.rs
@@ -7,14 +7,14 @@ use crate::services::persistence::rev_sqlite::{SQLiteGridRevisionPersistence, SQ
use crate::services::persistence::GridDatabase;
use crate::services::view_editor::make_grid_view_rev_manager;
use bytes::Bytes;
+use flowy_client_sync::client_grid::{make_grid_block_operations, make_grid_operations, make_grid_view_operations};
use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket};
-use flowy_sync::client_grid::{make_grid_block_operations, make_grid_operations, make_grid_view_operations};
-use grid_rev_model::{BuildGridContext, GridRevision, GridViewRevision};
+use grid_model::{BuildGridContext, GridRevision, GridViewRevision};
use lib_infra::async_trait::async_trait;
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
+use revision_model::Revision;
use crate::services::block_manager::make_grid_block_rev_manager;
use flowy_task::TaskDispatcher;
diff --git a/frontend/rust-lib/flowy-grid/src/services/block_editor.rs b/frontend/rust-lib/flowy-grid/src/services/block_editor.rs
index 2201a7bb65..69b4b0d3bb 100644
--- a/frontend/rust-lib/flowy-grid/src/services/block_editor.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/block_editor.rs
@@ -1,16 +1,15 @@
use bytes::Bytes;
+use flowy_client_sync::client_grid::{GridBlockRevisionChangeset, GridBlockRevisionPad};
+use flowy_client_sync::make_operations_from_revisions;
+use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision::{
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
};
-use flowy_sync::client_grid::{GridBlockRevisionChangeset, GridBlockRevisionPad};
-use flowy_sync::util::make_operations_from_revisions;
-use grid_rev_model::{CellRevision, GridBlockRevision, RowChangeset, RowRevision};
+use grid_model::{CellRevision, GridBlockRevision, RowChangeset, RowRevision};
use lib_infra::future::FutureResult;
-
-use flowy_database::ConnectionPool;
use lib_ot::core::EmptyAttributes;
+use revision_model::Revision;
use std::borrow::Cow;
use std::sync::Arc;
use tokio::sync::RwLock;
diff --git a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs
index 06f24dab2a..d811da4688 100644
--- a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs
@@ -11,7 +11,7 @@ use dashmap::DashMap;
use flowy_database::ConnectionPool;
use flowy_error::FlowyResult;
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
-use grid_rev_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
+use grid_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs b/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs
index a97b72ba16..7f00b2abca 100644
--- a/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs
@@ -3,7 +3,7 @@ use crate::services::cell::{AtomicCellDataCache, CellProtobufBlob, TypeCellData}
use crate::services::field::*;
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
-use grid_rev_model::{CellRevision, FieldRevision};
+use grid_model::{CellRevision, FieldRevision};
use std::fmt::Debug;
diff --git a/frontend/rust-lib/flowy-grid/src/services/cell/type_cell_data.rs b/frontend/rust-lib/flowy-grid/src/services/cell/type_cell_data.rs
index 16f02eff1b..db48da229a 100644
--- a/frontend/rust-lib/flowy-grid/src/services/cell/type_cell_data.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/cell/type_cell_data.rs
@@ -2,7 +2,7 @@ use crate::entities::FieldType;
use bytes::Bytes;
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use grid_rev_model::CellRevision;
+use grid_model::CellRevision;
use serde::{Deserialize, Serialize};
/// TypeCellData is a generic CellData, you can parse the type_cell_data according to the field_type.
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs b/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs
index 5f232d1232..c32df6cdc9 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs
@@ -2,7 +2,7 @@ use crate::entities::{FieldPB, FieldType};
use crate::services::field::{default_type_option_builder_from_type, TypeOptionBuilder};
-use grid_rev_model::FieldRevision;
+use grid_model::FieldRevision;
use indexmap::IndexMap;
pub struct FieldBuilder {
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/field_operation.rs b/frontend/rust-lib/flowy-grid/src/services/field/field_operation.rs
index 60f9f1702c..0c79e84166 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/field_operation.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/field_operation.rs
@@ -1,7 +1,7 @@
use crate::services::field::{MultiSelectTypeOptionPB, SingleSelectTypeOptionPB};
use crate::services::grid_editor::GridRevisionEditor;
use flowy_error::FlowyResult;
-use grid_rev_model::{TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{TypeOptionDataDeserializer, TypeOptionDataSerializer};
use std::sync::Arc;
pub async fn edit_field_type_option<T>(
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_option_builder.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_option_builder.rs
index 112903100d..f01209fe05 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_option_builder.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_option_builder.rs
@@ -1,7 +1,7 @@
use crate::entities::FieldType;
use crate::services::field::type_options::*;
use bytes::Bytes;
-use grid_rev_model::TypeOptionDataSerializer;
+use grid_model::TypeOptionDataSerializer;
pub trait TypeOptionBuilder {
/// Returns the type of the type-option data
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_tests.rs
index aca97d9344..1883b82098 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_tests.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_tests.rs
@@ -5,7 +5,7 @@ mod tests {
use crate::services::field::type_options::checkbox_type_option::*;
use crate::services::field::FieldBuilder;
- use grid_rev_model::FieldRevision;
+ use grid_model::FieldRevision;
#[test]
fn checkout_box_description_test() {
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs
index d29b205756..f1ea58e0ea 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs
@@ -8,7 +8,7 @@ use crate::services::field::{
use bytes::Bytes;
use flowy_derive::ProtoBuf;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::str::FromStr;
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs
index 44e459dbd5..58bb327448 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs
@@ -7,7 +7,7 @@ mod tests {
// use crate::services::field::{DateCellChangeset, DateCellData, DateFormat, DateTypeOptionPB, TimeFormat};
use chrono::format::strftime::StrftimeItems;
use chrono::{FixedOffset, NaiveDateTime};
- use grid_rev_model::FieldRevision;
+ use grid_model::FieldRevision;
use strum::IntoEnumIterator;
#[test]
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs
index d7eb7c4775..8406e32dcf 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs
@@ -11,7 +11,7 @@ use chrono::format::strftime::StrftimeItems;
use chrono::{NaiveDateTime, Timelike};
use flowy_derive::ProtoBuf;
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_tests.rs
index fa9c2a8df4..ac73756264 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_tests.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_tests.rs
@@ -5,7 +5,7 @@ mod tests {
use crate::services::field::FieldBuilder;
use crate::services::field::{strip_currency_symbol, NumberFormat, NumberTypeOptionPB};
- use grid_rev_model::FieldRevision;
+ use grid_model::FieldRevision;
use strum::IntoEnumIterator;
/// Testing when the input is not a number.
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_type_option.rs
index 5c2b15704a..22057167f1 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_type_option.rs
@@ -10,7 +10,7 @@ use bytes::Bytes;
use fancy_regex::Regex;
use flowy_derive::ProtoBuf;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use lazy_static::lazy_static;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_type_option.rs
index 0434f7a972..0ab1b907f0 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_type_option.rs
@@ -9,7 +9,7 @@ use crate::services::field::{
use bytes::Bytes;
use flowy_derive::ProtoBuf;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs
index 613f93256e..13179b91a0 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs
@@ -11,7 +11,7 @@ use crate::services::field::{
use bytes::Bytes;
use flowy_derive::ProtoBuf;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use serde::{Deserialize, Serialize};
// Multiple select
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_type_option.rs
index 9565394fd3..418802c0e1 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_type_option.rs
@@ -13,7 +13,7 @@ use crate::services::field::{
use bytes::Bytes;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::{internal_error, ErrorCode, FlowyResult};
-use grid_rev_model::{FieldRevision, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataSerializer};
use nanoid::nanoid;
use serde::{Deserialize, Serialize};
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs
index 1369628c0c..3fa6897f8e 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs
@@ -13,7 +13,7 @@ use crate::services::field::{
use bytes::Bytes;
use flowy_derive::ProtoBuf;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use serde::{Deserialize, Serialize};
// Single select
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/type_option_transform.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/type_option_transform.rs
index 9b05442a39..f699ce5bb5 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/type_option_transform.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/type_option_transform.rs
@@ -5,7 +5,7 @@ use crate::services::field::{
SingleSelectTypeOptionPB, TypeOption, CHECK, UNCHECK,
};
-use grid_rev_model::TypeOptionDataDeserializer;
+use grid_model::TypeOptionDataDeserializer;
/// Handles how to transform the cell data when switching between different field types
pub(crate) struct SelectOptionTypeOptionTransformHelper();
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs
index b624632e98..5ecf67dd84 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs
@@ -11,7 +11,7 @@ use crate::services::field::{
use bytes::Bytes;
use flowy_derive::ProtoBuf;
use flowy_error::{FlowyError, FlowyResult};
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use protobuf::ProtobufError;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option.rs
index 6318f669d1..f10025b84e 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option.rs
@@ -4,7 +4,7 @@ use crate::services::cell::{CellDataDecoder, FromCellChangesetString, FromCellSt
use crate::services::filter::FromFilterString;
use bytes::Bytes;
use flowy_error::FlowyResult;
-use grid_rev_model::FieldRevision;
+use grid_model::FieldRevision;
use protobuf::ProtobufError;
use std::cmp::Ordering;
use std::fmt::Debug;
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option_cell.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option_cell.rs
index 6420d6c153..619ef7f01b 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option_cell.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/type_option_cell.rs
@@ -10,7 +10,7 @@ use crate::services::field::{
};
use crate::services::filter::FilterType;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use std::any::Any;
use std::cmp::Ordering;
use std::collections::hash_map::DefaultHasher;
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs
index bf9a183ec1..3b55ff1acb 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs
@@ -5,7 +5,7 @@ mod tests {
use crate::services::field::FieldBuilder;
use crate::services::field::URLTypeOptionPB;
- use grid_rev_model::FieldRevision;
+ use grid_model::FieldRevision;
/// The expected_str will equal to the input string, but the expected_url will be empty if there's no
/// http url in the input string.
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs
index 90ccefd022..b4518c1685 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs
@@ -9,7 +9,7 @@ use bytes::Bytes;
use fancy_regex::Regex;
use flowy_derive::ProtoBuf;
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
+use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
diff --git a/frontend/rust-lib/flowy-grid/src/services/filter/controller.rs b/frontend/rust-lib/flowy-grid/src/services/filter/controller.rs
index 570cc020a0..65bbbe5daa 100644
--- a/frontend/rust-lib/flowy-grid/src/services/filter/controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/filter/controller.rs
@@ -7,7 +7,7 @@ use crate::services::row::GridBlockRowRevision;
use crate::services::view_editor::{GridViewChanged, GridViewChangedNotifier};
use flowy_error::FlowyResult;
use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
-use grid_rev_model::{CellRevision, FieldId, FieldRevision, FilterRevision, RowRevision};
+use grid_model::{CellRevision, FieldId, FieldRevision, FilterRevision, RowRevision};
use lib_infra::future::Fut;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
diff --git a/frontend/rust-lib/flowy-grid/src/services/filter/entities.rs b/frontend/rust-lib/flowy-grid/src/services/filter/entities.rs
index 86776455c1..f685d114ac 100644
--- a/frontend/rust-lib/flowy-grid/src/services/filter/entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/filter/entities.rs
@@ -1,5 +1,5 @@
use crate::entities::{AlterFilterParams, DeleteFilterParams, FieldType, GridSettingChangesetParams, InsertedRowPB};
-use grid_rev_model::{FieldRevision, FieldTypeRevision};
+use grid_model::{FieldRevision, FieldTypeRevision};
use std::sync::Arc;
#[derive(Debug)]
diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
index 8b5144daae..bc2b2b3451 100644
--- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
@@ -18,21 +18,21 @@ use crate::services::persistence::block_index::BlockIndexCache;
use crate::services::row::{GridBlockRow, GridBlockRowRevision, RowRevisionBuilder};
use crate::services::view_editor::{GridViewChanged, GridViewManager};
use bytes::Bytes;
+use flowy_client_sync::client_grid::{GridRevisionChangeset, GridRevisionPad, JsonDeserializer};
+use flowy_client_sync::errors::{SyncError, SyncResult};
use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision::{
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
};
-use flowy_sync::client_grid::{GridRevisionChangeset, GridRevisionPad, JsonDeserializer};
-use flowy_sync::errors::{CollaborateError, CollaborateResult};
-use flowy_sync::util::make_operations_from_revisions;
use flowy_task::TaskDispatcher;
-use grid_rev_model::*;
+use grid_model::*;
use lib_infra::future::{to_fut, FutureResult};
use lib_ot::core::EmptyAttributes;
+use revision_model::Revision;
use std::collections::HashMap;
+use flowy_client_sync::make_operations_from_revisions;
use std::sync::Arc;
use tokio::sync::{broadcast, RwLock};
@@ -235,7 +235,7 @@ impl GridRevisionEditor {
let old_field_rev = self.get_field_rev(field_id).await;
self.modify(|grid| {
let changeset = grid.modify_field(field_id, |field_rev| {
- f(field_rev).map_err(|e| CollaborateError::internal().context(e))
+ f(field_rev).map_err(|e| SyncError::internal().context(e))
})?;
is_changed = changeset.is_some();
Ok(changeset)
@@ -920,7 +920,7 @@ impl RevisionMergeable for GridRevisionMergeable {
struct TypeOptionJsonDeserializer(FieldType);
impl JsonDeserializer for TypeOptionJsonDeserializer {
- fn deserialize(&self, type_option_data: Vec<u8>) -> CollaborateResult<String> {
+ fn deserialize(&self, type_option_data: Vec<u8>) -> SyncResult<String> {
// The type_option_data sent from Dart is serialized by protobuf.
let builder = type_option_builder_from_bytes(type_option_data, &self.0);
let json = builder.serializer().json_str();
diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor_trait_impl.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor_trait_impl.rs
index 0a6902c243..950e640494 100644
--- a/frontend/rust-lib/flowy-grid/src/services/grid_editor_trait_impl.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor_trait_impl.rs
@@ -5,9 +5,9 @@ use crate::services::field::{TypeOptionCellDataHandler, TypeOptionCellExt};
use crate::services::row::GridBlockRowRevision;
use crate::services::view_editor::GridViewEditorDelegate;
-use flowy_sync::client_grid::GridRevisionPad;
+use flowy_client_sync::client_grid::GridRevisionPad;
use flowy_task::TaskDispatcher;
-use grid_rev_model::{FieldRevision, RowRevision};
+use grid_model::{FieldRevision, RowRevision};
use lib_infra::future::{to_fut, Fut};
use std::sync::Arc;
use tokio::sync::RwLock;
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/action.rs b/frontend/rust-lib/flowy-grid/src/services/group/action.rs
index a57ee6492e..fe739f123c 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/action.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/action.rs
@@ -3,7 +3,7 @@ use crate::services::cell::DecodedCellData;
use crate::services::group::controller::MoveGroupRowContext;
use crate::services::group::Group;
use flowy_error::FlowyResult;
-use grid_rev_model::{CellRevision, FieldRevision, RowRevision};
+use grid_model::{CellRevision, FieldRevision, RowRevision};
use std::sync::Arc;
/// Using polymorphism to provides the customs action for different group controller.
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs b/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs
index 4aa0999156..86085ad613 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs
@@ -2,7 +2,7 @@ use crate::entities::{GroupPB, GroupViewChangesetPB};
use crate::services::field::RowSingleCellData;
use crate::services::group::{default_group_configuration, GeneratedGroupContext, Group};
use flowy_error::{FlowyError, FlowyResult};
-use grid_rev_model::{
+use grid_model::{
FieldRevision, FieldTypeRevision, GroupConfigurationContentSerde, GroupConfigurationRevision, GroupRevision,
};
use indexmap::IndexMap;
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs
index 9ef69c23f0..34398812ea 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs
@@ -4,7 +4,7 @@ use crate::services::group::action::{GroupControllerCustomActions, GroupControll
use crate::services::group::configuration::GroupContext;
use crate::services::group::entities::Group;
use flowy_error::FlowyResult;
-use grid_rev_model::{
+use grid_model::{
FieldRevision, GroupConfigurationContentSerde, GroupRevision, RowChangeset, RowRevision, TypeOptionDataDeserializer,
};
use std::marker::PhantomData;
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs
index d021847eea..e8466e9141 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs
@@ -8,7 +8,7 @@ use crate::services::group::controller::{
use crate::services::cell::insert_checkbox_cell;
use crate::services::group::{move_group_row, GeneratedGroupConfig, GeneratedGroupContext};
-use grid_rev_model::{CellRevision, CheckboxGroupConfigurationRevision, FieldRevision, GroupRevision, RowRevision};
+use grid_model::{CellRevision, CheckboxGroupConfigurationRevision, FieldRevision, GroupRevision, RowRevision};
pub type CheckboxGroupController = GenericGroupController<
CheckboxGroupConfigurationRevision,
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs
index 47b536c443..3d74a47c3c 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs
@@ -2,7 +2,7 @@ use crate::entities::{GroupRowsNotificationPB, GroupViewChangesetPB, RowPB};
use crate::services::group::action::GroupControllerSharedActions;
use crate::services::group::{Group, GroupController, MoveGroupRowContext};
use flowy_error::FlowyResult;
-use grid_rev_model::{FieldRevision, RowRevision};
+use grid_model::{FieldRevision, RowRevision};
use std::sync::Arc;
/// A [DefaultGroupController] is used to handle the group actions for the [FieldType] that doesn't
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs
index 298e05affa..0fe22fc0d6 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs
@@ -9,7 +9,7 @@ use crate::services::group::controller::{
use crate::services::group::controller_impls::select_option_controller::util::*;
use crate::services::group::{make_no_status_group, GeneratedGroupContext};
-use grid_rev_model::{FieldRevision, RowRevision, SelectOptionGroupConfigurationRevision};
+use grid_model::{FieldRevision, RowRevision, SelectOptionGroupConfigurationRevision};
// MultiSelect
pub type MultiSelectGroupController = GenericGroupController<
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs
index 0f3f671c8f..d9c16d8e2d 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs
@@ -10,7 +10,7 @@ use crate::services::group::controller_impls::select_option_controller::util::*;
use crate::services::group::entities::Group;
use crate::services::group::{make_no_status_group, GeneratedGroupContext};
-use grid_rev_model::{FieldRevision, RowRevision, SelectOptionGroupConfigurationRevision};
+use grid_model::{FieldRevision, RowRevision, SelectOptionGroupConfigurationRevision};
// SingleSelect
pub type SingleSelectGroupController = GenericGroupController<
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs
index 9658d1d84f..51f506dc59 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs
@@ -4,7 +4,7 @@ use crate::services::field::{SelectOptionCellDataPB, SelectOptionPB, CHECK};
use crate::services::group::configuration::GroupContext;
use crate::services::group::controller::MoveGroupRowContext;
use crate::services::group::{GeneratedGroupConfig, Group};
-use grid_rev_model::{CellRevision, FieldRevision, GroupRevision, RowRevision, SelectOptionGroupConfigurationRevision};
+use grid_model::{CellRevision, FieldRevision, GroupRevision, RowRevision, SelectOptionGroupConfigurationRevision};
pub type SelectOptionGroupContext = GroupContext<SelectOptionGroupConfigurationRevision>;
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/url_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/url_controller.rs
index f64a968c25..4df0de982c 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/url_controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/url_controller.rs
@@ -7,7 +7,7 @@ use crate::services::group::controller::{
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
};
use crate::services::group::{make_no_status_group, move_group_row, GeneratedGroupConfig, GeneratedGroupContext};
-use grid_rev_model::{CellRevision, FieldRevision, GroupRevision, RowRevision, URLGroupConfigurationRevision};
+use grid_model::{CellRevision, FieldRevision, GroupRevision, RowRevision, URLGroupConfigurationRevision};
pub type URLGroupController =
GenericGroupController<URLGroupConfigurationRevision, URLTypeOptionPB, URLGroupGenerator, URLCellDataParser>;
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/group_util.rs b/frontend/rust-lib/flowy-grid/src/services/group/group_util.rs
index d1200eade5..eb984cd9a2 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/group_util.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/group_util.rs
@@ -7,7 +7,7 @@ use crate::services::group::{
URLGroupController,
};
use flowy_error::FlowyResult;
-use grid_rev_model::{
+use grid_model::{
CheckboxGroupConfigurationRevision, DateGroupConfigurationRevision, FieldRevision, GroupConfigurationRevision,
GroupRevision, LayoutRevision, NumberGroupConfigurationRevision, RowRevision,
SelectOptionGroupConfigurationRevision, TextGroupConfigurationRevision, URLGroupConfigurationRevision,
diff --git a/frontend/rust-lib/flowy-grid/src/services/persistence/migration.rs b/frontend/rust-lib/flowy-grid/src/services/persistence/migration.rs
index 8e0b569462..c9e730e7b7 100644
--- a/frontend/rust-lib/flowy-grid/src/services/persistence/migration.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/persistence/migration.rs
@@ -2,13 +2,13 @@ use crate::manager::GridUser;
use crate::services::persistence::rev_sqlite::SQLiteGridRevisionPersistence;
use crate::services::persistence::GridDatabase;
use bytes::Bytes;
+use flowy_client_sync::client_grid::{make_grid_rev_json_str, GridOperationsBuilder, GridRevisionPad};
use flowy_database::kv::KV;
use flowy_error::FlowyResult;
-use flowy_http_model::revision::Revision;
-use flowy_http_model::util::md5;
use flowy_revision::reset::{RevisionResettable, RevisionStructReset};
-use flowy_sync::client_grid::{make_grid_rev_json_str, GridOperationsBuilder, GridRevisionPad};
-use grid_rev_model::GridRevision;
+use grid_model::GridRevision;
+use lib_infra::util::md5;
+use revision_model::Revision;
use std::sync::Arc;
const V1_MIGRATION: &str = "GRID_V1_MIGRATION";
diff --git a/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_block_sqlite_impl.rs b/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_block_sqlite_impl.rs
index 11a10f787c..b3f18d9a53 100644
--- a/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_block_sqlite_impl.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_block_sqlite_impl.rs
@@ -7,9 +7,9 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::util::md5;
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::sync::Arc;
pub struct SQLiteGridBlockRevisionPersistence {
diff --git a/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_sqlite_impl.rs b/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_sqlite_impl.rs
index 846faa4639..de6a7b8daf 100644
--- a/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_sqlite_impl.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_sqlite_impl.rs
@@ -7,9 +7,9 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::util::md5;
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::sync::Arc;
pub struct SQLiteGridRevisionPersistence {
diff --git a/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_view_sqlite_impl.rs b/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_view_sqlite_impl.rs
index 81830779de..f8534510cf 100644
--- a/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_view_sqlite_impl.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/persistence/rev_sqlite/grid_view_sqlite_impl.rs
@@ -7,9 +7,9 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::util::md5;
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::sync::Arc;
pub struct SQLiteGridViewRevisionPersistence {
diff --git a/frontend/rust-lib/flowy-grid/src/services/row/row_builder.rs b/frontend/rust-lib/flowy-grid/src/services/row/row_builder.rs
index ddf8c40675..e66d4a5a64 100644
--- a/frontend/rust-lib/flowy-grid/src/services/row/row_builder.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/row/row_builder.rs
@@ -3,7 +3,7 @@ use crate::services::cell::{
insert_url_cell,
};
-use grid_rev_model::{gen_row_id, CellRevision, FieldRevision, RowRevision, DEFAULT_ROW_HEIGHT};
+use grid_model::{gen_row_id, CellRevision, FieldRevision, RowRevision, DEFAULT_ROW_HEIGHT};
use indexmap::IndexMap;
use std::collections::HashMap;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs b/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs
index 4071fc50a6..a5d5e35d98 100644
--- a/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs
@@ -1,5 +1,5 @@
use crate::entities::RowPB;
-use grid_rev_model::RowRevision;
+use grid_model::RowRevision;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-grid/src/services/sort/controller.rs b/frontend/rust-lib/flowy-grid/src/services/sort/controller.rs
index 135335a444..c6bd06e0b8 100644
--- a/frontend/rust-lib/flowy-grid/src/services/sort/controller.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/sort/controller.rs
@@ -6,7 +6,7 @@ use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult, SortCh
use crate::services::view_editor::{GridViewChanged, GridViewChangedNotifier};
use flowy_error::FlowyResult;
use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
-use grid_rev_model::{CellRevision, FieldRevision, RowRevision, SortCondition, SortRevision};
+use grid_model::{CellRevision, FieldRevision, RowRevision, SortCondition, SortRevision};
use lib_infra::future::Fut;
use rayon::prelude::ParallelSliceMut;
use serde::{Deserialize, Serialize};
diff --git a/frontend/rust-lib/flowy-grid/src/services/sort/entities.rs b/frontend/rust-lib/flowy-grid/src/services/sort/entities.rs
index e5a894f43e..d711c4b90f 100644
--- a/frontend/rust-lib/flowy-grid/src/services/sort/entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/sort/entities.rs
@@ -1,5 +1,5 @@
use crate::entities::{AlterSortParams, DeleteSortParams, FieldType};
-use grid_rev_model::{FieldRevision, FieldTypeRevision};
+use grid_model::{FieldRevision, FieldTypeRevision};
use std::sync::Arc;
#[derive(Hash, Eq, PartialEq, Debug, Clone)]
diff --git a/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs b/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs
index d5cda0cf44..db93b5f10c 100644
--- a/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs
@@ -13,13 +13,12 @@ use crate::services::sort::{DeletedSortType, SortChangeset, SortController, Sort
use crate::services::view_editor::changed_notifier::GridViewChangedNotifier;
use crate::services::view_editor::trait_impl::*;
use crate::services::view_editor::GridViewChangedReceiverRunner;
+use flowy_client_sync::client_grid::{make_grid_view_operations, GridViewRevisionChangeset, GridViewRevisionPad};
use flowy_database::ConnectionPool;
use flowy_error::FlowyResult;
-use flowy_http_model::revision::Revision;
use flowy_revision::RevisionManager;
-use flowy_sync::client_grid::{make_grid_view_operations, GridViewRevisionChangeset, GridViewRevisionPad};
use flowy_task::TaskDispatcher;
-use grid_rev_model::{
+use grid_model::{
gen_grid_filter_id, gen_grid_sort_id, FieldRevision, FieldTypeRevision, FilterRevision, LayoutRevision,
RowChangeset, RowRevision, SortRevision,
};
@@ -27,6 +26,7 @@ use lib_infra::async_trait::async_trait;
use lib_infra::future::Fut;
use lib_infra::ref_map::RefCountValue;
use nanoid::nanoid;
+use revision_model::Revision;
use std::borrow::Cow;
use std::future::Future;
use std::sync::Arc;
@@ -870,7 +870,7 @@ fn gen_handler_id() -> String {
#[cfg(test)]
mod tests {
- use flowy_sync::client_grid::GridOperations;
+ use flowy_client_sync::client_grid::GridOperations;
#[test]
fn test() {
diff --git a/frontend/rust-lib/flowy-grid/src/services/view_editor/editor_manager.rs b/frontend/rust-lib/flowy-grid/src/services/view_editor/editor_manager.rs
index 25effc8a7e..da85f8967e 100644
--- a/frontend/rust-lib/flowy-grid/src/services/view_editor/editor_manager.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/view_editor/editor_manager.rs
@@ -15,7 +15,7 @@ use crate::services::view_editor::{GridViewEditorDelegate, GridViewRevisionEdito
use flowy_database::ConnectionPool;
use flowy_error::FlowyResult;
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
-use grid_rev_model::{FieldRevision, FilterRevision, RowChangeset, RowRevision, SortRevision};
+use grid_model::{FieldRevision, FilterRevision, RowChangeset, RowRevision, SortRevision};
use lib_infra::future::Fut;
use lib_infra::ref_map::RefCountHashMap;
use std::borrow::Cow;
diff --git a/frontend/rust-lib/flowy-grid/src/services/view_editor/trait_impl.rs b/frontend/rust-lib/flowy-grid/src/services/view_editor/trait_impl.rs
index 7ff22e77b0..1076322d1b 100644
--- a/frontend/rust-lib/flowy-grid/src/services/view_editor/trait_impl.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/view_editor/trait_impl.rs
@@ -6,19 +6,19 @@ use crate::services::row::GridBlockRowRevision;
use crate::services::sort::{SortDelegate, SortType};
use crate::services::view_editor::{get_cells_for_field, GridViewEditorDelegate};
use bytes::Bytes;
+use flowy_client_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
+use flowy_client_sync::make_operations_from_revisions;
use flowy_database::ConnectionPool;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision::{
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer, RevisionObjectSerializer,
};
-use flowy_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
-use flowy_sync::util::make_operations_from_revisions;
-use grid_rev_model::{
+use grid_model::{
FieldRevision, FieldTypeRevision, FilterRevision, GroupConfigurationRevision, RowRevision, SortRevision,
};
use lib_infra::future::{to_fut, Fut, FutureResult};
use lib_ot::core::EmptyAttributes;
+use revision_model::Revision;
use std::sync::Arc;
use tokio::sync::RwLock;
diff --git a/frontend/rust-lib/flowy-grid/src/util.rs b/frontend/rust-lib/flowy-grid/src/util.rs
index 7b4e246b26..84f321916d 100644
--- a/frontend/rust-lib/flowy-grid/src/util.rs
+++ b/frontend/rust-lib/flowy-grid/src/util.rs
@@ -1,8 +1,8 @@
use crate::entities::FieldType;
use crate::services::field::*;
use crate::services::row::RowRevisionBuilder;
-use flowy_sync::client_grid::GridBuilder;
-use grid_rev_model::BuildGridContext;
+use flowy_client_sync::client_grid::GridBuilder;
+use grid_model::BuildGridContext;
pub fn make_default_grid() -> BuildGridContext {
let mut grid_builder = GridBuilder::new();
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/block_test/block_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/block_test/block_test.rs
index e9aa368f7d..5b70df7220 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/block_test/block_test.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/block_test/block_test.rs
@@ -1,7 +1,7 @@
use crate::grid::block_test::script::GridRowTest;
use crate::grid::block_test::script::RowScript::*;
-use grid_rev_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset};
+use grid_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset};
#[tokio::test]
async fn grid_create_block() {
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/block_test/row_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/block_test/row_test.rs
index 54e7375277..e26085f94a 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/block_test/row_test.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/block_test/row_test.rs
@@ -3,7 +3,7 @@ use crate::grid::block_test::script::{CreateRowScriptBuilder, GridRowTest};
use crate::grid::grid_editor::{COMPLETED, FACEBOOK, GOOGLE, PAUSED, TWITTER};
use flowy_grid::entities::FieldType;
use flowy_grid::services::field::{SELECTION_IDS_SEPARATOR, UNCHECK};
-use grid_rev_model::RowChangeset;
+use grid_model::RowChangeset;
#[tokio::test]
async fn grid_create_row_count_test() {
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs
index 2d58265dbb..b01e96c707 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs
@@ -4,7 +4,7 @@ use crate::grid::grid_editor::GridEditorTest;
use flowy_grid::entities::{CellPathParams, CreateRowParams, FieldType, GridLayout, RowPB};
use flowy_grid::services::field::*;
use flowy_grid::services::row::GridBlockRow;
-use grid_rev_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
+use grid_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
use std::collections::HashMap;
use std::sync::Arc;
use strum::IntoEnumIterator;
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs b/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs
index 13c38bc42b..faa5229194 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs
@@ -3,7 +3,7 @@ use flowy_grid::services::field::{
ChecklistTypeOptionPB, DateCellChangeset, MultiSelectTypeOptionPB, SelectOptionPB, SingleSelectTypeOptionPB,
};
use flowy_grid::services::row::RowRevisionBuilder;
-use grid_rev_model::{FieldRevision, RowRevision};
+use grid_model::{FieldRevision, RowRevision};
use std::sync::Arc;
use strum::EnumCount;
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/field_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/field_test/script.rs
index 9e5cfaa653..6b194d67bc 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/field_test/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/field_test/script.rs
@@ -1,7 +1,7 @@
use crate::grid::grid_editor::GridEditorTest;
use flowy_grid::entities::{CreateFieldParams, FieldChangesetParams, FieldType};
use flowy_grid::services::cell::{stringify_cell_data, TypeCellData};
-use grid_rev_model::FieldRevision;
+use grid_model::FieldRevision;
pub enum FieldScript {
CreateField {
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs b/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs
index 052962db78..07e244a345 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs
@@ -1,7 +1,7 @@
use flowy_grid::entities::*;
use flowy_grid::services::field::selection_type_option::SelectOptionPB;
use flowy_grid::services::field::*;
-use grid_rev_model::*;
+use grid_model::*;
pub fn create_text_field(grid_id: &str) -> (CreateFieldParams, FieldRevision) {
let mut field_rev = FieldBuilder::new(RichTextTypeOptionBuilder::default())
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs
index 0dc39a32ec..940b3d4c26 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs
@@ -10,7 +10,7 @@ use tokio::sync::broadcast::Receiver;
use flowy_grid::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, GridLayout, GridSettingChangesetParams, GridSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB};
use flowy_grid::services::field::{SelectOptionCellChangeset, SelectOptionIds};
use flowy_grid::services::setting::GridSettingChangesetBuilder;
-use grid_rev_model::{FieldRevision, FieldTypeRevision};
+use grid_model::{FieldRevision, FieldTypeRevision};
use flowy_database::schema::view_table::dsl::view_table;
use flowy_grid::services::cell::insert_select_option_cell;
use flowy_grid::services::filter::FilterType;
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs
index 474f6135f8..c591ca722f 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs
@@ -3,6 +3,7 @@
#![allow(unused_imports)]
use crate::grid::block_test::util::GridRowTestBuilder;
use bytes::Bytes;
+use flowy_client_sync::client_grid::GridBuilder;
use flowy_error::FlowyResult;
use flowy_grid::entities::*;
use flowy_grid::services::cell::ToCellChangesetString;
@@ -12,10 +13,9 @@ use flowy_grid::services::grid_editor::{GridRevisionEditor, GridRevisionSerde};
use flowy_grid::services::row::{CreateRowRevisionPayload, RowRevisionBuilder};
use flowy_grid::services::setting::GridSettingChangesetBuilder;
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
-use flowy_sync::client_grid::GridBuilder;
use flowy_test::helper::ViewTest;
use flowy_test::FlowySDKTest;
-use grid_rev_model::*;
+use grid_model::*;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/grid_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/grid_test.rs
index 61e3b8385d..87f81f7a84 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/grid_test.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/grid_test.rs
@@ -6,7 +6,7 @@ use flowy_grid::services::field::{
SingleSelectTypeOption, SELECTION_IDS_SEPARATOR,
};
use flowy_grid::services::row::{decode_cell_data_from_type_option_cell_data, CreateRowMetaBuilder};
-use grid_rev_model::entities::{
+use grid_model::entities::{
CellChangeset, FieldChangesetParams, FieldType, GridBlockInfoChangeset, GridBlockMetaSnapshot, RowMetaChangeset,
TypeOptionDataFormat,
};
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/group_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/group_test/script.rs
index 57e75a5a9a..9f44dffc6f 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/group_test/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/group_test/script.rs
@@ -6,7 +6,7 @@ use flowy_grid::services::cell::{delete_select_option_cell, insert_select_option
use flowy_grid::services::field::{
edit_single_select_type_option, SelectOptionPB, SelectTypeOptionSharedAction, SingleSelectTypeOptionPB,
};
-use grid_rev_model::{FieldRevision, RowChangeset};
+use grid_model::{FieldRevision, RowChangeset};
use std::sync::Arc;
pub enum GroupScript {
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/script.rs
index f8bf90dac2..9f7ef50aaa 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/script.rs
@@ -1,12 +1,12 @@
use bytes::Bytes;
+use flowy_client_sync::client_grid::GridBuilder;
use flowy_grid::services::field::*;
use flowy_grid::services::grid_meta_editor::{GridMetaEditor, GridPadBuilder};
use flowy_grid::services::row::CreateRowMetaPayload;
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
-use flowy_sync::client_grid::GridBuilder;
use flowy_test::helper::ViewTest;
use flowy_test::FlowySDKTest;
-use grid_rev_model::entities::{
+use grid_model::entities::{
BuildGridContext, CellChangeset, Field, FieldChangesetParams, FieldMeta, FieldOrder, FieldType,
GridBlockInfoChangeset, GridBlockMetaSnapshot, InsertFieldParams, RowMeta, RowMetaChangeset, RowOrder,
TypeOptionDataFormat,
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/snapshot_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/snapshot_test/script.rs
index 8dc751322c..aed9c37fbd 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/snapshot_test/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/snapshot_test/script.rs
@@ -1,9 +1,9 @@
use crate::grid::grid_editor::GridEditorTest;
-use flowy_http_model::revision::Revision;
+use flowy_client_sync::client_grid::{GridOperations, GridRevisionPad};
use flowy_revision::{RevisionSnapshot, REVISION_WRITE_INTERVAL_IN_MILLIS};
-use flowy_sync::client_grid::{GridOperations, GridRevisionPad};
-use grid_rev_model::FieldRevision;
+use grid_model::FieldRevision;
+use revision_model::Revision;
use std::time::Duration;
use tokio::time::sleep;
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/checkbox_and_text_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/checkbox_and_text_test.rs
index 315de599c3..5626d5fb1e 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/checkbox_and_text_test.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/checkbox_and_text_test.rs
@@ -1,6 +1,6 @@
use crate::grid::sort_test::script::{GridSortTest, SortScript::*};
use flowy_grid::entities::FieldType;
-use grid_rev_model::SortCondition;
+use grid_model::SortCondition;
#[tokio::test]
async fn sort_checkbox_and_then_text_by_descending_test() {
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/multi_sort_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/multi_sort_test.rs
index b1444f0d0f..7b529d3b6e 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/multi_sort_test.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/multi_sort_test.rs
@@ -1,7 +1,7 @@
use crate::grid::sort_test::script::GridSortTest;
use crate::grid::sort_test::script::SortScript::*;
use flowy_grid::entities::FieldType;
-use grid_rev_model::SortCondition;
+use grid_model::SortCondition;
#[tokio::test]
async fn sort_text_with_checkbox_by_ascending_test() {
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/script.rs
index dbeee849a1..3fd7595de5 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/script.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/script.rs
@@ -4,7 +4,7 @@ use flowy_grid::entities::{AlterSortParams, CellPathParams, DeleteSortParams};
use flowy_grid::services::sort::SortType;
use flowy_grid::services::view_editor::GridViewChanged;
use futures::stream::StreamExt;
-use grid_rev_model::{FieldRevision, SortCondition, SortRevision};
+use grid_model::{FieldRevision, SortCondition, SortRevision};
use std::cmp::min;
use std::sync::Arc;
use std::time::Duration;
diff --git a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/single_sort_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/single_sort_test.rs
index 3714e9fc3e..19476d6874 100644
--- a/frontend/rust-lib/flowy-grid/tests/grid/sort_test/single_sort_test.rs
+++ b/frontend/rust-lib/flowy-grid/tests/grid/sort_test/single_sort_test.rs
@@ -1,6 +1,6 @@
use crate::grid::sort_test::script::{GridSortTest, SortScript::*};
use flowy_grid::entities::FieldType;
-use grid_rev_model::SortCondition;
+use grid_model::SortCondition;
#[tokio::test]
async fn sort_text_by_ascending_test() {
diff --git a/frontend/rust-lib/flowy-net/Cargo.toml b/frontend/rust-lib/flowy-net/Cargo.toml
index e619ddf751..fb3e201b80 100644
--- a/frontend/rust-lib/flowy-net/Cargo.toml
+++ b/frontend/rust-lib/flowy-net/Cargo.toml
@@ -7,11 +7,18 @@ edition = "2018"
[dependencies]
lib-dispatch = { path = "../lib-dispatch" }
-flowy-error = { path = "../flowy-error", features = ["collaboration", "http_server"] }
+flowy-error = { path = "../flowy-error", features = ["adaptor_sync", "adaptor_reqwest", "adaptor_server_error"] }
flowy-derive = { path = "../flowy-derive" }
-flowy-sync = { path = "../flowy-sync"}
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model"}
-folder-rev-model = { path = "../../../shared-lib/folder-rev-model"}
+flowy-client-sync = { path = "../flowy-client-sync"}
+folder-model = { path = "../../../shared-lib/folder-model" }
+revision-model = { path = "../../../shared-lib/revision-model"}
+document-model = { path = "../../../shared-lib/document-model"}
+ws-model = { path = "../../../shared-lib/ws-model"}
+flowy-server-sync = { path = "../../../shared-lib/flowy-server-sync"}
+flowy-client-ws = { path = "../../../shared-lib/flowy-client-ws"}
+flowy-client-network-config= { path = "../../../shared-lib/flowy-client-network-config"}
+flowy-sync = { path = "../../../shared-lib/flowy-sync"}
+user-model = { path = "../../../shared-lib/user-model"}
flowy-folder = { path = "../flowy-folder" }
flowy-user = { path = "../flowy-user" }
flowy-document = { path = "../flowy-document" }
@@ -29,15 +36,14 @@ tracing = { version = "0.1", features = ["log"] }
dashmap = "5"
async-stream = "0.3.2"
futures-util = "0.3.15"
-http-flowy = { git = "https://github.com/AppFlowy-IO/AppFlowy-Server", features = ["with_reqwest"] }
-serde-aux = "1.0.1"
reqwest = "0.11"
hyper = "0.14"
config = { version = "0.10.1", default-features = false, features = ["yaml"] }
-log = "0.4.14"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
+serde-aux = "1.0.1"
nanoid = "0.4.0"
+thiserror = "1.0"
[features]
http_server = []
diff --git a/frontend/rust-lib/flowy-net/src/entities/network_state.rs b/frontend/rust-lib/flowy-net/src/entities/network_state.rs
index 162c0bc05e..868417e089 100644
--- a/frontend/rust-lib/flowy-net/src/entities/network_state.rs
+++ b/frontend/rust-lib/flowy-net/src/entities/network_state.rs
@@ -1,8 +1,9 @@
+use flowy_client_ws::NetworkType;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
#[derive(ProtoBuf_Enum, Debug, Clone, Eq, PartialEq)]
-pub enum NetworkType {
- UnknownNetworkType = 0,
+pub enum NetworkTypePB {
+ Unknown = 0,
Wifi = 1,
Cell = 2,
Ethernet = 3,
@@ -10,23 +11,36 @@ pub enum NetworkType {
VPN = 5,
}
-impl NetworkType {
+impl NetworkTypePB {
pub fn is_connect(&self) -> bool {
match self {
- NetworkType::UnknownNetworkType | NetworkType::Bluetooth => false,
- NetworkType::Wifi | NetworkType::Cell | NetworkType::Ethernet | NetworkType::VPN => true,
+ NetworkTypePB::Unknown | NetworkTypePB::Bluetooth => false,
+ NetworkTypePB::Wifi | NetworkTypePB::Cell | NetworkTypePB::Ethernet | NetworkTypePB::VPN => true,
}
}
}
-impl std::default::Default for NetworkType {
+impl std::default::Default for NetworkTypePB {
fn default() -> Self {
- NetworkType::UnknownNetworkType
+ NetworkTypePB::Unknown
+ }
+}
+
+impl std::convert::From<NetworkTypePB> for NetworkType {
+ fn from(ty: NetworkTypePB) -> Self {
+ match ty {
+ NetworkTypePB::Unknown => NetworkType::Unknown,
+ NetworkTypePB::Wifi => NetworkType::Wifi,
+ NetworkTypePB::Cell => NetworkType::Cell,
+ NetworkTypePB::Ethernet => NetworkType::Ethernet,
+ NetworkTypePB::Bluetooth => NetworkType::Bluetooth,
+ NetworkTypePB::VPN => NetworkType::VPN,
+ }
}
}
#[derive(ProtoBuf, Debug, Default, Clone)]
-pub struct NetworkState {
+pub struct NetworkStatePB {
#[pb(index = 1)]
- pub ty: NetworkType,
+ pub ty: NetworkTypePB,
}
diff --git a/frontend/rust-lib/flowy-net/src/event_map.rs b/frontend/rust-lib/flowy-net/src/event_map.rs
index aaaab10f7d..fc6155ae76 100644
--- a/frontend/rust-lib/flowy-net/src/event_map.rs
+++ b/frontend/rust-lib/flowy-net/src/event_map.rs
@@ -1,4 +1,5 @@
-use crate::{handlers::*, ws::connection::FlowyWebSocketConnect};
+use crate::handlers::*;
+use flowy_client_ws::FlowyWebSocketConnect;
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
use lib_dispatch::prelude::*;
use std::sync::Arc;
@@ -14,6 +15,6 @@ pub fn init(ws_conn: Arc<FlowyWebSocketConnect>) -> AFPlugin {
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
#[event_err = "FlowyError"]
pub enum NetworkEvent {
- #[event(input = "NetworkState")]
+ #[event(input = "NetworkStatePB")]
UpdateNetworkType = 0,
}
diff --git a/frontend/rust-lib/flowy-net/src/handlers/mod.rs b/frontend/rust-lib/flowy-net/src/handlers/mod.rs
index 2fbc71ff0b..c4d279e4b0 100644
--- a/frontend/rust-lib/flowy-net/src/handlers/mod.rs
+++ b/frontend/rust-lib/flowy-net/src/handlers/mod.rs
@@ -1,14 +1,15 @@
-use crate::{entities::NetworkState, ws::connection::FlowyWebSocketConnect};
+use crate::entities::NetworkStatePB;
+use flowy_client_ws::{FlowyWebSocketConnect, NetworkType};
use flowy_error::FlowyError;
use lib_dispatch::prelude::{AFPluginData, AFPluginState};
use std::sync::Arc;
#[tracing::instrument(level = "debug", skip(data, ws_manager))]
pub async fn update_network_ty(
- data: AFPluginData<NetworkState>,
+ data: AFPluginData<NetworkStatePB>,
ws_manager: AFPluginState<Arc<FlowyWebSocketConnect>>,
) -> Result<(), FlowyError> {
- let network_state = data.into_inner();
- ws_manager.update_network_type(&network_state.ty);
+ let network_type: NetworkType = data.into_inner().ty.into();
+ ws_manager.update_network_type(network_type);
Ok(())
}
diff --git a/frontend/rust-lib/flowy-net/src/http_server/document.rs b/frontend/rust-lib/flowy-net/src/http_server/document.rs
index 07c1234228..a8f9cacf55 100644
--- a/frontend/rust-lib/flowy-net/src/http_server/document.rs
+++ b/frontend/rust-lib/flowy-net/src/http_server/document.rs
@@ -1,11 +1,9 @@
-use crate::{
- configuration::*,
- request::{HttpRequestBuilder, ResponseMiddleware},
-};
+use crate::request::{HttpRequestBuilder, ResponseMiddleware};
+use crate::response::HttpResponse;
+use document_model::document::{CreateDocumentParams, DocumentId, DocumentInfo, ResetDocumentParams};
+use flowy_client_network_config::{ClientServerConfiguration, HEADER_TOKEN};
use flowy_document::DocumentCloudService;
use flowy_error::FlowyError;
-use flowy_http_model::document::{CreateDocumentParams, DocumentId, DocumentPayload, ResetDocumentParams};
-use http_flowy::response::FlowyResponse;
use lazy_static::lazy_static;
use lib_infra::future::FutureResult;
use std::sync::Arc;
@@ -27,7 +25,7 @@ impl DocumentCloudService for DocumentCloudServiceImpl {
FutureResult::new(async move { create_document_request(&token, params, &url).await })
}
- fn fetch_document(&self, token: &str, params: DocumentId) -> FutureResult<Option<DocumentPayload>, FlowyError> {
+ fn fetch_document(&self, token: &str, params: DocumentId) -> FutureResult<Option<DocumentInfo>, FlowyError> {
let token = token.to_owned();
let url = self.config.doc_url();
FutureResult::new(async move { read_document_request(&token, params, &url).await })
@@ -54,7 +52,7 @@ pub async fn read_document_request(
token: &str,
params: DocumentId,
url: &str,
-) -> Result<Option<DocumentPayload>, FlowyError> {
+) -> Result<Option<DocumentInfo>, FlowyError> {
let doc = request_builder()
.get(url)
.header(HEADER_TOKEN, token)
@@ -85,7 +83,7 @@ lazy_static! {
pub(crate) struct DocumentResponseMiddleware {}
impl ResponseMiddleware for DocumentResponseMiddleware {
- fn receive_response(&self, token: &Option<String>, response: &FlowyResponse) {
+ fn receive_response(&self, token: &Option<String>, response: &HttpResponse) {
if let Some(error) = &response.error {
if error.is_unauthorized() {
tracing::error!("document user is unauthorized");
diff --git a/frontend/rust-lib/flowy-net/src/http_server/folder.rs b/frontend/rust-lib/flowy-net/src/http_server/folder.rs
index a52cdf56ff..9e6862ef38 100644
--- a/frontend/rust-lib/flowy-net/src/http_server/folder.rs
+++ b/frontend/rust-lib/flowy-net/src/http_server/folder.rs
@@ -1,7 +1,6 @@
-use crate::{
- configuration::ClientServerConfiguration,
- request::{HttpRequestBuilder, ResponseMiddleware},
-};
+use crate::request::{HttpRequestBuilder, ResponseMiddleware};
+use crate::response::HttpResponse;
+use flowy_client_network_config::ClientServerConfiguration;
use flowy_error::FlowyError;
use flowy_folder::entities::{
trash::RepeatedTrashIdPB,
@@ -10,9 +9,7 @@ use flowy_folder::entities::{
{AppIdPB, CreateAppParams, UpdateAppParams},
};
use flowy_folder::event_map::FolderCouldServiceV1;
-use folder_rev_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
-use http_flowy::errors::ServerError;
-use http_flowy::response::FlowyResponse;
+use folder_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
use lazy_static::lazy_static;
use lib_infra::future::FutureResult;
use std::sync::Arc;
@@ -180,7 +177,7 @@ pub async fn create_workspace_request(
_token: &str,
_params: CreateWorkspaceParams,
_url: &str,
-) -> Result<WorkspaceRevision, ServerError> {
+) -> Result<WorkspaceRevision, FlowyError> {
// let workspace = request_builder()
// .post(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -195,7 +192,7 @@ pub async fn read_workspaces_request(
_token: &str,
_params: WorkspaceIdPB,
_url: &str,
-) -> Result<Vec<WorkspaceRevision>, ServerError> {
+) -> Result<Vec<WorkspaceRevision>, FlowyError> {
// let repeated_workspace = request_builder()
// .get(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -211,7 +208,7 @@ pub async fn update_workspace_request(
_token: &str,
_params: UpdateWorkspaceParams,
_url: &str,
-) -> Result<(), ServerError> {
+) -> Result<(), FlowyError> {
// let _ = request_builder()
// .patch(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -221,7 +218,7 @@ pub async fn update_workspace_request(
Ok(())
}
-pub async fn delete_workspace_request(_token: &str, _params: WorkspaceIdPB, _url: &str) -> Result<(), ServerError> {
+pub async fn delete_workspace_request(_token: &str, _params: WorkspaceIdPB, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .delete(url)
// .header(HEADER_TOKEN, token)
@@ -232,11 +229,7 @@ pub async fn delete_workspace_request(_token: &str, _params: WorkspaceIdPB, _url
}
// App
-pub async fn create_app_request(
- _token: &str,
- _params: CreateAppParams,
- _url: &str,
-) -> Result<AppRevision, ServerError> {
+pub async fn create_app_request(_token: &str, _params: CreateAppParams, _url: &str) -> Result<AppRevision, FlowyError> {
// let app = request_builder()
// .post(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -247,7 +240,7 @@ pub async fn create_app_request(
unimplemented!()
}
-pub async fn read_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<Option<AppRevision>, ServerError> {
+pub async fn read_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<Option<AppRevision>, FlowyError> {
// let app = request_builder()
// .get(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -259,7 +252,7 @@ pub async fn read_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Res
unimplemented!()
}
-pub async fn update_app_request(_token: &str, _params: UpdateAppParams, _url: &str) -> Result<(), ServerError> {
+pub async fn update_app_request(_token: &str, _params: UpdateAppParams, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .patch(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -269,7 +262,7 @@ pub async fn update_app_request(_token: &str, _params: UpdateAppParams, _url: &s
Ok(())
}
-pub async fn delete_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<(), ServerError> {
+pub async fn delete_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .delete(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -284,7 +277,7 @@ pub async fn create_view_request(
_token: &str,
_params: CreateViewParams,
_url: &str,
-) -> Result<ViewRevision, ServerError> {
+) -> Result<ViewRevision, FlowyError> {
// let view = request_builder()
// .post(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -299,7 +292,7 @@ pub async fn read_view_request(
_token: &str,
_params: ViewIdPB,
_url: &str,
-) -> Result<Option<ViewRevision>, ServerError> {
+) -> Result<Option<ViewRevision>, FlowyError> {
// let view = request_builder()
// .get(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -311,7 +304,7 @@ pub async fn read_view_request(
unimplemented!()
}
-pub async fn update_view_request(_token: &str, _params: UpdateViewParams, _url: &str) -> Result<(), ServerError> {
+pub async fn update_view_request(_token: &str, _params: UpdateViewParams, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .patch(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -321,7 +314,7 @@ pub async fn update_view_request(_token: &str, _params: UpdateViewParams, _url:
Ok(())
}
-pub async fn delete_view_request(_token: &str, _params: RepeatedViewIdPB, _url: &str) -> Result<(), ServerError> {
+pub async fn delete_view_request(_token: &str, _params: RepeatedViewIdPB, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .delete(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -331,7 +324,7 @@ pub async fn delete_view_request(_token: &str, _params: RepeatedViewIdPB, _url:
Ok(())
}
-pub async fn create_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), ServerError> {
+pub async fn create_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .post(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -341,7 +334,7 @@ pub async fn create_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url
Ok(())
}
-pub async fn delete_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), ServerError> {
+pub async fn delete_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), FlowyError> {
// let _ = request_builder()
// .delete(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -351,7 +344,7 @@ pub async fn delete_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url
Ok(())
}
-pub async fn read_trash_request(_token: &str, _url: &str) -> Result<Vec<TrashRevision>, ServerError> {
+pub async fn read_trash_request(_token: &str, _url: &str) -> Result<Vec<TrashRevision>, FlowyError> {
// let repeated_trash = request_builder()
// .get(&url.to_owned())
// .header(HEADER_TOKEN, token)
@@ -384,7 +377,7 @@ impl FolderResponseMiddleware {
}
impl ResponseMiddleware for FolderResponseMiddleware {
- fn receive_response(&self, token: &Option<String>, response: &FlowyResponse) {
+ fn receive_response(&self, token: &Option<String>, response: &HttpResponse) {
if let Some(error) = &response.error {
if error.is_unauthorized() {
tracing::error!("user is unauthorized");
diff --git a/frontend/rust-lib/flowy-net/src/http_server/user.rs b/frontend/rust-lib/flowy-net/src/http_server/user.rs
index d4fec92c8d..3b9407eeb7 100644
--- a/frontend/rust-lib/flowy-net/src/http_server/user.rs
+++ b/frontend/rust-lib/flowy-net/src/http_server/user.rs
@@ -1,11 +1,10 @@
-use crate::{configuration::*, request::HttpRequestBuilder};
+use crate::request::HttpRequestBuilder;
+use flowy_client_network_config::{ClientServerConfiguration, HEADER_TOKEN};
use flowy_error::FlowyError;
-use flowy_user::entities::{
- SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
-};
+use flowy_user::entities::UserProfilePB;
use flowy_user::event_map::UserCloudService;
-use http_flowy::errors::ServerError;
use lib_infra::future::FutureResult;
+use user_model::*;
pub struct UserHttpCloudService {
config: ClientServerConfiguration,
@@ -65,22 +64,22 @@ impl UserCloudService for UserHttpCloudService {
}
}
-pub async fn user_sign_up_request(params: SignUpParams, url: &str) -> Result<SignUpResponse, ServerError> {
- let response = request_builder().post(url).protobuf(params)?.response().await?;
+pub async fn user_sign_up_request(params: SignUpParams, url: &str) -> Result<SignUpResponse, FlowyError> {
+ let response = request_builder().post(url).json(params)?.json_response().await?;
Ok(response)
}
-pub async fn user_sign_in_request(params: SignInParams, url: &str) -> Result<SignInResponse, ServerError> {
- let response = request_builder().post(url).protobuf(params)?.response().await?;
+pub async fn user_sign_in_request(params: SignInParams, url: &str) -> Result<SignInResponse, FlowyError> {
+ let response = request_builder().post(url).json(params)?.json_response().await?;
Ok(response)
}
-pub async fn user_sign_out_request(token: &str, url: &str) -> Result<(), ServerError> {
+pub async fn user_sign_out_request(token: &str, url: &str) -> Result<(), FlowyError> {
request_builder().delete(url).header(HEADER_TOKEN, token).send().await?;
Ok(())
}
-pub async fn get_user_profile_request(token: &str, url: &str) -> Result<UserProfilePB, ServerError> {
+pub async fn get_user_profile_request(token: &str, url: &str) -> Result<UserProfilePB, FlowyError> {
let user_profile = request_builder()
.get(url)
.header(HEADER_TOKEN, token)
@@ -93,11 +92,11 @@ pub async fn update_user_profile_request(
token: &str,
params: UpdateUserProfileParams,
url: &str,
-) -> Result<(), ServerError> {
+) -> Result<(), FlowyError> {
request_builder()
.patch(url)
.header(HEADER_TOKEN, token)
- .protobuf(params)?
+ .json(params)?
.send()
.await?;
Ok(())
diff --git a/frontend/rust-lib/flowy-net/src/lib.rs b/frontend/rust-lib/flowy-net/src/lib.rs
index 6347e3f459..0056548cae 100644
--- a/frontend/rust-lib/flowy-net/src/lib.rs
+++ b/frontend/rust-lib/flowy-net/src/lib.rs
@@ -1,4 +1,3 @@
-mod configuration;
pub mod entities;
pub mod event_map;
mod handlers;
@@ -6,6 +5,6 @@ pub mod http_server;
pub mod local_server;
pub mod protobuf;
mod request;
-pub mod ws;
+mod response;
-pub use crate::configuration::{get_client_server_configuration, ClientServerConfiguration};
+pub use flowy_client_network_config::{get_client_server_configuration, ClientServerConfiguration};
diff --git a/frontend/rust-lib/flowy-net/src/local_server/mod.rs b/frontend/rust-lib/flowy-net/src/local_server/mod.rs
index 3cbc28664d..516de4f02a 100644
--- a/frontend/rust-lib/flowy-net/src/local_server/mod.rs
+++ b/frontend/rust-lib/flowy-net/src/local_server/mod.rs
@@ -1,4 +1,4 @@
-use crate::configuration::ClientServerConfiguration;
+use flowy_client_network_config::ClientServerConfiguration;
use tokio::sync::{broadcast, mpsc};
mod persistence;
diff --git a/frontend/rust-lib/flowy-net/src/local_server/persistence.rs b/frontend/rust-lib/flowy-net/src/local_server/persistence.rs
index 8e24051979..d412da38af 100644
--- a/frontend/rust-lib/flowy-net/src/local_server/persistence.rs
+++ b/frontend/rust-lib/flowy-net/src/local_server/persistence.rs
@@ -1,13 +1,10 @@
-use flowy_http_model::document::DocumentPayload;
-use flowy_http_model::folder::FolderInfo;
-use flowy_http_model::revision::Revision;
-use flowy_sync::{
- errors::CollaborateError,
- server_document::*,
- server_folder::FolderCloudPersistence,
- util::{make_document_from_revision_pbs, make_folder_from_revisions_pb},
-};
+use document_model::document::DocumentInfo;
+use flowy_client_sync::{errors::SyncError, util::make_document_info_from_revisions};
+use flowy_server_sync::server_folder::make_folder_from_revisions;
+use flowy_sync::ext::{DocumentCloudPersistence, FolderCloudPersistence};
+use folder_model::folder::FolderInfo;
use lib_infra::future::BoxResultFuture;
+use revision_model::Revision;
use std::{
fmt::{Debug, Formatter},
sync::Arc,
@@ -16,14 +13,9 @@ use std::{
// For the moment, we use memory to cache the data, it will be implemented with
// other storage. Like the Firestore,Dropbox.etc.
pub trait RevisionCloudStorage: Send + Sync {
- fn set_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
- fn get_revisions(
- &self,
- object_id: &str,
- rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError>;
-
- fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
+ fn set_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+ fn get_revisions(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> BoxResultFuture<Vec<Revision>, SyncError>;
+ fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
}
pub(crate) struct LocalDocumentCloudPersistence {
@@ -45,14 +37,14 @@ impl std::default::Default for LocalDocumentCloudPersistence {
}
impl FolderCloudPersistence for LocalDocumentCloudPersistence {
- fn read_folder(&self, _user_id: &str, folder_id: &str) -> BoxResultFuture<FolderInfo, CollaborateError> {
+ fn read_folder(&self, _user_id: &str, folder_id: &str) -> BoxResultFuture<FolderInfo, SyncError> {
let storage = self.storage.clone();
let folder_id = folder_id.to_owned();
Box::pin(async move {
let revisions = storage.get_revisions(&folder_id, None).await?;
- match make_folder_from_revisions_pb(&folder_id, revisions)? {
+ match make_folder_from_revisions(&folder_id, revisions)? {
Some(folder_info) => Ok(folder_info),
- None => Err(CollaborateError::record_not_found()),
+ None => Err(SyncError::record_not_found()),
}
})
}
@@ -62,16 +54,16 @@ impl FolderCloudPersistence for LocalDocumentCloudPersistence {
_user_id: &str,
folder_id: &str,
revisions: Vec<Revision>,
- ) -> BoxResultFuture<Option<FolderInfo>, CollaborateError> {
+ ) -> BoxResultFuture<Option<FolderInfo>, SyncError> {
let folder_id = folder_id.to_owned();
let storage = self.storage.clone();
Box::pin(async move {
storage.set_revisions(revisions.clone()).await?;
- make_folder_from_revisions_pb(&folder_id, revisions)
+ make_folder_from_revisions(&folder_id, revisions)
})
}
- fn save_folder_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
+ fn save_folder_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
let storage = self.storage.clone();
Box::pin(async move {
storage.set_revisions(revisions).await?;
@@ -83,13 +75,13 @@ impl FolderCloudPersistence for LocalDocumentCloudPersistence {
&self,
folder_id: &str,
rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
+ ) -> BoxResultFuture<Vec<Revision>, SyncError> {
let folder_id = folder_id.to_owned();
let storage = self.storage.clone();
Box::pin(async move { storage.get_revisions(&folder_id, rev_ids).await })
}
- fn reset_folder(&self, folder_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
+ fn reset_folder(&self, folder_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
let storage = self.storage.clone();
let folder_id = folder_id.to_owned();
Box::pin(async move {
@@ -100,14 +92,14 @@ impl FolderCloudPersistence for LocalDocumentCloudPersistence {
}
impl DocumentCloudPersistence for LocalDocumentCloudPersistence {
- fn read_document(&self, doc_id: &str) -> BoxResultFuture<DocumentPayload, CollaborateError> {
+ fn read_document(&self, doc_id: &str) -> BoxResultFuture<DocumentInfo, SyncError> {
let storage = self.storage.clone();
let doc_id = doc_id.to_owned();
Box::pin(async move {
let repeated_revision = storage.get_revisions(&doc_id, None).await?;
- match make_document_from_revision_pbs(&doc_id, repeated_revision)? {
+ match make_document_info_from_revisions(&doc_id, repeated_revision)? {
Some(document_info) => Ok(document_info),
- None => Err(CollaborateError::record_not_found()),
+ None => Err(SyncError::record_not_found()),
}
})
}
@@ -116,12 +108,12 @@ impl DocumentCloudPersistence for LocalDocumentCloudPersistence {
&self,
doc_id: &str,
revisions: Vec<Revision>,
- ) -> BoxResultFuture<Option<DocumentPayload>, CollaborateError> {
+ ) -> BoxResultFuture<Option<DocumentInfo>, SyncError> {
let doc_id = doc_id.to_owned();
let storage = self.storage.clone();
Box::pin(async move {
storage.set_revisions(revisions.clone()).await?;
- make_document_from_revision_pbs(&doc_id, revisions)
+ make_document_info_from_revisions(&doc_id, revisions)
})
}
@@ -129,13 +121,13 @@ impl DocumentCloudPersistence for LocalDocumentCloudPersistence {
&self,
doc_id: &str,
rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
+ ) -> BoxResultFuture<Vec<Revision>, SyncError> {
let doc_id = doc_id.to_owned();
let storage = self.storage.clone();
Box::pin(async move { storage.get_revisions(&doc_id, rev_ids).await })
}
- fn save_document_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
+ fn save_document_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
let storage = self.storage.clone();
Box::pin(async move {
storage.set_revisions(revisions).await?;
@@ -143,7 +135,7 @@ impl DocumentCloudPersistence for LocalDocumentCloudPersistence {
})
}
- fn reset_document(&self, doc_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
+ fn reset_document(&self, doc_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
let storage = self.storage.clone();
let doc_id = doc_id.to_owned();
Box::pin(async move {
@@ -156,19 +148,15 @@ impl DocumentCloudPersistence for LocalDocumentCloudPersistence {
#[derive(Default)]
struct MemoryDocumentCloudStorage {}
impl RevisionCloudStorage for MemoryDocumentCloudStorage {
- fn set_revisions(&self, _revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
+ fn set_revisions(&self, _revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
Box::pin(async move { Ok(()) })
}
- fn get_revisions(
- &self,
- _object_id: &str,
- _rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
+ fn get_revisions(&self, _object_id: &str, _rev_ids: Option<Vec<i64>>) -> BoxResultFuture<Vec<Revision>, SyncError> {
Box::pin(async move { Ok(vec![]) })
}
- fn reset_object(&self, _object_id: &str, _revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
+ fn reset_object(&self, _object_id: &str, _revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
Box::pin(async move { Ok(()) })
}
}
diff --git a/frontend/rust-lib/flowy-net/src/local_server/server.rs b/frontend/rust-lib/flowy-net/src/local_server/server.rs
index b29657ba70..723190c532 100644
--- a/frontend/rust-lib/flowy-net/src/local_server/server.rs
+++ b/frontend/rust-lib/flowy-net/src/local_server/server.rs
@@ -1,15 +1,25 @@
use crate::local_server::persistence::LocalDocumentCloudPersistence;
use async_stream::stream;
use bytes::Bytes;
+use document_model::document::{CreateDocumentParams, DocumentId, DocumentInfo, ResetDocumentParams};
+use flowy_client_sync::errors::SyncError;
+use flowy_document::DocumentCloudService;
use flowy_error::{internal_error, FlowyError};
-use flowy_folder::event_map::FolderCouldServiceV1;
-use flowy_sync::{
- errors::CollaborateError,
- server_document::ServerDocumentManager,
- server_folder::ServerFolderManager,
- synchronizer::{RevisionSyncResponse, RevisionUser},
+use flowy_folder::entities::{
+ app::{AppIdPB, CreateAppParams, UpdateAppParams},
+ trash::RepeatedTrashIdPB,
+ view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
+ workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
};
+use flowy_folder::event_map::FolderCouldServiceV1;
+use flowy_server_sync::server_document::ServerDocumentManager;
+use flowy_server_sync::server_folder::ServerFolderManager;
+use flowy_sync::{RevisionSyncResponse, RevisionUser};
+use flowy_user::entities::UserProfilePB;
+use flowy_user::event_map::UserCloudService;
+use folder_model::{gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
use futures_util::stream::StreamExt;
+use lib_infra::{future::FutureResult, util::timestamp};
use lib_ws::{WSChannel, WebSocketRawMessage};
use nanoid::nanoid;
use parking_lot::RwLock;
@@ -19,6 +29,8 @@ use std::{
sync::Arc,
};
use tokio::sync::{broadcast, mpsc, mpsc::UnboundedSender};
+use user_model::*;
+use ws_model::ws_revision::{ClientRevisionWSData, ClientRevisionWSDataType};
pub struct LocalServer {
doc_manager: Arc<ServerDocumentManager>,
@@ -128,7 +140,7 @@ impl LocalWebSocketRunner {
&self,
client_data: ClientRevisionWSData,
user_id: String,
- ) -> Result<(), CollaborateError> {
+ ) -> Result<(), SyncError> {
tracing::trace!(
"[LocalFolderServer] receive: {}:{}-{:?} ",
client_data.object_id,
@@ -157,7 +169,7 @@ impl LocalWebSocketRunner {
&self,
client_data: ClientRevisionWSData,
user_id: String,
- ) -> Result<(), CollaborateError> {
+ ) -> Result<(), SyncError> {
tracing::trace!(
"[LocalDocumentServer] receive: {}:{}-{:?} ",
client_data.object_id,
@@ -236,22 +248,6 @@ impl RevisionUser for LocalRevisionUser {
}
}
-use flowy_document::DocumentCloudService;
-use flowy_folder::entities::{
- app::{AppIdPB, CreateAppParams, UpdateAppParams},
- trash::RepeatedTrashIdPB,
- view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
- workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
-};
-use flowy_http_model::document::{CreateDocumentParams, DocumentId, DocumentPayload, ResetDocumentParams};
-use flowy_http_model::ws_data::{ClientRevisionWSData, ClientRevisionWSDataType};
-use flowy_user::entities::{
- SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
-};
-use flowy_user::event_map::UserCloudService;
-use folder_rev_model::{gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
-use lib_infra::{future::FutureResult, util::timestamp};
-
impl FolderCouldServiceV1 for LocalServer {
fn init(&self) {}
@@ -403,7 +399,7 @@ impl DocumentCloudService for LocalServer {
FutureResult::new(async { Ok(()) })
}
- fn fetch_document(&self, _token: &str, _params: DocumentId) -> FutureResult<Option<DocumentPayload>, FlowyError> {
+ fn fetch_document(&self, _token: &str, _params: DocumentId) -> FutureResult<Option<DocumentInfo>, FlowyError> {
FutureResult::new(async { Ok(None) })
}
diff --git a/frontend/rust-lib/flowy-net/src/local_server/ws.rs b/frontend/rust-lib/flowy-net/src/local_server/ws.rs
index 88f11f2709..42d943b396 100644
--- a/frontend/rust-lib/flowy-net/src/local_server/ws.rs
+++ b/frontend/rust-lib/flowy-net/src/local_server/ws.rs
@@ -1,6 +1,5 @@
-use crate::ws::connection::{FlowyRawWebSocket, FlowyWebSocket};
use dashmap::DashMap;
-use flowy_error::FlowyError;
+use flowy_client_ws::{FlowyRawWebSocket, FlowyWebSocket, WSErrorCode};
use futures_util::future::BoxFuture;
use lib_infra::future::FutureResult;
use lib_ws::{WSChannel, WSConnectState, WSMessageReceiver, WebSocketRawMessage};
@@ -36,7 +35,7 @@ impl LocalWebSocket {
}
impl FlowyRawWebSocket for LocalWebSocket {
- fn initialize(&self) -> FutureResult<(), FlowyError> {
+ fn initialize(&self) -> FutureResult<(), WSErrorCode> {
let mut server_ws_receiver = self.server_ws_receiver.write().take().expect("Only take once");
let receivers = self.receivers.clone();
tokio::spawn(async move {
@@ -50,12 +49,12 @@ impl FlowyRawWebSocket for LocalWebSocket {
FutureResult::new(async { Ok(()) })
}
- fn start_connect(&self, _addr: String, user_id: String) -> FutureResult<(), FlowyError> {
+ fn start_connect(&self, _addr: String, user_id: String) -> FutureResult<(), WSErrorCode> {
*self.user_id.write() = Some(user_id);
FutureResult::new(async { Ok(()) })
}
- fn stop_connect(&self) -> FutureResult<(), FlowyError> {
+ fn stop_connect(&self) -> FutureResult<(), WSErrorCode> {
FutureResult::new(async { Ok(()) })
}
@@ -64,17 +63,17 @@ impl FlowyRawWebSocket for LocalWebSocket {
Box::pin(async move { subscribe })
}
- fn reconnect(&self, _count: usize) -> FutureResult<(), FlowyError> {
+ fn reconnect(&self, _count: usize) -> FutureResult<(), WSErrorCode> {
FutureResult::new(async { Ok(()) })
}
- fn add_msg_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), FlowyError> {
+ fn add_msg_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), WSErrorCode> {
tracing::trace!("Local web socket add ws receiver: {:?}", receiver.source());
self.receivers.insert(receiver.source(), receiver);
Ok(())
}
- fn ws_msg_sender(&self) -> FutureResult<Option<Arc<dyn FlowyWebSocket>>, FlowyError> {
+ fn ws_msg_sender(&self) -> FutureResult<Option<Arc<dyn FlowyWebSocket>>, WSErrorCode> {
let ws: Arc<dyn FlowyWebSocket> = Arc::new(LocalWebSocketAdaptor(self.server_ws_sender.clone()));
FutureResult::new(async move { Ok(Some(ws)) })
}
@@ -84,7 +83,7 @@ impl FlowyRawWebSocket for LocalWebSocket {
struct LocalWebSocketAdaptor(broadcast::Sender<WebSocketRawMessage>);
impl FlowyWebSocket for LocalWebSocketAdaptor {
- fn send(&self, msg: WebSocketRawMessage) -> Result<(), FlowyError> {
+ fn send(&self, msg: WebSocketRawMessage) -> Result<(), WSErrorCode> {
let _ = self.0.send(msg);
Ok(())
}
diff --git a/frontend/rust-lib/flowy-net/src/request.rs b/frontend/rust-lib/flowy-net/src/request.rs
index 8da4d78741..95e98c9428 100644
--- a/frontend/rust-lib/flowy-net/src/request.rs
+++ b/frontend/rust-lib/flowy-net/src/request.rs
@@ -1,7 +1,7 @@
-use crate::configuration::HEADER_TOKEN;
+use crate::response::HttpResponse;
use bytes::Bytes;
-use http_flowy::errors::ServerError;
-use http_flowy::response::FlowyResponse;
+use flowy_client_network_config::HEADER_TOKEN;
+use flowy_error::FlowyError;
use hyper::http;
use protobuf::ProtobufError;
use reqwest::{header::HeaderMap, Client, Method, Response};
@@ -13,7 +13,7 @@ use std::{
use tokio::sync::oneshot;
pub trait ResponseMiddleware {
- fn receive_response(&self, token: &Option<String>, response: &FlowyResponse);
+ fn receive_response(&self, token: &Option<String>, response: &HttpResponse);
}
pub struct HttpRequestBuilder {
@@ -80,7 +80,8 @@ impl HttpRequestBuilder {
self
}
- pub fn protobuf<T>(self, body: T) -> Result<Self, ServerError>
+ #[allow(dead_code)]
+ pub fn protobuf<T>(self, body: T) -> Result<Self, FlowyError>
where
T: TryInto<Bytes, Error = ProtobufError>,
{
@@ -88,7 +89,7 @@ impl HttpRequestBuilder {
self.bytes(body)
}
- pub fn json<T>(self, body: T) -> Result<Self, ServerError>
+ pub fn json<T>(self, body: T) -> Result<Self, FlowyError>
where
T: serde::Serialize,
{
@@ -96,17 +97,17 @@ impl HttpRequestBuilder {
self.bytes(bytes)
}
- pub fn bytes(mut self, body: Bytes) -> Result<Self, ServerError> {
+ pub fn bytes(mut self, body: Bytes) -> Result<Self, FlowyError> {
self.body = Some(body);
Ok(self)
}
- pub async fn send(self) -> Result<(), ServerError> {
+ pub async fn send(self) -> Result<(), FlowyError> {
let _ = self.inner_send().await?;
Ok(())
}
- pub async fn response<T>(self) -> Result<T, ServerError>
+ pub async fn response<T>(self) -> Result<T, FlowyError>
where
T: TryFrom<Bytes, Error = ProtobufError>,
{
@@ -117,8 +118,19 @@ impl HttpRequestBuilder {
}
}
+ pub async fn json_response<T>(self) -> Result<T, FlowyError>
+ where
+ T: serde::de::DeserializeOwned,
+ {
+ let builder = self.inner_send().await?;
+ match builder.response {
+ None => Err(unexpected_empty_payload(&builder.url)),
+ Some(data) => Ok(serde_json::from_slice(&data)?),
+ }
+ }
+
#[allow(dead_code)]
- pub async fn option_protobuf_response<T>(self) -> Result<Option<T>, ServerError>
+ pub async fn option_protobuf_response<T>(self) -> Result<Option<T>, FlowyError>
where
T: TryFrom<Bytes, Error = ProtobufError>,
{
@@ -135,7 +147,7 @@ impl HttpRequestBuilder {
}
}
- pub async fn option_json_response<T>(self) -> Result<Option<T>, ServerError>
+ pub async fn option_json_response<T>(self) -> Result<Option<T>, FlowyError>
where
T: serde::de::DeserializeOwned + 'static,
{
@@ -162,7 +174,7 @@ impl HttpRequestBuilder {
}
}
- async fn inner_send(mut self) -> Result<Self, ServerError> {
+ async fn inner_send(mut self) -> Result<Self, FlowyError> {
let (tx, rx) = oneshot::channel::<Result<Response, _>>();
let url = self.url.clone();
let body = self.body.take();
@@ -183,7 +195,7 @@ impl HttpRequestBuilder {
let response = rx.await.map_err(|e| {
let mag = format!("Receive http response channel error: {}", e);
- ServerError::internal().context(mag)
+ FlowyError::internal().context(mag)
})??;
tracing::trace!("Http Response: {:?}", response);
let flowy_response = flowy_response_from(response).await?;
@@ -196,33 +208,33 @@ impl HttpRequestBuilder {
self.response = Some(flowy_response.data);
Ok(self)
}
- Some(error) => Err(error),
+ Some(error) => Err(FlowyError::new(error.code.into(), &error.msg)),
}
}
}
-fn unexpected_empty_payload(url: &str) -> ServerError {
+fn unexpected_empty_payload(url: &str) -> FlowyError {
let msg = format!("Request: {} receives unexpected empty payload", url);
- ServerError::payload_none().context(msg)
+ FlowyError::payload_none().context(msg)
}
-async fn flowy_response_from(original: Response) -> Result<FlowyResponse, ServerError> {
+async fn flowy_response_from(original: Response) -> Result<HttpResponse, FlowyError> {
let bytes = original.bytes().await?;
- let response: FlowyResponse = serde_json::from_slice(&bytes)?;
+ let response: HttpResponse = serde_json::from_slice(&bytes)?;
Ok(response)
}
#[allow(dead_code)]
-async fn get_response_data(original: Response) -> Result<Bytes, ServerError> {
+async fn get_response_data(original: Response) -> Result<Bytes, FlowyError> {
if original.status() == http::StatusCode::OK {
let bytes = original.bytes().await?;
- let response: FlowyResponse = serde_json::from_slice(&bytes)?;
+ let response: HttpResponse = serde_json::from_slice(&bytes)?;
match response.error {
None => Ok(response.data),
- Some(error) => Err(error),
+ Some(error) => Err(FlowyError::new(error.code.into(), &error.msg)),
}
} else {
- Err(ServerError::http().context(original))
+ Err(FlowyError::http().context(original))
}
}
@@ -235,7 +247,7 @@ fn default_client() -> Client {
match result {
Ok(client) => client,
Err(e) => {
- log::error!("Create reqwest client failed: {}", e);
+ tracing::error!("Create reqwest client failed: {}", e);
reqwest::Client::new()
}
}
diff --git a/frontend/rust-lib/flowy-net/src/response.rs b/frontend/rust-lib/flowy-net/src/response.rs
new file mode 100644
index 0000000000..fdf4ec72fa
--- /dev/null
+++ b/frontend/rust-lib/flowy-net/src/response.rs
@@ -0,0 +1,29 @@
+use bytes::Bytes;
+use flowy_error::ErrorCode;
+use serde::{Deserialize, Serialize};
+use std::fmt;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct HttpResponse {
+ pub data: Bytes,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub error: Option<HttpError>,
+}
+
+#[derive(thiserror::Error, Debug, Serialize, Deserialize, Clone)]
+pub struct HttpError {
+ pub code: ErrorCode,
+ pub msg: String,
+}
+
+impl HttpError {
+ pub fn is_unauthorized(&self) -> bool {
+ self.code == ErrorCode::UserUnauthorized
+ }
+}
+
+impl fmt::Display for HttpError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{:?}: {}", self.code, self.msg)
+ }
+}
diff --git a/frontend/rust-lib/flowy-net/src/ws/mod.rs b/frontend/rust-lib/flowy-net/src/ws/mod.rs
deleted file mode 100644
index f16abe75e3..0000000000
--- a/frontend/rust-lib/flowy-net/src/ws/mod.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod connection;
-pub mod http_ws;
diff --git a/frontend/rust-lib/flowy-notification/Cargo.toml b/frontend/rust-lib/flowy-notification/Cargo.toml
index 1d14ca21c4..afbce15cd3 100644
--- a/frontend/rust-lib/flowy-notification/Cargo.toml
+++ b/frontend/rust-lib/flowy-notification/Cargo.toml
@@ -8,7 +8,6 @@ edition = "2018"
[dependencies]
lazy_static = { version = "1.4.0" }
protobuf = { version = "2.20.0" }
-allo-isolate = { version = "^0.1", features = ["catch-unwind"] }
tracing = { version = "0.1", features = ["log"] }
bytes = { version = "1.0" }
serde = "1.0"
diff --git a/frontend/rust-lib/flowy-revision-persistence/Cargo.toml b/frontend/rust-lib/flowy-revision-persistence/Cargo.toml
index bd483b40ca..97252604d6 100644
--- a/frontend/rust-lib/flowy-revision-persistence/Cargo.toml
+++ b/frontend/rust-lib/flowy-revision-persistence/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
flowy-error = { path = "../flowy-error" }
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
+revision-model = { path = "../../../shared-lib/revision-model" }
[features]
rev-file = []
diff --git a/frontend/rust-lib/flowy-revision-persistence/src/disk_cache_impl/file_persistence.rs b/frontend/rust-lib/flowy-revision-persistence/src/disk_cache_impl/file_persistence.rs
index 32dc6e09ef..1cb3001b99 100644
--- a/frontend/rust-lib/flowy-revision-persistence/src/disk_cache_impl/file_persistence.rs
+++ b/frontend/rust-lib/flowy-revision-persistence/src/disk_cache_impl/file_persistence.rs
@@ -1,6 +1,6 @@
use crate::{RevisionChangeset, RevisionDiskCache, SyncRecord};
use flowy_error::FlowyResult;
-use flowy_http_model::revision::RevisionRange;
+use revision_model::RevisionRange;
pub struct FileRevisionDiskCache {
path: String,
diff --git a/frontend/rust-lib/flowy-revision-persistence/src/lib.rs b/frontend/rust-lib/flowy-revision-persistence/src/lib.rs
index 5196b43578..d6006af9fc 100644
--- a/frontend/rust-lib/flowy-revision-persistence/src/lib.rs
+++ b/frontend/rust-lib/flowy-revision-persistence/src/lib.rs
@@ -1,7 +1,7 @@
mod disk_cache_impl;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
+use revision_model::{Revision, RevisionRange};
use std::fmt::Debug;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-revision/Cargo.toml b/frontend/rust-lib/flowy-revision/Cargo.toml
index f68731d570..68459b069d 100644
--- a/frontend/rust-lib/flowy-revision/Cargo.toml
+++ b/frontend/rust-lib/flowy-revision/Cargo.toml
@@ -6,7 +6,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-flowy-http-model = { path = "../../../shared-lib/flowy-http-model" }
+revision-model = { path = "../../../shared-lib/revision-model" }
+ws-model = { path = "../../../shared-lib/ws-model" }
lib-ws = { path = "../../../shared-lib/lib-ws" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
flowy-error = { path = "../flowy-error" }
diff --git a/frontend/rust-lib/flowy-revision/src/cache/memory.rs b/frontend/rust-lib/flowy-revision/src/cache/memory.rs
index d0980f9d35..6942f71e27 100644
--- a/frontend/rust-lib/flowy-revision/src/cache/memory.rs
+++ b/frontend/rust-lib/flowy-revision/src/cache/memory.rs
@@ -1,8 +1,8 @@
use crate::REVISION_WRITE_INTERVAL_IN_MILLIS;
use dashmap::DashMap;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::RevisionRange;
use flowy_revision_persistence::SyncRecord;
+use revision_model::RevisionRange;
use std::{borrow::Cow, sync::Arc, time::Duration};
use tokio::{sync::RwLock, task::JoinHandle};
diff --git a/frontend/rust-lib/flowy-revision/src/cache/reset.rs b/frontend/rust-lib/flowy-revision/src/cache/reset.rs
index 2bdab1eea2..ee5971b30d 100644
--- a/frontend/rust-lib/flowy-revision/src/cache/reset.rs
+++ b/frontend/rust-lib/flowy-revision/src/cache/reset.rs
@@ -1,8 +1,8 @@
use crate::{RevisionLoader, RevisionPersistence, RevisionPersistenceConfiguration};
use bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use flowy_revision_persistence::{RevisionDiskCache, SyncRecord};
+use revision_model::Revision;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs b/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs
index 62bdd92aea..887b49dfbc 100644
--- a/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs
+++ b/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs
@@ -1,8 +1,8 @@
use crate::{RevisionMD5, RevisionManager};
use bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
use lib_infra::future::BoxResultFuture;
+use revision_model::{Revision, RevisionRange};
use std::sync::Arc;
pub struct TransformOperations<Operations> {
diff --git a/frontend/rust-lib/flowy-revision/src/history/persistence.rs b/frontend/rust-lib/flowy-revision/src/history/persistence.rs
index e422b08ab6..9fad1e257b 100644
--- a/frontend/rust-lib/flowy-revision/src/history/persistence.rs
+++ b/frontend/rust-lib/flowy-revision/src/history/persistence.rs
@@ -5,7 +5,7 @@ use flowy_database::{
ConnectionPool,
};
use flowy_error::{internal_error, FlowyResult};
-use flowy_http_model::revision::Revision;
+use revision_model::Revision;
use std::sync::Arc;
pub struct SQLiteRevisionHistoryPersistence {
diff --git a/frontend/rust-lib/flowy-revision/src/history/rev_history.rs b/frontend/rust-lib/flowy-revision/src/history/rev_history.rs
index b7802d248d..c18a91733d 100644
--- a/frontend/rust-lib/flowy-revision/src/history/rev_history.rs
+++ b/frontend/rust-lib/flowy-revision/src/history/rev_history.rs
@@ -2,10 +2,10 @@ use crate::{RevisionCompactor, RevisionHistory};
use async_stream::stream;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::Revision;
use futures_util::future::BoxFuture;
use futures_util::stream::StreamExt;
use futures_util::FutureExt;
+use revision_model::Revision;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{mpsc, RwLock};
diff --git a/frontend/rust-lib/flowy-revision/src/rev_manager.rs b/frontend/rust-lib/flowy-revision/src/rev_manager.rs
index 2c27deff6a..465b6ada61 100644
--- a/frontend/rust-lib/flowy-revision/src/rev_manager.rs
+++ b/frontend/rust-lib/flowy-revision/src/rev_manager.rs
@@ -5,9 +5,9 @@ use crate::{
};
use bytes::Bytes;
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::util::md5;
use lib_infra::future::FutureResult;
+use lib_infra::util::md5;
+use revision_model::{Revision, RevisionRange};
use std::sync::atomic::AtomicI64;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-revision/src/rev_persistence.rs b/frontend/rust-lib/flowy-revision/src/rev_persistence.rs
index 1395766869..54581f416f 100644
--- a/frontend/rust-lib/flowy-revision/src/rev_persistence.rs
+++ b/frontend/rust-lib/flowy-revision/src/rev_persistence.rs
@@ -2,8 +2,8 @@ use crate::cache::memory::RevisionMemoryCacheDelegate;
use crate::memory::RevisionMemoryCache;
use crate::RevisionMergeable;
use flowy_error::{internal_error, FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, RevisionState, SyncRecord};
+use revision_model::{Revision, RevisionRange};
use std::collections::{HashMap, VecDeque};
use std::{borrow::Cow, sync::Arc};
diff --git a/frontend/rust-lib/flowy-revision/src/rev_queue.rs b/frontend/rust-lib/flowy-revision/src/rev_queue.rs
index 94743a6e82..a52dadd59e 100644
--- a/frontend/rust-lib/flowy-revision/src/rev_queue.rs
+++ b/frontend/rust-lib/flowy-revision/src/rev_queue.rs
@@ -2,8 +2,8 @@ use crate::{RevIdCounter, RevisionMergeable, RevisionPersistence};
use async_stream::stream;
use bytes::Bytes;
use flowy_error::FlowyError;
-use flowy_http_model::revision::Revision;
use futures::stream::StreamExt;
+use revision_model::Revision;
use std::sync::Arc;
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::oneshot;
diff --git a/frontend/rust-lib/flowy-revision/src/rev_snapshot.rs b/frontend/rust-lib/flowy-revision/src/rev_snapshot.rs
index 097479ec52..90a81694bf 100644
--- a/frontend/rust-lib/flowy-revision/src/rev_snapshot.rs
+++ b/frontend/rust-lib/flowy-revision/src/rev_snapshot.rs
@@ -4,7 +4,7 @@
use crate::{RevIdCounter, RevisionMergeable, RevisionObjectDeserializer, RevisionPersistence};
use bytes::Bytes;
use flowy_error::FlowyResult;
-use flowy_http_model::revision::Revision;
+use revision_model::Revision;
use std::sync::atomic::AtomicI64;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
diff --git a/frontend/rust-lib/flowy-revision/src/ws_manager.rs b/frontend/rust-lib/flowy-revision/src/ws_manager.rs
index 217c6f4264..e11ae35406 100644
--- a/frontend/rust-lib/flowy-revision/src/ws_manager.rs
+++ b/frontend/rust-lib/flowy-revision/src/ws_manager.rs
@@ -2,11 +2,10 @@ use crate::ConflictRevisionSink;
use async_stream::stream;
use flowy_error::{FlowyError, FlowyResult};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::ws_data::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSData, WSRevisionPayload};
use futures_util::{future::BoxFuture, stream::StreamExt};
use lib_infra::future::{BoxResultFuture, FutureResult};
use lib_ws::WSConnectState;
+use revision_model::{Revision, RevisionRange};
use std::{collections::VecDeque, fmt::Formatter, sync::Arc};
use tokio::{
sync::{
@@ -16,6 +15,7 @@ use tokio::{
},
time::{interval, Duration},
};
+use ws_model::ws_revision::{ClientRevisionWSData, NewDocumentUser, ServerRevisionWSData, WSRevisionPayload};
// The consumer consumes the messages pushed by the web socket.
pub trait RevisionWSDataStream: Send + Sync {
diff --git a/frontend/rust-lib/flowy-revision/tests/revision_test/script.rs b/frontend/rust-lib/flowy-revision/tests/revision_test/script.rs
index 738abe3ea0..e4bf4b20ab 100644
--- a/frontend/rust-lib/flowy-revision/tests/revision_test/script.rs
+++ b/frontend/rust-lib/flowy-revision/tests/revision_test/script.rs
@@ -6,10 +6,10 @@ use flowy_revision::{
};
use flowy_revision_persistence::{RevisionChangeset, RevisionDiskCache, SyncRecord};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::util::md5;
+use lib_infra::util::md5;
use nanoid::nanoid;
use parking_lot::RwLock;
+use revision_model::{Revision, RevisionRange};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::time::Duration;
diff --git a/frontend/rust-lib/flowy-test/Cargo.toml b/frontend/rust-lib/flowy-test/Cargo.toml
index 2eefe8b979..6cbe07f4e5 100644
--- a/frontend/rust-lib/flowy-test/Cargo.toml
+++ b/frontend/rust-lib/flowy-test/Cargo.toml
@@ -13,13 +13,12 @@ flowy-folder = { path = "../flowy-folder", default-features = false}
flowy-document= { path = "../flowy-document", default-features = false}
lib-dispatch = { path = "../lib-dispatch" }
-flowy-sync = { path = "../flowy-sync"}
+flowy-client-sync = { path = "../flowy-client-sync"}
lib-ot = { path = "../../../shared-lib/lib-ot" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
serde = { version = "1.0", features = ["derive"] }
serde_json = {version = "1.0"}
-bincode = { version = "1.3"}
protobuf = {version = "2.24.1"}
claim = "0.5.0"
tokio = { version = "1", features = ["full"]}
@@ -33,7 +32,6 @@ nanoid = "0.4.0"
quickcheck = "1.0.3"
quickcheck_macros = "0.9.1"
fake = "2.4.3"
-claim = "0.4.0"
futures = "0.3.15"
serial_test = "0.5.1"
diff --git a/frontend/rust-lib/flowy-user/Cargo.toml b/frontend/rust-lib/flowy-user/Cargo.toml
index 2f6d2b9cea..d4473cb02a 100644
--- a/frontend/rust-lib/flowy-user/Cargo.toml
+++ b/frontend/rust-lib/flowy-user/Cargo.toml
@@ -8,8 +8,8 @@ edition = "2018"
[dependencies]
flowy-derive = { path = "../flowy-derive" }
flowy-database = { path = "../flowy-database", optional = true }
-flowy-error = { path = "../flowy-error", features = ["db", "http_server"] }
-
+flowy-error = { path = "../flowy-error", features = ["adaptor_database", "adaptor_dispatch", "adaptor_user"] }
+user-model = { path = "../../../shared-lib/user-model" }
lib-infra = { path = "../../../shared-lib/lib-infra" }
flowy-notification = { path = "../flowy-notification" }
lib-dispatch = { path = "../lib-dispatch" }
@@ -28,21 +28,10 @@ parking_lot = "0.12.1"
strum = "0.21"
strum_macros = "0.21"
tokio = { version = "1", features = ["rt"] }
-unicode-segmentation = "1.8"
-validator = "0.15"
-fancy-regex = "0.10.0"
[dev-dependencies]
flowy-test = { path = "../flowy-test" }
nanoid = "0.4.0"
-quickcheck = "1.0.3"
-quickcheck_macros = "0.9.1"
-fake = "2.4.3"
-claim = "0.4.0"
-futures = "0.3.15"
-serial_test = "0.5.1"
-rand_core = "0.6.3"
-rand = "0.8.5"
[features]
rev-sqlite = ["flowy-database"]
diff --git a/frontend/rust-lib/flowy-user/src/entities/auth.rs b/frontend/rust-lib/flowy-user/src/entities/auth.rs
index f7625b37d7..1ead6b6410 100644
--- a/frontend/rust-lib/flowy-user/src/entities/auth.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/auth.rs
@@ -1,7 +1,7 @@
-use crate::entities::parser::{UserEmail, UserName, UserPassword};
use crate::errors::ErrorCode;
use flowy_derive::ProtoBuf;
use std::convert::TryInto;
+use user_model::{SignInParams, SignUpParams, UserEmail, UserName, UserPassword};
#[derive(ProtoBuf, Default)]
pub struct SignInPayloadPB {
@@ -15,33 +15,6 @@ pub struct SignInPayloadPB {
pub name: String,
}
-#[derive(Default, ProtoBuf, Debug)]
-pub struct SignInParams {
- #[pb(index = 1)]
- pub email: String,
-
- #[pb(index = 2)]
- pub password: String,
-
- #[pb(index = 3)]
- pub name: String,
-}
-
-#[derive(Debug, Default, ProtoBuf, Clone)]
-pub struct SignInResponse {
- #[pb(index = 1)]
- pub user_id: String,
-
- #[pb(index = 2)]
- pub name: String,
-
- #[pb(index = 3)]
- pub email: String,
-
- #[pb(index = 4)]
- pub token: String,
-}
-
impl TryInto<SignInParams> for SignInPayloadPB {
type Error = ErrorCode;
@@ -83,30 +56,3 @@ impl TryInto<SignUpParams> for SignUpPayloadPB {
})
}
}
-
-#[derive(ProtoBuf, Default, Debug)]
-pub struct SignUpParams {
- #[pb(index = 1)]
- pub email: String,
-
- #[pb(index = 2)]
- pub name: String,
-
- #[pb(index = 3)]
- pub password: String,
-}
-
-#[derive(ProtoBuf, Debug, Default, Clone)]
-pub struct SignUpResponse {
- #[pb(index = 1)]
- pub user_id: String,
-
- #[pb(index = 2)]
- pub name: String,
-
- #[pb(index = 3)]
- pub email: String,
-
- #[pb(index = 4)]
- pub token: String,
-}
diff --git a/frontend/rust-lib/flowy-user/src/entities/mod.rs b/frontend/rust-lib/flowy-user/src/entities/mod.rs
index 18e64885dc..e7214db5ca 100644
--- a/frontend/rust-lib/flowy-user/src/entities/mod.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/mod.rs
@@ -3,6 +3,5 @@ pub use user_profile::*;
pub use user_setting::*;
pub mod auth;
-pub mod parser;
mod user_profile;
mod user_setting;
diff --git a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs
index f77be6880c..30a3933642 100644
--- a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs
@@ -1,10 +1,7 @@
+use crate::errors::ErrorCode;
use flowy_derive::ProtoBuf;
use std::convert::TryInto;
-
-use crate::{
- entities::parser::{UserEmail, UserIcon, UserId, UserName, UserPassword},
- errors::ErrorCode,
-};
+use user_model::{UpdateUserProfileParams, UserEmail, UserIcon, UserId, UserName, UserPassword};
#[derive(Default, ProtoBuf)]
pub struct UserTokenPB {
@@ -83,56 +80,6 @@ impl UpdateUserProfilePayloadPB {
}
}
-#[derive(ProtoBuf, Default, Clone, Debug)]
-pub struct UpdateUserProfileParams {
- #[pb(index = 1)]
- pub id: String,
-
- #[pb(index = 2, one_of)]
- pub name: Option<String>,
-
- #[pb(index = 3, one_of)]
- pub email: Option<String>,
-
- #[pb(index = 4, one_of)]
- pub password: Option<String>,
-
- #[pb(index = 5, one_of)]
- pub icon_url: Option<String>,
-}
-
-impl UpdateUserProfileParams {
- pub fn new(user_id: &str) -> Self {
- Self {
- id: user_id.to_owned(),
- name: None,
- email: None,
- password: None,
- icon_url: None,
- }
- }
-
- pub fn name(mut self, name: &str) -> Self {
- self.name = Some(name.to_owned());
- self
- }
-
- pub fn email(mut self, email: &str) -> Self {
- self.email = Some(email.to_owned());
- self
- }
-
- pub fn password(mut self, password: &str) -> Self {
- self.password = Some(password.to_owned());
- self
- }
-
- pub fn icon_url(mut self, icon_url: &str) -> Self {
- self.icon_url = Some(icon_url.to_owned());
- self
- }
-}
-
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayloadPB {
type Error = ErrorCode;
diff --git a/frontend/rust-lib/flowy-user/src/event_map.rs b/frontend/rust-lib/flowy-user/src/event_map.rs
index c543e895d3..58f3d29f0c 100644
--- a/frontend/rust-lib/flowy-user/src/event_map.rs
+++ b/frontend/rust-lib/flowy-user/src/event_map.rs
@@ -1,10 +1,9 @@
-use crate::entities::{
- SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
-};
+use crate::entities::UserProfilePB;
use crate::{errors::FlowyError, handlers::*, services::UserSession};
use lib_dispatch::prelude::*;
use lib_infra::future::FutureResult;
use std::sync::Arc;
+use user_model::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams};
pub fn init(user_session: Arc<UserSession>) -> AFPlugin {
AFPlugin::new()
diff --git a/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs b/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs
index e8a69ee239..baa1f62c6c 100644
--- a/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs
@@ -3,6 +3,7 @@ use crate::services::UserSession;
use flowy_error::FlowyError;
use lib_dispatch::prelude::*;
use std::{convert::TryInto, sync::Arc};
+use user_model::{SignInParams, SignUpParams};
// tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html
#[tracing::instrument(level = "debug", name = "sign_in", skip(data, session), fields(email = %data.email), err)]
diff --git a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs
index aaa43f2adb..f15b9e60c7 100644
--- a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs
@@ -1,11 +1,11 @@
use crate::entities::{
- AppearanceSettingsPB, UpdateUserProfileParams, UpdateUserProfilePayloadPB, UserProfilePB, UserSettingPB,
- APPEARANCE_DEFAULT_THEME,
+ AppearanceSettingsPB, UpdateUserProfilePayloadPB, UserProfilePB, UserSettingPB, APPEARANCE_DEFAULT_THEME,
};
use crate::{errors::FlowyError, services::UserSession};
use flowy_database::kv::KV;
use lib_dispatch::prelude::*;
use std::{convert::TryInto, sync::Arc};
+use user_model::UpdateUserProfileParams;
#[tracing::instrument(level = "debug", skip(session))]
pub async fn init_user_handler(session: AFPluginState<Arc<UserSession>>) -> Result<(), FlowyError> {
diff --git a/frontend/rust-lib/flowy-user/src/services/database.rs b/frontend/rust-lib/flowy-user/src/services/database.rs
index eaed88141c..b3a9529103 100644
--- a/frontend/rust-lib/flowy-user/src/services/database.rs
+++ b/frontend/rust-lib/flowy-user/src/services/database.rs
@@ -1,4 +1,4 @@
-use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfilePB};
+use crate::entities::UserProfilePB;
use flowy_database::ConnectionPool;
use flowy_database::{schema::user_table, DBConnection, Database};
use flowy_error::{ErrorCode, FlowyError};
@@ -6,6 +6,7 @@ use lazy_static::lazy_static;
use parking_lot::RwLock;
use std::path::PathBuf;
use std::{collections::HashMap, sync::Arc, time::Duration};
+use user_model::{SignInResponse, SignUpResponse, UpdateUserProfileParams};
pub struct UserDB {
db_dir: String,
@@ -41,7 +42,7 @@ impl UserDB {
tracing::trace!("open user db {} at path: {}", user_id, dir);
let db = flowy_database::init(&dir).map_err(|e| {
- log::error!("open user: {} db failed, {:?}", user_id, e);
+ tracing::error!("open user: {} db failed, {:?}", user_id, e);
FlowyError::internal().context(e)
})?;
let pool = db.get_pool();
diff --git a/frontend/rust-lib/flowy-user/src/services/user_session.rs b/frontend/rust-lib/flowy-user/src/services/user_session.rs
index de400ddcaa..dbc1904394 100644
--- a/frontend/rust-lib/flowy-user/src/services/user_session.rs
+++ b/frontend/rust-lib/flowy-user/src/services/user_session.rs
@@ -1,6 +1,4 @@
-use crate::entities::{
- SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB, UserSettingPB,
-};
+use crate::entities::{UserProfilePB, UserSettingPB};
use crate::{
errors::{ErrorCode, FlowyError},
event_map::UserCloudService,
@@ -20,6 +18,7 @@ use flowy_database::{
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::mpsc;
+use user_model::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams};
pub struct UserSessionConfig {
root_dir: String,
@@ -227,7 +226,7 @@ impl UserSession {
Ok(_) => {}
Err(e) => {
// TODO: retry?
- log::error!("update user profile failed: {:?}", e);
+ tracing::error!("update user profile failed: {:?}", e);
}
}
})
@@ -241,7 +240,7 @@ impl UserSession {
let _ = tokio::spawn(async move {
match server.sign_out(&token).await {
Ok(_) => {}
- Err(e) => log::error!("Sign out failed: {:?}", e),
+ Err(e) => tracing::error!("Sign out failed: {:?}", e),
}
})
.await;
@@ -339,7 +338,7 @@ impl std::convert::From<String> for Session {
match serde_json::from_str(&s) {
Ok(s) => s,
Err(e) => {
- log::error!("Deserialize string to Session failed: {:?}", e);
+ tracing::error!("Deserialize string to Session failed: {:?}", e);
Session::default()
}
}
@@ -350,7 +349,7 @@ impl std::convert::From<Session> for String {
match serde_json::to_string(&session) {
Ok(s) => s,
Err(e) => {
- log::error!("Serialize session to string failed: {:?}", e);
+ tracing::error!("Serialize session to string failed: {:?}", e);
"".to_string()
}
}
diff --git a/frontend/rust-lib/lib-dispatch/Cargo.toml b/frontend/rust-lib/lib-dispatch/Cargo.toml
index 6ec55ba8e5..1f6d9ece5a 100644
--- a/frontend/rust-lib/lib-dispatch/Cargo.toml
+++ b/frontend/rust-lib/lib-dispatch/Cargo.toml
@@ -8,7 +8,6 @@ edition = "2018"
[dependencies]
pin-project = "1.0"
futures-core = { version = "0.3", default-features = false }
-paste = "1"
futures-channel = "0.3.15"
futures = "0.3.15"
futures-util = "0.3.15"
@@ -16,16 +15,12 @@ bytes = {version = "1.0", features = ["serde"]}
tokio = { version = "1", features = ["full"] }
nanoid = "0.4.0"
log = "0.4.14"
-env_logger = "0.8"
-serde_with = "1.9.4"
thread-id = "3.3.0"
-lazy_static = "1.4.0"
dyn-clone = "1.0"
derivative = "2.2.0"
serde_json = {version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_repr = { version = "0.1", optional = true }
-dashmap = "5"
#optional crate
bincode = { version = "1.3", optional = true}
diff --git a/frontend/rust-lib/lib-dispatch/tests/api/module.rs b/frontend/rust-lib/lib-dispatch/tests/api/module.rs
index b14ee02494..90355d8b9b 100644
--- a/frontend/rust-lib/lib-dispatch/tests/api/module.rs
+++ b/frontend/rust-lib/lib-dispatch/tests/api/module.rs
@@ -8,8 +8,6 @@ pub async fn hello() -> String {
#[tokio::test]
async fn test() {
- env_logger::init();
-
let event = "1";
let runtime = tokio_default_runtime().unwrap();
let dispatch = Arc::new(AFPluginDispatcher::construct(runtime, || {
diff --git a/frontend/rust-lib/lib-log/Cargo.toml b/frontend/rust-lib/lib-log/Cargo.toml
index 07337a7576..193c3ea377 100644
--- a/frontend/rust-lib/lib-log/Cargo.toml
+++ b/frontend/rust-lib/lib-log/Cargo.toml
@@ -8,7 +8,6 @@ edition = "2018"
[dependencies]
tracing-log = { version = "0.1.1"}
-tracing-futures = "0.2.4"
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter", "ansi", "json"] }
tracing-bunyan-formatter = "0.2.2"
tracing-appender = "0.1"
diff --git a/shared-lib/Cargo.lock b/shared-lib/Cargo.lock
index 194952cfdd..ee9424ebf3 100644
--- a/shared-lib/Cargo.lock
+++ b/shared-lib/Cargo.lock
@@ -12,10 +12,31 @@ dependencies = [
]
[[package]]
-name = "anyhow"
-version = "1.0.47"
+name = "arrayvec"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
+
+[[package]]
+name = "async-stream"
+version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38d9ff5d688f1c13395289f67db01d4826b46dd694e7580accdc3e8430f2d98e"
+checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e"
+dependencies = [
+ "async-stream-impl",
+ "futures-core",
+]
+
+[[package]]
+name = "async-stream-impl"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
[[package]]
name = "async-trait"
@@ -51,6 +72,21 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
+[[package]]
+name = "bit-set"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
+dependencies = [
+ "bit-vec",
+]
+
+[[package]]
+name = "bit-vec"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -66,12 +102,6 @@ dependencies = [
"generic-array",
]
-[[package]]
-name = "bytecount"
-version = "0.6.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72feb31ffc86498dacdbd0fcebb56138e7177a8cc5cea4516031d15ae85a742e"
-
[[package]]
name = "byteorder"
version = "1.4.3"
@@ -104,10 +134,25 @@ dependencies = [
]
[[package]]
-name = "convert_case"
+name = "claim"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
+checksum = "68ad37958d55b29a7088909368968d2fe876a24c203f8441195130f3b15194b9"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "config"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3"
+dependencies = [
+ "lazy_static",
+ "nom",
+ "serde",
+ "yaml-rust",
+]
[[package]]
name = "cpufeatures"
@@ -129,19 +174,6 @@ dependencies = [
"parking_lot 0.12.1",
]
-[[package]]
-name = "derive_more"
-version = "0.99.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df"
-dependencies = [
- "convert_case",
- "proc-macro2",
- "quote",
- "rustc_version",
- "syn",
-]
-
[[package]]
name = "digest"
version = "0.9.0"
@@ -151,6 +183,15 @@ dependencies = [
"generic-array",
]
+[[package]]
+name = "document-model"
+version = "0.1.0"
+dependencies = [
+ "revision-model",
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "env_logger"
version = "0.8.4"
@@ -165,14 +206,96 @@ dependencies = [
]
[[package]]
-name = "flowy-http-model"
+name = "fake"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d68f517805463f3a896a9d29c1d6ff09d3579ded64a7201b4069f8f9c0d52fd"
+dependencies = [
+ "rand",
+]
+
+[[package]]
+name = "fancy-regex"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2"
+dependencies = [
+ "bit-set",
+ "regex",
+]
+
+[[package]]
+name = "flowy-client-network-config"
version = "0.1.0"
dependencies = [
- "bytes",
- "md5",
+ "config",
"serde",
+ "serde-aux",
"serde_json",
+]
+
+[[package]]
+name = "flowy-client-ws"
+version = "0.1.0"
+dependencies = [
+ "futures-util",
+ "lib-infra",
+ "lib-ws",
+ "parking_lot 0.12.1",
+ "serde",
"serde_repr",
+ "thiserror",
+ "tokio",
+ "tracing",
+]
+
+[[package]]
+name = "flowy-error-code"
+version = "0.1.0"
+dependencies = [
+ "http-error-code",
+ "serde",
+ "serde_repr",
+ "thiserror",
+]
+
+[[package]]
+name = "flowy-server-sync"
+version = "0.1.0"
+dependencies = [
+ "async-stream",
+ "bytes",
+ "dashmap",
+ "document-model",
+ "flowy-sync",
+ "folder-model",
+ "futures",
+ "lib-infra",
+ "lib-ot",
+ "log",
+ "revision-model",
+ "serde",
+ "tokio",
+ "tracing",
+ "ws-model",
+]
+
+[[package]]
+name = "flowy-sync"
+version = "0.1.0"
+dependencies = [
+ "document-model",
+ "folder-model",
+ "lib-infra",
+ "lib-ot",
+ "parking_lot 0.12.1",
+ "revision-model",
+ "serde",
+ "strum",
+ "strum_macros",
+ "tokio",
+ "tracing",
+ "ws-model",
]
[[package]]
@@ -182,17 +305,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
-name = "folder-rev-model"
+name = "folder-model"
version = "0.1.0"
dependencies = [
- "bytes",
"chrono",
"nanoid",
"serde",
- "serde_json",
"serde_repr",
- "strum",
- "strum_macros",
]
[[package]]
@@ -321,7 +440,7 @@ dependencies = [
]
[[package]]
-name = "grid-rev-model"
+name = "grid-model"
version = "0.1.0"
dependencies = [
"bytes",
@@ -367,6 +486,16 @@ dependencies = [
"itoa",
]
+[[package]]
+name = "http-error-code"
+version = "0.1.0"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Server?branch=refactor/appflowy_server#5e74d35e93efd6b92f501ee8f3081a23b9839108"
+dependencies = [
+ "serde",
+ "serde_repr",
+ "thiserror",
+]
+
[[package]]
name = "httparse"
version = "1.5.1"
@@ -428,6 +557,19 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+[[package]]
+name = "lexical-core"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
+dependencies = [
+ "arrayvec",
+ "bitflags",
+ "cfg-if",
+ "ryu",
+ "static_assertions",
+]
+
[[package]]
name = "lib-infra"
version = "0.1.0"
@@ -436,6 +578,7 @@ dependencies = [
"bytes",
"chrono",
"futures-core",
+ "md5",
"pin-project",
"rand",
"tokio",
@@ -445,23 +588,16 @@ dependencies = [
name = "lib-ot"
version = "0.1.0"
dependencies = [
- "anyhow",
- "bytecount",
"bytes",
- "dashmap",
- "derive_more",
"indexmap",
"indextree",
"lazy_static",
"log",
- "md5",
"serde",
"serde_json",
- "serde_repr",
"strum",
"strum_macros",
"thiserror",
- "tokio",
"tracing",
]
@@ -479,13 +615,11 @@ dependencies = [
"lib-infra",
"log",
"parking_lot 0.12.1",
- "paste",
"pin-project",
"protobuf",
"serde",
"serde_json",
"serde_repr",
- "strum",
"strum_macros",
"tokio",
"tokio-tungstenite",
@@ -499,6 +633,12 @@ version = "0.2.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219"
+[[package]]
+name = "linked-hash-map"
+version = "0.5.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
+
[[package]]
name = "lock_api"
version = "0.4.6"
@@ -566,6 +706,17 @@ dependencies = [
"rand",
]
+[[package]]
+name = "nom"
+version = "5.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
+dependencies = [
+ "lexical-core",
+ "memchr",
+ "version_check",
+]
+
[[package]]
name = "ntapi"
version = "0.3.6"
@@ -664,27 +815,12 @@ dependencies = [
"windows-sys",
]
-[[package]]
-name = "paste"
-version = "1.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5"
-
[[package]]
name = "percent-encoding"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
-[[package]]
-name = "pest"
-version = "2.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
-dependencies = [
- "ucd-trie",
-]
-
[[package]]
name = "pin-project"
version = "1.0.12"
@@ -750,6 +886,28 @@ version = "2.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47c327e191621a2158159df97cdbc2e7074bb4e940275e35abf38eb3d2595754"
+[[package]]
+name = "quickcheck"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6"
+dependencies = [
+ "env_logger",
+ "log",
+ "rand",
+]
+
+[[package]]
+name = "quickcheck_macros"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "608c156fd8e97febc07dc9c2e2c80bf74cfc6ef26893eae3daf8bc2bc94a4b7f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "quote"
version = "1.0.10"
@@ -816,12 +974,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
-name = "rustc_version"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
+name = "revision-model"
+version = "0.1.0"
dependencies = [
- "semver",
+ "bytes",
+ "md5",
+ "serde",
+ "serde_json",
]
[[package]]
@@ -837,30 +996,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
-name = "semver"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
-dependencies = [
- "semver-parser",
-]
-
-[[package]]
-name = "semver-parser"
-version = "0.10.2"
+name = "serde"
+version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7"
+checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
dependencies = [
- "pest",
+ "serde_derive",
]
[[package]]
-name = "serde"
-version = "1.0.136"
+name = "serde-aux"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
+checksum = "905f2fc9f3d1574e8b5923a58118240021f01d4e239673937ffb9f42707a4f22"
dependencies = [
- "serde_derive",
+ "chrono",
+ "serde",
+ "serde_json",
]
[[package]]
@@ -896,6 +1048,28 @@ dependencies = [
"syn",
]
+[[package]]
+name = "serial_test"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d"
+dependencies = [
+ "lazy_static",
+ "parking_lot 0.11.2",
+ "serial_test_derive",
+]
+
+[[package]]
+name = "serial_test_derive"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "sha-1"
version = "0.9.8"
@@ -930,6 +1104,12 @@ version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
+[[package]]
+name = "static_assertions"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+
[[package]]
name = "strum"
version = "0.21.0"
@@ -1116,12 +1296,6 @@ version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
-[[package]]
-name = "ucd-trie"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
-
[[package]]
name = "unicode-bidi"
version = "0.3.7"
@@ -1161,12 +1335,50 @@ dependencies = [
"percent-encoding",
]
+[[package]]
+name = "user-model"
+version = "0.1.0"
+dependencies = [
+ "claim",
+ "fake",
+ "fancy-regex",
+ "futures",
+ "lazy_static",
+ "nanoid",
+ "quickcheck",
+ "quickcheck_macros",
+ "rand",
+ "rand_core",
+ "serde",
+ "serde_repr",
+ "serial_test",
+ "thiserror",
+ "tracing",
+ "unicode-segmentation",
+ "validator",
+]
+
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
+[[package]]
+name = "validator"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32ad5bf234c7d3ad1042e5252b7eddb2c4669ee23f32c7dd0e9b7705f07ef591"
+dependencies = [
+ "idna",
+ "lazy_static",
+ "regex",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "url",
+]
+
[[package]]
name = "version_check"
version = "0.9.3"
@@ -1252,3 +1464,23 @@ name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
+
+[[package]]
+name = "ws-model"
+version = "0.1.0"
+dependencies = [
+ "bytes",
+ "revision-model",
+ "serde",
+ "serde_json",
+ "serde_repr",
+]
+
+[[package]]
+name = "yaml-rust"
+version = "0.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
+dependencies = [
+ "linked-hash-map",
+]
diff --git a/shared-lib/Cargo.toml b/shared-lib/Cargo.toml
index ccad2db7fe..7f19d7fe7d 100644
--- a/shared-lib/Cargo.toml
+++ b/shared-lib/Cargo.toml
@@ -3,9 +3,16 @@ members = [
"lib-ot",
"lib-ws",
"lib-infra",
- "grid-rev-model",
- "folder-rev-model",
- "flowy-http-model",
+ "grid-model",
+ "folder-model",
+ "document-model",
+ "ws-model",
+ "revision-model",
+ "flowy-sync",
+ "flowy-server-sync",
+ "user-model",
+ "flowy-client-network-config",
+ "flowy-client-ws",
]
[profile.dev]
diff --git a/shared-lib/document-model/Cargo.toml b/shared-lib/document-model/Cargo.toml
new file mode 100644
index 0000000000..eeb9f22233
--- /dev/null
+++ b/shared-lib/document-model/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "document-model"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+serde = { version = "1.0" }
+serde_json = { version = "1.0" }
+revision-model = { path = "../revision-model"}
\ No newline at end of file
diff --git a/shared-lib/flowy-http-model/src/entities/document.rs b/shared-lib/document-model/src/document.rs
similarity index 91%
rename from shared-lib/flowy-http-model/src/entities/document.rs
rename to shared-lib/document-model/src/document.rs
index 6dbf1cf2d1..90886b8532 100644
--- a/shared-lib/flowy-http-model/src/entities/document.rs
+++ b/shared-lib/document-model/src/document.rs
@@ -1,4 +1,4 @@
-use crate::revision::Revision;
+use revision_model::Revision;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
@@ -8,14 +8,14 @@ pub struct CreateDocumentParams {
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)]
-pub struct DocumentPayload {
+pub struct DocumentInfo {
pub doc_id: String,
pub data: Vec<u8>,
pub rev_id: i64,
pub base_rev_id: i64,
}
-impl std::convert::TryFrom<Revision> for DocumentPayload {
+impl std::convert::TryFrom<Revision> for DocumentInfo {
type Error = String;
fn try_from(revision: Revision) -> Result<Self, Self::Error> {
@@ -23,7 +23,7 @@ impl std::convert::TryFrom<Revision> for DocumentPayload {
return Err("Revision's rev_id should be 0 when creating the document".to_string());
}
- Ok(DocumentPayload {
+ Ok(DocumentInfo {
doc_id: revision.object_id,
data: revision.bytes,
rev_id: revision.rev_id,
diff --git a/shared-lib/document-model/src/lib.rs b/shared-lib/document-model/src/lib.rs
new file mode 100644
index 0000000000..b3316091b4
--- /dev/null
+++ b/shared-lib/document-model/src/lib.rs
@@ -0,0 +1 @@
+pub mod document;
diff --git a/shared-lib/flowy-client-network-config/Cargo.toml b/shared-lib/flowy-client-network-config/Cargo.toml
new file mode 100644
index 0000000000..e35e03dcab
--- /dev/null
+++ b/shared-lib/flowy-client-network-config/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "flowy-client-network-config"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+config = { version = "0.10.1", default-features = false, features = ["yaml"] }
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
+serde-aux = "1.0.1"
diff --git a/frontend/rust-lib/flowy-net/configuration/base.yaml b/shared-lib/flowy-client-network-config/configuration/base.yaml
similarity index 100%
rename from frontend/rust-lib/flowy-net/configuration/base.yaml
rename to shared-lib/flowy-client-network-config/configuration/base.yaml
diff --git a/frontend/rust-lib/flowy-net/configuration/local.yaml b/shared-lib/flowy-client-network-config/configuration/local.yaml
similarity index 100%
rename from frontend/rust-lib/flowy-net/configuration/local.yaml
rename to shared-lib/flowy-client-network-config/configuration/local.yaml
diff --git a/frontend/rust-lib/flowy-net/configuration/production.yaml b/shared-lib/flowy-client-network-config/configuration/production.yaml
similarity index 100%
rename from frontend/rust-lib/flowy-net/configuration/production.yaml
rename to shared-lib/flowy-client-network-config/configuration/production.yaml
diff --git a/frontend/rust-lib/flowy-net/src/configuration.rs b/shared-lib/flowy-client-network-config/src/configuration.rs
similarity index 100%
rename from frontend/rust-lib/flowy-net/src/configuration.rs
rename to shared-lib/flowy-client-network-config/src/configuration.rs
diff --git a/shared-lib/flowy-client-network-config/src/lib.rs b/shared-lib/flowy-client-network-config/src/lib.rs
new file mode 100644
index 0000000000..f1d68e4caa
--- /dev/null
+++ b/shared-lib/flowy-client-network-config/src/lib.rs
@@ -0,0 +1,2 @@
+mod configuration;
+pub use configuration::*;
diff --git a/shared-lib/flowy-client-ws/Cargo.toml b/shared-lib/flowy-client-ws/Cargo.toml
new file mode 100644
index 0000000000..62c45b09c1
--- /dev/null
+++ b/shared-lib/flowy-client-ws/Cargo.toml
@@ -0,0 +1,17 @@
+[package]
+name = "flowy-client-ws"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+lib-ws = { path = "../lib-ws" }
+lib-infra = { path = "../lib-infra" }
+futures-util = "0.3.15"
+tokio = {version = "1", features = ["sync"]}
+parking_lot = "0.12.1"
+tracing = { version = "0.1", features = ["log"] }
+thiserror = "1.0"
+serde_repr = "0.1"
+serde = "1.0"
diff --git a/frontend/rust-lib/flowy-net/src/ws/connection.rs b/shared-lib/flowy-client-ws/src/connection.rs
similarity index 78%
rename from frontend/rust-lib/flowy-net/src/ws/connection.rs
rename to shared-lib/flowy-client-ws/src/connection.rs
index e2b5d7db2d..04ce6fd8cc 100644
--- a/frontend/rust-lib/flowy-net/src/ws/connection.rs
+++ b/shared-lib/flowy-client-ws/src/connection.rs
@@ -1,27 +1,54 @@
-use crate::entities::NetworkType;
-
-pub use flowy_error::FlowyError;
-use lib_infra::future::FutureResult;
-pub use lib_ws::{WSConnectState, WSMessageReceiver, WebSocketRawMessage};
-
use futures_util::future::BoxFuture;
+use lib_infra::future::FutureResult;
use lib_ws::WSController;
+pub use lib_ws::{WSConnectState, WSMessageReceiver, WebSocketRawMessage};
use parking_lot::RwLock;
+use serde_repr::*;
use std::sync::Arc;
+use thiserror::Error;
use tokio::sync::broadcast;
+#[derive(Debug, Clone, PartialEq, Eq, Error, Serialize_repr, Deserialize_repr)]
+#[repr(u8)]
+pub enum WSErrorCode {
+ #[error("Internal error")]
+ Internal = 0,
+}
+
pub trait FlowyRawWebSocket: Send + Sync {
- fn initialize(&self) -> FutureResult<(), FlowyError>;
- fn start_connect(&self, addr: String, user_id: String) -> FutureResult<(), FlowyError>;
- fn stop_connect(&self) -> FutureResult<(), FlowyError>;
+ fn initialize(&self) -> FutureResult<(), WSErrorCode>;
+ fn start_connect(&self, addr: String, user_id: String) -> FutureResult<(), WSErrorCode>;
+ fn stop_connect(&self) -> FutureResult<(), WSErrorCode>;
fn subscribe_connect_state(&self) -> BoxFuture<broadcast::Receiver<WSConnectState>>;
- fn reconnect(&self, count: usize) -> FutureResult<(), FlowyError>;
- fn add_msg_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), FlowyError>;
- fn ws_msg_sender(&self) -> FutureResult<Option<Arc<dyn FlowyWebSocket>>, FlowyError>;
+ fn reconnect(&self, count: usize) -> FutureResult<(), WSErrorCode>;
+ fn add_msg_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), WSErrorCode>;
+ fn ws_msg_sender(&self) -> FutureResult<Option<Arc<dyn FlowyWebSocket>>, WSErrorCode>;
}
pub trait FlowyWebSocket: Send + Sync {
- fn send(&self, msg: WebSocketRawMessage) -> Result<(), FlowyError>;
+ fn send(&self, msg: WebSocketRawMessage) -> Result<(), WSErrorCode>;
+}
+
+#[derive(Debug, Clone, Eq, PartialEq)]
+pub enum NetworkType {
+ Unknown = 0,
+ Wifi = 1,
+ Cell = 2,
+ Ethernet = 3,
+ Bluetooth = 4,
+ VPN = 5,
+}
+
+impl std::default::Default for NetworkType {
+ fn default() -> Self {
+ NetworkType::Unknown
+ }
+}
+
+impl NetworkType {
+ pub fn is_connect(&self) -> bool {
+ !matches!(self, NetworkType::Unknown | NetworkType::Bluetooth)
+ }
}
pub struct FlowyWebSocketConnect {
@@ -60,7 +87,7 @@ impl FlowyWebSocketConnect {
}
}
- pub async fn start(&self, token: String, user_id: String) -> Result<(), FlowyError> {
+ pub async fn start(&self, token: String, user_id: String) -> Result<(), WSErrorCode> {
let addr = format!("{}/{}", self.addr, &token);
self.inner.stop_connect().await?;
self.inner.start_connect(addr, user_id).await?;
@@ -71,12 +98,12 @@ impl FlowyWebSocketConnect {
let _ = self.inner.stop_connect().await;
}
- pub fn update_network_type(&self, new_type: &NetworkType) {
+ pub fn update_network_type(&self, new_type: NetworkType) {
tracing::debug!("Network new state: {:?}", new_type);
let old_type = self.connect_type.read().clone();
let _ = self.status_notifier.send(new_type.clone());
- if &old_type != new_type {
+ if old_type != new_type {
tracing::debug!("Connect type switch from {:?} to {:?}", old_type, new_type);
match (old_type.is_connect(), new_type.is_connect()) {
(false, true) => {
@@ -89,7 +116,7 @@ impl FlowyWebSocketConnect {
_ => {}
}
- *self.connect_type.write() = new_type.clone();
+ *self.connect_type.write() = new_type;
}
}
@@ -101,12 +128,12 @@ impl FlowyWebSocketConnect {
self.status_notifier.subscribe()
}
- pub fn add_ws_message_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), FlowyError> {
+ pub fn add_ws_message_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), WSErrorCode> {
self.inner.add_msg_receiver(receiver)?;
Ok(())
}
- pub async fn web_socket(&self) -> Result<Option<Arc<dyn FlowyWebSocket>>, FlowyError> {
+ pub async fn web_socket(&self) -> Result<Option<Arc<dyn FlowyWebSocket>>, WSErrorCode> {
self.inner.ws_msg_sender().await
}
}
diff --git a/shared-lib/flowy-client-ws/src/lib.rs b/shared-lib/flowy-client-ws/src/lib.rs
new file mode 100644
index 0000000000..15b00f693a
--- /dev/null
+++ b/shared-lib/flowy-client-ws/src/lib.rs
@@ -0,0 +1,5 @@
+mod connection;
+mod ws;
+
+pub use connection::*;
+pub use ws::*;
diff --git a/frontend/rust-lib/flowy-net/src/ws/http_ws.rs b/shared-lib/flowy-client-ws/src/ws.rs
similarity index 76%
rename from frontend/rust-lib/flowy-net/src/ws/http_ws.rs
rename to shared-lib/flowy-client-ws/src/ws.rs
index c9cb6e1267..1de5c54cde 100644
--- a/frontend/rust-lib/flowy-net/src/ws/http_ws.rs
+++ b/shared-lib/flowy-client-ws/src/ws.rs
@@ -1,20 +1,18 @@
-use crate::ws::connection::{FlowyRawWebSocket, FlowyWebSocket};
-use flowy_error::internal_error;
-pub use flowy_error::FlowyError;
+use crate::connection::{FlowyRawWebSocket, FlowyWebSocket};
+use crate::WSErrorCode;
+use futures_util::future::BoxFuture;
use lib_infra::future::FutureResult;
pub use lib_ws::{WSConnectState, WSMessageReceiver, WebSocketRawMessage};
use lib_ws::{WSController, WSSender};
-
-use futures_util::future::BoxFuture;
use std::sync::Arc;
use tokio::sync::broadcast::Receiver;
impl FlowyRawWebSocket for Arc<WSController> {
- fn initialize(&self) -> FutureResult<(), FlowyError> {
+ fn initialize(&self) -> FutureResult<(), WSErrorCode> {
FutureResult::new(async { Ok(()) })
}
- fn start_connect(&self, addr: String, _user_id: String) -> FutureResult<(), FlowyError> {
+ fn start_connect(&self, addr: String, _user_id: String) -> FutureResult<(), WSErrorCode> {
let cloned_ws = self.clone();
FutureResult::new(async move {
cloned_ws.start(addr).await.map_err(internal_error)?;
@@ -22,7 +20,7 @@ impl FlowyRawWebSocket for Arc<WSController> {
})
}
- fn stop_connect(&self) -> FutureResult<(), FlowyError> {
+ fn stop_connect(&self) -> FutureResult<(), WSErrorCode> {
let controller = self.clone();
FutureResult::new(async move {
controller.stop().await;
@@ -35,7 +33,7 @@ impl FlowyRawWebSocket for Arc<WSController> {
Box::pin(async move { cloned_ws.subscribe_state().await })
}
- fn reconnect(&self, count: usize) -> FutureResult<(), FlowyError> {
+ fn reconnect(&self, count: usize) -> FutureResult<(), WSErrorCode> {
let cloned_ws = self.clone();
FutureResult::new(async move {
cloned_ws.retry(count).await.map_err(internal_error)?;
@@ -43,12 +41,12 @@ impl FlowyRawWebSocket for Arc<WSController> {
})
}
- fn add_msg_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), FlowyError> {
+ fn add_msg_receiver(&self, receiver: Arc<dyn WSMessageReceiver>) -> Result<(), WSErrorCode> {
self.add_ws_message_receiver(receiver).map_err(internal_error)?;
Ok(())
}
- fn ws_msg_sender(&self) -> FutureResult<Option<Arc<dyn FlowyWebSocket>>, FlowyError> {
+ fn ws_msg_sender(&self) -> FutureResult<Option<Arc<dyn FlowyWebSocket>>, WSErrorCode> {
let cloned_self = self.clone();
FutureResult::new(async move {
match cloned_self.ws_message_sender().await.map_err(internal_error)? {
@@ -63,8 +61,15 @@ impl FlowyRawWebSocket for Arc<WSController> {
}
impl FlowyWebSocket for WSSender {
- fn send(&self, msg: WebSocketRawMessage) -> Result<(), FlowyError> {
+ fn send(&self, msg: WebSocketRawMessage) -> Result<(), WSErrorCode> {
self.send_msg(msg).map_err(internal_error)?;
Ok(())
}
}
+
+fn internal_error<T>(_e: T) -> WSErrorCode
+where
+ T: std::fmt::Debug,
+{
+ WSErrorCode::Internal
+}
diff --git a/shared-lib/flowy-http-model/src/entities/mod.rs b/shared-lib/flowy-http-model/src/entities/mod.rs
deleted file mode 100644
index 93e6431dd0..0000000000
--- a/shared-lib/flowy-http-model/src/entities/mod.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-pub mod document;
-pub mod folder;
-
-pub use crate::ws_data::*;
-pub use document::*;
-pub use folder::*;
diff --git a/shared-lib/flowy-http-model/src/lib.rs b/shared-lib/flowy-http-model/src/lib.rs
deleted file mode 100644
index d62dc9a03f..0000000000
--- a/shared-lib/flowy-http-model/src/lib.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-pub mod entities;
-pub mod revision;
-pub mod util;
-pub mod ws_data;
-pub use entities::*;
diff --git a/shared-lib/flowy-http-model/src/util.rs b/shared-lib/flowy-http-model/src/util.rs
deleted file mode 100644
index 00c4473e93..0000000000
--- a/shared-lib/flowy-http-model/src/util.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-#[inline]
-pub fn md5<T: AsRef<[u8]>>(data: T) -> String {
- let md5 = format!("{:x}", md5::compute(data));
- md5
-}
diff --git a/shared-lib/flowy-server-sync/Cargo.toml b/shared-lib/flowy-server-sync/Cargo.toml
new file mode 100644
index 0000000000..e9ba2fb9d3
--- /dev/null
+++ b/shared-lib/flowy-server-sync/Cargo.toml
@@ -0,0 +1,23 @@
+[package]
+name = "flowy-server-sync"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+revision-model = { path = "../revision-model" }
+ws-model = { path = "../ws-model" }
+document-model = { path = "../document-model" }
+folder-model = { path = "../folder-model" }
+flowy-sync = { path = "../flowy-sync" }
+bytes = "1.0"
+log = "0.4.14"
+tokio = { version = "1", features = ["full"] }
+serde = { version = "1.0", features = ["derive", "rc"] }
+lib-ot = { path = "../lib-ot" }
+lib-infra = { path = "../lib-infra" }
+dashmap = "5"
+futures = "0.3.15"
+async-stream = "0.3.2"
+tracing = { version = "0.1", features = ["log"] }
diff --git a/shared-lib/flowy-server-sync/src/lib.rs b/shared-lib/flowy-server-sync/src/lib.rs
new file mode 100644
index 0000000000..9990e45b04
--- /dev/null
+++ b/shared-lib/flowy-server-sync/src/lib.rs
@@ -0,0 +1,2 @@
+pub mod server_document;
+pub mod server_folder;
diff --git a/frontend/rust-lib/flowy-sync/src/server_document/document_manager.rs b/shared-lib/flowy-server-sync/src/server_document/document_manager.rs
similarity index 70%
rename from frontend/rust-lib/flowy-sync/src/server_document/document_manager.rs
rename to shared-lib/flowy-server-sync/src/server_document/document_manager.rs
index 4c595113f9..572c0977b0 100644
--- a/frontend/rust-lib/flowy-sync/src/server_document/document_manager.rs
+++ b/shared-lib/flowy-server-sync/src/server_document/document_manager.rs
@@ -1,61 +1,20 @@
-use crate::{
- errors::{internal_error, CollaborateError, CollaborateResult},
- server_document::document_pad::ServerDocument,
- synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionSynchronizer, RevisionUser},
-};
+use crate::server_document::document_pad::ServerDocument;
use async_stream::stream;
use dashmap::DashMap;
-use flowy_http_model::document::DocumentPayload;
-use flowy_http_model::entities::ClientRevisionWSData;
-use flowy_http_model::revision::Revision;
-use flowy_http_model::ws_data::ServerRevisionWSDataBuilder;
+use document_model::document::DocumentInfo;
+use flowy_sync::errors::{internal_sync_error, SyncError, SyncResult};
+use flowy_sync::ext::DocumentCloudPersistence;
+use flowy_sync::{RevisionSyncResponse, RevisionSynchronizer, RevisionUser};
use futures::stream::StreamExt;
-use lib_infra::future::BoxResultFuture;
use lib_ot::core::AttributeHashMap;
use lib_ot::text_delta::DeltaTextOperations;
-use std::{collections::HashMap, fmt::Debug, sync::Arc};
+use revision_model::Revision;
+use std::{collections::HashMap, sync::Arc};
use tokio::{
sync::{mpsc, oneshot, RwLock},
task::spawn_blocking,
};
-
-pub trait DocumentCloudPersistence: Send + Sync + Debug {
- fn read_document(&self, doc_id: &str) -> BoxResultFuture<DocumentPayload, CollaborateError>;
-
- fn create_document(
- &self,
- doc_id: &str,
- revisions: Vec<Revision>,
- ) -> BoxResultFuture<Option<DocumentPayload>, CollaborateError>;
-
- fn read_document_revisions(
- &self,
- doc_id: &str,
- rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError>;
-
- fn save_document_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
-
- fn reset_document(&self, doc_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
-}
-
-impl RevisionSyncPersistence for Arc<dyn DocumentCloudPersistence> {
- fn read_revisions(
- &self,
- object_id: &str,
- rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
- (**self).read_document_revisions(object_id, rev_ids)
- }
-
- fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
- (**self).save_document_revisions(revisions)
- }
-
- fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
- (**self).reset_document(object_id, revisions)
- }
-}
+use ws_model::ws_revision::{ClientRevisionWSData, ServerRevisionWSDataBuilder};
pub struct ServerDocumentManager {
document_handlers: Arc<RwLock<HashMap<String, Arc<OpenDocumentHandler>>>>,
@@ -74,7 +33,7 @@ impl ServerDocumentManager {
&self,
user: Arc<dyn RevisionUser>,
client_data: ClientRevisionWSData,
- ) -> Result<(), CollaborateError> {
+ ) -> Result<(), SyncError> {
let cloned_user = user.clone();
let ack_id = client_data.rev_id;
let object_id = client_data.object_id;
@@ -85,9 +44,7 @@ impl ServerDocumentManager {
let _ = self
.create_document(&object_id, client_data.revisions)
.await
- .map_err(|e| {
- CollaborateError::internal().context(format!("Server create document failed: {}", e))
- })?;
+ .map_err(|e| SyncError::internal().context(format!("Server create document failed: {}", e)))?;
Ok(())
}
Some(handler) => {
@@ -108,7 +65,7 @@ impl ServerDocumentManager {
&self,
user: Arc<dyn RevisionUser>,
client_data: ClientRevisionWSData,
- ) -> Result<(), CollaborateError> {
+ ) -> Result<(), SyncError> {
let rev_id = client_data.rev_id;
let doc_id = client_data.object_id.clone();
match self.get_document_handler(&doc_id).await {
@@ -123,11 +80,7 @@ impl ServerDocumentManager {
}
}
- pub async fn handle_document_reset(
- &self,
- doc_id: &str,
- mut revisions: Vec<Revision>,
- ) -> Result<(), CollaborateError> {
+ pub async fn handle_document_reset(&self, doc_id: &str, mut revisions: Vec<Revision>) -> Result<(), SyncError> {
revisions.sort_by(|a, b| a.rev_id.cmp(&b.rev_id));
match self.get_document_handler(doc_id).await {
@@ -150,7 +103,7 @@ impl ServerDocumentManager {
let mut write_guard = self.document_handlers.write().await;
match self.persistence.read_document(doc_id).await {
Ok(doc) => {
- let handler = self.create_document_handler(doc).await.map_err(internal_error).unwrap();
+ let handler = self.create_document_handler(doc).await.unwrap();
write_guard.insert(doc_id.to_owned(), handler.clone());
drop(write_guard);
Some(handler)
@@ -163,9 +116,9 @@ impl ServerDocumentManager {
&self,
doc_id: &str,
revisions: Vec<Revision>,
- ) -> Result<Arc<OpenDocumentHandler>, CollaborateError> {
+ ) -> Result<Arc<OpenDocumentHandler>, SyncError> {
match self.persistence.create_document(doc_id, revisions).await? {
- None => Err(CollaborateError::internal().context("Create document info from revisions failed")),
+ None => Err(SyncError::internal().context("Create document info from revisions failed")),
Some(doc) => {
let handler = self.create_document_handler(doc).await?;
self.document_handlers
@@ -178,14 +131,11 @@ impl ServerDocumentManager {
}
#[tracing::instrument(level = "debug", skip(self, doc), err)]
- async fn create_document_handler(
- &self,
- doc: DocumentPayload,
- ) -> Result<Arc<OpenDocumentHandler>, CollaborateError> {
+ async fn create_document_handler(&self, doc: DocumentInfo) -> Result<Arc<OpenDocumentHandler>, SyncError> {
let persistence = self.persistence.clone();
let handle = spawn_blocking(|| OpenDocumentHandler::new(doc, persistence))
.await
- .map_err(|e| CollaborateError::internal().context(format!("Create document handler failed: {}", e)))?;
+ .map_err(|e| SyncError::internal().context(format!("Create document handler failed: {}", e)))?;
Ok(Arc::new(handle?))
}
}
@@ -205,7 +155,7 @@ struct OpenDocumentHandler {
}
impl OpenDocumentHandler {
- fn new(doc: DocumentPayload, persistence: Arc<dyn DocumentCloudPersistence>) -> Result<Self, CollaborateError> {
+ fn new(doc: DocumentInfo, persistence: Arc<dyn DocumentCloudPersistence>) -> Result<Self, SyncError> {
let doc_id = doc.doc_id.clone();
let (sender, receiver) = mpsc::channel(1000);
let users = DashMap::new();
@@ -225,11 +175,7 @@ impl OpenDocumentHandler {
skip(self, user, revisions),
err
)]
- async fn apply_revisions(
- &self,
- user: Arc<dyn RevisionUser>,
- revisions: Vec<Revision>,
- ) -> Result<(), CollaborateError> {
+ async fn apply_revisions(&self, user: Arc<dyn RevisionUser>, revisions: Vec<Revision>) -> Result<(), SyncError> {
let (ret, rx) = oneshot::channel();
self.users.insert(user.user_id(), user.clone());
let msg = DocumentCommand::ApplyRevisions { user, revisions, ret };
@@ -237,7 +183,7 @@ impl OpenDocumentHandler {
self.send(msg, rx).await?
}
- async fn apply_ping(&self, rev_id: i64, user: Arc<dyn RevisionUser>) -> Result<(), CollaborateError> {
+ async fn apply_ping(&self, rev_id: i64, user: Arc<dyn RevisionUser>) -> Result<(), SyncError> {
let (ret, rx) = oneshot::channel();
self.users.insert(user.user_id(), user.clone());
let msg = DocumentCommand::Ping { user, rev_id, ret };
@@ -245,18 +191,18 @@ impl OpenDocumentHandler {
}
#[tracing::instrument(level = "debug", skip(self, revisions), err)]
- async fn apply_document_reset(&self, revisions: Vec<Revision>) -> Result<(), CollaborateError> {
+ async fn apply_document_reset(&self, revisions: Vec<Revision>) -> Result<(), SyncError> {
let (ret, rx) = oneshot::channel();
let msg = DocumentCommand::Reset { revisions, ret };
self.send(msg, rx).await?
}
- async fn send<T>(&self, msg: DocumentCommand, rx: oneshot::Receiver<T>) -> CollaborateResult<T> {
+ async fn send<T>(&self, msg: DocumentCommand, rx: oneshot::Receiver<T>) -> SyncResult<T> {
self.sender
.send(msg)
.await
- .map_err(|e| CollaborateError::internal().context(format!("Send document command failed: {}", e)))?;
- rx.await.map_err(internal_error)
+ .map_err(|e| SyncError::internal().context(format!("Send document command failed: {}", e)))?;
+ rx.await.map_err(internal_sync_error)
}
}
@@ -271,16 +217,16 @@ enum DocumentCommand {
ApplyRevisions {
user: Arc<dyn RevisionUser>,
revisions: Vec<Revision>,
- ret: oneshot::Sender<CollaborateResult<()>>,
+ ret: oneshot::Sender<SyncResult<()>>,
},
Ping {
user: Arc<dyn RevisionUser>,
rev_id: i64,
- ret: oneshot::Sender<CollaborateResult<()>>,
+ ret: oneshot::Sender<SyncResult<()>>,
},
Reset {
revisions: Vec<Revision>,
- ret: oneshot::Sender<CollaborateResult<()>>,
+ ret: oneshot::Sender<SyncResult<()>>,
},
}
@@ -327,15 +273,15 @@ impl DocumentCommandRunner {
.synchronizer
.sync_revisions(user, revisions)
.await
- .map_err(internal_error);
+ .map_err(internal_sync_error);
let _ = ret.send(result);
}
DocumentCommand::Ping { user, rev_id, ret } => {
- let result = self.synchronizer.pong(user, rev_id).await.map_err(internal_error);
+ let result = self.synchronizer.pong(user, rev_id).await.map_err(internal_sync_error);
let _ = ret.send(result);
}
DocumentCommand::Reset { revisions, ret } => {
- let result = self.synchronizer.reset(revisions).await.map_err(internal_error);
+ let result = self.synchronizer.reset(revisions).await.map_err(internal_sync_error);
let _ = ret.send(result);
}
}
diff --git a/frontend/rust-lib/flowy-sync/src/server_document/document_pad.rs b/shared-lib/flowy-server-sync/src/server_document/document_pad.rs
similarity index 64%
rename from frontend/rust-lib/flowy-sync/src/server_document/document_pad.rs
rename to shared-lib/flowy-server-sync/src/server_document/document_pad.rs
index 46e82e4fa7..2c60c780b3 100644
--- a/frontend/rust-lib/flowy-sync/src/server_document/document_pad.rs
+++ b/shared-lib/flowy-server-sync/src/server_document/document_pad.rs
@@ -1,5 +1,5 @@
-use crate::synchronizer::RevisionOperations;
-use crate::{client_document::InitialDocument, errors::CollaborateError, synchronizer::RevisionSyncObject};
+use flowy_sync::errors::SyncError;
+use flowy_sync::{RevisionOperations, RevisionSyncObject};
use lib_ot::{core::*, text_delta::DeltaTextOperations};
pub struct ServerDocument {
@@ -8,12 +8,6 @@ pub struct ServerDocument {
}
impl ServerDocument {
- #[allow(dead_code)]
- pub fn new<C: InitialDocument>(doc_id: &str) -> Self {
- let operations = DeltaTextOperations::from_json(&C::json_str()).unwrap();
- Self::from_operations(doc_id, operations)
- }
-
pub fn from_operations(document_id: &str, operations: DeltaTextOperations) -> Self {
let document_id = document_id.to_owned();
ServerDocument {
@@ -32,16 +26,13 @@ impl RevisionSyncObject<AttributeHashMap> for ServerDocument {
self.operations.json_str()
}
- fn compose(&mut self, other: &DeltaTextOperations) -> Result<(), CollaborateError> {
+ fn compose(&mut self, other: &DeltaTextOperations) -> Result<(), SyncError> {
let operations = self.operations.compose(other)?;
self.operations = operations;
Ok(())
}
- fn transform(
- &self,
- other: &DeltaTextOperations,
- ) -> Result<(DeltaTextOperations, DeltaTextOperations), CollaborateError> {
+ fn transform(&self, other: &DeltaTextOperations) -> Result<(DeltaTextOperations, DeltaTextOperations), SyncError> {
let value = self.operations.transform(other)?;
Ok(value)
}
diff --git a/frontend/rust-lib/flowy-sync/src/server_document/mod.rs b/shared-lib/flowy-server-sync/src/server_document/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/server_document/mod.rs
rename to shared-lib/flowy-server-sync/src/server_document/mod.rs
diff --git a/frontend/rust-lib/flowy-sync/src/server_folder/folder_manager.rs b/shared-lib/flowy-server-sync/src/server_folder/folder_manager.rs
similarity index 71%
rename from frontend/rust-lib/flowy-sync/src/server_folder/folder_manager.rs
rename to shared-lib/flowy-server-sync/src/server_folder/folder_manager.rs
index 84c587de6c..c7c6d3c5fb 100644
--- a/frontend/rust-lib/flowy-sync/src/server_folder/folder_manager.rs
+++ b/shared-lib/flowy-server-sync/src/server_folder/folder_manager.rs
@@ -1,60 +1,18 @@
use crate::server_folder::folder_pad::{FolderOperations, FolderRevisionSynchronizer};
-use crate::{
- errors::{internal_error, CollaborateError, CollaborateResult},
- server_folder::folder_pad::ServerFolder,
- synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionUser},
-};
+use crate::server_folder::ServerFolder;
use async_stream::stream;
-use flowy_http_model::entities::ClientRevisionWSData;
-use flowy_http_model::folder::FolderInfo;
-use flowy_http_model::revision::Revision;
-use flowy_http_model::ws_data::ServerRevisionWSDataBuilder;
+use flowy_sync::errors::{internal_sync_error, SyncError, SyncResult};
+use flowy_sync::ext::FolderCloudPersistence;
+use flowy_sync::{RevisionSyncResponse, RevisionUser};
+use folder_model::FolderInfo;
use futures::stream::StreamExt;
-use lib_infra::future::BoxResultFuture;
-use std::{collections::HashMap, fmt::Debug, sync::Arc};
+use revision_model::Revision;
+use std::{collections::HashMap, sync::Arc};
use tokio::{
sync::{mpsc, oneshot, RwLock},
task::spawn_blocking,
};
-
-pub trait FolderCloudPersistence: Send + Sync + Debug {
- fn read_folder(&self, user_id: &str, folder_id: &str) -> BoxResultFuture<FolderInfo, CollaborateError>;
-
- fn create_folder(
- &self,
- user_id: &str,
- folder_id: &str,
- revisions: Vec<Revision>,
- ) -> BoxResultFuture<Option<FolderInfo>, CollaborateError>;
-
- fn save_folder_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
-
- fn read_folder_revisions(
- &self,
- folder_id: &str,
- rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError>;
-
- fn reset_folder(&self, folder_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
-}
-
-impl RevisionSyncPersistence for Arc<dyn FolderCloudPersistence> {
- fn read_revisions(
- &self,
- object_id: &str,
- rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
- (**self).read_folder_revisions(object_id, rev_ids)
- }
-
- fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
- (**self).save_folder_revisions(revisions)
- }
-
- fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError> {
- (**self).reset_folder(object_id, revisions)
- }
-}
+use ws_model::ws_revision::{ClientRevisionWSData, ServerRevisionWSDataBuilder};
pub struct ServerFolderManager {
folder_handlers: Arc<RwLock<HashMap<String, Arc<OpenFolderHandler>>>>,
@@ -73,7 +31,7 @@ impl ServerFolderManager {
&self,
user: Arc<dyn RevisionUser>,
client_data: ClientRevisionWSData,
- ) -> Result<(), CollaborateError> {
+ ) -> Result<(), SyncError> {
let cloned_user = user.clone();
let ack_id = client_data.rev_id;
let folder_id = client_data.object_id;
@@ -84,7 +42,7 @@ impl ServerFolderManager {
let _ = self
.create_folder(&user_id, &folder_id, client_data.revisions)
.await
- .map_err(|e| CollaborateError::internal().context(format!("Server create folder failed: {}", e)))?;
+ .map_err(|e| SyncError::internal().context(format!("Server create folder failed: {:?}", e)))?;
Ok(())
}
Some(handler) => {
@@ -105,7 +63,7 @@ impl ServerFolderManager {
&self,
user: Arc<dyn RevisionUser>,
client_data: ClientRevisionWSData,
- ) -> Result<(), CollaborateError> {
+ ) -> Result<(), SyncError> {
let user_id = user.user_id();
let rev_id = client_data.rev_id;
let folder_id = client_data.object_id.clone();
@@ -133,7 +91,7 @@ impl ServerFolderManager {
let handler = self
.create_folder_handler(folder_info)
.await
- .map_err(internal_error)
+ .map_err(internal_sync_error)
.unwrap();
write_guard.insert(folder_id, handler.clone());
drop(write_guard);
@@ -143,11 +101,11 @@ impl ServerFolderManager {
}
}
- async fn create_folder_handler(&self, folder_info: FolderInfo) -> Result<Arc<OpenFolderHandler>, CollaborateError> {
+ async fn create_folder_handler(&self, folder_info: FolderInfo) -> Result<Arc<OpenFolderHandler>, SyncError> {
let persistence = self.persistence.clone();
let handle = spawn_blocking(|| OpenFolderHandler::new(folder_info, persistence))
.await
- .map_err(|e| CollaborateError::internal().context(format!("Create folder handler failed: {}", e)))?;
+ .map_err(|e| SyncError::internal().context(format!("Create folder handler failed: {}", e)))?;
Ok(Arc::new(handle?))
}
@@ -157,7 +115,7 @@ impl ServerFolderManager {
user_id: &str,
folder_id: &str,
revisions: Vec<Revision>,
- ) -> Result<Arc<OpenFolderHandler>, CollaborateError> {
+ ) -> Result<Arc<OpenFolderHandler>, SyncError> {
match self.persistence.create_folder(user_id, folder_id, revisions).await? {
Some(folder_info) => {
let handler = self.create_folder_handler(folder_info).await?;
@@ -167,7 +125,7 @@ impl ServerFolderManager {
.insert(folder_id.to_owned(), handler.clone());
Ok(handler)
}
- None => Err(CollaborateError::internal().context(String::new())),
+ None => Err(SyncError::internal().context(String::new())),
}
}
}
@@ -178,7 +136,7 @@ struct OpenFolderHandler {
}
impl OpenFolderHandler {
- fn new(folder_info: FolderInfo, persistence: Arc<dyn FolderCloudPersistence>) -> CollaborateResult<Self> {
+ fn new(folder_info: FolderInfo, persistence: Arc<dyn FolderCloudPersistence>) -> SyncResult<Self> {
let (sender, receiver) = mpsc::channel(1000);
let folder_id = folder_info.folder_id.clone();
let operations = FolderOperations::from_bytes(&folder_info.text)?;
@@ -201,25 +159,25 @@ impl OpenFolderHandler {
skip(self, user, revisions),
err
)]
- async fn apply_revisions(&self, user: Arc<dyn RevisionUser>, revisions: Vec<Revision>) -> CollaborateResult<()> {
+ async fn apply_revisions(&self, user: Arc<dyn RevisionUser>, revisions: Vec<Revision>) -> SyncResult<()> {
let (ret, rx) = oneshot::channel();
let msg = FolderCommand::ApplyRevisions { user, revisions, ret };
self.send(msg, rx).await?
}
- async fn apply_ping(&self, rev_id: i64, user: Arc<dyn RevisionUser>) -> Result<(), CollaborateError> {
+ async fn apply_ping(&self, rev_id: i64, user: Arc<dyn RevisionUser>) -> Result<(), SyncError> {
let (ret, rx) = oneshot::channel();
let msg = FolderCommand::Ping { user, rev_id, ret };
self.send(msg, rx).await?
}
- async fn send<T>(&self, msg: FolderCommand, rx: oneshot::Receiver<T>) -> CollaborateResult<T> {
+ async fn send<T>(&self, msg: FolderCommand, rx: oneshot::Receiver<T>) -> SyncResult<T> {
self.sender
.send(msg)
.await
- .map_err(|e| CollaborateError::internal().context(format!("Send folder command failed: {}", e)))?;
- rx.await.map_err(internal_error)
+ .map_err(|e| SyncError::internal().context(format!("Send folder command failed: {}", e)))?;
+ rx.await.map_err(internal_sync_error)
}
}
@@ -233,12 +191,12 @@ enum FolderCommand {
ApplyRevisions {
user: Arc<dyn RevisionUser>,
revisions: Vec<Revision>,
- ret: oneshot::Sender<CollaborateResult<()>>,
+ ret: oneshot::Sender<SyncResult<()>>,
},
Ping {
user: Arc<dyn RevisionUser>,
rev_id: i64,
- ret: oneshot::Sender<CollaborateResult<()>>,
+ ret: oneshot::Sender<SyncResult<()>>,
},
}
@@ -284,11 +242,11 @@ impl FolderCommandRunner {
.synchronizer
.sync_revisions(user, revisions)
.await
- .map_err(internal_error);
+ .map_err(internal_sync_error);
let _ = ret.send(result);
}
FolderCommand::Ping { user, rev_id, ret } => {
- let result = self.synchronizer.pong(user, rev_id).await.map_err(internal_error);
+ let result = self.synchronizer.pong(user, rev_id).await.map_err(internal_sync_error);
let _ = ret.send(result);
}
}
diff --git a/frontend/rust-lib/flowy-sync/src/server_folder/folder_pad.rs b/shared-lib/flowy-server-sync/src/server_folder/folder_pad.rs
similarity index 54%
rename from frontend/rust-lib/flowy-sync/src/server_folder/folder_pad.rs
rename to shared-lib/flowy-server-sync/src/server_folder/folder_pad.rs
index b979b95f87..8aab49c1c1 100644
--- a/frontend/rust-lib/flowy-sync/src/server_folder/folder_pad.rs
+++ b/shared-lib/flowy-server-sync/src/server_folder/folder_pad.rs
@@ -1,6 +1,8 @@
-use crate::synchronizer::{RevisionOperations, RevisionSynchronizer};
-use crate::{errors::CollaborateError, synchronizer::RevisionSyncObject};
+use flowy_sync::errors::SyncError;
+use flowy_sync::{RevisionOperations, RevisionSyncObject, RevisionSynchronizer};
+use folder_model::FolderInfo;
use lib_ot::core::{DeltaOperationBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
+use revision_model::Revision;
pub type FolderRevisionSynchronizer = RevisionSynchronizer<EmptyAttributes>;
pub type FolderOperations = DeltaOperations<EmptyAttributes>;
@@ -29,13 +31,13 @@ impl RevisionSyncObject<EmptyAttributes> for ServerFolder {
self.operations.json_str()
}
- fn compose(&mut self, other: &FolderOperations) -> Result<(), CollaborateError> {
+ fn compose(&mut self, other: &FolderOperations) -> Result<(), SyncError> {
let operations = self.operations.compose(other)?;
self.operations = operations;
Ok(())
}
- fn transform(&self, other: &FolderOperations) -> Result<(FolderOperations, FolderOperations), CollaborateError> {
+ fn transform(&self, other: &FolderOperations) -> Result<(FolderOperations, FolderOperations), SyncError> {
let value = self.operations.transform(other)?;
Ok(value)
}
@@ -44,3 +46,31 @@ impl RevisionSyncObject<EmptyAttributes> for ServerFolder {
self.operations = operations;
}
}
+
+#[inline]
+pub fn make_folder_from_revisions(folder_id: &str, revisions: Vec<Revision>) -> Result<Option<FolderInfo>, SyncError> {
+ if revisions.is_empty() {
+ return Ok(None);
+ }
+
+ let mut folder_delta = FolderOperations::new();
+ let mut base_rev_id = 0;
+ let mut rev_id = 0;
+ for revision in revisions {
+ base_rev_id = revision.base_rev_id;
+ rev_id = revision.rev_id;
+ if revision.bytes.is_empty() {
+ tracing::warn!("revision delta_data is empty");
+ }
+ let delta = FolderOperations::from_bytes(revision.bytes)?;
+ folder_delta = folder_delta.compose(&delta)?;
+ }
+
+ let text = folder_delta.json_str();
+ Ok(Some(FolderInfo {
+ folder_id: folder_id.to_string(),
+ text,
+ rev_id,
+ base_rev_id,
+ }))
+}
diff --git a/frontend/rust-lib/flowy-sync/src/server_folder/mod.rs b/shared-lib/flowy-server-sync/src/server_folder/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-sync/src/server_folder/mod.rs
rename to shared-lib/flowy-server-sync/src/server_folder/mod.rs
diff --git a/shared-lib/flowy-sync/Cargo.toml b/shared-lib/flowy-sync/Cargo.toml
new file mode 100644
index 0000000000..876c51dcb7
--- /dev/null
+++ b/shared-lib/flowy-sync/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "flowy-sync"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+lib-ot = { path = "../lib-ot" }
+lib-infra = { path = "../lib-infra" }
+revision-model = { path = "../revision-model" }
+folder-model = { path = "../folder-model" }
+ws-model = { path = "../ws-model" }
+document-model = { path = "../document-model" }
+strum = "0.21"
+strum_macros = "0.21"
+parking_lot = "0.12.1"
+tokio = { version = "1", features = ["full"] }
+serde = { version = "1.0", features = ["derive", "rc"] }
+tracing = { version = "0.1", features = ["log"] }
diff --git a/frontend/rust-lib/flowy-sync/src/errors.rs b/shared-lib/flowy-sync/src/errors.rs
similarity index 71%
rename from frontend/rust-lib/flowy-sync/src/errors.rs
rename to shared-lib/flowy-sync/src/errors.rs
index 42419109d6..bf319a9a82 100644
--- a/frontend/rust-lib/flowy-sync/src/errors.rs
+++ b/shared-lib/flowy-sync/src/errors.rs
@@ -1,11 +1,12 @@
-use std::{fmt, fmt::Debug};
+use std::fmt;
+use std::fmt::Debug;
use strum_macros::Display;
macro_rules! static_error {
($name:ident, $status:expr) => {
#[allow(non_snake_case, missing_docs)]
- pub fn $name() -> CollaborateError {
- CollaborateError {
+ pub fn $name() -> SyncError {
+ SyncError {
code: $status,
msg: format!("{}", $status),
}
@@ -13,15 +14,15 @@ macro_rules! static_error {
};
}
-pub type CollaborateResult<T> = std::result::Result<T, CollaborateError>;
+pub type SyncResult<T> = std::result::Result<T, SyncError>;
#[derive(Debug, Clone)]
-pub struct CollaborateError {
+pub struct SyncError {
pub code: ErrorCode,
pub msg: String,
}
-impl CollaborateError {
+impl SyncError {
fn new(code: ErrorCode, msg: &str) -> Self {
Self {
code,
@@ -45,7 +46,7 @@ impl CollaborateError {
static_error!(unexpected_empty_revision, ErrorCode::UnexpectedEmptyRevision);
}
-impl fmt::Display for CollaborateError {
+impl fmt::Display for SyncError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}: {}", &self.code, &self.msg)
}
@@ -66,21 +67,21 @@ pub enum ErrorCode {
InternalError = 1000,
}
-impl std::convert::From<lib_ot::errors::OTError> for CollaborateError {
+impl std::convert::From<lib_ot::errors::OTError> for SyncError {
fn from(error: lib_ot::errors::OTError) -> Self {
- CollaborateError::new(ErrorCode::InternalError, "").context(error)
+ SyncError::new(ErrorCode::InternalError, "").context(error)
}
}
-impl std::convert::From<protobuf::ProtobufError> for CollaborateError {
- fn from(e: protobuf::ProtobufError) -> Self {
- CollaborateError::internal().context(e)
- }
-}
+// impl std::convert::From<protobuf::ProtobufError> for SyncError {
+// fn from(e: protobuf::ProtobufError) -> Self {
+// SyncError::internal().context(e)
+// }
+// }
-pub(crate) fn internal_error<T>(e: T) -> CollaborateError
+pub fn internal_sync_error<T>(e: T) -> SyncError
where
T: std::fmt::Debug,
{
- CollaborateError::internal().context(e)
+ SyncError::internal().context(e)
}
diff --git a/shared-lib/flowy-sync/src/ext.rs b/shared-lib/flowy-sync/src/ext.rs
new file mode 100644
index 0000000000..778c3c14d0
--- /dev/null
+++ b/shared-lib/flowy-sync/src/ext.rs
@@ -0,0 +1,77 @@
+use crate::errors::SyncError;
+use crate::RevisionSyncPersistence;
+use document_model::document::DocumentInfo;
+use folder_model::FolderInfo;
+use lib_infra::future::BoxResultFuture;
+use revision_model::Revision;
+use std::fmt::Debug;
+use std::sync::Arc;
+
+pub trait FolderCloudPersistence: Send + Sync + Debug {
+ fn read_folder(&self, user_id: &str, folder_id: &str) -> BoxResultFuture<FolderInfo, SyncError>;
+
+ fn create_folder(
+ &self,
+ user_id: &str,
+ folder_id: &str,
+ revisions: Vec<Revision>,
+ ) -> BoxResultFuture<Option<FolderInfo>, SyncError>;
+
+ fn save_folder_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+
+ fn read_folder_revisions(
+ &self,
+ folder_id: &str,
+ rev_ids: Option<Vec<i64>>,
+ ) -> BoxResultFuture<Vec<Revision>, SyncError>;
+
+ fn reset_folder(&self, folder_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+}
+
+impl RevisionSyncPersistence for Arc<dyn FolderCloudPersistence> {
+ fn read_revisions(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> BoxResultFuture<Vec<Revision>, SyncError> {
+ (**self).read_folder_revisions(object_id, rev_ids)
+ }
+
+ fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
+ (**self).save_folder_revisions(revisions)
+ }
+
+ fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
+ (**self).reset_folder(object_id, revisions)
+ }
+}
+
+pub trait DocumentCloudPersistence: Send + Sync + Debug {
+ fn read_document(&self, doc_id: &str) -> BoxResultFuture<DocumentInfo, SyncError>;
+
+ fn create_document(
+ &self,
+ doc_id: &str,
+ revisions: Vec<Revision>,
+ ) -> BoxResultFuture<Option<DocumentInfo>, SyncError>;
+
+ fn read_document_revisions(
+ &self,
+ doc_id: &str,
+ rev_ids: Option<Vec<i64>>,
+ ) -> BoxResultFuture<Vec<Revision>, SyncError>;
+
+ fn save_document_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+
+ fn reset_document(&self, doc_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+}
+
+impl RevisionSyncPersistence for Arc<dyn DocumentCloudPersistence> {
+ fn read_revisions(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> BoxResultFuture<Vec<Revision>, SyncError> {
+ (**self).read_document_revisions(object_id, rev_ids)
+ }
+
+ fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
+ (**self).save_document_revisions(revisions)
+ }
+
+ fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
+ (**self).reset_document(object_id, revisions)
+ }
+}
diff --git a/frontend/rust-lib/flowy-sync/src/synchronizer.rs b/shared-lib/flowy-sync/src/lib.rs
similarity index 82%
rename from frontend/rust-lib/flowy-sync/src/synchronizer.rs
rename to shared-lib/flowy-sync/src/lib.rs
index 0b88115050..e0f63cde58 100644
--- a/frontend/rust-lib/flowy-sync/src/synchronizer.rs
+++ b/shared-lib/flowy-sync/src/lib.rs
@@ -1,43 +1,33 @@
-use crate::{errors::CollaborateError, util::*};
-use flowy_http_model::revision::{Revision, RevisionRange};
-use flowy_http_model::ws_data::{ServerRevisionWSData, ServerRevisionWSDataBuilder};
+pub mod errors;
+pub mod ext;
+pub mod util;
+
+use crate::errors::SyncError;
+use crate::util::{make_operations_from_revisions, next, pair_rev_id_from_revision_pbs};
use lib_infra::future::BoxResultFuture;
use lib_ot::core::{DeltaOperations, OperationAttributes};
use parking_lot::RwLock;
+use revision_model::{Revision, RevisionRange};
use serde::de::DeserializeOwned;
-use std::{
- cmp::Ordering,
- fmt::Debug,
- sync::{
- atomic::{AtomicI64, Ordering::SeqCst},
- Arc,
- },
- time::Duration,
-};
+use std::cmp::Ordering;
+use std::fmt::Debug;
+use std::sync::atomic::AtomicI64;
+use std::sync::atomic::Ordering::SeqCst;
+use std::sync::Arc;
+use std::time::Duration;
+use ws_model::ws_revision::{ServerRevisionWSData, ServerRevisionWSDataBuilder};
pub type RevisionOperations<Attribute> = DeltaOperations<Attribute>;
-pub trait RevisionOperations2<Attribute>: Send + Sync {
- fn from_bytes<B: AsRef<[u8]>>(bytes: B) -> Result<Self, CollaborateError>
- where
- Self: Sized;
-}
-
pub trait RevisionUser: Send + Sync + Debug {
fn user_id(&self) -> String;
fn receive(&self, resp: RevisionSyncResponse);
}
-pub trait RevisionSyncPersistence: Send + Sync + 'static {
- fn read_revisions(
- &self,
- object_id: &str,
- rev_ids: Option<Vec<i64>>,
- ) -> BoxResultFuture<Vec<Revision>, CollaborateError>;
-
- fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
-
- fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), CollaborateError>;
+pub enum RevisionSyncResponse {
+ Pull(ServerRevisionWSData),
+ Push(ServerRevisionWSData),
+ Ack(ServerRevisionWSData),
}
pub trait RevisionSyncObject<Attribute: OperationAttributes>: Send + Sync + 'static {
@@ -45,20 +35,39 @@ pub trait RevisionSyncObject<Attribute: OperationAttributes>: Send + Sync + 'sta
fn object_json(&self) -> String;
- fn compose(&mut self, other: &RevisionOperations<Attribute>) -> Result<(), CollaborateError>;
+ fn compose(&mut self, other: &RevisionOperations<Attribute>) -> Result<(), SyncError>;
fn transform(
&self,
other: &RevisionOperations<Attribute>,
- ) -> Result<(RevisionOperations<Attribute>, RevisionOperations<Attribute>), CollaborateError>;
+ ) -> Result<(RevisionOperations<Attribute>, RevisionOperations<Attribute>), SyncError>;
fn set_operations(&mut self, operations: RevisionOperations<Attribute>);
}
-pub enum RevisionSyncResponse {
- Pull(ServerRevisionWSData),
- Push(ServerRevisionWSData),
- Ack(ServerRevisionWSData),
+pub trait RevisionSyncPersistence: Send + Sync + 'static {
+ fn read_revisions(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> BoxResultFuture<Vec<Revision>, SyncError>;
+
+ fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+
+ fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
+}
+
+impl<T> RevisionSyncPersistence for Arc<T>
+where
+ T: RevisionSyncPersistence + Sized,
+{
+ fn read_revisions(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> BoxResultFuture<Vec<Revision>, SyncError> {
+ (**self).read_revisions(object_id, rev_ids)
+ }
+
+ fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
+ (**self).save_revisions(revisions)
+ }
+
+ fn reset_object(&self, object_id: &str, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
+ (**self).reset_object(object_id, revisions)
+ }
}
pub struct RevisionSynchronizer<Attribute: OperationAttributes> {
@@ -89,11 +98,7 @@ where
}
#[tracing::instrument(level = "trace", skip(self, user, revisions), err)]
- pub async fn sync_revisions(
- &self,
- user: Arc<dyn RevisionUser>,
- revisions: Vec<Revision>,
- ) -> Result<(), CollaborateError> {
+ pub async fn sync_revisions(&self, user: Arc<dyn RevisionUser>, revisions: Vec<Revision>) -> Result<(), SyncError> {
let object_id = self.object_id.clone();
if revisions.is_empty() {
// Return all the revisions to client
@@ -146,10 +151,10 @@ where
}
#[tracing::instrument(level = "trace", skip(self, user), fields(server_rev_id), err)]
- pub async fn pong(&self, user: Arc<dyn RevisionUser>, client_rev_id: i64) -> Result<(), CollaborateError> {
+ pub async fn pong(&self, user: Arc<dyn RevisionUser>, client_rev_id: i64) -> Result<(), SyncError> {
let object_id = self.object_id.clone();
let server_rev_id = self.rev_id();
- tracing::Span::current().record("server_rev_id", server_rev_id);
+ tracing::Span::current().record("server_rev_id", &server_rev_id);
match server_rev_id.cmp(&client_rev_id) {
Ordering::Less => {
tracing::trace!("Client should not send ping and the server should pull the revisions from the client")
@@ -169,9 +174,9 @@ where
}
#[tracing::instrument(level = "debug", skip(self, revisions), fields(object_id), err)]
- pub async fn reset(&self, revisions: Vec<Revision>) -> Result<(), CollaborateError> {
+ pub async fn reset(&self, revisions: Vec<Revision>) -> Result<(), SyncError> {
let object_id = self.object_id.clone();
- tracing::Span::current().record("object_id", object_id.as_str());
+ tracing::Span::current().record("object_id", &object_id.as_str());
let (_, rev_id) = pair_rev_id_from_revision_pbs(&revisions);
let operations = make_operations_from_revisions(revisions.clone())?;
self.persistence.reset_object(&object_id, revisions).await?;
@@ -184,7 +189,7 @@ where
self.object.read().object_json()
}
- fn compose_revision(&self, revision: &Revision) -> Result<(), CollaborateError> {
+ fn compose_revision(&self, revision: &Revision) -> Result<(), SyncError> {
let operations = RevisionOperations::<Attribute>::from_bytes(&revision.bytes)?;
self.compose_operations(operations)?;
let _ = self.rev_id.fetch_update(SeqCst, SeqCst, |_e| Some(revision.rev_id));
@@ -195,19 +200,19 @@ where
fn transform_revision(
&self,
revision: &Revision,
- ) -> Result<(RevisionOperations<Attribute>, RevisionOperations<Attribute>), CollaborateError> {
+ ) -> Result<(RevisionOperations<Attribute>, RevisionOperations<Attribute>), SyncError> {
let client_operations = RevisionOperations::<Attribute>::from_bytes(&revision.bytes)?;
let result = self.object.read().transform(&client_operations)?;
Ok(result)
}
- fn compose_operations(&self, operations: RevisionOperations<Attribute>) -> Result<(), CollaborateError> {
+ fn compose_operations(&self, operations: RevisionOperations<Attribute>) -> Result<(), SyncError> {
if operations.is_empty() {
- log::warn!("Composed operations is empty");
+ tracing::warn!("Composed operations is empty");
}
match self.object.try_write_for(Duration::from_millis(300)) {
- None => log::error!("Failed to acquire write lock of object"),
+ None => tracing::error!("Failed to acquire write lock of object"),
Some(mut write_guard) => {
write_guard.compose(&operations)?;
}
@@ -250,13 +255,8 @@ where
user.receive(RevisionSyncResponse::Push(data));
}
Err(e) => {
- tracing::error!("{}", e);
+ tracing::error!("{:?}", e);
}
};
}
}
-
-#[inline]
-fn next(rev_id: i64) -> i64 {
- rev_id + 1
-}
diff --git a/shared-lib/flowy-sync/src/util.rs b/shared-lib/flowy-sync/src/util.rs
new file mode 100644
index 0000000000..328050ab74
--- /dev/null
+++ b/shared-lib/flowy-sync/src/util.rs
@@ -0,0 +1,45 @@
+use crate::errors::{SyncError, SyncResult};
+
+use lib_ot::core::{DeltaOperations, OperationAttributes, OperationTransform};
+use revision_model::Revision;
+use serde::de::DeserializeOwned;
+
+pub fn pair_rev_id_from_revision_pbs(revisions: &[Revision]) -> (i64, i64) {
+ let mut rev_id = 0;
+ revisions.iter().for_each(|revision| {
+ if rev_id < revision.rev_id {
+ rev_id = revision.rev_id;
+ }
+ });
+
+ if rev_id > 0 {
+ (rev_id - 1, rev_id)
+ } else {
+ (0, rev_id)
+ }
+}
+
+#[tracing::instrument(level = "trace", skip(revisions), err)]
+pub fn make_operations_from_revisions<T>(revisions: Vec<Revision>) -> SyncResult<DeltaOperations<T>>
+where
+ T: OperationAttributes + DeserializeOwned + OperationAttributes + serde::Serialize,
+{
+ let mut new_operations = DeltaOperations::<T>::new();
+ for revision in revisions {
+ if revision.bytes.is_empty() {
+ return Err(SyncError::unexpected_empty_revision().context("Unexpected Empty revision"));
+ }
+ let operations = DeltaOperations::<T>::from_bytes(revision.bytes).map_err(|e| {
+ let err_msg = format!("Deserialize revision failed: {:?}", e);
+ SyncError::internal().context(err_msg)
+ })?;
+
+ new_operations = new_operations.compose(&operations)?;
+ }
+ Ok(new_operations)
+}
+
+#[inline]
+pub fn next(rev_id: i64) -> i64 {
+ rev_id + 1
+}
diff --git a/shared-lib/folder-rev-model/Cargo.toml b/shared-lib/folder-model/Cargo.toml
similarity index 74%
rename from shared-lib/folder-rev-model/Cargo.toml
rename to shared-lib/folder-model/Cargo.toml
index 90976a13df..ea3804b6ef 100644
--- a/shared-lib/folder-rev-model/Cargo.toml
+++ b/shared-lib/folder-model/Cargo.toml
@@ -1,16 +1,12 @@
[package]
-name = "folder-rev-model"
+name = "folder-model"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-bytes = "1.0"
-strum = "0.21"
-strum_macros = "0.21"
nanoid = "0.4.0"
chrono = { version = "0.4" }
serde = { version = "1.0", features = ["derive", "rc"] }
-serde_json = "1.0"
serde_repr = "0.1"
diff --git a/shared-lib/folder-rev-model/src/app_rev.rs b/shared-lib/folder-model/src/app_rev.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/app_rev.rs
rename to shared-lib/folder-model/src/app_rev.rs
diff --git a/shared-lib/flowy-http-model/src/entities/folder.rs b/shared-lib/folder-model/src/folder.rs
similarity index 100%
rename from shared-lib/flowy-http-model/src/entities/folder.rs
rename to shared-lib/folder-model/src/folder.rs
diff --git a/shared-lib/folder-rev-model/src/folder_rev.rs b/shared-lib/folder-model/src/folder_rev.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/folder_rev.rs
rename to shared-lib/folder-model/src/folder_rev.rs
diff --git a/shared-lib/folder-rev-model/src/lib.rs b/shared-lib/folder-model/src/lib.rs
similarity index 87%
rename from shared-lib/folder-rev-model/src/lib.rs
rename to shared-lib/folder-model/src/lib.rs
index b6a8fb7b20..42337516c2 100644
--- a/shared-lib/folder-rev-model/src/lib.rs
+++ b/shared-lib/folder-model/src/lib.rs
@@ -2,6 +2,7 @@
mod macros;
mod app_rev;
+pub mod folder;
mod folder_rev;
mod trash_rev;
pub mod user_default;
@@ -9,6 +10,7 @@ mod view_rev;
mod workspace_rev;
pub use app_rev::*;
+pub use folder::*;
pub use folder_rev::*;
pub use trash_rev::*;
pub use view_rev::*;
diff --git a/shared-lib/folder-rev-model/src/macros.rs b/shared-lib/folder-model/src/macros.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/macros.rs
rename to shared-lib/folder-model/src/macros.rs
diff --git a/shared-lib/folder-rev-model/src/trash_rev.rs b/shared-lib/folder-model/src/trash_rev.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/trash_rev.rs
rename to shared-lib/folder-model/src/trash_rev.rs
diff --git a/shared-lib/folder-rev-model/src/user_default.rs b/shared-lib/folder-model/src/user_default.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/user_default.rs
rename to shared-lib/folder-model/src/user_default.rs
diff --git a/shared-lib/folder-rev-model/src/view_rev.rs b/shared-lib/folder-model/src/view_rev.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/view_rev.rs
rename to shared-lib/folder-model/src/view_rev.rs
diff --git a/shared-lib/folder-rev-model/src/workspace_rev.rs b/shared-lib/folder-model/src/workspace_rev.rs
similarity index 100%
rename from shared-lib/folder-rev-model/src/workspace_rev.rs
rename to shared-lib/folder-model/src/workspace_rev.rs
diff --git a/shared-lib/grid-rev-model/Cargo.toml b/shared-lib/grid-model/Cargo.toml
similarity index 82%
rename from shared-lib/grid-rev-model/Cargo.toml
rename to shared-lib/grid-model/Cargo.toml
index 786e59171c..5523121924 100644
--- a/shared-lib/grid-rev-model/Cargo.toml
+++ b/shared-lib/grid-model/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "grid-rev-model"
+name = "grid-model"
version = "0.1.0"
edition = "2021"
@@ -11,5 +11,4 @@ serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = {version = "1.0"}
serde_repr = "0.1"
nanoid = "0.4.0"
-#flowy-error-code = { path = "../flowy-error-code"}
indexmap = {version = "1.9.1", features = ["serde"]}
diff --git a/shared-lib/grid-rev-model/src/filter_rev.rs b/shared-lib/grid-model/src/filter_rev.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/filter_rev.rs
rename to shared-lib/grid-model/src/filter_rev.rs
diff --git a/shared-lib/grid-rev-model/src/grid_block.rs b/shared-lib/grid-model/src/grid_block.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/grid_block.rs
rename to shared-lib/grid-model/src/grid_block.rs
diff --git a/shared-lib/grid-rev-model/src/grid_rev.rs b/shared-lib/grid-model/src/grid_rev.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/grid_rev.rs
rename to shared-lib/grid-model/src/grid_rev.rs
diff --git a/shared-lib/grid-rev-model/src/grid_setting_rev.rs b/shared-lib/grid-model/src/grid_setting_rev.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/grid_setting_rev.rs
rename to shared-lib/grid-model/src/grid_setting_rev.rs
diff --git a/shared-lib/grid-rev-model/src/grid_view.rs b/shared-lib/grid-model/src/grid_view.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/grid_view.rs
rename to shared-lib/grid-model/src/grid_view.rs
diff --git a/shared-lib/grid-rev-model/src/group_rev.rs b/shared-lib/grid-model/src/group_rev.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/group_rev.rs
rename to shared-lib/grid-model/src/group_rev.rs
diff --git a/shared-lib/grid-rev-model/src/lib.rs b/shared-lib/grid-model/src/lib.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/lib.rs
rename to shared-lib/grid-model/src/lib.rs
diff --git a/shared-lib/grid-rev-model/src/sort_rev.rs b/shared-lib/grid-model/src/sort_rev.rs
similarity index 100%
rename from shared-lib/grid-rev-model/src/sort_rev.rs
rename to shared-lib/grid-model/src/sort_rev.rs
diff --git a/shared-lib/lib-infra/Cargo.toml b/shared-lib/lib-infra/Cargo.toml
index 8ee89b1b44..f62edfb615 100644
--- a/shared-lib/lib-infra/Cargo.toml
+++ b/shared-lib/lib-infra/Cargo.toml
@@ -12,4 +12,5 @@ pin-project = "1.0.12"
futures-core = { version = "0.3" }
tokio = { version = "1.0", features = ["time", "rt"] }
rand = "0.8.5"
-async-trait = "0.1.59"
\ No newline at end of file
+async-trait = "0.1.59"
+md5 = "0.7.0"
diff --git a/shared-lib/lib-infra/src/util.rs b/shared-lib/lib-infra/src/util.rs
index 8802c60d61..09ca5e1890 100644
--- a/shared-lib/lib-infra/src/util.rs
+++ b/shared-lib/lib-infra/src/util.rs
@@ -25,3 +25,9 @@ where
pub fn timestamp() -> i64 {
chrono::Utc::now().timestamp()
}
+
+#[inline]
+pub fn md5<T: AsRef<[u8]>>(data: T) -> String {
+ let md5 = format!("{:x}", md5::compute(data));
+ md5
+}
diff --git a/shared-lib/lib-ot/Cargo.toml b/shared-lib/lib-ot/Cargo.toml
index c654a00235..1c8a7ced5e 100644
--- a/shared-lib/lib-ot/Cargo.toml
+++ b/shared-lib/lib-ot/Cargo.toml
@@ -6,17 +6,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-bytecount = "0.6.0"
serde = { version = "1.0", features = ["derive", "rc"] }
-tokio = { version = "1", features = ["sync"] }
-dashmap = "5"
-md5 = "0.7.0"
-anyhow = "1.0"
thiserror = "1.0"
-
serde_json = { version = "1.0" }
-serde_repr = { version = "0.1" }
-derive_more = { version = "0.99", features = ["display"] }
indexmap = {version = "1.9.1", features = ["serde"]}
log = "0.4"
tracing = { version = "0.1", features = ["log"] }
diff --git a/shared-lib/lib-ws/Cargo.toml b/shared-lib/lib-ws/Cargo.toml
index 4c41097875..602b0da62a 100644
--- a/shared-lib/lib-ws/Cargo.toml
+++ b/shared-lib/lib-ws/Cargo.toml
@@ -19,12 +19,10 @@ futures = "0.3.17"
bytes = "1.0"
pin-project = "1.0"
futures-core = { version = "0.3", default-features = false }
-paste = "1"
url = "2.2.2"
log = "0.4"
tracing = { version = "0.1", features = ["log"] }
protobuf = {version = "2.18.0"}
-strum = "0.21"
strum_macros = "0.21"
parking_lot = "0.12.1"
dashmap = "5"
diff --git a/shared-lib/flowy-http-model/Cargo.toml b/shared-lib/revision-model/Cargo.toml
similarity index 84%
rename from shared-lib/flowy-http-model/Cargo.toml
rename to shared-lib/revision-model/Cargo.toml
index 61a7522352..37b4a9a32a 100644
--- a/shared-lib/flowy-http-model/Cargo.toml
+++ b/shared-lib/revision-model/Cargo.toml
@@ -1,15 +1,12 @@
[package]
-name = "flowy-http-model"
+name = "revision-model"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-bytes = "1.0"
-md5 = "0.7.0"
serde = { version = "1.0" }
serde_json = { version = "1.0" }
-serde_repr = "0.1"
-
-
+md5 = "0.7.0"
+bytes = "1.0"
diff --git a/shared-lib/revision-model/src/lib.rs b/shared-lib/revision-model/src/lib.rs
new file mode 100644
index 0000000000..5766cc66ce
--- /dev/null
+++ b/shared-lib/revision-model/src/lib.rs
@@ -0,0 +1,3 @@
+mod revision;
+
+pub use revision::*;
diff --git a/shared-lib/flowy-http-model/src/revision.rs b/shared-lib/revision-model/src/revision.rs
similarity index 93%
rename from shared-lib/flowy-http-model/src/revision.rs
rename to shared-lib/revision-model/src/revision.rs
index bec31d728a..c555dfcd1e 100644
--- a/shared-lib/flowy-http-model/src/revision.rs
+++ b/shared-lib/revision-model/src/revision.rs
@@ -1,4 +1,3 @@
-use crate::util::md5;
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, fmt::Formatter, ops::RangeInclusive};
@@ -60,9 +59,14 @@ impl Revision {
}
pub fn initial_revision(object_id: &str, bytes: Bytes) -> Self {
- let md5 = md5(&bytes);
+ let md5 = format!("{:x}", md5::compute(&bytes));
Self::new(object_id, 0, 0, bytes, md5)
}
+
+ pub fn to_bytes(&self) -> Bytes {
+ let bytes = serde_json::to_vec(self).unwrap();
+ Bytes::from(bytes)
+ }
}
impl std::fmt::Debug for Revision {
diff --git a/shared-lib/user-model/Cargo.toml b/shared-lib/user-model/Cargo.toml
new file mode 100644
index 0000000000..dfc3b41466
--- /dev/null
+++ b/shared-lib/user-model/Cargo.toml
@@ -0,0 +1,27 @@
+[package]
+name = "user-model"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+serde = { version = "1.0" }
+validator = "0.16.0"
+unicode-segmentation = "1.8"
+fancy-regex = "0.11.0"
+lazy_static = "1.4.0"
+tracing = { version = "0.1", features = ["log"] }
+thiserror = "1.0"
+serde_repr = "0.1"
+
+[dev-dependencies]
+nanoid = "0.4.0"
+quickcheck = "1.0.3"
+quickcheck_macros = "0.9.1"
+fake = "2.4.3"
+claim = "0.4.0"
+futures = "0.3.15"
+serial_test = "0.5.1"
+rand_core = "0.6.3"
+rand = "0.8.5"
\ No newline at end of file
diff --git a/shared-lib/user-model/src/errors.rs b/shared-lib/user-model/src/errors.rs
new file mode 100644
index 0000000000..bee7dee7f0
--- /dev/null
+++ b/shared-lib/user-model/src/errors.rs
@@ -0,0 +1,48 @@
+use serde_repr::*;
+use thiserror::Error;
+
+#[derive(Debug, Clone, PartialEq, Eq, Error, Serialize_repr, Deserialize_repr)]
+#[repr(u8)]
+pub enum UserErrorCode {
+ #[error("Internal error")]
+ Internal = 0,
+
+ #[error("Workspace id can not be empty or whitespace")]
+ WorkspaceIdInvalid = 1,
+
+ #[error("Email can not be empty or whitespace")]
+ EmailIsEmpty = 2,
+
+ #[error("Email format is not valid")]
+ EmailFormatInvalid = 3,
+
+ #[error("user id is empty or whitespace")]
+ UserIdInvalid = 4,
+
+ #[error("User name contain forbidden characters")]
+ UserNameContainForbiddenCharacters = 5,
+
+ #[error("User name can not be empty or whitespace")]
+ UserNameIsEmpty = 6,
+
+ #[error("User not exist")]
+ UserNotExist = 7,
+
+ #[error("Password can not be empty or whitespace")]
+ PasswordIsEmpty = 8,
+
+ #[error("Password format too long")]
+ PasswordTooLong = 9,
+
+ #[error("Password contains forbidden characters.")]
+ PasswordContainsForbidCharacters = 10,
+
+ #[error("Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
+ PasswordFormatInvalid = 11,
+
+ #[error("Password not match")]
+ PasswordNotMatch = 12,
+
+ #[error("User name is too long")]
+ UserNameTooLong = 13,
+}
diff --git a/shared-lib/user-model/src/lib.rs b/shared-lib/user-model/src/lib.rs
new file mode 100644
index 0000000000..e18a73b36e
--- /dev/null
+++ b/shared-lib/user-model/src/lib.rs
@@ -0,0 +1,86 @@
+pub mod errors;
+pub mod parser;
+
+pub use parser::*;
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Default, Serialize, Deserialize, Debug)]
+pub struct SignInParams {
+ pub email: String,
+ pub password: String,
+ pub name: String,
+}
+
+#[derive(Debug, Default, Serialize, Deserialize, Clone)]
+pub struct SignInResponse {
+ pub user_id: String,
+ pub name: String,
+ pub email: String,
+ pub token: String,
+}
+
+#[derive(Serialize, Deserialize, Default, Debug)]
+pub struct SignUpParams {
+ pub email: String,
+ pub name: String,
+ pub password: String,
+}
+
+#[derive(Serialize, Deserialize, Debug, Default, Clone)]
+pub struct SignUpResponse {
+ pub user_id: String,
+ pub name: String,
+ pub email: String,
+ pub token: String,
+}
+
+#[derive(Serialize, Deserialize, Default, Debug, Clone)]
+pub struct UserProfile {
+ pub id: String,
+ pub email: String,
+ pub name: String,
+ pub token: String,
+ pub icon_url: String,
+}
+
+#[derive(Serialize, Deserialize, Default, Clone, Debug)]
+pub struct UpdateUserProfileParams {
+ pub id: String,
+ pub name: Option<String>,
+ pub email: Option<String>,
+ pub password: Option<String>,
+ pub icon_url: Option<String>,
+}
+
+impl UpdateUserProfileParams {
+ pub fn new(user_id: &str) -> Self {
+ Self {
+ id: user_id.to_owned(),
+ name: None,
+ email: None,
+ password: None,
+ icon_url: None,
+ }
+ }
+
+ pub fn name(mut self, name: &str) -> Self {
+ self.name = Some(name.to_owned());
+ self
+ }
+
+ pub fn email(mut self, email: &str) -> Self {
+ self.email = Some(email.to_owned());
+ self
+ }
+
+ pub fn password(mut self, password: &str) -> Self {
+ self.password = Some(password.to_owned());
+ self
+ }
+
+ pub fn icon_url(mut self, icon_url: &str) -> Self {
+ self.icon_url = Some(icon_url.to_owned());
+ self
+ }
+}
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/mod.rs b/shared-lib/user-model/src/parser/mod.rs
similarity index 100%
rename from frontend/rust-lib/flowy-user/src/entities/parser/mod.rs
rename to shared-lib/user-model/src/parser/mod.rs
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/user_email.rs b/shared-lib/user-model/src/parser/user_email.rs
similarity index 89%
rename from frontend/rust-lib/flowy-user/src/entities/parser/user_email.rs
rename to shared-lib/user-model/src/parser/user_email.rs
index e1b276a46b..25a21599be 100644
--- a/frontend/rust-lib/flowy-user/src/entities/parser/user_email.rs
+++ b/shared-lib/user-model/src/parser/user_email.rs
@@ -1,19 +1,19 @@
-use crate::errors::ErrorCode;
+use crate::errors::UserErrorCode;
use validator::validate_email;
#[derive(Debug)]
pub struct UserEmail(pub String);
impl UserEmail {
- pub fn parse(s: String) -> Result<UserEmail, ErrorCode> {
+ pub fn parse(s: String) -> Result<UserEmail, UserErrorCode> {
if s.trim().is_empty() {
- return Err(ErrorCode::EmailIsEmpty);
+ return Err(UserErrorCode::EmailIsEmpty);
}
if validate_email(&s) {
Ok(Self(s))
} else {
- Err(ErrorCode::EmailFormatInvalid)
+ Err(UserErrorCode::EmailFormatInvalid)
}
}
}
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/user_icon.rs b/shared-lib/user-model/src/parser/user_icon.rs
similarity index 64%
rename from frontend/rust-lib/flowy-user/src/entities/parser/user_icon.rs
rename to shared-lib/user-model/src/parser/user_icon.rs
index 69258ca848..71d193c0eb 100644
--- a/frontend/rust-lib/flowy-user/src/entities/parser/user_icon.rs
+++ b/shared-lib/user-model/src/parser/user_icon.rs
@@ -1,10 +1,10 @@
-use crate::errors::ErrorCode;
+use crate::errors::UserErrorCode;
#[derive(Debug)]
pub struct UserIcon(pub String);
impl UserIcon {
- pub fn parse(s: String) -> Result<UserIcon, ErrorCode> {
+ pub fn parse(s: String) -> Result<UserIcon, UserErrorCode> {
Ok(Self(s))
}
}
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/user_id.rs b/shared-lib/user-model/src/parser/user_id.rs
similarity index 65%
rename from frontend/rust-lib/flowy-user/src/entities/parser/user_id.rs
rename to shared-lib/user-model/src/parser/user_id.rs
index 34e2f64505..5a8c7b9b3e 100644
--- a/frontend/rust-lib/flowy-user/src/entities/parser/user_id.rs
+++ b/shared-lib/user-model/src/parser/user_id.rs
@@ -1,13 +1,13 @@
-use crate::errors::ErrorCode;
+use crate::errors::UserErrorCode;
#[derive(Debug)]
pub struct UserId(pub String);
impl UserId {
- pub fn parse(s: String) -> Result<UserId, ErrorCode> {
+ pub fn parse(s: String) -> Result<UserId, UserErrorCode> {
let is_empty_or_whitespace = s.trim().is_empty();
if is_empty_or_whitespace {
- return Err(ErrorCode::UserIdInvalid);
+ return Err(UserErrorCode::UserIdInvalid);
}
Ok(Self(s))
}
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/user_name.rs b/shared-lib/user-model/src/parser/user_name.rs
similarity index 88%
rename from frontend/rust-lib/flowy-user/src/entities/parser/user_name.rs
rename to shared-lib/user-model/src/parser/user_name.rs
index 011ef1ef53..046bf455be 100644
--- a/frontend/rust-lib/flowy-user/src/entities/parser/user_name.rs
+++ b/shared-lib/user-model/src/parser/user_name.rs
@@ -1,14 +1,14 @@
-use crate::errors::ErrorCode;
+use crate::errors::UserErrorCode;
use unicode_segmentation::UnicodeSegmentation;
#[derive(Debug)]
pub struct UserName(pub String);
impl UserName {
- pub fn parse(s: String) -> Result<UserName, ErrorCode> {
+ pub fn parse(s: String) -> Result<UserName, UserErrorCode> {
let is_empty_or_whitespace = s.trim().is_empty();
if is_empty_or_whitespace {
- return Err(ErrorCode::UserNameIsEmpty);
+ return Err(UserErrorCode::UserNameIsEmpty);
}
// A grapheme is defined by the Unicode standard as a "user-perceived"
// character: `å` is a single grapheme, but it is composed of two characters
@@ -19,14 +19,14 @@ impl UserName {
// the recommended one.
let is_too_long = s.graphemes(true).count() > 256;
if is_too_long {
- return Err(ErrorCode::UserNameTooLong);
+ return Err(UserErrorCode::UserNameTooLong);
}
let forbidden_characters = ['/', '(', ')', '"', '<', '>', '\\', '{', '}'];
let contains_forbidden_characters = s.chars().any(|g| forbidden_characters.contains(&g));
if contains_forbidden_characters {
- return Err(ErrorCode::UserNameContainForbiddenCharacters);
+ return Err(UserErrorCode::UserNameContainForbiddenCharacters);
}
Ok(Self(s))
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/user_password.rs b/shared-lib/user-model/src/parser/user_password.rs
similarity index 76%
rename from frontend/rust-lib/flowy-user/src/entities/parser/user_password.rs
rename to shared-lib/user-model/src/parser/user_password.rs
index 2e23f0399f..22f2341ef9 100644
--- a/frontend/rust-lib/flowy-user/src/entities/parser/user_password.rs
+++ b/shared-lib/user-model/src/parser/user_password.rs
@@ -1,4 +1,4 @@
-use crate::errors::ErrorCode;
+use crate::errors::UserErrorCode;
use fancy_regex::Regex;
use lazy_static::lazy_static;
use unicode_segmentation::UnicodeSegmentation;
@@ -7,23 +7,23 @@ use unicode_segmentation::UnicodeSegmentation;
pub struct UserPassword(pub String);
impl UserPassword {
- pub fn parse(s: String) -> Result<UserPassword, ErrorCode> {
+ pub fn parse(s: String) -> Result<UserPassword, UserErrorCode> {
if s.trim().is_empty() {
- return Err(ErrorCode::PasswordIsEmpty);
+ return Err(UserErrorCode::PasswordIsEmpty);
}
if s.graphemes(true).count() > 100 {
- return Err(ErrorCode::PasswordTooLong);
+ return Err(UserErrorCode::PasswordTooLong);
}
let forbidden_characters = ['/', '(', ')', '"', '<', '>', '\\', '{', '}'];
let contains_forbidden_characters = s.chars().any(|g| forbidden_characters.contains(&g));
if contains_forbidden_characters {
- return Err(ErrorCode::PasswordContainsForbidCharacters);
+ return Err(UserErrorCode::PasswordContainsForbidCharacters);
}
if !validate_password(&s) {
- return Err(ErrorCode::PasswordFormatInvalid);
+ return Err(UserErrorCode::PasswordFormatInvalid);
}
Ok(Self(s))
@@ -57,7 +57,7 @@ pub fn validate_password(password: &str) -> bool {
match PASSWORD.is_match(password) {
Ok(is_match) => is_match,
Err(e) => {
- log::error!("validate_password fail: {:?}", e);
+ tracing::error!("validate_password fail: {:?}", e);
false
}
}
diff --git a/frontend/rust-lib/flowy-user/src/entities/parser/user_workspace.rs b/shared-lib/user-model/src/parser/user_workspace.rs
similarity index 64%
rename from frontend/rust-lib/flowy-user/src/entities/parser/user_workspace.rs
rename to shared-lib/user-model/src/parser/user_workspace.rs
index 3ac78588b5..5cfd69ff4f 100644
--- a/frontend/rust-lib/flowy-user/src/entities/parser/user_workspace.rs
+++ b/shared-lib/user-model/src/parser/user_workspace.rs
@@ -1,11 +1,13 @@
+use crate::errors::UserErrorCode;
+
#[derive(Debug)]
pub struct UserWorkspace(pub String);
impl UserWorkspace {
- pub fn parse(s: String) -> Result<UserWorkspace, String> {
+ pub fn parse(s: String) -> Result<UserWorkspace, UserErrorCode> {
let is_empty_or_whitespace = s.trim().is_empty();
if is_empty_or_whitespace {
- return Err("workspace id is empty or whitespace".to_string());
+ return Err(UserErrorCode::WorkspaceIdInvalid);
}
Ok(Self(s))
}
diff --git a/shared-lib/ws-model/Cargo.toml b/shared-lib/ws-model/Cargo.toml
new file mode 100644
index 0000000000..7e854c4456
--- /dev/null
+++ b/shared-lib/ws-model/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "ws-model"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+serde = { version = "1.0" }
+serde_json = { version = "1.0" }
+serde_repr = "0.1"
+revision-model = { path = "../revision-model"}
+bytes = "1.0"
diff --git a/shared-lib/ws-model/src/lib.rs b/shared-lib/ws-model/src/lib.rs
new file mode 100644
index 0000000000..6ebee9ba34
--- /dev/null
+++ b/shared-lib/ws-model/src/lib.rs
@@ -0,0 +1 @@
+pub mod ws_revision;
diff --git a/shared-lib/flowy-http-model/src/ws_data.rs b/shared-lib/ws-model/src/ws_revision.rs
similarity index 95%
rename from shared-lib/flowy-http-model/src/ws_data.rs
rename to shared-lib/ws-model/src/ws_revision.rs
index 64edf4f413..dabf0ff59f 100644
--- a/shared-lib/flowy-http-model/src/ws_data.rs
+++ b/shared-lib/ws-model/src/ws_revision.rs
@@ -1,5 +1,5 @@
-use crate::revision::{Revision, RevisionRange};
use bytes::Bytes;
+use revision_model::{Revision, RevisionRange};
use serde::{Deserialize, Serialize};
use serde_repr::*;
@@ -95,6 +95,12 @@ impl std::convert::TryFrom<ServerRevisionWSData> for Bytes {
}
}
+impl ServerRevisionWSData {
+ pub fn to_bytes(&self) -> Vec<u8> {
+ serde_json::to_vec(&self).unwrap_or_default()
+ }
+}
+
pub struct ServerRevisionWSDataBuilder();
impl ServerRevisionWSDataBuilder {
pub fn build_push_message(object_id: &str, revisions: Vec<Revision>) -> ServerRevisionWSData {