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 ee9cd8a9b6..8e97c8ac11 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart @@ -2,34 +2,12 @@ /// Auto gen code from rust ast, do not edit part of 'dispatch.dart'; -class UserEventAuthCheck { - UserSignInParams params; - UserEventAuthCheck(this.params); - - Future> send() { - return paramsToBytes(params).fold( - (bytes) { - final request = FFIRequest.create() - ..event = UserEvent.AuthCheck.toString() - ..payload = bytes; - - return Dispatch.asyncRequest(request) - .then((bytesResult) => bytesResult.fold( - (bytes) => left(UserSignInResult.fromBuffer(bytes)), - (error) => right(error), - )); - }, - (err) => Future(() => right(err)), - ); - } -} - class UserEventSignIn { - UserSignInParams params; - UserEventSignIn(this.params); + SignInRequest request; + UserEventSignIn(this.request); - Future> send() { - return paramsToBytes(params).fold( + Future> send() { + return requestToBytes(request).fold( (bytes) { final request = FFIRequest.create() ..event = UserEvent.SignIn.toString() @@ -37,7 +15,29 @@ class UserEventSignIn { return Dispatch.asyncRequest(request) .then((bytesResult) => bytesResult.fold( - (bytes) => left(UserSignInResult.fromBuffer(bytes)), + (bytes) => left(SignInResponse.fromBuffer(bytes)), + (error) => right(error), + )); + }, + (err) => Future(() => right(err)), + ); + } +} + +class UserEventSignUp { + SignUpRequest request; + UserEventSignUp(this.request); + + Future> send() { + return requestToBytes(request).fold( + (bytes) { + final request = FFIRequest.create() + ..event = UserEvent.SignUp.toString() + ..payload = bytes; + + return Dispatch.asyncRequest(request) + .then((bytesResult) => bytesResult.fold( + (bytes) => left(SignUpResponse.fromBuffer(bytes)), (error) => right(error), )); }, diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart index 4b44ab4676..9b16bca55f 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart @@ -86,7 +86,7 @@ Completer _sendToRust(FFIRequest request) { return completer; } -Either paramsToBytes( +Either requestToBytes( T? message) { try { if (message != null) { diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pb.dart index 4d1b7c4be4..c5bd9b5976 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pb.dart @@ -9,15 +9,15 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class UserSignInParams extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserSignInParams', createEmptyInstance: create) +class SignInRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignInRequest', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'password') ..hasRequiredFields = false ; - UserSignInParams._() : super(); - factory UserSignInParams({ + SignInRequest._() : super(); + factory SignInRequest({ $core.String? email, $core.String? password, }) { @@ -30,26 +30,26 @@ class UserSignInParams extends $pb.GeneratedMessage { } return _result; } - factory UserSignInParams.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserSignInParams.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SignInRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SignInRequest.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') - UserSignInParams clone() => UserSignInParams()..mergeFromMessage(this); + SignInRequest clone() => SignInRequest()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserSignInParams copyWith(void Function(UserSignInParams) updates) => super.copyWith((message) => updates(message as UserSignInParams)) as UserSignInParams; // ignore: deprecated_member_use + SignInRequest copyWith(void Function(SignInRequest) updates) => super.copyWith((message) => updates(message as SignInRequest)) as SignInRequest; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserSignInParams create() => UserSignInParams._(); - UserSignInParams createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SignInRequest create() => SignInRequest._(); + SignInRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserSignInParams getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserSignInParams? _defaultInstance; + static SignInRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SignInRequest? _defaultInstance; @$pb.TagNumber(1) $core.String get email => $_getSZ(0); @@ -70,15 +70,15 @@ class UserSignInParams extends $pb.GeneratedMessage { void clearPassword() => clearField(2); } -class UserSignInRequest extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserSignInRequest', createEmptyInstance: create) +class SignInParams extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignInParams', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'password') ..hasRequiredFields = false ; - UserSignInRequest._() : super(); - factory UserSignInRequest({ + SignInParams._() : super(); + factory SignInParams({ $core.String? email, $core.String? password, }) { @@ -91,26 +91,26 @@ class UserSignInRequest extends $pb.GeneratedMessage { } return _result; } - factory UserSignInRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserSignInRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SignInParams.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SignInParams.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') - UserSignInRequest clone() => UserSignInRequest()..mergeFromMessage(this); + SignInParams clone() => SignInParams()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserSignInRequest copyWith(void Function(UserSignInRequest) updates) => super.copyWith((message) => updates(message as UserSignInRequest)) as UserSignInRequest; // ignore: deprecated_member_use + SignInParams copyWith(void Function(SignInParams) updates) => super.copyWith((message) => updates(message as SignInParams)) as SignInParams; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserSignInRequest create() => UserSignInRequest._(); - UserSignInRequest createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SignInParams create() => SignInParams._(); + SignInParams createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserSignInRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserSignInRequest? _defaultInstance; + static SignInParams getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SignInParams? _defaultInstance; @$pb.TagNumber(1) $core.String get email => $_getSZ(0); @@ -131,14 +131,14 @@ class UserSignInRequest extends $pb.GeneratedMessage { void clearPassword() => clearField(2); } -class UserSignInResult extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserSignInResult', createEmptyInstance: create) +class SignInResponse extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignInResponse', createEmptyInstance: create) ..aOB(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'isSuccess') ..hasRequiredFields = false ; - UserSignInResult._() : super(); - factory UserSignInResult({ + SignInResponse._() : super(); + factory SignInResponse({ $core.bool? isSuccess, }) { final _result = create(); @@ -147,26 +147,26 @@ class UserSignInResult extends $pb.GeneratedMessage { } return _result; } - factory UserSignInResult.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserSignInResult.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SignInResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SignInResponse.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') - UserSignInResult clone() => UserSignInResult()..mergeFromMessage(this); + SignInResponse clone() => SignInResponse()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserSignInResult copyWith(void Function(UserSignInResult) updates) => super.copyWith((message) => updates(message as UserSignInResult)) as UserSignInResult; // ignore: deprecated_member_use + SignInResponse copyWith(void Function(SignInResponse) updates) => super.copyWith((message) => updates(message as SignInResponse)) as SignInResponse; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserSignInResult create() => UserSignInResult._(); - UserSignInResult createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SignInResponse create() => SignInResponse._(); + SignInResponse createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserSignInResult getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserSignInResult? _defaultInstance; + static SignInResponse getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SignInResponse? _defaultInstance; @$pb.TagNumber(1) $core.bool get isSuccess => $_getBF(0); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pbjson.dart index 6e92d43e01..4f0c79b2b9 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_in.pbjson.dart @@ -6,24 +6,24 @@ // 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 import 'dart:core' as $core; -const UserSignInParams$json = const { - '1': 'UserSignInParams', +const SignInRequest$json = const { + '1': 'SignInRequest', '2': const [ const {'1': 'email', '3': 1, '4': 1, '5': 9, '10': 'email'}, const {'1': 'password', '3': 2, '4': 1, '5': 9, '10': 'password'}, ], }; -const UserSignInRequest$json = const { - '1': 'UserSignInRequest', +const SignInParams$json = const { + '1': 'SignInParams', '2': const [ const {'1': 'email', '3': 1, '4': 1, '5': 9, '10': 'email'}, const {'1': 'password', '3': 2, '4': 1, '5': 9, '10': 'password'}, ], }; -const UserSignInResult$json = const { - '1': 'UserSignInResult', +const SignInResponse$json = const { + '1': 'SignInResponse', '2': const [ const {'1': 'is_success', '3': 1, '4': 1, '5': 8, '10': 'isSuccess'}, ], diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pb.dart index c39155074c..5eae8d834a 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pb.dart @@ -9,16 +9,16 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class UserSignUpParams extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserSignUpParams', createEmptyInstance: create) +class SignUpRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignUpRequest', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'password') ..hasRequiredFields = false ; - UserSignUpParams._() : super(); - factory UserSignUpParams({ + SignUpRequest._() : super(); + factory SignUpRequest({ $core.String? email, $core.String? name, $core.String? password, @@ -35,26 +35,26 @@ class UserSignUpParams extends $pb.GeneratedMessage { } return _result; } - factory UserSignUpParams.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserSignUpParams.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SignUpRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SignUpRequest.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') - UserSignUpParams clone() => UserSignUpParams()..mergeFromMessage(this); + SignUpRequest clone() => SignUpRequest()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserSignUpParams copyWith(void Function(UserSignUpParams) updates) => super.copyWith((message) => updates(message as UserSignUpParams)) as UserSignUpParams; // ignore: deprecated_member_use + SignUpRequest copyWith(void Function(SignUpRequest) updates) => super.copyWith((message) => updates(message as SignUpRequest)) as SignUpRequest; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserSignUpParams create() => UserSignUpParams._(); - UserSignUpParams createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SignUpRequest create() => SignUpRequest._(); + SignUpRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserSignUpParams getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserSignUpParams? _defaultInstance; + static SignUpRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SignUpRequest? _defaultInstance; @$pb.TagNumber(1) $core.String get email => $_getSZ(0); @@ -84,16 +84,16 @@ class UserSignUpParams extends $pb.GeneratedMessage { void clearPassword() => clearField(3); } -class UserSignUpRequest extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserSignUpRequest', createEmptyInstance: create) +class SignUpParams extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignUpParams', createEmptyInstance: create) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'password') ..hasRequiredFields = false ; - UserSignUpRequest._() : super(); - factory UserSignUpRequest({ + SignUpParams._() : super(); + factory SignUpParams({ $core.String? email, $core.String? name, $core.String? password, @@ -110,26 +110,26 @@ class UserSignUpRequest extends $pb.GeneratedMessage { } return _result; } - factory UserSignUpRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserSignUpRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SignUpParams.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SignUpParams.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') - UserSignUpRequest clone() => UserSignUpRequest()..mergeFromMessage(this); + SignUpParams clone() => SignUpParams()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserSignUpRequest copyWith(void Function(UserSignUpRequest) updates) => super.copyWith((message) => updates(message as UserSignUpRequest)) as UserSignUpRequest; // ignore: deprecated_member_use + SignUpParams copyWith(void Function(SignUpParams) updates) => super.copyWith((message) => updates(message as SignUpParams)) as SignUpParams; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserSignUpRequest create() => UserSignUpRequest._(); - UserSignUpRequest createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SignUpParams create() => SignUpParams._(); + SignUpParams createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserSignUpRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserSignUpRequest? _defaultInstance; + static SignUpParams getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SignUpParams? _defaultInstance; @$pb.TagNumber(1) $core.String get email => $_getSZ(0); @@ -159,14 +159,14 @@ class UserSignUpRequest extends $pb.GeneratedMessage { void clearPassword() => clearField(3); } -class UserSignUpResult extends $pb.GeneratedMessage { - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserSignUpResult', createEmptyInstance: create) +class SignUpResponse extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignUpResponse', createEmptyInstance: create) ..aOB(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'isSuccess') ..hasRequiredFields = false ; - UserSignUpResult._() : super(); - factory UserSignUpResult({ + SignUpResponse._() : super(); + factory SignUpResponse({ $core.bool? isSuccess, }) { final _result = create(); @@ -175,26 +175,26 @@ class UserSignUpResult extends $pb.GeneratedMessage { } return _result; } - factory UserSignUpResult.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory UserSignUpResult.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SignUpResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SignUpResponse.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') - UserSignUpResult clone() => UserSignUpResult()..mergeFromMessage(this); + SignUpResponse clone() => SignUpResponse()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - UserSignUpResult copyWith(void Function(UserSignUpResult) updates) => super.copyWith((message) => updates(message as UserSignUpResult)) as UserSignUpResult; // ignore: deprecated_member_use + SignUpResponse copyWith(void Function(SignUpResponse) updates) => super.copyWith((message) => updates(message as SignUpResponse)) as SignUpResponse; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static UserSignUpResult create() => UserSignUpResult._(); - UserSignUpResult createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SignUpResponse create() => SignUpResponse._(); + SignUpResponse createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static UserSignUpResult getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static UserSignUpResult? _defaultInstance; + static SignUpResponse getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SignUpResponse? _defaultInstance; @$pb.TagNumber(1) $core.bool get isSuccess => $_getBF(0); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pbjson.dart index b9b811fc83..290748e6da 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/sign_up.pbjson.dart @@ -6,8 +6,8 @@ // 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 import 'dart:core' as $core; -const UserSignUpParams$json = const { - '1': 'UserSignUpParams', +const SignUpRequest$json = const { + '1': 'SignUpRequest', '2': const [ const {'1': 'email', '3': 1, '4': 1, '5': 9, '10': 'email'}, const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, @@ -15,8 +15,8 @@ const UserSignUpParams$json = const { ], }; -const UserSignUpRequest$json = const { - '1': 'UserSignUpRequest', +const SignUpParams$json = const { + '1': 'SignUpParams', '2': const [ const {'1': 'email', '3': 1, '4': 1, '5': 9, '10': 'email'}, const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, @@ -24,8 +24,8 @@ const UserSignUpRequest$json = const { ], }; -const UserSignUpResult$json = const { - '1': 'UserSignUpResult', +const SignUpResponse$json = const { + '1': 'SignUpResponse', '2': const [ const {'1': 'is_success', '3': 1, '4': 1, '5': 8, '10': 'isSuccess'}, ], diff --git a/doc/APPFLOWY_SYSTEM_DESIGN.md b/doc/APPFLOWY_SYSTEM_DESIGN.md index e99cb9690c..9ef6760fdc 100644 --- a/doc/APPFLOWY_SYSTEM_DESIGN.md +++ b/doc/APPFLOWY_SYSTEM_DESIGN.md @@ -52,6 +52,10 @@ Here are the event flow: The event flow will be discussed in two parts: the frontend implemented in flutter and the FlowySDK implemented in Rust. +#### FlowySDK + + + #### Frontend The Frontend follows the DDD design pattern, you can recap from [**here**](DOMAIN_DRIVEN_DESIGN.md). ``` @@ -66,6 +70,4 @@ The Frontend follows the DDD design pattern, you can recap from [**here**](DOMAI └──────────────┘ ``` -#### FlowySDK - diff --git a/rust-lib/dart-ffi/src/lib.rs b/rust-lib/dart-ffi/src/lib.rs index 08273a60ae..57878432e9 100644 --- a/rust-lib/dart-ffi/src/lib.rs +++ b/rust-lib/dart-ffi/src/lib.rs @@ -25,6 +25,8 @@ pub extern "C" fn init_sdk(path: *mut c_char) -> i64 { let c_str: &CStr = unsafe { CStr::from_ptr(path) }; let path: &str = c_str.to_str().unwrap(); FlowySDK::init_log(path); + + log::info!("🔥 FlowySDK start running"); FlowySDK::init(path); return 1; } diff --git a/rust-lib/flowy-ast/src/attr.rs b/rust-lib/flowy-ast/src/attr.rs index 8dc7e393dd..48634d2272 100644 --- a/rust-lib/flowy-ast/src/attr.rs +++ b/rust-lib/flowy-ast/src/attr.rs @@ -135,6 +135,7 @@ impl<'c, T> ASTAttr<'c, T> { } pub struct ASTAttrField { + #[allow(dead_code)] name: String, pb_index: Option, pb_one_of: bool, 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 6dcb51649a..d4adf32546 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -18,15 +18,14 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "FFIRequest" | "FFIResponse" | "User" - | "UserSignUpParams" - | "UserSignUpRequest" - | "UserSignUpResult" - | "UserSignInParams" - | "UserSignInRequest" - | "UserSignInResult" + | "SignUpRequest" + | "SignUpParams" + | "SignUpResponse" + | "SignInRequest" + | "SignInParams" + | "SignInResponse" => TypeCategory::Protobuf, "FFIStatusCode" - | "UserEvent" => TypeCategory::Enum, "Option" => TypeCategory::Opt, diff --git a/rust-lib/flowy-dispatch/src/data.rs b/rust-lib/flowy-dispatch/src/data.rs index 2294b04224..961caec70c 100644 --- a/rust-lib/flowy-dispatch/src/data.rs +++ b/rust-lib/flowy-dispatch/src/data.rs @@ -111,7 +111,7 @@ where T: FromBytes, { match payload { - Payload::None => Err(format!("Expected payload")), + Payload::None => Err(format!("Parse fail, expected payload")), Payload::Bytes(bytes) => match T::parse_from_bytes(&bytes) { Ok(data) => Ok(Data(data)), Err(e) => Err(e), diff --git a/rust-lib/flowy-dispatch/src/dispatch.rs b/rust-lib/flowy-dispatch/src/dispatch.rs index 48dd0da420..40985ab726 100644 --- a/rust-lib/flowy-dispatch/src/dispatch.rs +++ b/rust-lib/flowy-dispatch/src/dispatch.rs @@ -35,7 +35,6 @@ impl EventDispatch { module_map, runtime, }; - *(EVENT_DISPATCH.write().unwrap()) = Some(dispatch); } @@ -65,7 +64,7 @@ impl EventDispatch { DispatchFuture { fut: Box::pin(async move { join_handle.await.unwrap_or_else(|e| { - InternalError::new(format!("Dispatch join error: {:?}", e)) + InternalError::new(format!("EVENT_DISPATCH join error: {:?}", e)) .as_response() }) }), diff --git a/rust-lib/flowy-dispatch/src/module/module.rs b/rust-lib/flowy-dispatch/src/module/module.rs index 3736c27608..30152e2c0e 100644 --- a/rust-lib/flowy-dispatch/src/module/module.rs +++ b/rust-lib/flowy-dispatch/src/module/module.rs @@ -55,7 +55,7 @@ pub type EventServiceFactory = BoxServiceFactory<(), ServiceRequest, ServiceResp pub struct Module { pub name: String, - data: DataContainer, + module_data: DataContainer, service_map: Arc>, } @@ -63,7 +63,7 @@ impl Module { pub fn new() -> Self { Self { name: "".to_owned(), - data: DataContainer::new(), + module_data: DataContainer::new(), service_map: Arc::new(HashMap::new()), } } @@ -74,7 +74,7 @@ impl Module { } pub fn data(mut self, data: D) -> Self { - self.data.insert(ModuleData::new(data)); + self.module_data.insert(ModuleData::new(data)); self } diff --git a/rust-lib/flowy-dispatch/src/request/payload.rs b/rust-lib/flowy-dispatch/src/request/payload.rs index 318897f669..9145a0a845 100644 --- a/rust-lib/flowy-dispatch/src/request/payload.rs +++ b/rust-lib/flowy-dispatch/src/request/payload.rs @@ -4,18 +4,24 @@ use std::{fmt, fmt::Formatter}; pub enum PayloadError {} // TODO: support stream data -#[derive(Clone, Debug, serde::Serialize)] +#[derive(Clone, serde::Serialize)] pub enum Payload { None, Bytes(Vec), } +impl std::fmt::Debug for Payload { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { format_payload_print(self, f) } +} + impl std::fmt::Display for Payload { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - Payload::Bytes(bytes) => f.write_fmt(format_args!("{} bytes", bytes.len())), - Payload::None => f.write_str("Empty"), - } + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { format_payload_print(self, f) } +} + +fn format_payload_print(payload: &Payload, f: &mut Formatter<'_>) -> fmt::Result { + match payload { + Payload::Bytes(bytes) => f.write_fmt(format_args!("{} bytes", bytes.len())), + Payload::None => f.write_str("Empty"), } } diff --git a/rust-lib/flowy-dispatch/src/response/response.rs b/rust-lib/flowy-dispatch/src/response/response.rs index c3c9a2e035..f245026bf4 100644 --- a/rust-lib/flowy-dispatch/src/response/response.rs +++ b/rust-lib/flowy-dispatch/src/response/response.rs @@ -4,6 +4,7 @@ use crate::{ request::{EventRequest, Payload}, response::Responder, }; +use derivative::*; use std::{fmt, fmt::Formatter}; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] @@ -13,8 +14,9 @@ pub enum StatusCode { } // serde user guide: https://serde.rs/field-attrs.html -#[derive(Debug, Clone, serde::Serialize)] +#[derive(Debug, Clone, serde::Serialize, Derivative)] pub struct EventResponse { + #[derivative(Debug = "ignore")] pub payload: Payload, pub status_code: StatusCode, pub error: Option, diff --git a/rust-lib/flowy-dispatch/src/system.rs b/rust-lib/flowy-dispatch/src/system.rs index ae395c0a0e..be224ff497 100644 --- a/rust-lib/flowy-dispatch/src/system.rs +++ b/rust-lib/flowy-dispatch/src/system.rs @@ -14,6 +14,7 @@ thread_local!( ); #[derive(Debug)] +#[allow(dead_code)] pub enum SystemCommand { Exit(i8), } @@ -23,6 +24,7 @@ pub struct FlowySystem { } impl FlowySystem { + #[allow(dead_code)] pub fn construct(module_factory: F, sender_factory: S) -> SystemRunner where F: FnOnce() -> Vec, @@ -49,6 +51,7 @@ impl FlowySystem { runner } + #[allow(dead_code)] pub fn stop(&self) { match self.sys_cmd_tx.send(SystemCommand::Exit(0)) { Ok(_) => {}, @@ -58,13 +61,14 @@ impl FlowySystem { } } - #[doc(hidden)] + #[allow(dead_code)] pub fn set_current(sys: FlowySystem) { CURRENT.with(|cell| { *cell.borrow_mut() = Some(Arc::new(sys)); }) } + #[allow(dead_code)] pub fn current() -> Arc { CURRENT.with(|cell| match *cell.borrow() { Some(ref sys) => sys.clone(), @@ -102,6 +106,7 @@ pub struct SystemRunner { } impl SystemRunner { + #[allow(dead_code)] pub fn run(self) -> io::Result<()> { let SystemRunner { rt, stop_rx } = self; match rt.block_on(stop_rx) { @@ -119,6 +124,7 @@ impl SystemRunner { } } + #[allow(dead_code)] pub fn spawn + 'static>(self, future: F) -> Self { self.rt.spawn(future); self @@ -135,6 +141,7 @@ pub struct Runtime { } impl Runtime { + #[allow(dead_code)] pub fn new() -> io::Result { let rt = tokio_default_runtime()?; Ok(Runtime { @@ -143,6 +150,7 @@ impl Runtime { }) } + #[allow(dead_code)] pub fn spawn(&self, future: F) -> &Self where F: Future + 'static, @@ -151,6 +159,7 @@ impl Runtime { self } + #[allow(dead_code)] pub fn block_on(&self, f: F) -> F::Output where F: Future + 'static, diff --git a/rust-lib/flowy-sdk/Cargo.toml b/rust-lib/flowy-sdk/Cargo.toml index 088b0effdd..19dec54f42 100644 --- a/rust-lib/flowy-sdk/Cargo.toml +++ b/rust-lib/flowy-sdk/Cargo.toml @@ -7,7 +7,8 @@ edition = "2018" [dependencies] flowy-dispatch = { path = "../flowy-dispatch", features = ["use_tracing"]} -flowy-log = { path = "../flowy-log", features = ["use_bunyan"] } +flowy-log = { path = "../flowy-log" } +#flowy-log = { path = "../flowy-log", features = ["use_bunyan"] } flowy-user = { path = "../flowy-user" } tracing = { version = "0.1" } log = "0.4.14" diff --git a/rust-lib/flowy-sdk/src/lib.rs b/rust-lib/flowy-sdk/src/lib.rs index a78266abb7..4359ea3360 100644 --- a/rust-lib/flowy-sdk/src/lib.rs +++ b/rust-lib/flowy-sdk/src/lib.rs @@ -9,8 +9,7 @@ impl FlowySDK { pub fn init_log(directory: &str) { flowy_log::init_log("flowy", directory, "Debug").unwrap(); } pub fn init(path: &str) { - log::info!("🔥 Start running"); - tracing::info!("🔥 Root path: {}", path); + tracing::trace!("🔥 Root path: {}", path); EventDispatch::construct(|| build_modules()); } } diff --git a/rust-lib/flowy-test/Cargo.toml b/rust-lib/flowy-test/Cargo.toml index 0fc9680290..0fe8ec51e8 100644 --- a/rust-lib/flowy-test/Cargo.toml +++ b/rust-lib/flowy-test/Cargo.toml @@ -14,4 +14,6 @@ bincode = { version = "1.3"} protobuf = {version = "2.24.1"} claim = "0.5.0" tokio = { version = "1", features = ["full"]} -futures-util = "0.3.15" \ No newline at end of file +futures-util = "0.3.15" +thread-id = "3.3.0" +log = "0.4" \ No newline at end of file diff --git a/rust-lib/flowy-test/src/lib.rs b/rust-lib/flowy-test/src/lib.rs index 5a8fc4a637..afb7792245 100644 --- a/rust-lib/flowy-test/src/lib.rs +++ b/rust-lib/flowy-test/src/lib.rs @@ -7,6 +7,7 @@ use std::{ hash::Hash, path::PathBuf, sync::Once, + thread, }; pub mod prelude { @@ -21,8 +22,8 @@ pub fn init_sdk() { INIT.call_once(|| { FlowySDK::init_log(&root_dir); + FlowySDK::init(&root_dir); }); - FlowySDK::init(&root_dir); } fn root_dir() -> String { @@ -42,7 +43,7 @@ fn root_dir() -> String { } pub struct EventTester { - request: Option, + inner_request: Option, assert_status_code: Option, response: Option, } @@ -53,22 +54,26 @@ impl EventTester { E: Eq + Hash + Debug + Clone + Display, { init_sdk(); - let request = ModuleRequest::new(event); + log::trace!( + "{:?} thread started: thread_id= {}", + thread::current(), + thread_id::get() + ); Self { - request: Some(request), + inner_request: Some(ModuleRequest::new(event)), assert_status_code: None, response: None, } } - pub fn payload

