diff --git a/data/document.go b/data/document.go new file mode 100644 index 00000000..1fb26417 --- /dev/null +++ b/data/document.go @@ -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 +} diff --git a/data/documentcontext.go b/data/documentcontext.go new file mode 100644 index 00000000..eb4ff5cd --- /dev/null +++ b/data/documentcontext.go @@ -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), + } +} diff --git a/data/pb/protos/plaintextchanges.proto b/data/pb/protos/plaintextchanges.proto index 4b5e9d37..0f9177af 100644 --- a/data/pb/protos/plaintextchanges.proto +++ b/data/pb/protos/plaintextchanges.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package anytype; option go_package = "pb"; +// TODO: move to separate package + message PlainTextChange { message Content { oneof value { diff --git a/data/threadmodels/models.go b/data/threadmodels/models.go index aa388596..63367f28 100644 --- a/data/threadmodels/models.go +++ b/data/threadmodels/models.go @@ -8,8 +8,9 @@ import ( type Thread interface { ID() string Heads() []string - // TODO: add ACL heads GetChange(ctx context.Context, recordID string) (*RawChange, error) + //SetHeads(heads []string) + //AddChanges(*pb.ACLChange) PushChange(payload proto.Marshaler) (id string, err error) }