From 5de69abb36b1e075ffc232c902cb30cf4cf22ab7 Mon Sep 17 00:00:00 2001 From: appflowy Date: Tue, 13 Jul 2021 17:19:39 +0800 Subject: [PATCH] add workspace and app --- .../flowy-workspace/app_create.pb.dart | 149 +++++ .../flowy-workspace/app_create.pbenum.dart | 7 + .../flowy-workspace/app_create.pbjson.dart | 25 + .../flowy-workspace/app_create.pbserver.dart | 9 + .../protobuf/flowy-workspace/errors.pb.dart | 76 +++ .../flowy-workspace/errors.pbenum.dart | 32 ++ .../flowy-workspace/errors.pbjson.dart | 27 + .../flowy-workspace/errors.pbserver.dart | 9 + .../protobuf/flowy-workspace/protobuf.dart | 4 + .../flowy-workspace/workspace_create.pb.dart | 72 +++ .../workspace_create.pbenum.dart | 7 + .../workspace_create.pbjson.dart | 16 + .../workspace_create.pbserver.dart | 9 + .../flowy-workspace/workspace_update.pb.dart | 86 +++ .../workspace_update.pbenum.dart | 7 + .../workspace_update.pbjson.dart | 17 + .../workspace_update.pbserver.dart | 9 + .../down.sql | 4 + .../2021-07-13-063102_flowy-workspace/up.sql | 34 ++ rust-lib/flowy-database/src/schema.rs | 47 ++ .../src/derive_cache/derive_cache.rs | 8 +- rust-lib/flowy-infra/Cargo.toml | 3 +- rust-lib/flowy-infra/src/lib.rs | 1 + rust-lib/flowy-user/src/entities/sign_in.rs | 2 +- .../src/handlers/{auth.rs => auth_handler.rs} | 0 rust-lib/flowy-user/src/handlers/mod.rs | 4 +- rust-lib/flowy-user/src/lib.rs | 2 +- rust-lib/flowy-workspace/Cargo.toml | 8 +- rust-lib/flowy-workspace/Flowy.toml | 7 +- .../src/entities/app/app_color_style.rs | 15 + .../src/entities/app/app_create.rs | 68 +++ .../src/entities/app/app_name.rs | 16 + .../flowy-workspace/src/entities/app/mod.rs | 5 + rust-lib/flowy-workspace/src/entities/mod.rs | 2 + .../src/entities/workspace/mod.rs | 11 + .../entities/workspace/workspace_create.rs | 34 ++ .../src/entities/workspace/workspace_id.rs | 16 + .../src/entities/workspace/workspace_name.rs | 16 + .../src/entities/workspace/workspace_query.rs | 51 ++ .../entities/workspace/workspace_update.rs | 48 ++ rust-lib/flowy-workspace/src/errors.rs | 96 ++++ rust-lib/flowy-workspace/src/handlers/mod.rs | 3 + .../src/handlers/workspace_handler.rs | 1 + rust-lib/flowy-workspace/src/lib.rs | 8 + rust-lib/flowy-workspace/src/macros.rs | 66 +++ .../src/protobuf/model/app_create.rs | 520 ++++++++++++++++++ .../src/protobuf/model/errors.rs | 312 +++++++++++ .../flowy-workspace/src/protobuf/model/mod.rs | 12 + .../src/protobuf/model/workspace_create.rs | 250 +++++++++ .../src/protobuf/model/workspace_update.rs | 296 ++++++++++ .../src/protobuf/proto/app_create.proto | 11 + .../src/protobuf/proto/errors.proto | 13 + .../src/protobuf/proto/workspace_create.proto | 6 + .../src/protobuf/proto/workspace_update.proto | 7 + .../flowy-workspace/src/sql_tables/app/app.rs | 56 ++ .../flowy-workspace/src/sql_tables/app/mod.rs | 3 + .../flowy-workspace/src/sql_tables/mod.rs | 2 + .../src/sql_tables/workspace/mod.rs | 3 + .../src/sql_tables/workspace/workspace.rs | 63 +++ 59 files changed, 2678 insertions(+), 13 deletions(-) create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbenum.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbserver.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pb.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbserver.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbenum.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbserver.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pb.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbenum.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbjson.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbserver.dart create mode 100644 rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/down.sql create mode 100644 rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/up.sql rename rust-lib/flowy-user/src/handlers/{auth.rs => auth_handler.rs} (100%) create mode 100644 rust-lib/flowy-workspace/src/entities/app/app_color_style.rs create mode 100644 rust-lib/flowy-workspace/src/entities/app/app_create.rs create mode 100644 rust-lib/flowy-workspace/src/entities/app/app_name.rs create mode 100644 rust-lib/flowy-workspace/src/entities/app/mod.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/mod.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/workspace_id.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs create mode 100644 rust-lib/flowy-workspace/src/handlers/mod.rs create mode 100644 rust-lib/flowy-workspace/src/handlers/workspace_handler.rs create mode 100644 rust-lib/flowy-workspace/src/macros.rs create mode 100644 rust-lib/flowy-workspace/src/protobuf/model/app_create.rs create mode 100644 rust-lib/flowy-workspace/src/protobuf/model/errors.rs create mode 100644 rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs create mode 100644 rust-lib/flowy-workspace/src/protobuf/model/workspace_update.rs create mode 100644 rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto create mode 100644 rust-lib/flowy-workspace/src/protobuf/proto/errors.proto create mode 100644 rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto create mode 100644 rust-lib/flowy-workspace/src/protobuf/proto/workspace_update.proto create mode 100644 rust-lib/flowy-workspace/src/sql_tables/app/app.rs create mode 100644 rust-lib/flowy-workspace/src/sql_tables/app/mod.rs create mode 100644 rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs create mode 100644 rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart new file mode 100644 index 0000000000..bda773c373 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart @@ -0,0 +1,149 @@ +/// +// Generated code. Do not modify. +// source: app_create.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 + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class CreateAppRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateAppRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspaceId') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..aOM(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'colorStyle', subBuilder: ColorStyle.create) + ..hasRequiredFields = false + ; + + CreateAppRequest._() : super(); + factory CreateAppRequest({ + $core.String? workspaceId, + $core.String? name, + $core.String? desc, + ColorStyle? colorStyle, + }) { + final _result = create(); + if (workspaceId != null) { + _result.workspaceId = workspaceId; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + if (colorStyle != null) { + _result.colorStyle = colorStyle; + } + return _result; + } + factory CreateAppRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory CreateAppRequest.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') + CreateAppRequest clone() => CreateAppRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + CreateAppRequest copyWith(void Function(CreateAppRequest) updates) => super.copyWith((message) => updates(message as CreateAppRequest)) as CreateAppRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static CreateAppRequest create() => CreateAppRequest._(); + CreateAppRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static CreateAppRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static CreateAppRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get workspaceId => $_getSZ(0); + @$pb.TagNumber(1) + set workspaceId($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasWorkspaceId() => $_has(0); + @$pb.TagNumber(1) + void clearWorkspaceId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get desc => $_getSZ(2); + @$pb.TagNumber(3) + set desc($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasDesc() => $_has(2); + @$pb.TagNumber(3) + void clearDesc() => clearField(3); + + @$pb.TagNumber(4) + ColorStyle get colorStyle => $_getN(3); + @$pb.TagNumber(4) + set colorStyle(ColorStyle v) { setField(4, v); } + @$pb.TagNumber(4) + $core.bool hasColorStyle() => $_has(3); + @$pb.TagNumber(4) + void clearColorStyle() => clearField(4); + @$pb.TagNumber(4) + ColorStyle ensureColorStyle() => $_ensure(3); +} + +class ColorStyle extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'ColorStyle', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'themeColor') + ..hasRequiredFields = false + ; + + ColorStyle._() : super(); + factory ColorStyle({ + $core.String? themeColor, + }) { + final _result = create(); + if (themeColor != null) { + _result.themeColor = themeColor; + } + return _result; + } + factory ColorStyle.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory ColorStyle.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') + ColorStyle clone() => ColorStyle()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + ColorStyle copyWith(void Function(ColorStyle) updates) => super.copyWith((message) => updates(message as ColorStyle)) as ColorStyle; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static ColorStyle create() => ColorStyle._(); + ColorStyle createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static ColorStyle getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static ColorStyle? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get themeColor => $_getSZ(0); + @$pb.TagNumber(1) + set themeColor($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasThemeColor() => $_has(0); + @$pb.TagNumber(1) + void clearThemeColor() => clearField(1); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbenum.dart new file mode 100644 index 0000000000..bc2ea229d3 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: app_create.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 + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart new file mode 100644 index 0000000000..56f32576f5 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart @@ -0,0 +1,25 @@ +/// +// Generated code. Do not modify. +// source: app_create.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 + +import 'dart:core' as $core; +const CreateAppRequest$json = const { + '1': 'CreateAppRequest', + '2': const [ + const {'1': 'workspace_id', '3': 1, '4': 1, '5': 9, '10': 'workspaceId'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, + const {'1': 'color_style', '3': 4, '4': 1, '5': 11, '6': '.ColorStyle', '10': 'colorStyle'}, + ], +}; + +const ColorStyle$json = const { + '1': 'ColorStyle', + '2': const [ + const {'1': 'theme_color', '3': 1, '4': 1, '5': 9, '10': 'themeColor'}, + ], +}; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbserver.dart new file mode 100644 index 0000000000..d8c1d7f3ee --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: app_create.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 + +export 'app_create.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pb.dart new file mode 100644 index 0000000000..5caae3229d --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pb.dart @@ -0,0 +1,76 @@ +/// +// 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 + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +import 'errors.pbenum.dart'; + +export 'errors.pbenum.dart'; + +class WorkspaceError extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'WorkspaceError', createEmptyInstance: create) + ..e(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: WorkspaceErrorCode.Unknown, valueOf: WorkspaceErrorCode.valueOf, enumValues: WorkspaceErrorCode.values) + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg') + ..hasRequiredFields = false + ; + + WorkspaceError._() : super(); + factory WorkspaceError({ + WorkspaceErrorCode? code, + $core.String? msg, + }) { + final _result = create(); + if (code != null) { + _result.code = code; + } + if (msg != null) { + _result.msg = msg; + } + return _result; + } + factory WorkspaceError.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory WorkspaceError.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') + WorkspaceError clone() => WorkspaceError()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + WorkspaceError copyWith(void Function(WorkspaceError) updates) => super.copyWith((message) => updates(message as WorkspaceError)) as WorkspaceError; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static WorkspaceError create() => WorkspaceError._(); + WorkspaceError createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static WorkspaceError getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static WorkspaceError? _defaultInstance; + + @$pb.TagNumber(1) + WorkspaceErrorCode get code => $_getN(0); + @$pb.TagNumber(1) + set code(WorkspaceErrorCode v) { setField(1, v); } + @$pb.TagNumber(1) + $core.bool hasCode() => $_has(0); + @$pb.TagNumber(1) + void clearCode() => clearField(1); + + @$pb.TagNumber(2) + $core.String get msg => $_getSZ(1); + @$pb.TagNumber(2) + set msg($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasMsg() => $_has(1); + @$pb.TagNumber(2) + void clearMsg() => clearField(2); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart new file mode 100644 index 0000000000..bd9299449b --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart @@ -0,0 +1,32 @@ +/// +// 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 WorkspaceErrorCode extends $pb.ProtobufEnum { + static const WorkspaceErrorCode Unknown = WorkspaceErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const WorkspaceErrorCode WorkspaceNameInvalid = WorkspaceErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceNameInvalid'); + static const WorkspaceErrorCode WorkspaceIdInvalid = WorkspaceErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceIdInvalid'); + static const WorkspaceErrorCode AppColorStyleInvalid = WorkspaceErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppColorStyleInvalid'); + static const WorkspaceErrorCode DatabaseInternalError = WorkspaceErrorCode._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DatabaseInternalError'); + + static const $core.List values = [ + Unknown, + WorkspaceNameInvalid, + WorkspaceIdInvalid, + AppColorStyleInvalid, + DatabaseInternalError, + ]; + + static final $core.Map<$core.int, WorkspaceErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); + static WorkspaceErrorCode? valueOf($core.int value) => _byValue[value]; + + const WorkspaceErrorCode._($core.int v, $core.String n) : super(v, n); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart new file mode 100644 index 0000000000..e0791990d0 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart @@ -0,0 +1,27 @@ +/// +// 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 + +import 'dart:core' as $core; +const WorkspaceErrorCode$json = const { + '1': 'WorkspaceErrorCode', + '2': const [ + const {'1': 'Unknown', '2': 0}, + const {'1': 'WorkspaceNameInvalid', '2': 1}, + const {'1': 'WorkspaceIdInvalid', '2': 2}, + const {'1': 'AppColorStyleInvalid', '2': 3}, + const {'1': 'DatabaseInternalError', '2': 5}, + ], +}; + +const WorkspaceError$json = const { + '1': 'WorkspaceError', + '2': const [ + const {'1': 'code', '3': 1, '4': 1, '5': 14, '6': '.WorkspaceErrorCode', '10': 'code'}, + const {'1': 'msg', '3': 2, '4': 1, '5': 9, '10': 'msg'}, + ], +}; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbserver.dart new file mode 100644 index 0000000000..f25fef535c --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbserver.dart @@ -0,0 +1,9 @@ +/// +// 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 + +export 'errors.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart index 58506e3e5f..622fb04a25 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/protobuf.dart @@ -1 +1,5 @@ // Auto-generated, do not edit +export './errors.pb.dart'; +export './workspace_update.pb.dart'; +export './app_create.pb.dart'; +export './workspace_create.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart new file mode 100644 index 0000000000..e075050fc3 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pb.dart @@ -0,0 +1,72 @@ +/// +// Generated code. Do not modify. +// source: workspace_create.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 + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class CreateWorkspaceRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateWorkspaceRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..hasRequiredFields = false + ; + + CreateWorkspaceRequest._() : super(); + factory CreateWorkspaceRequest({ + $core.String? name, + $core.String? desc, + }) { + final _result = create(); + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + return _result; + } + factory CreateWorkspaceRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory CreateWorkspaceRequest.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') + CreateWorkspaceRequest clone() => CreateWorkspaceRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + CreateWorkspaceRequest copyWith(void Function(CreateWorkspaceRequest) updates) => super.copyWith((message) => updates(message as CreateWorkspaceRequest)) as CreateWorkspaceRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static CreateWorkspaceRequest create() => CreateWorkspaceRequest._(); + CreateWorkspaceRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static CreateWorkspaceRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static CreateWorkspaceRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get name => $_getSZ(0); + @$pb.TagNumber(1) + set name($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasName() => $_has(0); + @$pb.TagNumber(1) + void clearName() => clearField(1); + + @$pb.TagNumber(2) + $core.String get desc => $_getSZ(1); + @$pb.TagNumber(2) + set desc($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasDesc() => $_has(1); + @$pb.TagNumber(2) + void clearDesc() => clearField(2); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbenum.dart new file mode 100644 index 0000000000..9dece8fe1f --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: workspace_create.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 + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart new file mode 100644 index 0000000000..a0e43198c8 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbjson.dart @@ -0,0 +1,16 @@ +/// +// Generated code. Do not modify. +// source: workspace_create.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 + +import 'dart:core' as $core; +const CreateWorkspaceRequest$json = const { + '1': 'CreateWorkspaceRequest', + '2': const [ + const {'1': 'name', '3': 1, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'desc', '3': 2, '4': 1, '5': 9, '10': 'desc'}, + ], +}; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbserver.dart new file mode 100644 index 0000000000..769db97c1b --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_create.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: workspace_create.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 + +export 'workspace_create.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pb.dart new file mode 100644 index 0000000000..a384e3e7e7 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pb.dart @@ -0,0 +1,86 @@ +/// +// Generated code. Do not modify. +// source: workspace_update.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 + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class UpdateWorkspaceRequest extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateWorkspaceRequest', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..hasRequiredFields = false + ; + + UpdateWorkspaceRequest._() : super(); + factory UpdateWorkspaceRequest({ + $core.String? id, + $core.String? name, + $core.String? desc, + }) { + final _result = create(); + if (id != null) { + _result.id = id; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + return _result; + } + factory UpdateWorkspaceRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory UpdateWorkspaceRequest.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') + UpdateWorkspaceRequest clone() => UpdateWorkspaceRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + UpdateWorkspaceRequest copyWith(void Function(UpdateWorkspaceRequest) updates) => super.copyWith((message) => updates(message as UpdateWorkspaceRequest)) as UpdateWorkspaceRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static UpdateWorkspaceRequest create() => UpdateWorkspaceRequest._(); + UpdateWorkspaceRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static UpdateWorkspaceRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static UpdateWorkspaceRequest? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get id => $_getSZ(0); + @$pb.TagNumber(1) + set id($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasId() => $_has(0); + @$pb.TagNumber(1) + void clearId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get desc => $_getSZ(2); + @$pb.TagNumber(3) + set desc($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasDesc() => $_has(2); + @$pb.TagNumber(3) + void clearDesc() => clearField(3); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbenum.dart new file mode 100644 index 0000000000..9a26b2befe --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: workspace_update.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 + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbjson.dart new file mode 100644 index 0000000000..69d9abfbf5 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbjson.dart @@ -0,0 +1,17 @@ +/// +// Generated code. Do not modify. +// source: workspace_update.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 + +import 'dart:core' as $core; +const UpdateWorkspaceRequest$json = const { + '1': 'UpdateWorkspaceRequest', + '2': const [ + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, + ], +}; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbserver.dart new file mode 100644 index 0000000000..e124664f3a --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/workspace_update.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: workspace_update.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 + +export 'workspace_update.pb.dart'; + diff --git a/rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/down.sql b/rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/down.sql new file mode 100644 index 0000000000..bacfe9a64b --- /dev/null +++ b/rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/down.sql @@ -0,0 +1,4 @@ +-- This file should undo anything in `up.sql` +DROP TABLE workspace_table; +DROP TABLE app_table; +DROP TABLE view_table; \ No newline at end of file diff --git a/rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/up.sql b/rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/up.sql new file mode 100644 index 0000000000..334b920141 --- /dev/null +++ b/rust-lib/flowy-database/migrations/2021-07-13-063102_flowy-workspace/up.sql @@ -0,0 +1,34 @@ +-- Your SQL goes here +CREATE TABLE workspace_table ( + id TEXT NOT NULL PRIMARY KEY, + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + user_id TEXT NOT NULL DEFAULT '', + version BIGINT NOT NULL DEFAULT 0 +); + +CREATE TABLE app_table ( + id TEXT NOT NULL PRIMARY KEY, + workspace_id TEXT NOT NULL DEFAULT '', + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + color_style BLOB NOT NULL DEFAULT (x''), + last_view_id TEXT DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + version BIGINT NOT NULL DEFAULT 0 +); + +CREATE TABLE view_table ( + id TEXT NOT NULL PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT '', + name TEXT NOT NULL DEFAULT '', + desc TEXT NOT NULL DEFAULT '', + modified_time BIGINT NOT NULL DEFAULT 0, + create_time BIGINT NOT NULL DEFAULT 0, + thumbnail TEXT NOT NULL DEFAULT '', + view_type INTEGER NOT NULL DEFAULT 0, + version BIGINT NOT NULL DEFAULT 0 +); diff --git a/rust-lib/flowy-database/src/schema.rs b/rust-lib/flowy-database/src/schema.rs index 49bd45e814..aa59c7a6ad 100644 --- a/rust-lib/flowy-database/src/schema.rs +++ b/rust-lib/flowy-database/src/schema.rs @@ -1,3 +1,17 @@ +table! { + app_table (id) { + id -> Text, + workspace_id -> Text, + name -> Text, + desc -> Text, + color_style -> Binary, + last_view_id -> Nullable, + modified_time -> BigInt, + create_time -> BigInt, + version -> BigInt, + } +} + table! { user_table (id) { id -> Text, @@ -6,3 +20,36 @@ table! { email -> Text, } } + +table! { + view_table (id) { + id -> Text, + app_id -> Text, + name -> Text, + desc -> Text, + modified_time -> BigInt, + create_time -> BigInt, + thumbnail -> Text, + view_type -> Integer, + version -> BigInt, + } +} + +table! { + workspace_table (id) { + id -> Text, + name -> Text, + desc -> Text, + modified_time -> BigInt, + create_time -> BigInt, + user_id -> Text, + version -> BigInt, + } +} + +allow_tables_to_appear_in_same_query!( + app_table, + user_table, + view_table, + workspace_table, +); 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 0449a10165..414c0ec729 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -16,6 +16,11 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "u8" => TypeCategory::Bytes, "String" => TypeCategory::Str, "KeyValue" + | "CreateAppRequest" + | "ColorStyle" + | "UpdateWorkspaceRequest" + | "CreateWorkspaceRequest" + | "WorkspaceError" | "FFIRequest" | "FFIResponse" | "UserDetail" @@ -26,7 +31,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "SignInParams" | "UserError" => TypeCategory::Protobuf, - "FFIStatusCode" + "WorkspaceErrorCode" + | "FFIStatusCode" | "UserStatus" | "UserEvent" | "UserErrorCode" diff --git a/rust-lib/flowy-infra/Cargo.toml b/rust-lib/flowy-infra/Cargo.toml index 1b8535f13c..74d36e0f37 100644 --- a/rust-lib/flowy-infra/Cargo.toml +++ b/rust-lib/flowy-infra/Cargo.toml @@ -14,4 +14,5 @@ flowy-derive = { path = "../flowy-derive"} flowy-sqlite = { path = "../flowy-sqlite"} lazy_static = "1.4.0" protobuf = {version = "2.18.0"} -log = "0.4.14" \ No newline at end of file +log = "0.4.14" +chrono = "0.4.19" \ No newline at end of file diff --git a/rust-lib/flowy-infra/src/lib.rs b/rust-lib/flowy-infra/src/lib.rs index 36f14b807f..03efbcfac5 100644 --- a/rust-lib/flowy-infra/src/lib.rs +++ b/rust-lib/flowy-infra/src/lib.rs @@ -11,3 +11,4 @@ pub mod kv; mod protobuf; pub fn uuid() -> String { uuid::Uuid::new_v4().to_string() } +pub fn timestamp() -> i64 { chrono::Utc::now().timestamp() } diff --git a/rust-lib/flowy-user/src/entities/sign_in.rs b/rust-lib/flowy-user/src/entities/sign_in.rs index 9411068381..c77bb530af 100644 --- a/rust-lib/flowy-user/src/entities/sign_in.rs +++ b/rust-lib/flowy-user/src/entities/sign_in.rs @@ -1,6 +1,6 @@ use crate::{ entities::{UserEmail, UserPassword}, - errors::{UserError, *}, + errors::*, }; use flowy_derive::ProtoBuf; use std::convert::TryInto; diff --git a/rust-lib/flowy-user/src/handlers/auth.rs b/rust-lib/flowy-user/src/handlers/auth_handler.rs similarity index 100% rename from rust-lib/flowy-user/src/handlers/auth.rs rename to rust-lib/flowy-user/src/handlers/auth_handler.rs diff --git a/rust-lib/flowy-user/src/handlers/mod.rs b/rust-lib/flowy-user/src/handlers/mod.rs index efadf8609e..e66bf9eb02 100644 --- a/rust-lib/flowy-user/src/handlers/mod.rs +++ b/rust-lib/flowy-user/src/handlers/mod.rs @@ -1,3 +1,3 @@ -pub mod auth; +pub mod auth_handler; -pub use auth::*; +pub use auth_handler::*; diff --git a/rust-lib/flowy-user/src/lib.rs b/rust-lib/flowy-user/src/lib.rs index b9afc5f934..76dccfe4bc 100644 --- a/rust-lib/flowy-user/src/lib.rs +++ b/rust-lib/flowy-user/src/lib.rs @@ -11,5 +11,5 @@ pub mod sql_tables; extern crate flowy_database; pub mod prelude { - pub use crate::{entities::*, handlers::auth::*, services::user_session::*}; + pub use crate::{entities::*, handlers::auth_handler::*, services::user_session::*}; } diff --git a/rust-lib/flowy-workspace/Cargo.toml b/rust-lib/flowy-workspace/Cargo.toml index bd9c8bbbc9..652f396d6c 100644 --- a/rust-lib/flowy-workspace/Cargo.toml +++ b/rust-lib/flowy-workspace/Cargo.toml @@ -12,8 +12,12 @@ flowy-derive = { path = "../flowy-derive" } flowy-database = { path = "../flowy-database" } flowy-sqlite = { path = "../flowy-sqlite" } flowy-infra = { path = "../flowy-infra" } - protobuf = {version = "2.18.0"} +log = "0.4.14" diesel = {version = "1.4.7", features = ["sqlite"]} diesel_derives = {version = "1.4.1", features = ["sqlite"]} -lazy_static = "1.4.0" \ No newline at end of file + +lazy_static = "1.4.0" +serde = { version = "1.0", features = ["derive"] } +derive_more = {version = "0.99", features = ["display"]} +bincode = { version = "1.3"} \ No newline at end of file diff --git a/rust-lib/flowy-workspace/Flowy.toml b/rust-lib/flowy-workspace/Flowy.toml index 7f8a3d3901..728e5eb776 100644 --- a/rust-lib/flowy-workspace/Flowy.toml +++ b/rust-lib/flowy-workspace/Flowy.toml @@ -1,6 +1,3 @@ -#proto_crates = ["src/entities", "src/event.rs", "src/errors.rs"] -#event_files = ["src/event.rs"] - -proto_crates = [] -event_files = [] \ No newline at end of file +proto_crates = ["src/entities", "src/event.rs", "src/errors.rs"] +event_files = ["src/event.rs"] \ No newline at end of file diff --git a/rust-lib/flowy-workspace/src/entities/app/app_color_style.rs b/rust-lib/flowy-workspace/src/entities/app/app_color_style.rs new file mode 100644 index 0000000000..9038c2f68a --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/app/app_color_style.rs @@ -0,0 +1,15 @@ +use crate::entities::app::ColorStyle; + +#[derive(Debug)] +pub struct AppColorStyle(pub ColorStyle); + +impl AppColorStyle { + pub fn parse(color_style: ColorStyle) -> Result { + // TODO: verify the color style format + Ok(Self(color_style)) + } +} + +impl AsRef for AppColorStyle { + fn as_ref(&self) -> &ColorStyle { &self.0 } +} diff --git a/rust-lib/flowy-workspace/src/entities/app/app_create.rs b/rust-lib/flowy-workspace/src/entities/app/app_create.rs new file mode 100644 index 0000000000..1337b232f2 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/app/app_create.rs @@ -0,0 +1,68 @@ +use crate::{ + entities::{ + app::{app_color_style::AppColorStyle, app_name::AppName}, + workspace::WorkspaceId, + }, + errors::*, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(ProtoBuf, Default)] +pub struct CreateAppRequest { + #[pb(index = 1)] + pub workspace_id: String, + + #[pb(index = 2)] + pub name: String, + + #[pb(index = 3)] + pub desc: String, + + #[pb(index = 4)] + pub color_style: ColorStyle, +} + +#[derive(ProtoBuf, Default, Debug)] +pub struct ColorStyle { + #[pb(index = 1)] + pub theme_color: String, +} + +pub struct CreateAppParams { + pub workspace_id: String, + pub name: String, + pub desc: String, + pub color_style: ColorStyle, +} + +impl TryInto for CreateAppRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let name = AppName::parse(self.name).map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::WorkspaceNameInvalid) + .msg(e) + .build() + })?; + + let id = WorkspaceId::parse(self.workspace_id).map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::WorkspaceIdInvalid) + .msg(e) + .build() + })?; + + let color_style = AppColorStyle::parse(self.color_style).map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::AppColorStyleInvalid) + .msg(e) + .build() + })?; + + Ok(CreateAppParams { + workspace_id: id.0, + name: name.0, + desc: self.desc, + color_style: color_style.0, + }) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/app/app_name.rs b/rust-lib/flowy-workspace/src/entities/app/app_name.rs new file mode 100644 index 0000000000..b69ab81c5a --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/app/app_name.rs @@ -0,0 +1,16 @@ +#[derive(Debug)] +pub struct AppName(pub String); + +impl AppName { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Workspace can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} + +impl AsRef for AppName { + fn as_ref(&self) -> &str { &self.0 } +} diff --git a/rust-lib/flowy-workspace/src/entities/app/mod.rs b/rust-lib/flowy-workspace/src/entities/app/mod.rs new file mode 100644 index 0000000000..59d7d0bfd8 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/app/mod.rs @@ -0,0 +1,5 @@ +mod app_color_style; +mod app_create; +mod app_name; + +pub use app_create::*; diff --git a/rust-lib/flowy-workspace/src/entities/mod.rs b/rust-lib/flowy-workspace/src/entities/mod.rs index e69de29bb2..8f9840256b 100644 --- a/rust-lib/flowy-workspace/src/entities/mod.rs +++ b/rust-lib/flowy-workspace/src/entities/mod.rs @@ -0,0 +1,2 @@ +pub mod app; +pub mod workspace; diff --git a/rust-lib/flowy-workspace/src/entities/workspace/mod.rs b/rust-lib/flowy-workspace/src/entities/workspace/mod.rs new file mode 100644 index 0000000000..7bbd8c96eb --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/mod.rs @@ -0,0 +1,11 @@ +mod workspace_create; +mod workspace_id; +mod workspace_name; +mod workspace_query; +mod workspace_update; + +pub use workspace_create::*; +pub use workspace_id::*; +pub use workspace_name::*; +pub use workspace_query::*; +pub use workspace_update::*; diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs new file mode 100644 index 0000000000..33dd0ec37d --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs @@ -0,0 +1,34 @@ +use crate::{entities::workspace::workspace_name::WorkspaceName, errors::*}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(ProtoBuf, Default)] +pub struct CreateWorkspaceRequest { + #[pb(index = 1)] + name: String, + + #[pb(index = 2)] + desc: String, +} + +pub struct CreateWorkspaceParams { + pub name: String, + pub desc: String, +} + +impl TryInto for CreateWorkspaceRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let name = WorkspaceName::parse(self.name).map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::WorkspaceNameInvalid) + .msg(e) + .build() + })?; + + Ok(CreateWorkspaceParams { + name: name.0, + desc: self.desc, + }) + } +} diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_id.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_id.rs new file mode 100644 index 0000000000..060ea982e6 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_id.rs @@ -0,0 +1,16 @@ +#[derive(Debug)] +pub struct WorkspaceId(pub String); + +impl WorkspaceId { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Workspace id can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} + +impl AsRef for WorkspaceId { + fn as_ref(&self) -> &str { &self.0 } +} diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs new file mode 100644 index 0000000000..81650d8c1f --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs @@ -0,0 +1,16 @@ +#[derive(Debug)] +pub struct WorkspaceName(pub String); + +impl WorkspaceName { + pub fn parse(s: String) -> Result { + if s.trim().is_empty() { + return Err(format!("Workspace can not be empty or whitespace")); + } + + Ok(Self(s)) + } +} + +impl AsRef for WorkspaceName { + fn as_ref(&self) -> &str { &self.0 } +} diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs new file mode 100644 index 0000000000..8f63e65520 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_query.rs @@ -0,0 +1,51 @@ +// use crate::sql_tables::workspace::Workspace; +// +// #[derive(Default, Debug, ProtoBuf)] +// pub struct WorkspaceDetail { +// #[pb(index = 1)] +// pub workspace: Workspace, +// +// #[pb(index = 2)] +// pub apps: Vec, +// } + +// use crate::entities::{RepeatedApp, Workspace}; +// use flowy_derive::ProtoBuf; +// use flowy_traits::cqrs::Identifiable; +// +// #[derive(ProtoBuf, Default, Debug)] +// pub struct WorkspaceQuery { +// #[pb(index = 1)] +// pub workspace_id: String, +// +// #[pb(index = 2)] +// pub read_apps: bool, +// } +// +// impl WorkspaceQuery { +// pub fn read_workspace(workspace_id: &str) -> Self { +// WorkspaceQuery { +// workspace_id: workspace_id.to_string(), +// read_apps: false, +// } +// } +// +// pub fn read_apps(workspace_id: &str) -> Self { +// WorkspaceQuery { +// workspace_id: workspace_id.to_string(), +// read_apps: true, +// } +// } +// } +// +// #[derive(Default, Debug, ProtoBuf)] +// pub struct WorkspaceQueryResult { +// #[pb(index = 1, oneof)] +// pub workspace: Option, +// +// #[pb(index = 2, oneof)] +// pub apps: Option, +// +// #[pb(index = 100)] +// pub error: String, +// } diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs new file mode 100644 index 0000000000..c85feb0fa2 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs @@ -0,0 +1,48 @@ +use crate::{ + entities::workspace::{workspace_id::WorkspaceId, workspace_name::WorkspaceName}, + errors::*, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(ProtoBuf, Default)] +pub struct UpdateWorkspaceRequest { + #[pb(index = 1)] + id: String, + + #[pb(index = 2)] + name: String, + + #[pb(index = 3)] + desc: String, +} + +pub struct UpdateWorkspaceParams { + pub id: String, + pub name: String, + pub desc: String, +} + +impl TryInto for UpdateWorkspaceRequest { + type Error = WorkspaceError; + + fn try_into(self) -> Result { + let name = WorkspaceName::parse(self.name).map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::WorkspaceNameInvalid) + .msg(e) + .build() + })?; + + let id = WorkspaceId::parse(self.id).map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::WorkspaceIdInvalid) + .msg(e) + .build() + })?; + + Ok(UpdateWorkspaceParams { + id: id.0, + name: name.0, + desc: self.desc, + }) + } +} diff --git a/rust-lib/flowy-workspace/src/errors.rs b/rust-lib/flowy-workspace/src/errors.rs index e69de29bb2..3b6dadac53 100644 --- a/rust-lib/flowy-workspace/src/errors.rs +++ b/rust-lib/flowy-workspace/src/errors.rs @@ -0,0 +1,96 @@ +use derive_more::Display; +use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_dispatch::prelude::{EventResponse, ResponseBuilder}; +use std::convert::TryInto; + +#[derive(Debug, Default, Clone, ProtoBuf)] +pub struct WorkspaceError { + #[pb(index = 1)] + pub code: WorkspaceErrorCode, + + #[pb(index = 2)] + pub msg: String, +} + +impl WorkspaceError { + fn new(code: WorkspaceErrorCode, msg: &str) -> Self { + Self { + code, + msg: msg.to_owned(), + } + } +} + +#[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] +pub enum WorkspaceErrorCode { + #[display(fmt = "Unknown")] + Unknown = 0, + + #[display(fmt = "Workspace name is invalid")] + WorkspaceNameInvalid = 1, + + #[display(fmt = "Workspace id is invalid")] + WorkspaceIdInvalid = 2, + + #[display(fmt = "App color style format error")] + AppColorStyleInvalid = 3, + + #[display(fmt = "Database internal error")] + DatabaseInternalError = 5, +} + +impl std::default::Default for WorkspaceErrorCode { + fn default() -> Self { WorkspaceErrorCode::Unknown } +} + +impl std::convert::From for WorkspaceError { + fn from(error: flowy_database::result::Error) -> Self { + ErrorBuilder::new(WorkspaceErrorCode::DatabaseInternalError) + .error(error) + .build() + } +} + +impl std::convert::From for WorkspaceError { + fn from(error: flowy_sqlite::Error) -> Self { + ErrorBuilder::new(WorkspaceErrorCode::DatabaseInternalError) + .error(error) + .build() + } +} + +impl flowy_dispatch::Error for WorkspaceError { + fn as_response(&self) -> EventResponse { + let bytes: Vec = self.clone().try_into().unwrap(); + ResponseBuilder::Err().data(bytes).build() + } +} + +pub struct ErrorBuilder { + pub code: WorkspaceErrorCode, + pub msg: Option, +} + +impl ErrorBuilder { + pub fn new(code: WorkspaceErrorCode) -> Self { ErrorBuilder { code, msg: None } } + + pub fn msg(mut self, msg: T) -> Self + where + T: Into, + { + self.msg = Some(msg.into()); + self + } + + pub fn error(mut self, msg: T) -> Self + where + T: std::fmt::Debug, + { + self.msg = Some(format!("{:?}", msg)); + self + } + + pub fn build(mut self) -> WorkspaceError { + WorkspaceError::new(self.code, &self.msg.take().unwrap_or("".to_owned())) + } +} diff --git a/rust-lib/flowy-workspace/src/handlers/mod.rs b/rust-lib/flowy-workspace/src/handlers/mod.rs new file mode 100644 index 0000000000..bfcb132c58 --- /dev/null +++ b/rust-lib/flowy-workspace/src/handlers/mod.rs @@ -0,0 +1,3 @@ +mod workspace_handler; + +pub use workspace_handler::*; diff --git a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs @@ -0,0 +1 @@ + diff --git a/rust-lib/flowy-workspace/src/lib.rs b/rust-lib/flowy-workspace/src/lib.rs index 4a0895aea1..343a00e341 100644 --- a/rust-lib/flowy-workspace/src/lib.rs +++ b/rust-lib/flowy-workspace/src/lib.rs @@ -1,5 +1,13 @@ pub mod entities; pub mod errors; pub mod event; +mod handlers; pub mod module; mod sql_tables; + +#[macro_use] +mod macros; +mod protobuf; + +#[macro_use] +extern crate flowy_database; diff --git a/rust-lib/flowy-workspace/src/macros.rs b/rust-lib/flowy-workspace/src/macros.rs new file mode 100644 index 0000000000..3a3b297064 --- /dev/null +++ b/rust-lib/flowy-workspace/src/macros.rs @@ -0,0 +1,66 @@ +#[macro_export] +macro_rules! impl_sql_binary_expression { + ($target:ident) => { + impl diesel::serialize::ToSql + for $target + { + fn to_sql( + &self, + out: &mut diesel::serialize::Output, + ) -> diesel::serialize::Result { + let bytes: Vec = self.try_into().map_err(|e| format!("{:?}", e))?; + diesel::serialize::ToSql::< + diesel::sql_types::Binary, + diesel::sqlite::Sqlite, + >::to_sql(&bytes, out) + + // match self.try_into() { + // Ok(bytes) => diesel::serialize::ToSql::< + // diesel::sql_types::Binary, + // diesel::sqlite::Sqlite, + // >::to_sql(&bytes, out), + // Err(e) => { + // log::error!( + // "{:?} serialize to bytes fail. {:?}", + // std::any::type_name::<$target>(), + // e + // ); + // panic!(); + // }, + // } + } + } + // https://docs.diesel.rs/src/diesel/sqlite/types/mod.rs.html#30-33 + // impl FromSql for *const [u8] { + // fn from_sql(bytes: Option<&SqliteValue>) -> deserialize::Result { + // let bytes = not_none!(bytes).read_blob(); + // Ok(bytes as *const _) + // } + // } + impl diesel::deserialize::FromSql for $target + where + DB: diesel::backend::Backend, + *const [u8]: diesel::deserialize::FromSql, + { + fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result { + let slice_ptr = <*const [u8] as diesel::deserialize::FromSql< + diesel::sql_types::Binary, + DB, + >>::from_sql(bytes)?; + let bytes = unsafe { &*slice_ptr }; + + match $target::try_from(bytes) { + Ok(object) => Ok(object), + Err(e) => { + log::error!( + "{:?} deserialize from bytes fail. {:?}", + std::any::type_name::<$target>(), + e + ); + panic!(); + }, + } + } + } + }; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs b/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs new file mode 100644 index 0000000000..5c2fea644e --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs @@ -0,0 +1,520 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `app_create.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct CreateAppRequest { + // message fields + pub workspace_id: ::std::string::String, + pub name: ::std::string::String, + pub desc: ::std::string::String, + pub color_style: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CreateAppRequest { + fn default() -> &'a CreateAppRequest { + ::default_instance() + } +} + +impl CreateAppRequest { + pub fn new() -> CreateAppRequest { + ::std::default::Default::default() + } + + // string workspace_id = 1; + + + pub fn get_workspace_id(&self) -> &str { + &self.workspace_id + } + pub fn clear_workspace_id(&mut self) { + self.workspace_id.clear(); + } + + // Param is passed by value, moved + pub fn set_workspace_id(&mut self, v: ::std::string::String) { + self.workspace_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_workspace_id(&mut self) -> &mut ::std::string::String { + &mut self.workspace_id + } + + // Take field + pub fn take_workspace_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.workspace_id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + &self.name + } + pub fn clear_name(&mut self) { + self.name.clear(); + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.name = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + &mut self.name + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.name, ::std::string::String::new()) + } + + // string desc = 3; + + + pub fn get_desc(&self) -> &str { + &self.desc + } + pub fn clear_desc(&mut self) { + self.desc.clear(); + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.desc = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + &mut self.desc + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.desc, ::std::string::String::new()) + } + + // .ColorStyle color_style = 4; + + + pub fn get_color_style(&self) -> &ColorStyle { + self.color_style.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_color_style(&mut self) { + self.color_style.clear(); + } + + pub fn has_color_style(&self) -> bool { + self.color_style.is_some() + } + + // Param is passed by value, moved + pub fn set_color_style(&mut self, v: ColorStyle) { + self.color_style = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_color_style(&mut self) -> &mut ColorStyle { + if self.color_style.is_none() { + self.color_style.set_default(); + } + self.color_style.as_mut().unwrap() + } + + // Take field + pub fn take_color_style(&mut self) -> ColorStyle { + self.color_style.take().unwrap_or_else(|| ColorStyle::new()) + } +} + +impl ::protobuf::Message for CreateAppRequest { + fn is_initialized(&self) -> bool { + for v in &self.color_style { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.workspace_id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; + }, + 4 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.color_style)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.workspace_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.workspace_id); + } + if !self.name.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.name); + } + if !self.desc.is_empty() { + my_size += ::protobuf::rt::string_size(3, &self.desc); + } + if let Some(ref v) = self.color_style.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.workspace_id.is_empty() { + os.write_string(1, &self.workspace_id)?; + } + if !self.name.is_empty() { + os.write_string(2, &self.name)?; + } + if !self.desc.is_empty() { + os.write_string(3, &self.desc)?; + } + if let Some(ref v) = self.color_style.as_ref() { + os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> CreateAppRequest { + CreateAppRequest::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::ProtobufTypeString>( + "workspace_id", + |m: &CreateAppRequest| { &m.workspace_id }, + |m: &mut CreateAppRequest| { &mut m.workspace_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &CreateAppRequest| { &m.name }, + |m: &mut CreateAppRequest| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "desc", + |m: &CreateAppRequest| { &m.desc }, + |m: &mut CreateAppRequest| { &mut m.desc }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "color_style", + |m: &CreateAppRequest| { &m.color_style }, + |m: &mut CreateAppRequest| { &mut m.color_style }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CreateAppRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CreateAppRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CreateAppRequest::new) + } +} + +impl ::protobuf::Clear for CreateAppRequest { + fn clear(&mut self) { + self.workspace_id.clear(); + self.name.clear(); + self.desc.clear(); + self.color_style.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CreateAppRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CreateAppRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct ColorStyle { + // message fields + pub theme_color: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a ColorStyle { + fn default() -> &'a ColorStyle { + ::default_instance() + } +} + +impl ColorStyle { + pub fn new() -> ColorStyle { + ::std::default::Default::default() + } + + // string theme_color = 1; + + + pub fn get_theme_color(&self) -> &str { + &self.theme_color + } + pub fn clear_theme_color(&mut self) { + self.theme_color.clear(); + } + + // Param is passed by value, moved + pub fn set_theme_color(&mut self, v: ::std::string::String) { + self.theme_color = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_theme_color(&mut self) -> &mut ::std::string::String { + &mut self.theme_color + } + + // Take field + pub fn take_theme_color(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.theme_color, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for ColorStyle { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.theme_color)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.theme_color.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.theme_color); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.theme_color.is_empty() { + os.write_string(1, &self.theme_color)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> ColorStyle { + ColorStyle::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::ProtobufTypeString>( + "theme_color", + |m: &ColorStyle| { &m.theme_color }, + |m: &mut ColorStyle| { &mut m.theme_color }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "ColorStyle", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static ColorStyle { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(ColorStyle::new) + } +} + +impl ::protobuf::Clear for ColorStyle { + fn clear(&mut self) { + self.theme_color.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ColorStyle { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ColorStyle { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10app_create.proto\"\x8b\x01\n\x10CreateAppRequest\x12!\n\x0cworkspa\ + ce_id\x18\x01\x20\x01(\tR\x0bworkspaceId\x12\x12\n\x04name\x18\x02\x20\ + \x01(\tR\x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12,\n\ + \x0bcolor_style\x18\x04\x20\x01(\x0b2\x0b.ColorStyleR\ncolorStyle\"-\n\n\ + ColorStyle\x12\x1f\n\x0btheme_color\x18\x01\x20\x01(\tR\nthemeColorJ\xd5\ + \x02\n\x06\x12\x04\0\0\n\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\ + \x04\0\x12\x04\x02\0\x07\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\x1c\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\x17\n\x0c\ + \n\x05\x04\0\x02\0\x03\x12\x03\x03\x1a\x1b\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\x14\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\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\ + \x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x04\x1f\n\x0c\n\x05\x04\0\x02\x03\ + \x06\x12\x03\x06\x04\x0e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0f\ + \x1a\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06\x1d\x1e\n\n\n\x02\x04\x01\ + \x12\x04\x08\0\n\x01\n\n\n\x03\x04\x01\x01\x12\x03\x08\x08\x12\n\x0b\n\ + \x04\x04\x01\x02\0\x12\x03\t\x04\x1b\n\x0c\n\x05\x04\x01\x02\0\x05\x12\ + \x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\t\x0b\x16\n\x0c\n\x05\ + \x04\x01\x02\0\x03\x12\x03\t\x19\x1ab\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/errors.rs b/rust-lib/flowy-workspace/src/protobuf/model/errors.rs new file mode 100644 index 0000000000..4b198b2fe5 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/errors.rs @@ -0,0 +1,312 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `errors.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct WorkspaceError { + // message fields + pub code: WorkspaceErrorCode, + pub msg: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a WorkspaceError { + fn default() -> &'a WorkspaceError { + ::default_instance() + } +} + +impl WorkspaceError { + pub fn new() -> WorkspaceError { + ::std::default::Default::default() + } + + // .WorkspaceErrorCode code = 1; + + + pub fn get_code(&self) -> WorkspaceErrorCode { + self.code + } + pub fn clear_code(&mut self) { + self.code = WorkspaceErrorCode::Unknown; + } + + // Param is passed by value, moved + pub fn set_code(&mut self, v: WorkspaceErrorCode) { + self.code = v; + } + + // string msg = 2; + + + pub fn get_msg(&self) -> &str { + &self.msg + } + pub fn clear_msg(&mut self) { + self.msg.clear(); + } + + // Param is passed by value, moved + pub fn set_msg(&mut self, v: ::std::string::String) { + self.msg = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_msg(&mut self) -> &mut ::std::string::String { + &mut self.msg + } + + // Take field + pub fn take_msg(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.msg, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for WorkspaceError { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.code, 1, &mut self.unknown_fields)? + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.msg)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if self.code != WorkspaceErrorCode::Unknown { + my_size += ::protobuf::rt::enum_size(1, self.code); + } + if !self.msg.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.msg); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if self.code != WorkspaceErrorCode::Unknown { + os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?; + } + if !self.msg.is_empty() { + os.write_string(2, &self.msg)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> WorkspaceError { + WorkspaceError::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>( + "code", + |m: &WorkspaceError| { &m.code }, + |m: &mut WorkspaceError| { &mut m.code }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "msg", + |m: &WorkspaceError| { &m.msg }, + |m: &mut WorkspaceError| { &mut m.msg }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "WorkspaceError", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static WorkspaceError { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(WorkspaceError::new) + } +} + +impl ::protobuf::Clear for WorkspaceError { + fn clear(&mut self) { + self.code = WorkspaceErrorCode::Unknown; + self.msg.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for WorkspaceError { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for WorkspaceError { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(Clone,PartialEq,Eq,Debug,Hash)] +pub enum WorkspaceErrorCode { + Unknown = 0, + WorkspaceNameInvalid = 1, + WorkspaceIdInvalid = 2, + AppColorStyleInvalid = 3, + DatabaseInternalError = 5, +} + +impl ::protobuf::ProtobufEnum for WorkspaceErrorCode { + fn value(&self) -> i32 { + *self as i32 + } + + fn from_i32(value: i32) -> ::std::option::Option { + match value { + 0 => ::std::option::Option::Some(WorkspaceErrorCode::Unknown), + 1 => ::std::option::Option::Some(WorkspaceErrorCode::WorkspaceNameInvalid), + 2 => ::std::option::Option::Some(WorkspaceErrorCode::WorkspaceIdInvalid), + 3 => ::std::option::Option::Some(WorkspaceErrorCode::AppColorStyleInvalid), + 5 => ::std::option::Option::Some(WorkspaceErrorCode::DatabaseInternalError), + _ => ::std::option::Option::None + } + } + + fn values() -> &'static [Self] { + static values: &'static [WorkspaceErrorCode] = &[ + WorkspaceErrorCode::Unknown, + WorkspaceErrorCode::WorkspaceNameInvalid, + WorkspaceErrorCode::WorkspaceIdInvalid, + WorkspaceErrorCode::AppColorStyleInvalid, + WorkspaceErrorCode::DatabaseInternalError, + ]; + values + } + + 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::("WorkspaceErrorCode", file_descriptor_proto()) + }) + } +} + +impl ::std::marker::Copy for WorkspaceErrorCode { +} + +impl ::std::default::Default for WorkspaceErrorCode { + fn default() -> Self { + WorkspaceErrorCode::Unknown + } +} + +impl ::protobuf::reflect::ProtobufValue for WorkspaceErrorCode { + 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\"K\n\x0eWorkspaceError\x12'\n\x04code\x18\x01\x20\x01\ + (\x0e2\x13.WorkspaceErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\ + \tR\x03msg*\x88\x01\n\x12WorkspaceErrorCode\x12\x0b\n\x07Unknown\x10\0\ + \x12\x18\n\x14WorkspaceNameInvalid\x10\x01\x12\x16\n\x12WorkspaceIdInval\ + id\x10\x02\x12\x18\n\x14AppColorStyleInvalid\x10\x03\x12\x19\n\x15Databa\ + seInternalError\x10\x05J\xfd\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\x16\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x20\n\ + \x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\ + \x01\x12\x03\x03\x17\x1b\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x1e\x1f\ + \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\x0c\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x17\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\x1d\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\ + \x04\x18\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1b\x1c\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\x1d\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\ + \x18\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\x1b\x1c\n\x0b\n\x04\x05\0\ + \x02\x04\x12\x03\x0b\x04\x1e\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\ + \x04\x19\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x1c\x1db\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/mod.rs b/rust-lib/flowy-workspace/src/protobuf/model/mod.rs index 58506e3e5f..fd73accf49 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/mod.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/mod.rs @@ -1 +1,13 @@ // Auto-generated, do not edit + +mod errors; +pub use errors::*; + +mod workspace_update; +pub use workspace_update::*; + +mod app_create; +pub use app_create::*; + +mod workspace_create; +pub use workspace_create::*; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs b/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs new file mode 100644 index 0000000000..1ea4968719 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/workspace_create.rs @@ -0,0 +1,250 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `workspace_create.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct CreateWorkspaceRequest { + // message fields + pub name: ::std::string::String, + pub desc: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CreateWorkspaceRequest { + fn default() -> &'a CreateWorkspaceRequest { + ::default_instance() + } +} + +impl CreateWorkspaceRequest { + pub fn new() -> CreateWorkspaceRequest { + ::std::default::Default::default() + } + + // string name = 1; + + + pub fn get_name(&self) -> &str { + &self.name + } + pub fn clear_name(&mut self) { + self.name.clear(); + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.name = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + &mut self.name + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.name, ::std::string::String::new()) + } + + // string desc = 2; + + + pub fn get_desc(&self) -> &str { + &self.desc + } + pub fn clear_desc(&mut self) { + self.desc.clear(); + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.desc = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + &mut self.desc + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.desc, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for CreateWorkspaceRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.name.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.name); + } + if !self.desc.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.desc); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.name.is_empty() { + os.write_string(1, &self.name)?; + } + if !self.desc.is_empty() { + os.write_string(2, &self.desc)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> CreateWorkspaceRequest { + CreateWorkspaceRequest::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::ProtobufTypeString>( + "name", + |m: &CreateWorkspaceRequest| { &m.name }, + |m: &mut CreateWorkspaceRequest| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "desc", + |m: &CreateWorkspaceRequest| { &m.desc }, + |m: &mut CreateWorkspaceRequest| { &mut m.desc }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CreateWorkspaceRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CreateWorkspaceRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CreateWorkspaceRequest::new) + } +} + +impl ::protobuf::Clear for CreateWorkspaceRequest { + fn clear(&mut self) { + self.name.clear(); + self.desc.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CreateWorkspaceRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CreateWorkspaceRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x16workspace_create.proto\"@\n\x16CreateWorkspaceRequest\x12\x12\n\ + \x04name\x18\x01\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x02\x20\x01(\ + \tR\x04descJ\x98\x01\n\x06\x12\x04\0\0\x05\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\x1e\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x14\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\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\x13\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\x13b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/workspace_update.rs b/rust-lib/flowy-workspace/src/protobuf/model/workspace_update.rs new file mode 100644 index 0000000000..b92f5b39af --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/model/workspace_update.rs @@ -0,0 +1,296 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `workspace_update.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct UpdateWorkspaceRequest { + // message fields + pub id: ::std::string::String, + pub name: ::std::string::String, + pub desc: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a UpdateWorkspaceRequest { + fn default() -> &'a UpdateWorkspaceRequest { + ::default_instance() + } +} + +impl UpdateWorkspaceRequest { + pub fn new() -> UpdateWorkspaceRequest { + ::std::default::Default::default() + } + + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + &self.name + } + pub fn clear_name(&mut self) { + self.name.clear(); + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.name = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + &mut self.name + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.name, ::std::string::String::new()) + } + + // string desc = 3; + + + pub fn get_desc(&self) -> &str { + &self.desc + } + pub fn clear_desc(&mut self) { + self.desc.clear(); + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.desc = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + &mut self.desc + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.desc, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for UpdateWorkspaceRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } + if !self.name.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.name); + } + if !self.desc.is_empty() { + my_size += ::protobuf::rt::string_size(3, &self.desc); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } + if !self.name.is_empty() { + os.write_string(2, &self.name)?; + } + if !self.desc.is_empty() { + os.write_string(3, &self.desc)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> UpdateWorkspaceRequest { + UpdateWorkspaceRequest::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::ProtobufTypeString>( + "id", + |m: &UpdateWorkspaceRequest| { &m.id }, + |m: &mut UpdateWorkspaceRequest| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &UpdateWorkspaceRequest| { &m.name }, + |m: &mut UpdateWorkspaceRequest| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "desc", + |m: &UpdateWorkspaceRequest| { &m.desc }, + |m: &mut UpdateWorkspaceRequest| { &mut m.desc }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "UpdateWorkspaceRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static UpdateWorkspaceRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(UpdateWorkspaceRequest::new) + } +} + +impl ::protobuf::Clear for UpdateWorkspaceRequest { + fn clear(&mut self) { + self.id.clear(); + self.name.clear(); + self.desc.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for UpdateWorkspaceRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for UpdateWorkspaceRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x16workspace_update.proto\"P\n\x16UpdateWorkspaceRequest\x12\x0e\n\ + \x02id\x18\x01\x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\ + \x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04descJ\xcf\x01\n\x06\ + \x12\x04\0\0\x06\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\x1e\n\x0b\n\x04\ + \x04\0\x02\0\x12\x03\x03\x04\x12\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\r\n\x0c\n\x05\x04\0\ + \x02\0\x03\x12\x03\x03\x10\x11\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\x14\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\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13b\x06p\ + roto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto b/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto new file mode 100644 index 0000000000..2f6bee1f19 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +message CreateAppRequest { + string workspace_id = 1; + string name = 2; + string desc = 3; + ColorStyle color_style = 4; +} +message ColorStyle { + string theme_color = 1; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto b/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto new file mode 100644 index 0000000000..e21729eb37 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +message WorkspaceError { + WorkspaceErrorCode code = 1; + string msg = 2; +} +enum WorkspaceErrorCode { + Unknown = 0; + WorkspaceNameInvalid = 1; + WorkspaceIdInvalid = 2; + AppColorStyleInvalid = 3; + DatabaseInternalError = 5; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto new file mode 100644 index 0000000000..798e4a2b5b --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_create.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +message CreateWorkspaceRequest { + string name = 1; + string desc = 2; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/workspace_update.proto b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_update.proto new file mode 100644 index 0000000000..a3568b68b7 --- /dev/null +++ b/rust-lib/flowy-workspace/src/protobuf/proto/workspace_update.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +message UpdateWorkspaceRequest { + string id = 1; + string name = 2; + string desc = 3; +} diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs b/rust-lib/flowy-workspace/src/sql_tables/app/app.rs new file mode 100644 index 0000000000..bdf5ebff53 --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/app/app.rs @@ -0,0 +1,56 @@ +use crate::{impl_sql_binary_expression, sql_tables::workspace::Workspace}; +use diesel::sql_types::Binary; +use flowy_database::schema::{app_table, app_table::dsl}; +use flowy_infra::{timestamp, uuid}; +use serde::{Deserialize, Serialize, __private::TryFrom}; +use std::convert::TryInto; + +#[derive( + PartialEq, + Serialize, + Deserialize, + Clone, + Debug, + Queryable, + Identifiable, + Insertable, + Associations, +)] +#[belongs_to(Workspace, foreign_key = "workspace_id")] +#[table_name = "app_table"] +#[serde(tag = "type")] +pub(crate) struct App { + pub id: String, + pub workspace_id: String, // equal to #[belongs_to(Workspace, foreign_key = "workspace_id")]. + pub name: String, + pub desc: String, + pub color_style: ColorStyleCol, + pub last_view_id: Option, + pub modified_time: i64, + pub create_time: i64, + pub version: i64, +} + +#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, Default, FromSqlRow, AsExpression)] +#[sql_type = "Binary"] +pub(crate) struct ColorStyleCol { + pub(crate) theme_color: String, +} + +impl std::convert::TryInto> for &ColorStyleCol { + type Error = String; + + fn try_into(self) -> Result, Self::Error> { + bincode::serialize(self).map_err(|e| format!("{:?}", e)) + } +} + +impl std::convert::TryFrom<&[u8]> for ColorStyleCol { + type Error = String; + + fn try_from(value: &[u8]) -> Result { + bincode::deserialize(value).map_err(|e| format!("{:?}", e)) + } +} + +impl_sql_binary_expression!(ColorStyleCol); diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs b/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs new file mode 100644 index 0000000000..732903754f --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/app/mod.rs @@ -0,0 +1,3 @@ +mod app; + +pub use app::*; diff --git a/rust-lib/flowy-workspace/src/sql_tables/mod.rs b/rust-lib/flowy-workspace/src/sql_tables/mod.rs index e69de29bb2..8f9840256b 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/mod.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/mod.rs @@ -0,0 +1,2 @@ +pub mod app; +pub mod workspace; diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs new file mode 100644 index 0000000000..c1f22fe9d7 --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/mod.rs @@ -0,0 +1,3 @@ +mod workspace; + +pub use workspace::*; diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs new file mode 100644 index 0000000000..f5c2f00b1d --- /dev/null +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs @@ -0,0 +1,63 @@ +use crate::{ + entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams}, + sql_tables::app::App, +}; +use flowy_database::schema::{workspace_table, workspace_table::dsl}; +use flowy_infra::{timestamp, uuid}; +use serde::{Deserialize, Serialize}; + +#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Queryable, Identifiable, Insertable)] +#[table_name = "workspace_table"] +#[serde(tag = "type")] +pub struct Workspace { + pub id: String, + pub name: String, + pub desc: String, + pub modified_time: i64, + pub create_time: i64, + pub user_id: String, + pub version: i64, +} + +impl Workspace { + #[allow(dead_code)] + pub fn new(params: CreateWorkspaceParams) -> Self { + let mut workspace = Workspace::default(); + workspace.name = params.name; + workspace.desc = params.desc; + workspace + } +} + +impl std::default::Default for Workspace { + fn default() -> Self { + let time = timestamp(); + Workspace { + id: uuid(), + name: String::default(), + desc: String::default(), + modified_time: time, + create_time: time, + user_id: String::default(), + version: 0, + } + } +} + +#[derive(AsChangeset, Identifiable, Clone, Default, Debug)] +#[table_name = "workspace_table"] +pub struct WorkspaceChangeset { + pub id: String, + pub name: Option, + pub desc: Option, +} + +impl WorkspaceChangeset { + pub fn new(params: UpdateWorkspaceParams) -> Self { + WorkspaceChangeset { + id: params.id, + name: Some(params.name), + desc: Some(params.desc), + } + } +}