Skip to content

Commit

Permalink
fix(daemon): The Breaking Change
Browse files Browse the repository at this point in the history
* Backend breaking change

* feat(frontend): unicode code points transform

* Bump protocol version to prevent talking to old peers

* Cleanup comments

* Hypermedia Documentation WIP

* Hypermedia Docs Continued

* Use spelled-out fields in blob data

* Final (almost) touches to the blob data

* Update Go to 1.23.2

* Fix formatting errors

* Fix linting errors

* ui: remove cursor pointer

* ui: drag window from titlebar window top bar

* Fix linter errors

* chore: fix test command to test shared

* WIP Robust Schema for Blocks

* breaking: HM Block types mostly working

* Disable experiments in settings

* Rename codeBlock to code

* editor: remove trailing nodes before publishing

* codeBlock => code

* Code block renamed

* soft disable accountType

* Rename ref to link in protobuf and backend

* Refactor tree crdt

* Rename @type to type

* frontend: values rename

* Deprecate original CRDT package

* Op ID encoding

* New RGA implementation

* WIP: tree crdt refactor

* Implement improved block hierarchy CRDT

* WIP wire in the new CRDT tree

* Break compatibility version

* Rename type descriminator field in Op to

---------

Co-authored-by: Horacio Herrera <[email protected]>
Co-authored-by: Eric Vicenti <[email protected]>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent 0c82362 commit ce8a6d6
Show file tree
Hide file tree
Showing 156 changed files with 6,248 additions and 4,103 deletions.
10 changes: 5 additions & 5 deletions backend/api/documents/v3alpha/access_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package documents
import (
"context"
"fmt"
"seed/backend/blob"
"seed/backend/core"
documents "seed/backend/genproto/documents/v3alpha"
"seed/backend/blob"
"seed/backend/util/cclock"
"seed/backend/util/errutil"
"time"

"github.com/ipfs/go-cid"
cbornode "github.com/ipfs/go-ipld-cbor"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (srv *Server) CreateCapability(ctx context.Context, in *documents.CreateCap
// TODO(burdiyan): Validate role according to the chain of capabilities.
role := in.Role.String()

cpb, err := blob.NewCapability(kp, del, acc, in.Path, role, time.Now().UnixMicro(), in.NoRecursive)
cpb, err := blob.NewCapability(kp, del, acc, in.Path, role, cclock.New().MustNow(), in.NoRecursive)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -146,11 +146,11 @@ func capToProto(c cid.Cid, cpb *blob.Capability) (*documents.Capability, error)
Id: c.String(),
Issuer: cpb.Issuer.String(),
Delegate: cpb.Delegate.String(),
Account: cpb.Account.String(),
Account: cpb.Space.String(),
Path: cpb.Path,
Role: documents.Role(role),
IsExact: cpb.NoRecursive,
CreateTime: timestamppb.New(time.UnixMicro(cpb.Ts)),
CreateTime: timestamppb.New(cpb.Ts),
}

return pb, nil
Expand Down
84 changes: 13 additions & 71 deletions backend/api/documents/v3alpha/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"fmt"
"seed/backend/api/documents/v3alpha/docmodel"
"seed/backend/blob"
"seed/backend/core"
documents "seed/backend/genproto/documents/v3alpha"
"seed/backend/hlc"
"seed/backend/blob"
"seed/backend/util/cclock"
"seed/backend/util/errutil"
"time"
"seed/backend/util/must"

"github.com/ipfs/go-cid"
cbornode "github.com/ipfs/go-ipld-cbor"
Expand Down Expand Up @@ -43,12 +43,12 @@ func (srv *Server) CreateComment(ctx context.Context, in *documents.CreateCommen
return nil, err
}

acc, err := core.DecodePrincipal(in.TargetAccount)
space, err := core.DecodePrincipal(in.TargetAccount)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to parse target account: %v", err)
}

clock := hlc.NewClock()
clock := cclock.New()

