Merge pull request #564 from AppFlowy-IO/feat/auto_import_pb

Feat/auto import proto
This commit is contained in:
Nathan.fooo 2022-06-17 17:32:06 +08:00 committed by GitHub
commit 370072dafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 117 additions and 1043 deletions

3
.gitignore vendored
View File

@ -19,4 +19,5 @@ node_modules
**/.cache
**/.DS_Store
**/src/protobuf
**/src/protobuf
**/resources/proto

View File

@ -11,4 +11,5 @@
**/**/temp
bin/
**/src/protobuf
**/resources/proto
.idea/

View File

@ -1,6 +0,0 @@
syntax = "proto3";
message FFIRequest {
string event = 1;
bytes payload = 2;
}

View File

@ -1,11 +0,0 @@
syntax = "proto3";
message FFIResponse {
bytes payload = 1;
FFIStatusCode code = 2;
}
enum FFIStatusCode {
Ok = 0;
Err = 1;
Internal = 2;
}

View File

@ -1,9 +0,0 @@
syntax = "proto3";
message SubscribeObject {
string source = 1;
int32 ty = 2;
string id = 3;
oneof one_of_payload { bytes payload = 4; };
oneof one_of_error { bytes error = 5; };
}

View File

@ -1,6 +0,0 @@
syntax = "proto3";
message FlowyError {
int32 code = 1;
string msg = 2;
}

View File

@ -1,18 +0,0 @@
syntax = "proto3";
enum FolderNotification {
Unknown = 0;
UserCreateWorkspace = 10;
UserDeleteWorkspace = 11;
WorkspaceUpdated = 12;
WorkspaceListUpdated = 13;
WorkspaceAppsChanged = 14;
WorkspaceSetting = 15;
AppUpdated = 21;
AppViewsChanged = 24;
ViewUpdated = 31;
ViewDeleted = 32;
ViewRestored = 33;
UserUnauthorized = 100;
TrashUpdated = 1000;
}

View File

@ -1,29 +0,0 @@
syntax = "proto3";
enum FolderEvent {
CreateWorkspace = 0;
ReadCurWorkspace = 1;
ReadWorkspaces = 2;
DeleteWorkspace = 3;
OpenWorkspace = 4;
ReadWorkspaceApps = 5;
CreateApp = 101;
DeleteApp = 102;
ReadApp = 103;
UpdateApp = 104;
CreateView = 201;
ReadView = 202;
UpdateView = 203;
DeleteView = 204;
DuplicateView = 205;
CloseView = 206;
ReadViewInfo = 207;
CopyLink = 220;
SetLatestView = 221;
MoveFolderItem = 230;
ReadTrash = 300;
PutbackTrash = 301;
DeleteTrash = 302;
RestoreAllTrash = 303;
DeleteAllTrash = 304;
}

View File

@ -1,12 +0,0 @@
syntax = "proto3";
import "field_entities.proto";
message CreateSelectOptionPayload {
FieldIdentifierPayload field_identifier = 1;
string option_name = 2;
}
message CellIdentifierPayload {
string grid_id = 1;
string field_id = 2;
string row_id = 3;
}

View File

@ -1,5 +0,0 @@
syntax = "proto3";
message CheckboxTypeOption {
bool is_selected = 1;
}

View File

@ -1,11 +0,0 @@
syntax = "proto3";
enum GridNotification {
Unknown = 0;
DidCreateBlock = 11;
DidUpdateGridRow = 20;
DidUpdateGridField = 21;
DidUpdateRow = 30;
DidUpdateCell = 40;
DidUpdateField = 50;
}

View File

@ -1,28 +0,0 @@
syntax = "proto3";
import "cell_entities.proto";
message DateTypeOption {
DateFormat date_format = 1;
TimeFormat time_format = 2;
bool include_time = 3;
}
message DateCellData {
string date = 1;
string time = 2;
int64 timestamp = 3;
}
message DateChangesetPayload {
CellIdentifierPayload cell_identifier = 1;
oneof one_of_date { string date = 2; };
oneof one_of_time { string time = 3; };
}
enum DateFormat {
Local = 0;
US = 1;
ISO = 2;
Friendly = 3;
}
enum TimeFormat {
TwelveHour = 0;
TwentyFourHour = 1;
}

View File

