WIP work on document structure

This commit is contained in:
mcrakhman 2022-07-05 11:59:01 +02:00
parent 102b33c3dc
commit 3395f35b59
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B
4 changed files with 94 additions and 1 deletions

58
data/document.go Normal file
View File

@ -0,0 +1,58 @@
package data
import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/threadmodels"
)
type AccountData struct {
Identity string
EncKey threadmodels.EncryptionPrivKey
}
type Document struct {
thread threadmodels.Thread
stateProvider InitialStateProvider
accountData AccountData
decoder threadmodels.SigningPubKeyDecoder
aclTree *Tree
fullTree *Tree
aclTreeBuilder *ACLTreeBuilder
aclStateBuilder *ACLStateBuilder
}
type UpdateResult int
const (
UpdateResultAppend = iota
UpdateResultRebuild
UpdateResultExists
UpdateResultNoAction
)
func NewDocument(
thread threadmodels.Thread,
stateProvider InitialStateProvider,
accountData AccountData) *Document {
return &Document{
thread: thread,
stateProvider: stateProvider,
accountData: accountData,
decoder: threadmodels.NewEd25519Decoder(),
}
}
func (d *Document) Update(changes []*pb.ACLChange) (DocumentState, UpdateResult, error) {
return nil, 0, nil
}
func (d *Document) Build() (DocumentState, error) {
treeBuilder := NewTreeBuilder(d.thread, threadmodels.NewEd25519Decoder())
return treeBuilder.Build(fromStart)
return nil, nil
}
func (d *Document) State() DocumentState {
return nil
}

32
data/documentcontext.go Normal file
View File

@ -0,0 +1,32 @@
package data
import "github.com/anytypeio/go-anytype-infrastructure-experiments/data/threadmodels"
type documentContext struct {
aclTree *Tree
fullTree *Tree
identity string
encryptionKey threadmodels.EncryptionPrivKey
decoder threadmodels.SigningPubKeyDecoder
aclState *ACLState
docState DocumentState
changeCache map[string]*Change
identityKeys map[string]threadmodels.SigningPubKey
}
func newDocumentContext(
identity string,
encryptionKey threadmodels.EncryptionPrivKey,
decoder threadmodels.SigningPubKeyDecoder) *documentContext {
return &documentContext{
aclTree: &Tree{},
fullTree: &Tree{},
identity: identity,
encryptionKey: encryptionKey,
decoder: decoder,
aclState: nil,
docState: nil,
changeCache: make(map[string]*Change),
identityKeys: make(map[string]threadmodels.SigningPubKey),
}
}

View File

@ -2,6 +2,8 @@ syntax = "proto3";
package anytype; package anytype;
option go_package = "pb"; option go_package = "pb";
// TODO: move to separate package
message PlainTextChange { message PlainTextChange {
message Content { message Content {
oneof value { oneof value {

View File

@ -8,8 +8,9 @@ import (
type Thread interface { type Thread interface {
ID() string ID() string
Heads() []string Heads() []string
// TODO: add ACL heads
GetChange(ctx context.Context, recordID string) (*RawChange, error) GetChange(ctx context.Context, recordID string) (*RawChange, error)
//SetHeads(heads []string)
//AddChanges(*pb.ACLChange)
PushChange(payload proto.Marshaler) (id string, err error) PushChange(payload proto.Marshaler) (id string, err error)
} }