Skip to content

Commit

Permalink
Cleanup proto (#614)
Browse files Browse the repository at this point in the history
* Remove unused client id(key) from API response

* Change clientID type from bytes to string in the API
  • Loading branch information
chacha912 authored Aug 18, 2023
1 parent b111ab1 commit cf74a80
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 680 deletions.
346 changes: 172 additions & 174 deletions api/yorkie/v1/resources.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,5 @@ enum DocEventType {

message DocEvent {
DocEventType type = 1;
bytes publisher = 2;
string publisher = 2;
}
561 changes: 117 additions & 444 deletions api/yorkie/v1/yorkie.pb.go

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions api/yorkie/v1/yorkie.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,45 @@ message ActivateClientRequest {
}

message ActivateClientResponse {
string client_key = 1;
bytes client_id = 2;
string client_id = 1;
}

message DeactivateClientRequest {
bytes client_id = 1;
string client_id = 1;
}

message DeactivateClientResponse {
bytes client_id = 1;
}

message AttachDocumentRequest {
bytes client_id = 1;
string client_id = 1;
ChangePack change_pack = 2;
}

message AttachDocumentResponse {
bytes client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
string document_id = 1;
ChangePack change_pack = 2;
}

message DetachDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
bool remove_if_not_attached = 4;
}

message DetachDocumentResponse {
string client_key = 1;
ChangePack change_pack = 2;
}

message WatchDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
}

message WatchDocumentResponse {
message Initialization {
repeated bytes client_ids = 1;
repeated string client_ids = 1;
}

oneof body {
Expand All @@ -94,24 +90,22 @@ message WatchDocumentResponse {
}

message RemoveDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
}

message RemoveDocumentResponse {
string client_key = 1;
ChangePack change_pack = 2;
ChangePack change_pack = 1;
}

message PushPullChangesRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
bool push_only = 4;
}

message PushPullChangesResponse {
bytes client_id = 1;
ChangePack change_pack = 2;
ChangePack change_pack = 1;
}
18 changes: 9 additions & 9 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (c *Client) Activate(ctx context.Context) error {
return err
}

clientID, err := time.ActorIDFromBytes(response.ClientId)
clientID, err := time.ActorIDFromHex(response.ClientId)
if err != nil {
return err
}
Expand All @@ -232,7 +232,7 @@ func (c *Client) Deactivate(ctx context.Context) error {
}

