rename flowy-editor to flowy-document

This commit is contained in:
appflowy 2021-07-31 10:50:56 +08:00
parent 033ea89bde
commit 55de7f69a4
89 changed files with 456 additions and 446 deletions

View File

@ -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<DocWatchEvent, DocWatchState> {
@ -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;
}

View File

@ -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<TResult extends Object?>({
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 extends Object?>({
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<TResult extends Object?>({
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 extends Object?>({
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<TResult extends Object?>({
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 extends Object?>({
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<TResult extends Object?>({
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 extends Object?>({
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<LoadFail> get copyWith =>
throw _privateConstructorUsedError;

View File

@ -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<Either<Doc, EditorError>> readDoc();
Future<Either<Unit, EditorError>> updateDoc(
Future<Either<Doc, DocError>> readDoc();
Future<Either<Unit, DocError>> updateDoc(
{String? name, String? desc, String? text});
Future<Either<Unit, EditorError>> closeDoc();
Future<Either<Unit, DocError>> closeDoc();
}

View File

@ -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<Either<Unit, EditorError>> closeDoc() {
Future<Either<Unit, DocError>> closeDoc() {
return repo.closeDoc();
}
@override
Future<Either<Doc, EditorError>> readDoc() async {
Future<Either<Doc, DocError>> 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<Either<Unit, EditorError>> updateDoc(
Future<Either<Unit, DocError>> updateDoc(
{String? name, String? desc, String? text}) {
final json = jsonEncode(text ?? "");
return repo.updateDoc(name: name, desc: desc, text: json);
}
Future<Either<Document, EditorError>> _loadDocument(String path) {
Future<Either<Document, DocError>> _loadDocument(String path) {
return repo.readDocData(path).then((docDataOrFail) {
return docDataOrFail.fold(
(docData) => left(_decodeToDocument(docData.text)),

View File

@ -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<Either<DocInfo, EditorError>> createDoc(
Future<Either<DocInfo, DocError>> 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<Either<DocInfo, EditorError>> readDoc() {
Future<Either<DocInfo, DocError>> readDoc() {
final request = QueryDocRequest.create()..docId = docId;
return EditorEventReadDocInfo(request).send();
}
Future<Either<DocData, EditorError>> readDocData(String path) {
Future<Either<DocData, DocError>> readDocData(String path) {
final request = QueryDocDataRequest.create()
..docId = docId
..path = path;
return EditorEventReadDocData(request).send();
}
Future<Either<Unit, EditorError>> updateDoc(
Future<Either<Unit, DocError>> updateDoc(
{String? name, String? desc, String? text}) {
final request = UpdateDocRequest(id: docId, name: name, text: text);
return EditorEventUpdateDoc(request).send();
}
Future<Either<Unit, EditorError>> closeDoc(
Future<Either<Unit, DocError>> closeDoc(
{String? name, String? desc, String? text}) {
throw UnimplementedError();
}

View File

@ -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<Either<DocInfo, EditorError>> 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<Either<Unit, EditorError>> 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<Either<DocInfo, EditorError>> 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<Either<DocData, EditorError>> 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<Either<DocInfo, DocError>> 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<Either<Unit, DocError>> 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<Either<DocInfo, DocError>> 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<Either<DocData, DocError>> 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();

View File

@ -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';

View File

@ -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<EditorErrorCode>(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<DocErrorCode>(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<EditorError> createRepeated() => $pb.PbList<EditorError>();
static DocError create() => DocError._();
DocError createEmptyInstance() => create();
static $pb.PbList<DocError> createRepeated() => $pb.PbList<DocError>();
@$core.pragma('dart2js:noInline')
static EditorError getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<EditorError>(create);
static EditorError? _defaultInstance;
static DocError getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<DocError>(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)

View File

@ -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<DocErrorCode> values = <DocErrorCode> [
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);
}

View File

@ -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');

View File

@ -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<EditorErrorCode> values = <EditorErrorCode> [
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);
}

View File

@ -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');

View File

@ -13,6 +13,7 @@ members = [
"flowy-infra",
"flowy-workspace",
"flowy-observable",
"flowy-document",
"flowy-editor",
]

View File

@ -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"

View File

@ -67,9 +67,9 @@ impl Responder for EventResponse {
fn respond_to(self, _: &EventRequest) -> EventResponse { self }
}
pub type ResponseResult<T, E> = std::result::Result<Data<T>, E>;
pub type DataResult<T, E> = std::result::Result<Data<T>, E>;
pub fn response_ok<T, E>(data: T) -> Result<Data<T>, E>
pub fn data_result<T, E>(data: T) -> Result<Data<T>, E>
where
E: Into<DispatchError>,
{

View File

@ -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" }

View File

@ -28,12 +28,12 @@ pub struct CreateDocParams {
}
impl TryInto<CreateDocParams> for CreateDocRequest {
type Error = EditorError;
type Error = DocError;
fn try_into(self) -> Result<CreateDocParams, Self::Error> {
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<CreateDocParams> for CreateDocRequest {
let id = DocViewId::parse(self.id)
.map_err(|e| {
ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid)
ErrorBuilder::new(DocErrorCode::DocViewIdInvalid)
.msg(e)
.build()
})?

View File

@ -25,12 +25,12 @@ pub(crate) struct UpdateDocParams {
}
impl TryInto<UpdateDocParams> for UpdateDocRequest {
type Error = EditorError;
type Error = DocError;
fn try_into(self) -> Result<UpdateDocParams, Self::Error> {
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<UpdateDocParams> 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<UpdateDocParams> for UpdateDocRequest {
Some(desc) => Some(
DocDesc::parse(desc)
.map_err(|e| {
ErrorBuilder::new(EditorErrorCode::DocDescTooLong)
ErrorBuilder::new(DocErrorCode::DocDescTooLong)
.msg(e)
.build()
})?

View File

@ -16,12 +16,12 @@ pub(crate) struct QueryDocParams {
}
impl TryInto<QueryDocParams> for QueryDocRequest {
type Error = EditorError;
type Error = DocError;
fn try_into(self) -> Result<QueryDocParams, Self::Error> {
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<QueryDocDataParams> for QueryDocDataRequest {
type Error = EditorError;
type Error = DocError;
fn try_into(self) -> Result<QueryDocDataParams, Self::Error> {
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<QueryDocDataParams> for QueryDocDataRequest {
let path = DocPath::parse(self.path)
.map_err(|e| {
ErrorBuilder::new(EditorErrorCode::DocFilePathInvalid)
ErrorBuilder::new(DocErrorCode::DocFilePathInvalid)
.msg(e)
.build()
})?

View File

@ -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<flowy_database::result::Error> for EditorError {
impl std::convert::From<flowy_database::result::Error> 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<FileError> for EditorError {
impl std::convert::From<FileError> 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<u8> = 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<String>,
}
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<T>(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()))
}
}

View File

@ -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")]

View File

@ -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<CreateDocRequest>,
controller: Unit<DocController>,
manager: Unit<RwLock<FileManager>>,
) -> ResponseResult<DocInfo, EditorError> {
) -> DataResult<DocInfo, DocError> {
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<QueryDocRequest>,
controller: Unit<DocController>,
manager: Unit<RwLock<FileManager>>,
) -> ResponseResult<DocInfo, EditorError> {
) -> DataResult<DocInfo, DocError> {
let params: QueryDocParams = data.into_inner().try_into()?;
let doc_info = controller.read_doc(&params.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<QueryDocDataRequest>,
manager: Unit<RwLock<FileManager>>,
) -> ResponseResult<DocData, EditorError> {
) -> DataResult<DocData, DocError> {
let params: QueryDocDataParams = data.into_inner().try_into()?;
let text = manager
.write()
.await
.open(Path::new(&params.path), params.doc_id)?;
response_ok(DocData { text })
data_result(DocData { text })
}
pub async fn update_doc(
data: Data<UpdateDocRequest>,
controller: Unit<DocController>,
manager: Unit<RwLock<FileManager>>,
) -> Result<(), EditorError> {
) -> Result<(), DocError> {
let mut params: UpdateDocParams = data.into_inner().try_into()?;
if let Some(s) = params.text.take() {

View File

@ -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::*;
}

View File

@ -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<DBConnection, EditorError>;
pub trait DocumentDatabase: Send + Sync {
fn db_connection(&self) -> Result<DBConnection, DocError>;
}
pub trait EditorUser: Send + Sync {
fn user_doc_dir(&self) -> Result<String, EditorError>;
pub trait DocumentUser: Send + Sync {
fn user_doc_dir(&self) -> Result<String, DocError>;
}
pub fn create(database: Arc<dyn EditorDatabase>, user: Arc<dyn EditorUser>) -> Module {
pub fn create(database: Arc<dyn DocumentDatabase>, user: Arc<dyn DocumentUser>) -> 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)

View File

@ -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 {
<EditorError as ::protobuf::Message>::default_instance()
impl<'a> ::std::default::Default for &'a DocError {
fn default() -> &'a DocError {
<DocError as ::protobuf::Message>::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<EditorErrorCode>>(
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum<DocErrorCode>>(
"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>(
"EditorError",
::protobuf::reflect::MessageDescriptor::new_pb_name::<DocError>(
"DocError",
fields,
file_descriptor_proto()
)
})
}
fn default_instance() -> &'static EditorError {
static instance: ::protobuf::rt::LazyV2<EditorError> = ::protobuf::rt::LazyV2::INIT;
instance.get(EditorError::new)
fn default_instance() -> &'static DocError {
static instance: ::protobuf::rt::LazyV2<DocError> = ::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<EditorErrorCode> {
fn from_i32(value: i32) -> ::std::option::Option<DocErrorCode> {
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>("EditorErrorCode", file_descriptor_proto())
::protobuf::reflect::EnumDescriptor::new_pb_name::<DocErrorCode>("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;

View File

@ -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;

View File

@ -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<dyn EditorDatabase>) -> Self {
pub(crate) fn new(database: Arc<dyn DocumentDatabase>) -> Self {
let sql = Arc::new(DocTableSql { database });
Self { sql }
}
@ -20,7 +20,7 @@ impl DocController {
&self,
params: CreateDocParams,
path: &str,
) -> Result<DocInfo, EditorError> {
) -> Result<DocInfo, DocError> {
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<DocInfo, EditorError> {
pub(crate) async fn read_doc(&self, doc_id: &str) -> Result<DocInfo, DocError> {
let doc_table = self.sql.read_doc_table(doc_id)?;
let doc_desc: DocInfo = doc_table.into();
Ok(doc_desc)

View File

@ -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<dyn EditorUser>,
pub user: Arc<dyn DocumentUser>,
open_files: HashMap<PathBuf, FileId>,
file_info: HashMap<FileId, FileInfo>,
}
impl FileManager {
pub(crate) fn new(user: Arc<dyn EditorUser>) -> Self {
pub(crate) fn new(user: Arc<dyn DocumentUser>) -> Self {
Self {
user,
open_files: HashMap::new(),

View File

@ -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<dyn EditorDatabase>,
pub database: Arc<dyn DocumentDatabase>,
}
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<DocTable, EditorError> {
pub(crate) fn read_doc_table(&self, doc_id: &str) -> Result<DocTable, DocError> {
let doc_table = dsl::doc_table
.filter(doc_table::id.eq(doc_id))
.first::<DocTable>(&*(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!() }
}

View File

@ -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" }

View File

@ -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);
}
}

View File

@ -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 }

View File

@ -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<UserSession>,
}
impl EditorDatabase for EditorDatabaseImpl {
fn db_connection(&self) -> Result<DBConnection, EditorError> {
impl DocumentDatabase for EditorDatabaseImpl {
fn db_connection(&self) -> Result<DBConnection, DocError> {
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<UserSession>,
}
impl EditorUser for EditorUserImpl {
fn user_doc_dir(&self) -> Result<String, EditorError> {
impl DocumentUser for EditorUserImpl {
fn user_doc_dir(&self) -> Result<String, DocError> {
let dir = self.user_session.get_user_dir().map_err(|e| {
ErrorBuilder::new(EditorErrorCode::EditorUserNotLoginYet)
ErrorBuilder::new(DocErrorCode::EditorUserNotLoginYet)
.error(e)
.build()
})?;

View File

@ -40,6 +40,6 @@ pub fn build_modules(config: ModuleConfig, _server: ArcFlowyServer) -> Vec<Modul
vec![
flowy_user::module::create(user_session),
flowy_workspace::module::create(workspace_user_impl, workspace_db),
flowy_editor::module::create(editor_db, editor_user),
flowy_document::module::create(editor_db, editor_user),
]
}

View File

@ -7,11 +7,11 @@ use std::{convert::TryInto, sync::Arc};
pub async fn sign_in(
data: Data<SignInRequest>,
session: Unit<Arc<UserSession>>,
) -> ResponseResult<UserDetail, UserError> {
) -> DataResult<UserDetail, UserError> {
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<SignUpRequest>,
session: Unit<Arc<UserSession>>,
) -> ResponseResult<UserDetail, UserError> {
) -> DataResult<UserDetail, UserError> {
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)
}

View File

@ -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<Arc<UserSession>>,
) -> ResponseResult<UserDetail, UserError> {
pub async fn get_user_status(session: Unit<Arc<UserSession>>) -> DataResult<UserDetail, UserError> {
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<Arc<UserSession>>) -> Result<(), UserError>
pub async fn update_user(
data: Data<UpdateUserRequest>,
session: Unit<Arc<UserSession>>,
) -> ResponseResult<UserDetail, UserError> {
) -> DataResult<UserDetail, UserError> {
let params: UpdateUserParams = data.into_inner().try_into()?;
let user_detail = session.update_user(params)?;
response_ok(user_detail)
data_result(user_detail)
}

View File

@ -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<CreateAppRequest>,
controller: Unit<Arc<AppController>>,
) -> ResponseResult<App, WorkspaceError> {
) -> DataResult<App, WorkspaceError> {
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<QueryAppRequest>,
app_controller: Unit<Arc<AppController>>,
view_controller: Unit<Arc<ViewController>>,
) -> ResponseResult<App, WorkspaceError> {
) -> DataResult<App, WorkspaceError> {
let params: QueryAppParams = data.into_inner().try_into()?;
let mut app = app_controller
.read_app(&params.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(&params.app_id).await?;
app.belongings = RepeatedView { items: views };
}
response_ok(app)
data_result(app)
}

View File

@ -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<CreateViewRequest>,
controller: Unit<Arc<ViewController>>,
) -> ResponseResult<View, WorkspaceError> {
) -> DataResult<View, WorkspaceError> {
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<QueryViewRequest>,
controller: Unit<Arc<ViewController>>,
) -> ResponseResult<View, WorkspaceError> {
) -> DataResult<View, WorkspaceError> {
let params: QueryViewParams = data.into_inner().try_into()?;
let mut view = controller
.read_view(&params.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))]

View File

@ -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<CreateWorkspaceRequest>,
controller: Unit<Arc<WorkspaceController>>,
) -> ResponseResult<Workspace, WorkspaceError> {
) -> DataResult<Workspace, WorkspaceError> {
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<Arc<WorkspaceController>>,
) -> ResponseResult<Workspace, WorkspaceError> {
) -> DataResult<Workspace, WorkspaceError> {
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<QueryWorkspaceRequest>,
controller: Unit<Arc<WorkspaceController>>,
) -> ResponseResult<Workspace, WorkspaceError> {
) -> DataResult<Workspace, WorkspaceError> {
let params: QueryWorkspaceParams = data.into_inner().try_into()?;
let mut workspace = controller.read_workspace(&params.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<Arc<WorkspaceController>>,
) -> ResponseResult<Workspaces, WorkspaceError> {
) -> DataResult<Workspaces, WorkspaceError> {
let workspaces = controller.read_workspaces_belong_to_user().await?;
response_ok(Workspaces { items: workspaces })
data_result(Workspaces { items: workspaces })
}

View File

@ -1,8 +1,5 @@
use crate::{
entities::{
app::{App, CreateAppParams, *},
view::View,
},
entities::app::{App, CreateAppParams, *},
errors::*,
module::{WorkspaceDatabase, WorkspaceUser},
observable::*,

View File

@ -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::*,

View File

@ -1,7 +1,7 @@
use crate::helper::*;
use flowy_workspace::entities::{
app::{QueryAppRequest, UpdateAppParams, UpdateAppRequest},
app::{QueryAppRequest, UpdateAppRequest},
view::*,
};