fix generate pb issues

This commit is contained in:
appflowy 2021-12-04 17:31:32 +08:00
parent c649673b2b
commit 63082418be
27 changed files with 79 additions and 56 deletions

View file

@ -14,12 +14,14 @@ class UserNotification extends $pb.ProtobufEnum {
static const UserNotification UserAuthChanged = UserNotification._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserAuthChanged'); static const UserNotification UserAuthChanged = UserNotification._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserAuthChanged');
static const UserNotification UserProfileUpdated = UserNotification._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserProfileUpdated'); static const UserNotification UserProfileUpdated = UserNotification._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserProfileUpdated');
static const UserNotification UserUnauthorized = UserNotification._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); static const UserNotification UserUnauthorized = UserNotification._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized');
static const UserNotification UserWsConnectStateChanged = UserNotification._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserWsConnectStateChanged');
static const $core.List<UserNotification> values = <UserNotification> [ static const $core.List<UserNotification> values = <UserNotification> [
Unknown, Unknown,
UserAuthChanged, UserAuthChanged,
UserProfileUpdated, UserProfileUpdated,
UserUnauthorized, UserUnauthorized,
UserWsConnectStateChanged,
]; ];
static final $core.Map<$core.int, UserNotification> _byValue = $pb.ProtobufEnum.initByValue(values); static final $core.Map<$core.int, UserNotification> _byValue = $pb.ProtobufEnum.initByValue(values);

View file

