From 55de7f69a4ad2aff10490839dbb903ec8735dd27 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 31 Jul 2021 10:50:56 +0800 Subject: [PATCH] rename flowy-editor to flowy-document --- .../application/view/doc_watch_bloc.dart | 4 +- .../view/doc_watch_bloc.freezed.dart | 28 +-- app_flowy/lib/workspace/domain/i_doc.dart | 10 +- .../workspace/infrastructure/i_doc_impl.dart | 10 +- .../infrastructure/repos/doc_repo.dart | 18 +- .../flowy_sdk/lib/dispatch/code_gen.dart | 136 ++++++------- .../flowy_sdk/lib/dispatch/dispatch.dart | 2 +- .../doc_create.pb.dart | 0 .../doc_create.pbenum.dart | 0 .../doc_create.pbjson.dart | 0 .../doc_create.pbserver.dart | 0 .../doc_modify.pb.dart | 0 .../doc_modify.pbenum.dart | 0 .../doc_modify.pbjson.dart | 0 .../doc_modify.pbserver.dart | 0 .../doc_query.pb.dart | 0 .../doc_query.pbenum.dart | 0 .../doc_query.pbjson.dart | 0 .../doc_query.pbserver.dart | 0 .../errors.pb.dart | 34 ++-- .../flowy-document/errors.pbenum.dart | 40 ++++ .../flowy-document/errors.pbjson.dart | 39 ++++ .../errors.pbserver.dart | 0 .../event.pb.dart | 0 .../event.pbenum.dart | 0 .../event.pbjson.dart | 0 .../event.pbserver.dart | 0 .../protobuf.dart | 0 .../protobuf/flowy-editor/errors.pbenum.dart | 40 ---- .../protobuf/flowy-editor/errors.pbjson.dart | 39 ---- rust-lib/Cargo.toml | 1 + .../src/derive_cache/derive_cache.rs | 20 +- .../flowy-dispatch/src/response/response.rs | 4 +- rust-lib/flowy-document/Cargo.toml | 25 +++ .../Flowy.toml | 0 .../src/entities/doc/doc_create.rs | 6 +- .../src/entities/doc/doc_modify.rs | 8 +- .../src/entities/doc/doc_query.rs | 10 +- .../src/entities/doc/mod.rs | 0 .../src/entities/doc/parser/doc_desc.rs | 0 .../src/entities/doc/parser/doc_id.rs | 0 .../src/entities/doc/parser/doc_name.rs | 0 .../src/entities/doc/parser/doc_path.rs | 0 .../src/entities/doc/parser/doc_view_id.rs | 0 .../src/entities/doc/parser/mod.rs | 0 .../src/entities/mod.rs | 0 .../src/errors.rs | 32 +-- .../src/event.rs | 2 +- .../src/handlers/doc_handler.rs | 16 +- .../src/handlers/mod.rs | 0 rust-lib/flowy-document/src/lib.rs | 15 ++ .../src/module.rs | 14 +- .../src/protobuf/mod.rs | 0 .../src/protobuf/model/doc_create.rs | 0 .../src/protobuf/model/doc_modify.rs | 0 .../src/protobuf/model/doc_query.rs | 0 .../src/protobuf/model/errors.rs | 182 +++++++++--------- .../src/protobuf/model/event.rs | 0 .../src/protobuf/model/mod.rs | 0 .../src/protobuf/proto/doc_create.proto | 0 .../src/protobuf/proto/doc_modify.proto | 0 .../src/protobuf/proto/doc_query.proto | 0 .../src/protobuf/proto/errors.proto | 6 +- .../src/protobuf/proto/event.proto | 0 .../src/services/doc_controller.rs | 12 +- .../src/services/file_manager/file.rs | 0 .../src/services/file_manager/manager.rs | 6 +- .../src/services/file_manager/mod.rs | 0 .../src/services/mod.rs | 0 .../src/sql_tables/doc/doc_sql.rs | 14 +- .../src/sql_tables/doc/doc_table.rs | 0 .../src/sql_tables/doc/mod.rs | 0 .../src/sql_tables/mod.rs | 0 .../tests/editor/doc_test.rs | 0 .../tests/editor/helper.rs | 0 .../tests/editor/main.rs | 0 rust-lib/flowy-editor/Cargo.toml | 17 -- rust-lib/flowy-editor/src/lib.rs | 20 +- rust-lib/flowy-sdk/Cargo.toml | 2 +- .../src/deps_resolve/editor_deps_impl.rs | 18 +- rust-lib/flowy-sdk/src/module.rs | 2 +- .../flowy-user/src/handlers/auth_handler.rs | 8 +- .../flowy-user/src/handlers/user_handler.rs | 10 +- .../src/handlers/app_handler.rs | 12 +- .../src/handlers/view_handler.rs | 10 +- .../src/handlers/workspace_handler.rs | 18 +- .../src/services/app_controller.rs | 5 +- .../src/sql_tables/app/app_sql.rs | 5 +- .../flowy-workspace/tests/event/app_test.rs | 2 +- 89 files changed, 456 insertions(+), 446 deletions(-) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_create.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_create.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_create.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_create.pbserver.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_modify.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_modify.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_modify.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_modify.pbserver.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_query.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_query.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_query.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/doc_query.pbserver.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/errors.pb.dart (54%) create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/errors.pbserver.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/event.pb.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/event.pbenum.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/event.pbjson.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/event.pbserver.dart (100%) rename app_flowy/packages/flowy_sdk/lib/protobuf/{flowy-editor => flowy-document}/protobuf.dart (100%) delete mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart delete mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart create mode 100644 rust-lib/flowy-document/Cargo.toml rename rust-lib/{flowy-editor => flowy-document}/Flowy.toml (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/doc_create.rs (89%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/doc_modify.rs (86%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/doc_query.rs (83%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/parser/doc_desc.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/parser/doc_id.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/parser/doc_name.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/parser/doc_path.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/parser/doc_view_id.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/doc/parser/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/entities/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/errors.rs (70%) rename rust-lib/{flowy-editor => flowy-document}/src/event.rs (95%) rename rust-lib/{flowy-editor => flowy-document}/src/handlers/doc_handler.rs (88%) rename rust-lib/{flowy-editor => flowy-document}/src/handlers/mod.rs (100%) create mode 100644 rust-lib/flowy-document/src/lib.rs rename rust-lib/{flowy-editor => flowy-document}/src/module.rs (65%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/model/doc_create.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/model/doc_modify.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/model/doc_query.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/model/errors.rs (54%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/model/event.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/model/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/proto/doc_create.proto (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/proto/doc_modify.proto (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/proto/doc_query.proto (100%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/proto/errors.proto (79%) rename rust-lib/{flowy-editor => flowy-document}/src/protobuf/proto/event.proto (100%) rename rust-lib/{flowy-editor => flowy-document}/src/services/doc_controller.rs (82%) rename rust-lib/{flowy-editor => flowy-document}/src/services/file_manager/file.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/services/file_manager/manager.rs (95%) rename rust-lib/{flowy-editor => flowy-document}/src/services/file_manager/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/services/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/sql_tables/doc/doc_sql.rs (81%) rename rust-lib/{flowy-editor => flowy-document}/src/sql_tables/doc/doc_table.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/sql_tables/doc/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/src/sql_tables/mod.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/tests/editor/doc_test.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/tests/editor/helper.rs (100%) rename rust-lib/{flowy-editor => flowy-document}/tests/editor/main.rs (100%) diff --git a/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart b/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart index e5268e49df..dc94e73cd3 100644 --- a/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart +++ b/app_flowy/lib/workspace/application/view/doc_watch_bloc.dart @@ -1,7 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:app_flowy/workspace/domain/i_doc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/errors.pb.dart'; part 'doc_watch_bloc.freezed.dart'; class DocWatchBloc extends Bloc { @@ -38,5 +38,5 @@ class DocWatchEvent with _$DocWatchEvent { class DocWatchState with _$DocWatchState { const factory DocWatchState.loading() = Loading; const factory DocWatchState.loadDoc(Doc doc) = LoadDoc; - const factory DocWatchState.loadFail(EditorError error) = LoadFail; + const factory DocWatchState.loadFail(DocError error) = LoadFail; } diff --git a/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart b/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart index afaac7752f..2c79c6c2ba 100644 --- a/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart +++ b/app_flowy/lib/workspace/application/view/doc_watch_bloc.freezed.dart @@ -160,7 +160,7 @@ class _$DocWatchStateTearOff { ); } - LoadFail loadFail(EditorError error) { + LoadFail loadFail(DocError error) { return LoadFail( error, ); @@ -176,14 +176,14 @@ mixin _$DocWatchState { TResult when({ required TResult Function() loading, required TResult Function(Doc doc) loadDoc, - required TResult Function(EditorError error) loadFail, + required TResult Function(DocError error) loadFail, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ TResult Function()? loading, TResult Function(Doc doc)? loadDoc, - TResult Function(EditorError error)? loadFail, + TResult Function(DocError error)? loadFail, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -260,7 +260,7 @@ class _$Loading implements Loading { TResult when({ required TResult Function() loading, required TResult Function(Doc doc) loadDoc, - required TResult Function(EditorError error) loadFail, + required TResult Function(DocError error) loadFail, }) { return loading(); } @@ -270,7 +270,7 @@ class _$Loading implements Loading { TResult maybeWhen({ TResult Function()? loading, TResult Function(Doc doc)? loadDoc, - TResult Function(EditorError error)? loadFail, + TResult Function(DocError error)? loadFail, required TResult orElse(), }) { if (loading != null) { @@ -372,7 +372,7 @@ class _$LoadDoc implements LoadDoc { TResult when({ required TResult Function() loading, required TResult Function(Doc doc) loadDoc, - required TResult Function(EditorError error) loadFail, + required TResult Function(DocError error) loadFail, }) { return loadDoc(doc); } @@ -382,7 +382,7 @@ class _$LoadDoc implements LoadDoc { TResult maybeWhen({ TResult Function()? loading, TResult Function(Doc doc)? loadDoc, - TResult Function(EditorError error)? loadFail, + TResult Function(DocError error)? loadFail, required TResult orElse(), }) { if (loadDoc != null) { @@ -428,7 +428,7 @@ abstract class LoadDoc implements DocWatchState { abstract class $LoadFailCopyWith<$Res> { factory $LoadFailCopyWith(LoadFail value, $Res Function(LoadFail) then) = _$LoadFailCopyWithImpl<$Res>; - $Res call({EditorError error}); + $Res call({DocError error}); } /// @nodoc @@ -448,7 +448,7 @@ class _$LoadFailCopyWithImpl<$Res> extends _$DocWatchStateCopyWithImpl<$Res> error == freezed ? _value.error : error // ignore: cast_nullable_to_non_nullable - as EditorError, + as DocError, )); } } @@ -459,7 +459,7 @@ class _$LoadFail implements LoadFail { const _$LoadFail(this.error); @override - final EditorError error; + final DocError error; @override String toString() { @@ -488,7 +488,7 @@ class _$LoadFail implements LoadFail { TResult when({ required TResult Function() loading, required TResult Function(Doc doc) loadDoc, - required TResult Function(EditorError error) loadFail, + required TResult Function(DocError error) loadFail, }) { return loadFail(error); } @@ -498,7 +498,7 @@ class _$LoadFail implements LoadFail { TResult maybeWhen({ TResult Function()? loading, TResult Function(Doc doc)? loadDoc, - TResult Function(EditorError error)? loadFail, + TResult Function(DocError error)? loadFail, required TResult orElse(), }) { if (loadFail != null) { @@ -533,9 +533,9 @@ class _$LoadFail implements LoadFail { } abstract class LoadFail implements DocWatchState { - const factory LoadFail(EditorError error) = _$LoadFail; + const factory LoadFail(DocError error) = _$LoadFail; - EditorError get error => throw _privateConstructorUsedError; + DocError get error => throw _privateConstructorUsedError; @JsonKey(ignore: true) $LoadFailCopyWith get copyWith => throw _privateConstructorUsedError; diff --git a/app_flowy/lib/workspace/domain/i_doc.dart b/app_flowy/lib/workspace/domain/i_doc.dart index ece8d529bc..a7761978de 100644 --- a/app_flowy/lib/workspace/domain/i_doc.dart +++ b/app_flowy/lib/workspace/domain/i_doc.dart @@ -1,7 +1,7 @@ import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/doc_create.pb.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/errors.pb.dart'; class Doc { final DocInfo info; @@ -11,8 +11,8 @@ class Doc { } abstract class IDoc { - Future> readDoc(); - Future> updateDoc( + Future> readDoc(); + Future> updateDoc( {String? name, String? desc, String? text}); - Future> closeDoc(); + Future> closeDoc(); } diff --git a/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart b/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart index 38acfe49e1..d941ba8bd0 100644 --- a/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart +++ b/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'package:dartz/dartz.dart'; import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/errors.pb.dart'; import 'package:app_flowy/workspace/domain/i_doc.dart'; import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; @@ -13,12 +13,12 @@ class IDocImpl extends IDoc { IDocImpl({required this.repo}); @override - Future> closeDoc() { + Future> closeDoc() { return repo.closeDoc(); } @override - Future> readDoc() async { + Future> readDoc() async { final docInfoOrFail = await repo.readDoc(); return docInfoOrFail.fold( (info) => _loadDocument(info.path).then((result) => result.fold( @@ -29,13 +29,13 @@ class IDocImpl extends IDoc { } @override - Future> updateDoc( + Future> updateDoc( {String? name, String? desc, String? text}) { final json = jsonEncode(text ?? ""); return repo.updateDoc(name: name, desc: desc, text: json); } - Future> _loadDocument(String path) { + Future> _loadDocument(String path) { return repo.readDocData(path).then((docDataOrFail) { return docDataOrFail.fold( (docData) => left(_decodeToDocument(docData.text)), diff --git a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart index 1e1a6c0e32..1834ee959a 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart @@ -1,9 +1,9 @@ import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/doc_modify.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/doc_query.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/doc_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/doc_modify.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/doc_query.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/errors.pb.dart'; class DocRepository { final String docId; @@ -11,7 +11,7 @@ class DocRepository { required this.docId, }); - Future> createDoc( + Future> createDoc( {required String name, String? desc, String? text}) { final request = CreateDocRequest(id: docId, name: name, desc: desc, text: text); @@ -19,26 +19,26 @@ class DocRepository { return EditorEventCreateDoc(request).send(); } - Future> readDoc() { + Future> readDoc() { final request = QueryDocRequest.create()..docId = docId; return EditorEventReadDocInfo(request).send(); } - Future> readDocData(String path) { + Future> readDocData(String path) { final request = QueryDocDataRequest.create() ..docId = docId ..path = path; return EditorEventReadDocData(request).send(); } - Future> updateDoc( + Future> updateDoc( {String? name, String? desc, String? text}) { final request = UpdateDocRequest(id: docId, name: name, text: text); return EditorEventUpdateDoc(request).send(); } - Future> closeDoc( + Future> closeDoc( {String? name, String? desc, String? text}) { throw UnimplementedError(); } diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart index f6e70ae4b9..9fac5217b3 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart @@ -2,74 +2,6 @@ /// Auto gen code from rust ast, do not edit part of 'dispatch.dart'; -class EditorEventCreateDoc { - CreateDocRequest request; - EditorEventCreateDoc(this.request); - - Future> send() { - final request = FFIRequest.create() - ..event = EditorEvent.CreateDoc.toString() - ..payload = requestToBytes(this.request); - - return Dispatch.asyncRequest(request) - .then((bytesResult) => bytesResult.fold( - (okBytes) => left(DocInfo.fromBuffer(okBytes)), - (errBytes) => right(EditorError.fromBuffer(errBytes)), - )); - } -} - -class EditorEventUpdateDoc { - UpdateDocRequest request; - EditorEventUpdateDoc(this.request); - - Future> send() { - final request = FFIRequest.create() - ..event = EditorEvent.UpdateDoc.toString() - ..payload = requestToBytes(this.request); - - return Dispatch.asyncRequest(request) - .then((bytesResult) => bytesResult.fold( - (bytes) => left(unit), - (errBytes) => right(EditorError.fromBuffer(errBytes)), - )); - } -} - -class EditorEventReadDocInfo { - QueryDocRequest request; - EditorEventReadDocInfo(this.request); - - Future> send() { - final request = FFIRequest.create() - ..event = EditorEvent.ReadDocInfo.toString() - ..payload = requestToBytes(this.request); - - return Dispatch.asyncRequest(request) - .then((bytesResult) => bytesResult.fold( - (okBytes) => left(DocInfo.fromBuffer(okBytes)), - (errBytes) => right(EditorError.fromBuffer(errBytes)), - )); - } -} - -class EditorEventReadDocData { - QueryDocDataRequest request; - EditorEventReadDocData(this.request); - - Future> send() { - final request = FFIRequest.create() - ..event = EditorEvent.ReadDocData.toString() - ..payload = requestToBytes(this.request); - - return Dispatch.asyncRequest(request) - .then((bytesResult) => bytesResult.fold( - (okBytes) => left(DocData.fromBuffer(okBytes)), - (errBytes) => right(EditorError.fromBuffer(errBytes)), - )); - } -} - class WorkspaceEventCreateWorkspace { CreateWorkspaceRequest request; WorkspaceEventCreateWorkspace(this.request); @@ -285,6 +217,74 @@ class WorkspaceEventDeleteView { } } +class EditorEventCreateDoc { + CreateDocRequest request; + EditorEventCreateDoc(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.CreateDoc.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(DocInfo.fromBuffer(okBytes)), + (errBytes) => right(DocError.fromBuffer(errBytes)), + )); + } +} + +class EditorEventUpdateDoc { + UpdateDocRequest request; + EditorEventUpdateDoc(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.UpdateDoc.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (bytes) => left(unit), + (errBytes) => right(DocError.fromBuffer(errBytes)), + )); + } +} + +class EditorEventReadDocInfo { + QueryDocRequest request; + EditorEventReadDocInfo(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.ReadDocInfo.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(DocInfo.fromBuffer(okBytes)), + (errBytes) => right(DocError.fromBuffer(errBytes)), + )); + } +} + +class EditorEventReadDocData { + QueryDocDataRequest request; + EditorEventReadDocData(this.request); + + Future> send() { + final request = FFIRequest.create() + ..event = EditorEvent.ReadDocData.toString() + ..payload = requestToBytes(this.request); + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (okBytes) => left(DocData.fromBuffer(okBytes)), + (errBytes) => right(DocError.fromBuffer(errBytes)), + )); + } +} + class UserEventGetStatus { UserEventGetStatus(); diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart index 5e6bbff243..236796caba 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart @@ -13,7 +13,7 @@ import 'package:flowy_sdk/ffi.dart' as ffi; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; -import 'package:flowy_sdk/protobuf/flowy-editor/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-document/protobuf.dart'; // ignore: unused_import import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart'; import 'package:protobuf/protobuf.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_create.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_modify.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/doc_query.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart similarity index 54% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart index bffe2ef3c6..2474ad5037 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pb.dart @@ -13,16 +13,16 @@ import 'errors.pbenum.dart'; export 'errors.pbenum.dart'; -class EditorError extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'EditorError', createEmptyInstance: create) - ..e(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: EditorErrorCode.Unknown, valueOf: EditorErrorCode.valueOf, enumValues: EditorErrorCode.values) +class DocError extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'DocError', createEmptyInstance: create) + ..e(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: DocErrorCode.Unknown, valueOf: DocErrorCode.valueOf, enumValues: DocErrorCode.values) ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg') ..hasRequiredFields = false ; - EditorError._() : super(); - factory EditorError({ - EditorErrorCode? code, + DocError._() : super(); + factory DocError({ + DocErrorCode? code, $core.String? msg, }) { final _result = create(); @@ -34,31 +34,31 @@ class EditorError extends $pb.GeneratedMessage { } return _result; } - factory EditorError.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory EditorError.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory DocError.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory DocError.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - EditorError clone() => EditorError()..mergeFromMessage(this); + DocError clone() => DocError()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - EditorError copyWith(void Function(EditorError) updates) => super.copyWith((message) => updates(message as EditorError)) as EditorError; // ignore: deprecated_member_use + DocError copyWith(void Function(DocError) updates) => super.copyWith((message) => updates(message as DocError)) as DocError; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static EditorError create() => EditorError._(); - EditorError createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static DocError create() => DocError._(); + DocError createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static EditorError getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static EditorError? _defaultInstance; + static DocError getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static DocError? _defaultInstance; @$pb.TagNumber(1) - EditorErrorCode get code => $_getN(0); + DocErrorCode get code => $_getN(0); @$pb.TagNumber(1) - set code(EditorErrorCode v) { setField(1, v); } + set code(DocErrorCode v) { setField(1, v); } @$pb.TagNumber(1) $core.bool hasCode() => $_has(0); @$pb.TagNumber(1) diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart new file mode 100644 index 0000000000..b90b9fa2d1 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbenum.dart @@ -0,0 +1,40 @@ +/// +// Generated code. Do not modify. +// source: errors.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +// ignore_for_file: UNDEFINED_SHOWN_NAME +import 'dart:core' as $core; +import 'package:protobuf/protobuf.dart' as $pb; + +class DocErrorCode extends $pb.ProtobufEnum { + static const DocErrorCode Unknown = DocErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const DocErrorCode EditorDBInternalError = DocErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorDBInternalError'); + static const DocErrorCode EditorDBConnFailed = DocErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorDBConnFailed'); + static const DocErrorCode DocNameInvalid = DocErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocNameInvalid'); + static const DocErrorCode DocViewIdInvalid = DocErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocViewIdInvalid'); + static const DocErrorCode DocDescTooLong = DocErrorCode._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocDescTooLong'); + static const DocErrorCode DocOpenFileError = DocErrorCode._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocOpenFileError'); + static const DocErrorCode DocFilePathInvalid = DocErrorCode._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocFilePathInvalid'); + static const DocErrorCode EditorUserNotLoginYet = DocErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorUserNotLoginYet'); + + static const $core.List values = [ + Unknown, + EditorDBInternalError, + EditorDBConnFailed, + DocNameInvalid, + DocViewIdInvalid, + DocDescTooLong, + DocOpenFileError, + DocFilePathInvalid, + EditorUserNotLoginYet, + ]; + + static final $core.Map<$core.int, DocErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); + static DocErrorCode? valueOf($core.int value) => _byValue[value]; + + const DocErrorCode._($core.int v, $core.String n) : super(v, n); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart new file mode 100644 index 0000000000..283fc8e15f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbjson.dart @@ -0,0 +1,39 @@ +/// +// Generated code. Do not modify. +// source: errors.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use docErrorCodeDescriptor instead') +const DocErrorCode$json = const { + '1': 'DocErrorCode', + '2': const [ + const {'1': 'Unknown', '2': 0}, + const {'1': 'EditorDBInternalError', '2': 1}, + const {'1': 'EditorDBConnFailed', '2': 2}, + const {'1': 'DocNameInvalid', '2': 10}, + const {'1': 'DocViewIdInvalid', '2': 11}, + const {'1': 'DocDescTooLong', '2': 12}, + const {'1': 'DocOpenFileError', '2': 13}, + const {'1': 'DocFilePathInvalid', '2': 14}, + const {'1': 'EditorUserNotLoginYet', '2': 100}, + ], +}; + +/// Descriptor for `DocErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List docErrorCodeDescriptor = $convert.base64Decode('CgxEb2NFcnJvckNvZGUSCwoHVW5rbm93bhAAEhkKFUVkaXRvckRCSW50ZXJuYWxFcnJvchABEhYKEkVkaXRvckRCQ29ubkZhaWxlZBACEhIKDkRvY05hbWVJbnZhbGlkEAoSFAoQRG9jVmlld0lkSW52YWxpZBALEhIKDkRvY0Rlc2NUb29Mb25nEAwSFAoQRG9jT3BlbkZpbGVFcnJvchANEhYKEkRvY0ZpbGVQYXRoSW52YWxpZBAOEhkKFUVkaXRvclVzZXJOb3RMb2dpbllldBBk'); +@$core.Deprecated('Use docErrorDescriptor instead') +const DocError$json = const { + '1': 'DocError', + '2': const [ + const {'1': 'code', '3': 1, '4': 1, '5': 14, '6': '.DocErrorCode', '10': 'code'}, + const {'1': 'msg', '3': 2, '4': 1, '5': 9, '10': 'msg'}, + ], +}; + +/// Descriptor for `DocError`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List docErrorDescriptor = $convert.base64Decode('CghEb2NFcnJvchIhCgRjb2RlGAEgASgOMg0uRG9jRXJyb3JDb2RlUgRjb2RlEhAKA21zZxgCIAEoCVIDbXNn'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/errors.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pb.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pb.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pb.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbenum.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbenum.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbenum.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbjson.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbjson.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbjson.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbserver.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/event.pbserver.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/event.pbserver.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/protobuf.dart similarity index 100% rename from app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart rename to app_flowy/packages/flowy_sdk/lib/protobuf/flowy-document/protobuf.dart diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart deleted file mode 100644 index 96ad5b534c..0000000000 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbenum.dart +++ /dev/null @@ -1,40 +0,0 @@ -/// -// Generated code. Do not modify. -// source: errors.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields - -// ignore_for_file: UNDEFINED_SHOWN_NAME -import 'dart:core' as $core; -import 'package:protobuf/protobuf.dart' as $pb; - -class EditorErrorCode extends $pb.ProtobufEnum { - static const EditorErrorCode Unknown = EditorErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); - static const EditorErrorCode EditorDBInternalError = EditorErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorDBInternalError'); - static const EditorErrorCode EditorDBConnFailed = EditorErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorDBConnFailed'); - static const EditorErrorCode DocNameInvalid = EditorErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocNameInvalid'); - static const EditorErrorCode DocViewIdInvalid = EditorErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocViewIdInvalid'); - static const EditorErrorCode DocDescTooLong = EditorErrorCode._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocDescTooLong'); - static const EditorErrorCode DocOpenFileError = EditorErrorCode._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocOpenFileError'); - static const EditorErrorCode DocFilePathInvalid = EditorErrorCode._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DocFilePathInvalid'); - static const EditorErrorCode EditorUserNotLoginYet = EditorErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EditorUserNotLoginYet'); - - static const $core.List values = [ - Unknown, - EditorDBInternalError, - EditorDBConnFailed, - DocNameInvalid, - DocViewIdInvalid, - DocDescTooLong, - DocOpenFileError, - DocFilePathInvalid, - EditorUserNotLoginYet, - ]; - - static final $core.Map<$core.int, EditorErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); - static EditorErrorCode? valueOf($core.int value) => _byValue[value]; - - const EditorErrorCode._($core.int v, $core.String n) : super(v, n); -} - diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart deleted file mode 100644 index 2e92891638..0000000000 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/errors.pbjson.dart +++ /dev/null @@ -1,39 +0,0 @@ -/// -// Generated code. Do not modify. -// source: errors.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package - -import 'dart:core' as $core; -import 'dart:convert' as $convert; -import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use editorErrorCodeDescriptor instead') -const EditorErrorCode$json = const { - '1': 'EditorErrorCode', - '2': const [ - const {'1': 'Unknown', '2': 0}, - const {'1': 'EditorDBInternalError', '2': 1}, - const {'1': 'EditorDBConnFailed', '2': 2}, - const {'1': 'DocNameInvalid', '2': 10}, - const {'1': 'DocViewIdInvalid', '2': 11}, - const {'1': 'DocDescTooLong', '2': 12}, - const {'1': 'DocOpenFileError', '2': 13}, - const {'1': 'DocFilePathInvalid', '2': 14}, - const {'1': 'EditorUserNotLoginYet', '2': 100}, - ], -}; - -/// Descriptor for `EditorErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List editorErrorCodeDescriptor = $convert.base64Decode('Cg9FZGl0b3JFcnJvckNvZGUSCwoHVW5rbm93bhAAEhkKFUVkaXRvckRCSW50ZXJuYWxFcnJvchABEhYKEkVkaXRvckRCQ29ubkZhaWxlZBACEhIKDkRvY05hbWVJbnZhbGlkEAoSFAoQRG9jVmlld0lkSW52YWxpZBALEhIKDkRvY0Rlc2NUb29Mb25nEAwSFAoQRG9jT3BlbkZpbGVFcnJvchANEhYKEkRvY0ZpbGVQYXRoSW52YWxpZBAOEhkKFUVkaXRvclVzZXJOb3RMb2dpbllldBBk'); -@$core.Deprecated('Use editorErrorDescriptor instead') -const EditorError$json = const { - '1': 'EditorError', - '2': const [ - const {'1': 'code', '3': 1, '4': 1, '5': 14, '6': '.EditorErrorCode', '10': 'code'}, - const {'1': 'msg', '3': 2, '4': 1, '5': 9, '10': 'msg'}, - ], -}; - -/// Descriptor for `EditorError`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List editorErrorDescriptor = $convert.base64Decode('CgtFZGl0b3JFcnJvchIkCgRjb2RlGAEgASgOMhAuRWRpdG9yRXJyb3JDb2RlUgRjb2RlEhAKA21zZxgCIAEoCVIDbXNn'); diff --git a/rust-lib/Cargo.toml b/rust-lib/Cargo.toml index 87a8758ff7..2f39b9ac10 100644 --- a/rust-lib/Cargo.toml +++ b/rust-lib/Cargo.toml @@ -13,6 +13,7 @@ members = [ "flowy-infra", "flowy-workspace", "flowy-observable", + "flowy-document", "flowy-editor", ] diff --git a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs index 758c295c40..0d7d78aec3 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -17,13 +17,6 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "String" => TypeCategory::Str, "ObservableSubject" | "KeyValue" - | "CreateDocRequest" - | "DocInfo" - | "DocData" - | "QueryDocRequest" - | "QueryDocDataRequest" - | "UpdateDocRequest" - | "EditorError" | "QueryAppRequest" | "CreateAppRequest" | "ColorStyle" @@ -45,6 +38,13 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "View" | "RepeatedView" | "WorkspaceError" + | "CreateDocRequest" + | "DocInfo" + | "DocData" + | "QueryDocRequest" + | "QueryDocDataRequest" + | "UpdateDocRequest" + | "DocError" | "FFIRequest" | "FFIResponse" | "UserDetail" @@ -56,12 +56,12 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "SignInParams" | "UserError" => TypeCategory::Protobuf, - "EditorEvent" - | "EditorErrorCode" - | "ViewType" + "ViewType" | "WorkspaceEvent" | "WsErrCode" | "WorkspaceObservable" + | "EditorEvent" + | "DocErrorCode" | "FFIStatusCode" | "UserStatus" | "UserEvent" diff --git a/rust-lib/flowy-dispatch/src/response/response.rs b/rust-lib/flowy-dispatch/src/response/response.rs index 593a3b4d3a..32356472f1 100644 --- a/rust-lib/flowy-dispatch/src/response/response.rs +++ b/rust-lib/flowy-dispatch/src/response/response.rs @@ -67,9 +67,9 @@ impl Responder for EventResponse { fn respond_to(self, _: &EventRequest) -> EventResponse { self } } -pub type ResponseResult = std::result::Result, E>; +pub type DataResult = std::result::Result, E>; -pub fn response_ok(data: T) -> Result, E> +pub fn data_result(data: T) -> Result, E> where E: Into, { diff --git a/rust-lib/flowy-document/Cargo.toml b/rust-lib/flowy-document/Cargo.toml new file mode 100644 index 0000000000..17199ba162 --- /dev/null +++ b/rust-lib/flowy-document/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "flowy-document" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +derive_more = {version = "0.99", features = ["display"]} +flowy-dispatch = { path = "../flowy-dispatch" } +flowy-log = { path = "../flowy-log" } +flowy-derive = { path = "../flowy-derive" } +flowy-database = { path = "../flowy-database" } +flowy-infra = { path = "../flowy-infra" } +diesel = {version = "1.4.7", features = ["sqlite"]} +diesel_derives = {version = "1.4.1", features = ["sqlite"]} +protobuf = {version = "2.18.0"} +unicode-segmentation = "1.7.1" +lazy_static = "1.4.0" +log = "0.4.14" +tokio = {version = "1.6.0", features = ["sync"]} +tracing = { version = "0.1", features = ["log"] } + +[dev-dependencies] +flowy-test = { path = "../flowy-test" } \ No newline at end of file diff --git a/rust-lib/flowy-editor/Flowy.toml b/rust-lib/flowy-document/Flowy.toml similarity index 100% rename from rust-lib/flowy-editor/Flowy.toml rename to rust-lib/flowy-document/Flowy.toml diff --git a/rust-lib/flowy-editor/src/entities/doc/doc_create.rs b/rust-lib/flowy-document/src/entities/doc/doc_create.rs similarity index 89% rename from rust-lib/flowy-editor/src/entities/doc/doc_create.rs rename to rust-lib/flowy-document/src/entities/doc/doc_create.rs index c160c8293b..ef8ccef007 100644 --- a/rust-lib/flowy-editor/src/entities/doc/doc_create.rs +++ b/rust-lib/flowy-document/src/entities/doc/doc_create.rs @@ -28,12 +28,12 @@ pub struct CreateDocParams { } impl TryInto for CreateDocRequest { - type Error = EditorError; + type Error = DocError; fn try_into(self) -> Result { let name = DocName::parse(self.name) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocNameInvalid) + ErrorBuilder::new(DocErrorCode::DocNameInvalid) .msg(e) .build() })? @@ -41,7 +41,7 @@ impl TryInto for CreateDocRequest { let id = DocViewId::parse(self.id) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + ErrorBuilder::new(DocErrorCode::DocViewIdInvalid) .msg(e) .build() })? diff --git a/rust-lib/flowy-editor/src/entities/doc/doc_modify.rs b/rust-lib/flowy-document/src/entities/doc/doc_modify.rs similarity index 86% rename from rust-lib/flowy-editor/src/entities/doc/doc_modify.rs rename to rust-lib/flowy-document/src/entities/doc/doc_modify.rs index 7980bbc89c..eacd173f0c 100644 --- a/rust-lib/flowy-editor/src/entities/doc/doc_modify.rs +++ b/rust-lib/flowy-document/src/entities/doc/doc_modify.rs @@ -25,12 +25,12 @@ pub(crate) struct UpdateDocParams { } impl TryInto for UpdateDocRequest { - type Error = EditorError; + type Error = DocError; fn try_into(self) -> Result { let id = DocId::parse(self.id) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + ErrorBuilder::new(DocErrorCode::DocViewIdInvalid) .msg(e) .build() })? @@ -41,7 +41,7 @@ impl TryInto for UpdateDocRequest { Some(name) => Some( DocName::parse(name) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocNameInvalid) + ErrorBuilder::new(DocErrorCode::DocNameInvalid) .msg(e) .build() })? @@ -54,7 +54,7 @@ impl TryInto for UpdateDocRequest { Some(desc) => Some( DocDesc::parse(desc) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocDescTooLong) + ErrorBuilder::new(DocErrorCode::DocDescTooLong) .msg(e) .build() })? diff --git a/rust-lib/flowy-editor/src/entities/doc/doc_query.rs b/rust-lib/flowy-document/src/entities/doc/doc_query.rs similarity index 83% rename from rust-lib/flowy-editor/src/entities/doc/doc_query.rs rename to rust-lib/flowy-document/src/entities/doc/doc_query.rs index ea1573fe7d..99e872a7e6 100644 --- a/rust-lib/flowy-editor/src/entities/doc/doc_query.rs +++ b/rust-lib/flowy-document/src/entities/doc/doc_query.rs @@ -16,12 +16,12 @@ pub(crate) struct QueryDocParams { } impl TryInto for QueryDocRequest { - type Error = EditorError; + type Error = DocError; fn try_into(self) -> Result { let doc_id = DocId::parse(self.doc_id) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + ErrorBuilder::new(DocErrorCode::DocViewIdInvalid) .msg(e) .build() })? @@ -46,12 +46,12 @@ pub(crate) struct QueryDocDataParams { } impl TryInto for QueryDocDataRequest { - type Error = EditorError; + type Error = DocError; fn try_into(self) -> Result { let doc_id = DocId::parse(self.doc_id) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid) + ErrorBuilder::new(DocErrorCode::DocViewIdInvalid) .msg(e) .build() })? @@ -59,7 +59,7 @@ impl TryInto for QueryDocDataRequest { let path = DocPath::parse(self.path) .map_err(|e| { - ErrorBuilder::new(EditorErrorCode::DocFilePathInvalid) + ErrorBuilder::new(DocErrorCode::DocFilePathInvalid) .msg(e) .build() })? diff --git a/rust-lib/flowy-editor/src/entities/doc/mod.rs b/rust-lib/flowy-document/src/entities/doc/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/mod.rs rename to rust-lib/flowy-document/src/entities/doc/mod.rs diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_desc.rs b/rust-lib/flowy-document/src/entities/doc/parser/doc_desc.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/parser/doc_desc.rs rename to rust-lib/flowy-document/src/entities/doc/parser/doc_desc.rs diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs b/rust-lib/flowy-document/src/entities/doc/parser/doc_id.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs rename to rust-lib/flowy-document/src/entities/doc/parser/doc_id.rs diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_name.rs b/rust-lib/flowy-document/src/entities/doc/parser/doc_name.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/parser/doc_name.rs rename to rust-lib/flowy-document/src/entities/doc/parser/doc_name.rs diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_path.rs b/rust-lib/flowy-document/src/entities/doc/parser/doc_path.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/parser/doc_path.rs rename to rust-lib/flowy-document/src/entities/doc/parser/doc_path.rs diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/doc_view_id.rs b/rust-lib/flowy-document/src/entities/doc/parser/doc_view_id.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/parser/doc_view_id.rs rename to rust-lib/flowy-document/src/entities/doc/parser/doc_view_id.rs diff --git a/rust-lib/flowy-editor/src/entities/doc/parser/mod.rs b/rust-lib/flowy-document/src/entities/doc/parser/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/doc/parser/mod.rs rename to rust-lib/flowy-document/src/entities/doc/parser/mod.rs diff --git a/rust-lib/flowy-editor/src/entities/mod.rs b/rust-lib/flowy-document/src/entities/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/entities/mod.rs rename to rust-lib/flowy-document/src/entities/mod.rs diff --git a/rust-lib/flowy-editor/src/errors.rs b/rust-lib/flowy-document/src/errors.rs similarity index 70% rename from rust-lib/flowy-editor/src/errors.rs rename to rust-lib/flowy-document/src/errors.rs index ad15db1f88..3e1ef74860 100644 --- a/rust-lib/flowy-editor/src/errors.rs +++ b/rust-lib/flowy-document/src/errors.rs @@ -5,16 +5,16 @@ use flowy_dispatch::prelude::{EventResponse, ResponseBuilder}; use std::convert::TryInto; #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct EditorError { +pub struct DocError { #[pb(index = 1)] - pub code: EditorErrorCode, + pub code: DocErrorCode, #[pb(index = 2)] pub msg: String, } -impl EditorError { - fn new(code: EditorErrorCode, msg: &str) -> Self { +impl DocError { + fn new(code: DocErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned(), @@ -23,7 +23,7 @@ impl EditorError { } #[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] -pub enum EditorErrorCode { +pub enum DocErrorCode { #[display(fmt = "Unknown")] Unknown = 0, @@ -52,27 +52,27 @@ pub enum EditorErrorCode { EditorUserNotLoginYet = 100, } -impl std::default::Default for EditorErrorCode { - fn default() -> Self { EditorErrorCode::Unknown } +impl std::default::Default for DocErrorCode { + fn default() -> Self { DocErrorCode::Unknown } } -impl std::convert::From for EditorError { +impl std::convert::From for DocError { fn from(error: flowy_database::result::Error) -> Self { - ErrorBuilder::new(EditorErrorCode::EditorDBInternalError) + ErrorBuilder::new(DocErrorCode::EditorDBInternalError) .error(error) .build() } } -impl std::convert::From for EditorError { +impl std::convert::From for DocError { fn from(error: FileError) -> Self { - ErrorBuilder::new(EditorErrorCode::DocOpenFileError) + ErrorBuilder::new(DocErrorCode::DocOpenFileError) .error(error) .build() } } -impl flowy_dispatch::Error for EditorError { +impl flowy_dispatch::Error for DocError { fn as_response(&self) -> EventResponse { let bytes: Vec = self.clone().try_into().unwrap(); ResponseBuilder::Err().data(bytes).build() @@ -80,12 +80,12 @@ impl flowy_dispatch::Error for EditorError { } pub struct ErrorBuilder { - pub code: EditorErrorCode, + pub code: DocErrorCode, pub msg: Option, } impl ErrorBuilder { - pub fn new(code: EditorErrorCode) -> Self { ErrorBuilder { code, msg: None } } + pub fn new(code: DocErrorCode) -> Self { ErrorBuilder { code, msg: None } } pub fn msg(mut self, msg: T) -> Self where @@ -103,7 +103,7 @@ impl ErrorBuilder { self } - pub fn build(mut self) -> EditorError { - EditorError::new(self.code, &self.msg.take().unwrap_or("".to_owned())) + pub fn build(mut self) -> DocError { + DocError::new(self.code, &self.msg.take().unwrap_or("".to_owned())) } } diff --git a/rust-lib/flowy-editor/src/event.rs b/rust-lib/flowy-document/src/event.rs similarity index 95% rename from rust-lib/flowy-editor/src/event.rs rename to rust-lib/flowy-document/src/event.rs index 358f863a93..c77af2d28a 100644 --- a/rust-lib/flowy-editor/src/event.rs +++ b/rust-lib/flowy-document/src/event.rs @@ -2,7 +2,7 @@ use derive_more::Display; use flowy_derive::{Flowy_Event, ProtoBuf_Enum}; #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] -#[event_err = "EditorError"] +#[event_err = "DocError"] pub enum EditorEvent { #[display(fmt = "CreateDoc")] #[event(input = "CreateDocRequest", output = "DocInfo")] diff --git a/rust-lib/flowy-editor/src/handlers/doc_handler.rs b/rust-lib/flowy-document/src/handlers/doc_handler.rs similarity index 88% rename from rust-lib/flowy-editor/src/handlers/doc_handler.rs rename to rust-lib/flowy-document/src/handlers/doc_handler.rs index 4ba6e2669c..75a0f7305d 100644 --- a/rust-lib/flowy-editor/src/handlers/doc_handler.rs +++ b/rust-lib/flowy-document/src/handlers/doc_handler.rs @@ -1,6 +1,6 @@ use crate::{ entities::doc::*, - errors::EditorError, + errors::DocError, services::{doc_controller::DocController, file_manager::FileManager}, }; use flowy_dispatch::prelude::*; @@ -12,7 +12,7 @@ pub async fn create_doc( data: Data, controller: Unit, manager: Unit>, -) -> ResponseResult { +) -> DataResult { let params: CreateDocParams = data.into_inner().try_into()?; let dir = manager.read().await.user.user_doc_dir()?; let path = manager @@ -22,7 +22,7 @@ pub async fn create_doc( let doc_desc = controller .create_doc(params, path.to_str().unwrap()) .await?; - response_ok(doc_desc) + data_result(doc_desc) } #[tracing::instrument(name = "read_doc", skip(data, controller, manager))] @@ -30,7 +30,7 @@ pub async fn read_doc( data: Data, controller: Unit, manager: Unit>, -) -> ResponseResult { +) -> DataResult { let params: QueryDocParams = data.into_inner().try_into()?; let doc_info = controller.read_doc(¶ms.doc_id).await?; let _ = manager @@ -38,28 +38,28 @@ pub async fn read_doc( .await .open(Path::new(&doc_info.path), doc_info.id.clone())?; - response_ok(doc_info) + data_result(doc_info) } #[tracing::instrument(name = "read_doc_data", skip(data, manager))] pub async fn read_doc_data( data: Data, manager: Unit>, -) -> ResponseResult { +) -> DataResult { let params: QueryDocDataParams = data.into_inner().try_into()?; let text = manager .write() .await .open(Path::new(¶ms.path), params.doc_id)?; - response_ok(DocData { text }) + data_result(DocData { text }) } pub async fn update_doc( data: Data, controller: Unit, manager: Unit>, -) -> Result<(), EditorError> { +) -> Result<(), DocError> { let mut params: UpdateDocParams = data.into_inner().try_into()?; if let Some(s) = params.text.take() { diff --git a/rust-lib/flowy-editor/src/handlers/mod.rs b/rust-lib/flowy-document/src/handlers/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/handlers/mod.rs rename to rust-lib/flowy-document/src/handlers/mod.rs diff --git a/rust-lib/flowy-document/src/lib.rs b/rust-lib/flowy-document/src/lib.rs new file mode 100644 index 0000000000..9782f9f922 --- /dev/null +++ b/rust-lib/flowy-document/src/lib.rs @@ -0,0 +1,15 @@ +pub mod entities; +pub mod errors; +pub mod event; +mod handlers; +pub mod module; +mod protobuf; +mod services; +mod sql_tables; + +#[macro_use] +extern crate flowy_database; + +pub mod prelude { + pub use crate::module::*; +} diff --git a/rust-lib/flowy-editor/src/module.rs b/rust-lib/flowy-document/src/module.rs similarity index 65% rename from rust-lib/flowy-editor/src/module.rs rename to rust-lib/flowy-document/src/module.rs index afc540b414..1f9c980065 100644 --- a/rust-lib/flowy-editor/src/module.rs +++ b/rust-lib/flowy-document/src/module.rs @@ -1,5 +1,5 @@ use crate::{ - errors::EditorError, + errors::DocError, event::EditorEvent, handlers::*, services::{doc_controller::DocController, file_manager::FileManager}, @@ -9,20 +9,20 @@ use flowy_dispatch::prelude::*; use std::sync::Arc; use tokio::sync::RwLock; -pub trait EditorDatabase: Send + Sync { - fn db_connection(&self) -> Result; +pub trait DocumentDatabase: Send + Sync { + fn db_connection(&self) -> Result; } -pub trait EditorUser: Send + Sync { - fn user_doc_dir(&self) -> Result; +pub trait DocumentUser: Send + Sync { + fn user_doc_dir(&self) -> Result; } -pub fn create(database: Arc, user: Arc) -> Module { +pub fn create(database: Arc, user: Arc) -> Module { let file_manager = RwLock::new(FileManager::new(user.clone())); let doc_controller = DocController::new(database); Module::new() - .name("Flowy-Editor") + .name("flowy-document") .data(file_manager) .data(doc_controller) .event(EditorEvent::CreateDoc, create_doc) diff --git a/rust-lib/flowy-editor/src/protobuf/mod.rs b/rust-lib/flowy-document/src/protobuf/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/mod.rs rename to rust-lib/flowy-document/src/protobuf/mod.rs diff --git a/rust-lib/flowy-editor/src/protobuf/model/doc_create.rs b/rust-lib/flowy-document/src/protobuf/model/doc_create.rs similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/model/doc_create.rs rename to rust-lib/flowy-document/src/protobuf/model/doc_create.rs diff --git a/rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs b/rust-lib/flowy-document/src/protobuf/model/doc_modify.rs similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs rename to rust-lib/flowy-document/src/protobuf/model/doc_modify.rs diff --git a/rust-lib/flowy-editor/src/protobuf/model/doc_query.rs b/rust-lib/flowy-document/src/protobuf/model/doc_query.rs similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/model/doc_query.rs rename to rust-lib/flowy-document/src/protobuf/model/doc_query.rs diff --git a/rust-lib/flowy-editor/src/protobuf/model/errors.rs b/rust-lib/flowy-document/src/protobuf/model/errors.rs similarity index 54% rename from rust-lib/flowy-editor/src/protobuf/model/errors.rs rename to rust-lib/flowy-document/src/protobuf/model/errors.rs index 9cd328d33a..d4b1250fe6 100644 --- a/rust-lib/flowy-editor/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-document/src/protobuf/model/errors.rs @@ -24,38 +24,38 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] -pub struct EditorError { +pub struct DocError { // message fields - pub code: EditorErrorCode, + pub code: DocErrorCode, pub msg: ::std::string::String, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a EditorError { - fn default() -> &'a EditorError { - ::default_instance() +impl<'a> ::std::default::Default for &'a DocError { + fn default() -> &'a DocError { + ::default_instance() } } -impl EditorError { - pub fn new() -> EditorError { +impl DocError { + pub fn new() -> DocError { ::std::default::Default::default() } - // .EditorErrorCode code = 1; + // .DocErrorCode code = 1; - pub fn get_code(&self) -> EditorErrorCode { + pub fn get_code(&self) -> DocErrorCode { self.code } pub fn clear_code(&mut self) { - self.code = EditorErrorCode::Unknown; + self.code = DocErrorCode::Unknown; } // Param is passed by value, moved - pub fn set_code(&mut self, v: EditorErrorCode) { + pub fn set_code(&mut self, v: DocErrorCode) { self.code = v; } @@ -86,7 +86,7 @@ impl EditorError { } } -impl ::protobuf::Message for EditorError { +impl ::protobuf::Message for DocError { fn is_initialized(&self) -> bool { true } @@ -113,7 +113,7 @@ impl ::protobuf::Message for EditorError { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if self.code != EditorErrorCode::Unknown { + if self.code != DocErrorCode::Unknown { my_size += ::protobuf::rt::enum_size(1, self.code); } if !self.msg.is_empty() { @@ -125,7 +125,7 @@ impl ::protobuf::Message for EditorError { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.code != EditorErrorCode::Unknown { + if self.code != DocErrorCode::Unknown { os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?; } if !self.msg.is_empty() { @@ -161,60 +161,60 @@ impl ::protobuf::Message for EditorError { Self::descriptor_static() } - fn new() -> EditorError { - EditorError::new() + fn new() -> DocError { + DocError::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( "code", - |m: &EditorError| { &m.code }, - |m: &mut EditorError| { &mut m.code }, + |m: &DocError| { &m.code }, + |m: &mut DocError| { &mut m.code }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "msg", - |m: &EditorError| { &m.msg }, - |m: &mut EditorError| { &mut m.msg }, + |m: &DocError| { &m.msg }, + |m: &mut DocError| { &mut m.msg }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "EditorError", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DocError", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static EditorError { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(EditorError::new) + fn default_instance() -> &'static DocError { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DocError::new) } } -impl ::protobuf::Clear for EditorError { +impl ::protobuf::Clear for DocError { fn clear(&mut self) { - self.code = EditorErrorCode::Unknown; + self.code = DocErrorCode::Unknown; self.msg.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for EditorError { +impl ::std::fmt::Debug for DocError { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for EditorError { +impl ::protobuf::reflect::ProtobufValue for DocError { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum EditorErrorCode { +pub enum DocErrorCode { Unknown = 0, EditorDBInternalError = 1, EditorDBConnFailed = 2, @@ -226,37 +226,37 @@ pub enum EditorErrorCode { EditorUserNotLoginYet = 100, } -impl ::protobuf::ProtobufEnum for EditorErrorCode { +impl ::protobuf::ProtobufEnum for DocErrorCode { fn value(&self) -> i32 { *self as i32 } - fn from_i32(value: i32) -> ::std::option::Option { + fn from_i32(value: i32) -> ::std::option::Option { match value { - 0 => ::std::option::Option::Some(EditorErrorCode::Unknown), - 1 => ::std::option::Option::Some(EditorErrorCode::EditorDBInternalError), - 2 => ::std::option::Option::Some(EditorErrorCode::EditorDBConnFailed), - 10 => ::std::option::Option::Some(EditorErrorCode::DocNameInvalid), - 11 => ::std::option::Option::Some(EditorErrorCode::DocViewIdInvalid), - 12 => ::std::option::Option::Some(EditorErrorCode::DocDescTooLong), - 13 => ::std::option::Option::Some(EditorErrorCode::DocOpenFileError), - 14 => ::std::option::Option::Some(EditorErrorCode::DocFilePathInvalid), - 100 => ::std::option::Option::Some(EditorErrorCode::EditorUserNotLoginYet), + 0 => ::std::option::Option::Some(DocErrorCode::Unknown), + 1 => ::std::option::Option::Some(DocErrorCode::EditorDBInternalError), + 2 => ::std::option::Option::Some(DocErrorCode::EditorDBConnFailed), + 10 => ::std::option::Option::Some(DocErrorCode::DocNameInvalid), + 11 => ::std::option::Option::Some(DocErrorCode::DocViewIdInvalid), + 12 => ::std::option::Option::Some(DocErrorCode::DocDescTooLong), + 13 => ::std::option::Option::Some(DocErrorCode::DocOpenFileError), + 14 => ::std::option::Option::Some(DocErrorCode::DocFilePathInvalid), + 100 => ::std::option::Option::Some(DocErrorCode::EditorUserNotLoginYet), _ => ::std::option::Option::None } } fn values() -> &'static [Self] { - static values: &'static [EditorErrorCode] = &[ - EditorErrorCode::Unknown, - EditorErrorCode::EditorDBInternalError, - EditorErrorCode::EditorDBConnFailed, - EditorErrorCode::DocNameInvalid, - EditorErrorCode::DocViewIdInvalid, - EditorErrorCode::DocDescTooLong, - EditorErrorCode::DocOpenFileError, - EditorErrorCode::DocFilePathInvalid, - EditorErrorCode::EditorUserNotLoginYet, + static values: &'static [DocErrorCode] = &[ + DocErrorCode::Unknown, + DocErrorCode::EditorDBInternalError, + DocErrorCode::EditorDBConnFailed, + DocErrorCode::DocNameInvalid, + DocErrorCode::DocViewIdInvalid, + DocErrorCode::DocDescTooLong, + DocErrorCode::DocOpenFileError, + DocErrorCode::DocFilePathInvalid, + DocErrorCode::EditorUserNotLoginYet, ]; values } @@ -264,61 +264,61 @@ impl ::protobuf::ProtobufEnum for EditorErrorCode { fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("EditorErrorCode", file_descriptor_proto()) + ::protobuf::reflect::EnumDescriptor::new_pb_name::("DocErrorCode", file_descriptor_proto()) }) } } -impl ::std::marker::Copy for EditorErrorCode { +impl ::std::marker::Copy for DocErrorCode { } -impl ::std::default::Default for EditorErrorCode { +impl ::std::default::Default for DocErrorCode { fn default() -> Self { - EditorErrorCode::Unknown + DocErrorCode::Unknown } } -impl ::protobuf::reflect::ProtobufValue for EditorErrorCode { +impl ::protobuf::reflect::ProtobufValue for DocErrorCode { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0cerrors.proto\"E\n\x0bEditorError\x12$\n\x04code\x18\x01\x20\x01(\ - \x0e2\x10.EditorErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\ - \x03msg*\xd8\x01\n\x0fEditorErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x19\ - \n\x15EditorDBInternalError\x10\x01\x12\x16\n\x12EditorDBConnFailed\x10\ - \x02\x12\x12\n\x0eDocNameInvalid\x10\n\x12\x14\n\x10DocViewIdInvalid\x10\ - \x0b\x12\x12\n\x0eDocDescTooLong\x10\x0c\x12\x14\n\x10DocOpenFileError\ - \x10\r\x12\x16\n\x12DocFilePathInvalid\x10\x0e\x12\x19\n\x15EditorUserNo\ - tLoginYet\x10dJ\xa1\x04\n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\ - \x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\ - \x12\x03\x02\x08\x13\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x1d\n\x0c\n\ - \x05\x04\0\x02\0\x06\x12\x03\x03\x04\x13\n\x0c\n\x05\x04\0\x02\0\x01\x12\ - \x03\x03\x14\x18\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x1b\x1c\n\x0b\n\ - \x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\ - \x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\ - \x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\ - \x10\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x14\n\x0b\n\x04\x05\0\x02\0\ - \x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\ - \x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\ - \x12\x03\x08\x04\x1e\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x19\n\ - \x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1c\x1d\n\x0b\n\x04\x05\0\x02\ - \x02\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x16\n\ - \x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\x04\x05\0\x02\x03\ - \x12\x03\n\x04\x18\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x12\n\x0c\ - \n\x05\x05\0\x02\x03\x02\x12\x03\n\x15\x17\n\x0b\n\x04\x05\0\x02\x04\x12\ - \x03\x0b\x04\x1a\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x14\n\x0c\ - \n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x17\x19\n\x0b\n\x04\x05\0\x02\x05\ - \x12\x03\x0c\x04\x18\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x12\n\ - \x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x15\x17\n\x0b\n\x04\x05\0\x02\ - \x06\x12\x03\r\x04\x1a\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x14\n\ - \x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\x17\x19\n\x0b\n\x04\x05\0\x02\x07\ - \x12\x03\x0e\x04\x1c\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x16\n\ - \x0c\n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x19\x1b\n\x0b\n\x04\x05\0\x02\ - \x08\x12\x03\x0f\x04\x20\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\ - \x19\n\x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x1c\x1fb\x06proto3\ + \n\x0cerrors.proto\"?\n\x08DocError\x12!\n\x04code\x18\x01\x20\x01(\x0e2\ + \r.DocErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\ + \xd5\x01\n\x0cDocErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x19\n\x15Edito\ + rDBInternalError\x10\x01\x12\x16\n\x12EditorDBConnFailed\x10\x02\x12\x12\ + \n\x0eDocNameInvalid\x10\n\x12\x14\n\x10DocViewIdInvalid\x10\x0b\x12\x12\ + \n\x0eDocDescTooLong\x10\x0c\x12\x14\n\x10DocOpenFileError\x10\r\x12\x16\ + \n\x12DocFilePathInvalid\x10\x0e\x12\x19\n\x15EditorUserNotLoginYet\x10d\ + J\xa1\x04\n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\ + \n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\ + \x10\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x1a\n\x0c\n\x05\x04\0\x02\0\ + \x06\x12\x03\x03\x04\x10\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x11\x15\ + \n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x18\x19\n\x0b\n\x04\x04\0\x02\ + \x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\ + \n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\ + \x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x10\x01\n\n\n\ + \x03\x05\0\x01\x12\x03\x06\x05\x11\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\ + \x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\ + \0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\ + \x04\x1e\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x19\n\x0c\n\x05\ + \x05\0\x02\x01\x02\x12\x03\x08\x1c\x1d\n\x0b\n\x04\x05\0\x02\x02\x12\x03\ + \t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x16\n\x0c\n\x05\ + \x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\ + \x04\x18\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x12\n\x0c\n\x05\x05\ + \0\x02\x03\x02\x12\x03\n\x15\x17\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\ + \x04\x1a\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x14\n\x0c\n\x05\ + \x05\0\x02\x04\x02\x12\x03\x0b\x17\x19\n\x0b\n\x04\x05\0\x02\x05\x12\x03\ + \x0c\x04\x18\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x12\n\x0c\n\ + \x05\x05\0\x02\x05\x02\x12\x03\x0c\x15\x17\n\x0b\n\x04\x05\0\x02\x06\x12\ + \x03\r\x04\x1a\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x14\n\x0c\n\ + \x05\x05\0\x02\x06\x02\x12\x03\r\x17\x19\n\x0b\n\x04\x05\0\x02\x07\x12\ + \x03\x0e\x04\x1c\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x16\n\x0c\ + \n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x19\x1b\n\x0b\n\x04\x05\0\x02\x08\ + \x12\x03\x0f\x04\x20\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x19\n\ + \x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x1c\x1fb\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-editor/src/protobuf/model/event.rs b/rust-lib/flowy-document/src/protobuf/model/event.rs similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/model/event.rs rename to rust-lib/flowy-document/src/protobuf/model/event.rs diff --git a/rust-lib/flowy-editor/src/protobuf/model/mod.rs b/rust-lib/flowy-document/src/protobuf/model/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/model/mod.rs rename to rust-lib/flowy-document/src/protobuf/model/mod.rs diff --git a/rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto b/rust-lib/flowy-document/src/protobuf/proto/doc_create.proto similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto rename to rust-lib/flowy-document/src/protobuf/proto/doc_create.proto diff --git a/rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto b/rust-lib/flowy-document/src/protobuf/proto/doc_modify.proto similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto rename to rust-lib/flowy-document/src/protobuf/proto/doc_modify.proto diff --git a/rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto b/rust-lib/flowy-document/src/protobuf/proto/doc_query.proto similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto rename to rust-lib/flowy-document/src/protobuf/proto/doc_query.proto diff --git a/rust-lib/flowy-editor/src/protobuf/proto/errors.proto b/rust-lib/flowy-document/src/protobuf/proto/errors.proto similarity index 79% rename from rust-lib/flowy-editor/src/protobuf/proto/errors.proto rename to rust-lib/flowy-document/src/protobuf/proto/errors.proto index a63ee113ac..38843f0fcc 100644 --- a/rust-lib/flowy-editor/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-document/src/protobuf/proto/errors.proto @@ -1,10 +1,10 @@ syntax = "proto3"; -message EditorError { - EditorErrorCode code = 1; +message DocError { + DocErrorCode code = 1; string msg = 2; } -enum EditorErrorCode { +enum DocErrorCode { Unknown = 0; EditorDBInternalError = 1; EditorDBConnFailed = 2; diff --git a/rust-lib/flowy-editor/src/protobuf/proto/event.proto b/rust-lib/flowy-document/src/protobuf/proto/event.proto similarity index 100% rename from rust-lib/flowy-editor/src/protobuf/proto/event.proto rename to rust-lib/flowy-document/src/protobuf/proto/event.proto diff --git a/rust-lib/flowy-editor/src/services/doc_controller.rs b/rust-lib/flowy-document/src/services/doc_controller.rs similarity index 82% rename from rust-lib/flowy-editor/src/services/doc_controller.rs rename to rust-lib/flowy-document/src/services/doc_controller.rs index 727459294e..3cd4c2cfac 100644 --- a/rust-lib/flowy-editor/src/services/doc_controller.rs +++ b/rust-lib/flowy-document/src/services/doc_controller.rs @@ -1,7 +1,7 @@ use crate::{ entities::doc::{CreateDocParams, DocInfo, UpdateDocParams}, - errors::EditorError, - module::EditorDatabase, + errors::DocError, + module::DocumentDatabase, sql_tables::doc::{DocTable, DocTableChangeset, DocTableSql}, }; use std::sync::Arc; @@ -11,7 +11,7 @@ pub struct DocController { } impl DocController { - pub(crate) fn new(database: Arc) -> Self { + pub(crate) fn new(database: Arc) -> Self { let sql = Arc::new(DocTableSql { database }); Self { sql } } @@ -20,7 +20,7 @@ impl DocController { &self, params: CreateDocParams, path: &str, - ) -> Result { + ) -> Result { let doc_table = DocTable::new(params, path); let doc: DocInfo = doc_table.clone().into(); let _ = self.sql.create_doc_table(doc_table)?; @@ -28,13 +28,13 @@ impl DocController { Ok(doc) } - pub(crate) async fn update_doc(&self, params: UpdateDocParams) -> Result<(), EditorError> { + pub(crate) async fn update_doc(&self, params: UpdateDocParams) -> Result<(), DocError> { let changeset = DocTableChangeset::new(params); let _ = self.sql.update_doc_table(changeset)?; Ok(()) } - pub(crate) async fn read_doc(&self, doc_id: &str) -> Result { + pub(crate) async fn read_doc(&self, doc_id: &str) -> Result { let doc_table = self.sql.read_doc_table(doc_id)?; let doc_desc: DocInfo = doc_table.into(); Ok(doc_desc) diff --git a/rust-lib/flowy-editor/src/services/file_manager/file.rs b/rust-lib/flowy-document/src/services/file_manager/file.rs similarity index 100% rename from rust-lib/flowy-editor/src/services/file_manager/file.rs rename to rust-lib/flowy-document/src/services/file_manager/file.rs diff --git a/rust-lib/flowy-editor/src/services/file_manager/manager.rs b/rust-lib/flowy-document/src/services/file_manager/manager.rs similarity index 95% rename from rust-lib/flowy-editor/src/services/file_manager/manager.rs rename to rust-lib/flowy-document/src/services/file_manager/manager.rs index 9d29e08193..6b87520851 100644 --- a/rust-lib/flowy-editor/src/services/file_manager/manager.rs +++ b/rust-lib/flowy-document/src/services/file_manager/manager.rs @@ -1,4 +1,4 @@ -use crate::{module::EditorUser, services::file_manager::*}; +use crate::{module::DocumentUser, services::file_manager::*}; use std::{ collections::HashMap, path::{Path, PathBuf}, @@ -6,13 +6,13 @@ use std::{ }; pub struct FileManager { - pub user: Arc, + pub user: Arc, open_files: HashMap, file_info: HashMap, } impl FileManager { - pub(crate) fn new(user: Arc) -> Self { + pub(crate) fn new(user: Arc) -> Self { Self { user, open_files: HashMap::new(), diff --git a/rust-lib/flowy-editor/src/services/file_manager/mod.rs b/rust-lib/flowy-document/src/services/file_manager/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/services/file_manager/mod.rs rename to rust-lib/flowy-document/src/services/file_manager/mod.rs diff --git a/rust-lib/flowy-editor/src/services/mod.rs b/rust-lib/flowy-document/src/services/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/services/mod.rs rename to rust-lib/flowy-document/src/services/mod.rs diff --git a/rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs b/rust-lib/flowy-document/src/sql_tables/doc/doc_sql.rs similarity index 81% rename from rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs rename to rust-lib/flowy-document/src/sql_tables/doc/doc_sql.rs index 25f074feae..bdd4c0515d 100644 --- a/rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs +++ b/rust-lib/flowy-document/src/sql_tables/doc/doc_sql.rs @@ -1,6 +1,6 @@ use crate::{ - errors::EditorError, - module::EditorDatabase, + errors::DocError, + module::DocumentDatabase, sql_tables::doc::{DocTable, DocTableChangeset}, }; use flowy_database::{ @@ -10,11 +10,11 @@ use flowy_database::{ use std::sync::Arc; pub struct DocTableSql { - pub database: Arc, + pub database: Arc, } impl DocTableSql { - pub(crate) fn create_doc_table(&self, doc_table: DocTable) -> Result<(), EditorError> { + pub(crate) fn create_doc_table(&self, doc_table: DocTable) -> Result<(), DocError> { let conn = self.database.db_connection()?; let _ = diesel::insert_into(doc_table::table) .values(doc_table) @@ -22,13 +22,13 @@ impl DocTableSql { Ok(()) } - pub(crate) fn update_doc_table(&self, changeset: DocTableChangeset) -> Result<(), EditorError> { + pub(crate) fn update_doc_table(&self, changeset: DocTableChangeset) -> Result<(), DocError> { let conn = self.database.db_connection()?; diesel_update_table!(doc_table, changeset, conn); Ok(()) } - pub(crate) fn read_doc_table(&self, doc_id: &str) -> Result { + pub(crate) fn read_doc_table(&self, doc_id: &str) -> Result { let doc_table = dsl::doc_table .filter(doc_table::id.eq(doc_id)) .first::(&*(self.database.db_connection()?))?; @@ -36,5 +36,5 @@ impl DocTableSql { Ok(doc_table) } - pub(crate) fn delete_doc(&self, _view_id: &str) -> Result<(), EditorError> { unimplemented!() } + pub(crate) fn delete_doc(&self, _view_id: &str) -> Result<(), DocError> { unimplemented!() } } diff --git a/rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs b/rust-lib/flowy-document/src/sql_tables/doc/doc_table.rs similarity index 100% rename from rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs rename to rust-lib/flowy-document/src/sql_tables/doc/doc_table.rs diff --git a/rust-lib/flowy-editor/src/sql_tables/doc/mod.rs b/rust-lib/flowy-document/src/sql_tables/doc/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/sql_tables/doc/mod.rs rename to rust-lib/flowy-document/src/sql_tables/doc/mod.rs diff --git a/rust-lib/flowy-editor/src/sql_tables/mod.rs b/rust-lib/flowy-document/src/sql_tables/mod.rs similarity index 100% rename from rust-lib/flowy-editor/src/sql_tables/mod.rs rename to rust-lib/flowy-document/src/sql_tables/mod.rs diff --git a/rust-lib/flowy-editor/tests/editor/doc_test.rs b/rust-lib/flowy-document/tests/editor/doc_test.rs similarity index 100% rename from rust-lib/flowy-editor/tests/editor/doc_test.rs rename to rust-lib/flowy-document/tests/editor/doc_test.rs diff --git a/rust-lib/flowy-editor/tests/editor/helper.rs b/rust-lib/flowy-document/tests/editor/helper.rs similarity index 100% rename from rust-lib/flowy-editor/tests/editor/helper.rs rename to rust-lib/flowy-document/tests/editor/helper.rs diff --git a/rust-lib/flowy-editor/tests/editor/main.rs b/rust-lib/flowy-document/tests/editor/main.rs similarity index 100% rename from rust-lib/flowy-editor/tests/editor/main.rs rename to rust-lib/flowy-document/tests/editor/main.rs diff --git a/rust-lib/flowy-editor/Cargo.toml b/rust-lib/flowy-editor/Cargo.toml index d62fce0b3f..8d3fb43dd9 100644 --- a/rust-lib/flowy-editor/Cargo.toml +++ b/rust-lib/flowy-editor/Cargo.toml @@ -6,20 +6,3 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -derive_more = {version = "0.99", features = ["display"]} -flowy-dispatch = { path = "../flowy-dispatch" } -flowy-log = { path = "../flowy-log" } -flowy-derive = { path = "../flowy-derive" } -flowy-database = { path = "../flowy-database" } -flowy-infra = { path = "../flowy-infra" } -diesel = {version = "1.4.7", features = ["sqlite"]} -diesel_derives = {version = "1.4.1", features = ["sqlite"]} -protobuf = {version = "2.18.0"} -unicode-segmentation = "1.7.1" -lazy_static = "1.4.0" -log = "0.4.14" -tokio = {version = "1.6.0", features = ["sync"]} -tracing = { version = "0.1", features = ["log"] } - -[dev-dependencies] -flowy-test = { path = "../flowy-test" } \ No newline at end of file diff --git a/rust-lib/flowy-editor/src/lib.rs b/rust-lib/flowy-editor/src/lib.rs index 9782f9f922..31e1bb209f 100644 --- a/rust-lib/flowy-editor/src/lib.rs +++ b/rust-lib/flowy-editor/src/lib.rs @@ -1,15 +1,7 @@ -pub mod entities; -pub mod errors; -pub mod event; -mod handlers; -pub mod module; -mod protobuf; -mod services; -mod sql_tables; - -#[macro_use] -extern crate flowy_database; - -pub mod prelude { - pub use crate::module::*; +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } } diff --git a/rust-lib/flowy-sdk/Cargo.toml b/rust-lib/flowy-sdk/Cargo.toml index 7ba480104d..66d16677ba 100644 --- a/rust-lib/flowy-sdk/Cargo.toml +++ b/rust-lib/flowy-sdk/Cargo.toml @@ -13,7 +13,7 @@ flowy-user = { path = "../flowy-user" } flowy-infra = { path = "../flowy-infra" } flowy-workspace = { path = "../flowy-workspace" } flowy-database = { path = "../flowy-database" } -flowy-editor = { path = "../flowy-editor" } +flowy-document = { path = "../flowy-document" } tracing = { version = "0.1" } log = "0.4.14" futures-core = { version = "0.3", default-features = false } diff --git a/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs b/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs index b2dfae9887..9147bd0d1f 100644 --- a/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs +++ b/rust-lib/flowy-sdk/src/deps_resolve/editor_deps_impl.rs @@ -1,7 +1,7 @@ use flowy_database::DBConnection; -use flowy_editor::{ - errors::{EditorError, EditorErrorCode, ErrorBuilder}, - module::{EditorDatabase, EditorUser}, +use flowy_document::{ + errors::{DocError, DocErrorCode, ErrorBuilder}, + module::{DocumentDatabase, DocumentUser}, }; use flowy_user::prelude::UserSession; use std::{path::Path, sync::Arc}; @@ -10,10 +10,10 @@ pub struct EditorDatabaseImpl { pub(crate) user_session: Arc, } -impl EditorDatabase for EditorDatabaseImpl { - fn db_connection(&self) -> Result { +impl DocumentDatabase for EditorDatabaseImpl { + fn db_connection(&self) -> Result { self.user_session.get_db_connection().map_err(|e| { - ErrorBuilder::new(EditorErrorCode::EditorDBConnFailed) + ErrorBuilder::new(DocErrorCode::EditorDBConnFailed) .error(e) .build() }) @@ -24,10 +24,10 @@ pub struct EditorUserImpl { pub(crate) user_session: Arc, } -impl EditorUser for EditorUserImpl { - fn user_doc_dir(&self) -> Result { +impl DocumentUser for EditorUserImpl { + fn user_doc_dir(&self) -> Result { let dir = self.user_session.get_user_dir().map_err(|e| { - ErrorBuilder::new(EditorErrorCode::EditorUserNotLoginYet) + ErrorBuilder::new(DocErrorCode::EditorUserNotLoginYet) .error(e) .build() })?; diff --git a/rust-lib/flowy-sdk/src/module.rs b/rust-lib/flowy-sdk/src/module.rs index 3ed53cd87d..bbfa192012 100644 --- a/rust-lib/flowy-sdk/src/module.rs +++ b/rust-lib/flowy-sdk/src/module.rs @@ -40,6 +40,6 @@ pub fn build_modules(config: ModuleConfig, _server: ArcFlowyServer) -> Vec, session: Unit>, -) -> ResponseResult { +) -> DataResult { let params: SignInParams = data.into_inner().try_into()?; let user = session.sign_in(params).await?; let user_detail = UserDetail::from(user); - response_ok(user_detail) + data_result(user_detail) } #[tracing::instrument( @@ -25,9 +25,9 @@ pub async fn sign_in( pub async fn sign_up( data: Data, session: Unit>, -) -> ResponseResult { +) -> DataResult { let params: SignUpParams = data.into_inner().try_into()?; let user = session.sign_up(params).await?; let user_detail = UserDetail::from(user); - response_ok(user_detail) + data_result(user_detail) } diff --git a/rust-lib/flowy-user/src/handlers/user_handler.rs b/rust-lib/flowy-user/src/handlers/user_handler.rs index e5c0af0a8a..851e9408b7 100644 --- a/rust-lib/flowy-user/src/handlers/user_handler.rs +++ b/rust-lib/flowy-user/src/handlers/user_handler.rs @@ -3,11 +3,9 @@ use flowy_dispatch::prelude::*; use std::{convert::TryInto, sync::Arc}; #[tracing::instrument(name = "get_user_status", skip(session))] -pub async fn get_user_status( - session: Unit>, -) -> ResponseResult { +pub async fn get_user_status(session: Unit>) -> DataResult { let user_detail = session.user_detail()?; - response_ok(user_detail) + data_result(user_detail) } #[tracing::instrument(name = "sign_out", skip(session))] @@ -20,8 +18,8 @@ pub async fn sign_out(session: Unit>) -> Result<(), UserError> pub async fn update_user( data: Data, session: Unit>, -) -> ResponseResult { +) -> DataResult { let params: UpdateUserParams = data.into_inner().try_into()?; let user_detail = session.update_user(params)?; - response_ok(user_detail) + data_result(user_detail) } diff --git a/rust-lib/flowy-workspace/src/handlers/app_handler.rs b/rust-lib/flowy-workspace/src/handlers/app_handler.rs index 3d5c9008d0..e53486b56b 100644 --- a/rust-lib/flowy-workspace/src/handlers/app_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/app_handler.rs @@ -16,17 +16,17 @@ use crate::{ errors::WorkspaceError, services::{AppController, ViewController}, }; -use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit}; +use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit}; use std::{convert::TryInto, sync::Arc}; #[tracing::instrument(name = "create_app", skip(data, controller))] pub async fn create_app( data: Data, controller: Unit>, -) -> ResponseResult { +) -> DataResult { let params: CreateAppParams = data.into_inner().try_into()?; let detail = controller.create_app(params)?; - response_ok(detail) + data_result(detail) } #[tracing::instrument(name = "delete_app", skip(data, controller))] @@ -54,15 +54,17 @@ pub async fn read_app( data: Data, app_controller: Unit>, view_controller: Unit>, -) -> ResponseResult { +) -> DataResult { let params: QueryAppParams = data.into_inner().try_into()?; let mut app = app_controller .read_app(¶ms.app_id, params.is_trash) .await?; + + // The View's belonging is the view indexed by the belong_to_id for now if params.read_belongings { let views = view_controller.read_views_belong_to(¶ms.app_id).await?; app.belongings = RepeatedView { items: views }; } - response_ok(app) + data_result(app) } diff --git a/rust-lib/flowy-workspace/src/handlers/view_handler.rs b/rust-lib/flowy-workspace/src/handlers/view_handler.rs index 0dc6bf86f1..97172bbfce 100644 --- a/rust-lib/flowy-workspace/src/handlers/view_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/view_handler.rs @@ -14,24 +14,24 @@ use crate::{ errors::WorkspaceError, services::ViewController, }; -use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit}; +use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit}; use std::{convert::TryInto, sync::Arc}; #[tracing::instrument(name = "create_view", skip(data, controller))] pub async fn create_view( data: Data, controller: Unit>, -) -> ResponseResult { +) -> DataResult { let params: CreateViewParams = data.into_inner().try_into()?; let view = controller.create_view(params).await?; - response_ok(view) + data_result(view) } #[tracing::instrument(name = "read_view", skip(data, controller))] pub async fn read_view( data: Data, controller: Unit>, -) -> ResponseResult { +) -> DataResult { let params: QueryViewParams = data.into_inner().try_into()?; let mut view = controller .read_view(¶ms.view_id, params.is_trash) @@ -42,7 +42,7 @@ pub async fn read_view( view.belongings = RepeatedView { items: views } } - response_ok(view) + data_result(view) } #[tracing::instrument(name = "update_view", skip(data, controller))] diff --git a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs index 7a5a60f5a2..0853c6a8f3 100644 --- a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs @@ -3,33 +3,33 @@ use crate::{ errors::WorkspaceError, services::WorkspaceController, }; -use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit}; +use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit}; use std::{convert::TryInto, sync::Arc}; #[tracing::instrument(name = "create_workspace", skip(data, controller))] pub async fn create_workspace( data: Data, controller: Unit>, -) -> ResponseResult { +) -> DataResult { let controller = controller.get_ref().clone(); let params: CreateWorkspaceParams = data.into_inner().try_into()?; let detail = controller.create_workspace(params).await?; - response_ok(detail) + data_result(detail) } #[tracing::instrument(name = "read_cur_workspace", skip(controller))] pub async fn read_cur_workspace( controller: Unit>, -) -> ResponseResult { +) -> DataResult { let workspace = controller.read_cur_workspace().await?; - response_ok(workspace) + data_result(workspace) } #[tracing::instrument(name = "read_workspace", skip(data, controller))] pub async fn read_workspace( data: Data, controller: Unit>, -) -> ResponseResult { +) -> DataResult { let params: QueryWorkspaceParams = data.into_inner().try_into()?; let mut workspace = controller.read_workspace(¶ms.workspace_id).await?; @@ -38,14 +38,14 @@ pub async fn read_workspace( workspace.apps = RepeatedApp { items: apps }; } - response_ok(workspace) + data_result(workspace) } #[tracing::instrument(name = "get_all_workspaces", skip(controller))] pub async fn read_all_workspaces( controller: Unit>, -) -> ResponseResult { +) -> DataResult { let workspaces = controller.read_workspaces_belong_to_user().await?; - response_ok(Workspaces { items: workspaces }) + data_result(Workspaces { items: workspaces }) } diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs index 00f8423a13..d8c3a17ff7 100644 --- a/rust-lib/flowy-workspace/src/services/app_controller.rs +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -1,8 +1,5 @@ use crate::{ - entities::{ - app::{App, CreateAppParams, *}, - view::View, - }, + entities::app::{App, CreateAppParams, *}, errors::*, module::{WorkspaceDatabase, WorkspaceUser}, observable::*, diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs b/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs index 035e5dd513..5a56a44560 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/app/app_sql.rs @@ -1,10 +1,7 @@ use crate::{ errors::WorkspaceError, module::WorkspaceDatabase, - sql_tables::{ - app::{AppTable, AppTableChangeset}, - view::ViewTable, - }, + sql_tables::app::{AppTable, AppTableChangeset}, }; use flowy_database::{ prelude::*, diff --git a/rust-lib/flowy-workspace/tests/event/app_test.rs b/rust-lib/flowy-workspace/tests/event/app_test.rs index 630555eb89..069a9463b9 100644 --- a/rust-lib/flowy-workspace/tests/event/app_test.rs +++ b/rust-lib/flowy-workspace/tests/event/app_test.rs @@ -1,7 +1,7 @@ use crate::helper::*; use flowy_workspace::entities::{ - app::{QueryAppRequest, UpdateAppParams, UpdateAppRequest}, + app::{QueryAppRequest, UpdateAppRequest}, view::*, };