@ -1,27 +0,0 @@
syntax = "proto3";
enum GridEvent {
GetGridData = 0;
GetGridBlocks = 1;
GetFields = 10;
UpdateField = 11;
UpdateFieldTypeOption = 12;
InsertField = 13;
DeleteField = 14;
SwitchToField = 20;
DuplicateField = 21;
MoveItem = 22;
GetFieldTypeOption = 23;
CreateFieldTypeOption = 24;
NewSelectOption = 30;
GetSelectOptionCellData = 31;
UpdateSelectOption = 32;
CreateRow = 50;
GetRow = 51;
DeleteRow = 52;
DuplicateRow = 53;
GetCell = 70;
UpdateCell = 71;
UpdateSelectOptionCell = 72;
UpdateDateCell = 80;
}

View File

@ -1,6 +0,0 @@
syntax = "proto3";
message FieldIdentifierPayload {
string field_id = 1;
string grid_id = 2;
}

View File

@ -1,40 +0,0 @@
syntax = "proto3";
enum NumberFormat {
Number = 0;
USD = 1;
CanadianDollar = 2;
EUR = 4;
Pound = 5;
Yen = 6;
Ruble = 7;
Rupee = 8;
Won = 9;
Yuan = 10;
Real = 11;
Lira = 12;
Rupiah = 13;
Franc = 14;
HongKongDollar = 15;
NewZealandDollar = 16;
Krona = 17;
NorwegianKrone = 18;
MexicanPeso = 19;
Rand = 20;
NewTaiwanDollar = 21;
DanishKrone = 22;
Baht = 23;
Forint = 24;
Koruna = 25;
Shekel = 26;
ChileanPeso = 27;
PhilippinePeso = 28;
Dirham = 29;
ColombianPeso = 30;
Riyal = 31;
Ringgit = 32;
Leu = 33;
ArgentinePeso = 34;
UruguayanPeso = 35;
Percent = 36;
}

View File

@ -1,10 +0,0 @@
syntax = "proto3";
import "format.proto";
message NumberTypeOption {
NumberFormat format = 1;
uint32 scale = 2;
string symbol = 3;
bool sign_positive = 4;
string name = 5;
}

View File

@ -1,6 +0,0 @@
syntax = "proto3";
message RowIdentifierPayload {
string grid_id = 1;
string row_id = 3;
}

View File

@ -1,42 +0,0 @@
syntax = "proto3";
import "cell_entities.proto";
message SingleSelectTypeOption {
repeated SelectOption options = 1;
bool disable_color = 2;
}
message MultiSelectTypeOption {
repeated SelectOption options = 1;
bool disable_color = 2;
}
message SelectOption {
string id = 1;
string name = 2;
SelectOptionColor color = 3;
}
message SelectOptionChangesetPayload {
CellIdentifierPayload cell_identifier = 1;
oneof one_of_insert_option { SelectOption insert_option = 2; };
oneof one_of_update_option { SelectOption update_option = 3; };
oneof one_of_delete_option { SelectOption delete_option = 4; };
}
message SelectOptionCellChangesetPayload {
CellIdentifierPayload cell_identifier = 1;
oneof one_of_insert_option_id { string insert_option_id = 2; };
oneof one_of_delete_option_id { string delete_option_id = 3; };
}
message SelectOptionCellData {
repeated SelectOption options = 1;
repeated SelectOption select_options = 2;
}
enum SelectOptionColor {
Purple = 0;
Pink = 1;
LightPink = 2;
Orange = 3;
Yellow = 4;
Lime = 5;
Green = 6;
Aqua = 7;
Blue = 8;
}

View File

@ -1,5 +0,0 @@
syntax = "proto3";
message RichTextTypeOption {
string data = 1;
}

View File

@ -1,9 +0,0 @@
syntax = "proto3";
message URLTypeOption {
string data = 1;
}
message URLCellData {
string url = 1;
string content = 2;
}

View File

@ -1,5 +0,0 @@
syntax = "proto3";
enum NetworkEvent {
UpdateNetworkType = 0;
}

View File

@ -1,11 +0,0 @@
syntax = "proto3";
message NetworkState {
NetworkType ty = 1;
}
enum NetworkType {
UnknownNetworkType = 0;
Wifi = 1;
Cell = 2;
Ethernet = 3;
}

View File

@ -1,15 +0,0 @@
syntax = "proto3";
message ExportPayload {
string view_id = 1;
ExportType export_type = 2;
}
message ExportData {
string data = 1;
ExportType export_type = 2;
}
enum ExportType {
Text = 0;
Markdown = 1;
Link = 2;
}

