WIP add snapshot methods to debug api

This commit is contained in:
mcrakhman 2022-12-03 14:43:18 +01:00 committed by Mikhail Iudin
parent 78f67d221c
commit e6f4ff2f20
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
8 changed files with 717 additions and 202 deletions

View File

@ -362,6 +362,7 @@ type AddTextRequest struct {
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
DocumentId string `protobuf:"bytes,2,opt,name=documentId,proto3" json:"documentId,omitempty"`
Text string `protobuf:"bytes,3,opt,name=text,proto3" json:"text,omitempty"`
IsSnapshot bool `protobuf:"varint,4,opt,name=isSnapshot,proto3" json:"isSnapshot,omitempty"`
}
func (m *AddTextRequest) Reset() { *m = AddTextRequest{} }
@ -418,9 +419,17 @@ func (m *AddTextRequest) GetText() string {
return ""
}
func (m *AddTextRequest) GetIsSnapshot() bool {
if m != nil {
return m.IsSnapshot
}
return false
}
type AddTextResponse struct {
DocumentId string `protobuf:"bytes,1,opt,name=documentId,proto3" json:"documentId,omitempty"`
HeadId string `protobuf:"bytes,2,opt,name=headId,proto3" json:"headId,omitempty"`
RootId string `protobuf:"bytes,3,opt,name=rootId,proto3" json:"rootId,omitempty"`
}
func (m *AddTextResponse) Reset() { *m = AddTextResponse{} }
@ -470,6 +479,13 @@ func (m *AddTextResponse) GetHeadId() string {
return ""
}
func (m *AddTextResponse) GetRootId() string {
if m != nil {
return m.RootId
}
return ""
}
type DumpTreeRequest struct {
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
DocumentId string `protobuf:"bytes,2,opt,name=documentId,proto3" json:"documentId,omitempty"`
@ -866,6 +882,110 @@ func (m *LoadSpaceResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_LoadSpaceResponse proto.InternalMessageInfo
type TreeParamsRequest struct {
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
DocumentId string `protobuf:"bytes,2,opt,name=documentId,proto3" json:"documentId,omitempty"`
}
func (m *TreeParamsRequest) Reset() { *m = TreeParamsRequest{} }
func (m *TreeParamsRequest) String() string { return proto.CompactTextString(m) }
func (*TreeParamsRequest) ProtoMessage() {}
func (*TreeParamsRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_fc31080c27db9707, []int{19}
}
func (m *TreeParamsRequest) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TreeParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TreeParamsRequest.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TreeParamsRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_TreeParamsRequest.Merge(m, src)
}
func (m *TreeParamsRequest) XXX_Size() int {
return m.Size()
}
func (m *TreeParamsRequest) XXX_DiscardUnknown() {
xxx_messageInfo_TreeParamsRequest.DiscardUnknown(m)
}
var xxx_messageInfo_TreeParamsRequest proto.InternalMessageInfo
func (m *TreeParamsRequest) GetSpaceId() string {
if m != nil {
return m.SpaceId
}
return ""
}
func (m *TreeParamsRequest) GetDocumentId() string {
if m != nil {
return m.DocumentId
}
return ""
}
type TreeParamsResponse struct {
RootId string `protobuf:"bytes,1,opt,name=rootId,proto3" json:"rootId,omitempty"`
HeadIds []string `protobuf:"bytes,2,rep,name=headIds,proto3" json:"headIds,omitempty"`
}
func (m *TreeParamsResponse) Reset() { *m = TreeParamsResponse{} }
func (m *TreeParamsResponse) String() string { return proto.CompactTextString(m) }
func (*TreeParamsResponse) ProtoMessage() {}
func (*TreeParamsResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_fc31080c27db9707, []int{20}
}
func (m *TreeParamsResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TreeParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TreeParamsResponse.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TreeParamsResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_TreeParamsResponse.Merge(m, src)
}
func (m *TreeParamsResponse) XXX_Size() int {
return m.Size()
}
func (m *TreeParamsResponse) XXX_DiscardUnknown() {
xxx_messageInfo_TreeParamsResponse.DiscardUnknown(m)
}
var xxx_messageInfo_TreeParamsResponse proto.InternalMessageInfo
func (m *TreeParamsResponse) GetRootId() string {
if m != nil {
return m.RootId
}
return ""
}
func (m *TreeParamsResponse) GetHeadIds() []string {
if m != nil {
return m.HeadIds
}
return nil
}
func init() {
proto.RegisterType((*CreateSpaceRequest)(nil), "clientapi.CreateSpaceRequest")
proto.RegisterType((*CreateSpaceResponse)(nil), "clientapi.CreateSpaceResponse")
@ -886,47 +1006,54 @@ func init() {
proto.RegisterType((*AllSpacesResponse)(nil), "clientapi.AllSpacesResponse")
proto.RegisterType((*LoadSpaceRequest)(nil), "clientapi.LoadSpaceRequest")
proto.RegisterType((*LoadSpaceResponse)(nil), "clientapi.LoadSpaceResponse")
proto.RegisterType((*TreeParamsRequest)(nil), "clientapi.TreeParamsRequest")
proto.RegisterType((*TreeParamsResponse)(nil), "clientapi.TreeParamsResponse")
}
func init() { proto.RegisterFile("api/apiproto/protos/api.proto", fileDescriptor_fc31080c27db9707) }
var fileDescriptor_fc31080c27db9707 = []byte{
// 553 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x95, 0xcb, 0x6e, 0xd3, 0x40,
0x14, 0x86, 0xe3, 0x5c, 0xda, 0xfa, 0x04, 0x25, 0xe9, 0x69, 0x1b, 0x19, 0x43, 0xad, 0x30, 0x52,
0xab, 0x48, 0x54, 0x89, 0x28, 0x2b, 0x76, 0x84, 0x44, 0x48, 0x11, 0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x46, 0xcb, 0x1b, 0x57, 0xa3, 0x15, 0x39, 0xf8,
0x23, 0x34, 0x74, 0xfb, 0x61, 0x27, 0x37, 0x3f, 0xe3, 0x37, 0xfb, 0xd9, 0x3d, 0x15, 0x29, 0x56,
0x37, 0x96, 0x86, 0x2d, 0xb4, 0xb1, 0x86, 0x2d, 0x76, 0x25, 0xbe, 0x86, 0x43, 0xe9, 0x1a, 0x7c,
0xac, 0x54, 0xeb, 0x4e, 0xb5, 0xed, 0xa2, 0x94, 0x24, 0x0c, 0xe1, 0x28, 0xd6, 0x37, 0xaa, 0x75,
0x19, 0x07, 0xd9, 0x4f, 0x0a, 0x73, 0x29, 0x24, 0x56, 0xa8, 0x06, 0xc9, 0x38, 0x42, 0x83, 0xe4,
0x24, 0xfd, 0x16, 0xcc, 0x44, 0x97, 0x98, 0xa9, 0xd4, 0x14, 0x6c, 0x3f, 0x2d, 0x4e, 0xa6, 0x9c,
0x44, 0x80, 0x1a, 0x27, 0x2b, 0x62, 0x8d, 0x93, 0xd3, 0xec, 0x9b, 0xcb, 0x5f, 0x5b, 0xc7, 0xb8,
0xdb, 0x3a, 0xc6, 0x9f, 0xad, 0x63, 0xfc, 0xd8, 0x39, 0xa5, 0xbb, 0x9d, 0x53, 0xfa, 0xbd, 0x73,
0x4a, 0x9f, 0x1e, 0xa9, 0xff, 0x3c, 0x5f, 0x0e, 0xc4, 0xd7, 0xcb, 0xbf, 0x01, 0x00, 0x00, 0xff,
0xff, 0x5d, 0x2e, 0xfd, 0x34, 0x90, 0x06, 0x00, 0x00,
// 630 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcd, 0x6e, 0xda, 0x40,
0x10, 0x8e, 0x09, 0x49, 0xf0, 0x50, 0xf1, 0xb3, 0x49, 0x90, 0xeb, 0x06, 0x8b, 0xae, 0x94, 0x08,
0xa9, 0x11, 0xa8, 0xe9, 0xa9, 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6, 0xb4,
0xdf, 0x6b, 0x4b, 0xfb, 0xb1, 0xb1, 0xf6, 0x1e, 0x36, 0xd6, 0xde, 0xaf, 0x8d, 0xb5, 0xf7, 0xf9,
0x89, 0xfc, 0x9f, 0xfc, 0xe5, 0x90, 0x7f, 0xbd, 0xfa, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x82, 0x87,
0xed, 0x38, 0xaa, 0x07, 0x00, 0x00,
}
func (m *CreateSpaceRequest) Marshal() (dAtA []byte, err error) {
@ -1175,6 +1302,16 @@ func (m *AddTextRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if m.IsSnapshot {
i--
if m.IsSnapshot {
dAtA[i] = 1
} else {
dAtA[i] = 0
}
i--
dAtA[i] = 0x20
}
if len(m.Text) > 0 {
i -= len(m.Text)
copy(dAtA[i:], m.Text)
@ -1219,6 +1356,13 @@ func (m *AddTextResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.RootId) > 0 {
i -= len(m.RootId)
copy(dAtA[i:], m.RootId)
i = encodeVarintApi(dAtA, i, uint64(len(m.RootId)))
i--
dAtA[i] = 0x1a
}
if len(m.HeadId) > 0 {
i -= len(m.HeadId)
copy(dAtA[i:], m.HeadId)
@ -1517,6 +1661,82 @@ func (m *LoadSpaceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *TreeParamsRequest) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TreeParamsRequest) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TreeParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.DocumentId) > 0 {
i -= len(m.DocumentId)
copy(dAtA[i:], m.DocumentId)
i = encodeVarintApi(dAtA, i, uint64(len(m.DocumentId)))
i--
dAtA[i] = 0x12
}
if len(m.SpaceId) > 0 {
i -= len(m.SpaceId)
copy(dAtA[i:], m.SpaceId)
i = encodeVarintApi(dAtA, i, uint64(len(m.SpaceId)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *TreeParamsResponse) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TreeParamsResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TreeParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.HeadIds) > 0 {
for iNdEx := len(m.HeadIds) - 1; iNdEx >= 0; iNdEx-- {
i -= len(m.HeadIds[iNdEx])
copy(dAtA[i:], m.HeadIds[iNdEx])
i = encodeVarintApi(dAtA, i, uint64(len(m.HeadIds[iNdEx])))
i--
dAtA[i] = 0x12
}
}
if len(m.RootId) > 0 {
i -= len(m.RootId)
copy(dAtA[i:], m.RootId)
i = encodeVarintApi(dAtA, i, uint64(len(m.RootId)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintApi(dAtA []byte, offset int, v uint64) int {
offset -= sovApi(v)
base := offset
@ -1642,6 +1862,9 @@ func (m *AddTextRequest) Size() (n int) {
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
if m.IsSnapshot {
n += 2
}
return n
}
@ -1659,6 +1882,10 @@ func (m *AddTextResponse) Size() (n int) {
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
l = len(m.RootId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
return n
}
@ -1785,6 +2012,42 @@ func (m *LoadSpaceResponse) Size() (n int) {
return n
}
func (m *TreeParamsRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.SpaceId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
l = len(m.DocumentId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
return n
}
func (m *TreeParamsResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.RootId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
if len(m.HeadIds) > 0 {
for _, s := range m.HeadIds {
l = len(s)
n += 1 + l + sovApi(uint64(l))
}
}
return n
}
func sovApi(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -2508,6 +2771,26 @@ func (m *AddTextRequest) Unmarshal(dAtA []byte) error {
}
m.Text = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field IsSnapshot", wireType)
}
var v int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
m.IsSnapshot = bool(v != 0)
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
@ -2622,6 +2905,38 @@ func (m *AddTextResponse) Unmarshal(dAtA []byte) error {
}
m.HeadId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field RootId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.RootId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
@ -3383,6 +3698,234 @@ func (m *LoadSpaceResponse) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *TreeParamsRequest) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TreeParamsRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TreeParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.SpaceId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DocumentId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.DocumentId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthApi
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *TreeParamsResponse) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TreeParamsResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TreeParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field RootId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.RootId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field HeadIds", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.HeadIds = append(m.HeadIds, string(dAtA[iNdEx:postIndex]))
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthApi
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipApi(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0

View File

@ -46,6 +46,7 @@ type DRPCClientApiClient interface {
DeleteDocument(ctx context.Context, in *DeleteDocumentRequest) (*DeleteDocumentResponse, error)
AddText(ctx context.Context, in *AddTextRequest) (*AddTextResponse, error)
DumpTree(ctx context.Context, in *DumpTreeRequest) (*DumpTreeResponse, error)
TreeParams(ctx context.Context, in *TreeParamsRequest) (*TreeParamsResponse, error)
AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error)
AllSpaces(ctx context.Context, in *AllSpacesRequest) (*AllSpacesResponse, error)
LoadSpace(ctx context.Context, in *LoadSpaceRequest) (*LoadSpaceResponse, error)
@ -115,6 +116,15 @@ func (c *drpcClientApiClient) DumpTree(ctx context.Context, in *DumpTreeRequest)
return out, nil
}
func (c *drpcClientApiClient) TreeParams(ctx context.Context, in *TreeParamsRequest) (*TreeParamsResponse, error) {
out := new(TreeParamsResponse)
err := c.cc.Invoke(ctx, "/clientapi.ClientApi/TreeParams", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *drpcClientApiClient) AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error) {
out := new(AllTreesResponse)
err := c.cc.Invoke(ctx, "/clientapi.ClientApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
@ -149,6 +159,7 @@ type DRPCClientApiServer interface {
DeleteDocument(context.Context, *DeleteDocumentRequest) (*DeleteDocumentResponse, error)
AddText(context.Context, *AddTextRequest) (*AddTextResponse, error)
DumpTree(context.Context, *DumpTreeRequest) (*DumpTreeResponse, error)
TreeParams(context.Context, *TreeParamsRequest) (*TreeParamsResponse, error)
AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error)
AllSpaces(context.Context, *AllSpacesRequest) (*AllSpacesResponse, error)
LoadSpace(context.Context, *LoadSpaceRequest) (*LoadSpaceResponse, error)
@ -180,6 +191,10 @@ func (s *DRPCClientApiUnimplementedServer) DumpTree(context.Context, *DumpTreeRe
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
func (s *DRPCClientApiUnimplementedServer) TreeParams(context.Context, *TreeParamsRequest) (*TreeParamsResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
func (s *DRPCClientApiUnimplementedServer) AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
@ -194,7 +209,7 @@ func (s *DRPCClientApiUnimplementedServer) LoadSpace(context.Context, *LoadSpace
type DRPCClientApiDescription struct{}
func (DRPCClientApiDescription) NumMethods() int { return 9 }
func (DRPCClientApiDescription) NumMethods() int { return 10 }
func (DRPCClientApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n {
@ -253,6 +268,15 @@ func (DRPCClientApiDescription) Method(n int) (string, drpc.Encoding, drpc.Recei
)
}, DRPCClientApiServer.DumpTree, true
case 6:
return "/clientapi.ClientApi/TreeParams", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCClientApiServer).
TreeParams(
ctx,
in1.(*TreeParamsRequest),
)
}, DRPCClientApiServer.TreeParams, true
case 7:
return "/clientapi.ClientApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCClientApiServer).
@ -261,7 +285,7 @@ func (DRPCClientApiDescription) Method(n int) (string, drpc.Encoding, drpc.Recei
in1.(*AllTreesRequest),
)
}, DRPCClientApiServer.AllTrees, true
case 7:
case 8:
return "/clientapi.ClientApi/AllSpaces", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCClientApiServer).
@ -270,7 +294,7 @@ func (DRPCClientApiDescription) Method(n int) (string, drpc.Encoding, drpc.Recei
in1.(*AllSpacesRequest),
)
}, DRPCClientApiServer.AllSpaces, true
case 8:
case 9:
return "/clientapi.ClientApi/LoadSpace", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCClientApiServer).
@ -384,6 +408,22 @@ func (x *drpcClientApi_DumpTreeStream) SendAndClose(m *DumpTreeResponse) error {
return x.CloseSend()
}
type DRPCClientApi_TreeParamsStream interface {
drpc.Stream
SendAndClose(*TreeParamsResponse) error
}
type drpcClientApi_TreeParamsStream struct {
drpc.Stream
}
func (x *drpcClientApi_TreeParamsStream) SendAndClose(m *TreeParamsResponse) error {
if err := x.MsgSend(m, drpcEncoding_File_api_apiproto_protos_api_proto{}); err != nil {
return err
}
return x.CloseSend()
}
type DRPCClientApi_AllTreesStream interface {
drpc.Stream
SendAndClose(*AllTreesResponse) error

View File

@ -10,6 +10,7 @@ service ClientApi {
rpc DeleteDocument(DeleteDocumentRequest) returns(DeleteDocumentResponse);
rpc AddText(AddTextRequest) returns(AddTextResponse);
rpc DumpTree(DumpTreeRequest) returns(DumpTreeResponse);
rpc TreeParams(TreeParamsRequest) returns(TreeParamsResponse);
rpc AllTrees(AllTreesRequest) returns(AllTreesResponse);
rpc AllSpaces(AllSpacesRequest) returns(AllSpacesResponse);
rpc LoadSpace(LoadSpaceRequest) returns(LoadSpaceResponse);
@ -49,11 +50,13 @@ message AddTextRequest {
string spaceId = 1;
string documentId = 2;
string text = 3;
bool isSnapshot = 4;
}
message AddTextResponse {
string documentId = 1;
string headId = 2;
string rootId = 3;
}
message DumpTreeRequest {
@ -90,4 +93,14 @@ message LoadSpaceRequest {
}
message LoadSpaceResponse {
}
message TreeParamsRequest {
string spaceId = 1;
string documentId = 2;
}
message TreeParamsResponse {
string rootId = 1;
repeated string headIds = 2;
}

View File

@ -1,138 +0,0 @@
package api
import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"math/rand"
)
type Controller interface {
// DeriveSpace derives the space from current account
DeriveSpace() (id string, err error)
// CreateSpace creates new space with random data
CreateSpace() (id string, err error)
// AllSpaceIds returns ids of all spaces
AllSpaceIds() (ids []string, err error)
// LoadSpace asks node to load a particular space
LoadSpace(id string) (err error)
// CreateDocument creates new document in space
CreateDocument(spaceId string) (id string, err error)
// DeleteDocument deletes a document from space
DeleteDocument(spaceId, documentId string) (err error)
// AllDocumentIds gets all ids of documents in space
AllDocumentIds(spaceId string) (ids []string, err error)
// AllDocumentHeads gets heads of all documents
AllDocumentHeads(spaceId string) (ids []diffservice.TreeHeads, err error)
// AddText adds text to space document
AddText(spaceId, documentId, text string) (head string, err error)
// DumpDocumentTree dumps the tree data into string
DumpDocumentTree(spaceId, documentId string) (dump string, err error)
ValidInvites(spaceId string) (invites []string, err error)
GenerateInvite(spaceId string) (invite string, err error)
JoinSpace(invite string) (err error)
}
type controller struct {
spaceService clientspace.Service
storageService storage.ClientStorage
docService document.Service
account account.Service
}
func newController(spaceService clientspace.Service,
storageService storage.ClientStorage,
docService document.Service,
account account.Service) Controller {
return &controller{
spaceService: spaceService,
storageService: storageService,
docService: docService,
account: account,
}
}
func (c *controller) DeriveSpace() (id string, err error) {
sp, err := c.spaceService.DeriveSpace(context.Background(), commonspace.SpaceDerivePayload{
SigningKey: c.account.Account().SignKey,
EncryptionKey: c.account.Account().EncKey,
})
if err != nil {
return
}
id = sp.Id()
return
}
func (c *controller) CreateSpace() (id string, err error) {
key, err := symmetric.NewRandom()
if err != nil {
return
}
sp, err := c.spaceService.CreateSpace(context.Background(), commonspace.SpaceCreatePayload{
SigningKey: c.account.Account().SignKey,
EncryptionKey: c.account.Account().EncKey,
ReadKey: key.Bytes(),
ReplicationKey: rand.Uint64(),
})
if err != nil {
return
}
id = sp.Id()
return
}
func (c *controller) AllSpaceIds() (ids []string, err error) {
return c.storageService.AllSpaceIds()
}
func (c *controller) LoadSpace(id string) (err error) {
_, err = c.spaceService.GetSpace(context.Background(), id)
return
}
func (c *controller) CreateDocument(spaceId string) (id string, err error) {
return c.docService.CreateDocument(spaceId)
}
func (c *controller) DeleteDocument(spaceId, documentId string) (err error) {
return c.docService.DeleteDocument(spaceId, documentId)
}
func (c *controller) AllDocumentIds(spaceId string) (ids []string, err error) {
return c.docService.AllDocumentIds(spaceId)
}
func (c *controller) AllDocumentHeads(spaceId string) (ids []diffservice.TreeHeads, err error) {
return c.docService.AllDocumentHeads(spaceId)
}
func (c *controller) AddText(spaceId, documentId, text string) (head string, err error) {
return c.docService.AddText(spaceId, documentId, text)
}
func (c *controller) DumpDocumentTree(spaceId, documentId string) (dump string, err error) {
return c.docService.DumpDocumentTree(spaceId, documentId)
}
func (c *controller) ValidInvites(spaceId string) (invites []string, err error) {
//TODO implement me
panic("implement me")
}
func (c *controller) GenerateInvite(spaceId string) (invite string, err error) {
//TODO implement me
panic("implement me")
}
func (c *controller) JoinSpace(invite string) (err error) {
//TODO implement me
panic("implement me")
}

View File

@ -3,14 +3,24 @@ package api
import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/api/apiproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"math/rand"
)
type rpcHandler struct {
controller Controller
spaceService clientspace.Service
storageService storage.ClientStorage
docService document.Service
account account.Service
}
func (r *rpcHandler) LoadSpace(ctx context.Context, request *apiproto.LoadSpaceRequest) (resp *apiproto.LoadSpaceResponse, err error) {
err = r.controller.LoadSpace(request.SpaceId)
_, err = r.spaceService.GetSpace(context.Background(), request.SpaceId)
if err != nil {
return
}
@ -19,7 +29,20 @@ func (r *rpcHandler) LoadSpace(ctx context.Context, request *apiproto.LoadSpaceR
}
func (r *rpcHandler) CreateSpace(ctx context.Context, request *apiproto.CreateSpaceRequest) (resp *apiproto.CreateSpaceResponse, err error) {
id, err := r.controller.CreateSpace()
key, err := symmetric.NewRandom()
if err != nil {
return
}
sp, err := r.spaceService.CreateSpace(context.Background(), commonspace.SpaceCreatePayload{
SigningKey: r.account.Account().SignKey,
EncryptionKey: r.account.Account().EncKey,
ReadKey: key.Bytes(),
ReplicationKey: rand.Uint64(),
})
if err != nil {
return
}
id := sp.Id()
if err != nil {
return
}
@ -28,7 +51,14 @@ func (r *rpcHandler) CreateSpace(ctx context.Context, request *apiproto.CreateSp
}
func (r *rpcHandler) DeriveSpace(ctx context.Context, request *apiproto.DeriveSpaceRequest) (resp *apiproto.DeriveSpaceResponse, err error) {
id, err := r.controller.DeriveSpace()
sp, err := r.spaceService.DeriveSpace(context.Background(), commonspace.SpaceDerivePayload{
SigningKey: r.account.Account().SignKey,
EncryptionKey: r.account.Account().EncKey,
})
if err != nil {
return
}
id := sp.Id()
if err != nil {
return
}
@ -37,7 +67,7 @@ func (r *rpcHandler) DeriveSpace(ctx context.Context, request *apiproto.DeriveSp
}
func (r *rpcHandler) CreateDocument(ctx context.Context, request *apiproto.CreateDocumentRequest) (resp *apiproto.CreateDocumentResponse, err error) {
id, err := r.controller.CreateDocument(request.SpaceId)
id, err := r.docService.CreateDocument(request.SpaceId)
if err != nil {
return
}
@ -46,7 +76,7 @@ func (r *rpcHandler) CreateDocument(ctx context.Context, request *apiproto.Creat
}
func (r *rpcHandler) DeleteDocument(ctx context.Context, request *apiproto.DeleteDocumentRequest) (resp *apiproto.DeleteDocumentResponse, err error) {
err = r.controller.DeleteDocument(request.SpaceId, request.DocumentId)
err = r.docService.DeleteDocument(request.SpaceId, request.DocumentId)
if err != nil {
return
}
@ -55,19 +85,20 @@ func (r *rpcHandler) DeleteDocument(ctx context.Context, request *apiproto.Delet
}
func (r *rpcHandler) AddText(ctx context.Context, request *apiproto.AddTextRequest) (resp *apiproto.AddTextResponse, err error) {
head, err := r.controller.AddText(request.SpaceId, request.DocumentId, request.Text)
root, head, err := r.docService.AddText(request.SpaceId, request.DocumentId, request.Text, request.IsSnapshot)
if err != nil {
return
}
resp = &apiproto.AddTextResponse{
DocumentId: request.DocumentId,
HeadId: head,
RootId: root,
}
return
}
func (r *rpcHandler) DumpTree(ctx context.Context, request *apiproto.DumpTreeRequest) (resp *apiproto.DumpTreeResponse, err error) {
dump, err := r.controller.DumpDocumentTree(request.SpaceId, request.DocumentId)
dump, err := r.docService.DumpDocumentTree(request.SpaceId, request.DocumentId)
if err != nil {
return
}
@ -78,7 +109,7 @@ func (r *rpcHandler) DumpTree(ctx context.Context, request *apiproto.DumpTreeReq
}
func (r *rpcHandler) AllTrees(ctx context.Context, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) {
heads, err := r.controller.AllDocumentHeads(request.SpaceId)
heads, err := r.docService.AllDocumentHeads(request.SpaceId)
if err != nil {
return
}
@ -94,10 +125,24 @@ func (r *rpcHandler) AllTrees(ctx context.Context, request *apiproto.AllTreesReq
}
func (r *rpcHandler) AllSpaces(ctx context.Context, request *apiproto.AllSpacesRequest) (resp *apiproto.AllSpacesResponse, err error) {
ids, err := r.controller.AllSpaceIds()
ids, err := r.storageService.AllSpaceIds()
if err != nil {
return
}
resp = &apiproto.AllSpacesResponse{SpaceIds: ids}
return
}
func (r *rpcHandler) TreeParams(ctx context.Context, request *apiproto.TreeParamsRequest) (resp *apiproto.TreeParamsResponse, err error) {
root, heads, err := r.docService.TreeParams(request.SpaceId, request.DocumentId)
if err != nil {
return
}
resp = &apiproto.TreeParamsResponse{
RootId: root,
HeadIds: heads,
}
return
}
//TreeParams(spaceId, documentId string) (root string, head []string, err error)

View File

@ -30,18 +30,20 @@ type Service interface {
}
type service struct {
controller Controller
transport secure.Service
cfg *config.Config
transport secure.Service
cfg *config.Config
spaceService clientspace.Service
storageService clientstorage.ClientStorage
docService document.Service
account account.Service
*server.BaseDrpcServer
}
func (s *service) Init(a *app.App) (err error) {
s.controller = newController(
a.MustComponent(clientspace.CName).(clientspace.Service),
a.MustComponent(storage.CName).(clientstorage.ClientStorage),
a.MustComponent(document.CName).(document.Service),
a.MustComponent(account.CName).(account.Service))
s.spaceService = a.MustComponent(clientspace.CName).(clientspace.Service)
s.storageService = a.MustComponent(storage.CName).(clientstorage.ClientStorage)
s.docService = a.MustComponent(document.CName).(document.Service)
s.account = a.MustComponent(account.CName).(account.Service)
s.cfg = a.MustComponent(config.CName).(*config.Config)
s.transport = a.MustComponent(secure.CName).(secure.Service)
return nil
@ -62,7 +64,7 @@ func (s *service) Run(ctx context.Context) (err error) {
if err != nil {
return
}
return apiproto.DRPCRegisterClientApi(s, &rpcHandler{s.controller})
return apiproto.DRPCRegisterClientApi(s, &rpcHandler{s.spaceService, s.storageService, s.docService, s.account})
}
func (s *service) Close(ctx context.Context) (err error) {

View File

@ -18,8 +18,9 @@ type Service interface {
DeleteDocument(spaceId, documentId string) (err error)
AllDocumentIds(spaceId string) (ids []string, err error)
AllDocumentHeads(spaceId string) (ids []diffservice.TreeHeads, err error)
AddText(spaceId, documentId, text string) (head string, err error)
AddText(spaceId, documentId, text string, isSnapshot bool) (root, head string, err error)
DumpDocumentTree(spaceId, documentId string) (dump string, err error)
TreeParams(spaceId, documentId string) (root string, head []string, err error)
}
const CName = "client.document"
@ -86,12 +87,12 @@ func (s *service) AllDocumentHeads(spaceId string) (ids []diffservice.TreeHeads,
return
}
func (s *service) AddText(spaceId, documentId, text string) (head string, err error) {
func (s *service) AddText(spaceId, documentId, text string, isSnapshot bool) (root, head string, err error) {
doc, err := s.cache.GetDocument(context.Background(), spaceId, documentId)
if err != nil {
return
}
return doc.AddText(text)
return doc.AddText(text, isSnapshot)
}
func (s *service) DumpDocumentTree(spaceId, documentId string) (dump string, err error) {
@ -101,3 +102,11 @@ func (s *service) DumpDocumentTree(spaceId, documentId string) (dump string, err
}
return doc.DebugDump()
}
func (s *service) TreeParams(spaceId, documentId string) (root string, heads []string, err error) {
tr, err := s.cache.GetTree(context.Background(), spaceId, documentId)
if err != nil {
return
}
return tr.Root().Id, tr.Heads(), nil
}

View File

@ -13,7 +13,7 @@ import (
type TextDocument interface {
tree.ObjectTree
InnerTree() tree.ObjectTree
AddText(text string) (string, error)
AddText(text string, isSnapshot bool) (string, string, error)
Text() (string, error)
TreeDump() string
Close() error
@ -60,7 +60,7 @@ func (t *textDocument) InnerTree() tree.ObjectTree {
return t.ObjectTree
}
func (t *textDocument) AddText(text string) (head string, err error) {
func (t *textDocument) AddText(text string, isSnapshot bool) (root, head string, err error) {
content := &testchanges.TextContent_TextAppend{
TextAppend: &testchanges.TextAppend{Text: text},
}
@ -80,11 +80,12 @@ func (t *textDocument) AddText(text string) (head string, err error) {
Data: res,
Key: t.account.Account().SignKey,
Identity: t.account.Account().Identity,
IsSnapshot: false,
IsSnapshot: isSnapshot,
})
if err != nil {
return
}
root = t.Root().Id
head = addRes.Heads[0]
return
}