Skip to content

Commit

Permalink
Merge branch 'main' into reduce-ci-time
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-ho committed Sep 5, 2024
2 parents ff5f6a4 + 7a23cb1 commit 10a036d
Show file tree
Hide file tree
Showing 27 changed files with 1,597 additions and 429 deletions.
27 changes: 27 additions & 0 deletions admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,30 @@ func withShardKey[T any](conn *connect.Request[T], keys ...string) *connect.Requ

return conn
}

// DeleteAccount deletes the user's account.
func (c *Client) DeleteAccount(ctx context.Context, username, password string) error {
_, err := c.client.DeleteAccount(ctx, connect.NewRequest(&api.DeleteAccountRequest{
Username: username,
Password: password,
}))
if err != nil {
return err
}

return nil
}

// ChangePassword changes the user's password.
func (c *Client) ChangePassword(ctx context.Context, username, password, newPassword string) error {
_, err := c.client.ChangePassword(ctx, connect.NewRequest(&api.ChangePasswordRequest{
Username: username,
CurrentPassword: password,
NewPassword: newPassword,
}))
if err != nil {
return err
}

return nil
}
27 changes: 27 additions & 0 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ func FromOperations(pbOps []*api.Operation) ([]operations.Operation, error) {
op, err = fromTreeEdit(decoded.TreeEdit)
case *api.Operation_TreeStyle_:
op, err = fromTreeStyle(decoded.TreeStyle)
case *api.Operation_ArraySet_:
op, err = fromArraySet(decoded.ArraySet)
default:
return nil, ErrUnsupportedOperation
}
Expand Down Expand Up @@ -539,6 +541,31 @@ func fromTreeStyle(pbTreeStyle *api.Operation_TreeStyle) (*operations.TreeStyle,
), nil
}

func fromArraySet(pbSetByIndex *api.Operation_ArraySet) (*operations.ArraySet, error) {
parentCreatedAt, err := fromTimeTicket(pbSetByIndex.ParentCreatedAt)
if err != nil {
return nil, err
}
createdAt, err := fromTimeTicket(pbSetByIndex.CreatedAt)
if err != nil {
return nil, err
}
elem, err := fromElement(pbSetByIndex.Value)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbSetByIndex.ExecutedAt)
if err != nil {
return nil, err
}
return operations.NewArraySet(
parentCreatedAt,
createdAt,
elem,
executedAt,
), nil
}

func fromCreatedAtMapByActor(
pbCreatedAtMapByActor map[string]*api.TimeTicket,
) (map[string]*time.Ticket, error) {
Expand Down
18 changes: 18 additions & 0 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func ToOperations(ops []operations.Operation) ([]*api.Operation, error) {
pbOperation.Body, err = toTreeEdit(op)
case *operations.TreeStyle:
pbOperation.Body, err = toTreeStyle(op)
case *operations.ArraySet:
pbOperation.Body, err = toArraySet(op)
default:
return nil, ErrUnsupportedOperation
}
Expand Down Expand Up @@ -375,6 +377,22 @@ func toTreeStyle(style *operations.TreeStyle) (*api.Operation_TreeStyle_, error)
}, nil
}

func toArraySet(setByIndex *operations.ArraySet) (*api.Operation_ArraySet_, error) {
pbElem, err := toJSONElementSimple(setByIndex.Value())
if err != nil {
return nil, err
}

return &api.Operation_ArraySet_{
ArraySet: &api.Operation_ArraySet{
ParentCreatedAt: ToTimeTicket(setByIndex.ParentCreatedAt()),
CreatedAt: ToTimeTicket(setByIndex.CreatedAt()),
Value: pbElem,
ExecutedAt: ToTimeTicket(setByIndex.ExecutedAt()),
},
}, nil
}

func toJSONElementSimple(elem crdt.Element) (*api.JSONElementSimple, error) {
switch elem := elem.(type) {
case *crdt.Object:
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/admin.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,12 @@ components:
description: ""
title: add
type: object
arraySet:
$ref: '#/components/schemas/yorkie.v1.Operation.ArraySet'
additionalProperties: false
description: ""
title: array_set
type: object
edit:
$ref: '#/components/schemas/yorkie.v1.Operation.Edit'
additionalProperties: false
Expand Down Expand Up @@ -1257,6 +1263,36 @@ components:
type: object
title: Add
type: object
yorkie.v1.Operation.ArraySet:
additionalProperties: false
description: ""
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: ArraySet
type: object
yorkie.v1.Operation.Edit:
additionalProperties: false
description: ""
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/resources.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ components:
description: ""
title: add
type: object
arraySet:
$ref: '#/components/schemas/yorkie.v1.Operation.ArraySet'
additionalProperties: false
description: ""
title: array_set
type: object
edit:
$ref: '#/components/schemas/yorkie.v1.Operation.Edit'
additionalProperties: false
Expand Down Expand Up @@ -766,6 +772,36 @@ components:
type: object
title: Add
type: object
yorkie.v1.Operation.ArraySet:
additionalProperties: false
description: ""
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: ArraySet
type: object
yorkie.v1.Operation.Edit:
additionalProperties: false
description: ""
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/yorkie.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,12 @@ components:
description: ""
title: add
type: object
arraySet:
$ref: '#/components/schemas/yorkie.v1.Operation.ArraySet'
additionalProperties: false
description: ""
title: array_set
type: object
edit:
$ref: '#/components/schemas/yorkie.v1.Operation.Edit'
additionalProperties: false
Expand Down Expand Up @@ -750,6 +756,36 @@ components:
type: object
title: Add
type: object
yorkie.v1.Operation.ArraySet:
additionalProperties: false
description: ""
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: ArraySet
type: object
yorkie.v1.Operation.Edit:
additionalProperties: false
description: ""
Expand Down
Loading

0 comments on commit 10a036d

Please sign in to comment.