Cleanup of proto

Co-authored-by: alemi.dev <me@alemi.dev>
This commit is contained in:
frelodev 2024-02-05 23:31:06 +01:00
parent d14f004f73
commit 3738f7beb4
7 changed files with 70 additions and 99 deletions

View file

@ -1,6 +1,7 @@
syntax = "proto2"; syntax = "proto2";
package auth_service; package auth;
// authenticates users, issuing tokens // authenticates users, issuing tokens
service Auth { service Auth {
@ -8,10 +9,12 @@ service Auth {
rpc Login (WorkspaceJoinRequest) returns (Token); rpc Login (WorkspaceJoinRequest) returns (Token);
} }
message Token { message Token {
required string token = 1; required string token = 1;
} }
message WorkspaceJoinRequest { message WorkspaceJoinRequest {
required string workspace_id = 1; required string workspace_id = 1;
required string username = 2; required string username = 2;

View file

@ -1,6 +1,6 @@
syntax = "proto2"; syntax = "proto2";
package buffer_service; package buffer;
// handle buffer changes, keep in sync users // handle buffer changes, keep in sync users
service Buffer { service Buffer {

18
proto/common.proto Normal file
View file

@ -0,0 +1,18 @@
syntax = "proto2";
package common;
// payload identifying user
message UserIdentity {
// user identifier
required string id = 1;
}
message UserList {
repeated UserIdentity users = 1;
}
message Empty{
//generic Empty message
}

View file

@ -1,8 +1,14 @@
syntax = "proto2"; syntax = "proto2";
package cursor; package cursor;
import "common.proto";
// handle cursor events and broadcast to all users
service Cursor {
// subscribe to a workspace's cursor events
rpc Attach (stream cursor.CursorEvent) returns (stream cursor.CursorEvent);
}
import "user.proto";
// empty request // empty request
message MovedResponse {} message MovedResponse {}
@ -26,7 +32,7 @@ message CursorPosition {
// cursor event, with user id and cursor position // cursor event, with user id and cursor position
message CursorEvent { message CursorEvent {
// user moving the cursor // user moving the cursor
required user.UserIdentity user = 1; required common.UserIdentity user = 1;
// new cursor position // new cursor position
required CursorPosition position = 2; required CursorPosition position = 2;
} }

View file

@ -1,11 +0,0 @@
syntax = "proto2";
package cursor_service;
import "cursor.proto";
import "user.proto";
// handle cursor events and broadcast to all users
service Cursor {
// subscribe to a workspace's cursor events
rpc Attach (stream cursor.CursorEvent) returns (stream cursor.CursorEvent);
}

View file

@ -1,83 +1,56 @@
syntax = "proto2"; syntax = "proto2";
package workspace; package workspace;
import "user.proto";
import "files.proto"; import "files.proto";
import "auth.proto";
import "common.proto";
message Empty {} service Workspace {
rpc CreateWorkspace (workspace.WorkspaceId) returns (common.Empty);
message TreeRequest {} // empty rpc RequestAccess (workspace.BufferPath) returns (auth.Token);
message UserRequest {} rpc LeaveWorkspace (workspace.WorkspaceId) returns (common.Empty);
message CursorResponse {} rpc CreateBuffer (workspace.BufferPath) returns (common.Empty);
message UserListRequest {} rpc ListBuffers (common.Empty) returns (files.BufferTree);
rpc ListUsers (common.Empty) returns (common.UserList);
message WorkspaceUserList { rpc ListBufferUsers (workspace.BufferPath) returns (common.UserList); //TODO discuss
repeated user.UserIdentity user = 1; rpc Attach (common.Empty) returns (stream workspace.WorkspaceEvent);
} rpc Delete (workspace.BufferPath) returns (common.Empty); //deletes buffer
message WorkspaceMessage {
required string id = 1; //unused???
}
enum WorkspaceEventType {
USER_JOIN = 0;
USER_LEAVE = 1;
FILE_CREATE = 2;
FILE_DELETE = 3;
FILE_RENAME = 4;
} }
message WorkspaceEvent { message WorkspaceEvent {
required string id = 1; // the id of the user, or the path of the file message UserJoin {
required WorkspaceEventType event = 2; required common.UserIdentity id = 1;
optional string extra = 3; // new name? extra info on user events etc...
} }
message UserLeave {
message JoinRequest { required common.UserIdentity id = 1;
required string username = 1;
required string password = 2;
} }
message FileCreate {
message AttachRequest { required string path = 1;
}
message FileRename {
required string before = 1;
required string after = 2;
}
message FileDelete {
required string path = 1; required string path = 1;
} }
message Token { oneof event {
required string token = 1; UserJoin join = 1;
UserLeave leave = 2;
FileCreate create = 3;
FileRename rename = 4;
FileDelete delete = 5;
}
} }
enum FileEventType { message BufferPath {
CREATE = 0;
DELETE = 1;
RENAME = 2;
}
message FileEvent {
required string bufferbuffertree = 1;
required FileEventType type = 2;
}
enum UserEventType {
JOIN = 0;
LEAVE = 1;
}
message UserEvent {
required user.UserIdentity user = 1;
required UserEventType type = 2;
}
message BufferPayload {
// buffer path to operate onto // buffer path to operate onto
required string path = 1; required string path = 1;
} }
message BufferListRequest {}
message UserList { message WorkspaceId {
repeated user.UserIdentity users = 1;
}
message WorkspaceDetails {
required string id = 1; required string id = 1;
} }

View file

@ -1,18 +0,0 @@
syntax = "proto2";
package workspace_service;
import "user.proto";
import "files.proto";
import "workspace.proto";
service Workspace {
rpc Attach (workspace.AttachRequest) returns (workspace.Token);
rpc LeaveWorkspace (workspace.WorkspaceDetails) returns (workspace.Empty);
rpc CreateWorkspace (workspace.WorkspaceDetails) returns (workspace.Empty);
rpc CreateBuffer (workspace.BufferPayload) returns (workspace.Empty);
rpc ListBuffers (workspace.BufferListRequest) returns (files.BufferTree);
rpc ListUsers (workspace.UserListRequest) returns (workspace.UserList);
rpc ListBufferUsers (workspace.BufferPayload) returns (workspace.UserList); //TODO discuss
rpc Join (workspace.JoinRequest) returns (stream workspace.WorkspaceEvent);
rpc Delete (workspace.BufferPayload) returns (workspace.Empty); //deletes buffer
}