View File

@ -1,7 +0,0 @@
syntax = "proto3";
enum TextBlockEvent {
GetBlockData = 0;
ApplyDelta = 1;
ExportDocument = 2;
}

View File

@ -1,9 +0,0 @@
syntax = "proto3";
enum UserNotification {
Unknown = 0;
UserAuthChanged = 1;
UserProfileUpdated = 2;
UserUnauthorized = 3;
UserWsConnectStateChanged = 4;
}

View File

@ -1,13 +0,0 @@
syntax = "proto3";
enum UserEvent {
InitUser = 0;
SignIn = 1;
SignUp = 2;
SignOut = 3;
UpdateUser = 4;
GetUserProfile = 5;
CheckUser = 6;
SetAppearanceSetting = 7;
GetAppearanceSetting = 8;
}

View File

@ -1,4 +0,0 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
// Auto-generated, do not edit
mod model;
pub use model::*;

View File

@ -1,5 +0,0 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
// Auto-generated, do not edit
mod code;
pub use code::*;

View File

@ -1,48 +0,0 @@
syntax = "proto3";
enum ErrorCode {
Internal = 0;
UserUnauthorized = 2;
RecordNotFound = 3;
UserIdIsEmpty = 4;
WorkspaceNameInvalid = 100;
WorkspaceIdInvalid = 101;
AppColorStyleInvalid = 102;
WorkspaceDescTooLong = 103;
WorkspaceNameTooLong = 104;
AppIdInvalid = 110;
AppNameInvalid = 111;
ViewNameInvalid = 120;
ViewThumbnailInvalid = 121;
ViewIdInvalid = 122;
ViewDescTooLong = 123;
ViewDataInvalid = 124;
ViewNameTooLong = 125;
ConnectError = 200;
EmailIsEmpty = 300;
EmailFormatInvalid = 301;
EmailAlreadyExists = 302;
PasswordIsEmpty = 303;
PasswordTooLong = 304;
PasswordContainsForbidCharacters = 305;
PasswordFormatInvalid = 306;
PasswordNotMatch = 307;
UserNameTooLong = 308;
UserNameContainForbiddenCharacters = 309;
UserNameIsEmpty = 310;
UserIdInvalid = 311;
UserNotExist = 312;
TextTooLong = 400;
GridIdIsEmpty = 410;
BlockIdIsEmpty = 420;
RowIdIsEmpty = 430;
OptionIdIsEmpty = 431;
FieldIdIsEmpty = 440;
FieldDoesNotExist = 441;
SelectOptionNameIsEmpty = 442;
FieldNotExists = 443;
FieldInvalidOperation = 444;
TypeOptionDataIsEmpty = 450;
InvalidDateTimeFormat = 500;
UnexpectedEmptyString = 999;
InvalidData = 1000;
}

View File

@ -1,49 +0,0 @@
syntax = "proto3";
enum ErrorCode {
Internal = 0;
UserUnauthorized = 2;
RecordNotFound = 3;
UserIdIsEmpty = 4;
WorkspaceNameInvalid = 100;
WorkspaceIdInvalid = 101;
AppColorStyleInvalid = 102;
WorkspaceDescTooLong = 103;
WorkspaceNameTooLong = 104;
AppIdInvalid = 110;
AppNameInvalid = 111;
ViewNameInvalid = 120;
ViewThumbnailInvalid = 121;
ViewIdInvalid = 122;
ViewDescTooLong = 123;
ViewDataInvalid = 124;
ViewNameTooLong = 125;
ConnectError = 200;
EmailIsEmpty = 300;
EmailFormatInvalid = 301;
EmailAlreadyExists = 302;
PasswordIsEmpty = 303;
PasswordTooLong = 304;
PasswordContainsForbidCharacters = 305;
PasswordFormatInvalid = 306;
PasswordNotMatch = 307;
UserNameTooLong = 308;
UserNameContainForbiddenCharacters = 309;
UserNameIsEmpty = 310;
UserIdInvalid = 311;
UserNotExist = 312;
TextTooLong = 400;
GridIdIsEmpty = 410;
BlockIdIsEmpty = 420;
RowIdIsEmpty = 430;
OptionIdIsEmpty = 431;
FieldIdIsEmpty = 440;
FieldDoesNotExist = 441;
SelectOptionNameIsEmpty = 442;
FieldNotExists = 443;
FieldInvalidOperation = 444;
TypeOptionDataIsEmpty = 450;
InvalidDateTimeFormat = 500;
UnexpectedEmptyString = 999;
InvalidData = 1000;
}