@ -16,8 +16,9 @@ const UserNotification$json = const {
const {'1': 'UserAuthChanged', '2': 1}, const {'1': 'UserAuthChanged', '2': 1},
const {'1': 'UserProfileUpdated', '2': 2}, const {'1': 'UserProfileUpdated', '2': 2},
const {'1': 'UserUnauthorized', '2': 3}, const {'1': 'UserUnauthorized', '2': 3},
const {'1': 'UserWsConnectStateChanged', '2': 4},
], ],
}; };
/// Descriptor for `UserNotification`. Decode as a `google.protobuf.EnumDescriptorProto`. /// Descriptor for `UserNotification`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List userNotificationDescriptor = $convert.base64Decode('ChBVc2VyTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABITCg9Vc2VyQXV0aENoYW5nZWQQARIWChJVc2VyUHJvZmlsZVVwZGF0ZWQQAhIUChBVc2VyVW5hdXRob3JpemVkEAM='); final $typed_data.Uint8List userNotificationDescriptor = $convert.base64Decode('ChBVc2VyTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABITCg9Vc2VyQXV0aENoYW5nZWQQARIWChJVc2VyUHJvZmlsZVVwZGF0ZWQQAhIUChBVc2VyVW5hdXRob3JpemVkEAMSHQoZVXNlcldzQ29ubmVjdFN0YXRlQ2hhbmdlZBAE');

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -191,14 +191,8 @@ impl ClientDocEditor {
let retry = Retry::spawn(strategy, action); let retry = Retry::spawn(strategy, action);
tokio::spawn(async move { tokio::spawn(async move {
match retry.await { match retry.await {
Ok(_) => { Ok(_) => log::debug!("Notify open doc success"),
// Err(e) => log::error!("Notify open doc failed: {}", e),
log::debug!("Notify open doc success");
},
Err(e) => {
//
log::error!("Notify open doc failed: {}", e);
},
} }
}); });
} }
@ -280,6 +274,12 @@ impl ClientDocEditor {
pub struct EditDocWsHandler(pub Arc<ClientDocEditor>); pub struct EditDocWsHandler(pub Arc<ClientDocEditor>);
impl std::ops::Deref for EditDocWsHandler {
type Target = Arc<ClientDocEditor>;
fn deref(&self) -> &Self::Target { &self.0 }
}
impl WsDocumentHandler for EditDocWsHandler { impl WsDocumentHandler for EditDocWsHandler {
fn receive(&self, doc_data: WsDocumentData) { fn receive(&self, doc_data: WsDocumentData) {
let edit_doc = self.0.clone(); let edit_doc = self.0.clone();
@ -293,7 +293,7 @@ impl WsDocumentHandler for EditDocWsHandler {
fn state_changed(&self, state: &WsState) { fn state_changed(&self, state: &WsState) {
match state { match state {
WsState::Init => {}, WsState::Init => {},
WsState::Connected(_) => self.0.notify_open_doc(), WsState::Connected(_) => self.notify_open_doc(),
WsState::Disconnected(_e) => {}, WsState::Disconnected(_e) => {},
} }
} }

View file

@ -1,7 +1,7 @@
mod doc_actor;
mod editor; mod editor;
mod model; mod model;
mod queue;
pub(crate) use doc_actor::*;
pub use editor::*; pub use editor::*;
pub(crate) use model::*; pub(crate) use model::*;
pub(crate) use queue::*;

View file

@ -1,7 +1,6 @@
mod deps_resolve; mod deps_resolve;
// mod flowy_server; // mod flowy_server;
pub mod module; pub mod module;
use crate::deps_resolve::WorkspaceDepsResolver; use crate::deps_resolve::WorkspaceDepsResolver;
use backend_service::config::ServerConfig; use backend_service::config::ServerConfig;
use flowy_document::module::FlowyDocument; use flowy_document::module::FlowyDocument;
@ -63,7 +62,7 @@ pub struct FlowySDK {
config: FlowySDKConfig, config: FlowySDKConfig,
pub user_session: Arc<UserSession>, pub user_session: Arc<UserSession>,
pub flowy_document: Arc<FlowyDocument>, pub flowy_document: Arc<FlowyDocument>,
pub workspace: Arc<WorkspaceController>, pub workspace_ctrl: Arc<WorkspaceController>,
pub dispatcher: Arc<EventDispatcher>, pub dispatcher: Arc<EventDispatcher>,
} }
@ -80,16 +79,17 @@ impl FlowySDK {
.build(), .build(),
); );
let flowy_document = mk_document_module(user_session.clone(), &config.server_config); let flowy_document = mk_document_module(user_session.clone(), &config.server_config);
let workspace = mk_workspace(user_session.clone(), flowy_document.clone(), &config.server_config); let workspace_ctrl =
let modules = mk_modules(workspace.clone(), user_session.clone()); mk_workspace_controller(user_session.clone(), flowy_document.clone(), &config.server_config);
let modules = mk_modules(workspace_ctrl.clone(), user_session.clone());
let dispatcher = Arc::new(EventDispatcher::construct(|| modules)); let dispatcher = Arc::new(EventDispatcher::construct(|| modules));
_init(&dispatcher, user_session.clone(), workspace.clone()); _init(&dispatcher, user_session.clone(), workspace_ctrl.clone());
Self { Self {
config, config,
user_session, user_session,
flowy_document, flowy_document,
workspace, workspace_ctrl,
dispatcher, dispatcher,
} }
} }
@ -155,12 +155,12 @@ fn init_log(config: &FlowySDKConfig) {
} }
} }
fn mk_workspace( fn mk_workspace_controller(
user_session: Arc<UserSession>, user_session: Arc<UserSession>,
flowy_document: Arc<FlowyDocument>, flowy_document: Arc<FlowyDocument>,
server_config: &ServerConfig, server_config: &ServerConfig,
) -> Arc<WorkspaceController> { ) -> Arc<WorkspaceController> {
let workspace_deps = WorkspaceDepsResolver::new(user_session); let workspace_deps = WorkspaceDepsResolver::new(user_session);
let (user, database) = workspace_deps.split_into(); let (user, database) = workspace_deps.split_into();
flowy_workspace::module::mk_workspace(user, database, flowy_document, server_config) flowy_workspace::module::init_workspace_controller(user, database, flowy_document, server_config)
} }

View file

@ -7,7 +7,9 @@ use lib_dispatch::prelude::Module;
use std::sync::Arc; use std::sync::Arc;
pub fn mk_modules(workspace_controller: Arc<WorkspaceController>, user_session: Arc<UserSession>) -> Vec<Module> { pub fn mk_modules(workspace_controller: Arc<WorkspaceController>, user_session: Arc<UserSession>) -> Vec<Module> {
vec![mk_user_module(user_session), mk_workspace_module(workspace_controller)] let user_module = mk_user_module(user_session);
let workspace_module = mk_workspace_module(workspace_controller);
vec![user_module, workspace_module]
} }
fn mk_user_module(user_session: Arc<UserSession>) -> Module { flowy_user::module::create(user_session) } fn mk_user_module(user_session: Arc<UserSession>) -> Module { flowy_user::module::create(user_session) }

View file

@ -1,3 +1,3 @@
proto_crates = ["src/entities", "src/event.rs", "src/errors.rs", "src/notify"] proto_crates = ["src/event.rs", "src/errors.rs", "src/notify"]
event_files = ["src/event.rs"] event_files = ["src/event.rs"]

