mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
project structure proposal
This commit is contained in:
parent
a06924829e
commit
231c571787
48 changed files with 83 additions and 65 deletions
10
README.md
10
README.md
|
@ -1,2 +1,12 @@
|
||||||
# go-anytype-infrastructure-experiments
|
# go-anytype-infrastructure-experiments
|
||||||
This repository will have the code for new infrastructure client and node prototypes
|
This repository will have the code for new infrastructure client and node prototypes
|
||||||
|
|
||||||
|
## Project structure
|
||||||
|
- **app** - DI, loggers, common engine
|
||||||
|
- **bin** - contains compiled binaries (under gitignore)
|
||||||
|
- **cmd** - main files by directories
|
||||||
|
- **config** - config component
|
||||||
|
- **etc** - default/example config files, keys, etc
|
||||||
|
- **service** - services, runtime components (these packages can use code from everywhere)
|
||||||
|
- **pkg** - some static packages that can be able to move to a separate repo, dependencies of these packages limited to this folder (maybe util)
|
||||||
|
- **util** - helpers
|
BIN
bin/anytype-node
BIN
bin/anytype-node
Binary file not shown.
|
@ -34,34 +34,42 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create app
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
a := new(app.App)
|
a := new(app.App)
|
||||||
|
|
||||||
|
// open config file
|
||||||
conf, err := config.NewFromFile(*flagConfigFile)
|
conf, err := config.NewFromFile(*flagConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("can't open config file", zap.Error(err))
|
log.Fatal("can't open config file", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bootstrap components
|
||||||
a.Register(conf)
|
a.Register(conf)
|
||||||
|
|
||||||
Bootstrap(a)
|
Bootstrap(a)
|
||||||
|
|
||||||
|
// start app
|
||||||
if err := a.Start(ctx); err != nil {
|
if err := a.Start(ctx); err != nil {
|
||||||
log.Error("can't start app", zap.Error(err))
|
log.Error("can't start app", zap.Error(err))
|
||||||
}
|
}
|
||||||
log.Info("app started", zap.String("version", a.Version()))
|
log.Info("app started", zap.String("version", a.Version()))
|
||||||
|
|
||||||
|
// wait exit signal
|
||||||
exit := make(chan os.Signal, 1)
|
exit := make(chan os.Signal, 1)
|
||||||
signal.Notify(exit, os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGQUIT)
|
signal.Notify(exit, os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
sig := <-exit
|
sig := <-exit
|
||||||
log.Info("received exit signal, stop app", zap.String("signal", fmt.Sprint(sig)))
|
log.Info("received exit signal, stop app...", zap.String("signal", fmt.Sprint(sig)))
|
||||||
|
|
||||||
|
// close app
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := a.Close(ctx); err != nil {
|
if err := a.Close(ctx); err != nil {
|
||||||
log.Fatal("close error", zap.Error(err))
|
log.Fatal("close error", zap.Error(err))
|
||||||
|
} else {
|
||||||
|
log.Info("goodbye!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Bootstrap(a *app.App) {
|
func Bootstrap(a *app.App) {
|
||||||
|
//a.Register(mycomponent.New())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package aclchanges
|
package aclchanges
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Change interface {
|
type Change interface {
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/textileio/go-threads/crypto/symmetric"
|
"github.com/textileio/go-threads/crypto/symmetric"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
|
@ -2,8 +2,8 @@ package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
)
|
)
|
|
@ -1,8 +1,8 @@
|
||||||
package acltree
|
package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
|
@ -1,9 +1,9 @@
|
||||||
package acltree
|
package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/threadbuilder"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/threadbuilder"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
|
@ -2,7 +2,7 @@ package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
|
@ -2,8 +2,8 @@ package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
|
|
||||||
"github.com/textileio/go-threads/crypto/symmetric"
|
"github.com/textileio/go-threads/crypto/symmetric"
|
|
@ -1,8 +1,8 @@
|
||||||
package acltree
|
package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
|
@ -3,8 +3,8 @@ package acltree
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
|
@ -2,7 +2,7 @@ package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
)
|
)
|
|
@ -1,8 +1,8 @@
|
||||||
package acltree
|
package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,10 +2,10 @@ package acltree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/threadbuilder"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/threadbuilder"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
|
@ -3,7 +3,7 @@ package acltree
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
//"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/lib/logging"
|
//"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/lib/logging"
|
|
@ -2,11 +2,11 @@ package plaintextdocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
aclpb "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
aclpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
acltree2 "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/acltree"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/acltree"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/testchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/pb"
|
||||||
thread2 "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,7 @@ type PlainTextDocument interface {
|
||||||
|
|
||||||
type plainTextDocument struct {
|
type plainTextDocument struct {
|
||||||
heads []string
|
heads []string
|
||||||
aclTree acltree2.ACLTree
|
aclTree acltree.ACLTree
|
||||||
state *DocumentState
|
state *DocumentState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func (p *plainTextDocument) Text() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *plainTextDocument) AddText(text string) error {
|
func (p *plainTextDocument) AddText(text string) error {
|
||||||
_, err := p.aclTree.AddContent(func(builder acltree2.ChangeBuilder) error {
|
_, err := p.aclTree.AddContent(func(builder acltree.ChangeBuilder) error {
|
||||||
builder.AddChangeContent(
|
builder.AddChangeContent(
|
||||||
&pb.PlainTextChangeData{
|
&pb.PlainTextChangeData{
|
||||||
Content: []*pb.PlainTextChangeContent{
|
Content: []*pb.PlainTextChangeContent{
|
||||||
|
@ -42,7 +42,7 @@ func (p *plainTextDocument) AddText(text string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *plainTextDocument) Update(tree acltree2.ACLTree) {
|
func (p *plainTextDocument) Update(tree acltree.ACLTree) {
|
||||||
p.aclTree = tree
|
p.aclTree = tree
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -54,7 +54,7 @@ func (p *plainTextDocument) Update(tree acltree2.ACLTree) {
|
||||||
prevHeads := p.heads
|
prevHeads := p.heads
|
||||||
p.heads = tree.Heads()
|
p.heads = tree.Heads()
|
||||||
startId := prevHeads[0]
|
startId := prevHeads[0]
|
||||||
tree.IterateFrom(startId, func(change *acltree2.Change) (isContinue bool) {
|
tree.IterateFrom(startId, func(change *acltree.Change) (isContinue bool) {
|
||||||
if change.Id == startId {
|
if change.Id == startId {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (p *plainTextDocument) Update(tree acltree2.ACLTree) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *plainTextDocument) Rebuild(tree acltree2.ACLTree) {
|
func (p *plainTextDocument) Rebuild(tree acltree.ACLTree) {
|
||||||
p.aclTree = tree
|
p.aclTree = tree
|
||||||
p.heads = tree.Heads()
|
p.heads = tree.Heads()
|
||||||
var startId string
|
var startId string
|
||||||
|
@ -92,7 +92,7 @@ func (p *plainTextDocument) Rebuild(tree acltree2.ACLTree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
startId = rootChange.Id
|
startId = rootChange.Id
|
||||||
tree.Iterate(func(change *acltree2.Change) (isContinue bool) {
|
tree.Iterate(func(change *acltree.Change) (isContinue bool) {
|
||||||
if startId == change.Id {
|
if startId == change.Id {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -111,14 +111,14 @@ func (p *plainTextDocument) Rebuild(tree acltree2.ACLTree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInMemoryPlainTextDocument(acc *account.AccountData, text string) (PlainTextDocument, error) {
|
func NewInMemoryPlainTextDocument(acc *account.AccountData, text string) (PlainTextDocument, error) {
|
||||||
return NewPlainTextDocument(acc, thread2.NewInMemoryThread, text)
|
return NewPlainTextDocument(acc, thread.NewInMemoryThread, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlainTextDocument(
|
func NewPlainTextDocument(
|
||||||
acc *account.AccountData,
|
acc *account.AccountData,
|
||||||
create func(change *thread2.RawChange) (thread2.Thread, error),
|
create func(change *thread.RawChange) (thread.Thread, error),
|
||||||
text string) (PlainTextDocument, error) {
|
text string) (PlainTextDocument, error) {
|
||||||
changeBuilder := func(builder acltree2.ChangeBuilder) error {
|
changeBuilder := func(builder acltree.ChangeBuilder) error {
|
||||||
err := builder.UserAdd(acc.Identity, acc.EncKey.GetPublic(), aclpb.ACLChange_Admin)
|
err := builder.UserAdd(acc.Identity, acc.EncKey.GetPublic(), aclpb.ACLChange_Admin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -126,7 +126,7 @@ func NewPlainTextDocument(
|
||||||
builder.AddChangeContent(createInitialChangeContent(text))
|
builder.AddChangeContent(createInitialChangeContent(text))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
t, err := acltree2.BuildThreadWithACL(
|
t, err := acltree.BuildThreadWithACL(
|
||||||
acc,
|
acc,
|
||||||
changeBuilder,
|
changeBuilder,
|
||||||
create)
|
create)
|
||||||
|
@ -139,7 +139,7 @@ func NewPlainTextDocument(
|
||||||
aclTree: nil,
|
aclTree: nil,
|
||||||
state: nil,
|
state: nil,
|
||||||
}
|
}
|
||||||
tree, err := acltree2.BuildACLTree(t, acc, doc)
|
tree, err := acltree.BuildACLTree(t, acc, doc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package plaintextdocument
|
package plaintextdocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/threadbuilder"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/threadbuilder"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
|
@ -2,7 +2,7 @@ package plaintextdocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/testchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/pb"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
|
@ -3,12 +3,12 @@ package threadbuilder
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||||
testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/testchanges/pb"
|
testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/yamltests"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/yamltests"
|
||||||
thread2 "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread"
|
||||||
threadpb "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread/pb"
|
threadpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
|
@ -87,7 +87,7 @@ func (t *ThreadBuilder) Heads() []string {
|
||||||
return t.heads
|
return t.heads
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) AddRawChange(change *thread2.RawChange) error {
|
func (t *ThreadBuilder) AddRawChange(change *thread.RawChange) error {
|
||||||
aclChange := new(pb.ACLChange)
|
aclChange := new(pb.ACLChange)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -162,12 +162,12 @@ func (t *ThreadBuilder) RemoveOrphans(orphans ...string) {
|
||||||
t.orphans = slice.Difference(t.orphans, orphans)
|
t.orphans = slice.Difference(t.orphans, orphans)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) GetChange(ctx context.Context, recordID string) (*thread2.RawChange, error) {
|
func (t *ThreadBuilder) GetChange(ctx context.Context, recordID string) (*thread.RawChange, error) {
|
||||||
return t.getChange(recordID, t.allChanges), nil
|
return t.getChange(recordID, t.allChanges), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) GetUpdates(useCase string) []*thread2.RawChange {
|
func (t *ThreadBuilder) GetUpdates(useCase string) []*thread.RawChange {
|
||||||
var res []*thread2.RawChange
|
var res []*thread.RawChange
|
||||||
update := t.updates[useCase]
|
update := t.updates[useCase]
|
||||||
for _, ch := range update.changes {
|
for _, ch := range update.changes {
|
||||||
rawCh := t.getChange(ch.id, update.changes)
|
rawCh := t.getChange(ch.id, update.changes)
|
||||||
|
@ -180,7 +180,7 @@ func (t *ThreadBuilder) Header() *threadpb.ThreadHeader {
|
||||||
return t.header
|
return t.header
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *thread2.RawChange {
|
func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *thread.RawChange {
|
||||||
rec := m[changeId]
|
rec := m[changeId]
|
||||||
|
|
||||||
if rec.changesDataDecrypted != nil {
|
if rec.changesDataDecrypted != nil {
|
||||||
|
@ -202,7 +202,7 @@ func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *
|
||||||
panic("should be able to sign final acl message!")
|
panic("should be able to sign final acl message!")
|
||||||
}
|
}
|
||||||
|
|
||||||
transformedRec := &thread2.RawChange{
|
transformedRec := &thread.RawChange{
|
||||||
Payload: aclMarshaled,
|
Payload: aclMarshaled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
Id: changeId,
|
Id: changeId,
|
||||||
|
@ -279,7 +279,7 @@ func (t *ThreadBuilder) parseThreadId(description *ThreadDescription) string {
|
||||||
panic("no author in thread")
|
panic("no author in thread")
|
||||||
}
|
}
|
||||||
key := t.keychain.SigningKeys[description.Author]
|
key := t.keychain.SigningKeys[description.Author]
|
||||||
id, err := thread2.CreateACLThreadID(key.GetPublic(), plainTextDocType)
|
id, err := thread.CreateACLThreadID(key.GetPublic(), plainTextDocType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ package threadbuilder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/acl/testutils/testchanges/pb"
|
testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/pb"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"strings"
|
"strings"
|
|
@ -3,8 +3,8 @@ package thread
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
|
@ -2,8 +2,8 @@ package thread
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/aclchanges"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acl/thread/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/thread/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: change methods to have errors as a return parameter, because we will be dealing with a real database
|
// TODO: change methods to have errors as a return parameter, because we will be dealing with a real database
|
Loading…
Add table
Add a link
Reference in a new issue