View File

@ -1,48 +0,0 @@
syntax = "proto3";
import "view.proto";
message App {
string id = 1;
string workspace_id = 2;
string name = 3;
string desc = 4;
RepeatedView belongings = 5;
int64 version = 6;
int64 modified_time = 7;
int64 create_time = 8;
}
message RepeatedApp {
repeated App items = 1;
}
message CreateAppPayload {
string workspace_id = 1;
string name = 2;
string desc = 3;
ColorStyle color_style = 4;
}
message ColorStyle {
string theme_color = 1;
}
message CreateAppParams {
string workspace_id = 1;
string name = 2;
string desc = 3;
ColorStyle color_style = 4;
}
message AppId {
string value = 1;
}
message UpdateAppPayload {
string app_id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; };
oneof one_of_color_style { ColorStyle color_style = 4; };
oneof one_of_is_trash { bool is_trash = 5; };
}
message UpdateAppParams {
string app_id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; };
oneof one_of_color_style { ColorStyle color_style = 4; };
oneof one_of_is_trash { bool is_trash = 5; };
}

View File

@ -1,25 +0,0 @@
syntax = "proto3";
message Trash {
string id = 1;
string name = 2;
int64 modified_time = 3;
int64 create_time = 4;
TrashType ty = 5;
}
message RepeatedTrash {
repeated Trash items = 1;
}
message RepeatedTrashId {
repeated TrashId items = 1;
bool delete_all = 2;
}
message TrashId {
string id = 1;
TrashType ty = 2;
}
enum TrashType {
Unknown = 0;
TrashView = 1;
TrashApp = 2;
}

View File

@ -1,65 +0,0 @@
syntax = "proto3";
message View {
string id = 1;
string belong_to_id = 2;
string name = 3;
ViewDataType data_type = 4;
int64 modified_time = 5;
int64 create_time = 6;
int32 plugin_type = 7;
}
message RepeatedView {
repeated View items = 1;
}
message RepeatedViewId {
repeated string items = 1;
}
message CreateViewPayload {
string belong_to_id = 1;
string name = 2;
string desc = 3;
oneof one_of_thumbnail { string thumbnail = 4; };
ViewDataType data_type = 5;
int32 plugin_type = 6;
bytes data = 7;
}
message CreateViewParams {
string belong_to_id = 1;
string name = 2;
string desc = 3;
string thumbnail = 4;
ViewDataType data_type = 5;
string view_id = 6;
bytes data = 7;
int32 plugin_type = 8;
}
message ViewId {
string value = 1;
}
message UpdateViewPayload {
string view_id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; };
oneof one_of_thumbnail { string thumbnail = 4; };
}
message UpdateViewParams {
string view_id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; };
oneof one_of_thumbnail { string thumbnail = 4; };
}
message MoveFolderItemPayload {
string item_id = 1;
int32 from = 2;
int32 to = 3;
MoveFolderItemType ty = 4;
}
enum ViewDataType {
TextBlock = 0;
Grid = 1;
}
enum MoveFolderItemType {
MoveApp = 0;
MoveView = 1;
}

View File

@ -1,12 +0,0 @@
syntax = "proto3";
import "view.proto";
message ViewInfo {
string id = 1;
string belong_to_id = 2;
string name = 3;
string desc = 4;
ViewDataType data_type = 5;
RepeatedView belongings = 6;
string ext_data = 7;
}

View File

@ -1,40 +0,0 @@
syntax = "proto3";
import "app.proto";
import "view.proto";
message Workspace {
string id = 1;
string name = 2;
string desc = 3;
RepeatedApp apps = 4;
int64 modified_time = 5;
int64 create_time = 6;
}
message RepeatedWorkspace {
repeated Workspace items = 1;
}
message CreateWorkspacePayload {
string name = 1;
string desc = 2;
}
message CreateWorkspaceParams {
string name = 1;
string desc = 2;
}
message WorkspaceId {
oneof one_of_value { string value = 1; };
}
message CurrentWorkspaceSetting {
Workspace workspace = 1;
oneof one_of_latest_view { View latest_view = 2; };
}
message UpdateWorkspaceRequest {
string id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; };
}
message UpdateWorkspaceParams {
string id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; };
}