var (
threadRoot cid.Cid
Expand All @@ -75,7 +75,7 @@ func (srv *Server) CreateComment(ctx context.Context, in *documents.CreateCommen
threadRoot = replyParent
}

if err := clock.Track(hlc.Timestamp(rp.Ts)); err != nil {
if err := clock.Track(rp.Ts); err != nil {
return nil, err
}

Expand All @@ -84,13 +84,7 @@ func (srv *Server) CreateComment(ctx context.Context, in *documents.CreateCommen
}
}

target := blob.CommentTarget{
Account: acc,
Path: in.TargetPath,
Version: versionHeads,
}

blob, err := blob.NewComment(kp, cid.Undef, target, threadRoot, replyParent, commentContentFromProto(in.Content), int64(clock.MustNow()))
blob, err := blob.NewComment(kp, cid.Undef, space, in.TargetPath, versionHeads, threadRoot, replyParent, commentContentFromProto(in.Content), clock.MustNow())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -158,12 +152,12 @@ func (srv *Server) ListComments(ctx context.Context, in *documents.ListCommentsR
func commentToProto(c cid.Cid, cmt *blob.Comment) (*documents.Comment, error) {
pb := &documents.Comment{
Id: c.String(),
TargetAccount: cmt.Target.Account.String(),
TargetPath: cmt.Target.Path,
TargetVersion: docmodel.NewVersion(cmt.Target.Version...).String(),
TargetAccount: cmt.Space.String(),
TargetPath: cmt.Path,
TargetVersion: docmodel.NewVersion(cmt.Version...).String(),
Author: cmt.Author.String(),
Content: commentContentToProto(cmt.Body),
CreateTime: timestamppb.New(time.UnixMicro(cmt.Ts)),
CreateTime: timestamppb.New(cmt.Ts),
}

if cmt.ReplyParent.Defined() {
Expand All @@ -189,40 +183,14 @@ func commentContentToProto(in []blob.CommentBlock) []*documents.BlockNode {
out := make([]*documents.BlockNode, len(in))
for i, b := range in {
out[i] = &documents.BlockNode{
Block: &documents.Block{
Id: b.ID,
Type: b.Type,
Text: b.Text,
Ref: b.Ref,
Attributes: b.Attributes,
Annotations: annotationsToProto(b.Annotations),
},
Block: docmodel.BlockToProto(b.Block, cid.Undef),
Children: commentContentToProto(b.Children),
}
}

return out
}

func annotationsToProto(in []blob.Annotation) []*documents.Annotation {
if in == nil {
return nil
}

out := make([]*documents.Annotation, len(in))
for i, a := range in {
out[i] = &documents.Annotation{
Type: a.Type,
Ref: a.Ref,
Attributes: a.Attributes,
Starts: a.Starts,
Ends: a.Ends,
}
}

return out
}

func commentContentFromProto(in []*documents.BlockNode) []blob.CommentBlock {
if in == nil {
return nil
Expand All @@ -232,36 +200,10 @@ func commentContentFromProto(in []*documents.BlockNode) []blob.CommentBlock {

for i, n := range in {
out[i] = blob.CommentBlock{
Block: blob.Block{
ID: n.Block.Id,
Type: n.Block.Type,
Text: n.Block.Text,
Ref: n.Block.Ref,
Attributes: n.Block.Attributes,
Annotations: annotationsFromProto(n.Block.Annotations),
},
Block: must.Do2(docmodel.BlockFromProto(n.Block)),
Children: commentContentFromProto(n.Children),
}
}

return out
}

func annotationsFromProto(in []*documents.Annotation) []blob.Annotation {
if in == nil {
return nil
}

out := make([]blob.Annotation, len(in))
for i, a := range in {
out[i] = blob.Annotation{
Type: a.Type,
Ref: a.Ref,
Attributes: a.Attributes,
Starts: a.Starts,
Ends: a.Ends,
}
}

return out
}
3 changes: 0 additions & 3 deletions backend/api/documents/v3alpha/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"seed/backend/core/coretest"
pb "seed/backend/genproto/documents/v3alpha"
"seed/backend/testutil"
"seed/backend/util/debugx"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -89,6 +88,4 @@ func TestComments_Smoke(t *testing.T) {
require.NoError(t, err)

testutil.StructsEqual(want, list).Compare(t, "comment list must match")

debugx.Dump(list)
}
5 changes: 2 additions & 3 deletions backend/api/documents/v3alpha/dochistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"seed/backend/api/documents/v3alpha/docmodel"
"seed/backend/core"
documents "seed/backend/genproto/documents/v3alpha"
"seed/backend/hlc"
"seed/backend/util/apiutil"
"seed/backend/util/colx"
"seed/backend/util/errutil"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (srv *Server) ListDocumentChanges(ctx context.Context, in *documents.ListDo
Changes: make([]*documents.DocumentChangeInfo, 0, in.PageSize),
}

changes, err := doc.Entity().BFTDeps(slices.Collect(maps.Keys(doc.Entity().Heads())))
changes, err := doc.BFTDeps(slices.Collect(maps.Keys(doc.Heads())))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -97,7 +96,7 @@ func (srv *Server) ListDocumentChanges(ctx context.Context, in *documents.ListDo
Id: cc,
Author: change.Data.Author.String(),
Deps: colx.SliceMap(change.Data.Deps, cid.Cid.String),
CreateTime: timestamppb.New(hlc.Timestamp(change.Data.Ts).Time()),
CreateTime: timestamppb.New(change.Data.Ts),
})
}

Expand Down
Loading

0 comments on commit ce8a6d6

Please sign in to comment.