Change updates format in yaml
This commit is contained in:
parent
6490f09662
commit
029fead117
@ -148,6 +148,10 @@ func (a *aclTree) rebuildFromThread(fromStart bool) error {
|
||||
return a.rebuildFromThread(true)
|
||||
}
|
||||
}
|
||||
// TODO: there is a question how we can validate not only that the full tree is built correctly
|
||||
// but also that the ACL prev ids are not messed up. I think we should probably compare the resulting
|
||||
// acl state with the acl state which is built in aclTreeFromStart
|
||||
|
||||
err = a.aclStateBuilder.Init(a.fullTree)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -2,6 +2,7 @@ package acltree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||
@ -46,6 +47,18 @@ func (ch *Change) IsACLChange() bool {
|
||||
return ch.Content.GetAclData() != nil
|
||||
}
|
||||
|
||||
func NewFromRawChange(rawChange *thread.RawChange) (*Change, error) {
|
||||
unmarshalled := &pb.ACLChange{}
|
||||
err := proto.Unmarshal(rawChange.Payload, unmarshalled)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ch := NewChange(rawChange.Id, unmarshalled)
|
||||
ch.Sign = rawChange.Signature
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func NewChange(id string, ch *pb.ACLChange) *Change {
|
||||
return &Change{
|
||||
Next: nil,
|
||||
|
||||
@ -30,10 +30,14 @@ type threadChange struct {
|
||||
changesDataDecrypted []byte
|
||||
}
|
||||
|
||||
type updateUseCase struct {
|
||||
changes map[string]*threadChange
|
||||
}
|
||||
|
||||
type ThreadBuilder struct {
|
||||
threadId string
|
||||
allChanges map[string]*threadChange
|
||||
updatedChanges map[string]*threadChange
|
||||
updates map[string]*updateUseCase
|
||||
heads []string
|
||||
orphans []string
|
||||
keychain *Keychain
|
||||
@ -43,7 +47,7 @@ type ThreadBuilder struct {
|
||||
func NewThreadBuilder(keychain *Keychain) *ThreadBuilder {
|
||||
return &ThreadBuilder{
|
||||
allChanges: make(map[string]*threadChange),
|
||||
updatedChanges: make(map[string]*threadChange),
|
||||
updates: make(map[string]*updateUseCase),
|
||||
keychain: keychain,
|
||||
}
|
||||
}
|
||||
@ -162,10 +166,11 @@ func (t *ThreadBuilder) GetChange(ctx context.Context, recordID string) (*thread
|
||||
return t.getChange(recordID, t.allChanges), nil
|
||||
}
|
||||
|
||||
func (t *ThreadBuilder) GetUpdatedChanges() []*thread.RawChange {
|
||||
func (t *ThreadBuilder) GetUpdates(useCase string) []*thread.RawChange {
|
||||
var res []*thread.RawChange
|
||||
for _, ch := range t.updatedChanges {
|
||||
rawCh := t.getChange(ch.id, t.updatedChanges)
|
||||
update := t.updates[useCase]
|
||||
for _, ch := range update.changes {
|
||||
rawCh := t.getChange(ch.id, update.changes)
|
||||
res = append(res, rawCh)
|
||||
}
|
||||
return res
|
||||
@ -216,14 +221,10 @@ func (t *ThreadBuilder) Parse(thread *YMLThread) {
|
||||
t.allChanges[newChange.id] = newChange
|
||||
}
|
||||
|
||||
for _, ch := range thread.UpdatedChanges {
|
||||
newChange := t.parseChange(ch)
|
||||
t.updatedChanges[newChange.id] = newChange
|
||||
}
|
||||
|
||||
t.parseGraph(thread)
|
||||
t.parseOrphans(thread)
|
||||
t.parseHeader(thread)
|
||||
t.parseUpdates(thread.Updates)
|
||||
}
|
||||
|
||||
func (t *ThreadBuilder) parseChange(ch *Change) *threadChange {
|
||||
@ -500,16 +501,29 @@ func (t *ThreadBuilder) traverseFromHeads(f func(t *threadChange) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ThreadBuilder) parseGraph(thread *YMLThread) {
|
||||
for _, node := range thread.Graph {
|
||||
rec := t.allChanges[node.Id]
|
||||
func (t *ThreadBuilder) parseUpdates(updates []*Update) {
|
||||
for _, update := range updates {
|
||||
useCase := &updateUseCase{
|
||||
changes: map[string]*threadChange{},
|
||||
}
|
||||
for _, ch := range update.Changes {
|
||||
newChange := t.parseChange(ch)
|
||||
useCase.changes[newChange.id] = newChange
|
||||
}
|
||||
for _, node := range update.Graph {
|
||||
rec := useCase.changes[node.Id]
|
||||
rec.AclHeadIds = node.ACLHeads
|
||||
rec.TreeHeadIds = node.TreeHeads
|
||||
rec.SnapshotBaseId = node.BaseSnapshot
|
||||
}
|
||||
|
||||
for _, node := range thread.UpdatedGraph {
|
||||
rec := t.updatedChanges[node.Id]
|
||||
t.updates[update.UseCase] = useCase
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ThreadBuilder) parseGraph(thread *YMLThread) {
|
||||
for _, node := range thread.Graph {
|
||||
rec := t.allChanges[node.Id]
|
||||
rec.AclHeadIds = node.ACLHeads
|
||||
rec.TreeHeadIds = node.TreeHeads
|
||||
rec.SnapshotBaseId = node.BaseSnapshot
|
||||
|
||||
@ -95,15 +95,20 @@ type Header struct {
|
||||
IsWorkspace bool `yaml:"isWorkspace"`
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
UseCase string `yaml:"useCase"`
|
||||
Changes []*Change `yaml:"changes"`
|
||||
Graph []*GraphNode `yaml:"graph"`
|
||||
}
|
||||
|
||||
type YMLThread struct {
|
||||
Description *ThreadDescription `yaml:"thread"`
|
||||
Changes []*Change `yaml:"changes"`
|
||||
UpdatedChanges []*Change `yaml:"updatedChanges"`
|
||||
Updates []*Update `yaml:"updates"`
|
||||
|
||||
Keys Keys `yaml:"keys"`
|
||||
|
||||
Graph []*GraphNode `yaml:"graph"`
|
||||
UpdatedGraph []*GraphNode `yaml:"updatedGraph"`
|
||||
|
||||
Heads []string `yaml:"heads"`
|
||||
Orphans []string `yaml:"orphans"`
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func Test_YamlParse(t *testing.T) {
|
||||
tb, _ := NewThreadBuilderWithTestName("userjoinexample.yml")
|
||||
tb, _ := NewThreadBuilderWithTestName("userjoinexampleupdate.yml")
|
||||
gr, _ := tb.Graph()
|
||||
fmt.Println(gr)
|
||||
}
|
||||
|
||||
@ -104,15 +104,3 @@ header:
|
||||
isWorkspace: false
|
||||
orphans:
|
||||
- "A.1.3"
|
||||
updatedChanges:
|
||||
- id: B.1.3
|
||||
identity: B
|
||||
changes:
|
||||
- textAppend:
|
||||
text: "second"
|
||||
readKey: key.Read.1
|
||||
updatedGraph:
|
||||
- id: B.1.3
|
||||
baseSnapshot: A.1.1
|
||||
aclHeads: [ B.1.1 ]
|
||||
treeHeads: [ B.1.2 ]
|
||||
|
||||
@ -106,7 +106,9 @@ header:
|
||||
isWorkspace: false
|
||||
orphans:
|
||||
- "A.1.3"
|
||||
updatedChanges:
|
||||
updates:
|
||||
- useCase: append
|
||||
changes:
|
||||
- id: B.1.3
|
||||
identity: B
|
||||
changes:
|
||||
@ -125,7 +127,7 @@ updatedChanges:
|
||||
- textAppend:
|
||||
text: "second"
|
||||
readKey: key.Read.1
|
||||
updatedGraph:
|
||||
graph:
|
||||
- id: B.1.3
|
||||
baseSnapshot: A.1.1
|
||||
aclHeads: [ B.1.1 ]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user