View File

@ -1,87 +0,0 @@
syntax = "proto3";
message Field {
string id = 1;
string name = 2;
string desc = 3;
FieldType field_type = 4;
bool frozen = 5;
bool visibility = 6;
int32 width = 7;
bool is_primary = 8;
}
message FieldOrder {
string field_id = 1;
}
message GridFieldChangeset {
string grid_id = 1;
repeated IndexField inserted_fields = 2;
repeated FieldOrder deleted_fields = 3;
repeated Field updated_fields = 4;
}
message IndexField {
Field field = 1;
int32 index = 2;
}
message GetEditFieldContextPayload {
string grid_id = 1;
oneof one_of_field_id { string field_id = 2; };
FieldType field_type = 3;
}
message EditFieldPayload {
string grid_id = 1;
string field_id = 2;
FieldType field_type = 3;
bool create_if_not_exist = 4;
}
message FieldTypeOptionContext {
string grid_id = 1;
Field grid_field = 2;
bytes type_option_data = 3;
}
message FieldTypeOptionData {
string grid_id = 1;
Field field = 2;
bytes type_option_data = 3;
}
message RepeatedField {
repeated Field items = 1;
}
message RepeatedFieldOrder {
repeated FieldOrder items = 1;
}
message InsertFieldPayload {
string grid_id = 1;
Field field = 2;
bytes type_option_data = 3;
oneof one_of_start_field_id { string start_field_id = 4; };
}
message UpdateFieldTypeOptionPayload {
string grid_id = 1;
string field_id = 2;
bytes type_option_data = 3;
}
message QueryFieldPayload {
string grid_id = 1;
RepeatedFieldOrder field_orders = 2;
}
message FieldChangesetPayload {
string field_id = 1;
string grid_id = 2;
oneof one_of_name { string name = 3; };
oneof one_of_desc { string desc = 4; };
oneof one_of_field_type { FieldType field_type = 5; };
oneof one_of_frozen { bool frozen = 6; };
oneof one_of_visibility { bool visibility = 7; };
oneof one_of_width { int32 width = 8; };
oneof one_of_type_option_data { bytes type_option_data = 9; };
}
enum FieldType {
RichText = 0;
Number = 1;
DateTime = 2;
SingleSelect = 3;
MultiSelect = 4;
Checkbox = 5;
URL = 6;
}

View File

@ -1,87 +0,0 @@
syntax = "proto3";
import "field.proto";
message Grid {
string id = 1;
repeated FieldOrder field_orders = 2;
repeated GridBlockOrder block_orders = 3;
}
message RowOrder {
string row_id = 1;
string block_id = 2;
int32 height = 3;
}
message Row {
string id = 1;
map<string, Cell> cell_by_field_id = 2;
int32 height = 3;
}
message RepeatedRow {
repeated Row items = 1;
}
message RepeatedGridBlock {
repeated GridBlock items = 1;
}
message GridBlockOrder {
string block_id = 1;
repeated RowOrder row_orders = 2;
}
message IndexRowOrder {
RowOrder row_order = 1;
oneof one_of_index { int32 index = 2; };
}
message UpdatedRowOrder {
RowOrder row_order = 1;
Row row = 2;
}
message GridRowsChangeset {
string block_id = 1;
repeated IndexRowOrder inserted_rows = 2;
repeated RowOrder deleted_rows = 3;
repeated UpdatedRowOrder updated_rows = 4;
}
message GridBlock {
string id = 1;
repeated RowOrder row_orders = 2;
}
message Cell {
string field_id = 1;
bytes data = 2;
}
message RepeatedCell {
repeated Cell items = 1;
}
message CreateGridPayload {
string name = 1;
}
message GridId {
string value = 1;
}
message GridBlockId {
string value = 1;
}
message CreateRowPayload {
string grid_id = 1;
oneof one_of_start_row_id { string start_row_id = 2; };
}
message QueryGridBlocksPayload {
string grid_id = 1;
repeated GridBlockOrder block_orders = 2;
}
message MoveItemPayload {
string grid_id = 1;
string item_id = 2;
int32 from_index = 3;
int32 to_index = 4;
MoveItemType ty = 5;
}
message CellChangeset {
string grid_id = 1;
string row_id = 2;
string field_id = 3;
oneof one_of_cell_content_changeset { string cell_content_changeset = 4; };
}
enum MoveItemType {
MoveField = 0;
MoveRow = 1;
}