_, err := c.client.DeactivateClient(withShardKey(ctx, c.options.APIKey), &api.DeactivateClientRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
})
if err != nil {
return err
Expand Down Expand Up @@ -276,7 +276,7 @@ func (c *Client) Attach(ctx context.Context, doc *document.Document, options ...
res, err := c.client.AttachDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.AttachDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
ChangePack: pbChangePack,
},
)
Expand Down Expand Up @@ -349,7 +349,7 @@ func (c *Client) Detach(ctx context.Context, doc *document.Document, options ...
res, err := c.client.DetachDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.DetachDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
ChangePack: pbChangePack,
RemoveIfNotAttached: opts.removeIfNotAttached,
Expand Down Expand Up @@ -412,7 +412,7 @@ func (c *Client) Watch(
stream, err := c.client.WatchDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.WatchDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
},
)
Expand All @@ -425,7 +425,7 @@ func (c *Client) Watch(
case *api.WatchDocumentResponse_Initialization_:
var clientIDs []string
for _, clientID := range resp.Initialization.ClientIds {
id, err := time.ActorIDFromBytes(clientID)
id, err := time.ActorIDFromHex(clientID)
if err != nil {
return nil, err
}
Expand All @@ -440,7 +440,7 @@ func (c *Client) Watch(
return nil, err
}

cli, err := time.ActorIDFromBytes(resp.Event.Publisher)
cli, err := time.ActorIDFromHex(resp.Event.Publisher)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -581,7 +581,7 @@ func (c *Client) pushPullChanges(ctx context.Context, opt SyncOptions) error {
res, err := c.client.PushPullChanges(
withShardKey(ctx, c.options.APIKey, opt.key.String()),
&api.PushPullChangesRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
ChangePack: pbChangePack,
PushOnly: opt.mode == types.SyncModePushOnly,
Expand Down Expand Up @@ -626,7 +626,7 @@ func (c *Client) Remove(ctx context.Context, doc *document.Document) error {
res, err := c.client.RemoveDocument(
withShardKey(ctx, c.options.APIKey, doc.Key().String()),
&api.RemoveDocumentRequest{
ClientId: c.id.Bytes(),
ClientId: c.id.String(),
DocumentId: attachment.docID.String(),
ChangePack: pbChangePack,
},
Expand Down
4 changes: 1 addition & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ func TestClient(t *testing.T) {

t.Run("x-shard-key test", func(t *testing.T) {
dummyID := types.ID("000000000000000000000000")
dummyActorID, err := dummyID.Bytes()
assert.NoError(t, err)

testServer, addr := dialTestYorkieServer(t)
defer testServer.Stop()
Expand All @@ -113,7 +111,7 @@ func TestClient(t *testing.T) {
assert.Equal(t, "dummy-api-key", data[types.ShardKey][0])

return &api.ActivateClientResponse{
ClientId: dummyActorID,
ClientId: dummyID.String(),
}, nil
},
)
Expand Down
13 changes: 7 additions & 6 deletions server/rpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ var (
defaultProjectName = "default"
invalidSlugName = "@#$%^&*()_+"

nilClientID, _ = hex.DecodeString("000000000000000000000000")
emptyClientID, _ = hex.DecodeString("")
invalidClientID, _ = hex.DecodeString("invalid")
nilClientID = "000000000000000000000000"
emptyClientID = ""
invalidClientID = "invalid"

testRPCServer *rpc.Server
testRPCAddr = fmt.Sprintf("localhost:%d", helper.RPCPort)
Expand Down Expand Up @@ -387,6 +387,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
)
assert.NoError(t, err)

actorID, _ := hex.DecodeString(activateResp.ClientId)
resPack, err := testClient.AttachDocument(
context.Background(),
&api.AttachDocumentRequest{
Expand All @@ -398,7 +399,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
Id: &api.ChangeID{
ClientSeq: 1,
Lamport: 1,
ActorId: activateResp.ClientId,
ActorId: actorID,
},
}},
},
Expand All @@ -418,7 +419,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
Id: &api.ChangeID{
ClientSeq: 2,
Lamport: 2,
ActorId: activateResp.ClientId,
ActorId: actorID,
},
}},
},
Expand All @@ -438,7 +439,7 @@ func TestSDKRPCServerBackend(t *testing.T) {
Id: &api.ChangeID{
ClientSeq: 3,
Lamport: 3,
ActorId: activateResp.ClientId,
ActorId: actorID,
},
}},
},
Expand Down
37 changes: 12 additions & 25 deletions server/rpc/yorkie_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,8 @@ func (s *yorkieServer) ActivateClient(
return nil, err
}

pbClientID, err := cli.ID.Bytes()
if err != nil {
return nil, err
}

return &api.ActivateClientResponse{
ClientKey: cli.Key,
ClientId: pbClientID,
ClientId: cli.ID.String(),
}, nil
}

Expand All @@ -85,7 +79,7 @@ func (s *yorkieServer) DeactivateClient(
ctx context.Context,
req *api.DeactivateClientRequest,
) (*api.DeactivateClientResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand All @@ -97,27 +91,20 @@ func (s *yorkieServer) DeactivateClient(
}

project := projects.From(ctx)
cli, err := clients.Deactivate(ctx, s.backend.DB, project.ID, types.IDFromActorID(actorID))
_, err = clients.Deactivate(ctx, s.backend.DB, project.ID, types.IDFromActorID(actorID))
if err != nil {
return nil, err
}

pbClientID, err := cli.ID.Bytes()
if err != nil {
return nil, err
}

return &api.DeactivateClientResponse{
ClientId: pbClientID,
}, nil
return &api.DeactivateClientResponse{}, nil
}

// AttachDocument attaches the given document to the client.
func (s *yorkieServer) AttachDocument(
ctx context.Context,
req *api.AttachDocumentRequest,
) (*api.AttachDocumentResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -186,7 +173,7 @@ func (s *yorkieServer) DetachDocument(
ctx context.Context,
req *api.DetachDocumentRequest,
) (*api.DetachDocumentResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -268,7 +255,7 @@ func (s *yorkieServer) PushPullChanges(
ctx context.Context,
req *api.PushPullChangesRequest,
) (*api.PushPullChangesResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -348,7 +335,7 @@ func (s *yorkieServer) WatchDocument(
req *api.WatchDocumentRequest,
stream api.YorkieService_WatchDocumentServer,
) error {
clientID, err := time.ActorIDFromBytes(req.ClientId)
clientID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return err
}
Expand Down Expand Up @@ -404,9 +391,9 @@ func (s *yorkieServer) WatchDocument(
s.unwatchDoc(subscription, docID)
}()

var pbClientIDs [][]byte
var pbClientIDs []string
for _, id := range clientIDs {
pbClientIDs = append(pbClientIDs, id.Bytes())
pbClientIDs = append(pbClientIDs, id.String())
}
if err := stream.Send(&api.WatchDocumentResponse{
Body: &api.WatchDocumentResponse_Initialization_{
Expand Down Expand Up @@ -434,7 +421,7 @@ func (s *yorkieServer) WatchDocument(
Body: &api.WatchDocumentResponse_Event{
Event: &api.DocEvent{
Type: eventType,
Publisher: event.Publisher.Bytes(),
Publisher: event.Publisher.String(),
},
},
}); err != nil {
Expand All @@ -449,7 +436,7 @@ func (s *yorkieServer) RemoveDocument(
ctx context.Context,
req *api.RemoveDocumentRequest,
) (*api.RemoveDocumentResponse, error) {
actorID, err := time.ActorIDFromBytes(req.ClientId)
actorID, err := time.ActorIDFromHex(req.ClientId)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit cf74a80

Please sign in to comment.