View file

@ -10,6 +10,7 @@ pub(crate) enum UserNotification {
UserAuthChanged = 1, UserAuthChanged = 1,
UserProfileUpdated = 2, UserProfileUpdated = 2,
UserUnauthorized = 3, UserUnauthorized = 3,
UserWsConnectStateChanged = 4,
} }
impl std::default::Default for UserNotification { impl std::default::Default for UserNotification {

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -29,6 +29,7 @@ pub enum UserNotification {
UserAuthChanged = 1, UserAuthChanged = 1,
UserProfileUpdated = 2, UserProfileUpdated = 2,
UserUnauthorized = 3, UserUnauthorized = 3,
UserWsConnectStateChanged = 4,
} }
impl ::protobuf::ProtobufEnum for UserNotification { impl ::protobuf::ProtobufEnum for UserNotification {
@ -42,6 +43,7 @@ impl ::protobuf::ProtobufEnum for UserNotification {
1 => ::std::option::Option::Some(UserNotification::UserAuthChanged), 1 => ::std::option::Option::Some(UserNotification::UserAuthChanged),
2 => ::std::option::Option::Some(UserNotification::UserProfileUpdated), 2 => ::std::option::Option::Some(UserNotification::UserProfileUpdated),
3 => ::std::option::Option::Some(UserNotification::UserUnauthorized), 3 => ::std::option::Option::Some(UserNotification::UserUnauthorized),
4 => ::std::option::Option::Some(UserNotification::UserWsConnectStateChanged),
_ => ::std::option::Option::None _ => ::std::option::Option::None
} }
} }
@ -52,6 +54,7 @@ impl ::protobuf::ProtobufEnum for UserNotification {
UserNotification::UserAuthChanged, UserNotification::UserAuthChanged,
UserNotification::UserProfileUpdated, UserNotification::UserProfileUpdated,
UserNotification::UserUnauthorized, UserNotification::UserUnauthorized,
UserNotification::UserWsConnectStateChanged,
]; ];
values values
} }
@ -80,19 +83,22 @@ impl ::protobuf::reflect::ProtobufValue for UserNotification {
} }
static file_descriptor_proto_data: &'static [u8] = b"\ static file_descriptor_proto_data: &'static [u8] = b"\
\n\x10observable.proto*b\n\x10UserNotification\x12\x0b\n\x07Unknown\x10\ \n\x10observable.proto*\x81\x01\n\x10UserNotification\x12\x0b\n\x07Unkno\
\0\x12\x13\n\x0fUserAuthChanged\x10\x01\x12\x16\n\x12UserProfileUpdated\ wn\x10\0\x12\x13\n\x0fUserAuthChanged\x10\x01\x12\x16\n\x12UserProfileUp\
\x10\x02\x12\x14\n\x10UserUnauthorized\x10\x03J\xce\x01\n\x06\x12\x04\0\ dated\x10\x02\x12\x14\n\x10UserUnauthorized\x10\x03\x12\x1d\n\x19UserWsC\
\0\x07\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\ onnectStateChanged\x10\x04J\xf7\x01\n\x06\x12\x04\0\0\x08\x01\n\x08\n\
\x07\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x15\n\x0b\n\x04\x05\0\x02\0\ \x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\x08\x01\n\n\n\x03\
\x12\x03\x03\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\x0b\n\ \x05\0\x01\x12\x03\x02\x05\x15\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\
\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\ \x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\x0b\n\x0c\n\x05\x05\0\
\x12\x03\x04\x04\x18\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\x13\n\ \x02\0\x02\x12\x03\x03\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\
\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\x16\x17\n\x0b\n\x04\x05\0\x02\ \x18\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x05\0\
\x02\x12\x03\x05\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x05\x04\ \x02\x01\x02\x12\x03\x04\x16\x17\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\
\x16\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x05\x19\x1a\n\x0b\n\x04\x05\0\ \x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x05\x04\x16\n\x0c\n\x05\
\x02\x03\x12\x03\x06\x04\x19\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x06\ \x05\0\x02\x02\x02\x12\x03\x05\x19\x1a\n\x0b\n\x04\x05\0\x02\x03\x12\x03\
\x04\x14\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\x06\x17\x18b\x06proto3\ \x06\x04\x19\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x06\x04\x14\n\x0c\n\
\x05\x05\0\x02\x03\x02\x12\x03\x06\x17\x18\n\x0b\n\x04\x05\0\x02\x04\x12\
\x03\x07\x04\"\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x07\x04\x1d\n\x0c\n\
\x05\x05\0\x02\x04\x02\x12\x03\x07\x20!b\x06proto3\
"; ";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View file