View File

@ -1,23 +0,0 @@
syntax = "proto3";
message ViewExtData {
ViewFilter filter = 1;
ViewGroup group = 2;
ViewSort sort = 3;
}
message ViewFilter {
oneof one_of_field_id { string field_id = 1; };
}
message ViewGroup {
oneof one_of_group_field_id { string group_field_id = 1; };
oneof one_of_sub_group_field_id { string sub_group_field_id = 2; };
}
message ViewSort {
oneof one_of_field_id { string field_id = 1; };
}
message GridInfoChangesetPayload {
string grid_id = 1;
oneof one_of_filter { ViewFilter filter = 2; };
oneof one_of_group { ViewGroup group = 3; };
oneof one_of_sort { ViewSort sort = 4; };
}

View File

@ -1,8 +0,0 @@
syntax = "proto3";
message FolderInfo {
string folder_id = 1;
string text = 2;
int64 rev_id = 3;
int64 base_rev_id = 4;
}

View File

@ -1,25 +0,0 @@
syntax = "proto3";
message Revision {
int64 base_rev_id = 1;
int64 rev_id = 2;
bytes delta_data = 3;
string md5 = 4;
string object_id = 5;
RevType ty = 6;
string user_id = 7;
}
message RepeatedRevision {
repeated Revision items = 1;
}
message RevId {
int64 value = 1;
}
message RevisionRange {
int64 start = 1;
int64 end = 2;
}
enum RevType {
DeprecatedLocal = 0;
DeprecatedRemote = 1;
}

View File

@ -1,29 +0,0 @@
syntax = "proto3";
import "revision.proto";
message CreateTextBlockParams {
string id = 1;
RepeatedRevision revisions = 2;
}
message TextBlockInfo {
string block_id = 1;
string text = 2;
int64 rev_id = 3;
int64 base_rev_id = 4;
}
message ResetTextBlockParams {
string block_id = 1;
RepeatedRevision revisions = 2;
}
message TextBlockDelta {
string block_id = 1;
string delta_str = 2;
}
message NewDocUser {
string user_id = 1;
int64 rev_id = 2;
string doc_id = 3;
}
message TextBlockId {
string value = 1;
}

View File

@ -1,29 +0,0 @@
syntax = "proto3";
import "revision.proto";
message ClientRevisionWSData {
string object_id = 1;
ClientRevisionWSDataType ty = 2;
RepeatedRevision revisions = 3;
string data_id = 4;
}
message ServerRevisionWSData {
string object_id = 1;
ServerRevisionWSDataType ty = 2;
bytes data = 3;
}
message NewDocumentUser {
string user_id = 1;
string doc_id = 2;
bytes revision_data = 3;
}
enum ClientRevisionWSDataType {
ClientPushRev = 0;
ClientPing = 1;
}
enum ServerRevisionWSDataType {
ServerAck = 0;
ServerPushRev = 1;
ServerPullRev = 2;
UserConnect = 3;
}

View File

@ -1,34 +0,0 @@
syntax = "proto3";
message SignInPayload {
string email = 1;
string password = 2;
string name = 3;
}
message SignInParams {
string email = 1;
string password = 2;
string name = 3;
}
message SignInResponse {
string user_id = 1;
string name = 2;
string email = 3;
string token = 4;
}
message SignUpPayload {
string email = 1;
string name = 2;
string password = 3;
}
message SignUpParams {
string email = 1;
string name = 2;
string password = 3;
}
message SignUpResponse {
string user_id = 1;
string name = 2;
string email = 3;
string token = 4;
}

View File

@ -1,23 +0,0 @@
syntax = "proto3";
message UserToken {
string token = 1;
}
message UserProfile {
string id = 1;
string email = 2;
string name = 3;
string token = 4;
}
message UpdateUserPayload {
string id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_email { string email = 3; };
oneof one_of_password { string password = 4; };
}
message UpdateUserParams {
string id = 1;
oneof one_of_name { string name = 2; };
oneof one_of_email { string email = 3; };
oneof one_of_password { string password = 4; };
}

View File

