Skip to content

Commit

Permalink
Add edit_reverse operation for js-sdk test
Browse files Browse the repository at this point in the history
  • Loading branch information
hyemmie committed Sep 11, 2023
1 parent 3ff801a commit 284d6b2
Show file tree
Hide file tree
Showing 5 changed files with 1,167 additions and 179 deletions.
29 changes: 29 additions & 0 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ func FromOperations(pbOps []*api.Operation) ([]operations.Operation, error) {
op, err = fromRemove(decoded.Remove)
case *api.Operation_Edit_:
op, err = fromEdit(decoded.Edit)
case *api.Operation_EditReverse_:
op, err = fromEditReverse(decoded.EditReverse)
case *api.Operation_Style_:
op, err = fromStyle(decoded.Style)
case *api.Operation_Select_:
Expand Down Expand Up @@ -427,6 +429,33 @@ func fromEdit(pbEdit *api.Operation_Edit) (*operations.Edit, error) {
), nil
}

func fromEditReverse(pbEditReverse *api.Operation_EditReverse) (*operations.EditReverse, error) {
parentCreatedAt, err := fromTimeTicket(pbEditReverse.ParentCreatedAt)
if err != nil {
return nil, err
}

createdAtMapByActor, err := fromCreatedAtMapByActor(
pbEditReverse.CreatedAtMapByActor,
)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbEditReverse.ExecutedAt)
if err != nil {
return nil, err
}
return operations.NewEditReverse(
parentCreatedAt,
pbEditReverse.FromIdx,
pbEditReverse.ToIdx,
createdAtMapByActor,
pbEditReverse.Content,
pbEditReverse.Attributes,
executedAt,
), nil
}

func fromStyle(pbStyle *api.Operation_Style) (*operations.Style, error) {
parentCreatedAt, err := fromTimeTicket(pbStyle.ParentCreatedAt)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ func ToOperations(ops []operations.Operation) ([]*api.Operation, error) {
pbOperation.Body, err = toRemove(op)
case *operations.Edit:
pbOperation.Body, err = toEdit(op)
case *operations.EditReverse:
pbOperation.Body, err = toEditReverse(op)
case *operations.Style:
pbOperation.Body, err = toStyle(op)
case *operations.Increase:
Expand Down Expand Up @@ -351,6 +353,21 @@ func toEdit(e *operations.Edit) (*api.Operation_Edit_, error) {
}, nil
}

func toEditReverse(e *operations.EditReverse) (*api.Operation_EditReverse_, error) {
return &api.Operation_EditReverse_{
EditReverse: &api.Operation_EditReverse{
ParentCreatedAt: ToTimeTicket(e.ParentCreatedAt()),
FromIdx: e.FromIdx(),
ToIdx: e.ToIdx(),
CreatedAtMapByActor: toCreatedAtMapByActor(e.CreatedAtMapByActor()),
Content: e.Content(),
Attributes: e.Attributes(),
ExecutedAt: ToTimeTicket(e.ExecutedAt()),
},
}, nil
}


func toStyle(style *operations.Style) (*api.Operation_Style_, error) {
return &api.Operation_Style_{
Style: &api.Operation_Style{
Expand Down
Loading

0 comments on commit 284d6b2

Please sign in to comment.