@ -5,4 +5,5 @@ enum UserNotification {
UserAuthChanged = 1; UserAuthChanged = 1;
UserProfileUpdated = 2; UserProfileUpdated = 2;
UserUnauthorized = 3; UserUnauthorized = 3;
UserWsConnectStateChanged = 4;
} }

View file

@ -333,7 +333,7 @@ impl UserSession {
WsState::Disconnected(_) => match ws_controller.retry().await { WsState::Disconnected(_) => match ws_controller.retry().await {
Ok(_) => {}, Ok(_) => {},
Err(e) => { Err(e) => {
log::error!("Retry websocket connect failed: {:?}", e); log::error!("websocket connect failed: {:?}", e);
}, },
}, },
} }

View file

@ -28,7 +28,7 @@ pub trait WorkspaceDatabase: Send + Sync {
} }
} }
pub fn mk_workspace( pub fn init_workspace_controller(
user: Arc<dyn WorkspaceUser>, user: Arc<dyn WorkspaceUser>,
database: Arc<dyn WorkspaceDatabase>, database: Arc<dyn WorkspaceDatabase>,
flowy_document: Arc<FlowyDocument>, flowy_document: Arc<FlowyDocument>,

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -53,12 +53,12 @@ fn write_rust_crate_mod_file(crate_infos: &[CrateProtoInfo]) {
{ {
Ok(ref mut file) => { Ok(ref mut file) => {
let mut mod_file_content = String::new(); let mut mod_file_content = String::new();
mod_file_content.push_str("// Auto-generated, do not edit \n"); mod_file_content.push_str("// Auto-generated, do not edit\n");
walk_dir( walk_dir(
crate_info.inner.proto_file_output_dir().as_ref(), crate_info.inner.proto_file_output_dir().as_ref(),
|e| !e.file_type().is_dir(), |e| !e.file_type().is_dir(),
|_, name| { |_, name| {
let c = format!("\nmod {}; \npub use {}::*; \n", &name, &name); let c = format!("\nmod {};\npub use {}::*;\n", &name, &name);
mod_file_content.push_str(c.as_ref()); mod_file_content.push_str(c.as_ref());
}, },
); );

View file

@ -17,10 +17,8 @@ impl CrateProtoInfo {
// mod model; // mod model;
// pub use model::*; // pub use model::*;
let mod_file_path = format!("{}/mod.rs", self.inner.protobuf_crate_name()); let mod_file_path = format!("{}/mod.rs", self.inner.protobuf_crate_name());
let content = r#" let mut content = format!("// Auto-generated, do not edit\n");
mod model; content.push_str("mod model;\npub use model::*;");
pub use model::*;
"#;
match OpenOptions::new() match OpenOptions::new()
.create(true) .create(true)
.write(true) .write(true)

View file

@ -28,7 +28,7 @@ script = [
cargo run \ cargo run \
--manifest-path ${flowy_tool} pb-gen \ --manifest-path ${flowy_tool} pb-gen \
--rust_sources ${rust_lib},${shared_lib} \ --rust_sources ${rust_lib} ${shared_lib} \
--derive_meta=${derive_meta} \ --derive_meta=${derive_meta} \
--flutter_package_lib=${flutter_package_lib} --flutter_package_lib=${flutter_package_lib}
""", """,

View file

@ -77,7 +77,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "UserToken" | "UserToken"
| "UserProfile" | "UserProfile"
| "UpdateUserRequest" | "UpdateUserRequest"
| "UpdateUserParams" => TypeCategory::Protobuf, | "UpdateUserParams"
=> TypeCategory::Protobuf,
"WorkspaceEvent" "WorkspaceEvent"
| "WorkspaceNotification" | "WorkspaceNotification"
| "ErrorCode" | "ErrorCode"
@ -90,7 +91,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "ExportType" | "ExportType"
| "RevType" | "RevType"
| "WsDataType" | "WsDataType"
| "WsModule" => TypeCategory::Enum, | "WsModule"
=> TypeCategory::Enum,
"Option" => TypeCategory::Opt, "Option" => TypeCategory::Opt,
_ => TypeCategory::Primitive, _ => TypeCategory::Primitive,

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;

View file

@ -1,2 +1,3 @@
// Auto-generated, do not edit
mod model; mod model;
pub use model::*; pub use model::*;