@ -1,15 +0,0 @@
syntax = "proto3";
message UserPreferences {
string user_id = 1;
AppearanceSettings appearance_setting = 2;
}
message AppearanceSettings {
string theme = 1;
LocaleSettings locale = 2;
bool reset_as_default = 3;
}
message LocaleSettings {
string language_code = 1;
string country_code = 2;
}

View File

@ -2,7 +2,7 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_results)]
use crate::code_gen::protobuf_file::template::{EnumTemplate, StructTemplate};
use crate::code_gen::protobuf_file::template::{EnumTemplate, StructTemplate, RUST_TYPE_MAP};
use crate::code_gen::protobuf_file::{parse_crate_info_from_path, ProtoFile, ProtobufCrateContext};
use crate::code_gen::util::*;
use fancy_regex::Regex;
@ -57,19 +57,28 @@ fn parse_files_protobuf(proto_crate_path: &Path, proto_output_path: &Path) -> Ve
let structs = get_ast_structs(&ast);
let proto_file = format!("{}.proto", &file_name);
let proto_file_path = path_string_with_component(proto_output_path, vec![&proto_file]);
let mut proto_file_content = find_proto_syntax(proto_file_path.as_ref());
let proto_syntax = find_proto_syntax(proto_file_path.as_ref());
let mut proto_content = String::new();
// The types that are not defined in the current file.
let mut ref_types: Vec<String> = vec![];
structs.iter().for_each(|s| {
let mut struct_template = StructTemplate::new();
struct_template.set_message_struct_name(&s.name);
s.fields.iter().filter(|f| f.attrs.pb_index().is_some()).for_each(|f| {
struct_template.set_field(f);
});
s.fields
.iter()
.filter(|field| field.attrs.pb_index().is_some())
.for_each(|field| {
ref_types.push(field.ty_as_str().to_string());
struct_template.set_field(field);
});
let s = struct_template.render().unwrap();
proto_file_content.push_str(s.as_ref());
proto_file_content.push('\n');
proto_content.push_str(s.as_ref());
proto_content.push('\n');
});
let enums = get_ast_enums(&ast);
@ -77,17 +86,26 @@ fn parse_files_protobuf(proto_crate_path: &Path, proto_output_path: &Path) -> Ve
let mut enum_template = EnumTemplate::new();
enum_template.set_message_enum(e);
let s = enum_template.render().unwrap();
proto_file_content.push_str(s.as_ref());
proto_file_content.push('\n');
proto_content.push_str(s.as_ref());
ref_types.push(e.name.clone());
proto_content.push('\n');
});
if !enums.is_empty() || !structs.is_empty() {
let structs: Vec<String> = structs.iter().map(|s| s.name.clone()).collect();
let enums: Vec<String> = enums.iter().map(|e| e.name.clone()).collect();
ref_types.retain(|s| !structs.contains(&s));
ref_types.retain(|s| !enums.contains(&s));
let info = ProtoFile {
file_path: path.clone(),
file_name: file_name.clone(),
structs: structs.iter().map(|s| s.name.clone()).collect(),
enums: enums.iter().map(|e| e.name.clone()).collect(),
generated_content: proto_file_content.clone(),
ref_types,
structs,
enums,
syntax: proto_syntax,
content: proto_content,
};
gen_proto_vec.push(info);
}
@ -148,12 +166,12 @@ pub struct Struct<'a> {
lazy_static! {
static ref SYNTAX_REGEX: Regex = Regex::new("syntax.*;").unwrap();
static ref IMPORT_REGEX: Regex = Regex::new("(import\\s).*;").unwrap();
// static ref IMPORT_REGEX: Regex = Regex::new("(import\\s).*;").unwrap();
}
fn find_proto_syntax(path: &str) -> String {
if !Path::new(path).exists() {
return String::from("syntax = \"proto3\";\n\n");
return String::from("syntax = \"proto3\";\n");
}
let mut result = String::new();
@ -165,13 +183,12 @@ fn find_proto_syntax(path: &str) -> String {
////Result<Option<Match<'t>>>
if let Ok(Some(m)) = SYNTAX_REGEX.find(line) {
result.push_str(m.as_str());
result.push('\n');
}
if let Ok(Some(m)) = IMPORT_REGEX.find(line) {
result.push_str(m.as_str());
result.push('\n');
}
// if let Ok(Some(m)) = IMPORT_REGEX.find(line) {
// result.push_str(m.as_str());
// result.push('\n');
// }
});
result.push('\n');

View File