(mut self, payload: P) -> Self + pub fn request

(mut self, request: P) -> Self where P: ToBytes, { - let mut request = self.request.take().unwrap(); - let bytes = payload.into_bytes().unwrap(); - request = request.payload(bytes); - self.request = Some(request); + let mut inner_request = self.inner_request.take().unwrap(); + let bytes = request.into_bytes().unwrap(); + inner_request = inner_request.payload(bytes); + self.inner_request = Some(inner_request); self } @@ -77,26 +82,25 @@ impl EventTester { self } + pub fn assert_error(mut self) -> Self { + self.assert_status_code = Some(StatusCode::Err); + self + } + #[allow(dead_code)] pub async fn async_send(mut self) -> Self { let resp = - EventDispatch::async_send(self.request.take().unwrap(), |_| Box::pin(async {})).await; + EventDispatch::async_send(self.inner_request.take().unwrap(), |_| Box::pin(async {})) + .await; - if let Some(ref status_code) = self.assert_status_code { - assert_eq!(&resp.status_code, status_code) - } - dbg!(&resp); + check(&resp, &self.assert_status_code); self.response = Some(resp); self } pub fn sync_send(mut self) -> Self { - let resp = EventDispatch::sync_send(self.request.take().unwrap()); - - if let Some(ref status_code) = self.assert_status_code { - assert_eq!(&resp.status_code, status_code) - } - dbg!(&resp); + let resp = EventDispatch::sync_send(self.inner_request.take().unwrap()); + check(&resp, &self.assert_status_code); self.response = Some(resp); self } @@ -109,3 +113,12 @@ impl EventTester { >::try_from(response.payload).unwrap().into_inner() } } + +fn check(response: &EventResponse, status_code: &Option) { + if let Some(ref status_code) = status_code { + if &response.status_code != status_code { + eprintln!("{:#?}", response); + } + assert_eq!(&response.status_code, status_code) + } +} diff --git a/rust-lib/flowy-user/Cargo.toml b/rust-lib/flowy-user/Cargo.toml index af5a7727d9..075b7d0f96 100644 --- a/rust-lib/flowy-user/Cargo.toml +++ b/rust-lib/flowy-user/Cargo.toml @@ -26,4 +26,6 @@ quickcheck = "0.9.2" quickcheck_macros = "0.9.1" fake = "~2.3.0" claim = "0.4.0" -flowy-test = { path = "../flowy-test" } \ No newline at end of file +flowy-test = { path = "../flowy-test" } +tokio = { version = "1", features = ["full"] } +futures = "0.3.15" \ No newline at end of file diff --git a/rust-lib/flowy-user/Flowy.toml b/rust-lib/flowy-user/Flowy.toml index dc3a6d5933..da6d936fbb 100644 --- a/rust-lib/flowy-user/Flowy.toml +++ b/rust-lib/flowy-user/Flowy.toml @@ -1,3 +1,3 @@ proto_crates = ["src/domain"] -event_files = ["src/domain/event.rs"] \ No newline at end of file +event_files = ["src/event.rs"] \ No newline at end of file diff --git a/rust-lib/flowy-user/src/domain/mod.rs b/rust-lib/flowy-user/src/domain/mod.rs index ea1ea98784..6f3bffb8ae 100644 --- a/rust-lib/flowy-user/src/domain/mod.rs +++ b/rust-lib/flowy-user/src/domain/mod.rs @@ -1,4 +1,3 @@ -pub mod event; -pub mod user; - pub use user::*; + +pub mod user; diff --git a/rust-lib/flowy-user/src/domain/user/sign_in.rs b/rust-lib/flowy-user/src/domain/user/sign_in.rs index 132a2cab95..8a92e8beb0 100644 --- a/rust-lib/flowy-user/src/domain/user/sign_in.rs +++ b/rust-lib/flowy-user/src/domain/user/sign_in.rs @@ -3,7 +3,7 @@ use flowy_derive::ProtoBuf; use std::convert::TryInto; #[derive(ProtoBuf, Default)] -pub struct UserSignInParams { +pub struct SignInRequest { #[pb(index = 1)] pub email: String, @@ -12,7 +12,7 @@ pub struct UserSignInParams { } #[derive(Default, ProtoBuf)] -pub struct UserSignInRequest { +pub struct SignInParams { #[pb(index = 1)] pub email: String, @@ -20,14 +20,14 @@ pub struct UserSignInRequest { pub password: String, } -impl TryInto for UserSignInParams { +impl TryInto for SignInRequest { type Error = String; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let email = UserEmail::parse(self.email)?; let password = UserPassword::parse(self.password)?; - Ok(UserSignInRequest { + Ok(SignInParams { email: email.0, password: password.0, }) @@ -35,11 +35,11 @@ impl TryInto for UserSignInParams { } #[derive(ProtoBuf, Default, Debug)] -pub struct UserSignInResult { +pub struct SignInResponse { #[pb(index = 1)] pub is_success: bool, } -impl UserSignInResult { +impl SignInResponse { pub fn new(is_success: bool) -> Self { Self { is_success } } } diff --git a/rust-lib/flowy-user/src/domain/user/sign_up.rs b/rust-lib/flowy-user/src/domain/user/sign_up.rs index d661d4e891..7463e510d6 100644 --- a/rust-lib/flowy-user/src/domain/user/sign_up.rs +++ b/rust-lib/flowy-user/src/domain/user/sign_up.rs @@ -3,7 +3,7 @@ use flowy_derive::ProtoBuf; use std::convert::TryInto; #[derive(ProtoBuf, Default)] -pub struct UserSignUpParams { +pub struct SignUpRequest { #[pb(index = 1)] pub email: String, @@ -13,14 +13,14 @@ pub struct UserSignUpParams { #[pb(index = 3)] pub password: String, } -impl TryInto for UserSignUpParams { +impl TryInto for SignUpRequest { type Error = String; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let email = UserEmail::parse(self.email)?; let name = UserName::parse(self.name)?; let password = UserPassword::parse(self.password)?; - Ok(UserSignUpRequest { + Ok(SignUpParams { email: email.0, name: name.0, password: password.0, @@ -29,7 +29,7 @@ impl TryInto for UserSignUpParams { } #[derive(ProtoBuf, Default)] -pub struct UserSignUpRequest { +pub struct SignUpParams { #[pb(index = 1)] pub email: String, @@ -40,12 +40,12 @@ pub struct UserSignUpRequest { pub password: String, } -#[derive(ProtoBuf, Default)] -pub struct UserSignUpResult { +#[derive(ProtoBuf, Debug, Default)] +pub struct SignUpResponse { #[pb(index = 1)] pub is_success: bool, } -impl UserSignUpResult { +impl SignUpResponse { pub fn new(is_success: bool) -> Self { Self { is_success } } } diff --git a/rust-lib/flowy-user/src/domain/event.rs b/rust-lib/flowy-user/src/event.rs similarity index 73% rename from rust-lib/flowy-user/src/domain/event.rs rename to rust-lib/flowy-user/src/event.rs index ee6f232219..5e11074c95 100644 --- a/rust-lib/flowy-user/src/domain/event.rs +++ b/rust-lib/flowy-user/src/event.rs @@ -4,12 +4,12 @@ use flowy_derive::{Flowy_Event, ProtoBuf_Enum}; #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] pub enum UserEvent { #[display(fmt = "AuthCheck")] - #[event(input = "UserSignInParams", output = "UserSignInResult")] AuthCheck = 0, - #[event(input = "UserSignInParams", output = "UserSignInResult")] #[display(fmt = "SignIn")] + #[event(input = "SignInRequest", output = "SignInResponse")] SignIn = 1, #[display(fmt = "SignUp")] + #[event(input = "SignUpRequest", output = "SignUpResponse")] SignUp = 2, #[display(fmt = "SignOut")] SignOut = 3, diff --git a/rust-lib/flowy-user/src/handlers/auth.rs b/rust-lib/flowy-user/src/handlers/auth.rs index c7d6231208..e2e3b99673 100644 --- a/rust-lib/flowy-user/src/handlers/auth.rs +++ b/rust-lib/flowy-user/src/handlers/auth.rs @@ -10,12 +10,10 @@ use std::convert::TryInto; email = %data.email, ) )] -pub async fn user_sign_in( - data: Data, -) -> ResponseResult { - let _request: UserSignInRequest = data.into_inner().try_into()?; - - let response = UserSignInResult::new(true); +pub async fn user_sign_in(data: Data) -> ResponseResult { + let _params: SignInParams = data.into_inner().try_into()?; + // TODO: user sign in + let response = SignInResponse::new(true); response_ok(response) } @@ -26,11 +24,10 @@ pub async fn user_sign_in( email = %data.email, ) )] -pub async fn user_sign_up( - data: Data, -) -> ResponseResult { - let _request: UserSignUpRequest = data.into_inner().try_into()?; +pub async fn user_sign_up(data: Data) -> ResponseResult { + let _params: SignUpParams = data.into_inner().try_into()?; + // TODO: user sign up - let response = UserSignUpResult::new(true); - response_ok(response) + let fake_resp = SignUpResponse::new(true); + response_ok(fake_resp) } diff --git a/rust-lib/flowy-user/src/lib.rs b/rust-lib/flowy-user/src/lib.rs index 365c3a4df5..dd59b9f92b 100644 --- a/rust-lib/flowy-user/src/lib.rs +++ b/rust-lib/flowy-user/src/lib.rs @@ -1,5 +1,6 @@ mod domain; mod error; +pub mod event; mod handlers; pub mod module; mod protobuf; diff --git a/rust-lib/flowy-user/src/module.rs b/rust-lib/flowy-user/src/module.rs index 94e53ec06f..eb0a8b0d62 100644 --- a/rust-lib/flowy-user/src/module.rs +++ b/rust-lib/flowy-user/src/module.rs @@ -1,6 +1,7 @@ -use crate::{domain::event::UserEvent, handlers::*}; use flowy_dispatch::prelude::*; +use crate::{event::UserEvent, handlers::*}; + pub fn create() -> Module { Module::new() .name("Flowy-User") diff --git a/rust-lib/flowy-user/src/protobuf/model/sign_in.rs b/rust-lib/flowy-user/src/protobuf/model/sign_in.rs index 00a9b956d1..af8b9e9928 100644 --- a/rust-lib/flowy-user/src/protobuf/model/sign_in.rs +++ b/rust-lib/flowy-user/src/protobuf/model/sign_in.rs @@ -24,7 +24,7 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] -pub struct UserSignInParams { +pub struct SignInRequest { // message fields pub email: ::std::string::String, pub password: ::std::string::String, @@ -33,14 +33,14 @@ pub struct UserSignInParams { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserSignInParams { - fn default() -> &'a UserSignInParams { - ::default_instance() +impl<'a> ::std::default::Default for &'a SignInRequest { + fn default() -> &'a SignInRequest { + ::default_instance() } } -impl UserSignInParams { - pub fn new() -> UserSignInParams { +impl SignInRequest { + pub fn new() -> SignInRequest { ::std::default::Default::default() } @@ -97,7 +97,7 @@ impl UserSignInParams { } } -impl ::protobuf::Message for UserSignInParams { +impl ::protobuf::Message for SignInRequest { fn is_initialized(&self) -> bool { true } @@ -172,8 +172,8 @@ impl ::protobuf::Message for UserSignInParams { Self::descriptor_static() } - fn new() -> UserSignInParams { - UserSignInParams::new() + fn new() -> SignInRequest { + SignInRequest::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -182,29 +182,29 @@ impl ::protobuf::Message for UserSignInParams { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "email", - |m: &UserSignInParams| { &m.email }, - |m: &mut UserSignInParams| { &mut m.email }, + |m: &SignInRequest| { &m.email }, + |m: &mut SignInRequest| { &mut m.email }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "password", - |m: &UserSignInParams| { &m.password }, - |m: &mut UserSignInParams| { &mut m.password }, + |m: &SignInRequest| { &m.password }, + |m: &mut SignInRequest| { &mut m.password }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserSignInParams", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SignInRequest", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserSignInParams { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserSignInParams::new) + fn default_instance() -> &'static SignInRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SignInRequest::new) } } -impl ::protobuf::Clear for UserSignInParams { +impl ::protobuf::Clear for SignInRequest { fn clear(&mut self) { self.email.clear(); self.password.clear(); @@ -212,20 +212,20 @@ impl ::protobuf::Clear for UserSignInParams { } } -impl ::std::fmt::Debug for UserSignInParams { +impl ::std::fmt::Debug for SignInRequest { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserSignInParams { +impl ::protobuf::reflect::ProtobufValue for SignInRequest { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct UserSignInRequest { +pub struct SignInParams { // message fields pub email: ::std::string::String, pub password: ::std::string::String, @@ -234,14 +234,14 @@ pub struct UserSignInRequest { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserSignInRequest { - fn default() -> &'a UserSignInRequest { - ::default_instance() +impl<'a> ::std::default::Default for &'a SignInParams { + fn default() -> &'a SignInParams { + ::default_instance() } } -impl UserSignInRequest { - pub fn new() -> UserSignInRequest { +impl SignInParams { + pub fn new() -> SignInParams { ::std::default::Default::default() } @@ -298,7 +298,7 @@ impl UserSignInRequest { } } -impl ::protobuf::Message for UserSignInRequest { +impl ::protobuf::Message for SignInParams { fn is_initialized(&self) -> bool { true } @@ -373,8 +373,8 @@ impl ::protobuf::Message for UserSignInRequest { Self::descriptor_static() } - fn new() -> UserSignInRequest { - UserSignInRequest::new() + fn new() -> SignInParams { + SignInParams::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -383,29 +383,29 @@ impl ::protobuf::Message for UserSignInRequest { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "email", - |m: &UserSignInRequest| { &m.email }, - |m: &mut UserSignInRequest| { &mut m.email }, + |m: &SignInParams| { &m.email }, + |m: &mut SignInParams| { &mut m.email }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "password", - |m: &UserSignInRequest| { &m.password }, - |m: &mut UserSignInRequest| { &mut m.password }, + |m: &SignInParams| { &m.password }, + |m: &mut SignInParams| { &mut m.password }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserSignInRequest", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SignInParams", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserSignInRequest { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserSignInRequest::new) + fn default_instance() -> &'static SignInParams { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SignInParams::new) } } -impl ::protobuf::Clear for UserSignInRequest { +impl ::protobuf::Clear for SignInParams { fn clear(&mut self) { self.email.clear(); self.password.clear(); @@ -413,20 +413,20 @@ impl ::protobuf::Clear for UserSignInRequest { } } -impl ::std::fmt::Debug for UserSignInRequest { +impl ::std::fmt::Debug for SignInParams { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserSignInRequest { +impl ::protobuf::reflect::ProtobufValue for SignInParams { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct UserSignInResult { +pub struct SignInResponse { // message fields pub is_success: bool, // special fields @@ -434,14 +434,14 @@ pub struct UserSignInResult { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserSignInResult { - fn default() -> &'a UserSignInResult { - ::default_instance() +impl<'a> ::std::default::Default for &'a SignInResponse { + fn default() -> &'a SignInResponse { + ::default_instance() } } -impl UserSignInResult { - pub fn new() -> UserSignInResult { +impl SignInResponse { + pub fn new() -> SignInResponse { ::std::default::Default::default() } @@ -461,7 +461,7 @@ impl UserSignInResult { } } -impl ::protobuf::Message for UserSignInResult { +impl ::protobuf::Message for SignInResponse { fn is_initialized(&self) -> bool { true } @@ -531,8 +531,8 @@ impl ::protobuf::Message for UserSignInResult { Self::descriptor_static() } - fn new() -> UserSignInResult { - UserSignInResult::new() + fn new() -> SignInResponse { + SignInResponse::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -541,66 +541,66 @@ impl ::protobuf::Message for UserSignInResult { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( "is_success", - |m: &UserSignInResult| { &m.is_success }, - |m: &mut UserSignInResult| { &mut m.is_success }, + |m: &SignInResponse| { &m.is_success }, + |m: &mut SignInResponse| { &mut m.is_success }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserSignInResult", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SignInResponse", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserSignInResult { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserSignInResult::new) + fn default_instance() -> &'static SignInResponse { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SignInResponse::new) } } -impl ::protobuf::Clear for UserSignInResult { +impl ::protobuf::Clear for SignInResponse { fn clear(&mut self) { self.is_success = false; self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for UserSignInResult { +impl ::std::fmt::Debug for SignInResponse { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserSignInResult { +impl ::protobuf::reflect::ProtobufValue for SignInResponse { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rsign_in.proto\"D\n\x10UserSignInParams\x12\x14\n\x05email\x18\x01\ - \x20\x01(\tR\x05email\x12\x1a\n\x08password\x18\x02\x20\x01(\tR\x08passw\ - ord\"E\n\x11UserSignInRequest\x12\x14\n\x05email\x18\x01\x20\x01(\tR\x05\ - email\x12\x1a\n\x08password\x18\x02\x20\x01(\tR\x08password\"1\n\x10User\ - SignInResult\x12\x1d\n\nis_success\x18\x01\x20\x01(\x08R\tisSuccessJ\xed\ - \x02\n\x06\x12\x04\0\0\x0c\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\ - \x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\ - \x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x15\n\x0c\n\x05\x04\0\x02\0\x05\ - \x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x10\n\x0c\ - \n\x05\x04\0\x02\0\x03\x12\x03\x03\x13\x14\n\x0b\n\x04\x04\0\x02\x01\x12\ - \x03\x04\x04\x18\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\x13\n\x0c\n\x05\x04\0\x02\x01\x03\ - \x12\x03\x04\x16\x17\n\n\n\x02\x04\x01\x12\x04\x06\0\t\x01\n\n\n\x03\x04\ - \x01\x01\x12\x03\x06\x08\x19\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x07\x04\ - \x15\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\x01\ - \x02\0\x01\x12\x03\x07\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x07\ - \x13\x14\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x08\x04\x18\n\x0c\n\x05\x04\ - \x01\x02\x01\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\ - \x03\x08\x0b\x13\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x08\x16\x17\n\n\ - \n\x02\x04\x02\x12\x04\n\0\x0c\x01\n\n\n\x03\x04\x02\x01\x12\x03\n\x08\ - \x18\n\x0b\n\x04\x04\x02\x02\0\x12\x03\x0b\x04\x18\n\x0c\n\x05\x04\x02\ - \x02\0\x05\x12\x03\x0b\x04\x08\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0b\ - \t\x13\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0b\x16\x17b\x06proto3\ + \n\rsign_in.proto\"A\n\rSignInRequest\x12\x14\n\x05email\x18\x01\x20\x01\ + (\tR\x05email\x12\x1a\n\x08password\x18\x02\x20\x01(\tR\x08password\"@\n\ + \x0cSignInParams\x12\x14\n\x05email\x18\x01\x20\x01(\tR\x05email\x12\x1a\ + \n\x08password\x18\x02\x20\x01(\tR\x08password\"/\n\x0eSignInResponse\ + \x12\x1d\n\nis_success\x18\x01\x20\x01(\x08R\tisSuccessJ\xed\x02\n\x06\ + \x12\x04\0\0\x0c\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\ + \x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x15\n\x0b\n\x04\ + \x04\0\x02\0\x12\x03\x03\x04\x15\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\ + \x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x10\n\x0c\n\x05\x04\0\ + \x02\0\x03\x12\x03\x03\x13\x14\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\ + \x18\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\x13\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ + \x04\x16\x17\n\n\n\x02\x04\x01\x12\x04\x06\0\t\x01\n\n\n\x03\x04\x01\x01\ + \x12\x03\x06\x08\x14\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x07\x04\x15\n\x0c\ + \n\x05\x04\x01\x02\0\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\ + \x12\x03\x07\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x07\x13\x14\n\ + \x0b\n\x04\x04\x01\x02\x01\x12\x03\x08\x04\x18\n\x0c\n\x05\x04\x01\x02\ + \x01\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x08\ + \x0b\x13\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x08\x16\x17\n\n\n\x02\ + \x04\x02\x12\x04\n\0\x0c\x01\n\n\n\x03\x04\x02\x01\x12\x03\n\x08\x16\n\ + \x0b\n\x04\x04\x02\x02\0\x12\x03\x0b\x04\x18\n\x0c\n\x05\x04\x02\x02\0\ + \x05\x12\x03\x0b\x04\x08\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0b\t\x13\ + \n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0b\x16\x17b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/model/sign_up.rs b/rust-lib/flowy-user/src/protobuf/model/sign_up.rs index 3c410314df..010e8c4e9b 100644 --- a/rust-lib/flowy-user/src/protobuf/model/sign_up.rs +++ b/rust-lib/flowy-user/src/protobuf/model/sign_up.rs @@ -24,7 +24,7 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] -pub struct UserSignUpParams { +pub struct SignUpRequest { // message fields pub email: ::std::string::String, pub name: ::std::string::String, @@ -34,14 +34,14 @@ pub struct UserSignUpParams { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserSignUpParams { - fn default() -> &'a UserSignUpParams { - ::default_instance() +impl<'a> ::std::default::Default for &'a SignUpRequest { + fn default() -> &'a SignUpRequest { + ::default_instance() } } -impl UserSignUpParams { - pub fn new() -> UserSignUpParams { +impl SignUpRequest { + pub fn new() -> SignUpRequest { ::std::default::Default::default() } @@ -124,7 +124,7 @@ impl UserSignUpParams { } } -impl ::protobuf::Message for UserSignUpParams { +impl ::protobuf::Message for SignUpRequest { fn is_initialized(&self) -> bool { true } @@ -208,8 +208,8 @@ impl ::protobuf::Message for UserSignUpParams { Self::descriptor_static() } - fn new() -> UserSignUpParams { - UserSignUpParams::new() + fn new() -> SignUpRequest { + SignUpRequest::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -218,34 +218,34 @@ impl ::protobuf::Message for UserSignUpParams { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "email", - |m: &UserSignUpParams| { &m.email }, - |m: &mut UserSignUpParams| { &mut m.email }, + |m: &SignUpRequest| { &m.email }, + |m: &mut SignUpRequest| { &mut m.email }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "name", - |m: &UserSignUpParams| { &m.name }, - |m: &mut UserSignUpParams| { &mut m.name }, + |m: &SignUpRequest| { &m.name }, + |m: &mut SignUpRequest| { &mut m.name }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "password", - |m: &UserSignUpParams| { &m.password }, - |m: &mut UserSignUpParams| { &mut m.password }, + |m: &SignUpRequest| { &m.password }, + |m: &mut SignUpRequest| { &mut m.password }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserSignUpParams", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SignUpRequest", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserSignUpParams { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserSignUpParams::new) + fn default_instance() -> &'static SignUpRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SignUpRequest::new) } } -impl ::protobuf::Clear for UserSignUpParams { +impl ::protobuf::Clear for SignUpRequest { fn clear(&mut self) { self.email.clear(); self.name.clear(); @@ -254,20 +254,20 @@ impl ::protobuf::Clear for UserSignUpParams { } } -impl ::std::fmt::Debug for UserSignUpParams { +impl ::std::fmt::Debug for SignUpRequest { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserSignUpParams { +impl ::protobuf::reflect::ProtobufValue for SignUpRequest { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct UserSignUpRequest { +pub struct SignUpParams { // message fields pub email: ::std::string::String, pub name: ::std::string::String, @@ -277,14 +277,14 @@ pub struct UserSignUpRequest { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserSignUpRequest { - fn default() -> &'a UserSignUpRequest { - ::default_instance() +impl<'a> ::std::default::Default for &'a SignUpParams { + fn default() -> &'a SignUpParams { + ::default_instance() } } -impl UserSignUpRequest { - pub fn new() -> UserSignUpRequest { +impl SignUpParams { + pub fn new() -> SignUpParams { ::std::default::Default::default() } @@ -367,7 +367,7 @@ impl UserSignUpRequest { } } -impl ::protobuf::Message for UserSignUpRequest { +impl ::protobuf::Message for SignUpParams { fn is_initialized(&self) -> bool { true } @@ -451,8 +451,8 @@ impl ::protobuf::Message for UserSignUpRequest { Self::descriptor_static() } - fn new() -> UserSignUpRequest { - UserSignUpRequest::new() + fn new() -> SignUpParams { + SignUpParams::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -461,34 +461,34 @@ impl ::protobuf::Message for UserSignUpRequest { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "email", - |m: &UserSignUpRequest| { &m.email }, - |m: &mut UserSignUpRequest| { &mut m.email }, + |m: &SignUpParams| { &m.email }, + |m: &mut SignUpParams| { &mut m.email }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "name", - |m: &UserSignUpRequest| { &m.name }, - |m: &mut UserSignUpRequest| { &mut m.name }, + |m: &SignUpParams| { &m.name }, + |m: &mut SignUpParams| { &mut m.name }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "password", - |m: &UserSignUpRequest| { &m.password }, - |m: &mut UserSignUpRequest| { &mut m.password }, + |m: &SignUpParams| { &m.password }, + |m: &mut SignUpParams| { &mut m.password }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserSignUpRequest", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SignUpParams", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserSignUpRequest { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserSignUpRequest::new) + fn default_instance() -> &'static SignUpParams { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SignUpParams::new) } } -impl ::protobuf::Clear for UserSignUpRequest { +impl ::protobuf::Clear for SignUpParams { fn clear(&mut self) { self.email.clear(); self.name.clear(); @@ -497,20 +497,20 @@ impl ::protobuf::Clear for UserSignUpRequest { } } -impl ::std::fmt::Debug for UserSignUpRequest { +impl ::std::fmt::Debug for SignUpParams { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserSignUpRequest { +impl ::protobuf::reflect::ProtobufValue for SignUpParams { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct UserSignUpResult { +pub struct SignUpResponse { // message fields pub is_success: bool, // special fields @@ -518,14 +518,14 @@ pub struct UserSignUpResult { pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a UserSignUpResult { - fn default() -> &'a UserSignUpResult { - ::default_instance() +impl<'a> ::std::default::Default for &'a SignUpResponse { + fn default() -> &'a SignUpResponse { + ::default_instance() } } -impl UserSignUpResult { - pub fn new() -> UserSignUpResult { +impl SignUpResponse { + pub fn new() -> SignUpResponse { ::std::default::Default::default() } @@ -545,7 +545,7 @@ impl UserSignUpResult { } } -impl ::protobuf::Message for UserSignUpResult { +impl ::protobuf::Message for SignUpResponse { fn is_initialized(&self) -> bool { true } @@ -615,8 +615,8 @@ impl ::protobuf::Message for UserSignUpResult { Self::descriptor_static() } - fn new() -> UserSignUpResult { - UserSignUpResult::new() + fn new() -> SignUpResponse { + SignUpResponse::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -625,73 +625,73 @@ impl ::protobuf::Message for UserSignUpResult { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( "is_success", - |m: &UserSignUpResult| { &m.is_success }, - |m: &mut UserSignUpResult| { &mut m.is_success }, + |m: &SignUpResponse| { &m.is_success }, + |m: &mut SignUpResponse| { &mut m.is_success }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "UserSignUpResult", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SignUpResponse", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static UserSignUpResult { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(UserSignUpResult::new) + fn default_instance() -> &'static SignUpResponse { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SignUpResponse::new) } } -impl ::protobuf::Clear for UserSignUpResult { +impl ::protobuf::Clear for SignUpResponse { fn clear(&mut self) { self.is_success = false; self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for UserSignUpResult { +impl ::std::fmt::Debug for SignUpResponse { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for UserSignUpResult { +impl ::protobuf::reflect::ProtobufValue for SignUpResponse { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rsign_up.proto\"X\n\x10UserSignUpParams\x12\x14\n\x05email\x18\x01\ - \x20\x01(\tR\x05email\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\ - \x1a\n\x08password\x18\x03\x20\x01(\tR\x08password\"Y\n\x11UserSignUpReq\ - uest\x12\x14\n\x05email\x18\x01\x20\x01(\tR\x05email\x12\x12\n\x04name\ - \x18\x02\x20\x01(\tR\x04name\x12\x1a\n\x08password\x18\x03\x20\x01(\tR\ - \x08password\"1\n\x10UserSignUpResult\x12\x1d\n\nis_success\x18\x01\x20\ - \x01(\x08R\tisSuccessJ\xdb\x03\n\x06\x12\x04\0\0\x0e\x01\n\x08\n\x01\x0c\ - \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\ - \x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x15\n\ - \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\ - \x12\x03\x03\x0b\x10\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x13\x14\n\ - \x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\ - \x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\ - \n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\ - \x02\x12\x03\x05\x04\x18\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\ - \n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\x13\n\x0c\n\x05\x04\0\x02\ - \x02\x03\x12\x03\x05\x16\x17\n\n\n\x02\x04\x01\x12\x04\x07\0\x0b\x01\n\n\ - \n\x03\x04\x01\x01\x12\x03\x07\x08\x19\n\x0b\n\x04\x04\x01\x02\0\x12\x03\ - \x08\x04\x15\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\ - \x04\x01\x02\0\x01\x12\x03\x08\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\ - \x03\x08\x13\x14\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\ - \x05\x04\x01\x02\x01\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\ - \x12\x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\ - \x0b\n\x04\x04\x01\x02\x02\x12\x03\n\x04\x18\n\x0c\n\x05\x04\x01\x02\x02\ - \x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x13\n\ - \x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\n\x16\x17\n\n\n\x02\x04\x02\x12\ - \x04\x0c\0\x0e\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0c\x08\x18\n\x0b\n\x04\ - \x04\x02\x02\0\x12\x03\r\x04\x18\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\ - \x04\x08\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\r\t\x13\n\x0c\n\x05\x04\ - \x02\x02\0\x03\x12\x03\r\x16\x17b\x06proto3\ + \n\rsign_up.proto\"U\n\rSignUpRequest\x12\x14\n\x05email\x18\x01\x20\x01\ + (\tR\x05email\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x1a\n\ + \x08password\x18\x03\x20\x01(\tR\x08password\"T\n\x0cSignUpParams\x12\ + \x14\n\x05email\x18\x01\x20\x01(\tR\x05email\x12\x12\n\x04name\x18\x02\ + \x20\x01(\tR\x04name\x12\x1a\n\x08password\x18\x03\x20\x01(\tR\x08passwo\ + rd\"/\n\x0eSignUpResponse\x12\x1d\n\nis_success\x18\x01\x20\x01(\x08R\ti\ + sSuccessJ\xdb\x03\n\x06\x12\x04\0\0\x0e\x01\n\x08\n\x01\x0c\x12\x03\0\0\ + \x12\n\n\n\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\ + \x02\x08\x15\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x15\n\x0c\n\x05\x04\ + \0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\ + \x0b\x10\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x13\x14\n\x0b\n\x04\x04\ + \0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\ + \x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\ + \0\x02\x01\x03\x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\ + \x04\x18\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\ + \0\x02\x02\x01\x12\x03\x05\x0b\x13\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\ + \x05\x16\x17\n\n\n\x02\x04\x01\x12\x04\x07\0\x0b\x01\n\n\n\x03\x04\x01\ + \x01\x12\x03\x07\x08\x14\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\x04\x15\n\ + \x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\0\ + \x01\x12\x03\x08\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x08\x13\ + \x14\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\x05\x04\x01\ + \x02\x01\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\t\ + \x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\x0b\n\x04\ + \x04\x01\x02\x02\x12\x03\n\x04\x18\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\ + \x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x13\n\x0c\n\ + \x05\x04\x01\x02\x02\x03\x12\x03\n\x16\x17\n\n\n\x02\x04\x02\x12\x04\x0c\ + \0\x0e\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0c\x08\x16\n\x0b\n\x04\x04\x02\ + \x02\0\x12\x03\r\x04\x18\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\x04\x08\ + \n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\r\t\x13\n\x0c\n\x05\x04\x02\x02\0\ + \x03\x12\x03\r\x16\x17b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/proto/sign_in.proto b/rust-lib/flowy-user/src/protobuf/proto/sign_in.proto index 91dc2b175c..a9fa4979c0 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/sign_in.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/sign_in.proto @@ -1,13 +1,13 @@ syntax = "proto3"; -message UserSignInParams { +message SignInRequest { string email = 1; string password = 2; } -message UserSignInRequest { +message SignInParams { string email = 1; string password = 2; } -message UserSignInResult { +message SignInResponse { bool is_success = 1; } diff --git a/rust-lib/flowy-user/src/protobuf/proto/sign_up.proto b/rust-lib/flowy-user/src/protobuf/proto/sign_up.proto index 6940c9ef61..f6a7666970 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/sign_up.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/sign_up.proto @@ -1,15 +1,15 @@ syntax = "proto3"; -message UserSignUpParams { +message SignUpRequest { string email = 1; string name = 2; string password = 3; } -message UserSignUpRequest { +message SignUpParams { string email = 1; string name = 2; string password = 3; } -message UserSignUpResult { +message SignUpResponse { bool is_success = 1; } diff --git a/rust-lib/flowy-user/tests/auth.rs b/rust-lib/flowy-user/tests/auth.rs new file mode 100644 index 0000000000..607138ef99 --- /dev/null +++ b/rust-lib/flowy-user/tests/auth.rs @@ -0,0 +1,132 @@ +use flowy_test::prelude::*; +use flowy_user::{event::UserEvent::*, prelude::*}; + +#[test] +fn sign_up_success() { + let request = SignUpRequest { + email: valid_email(), + name: valid_name(), + password: valid_password(), + }; + + let response = EventTester::new(SignUp) + .request(request) + .sync_send() + .parse::(); + dbg!(&response); +} + +#[test] +fn sign_in_success() { + let request = SignInRequest { + email: valid_email(), + password: valid_password(), + }; + + let response = EventTester::new(SignIn) + .request(request) + .sync_send() + .parse::(); + dbg!(&response); +} + +#[test] +fn sign_up_with_invalid_email() { + for email in invalid_email_test_case() { + let request = SignUpRequest { + email: email.to_string(), + name: valid_name(), + password: valid_password(), + }; + + let _ = EventTester::new(SignUp) + .request(request) + .assert_error() + .sync_send(); + } +} +#[test] +fn sign_up_with_invalid_password() { + for password in invalid_password_test_case() { + let request = SignUpRequest { + email: valid_email(), + name: valid_name(), + password, + }; + + let _ = EventTester::new(SignUp) + .request(request) + .assert_error() + .sync_send(); + } +} +#[test] +fn sign_in_with_invalid_email() { + for email in invalid_email_test_case() { + let request = SignInRequest { + email: email.to_string(), + password: valid_password(), + }; + + let _ = EventTester::new(SignIn) + .request(request) + .assert_error() + .sync_send(); + } +} + +#[test] +fn sign_in_with_invalid_password() { + for password in invalid_password_test_case() { + let request = SignInRequest { + email: valid_email(), + password, + }; + + let _ = EventTester::new(SignIn) + .request(request) + .assert_error() + .sync_send(); + } +} + +fn invalid_email_test_case() -> Vec { + // https://gist.github.com/cjaoude/fd9910626629b53c4d25 + vec![ + "", + "annie@", + "annie@gmail@", + "#@%^%#$@#$@#.com", + "@example.com", + "Joe Smith ", + "email.example.com", + "email@example@example.com", + "email@-example.com", + "email@example..com", + "あいうえお@example.com", + /* The following email is valid according to the validate_email function return + * ".email@example.com", + * "email.@example.com", + * "email..email@example.com", + * "email@example", + * "email@example.web", + * "email@111.222.333.44444", + * "Abc..123@example.com", */ + ] + .iter() + .map(|s| s.to_string()) + .collect::>() +} + +fn invalid_password_test_case() -> Vec { + vec!["", "123456", "1234".repeat(100).as_str()] + .iter() + .map(|s| s.to_string()) + .collect::>() +} + +fn valid_email() -> String { "annie@appflowy.io".to_string() } + +fn valid_password() -> String { "HelloWorld!123".to_string() } + +fn valid_name() -> String { "AppFlowy".to_string() } diff --git a/rust-lib/flowy-user/tests/main.rs b/rust-lib/flowy-user/tests/main.rs index 4aeca270a6..12bc9de49d 100644 --- a/rust-lib/flowy-user/tests/main.rs +++ b/rust-lib/flowy-user/tests/main.rs @@ -1 +1 @@ -mod sign_in; +mod auth; diff --git a/rust-lib/flowy-user/tests/sign_in.rs b/rust-lib/flowy-user/tests/sign_in.rs deleted file mode 100644 index 273918149a..0000000000 --- a/rust-lib/flowy-user/tests/sign_in.rs +++ /dev/null @@ -1,53 +0,0 @@ -use flowy_test::prelude::*; -use flowy_user::prelude::{event::UserEvent::*, *}; - -#[test] -fn sign_in_with_invalid_email() { - let test_cases = vec!["", "annie@", "annie@gmail@"]; - let password = "Appflowy!123".to_string(); - - for email in test_cases { - let params = UserSignInParams { - email: email.to_string(), - password: password.clone(), - }; - - let _ = EventTester::new(SignIn) - .payload(params) - .assert_status_code(StatusCode::Err) - .sync_send(); - } -} - -#[test] -fn sign_in_with_invalid_password() { - let test_cases = vec!["".to_string(), "123456".to_owned(), "1234".repeat(100)]; - let email = "annie@appflowy.io".to_string(); - - for password in test_cases { - let params = UserSignInParams { - email: email.clone(), - password, - }; - - let _ = EventTester::new(SignIn) - .payload(params) - .assert_status_code(StatusCode::Err) - .sync_send(); - } -} - -#[test] -fn sign_in_success() { - let params = UserSignInParams { - email: "annie@appflowy.io".to_string(), - password: "HelloWorld!123".to_string(), - }; - - let result = EventTester::new(SignIn) - .payload(params) - .assert_status_code(StatusCode::Ok) - .sync_send() - .parse::(); - dbg!(&result); -} diff --git a/scripts/flowy-tool/src/dart_event/event_template.tera b/scripts/flowy-tool/src/dart_event/event_template.tera index 43e5570e35..476b5e93ef 100644 --- a/scripts/flowy-tool/src/dart_event/event_template.tera +++ b/scripts/flowy-tool/src/dart_event/event_template.tera @@ -3,11 +3,11 @@ {%- endif -%} class {{ event_class }} { - {{ input_deserializer }} params; - {{ event_class }}(this.params); + {{ input_deserializer }} request; + {{ event_class }}(this.request); Future> send() { - return paramsToBytes(params).fold( + return requestToBytes(request).fold( (bytes) { final request = FFIRequest.create() ..event = {{ event }}.toString()