@ -7,6 +7,7 @@ use crate::code_gen::protobuf_file::proto_info::ProtobufCrateContext;
use crate::code_gen::protobuf_file::ProtoFile;
use crate::code_gen::util::*;
use crate::code_gen::ProtoCache;
use std::collections::HashMap;
use std::fs::File;
use std::path::Path;
use std::{fs::OpenOptions, io::Write};
@ -49,16 +50,72 @@ impl ProtoGenerator {
}
fn write_proto_files(crate_contexts: &[ProtobufCrateContext]) {
let file_path_content_map = crate_contexts
.iter()
.map(|ctx| {
ctx.files
.iter()
.map(|file| {
(
file.file_path.clone(),
ProtoFileSymbol {
file_name: file.file_name.clone(),
symbols: file.symbols(),
},
)
})
.collect::<HashMap<String, ProtoFileSymbol>>()
})
.flatten()
.collect::<HashMap<String, ProtoFileSymbol>>();
for context in crate_contexts {
let dir = context.protobuf_crate.proto_output_path();
context.files.iter().for_each(|info| {
let proto_file = format!("{}.proto", &info.file_name);
context.files.iter().for_each(|file| {
// syntax
let mut file_content = file.syntax.clone();
// import
file_content.push_str(&gen_import_content(&file, &file_path_content_map));
// content
file_content.push_str(&file.content);
let proto_file = format!("{}.proto", &file.file_name);
let proto_file_path = path_string_with_component(&dir, vec![&proto_file]);
save_content_to_file_with_diff_prompt(&info.generated_content, proto_file_path.as_ref());
save_content_to_file_with_diff_prompt(&file_content, proto_file_path.as_ref());
});
}
}
fn gen_import_content(current_file: &ProtoFile, file_path_symbols_map: &HashMap<String, ProtoFileSymbol>) -> String {
let mut import_files: Vec<String> = vec![];
file_path_symbols_map
.iter()
.for_each(|(file_path, proto_file_symbols)| {
if file_path != &current_file.file_path {
current_file.ref_types.iter().for_each(|ref_type| {
if proto_file_symbols.symbols.contains(ref_type) {
let import_file = format!("import \"{}.proto\";", proto_file_symbols.file_name);
if !import_files.contains(&import_file) {
import_files.push(import_file);
}
}
});
}
});
if import_files.len() == 1 {
format!("{}\n", import_files.pop().unwrap())
} else {
import_files.join("\n")
}
}
struct ProtoFileSymbol {
file_name: String,
symbols: Vec<String>,
}
fn write_rust_crate_mod_file(crate_contexts: &[ProtobufCrateContext]) {
for context in crate_contexts {
let mod_path = context.protobuf_crate.proto_model_mod_file();

View File

@ -106,8 +106,24 @@ pub struct ProtoFile {
pub file_path: String,
pub file_name: String,
pub structs: Vec<String>,
// store the type of current file using
pub ref_types: Vec<String>,
pub enums: Vec<String>,
pub generated_content: String,
// proto syntax. "proto3" or "proto2"
pub syntax: String,
// proto message content
pub content: String,
}
impl ProtoFile {
pub fn symbols(&self) -> Vec<String> {
let mut symbols = self.structs.clone();
let mut enum_symbols = self.enums.clone();
symbols.append(&mut enum_symbols);
symbols
}
}
pub fn parse_crate_info_from_path(roots: Vec<String>) -> Vec<ProtobufCrate> {

View File

@ -4,7 +4,7 @@ use phf::phf_map;
use tera::Context;
// Protobuf data type : https://developers.google.com/protocol-buffers/docs/proto3
static RUST_TYPE_MAP: phf::Map<&'static str, &'static str> = phf_map! {
pub static RUST_TYPE_MAP: phf::Map<&'static str, &'static str> = phf_map! {
"String" => "string",
"i64" => "int64",
"i32" => "int32",

View File

@ -1,11 +0,0 @@
syntax = "proto3";
message WSError {
ErrorCode code = 1;
string msg = 2;
}
enum ErrorCode {
InternalError = 0;
UnsupportedMessage = 1;
Unauthorized = 2;
}

View File

@ -1,11 +0,0 @@
syntax = "proto3";
message WebSocketRawMessage {
WSChannel channel = 1;
bytes data = 2;
}
enum WSChannel {
Document = 0;
Folder = 1;
Grid = 2;
}