1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-07 21:37:04 +09:00

GO-551: removed unused code

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
AnastasiaShemyakinskaya 2022-12-22 16:33:54 +03:00
parent bec12745eb
commit 033c6bbf05
No known key found for this signature in database
GPG key ID: CCD60ED83B103281
55 changed files with 9 additions and 1347 deletions

View file

@ -1,7 +1,6 @@
package change
import (
"sort"
"time"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/state"
@ -87,105 +86,3 @@ func BuildStateSimpleCRDT(root *state.State, t *Tree) (s *state.State, err error
log.Infof("build state (crdt): changes: %d; dur: %v;", count, time.Since(st))
return s, err
}
// Full version found parallel branches and proposes to resolve conflicts
func BuildState(root *state.State, t *Tree) (s *state.State, err error) {
var (
sc = NewStateCache()
startId string
applyRoot bool
st = time.Now()
count int
)
if startId = root.ChangeId(); startId == "" {
startId = t.RootId()
applyRoot = true
}
t.IterateBranching(startId, func(c *Change, branchLevel int) (isContinue bool) {
if root.ChangeId() == c.Id {
s = root
if applyRoot {
s = s.NewState()
if err = s.ApplyChange(c.Change.Content...); err != nil {
return false
}
s.SetLastModified(c.Timestamp, c.Account)
s.AddFileKeys(c.FileKeys...)
count++
}
sc.Set(c.Id, s, len(c.Next))
return true
}
if len(c.PreviousIds) == 1 {
ps := sc.Get(c.PreviousIds[0])
s := ps.NewState()
if err = s.ApplyChange(c.Change.Content...); err != nil {
return false
}
s.SetLastModified(c.Timestamp, c.Account)
s.AddFileKeys(c.FileKeys...)
count++
s.SetChangeId(c.Id)
if branchLevel == 0 {
if _, _, err = state.ApplyStateFastOne(s); err != nil {
return false
}
sc.Set(c.Id, ps, len(c.Next))
} else {
sc.Set(c.Id, s, len(c.Next))
}
} else if len(c.PreviousIds) > 1 {
toMerge := make([]*state.State, len(c.PreviousIds))
sort.Strings(c.PreviousIds)
for i, prevId := range c.PreviousIds {
toMerge[i] = sc.Get(prevId)
}
ps := merge(t, toMerge...)
s := ps.NewState()
if err = s.ApplyChange(c.Change.Content...); err != nil {
return false
}
s.SetLastModified(c.Timestamp, c.Account)
s.AddFileKeys(c.FileKeys...)
count++
s.SetChangeId(c.Id)
if branchLevel == 0 {
if _, _, err = state.ApplyStateFastOne(s); err != nil {
return false
}
sc.Set(c.Id, ps, len(c.Next))
} else {
sc.Set(c.Id, s, len(c.Next))
}
}
return true
})
if err != nil {
return nil, err
}
if len(t.headIds) > 1 {
toMerge := make([]*state.State, len(t.headIds))
sort.Strings(t.headIds)
for i, hid := range t.headIds {
if s.ChangeId() == hid {
toMerge[i] = s
} else {
toMerge[i] = sc.Get(hid)
}
}
s = merge(t, toMerge...)
}
log.Infof("build state: changes: %d; dur: %v;", count, time.Since(st))
return
}
func merge(t *Tree, states ...*state.State) (s *state.State) {
for _, st := range states {
if s == nil {
s = st
} else {
s = s.Merge(st)
}
}
return s
}

View file

@ -5,13 +5,10 @@ import (
"github.com/anytypeio/go-anytype-middleware/app"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/cafe"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/cafe/pb"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
)
const CName = "account"
var log = logging.Logger("anytype-account")
type Service interface {
app.Component
DeleteAccount(ctx context.Context, isReverted bool) (resp *pb.AccountDeleteResponse, err error)

View file

@ -4,12 +4,10 @@ import (
"context"
"sync"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/core"
"github.com/gogo/protobuf/types"
"github.com/anytypeio/go-anytype-middleware/app"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/state"
"github.com/anytypeio/go-anytype-middleware/core/recordsbatcher"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/core"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
"github.com/anytypeio/go-anytype-middleware/util/slice"
)
@ -31,11 +29,6 @@ type DocInfo struct {
State *state.State
}
type RelationOptionsInfo struct {
RelationId string
Options []*types.Struct
}
type OnDocChangeCallback func(ctx context.Context, info DocInfo) error
type Service interface {

View file

@ -1,7 +1,6 @@
package clipboard
import (
"context"
"errors"
"fmt"
"io/ioutil"
@ -29,10 +28,8 @@ import (
)
var (
ErrAllSlotsEmpty = errors.New("all slots are empty")
ErrTitlePasteRestricted = errors.New("paste to title restricted")
ErrOutOfRange = errors.New("out of range")
log = logging.Logger("anytype-clipboard")
ErrAllSlotsEmpty = errors.New("all slots are empty")
log = logging.Logger("anytype-clipboard")
)
type Clipboard interface {
@ -236,28 +233,6 @@ func (cb *clipboard) Cut(ctx *session.Context, req pb.RpcBlockCutRequest) (textS
return textSlot, htmlSlot, anySlot, cb.Apply(s)
}
func (cb *clipboard) getImages(blocks map[string]*model.Block) (images map[string][]byte, err error) {
for _, b := range blocks {
if file := b.GetFile(); file != nil {
if file.Type == model.BlockContentFile_Image {
fh, err := cb.anytype.FileByHash(context.TODO(), file.Hash)
if err != nil {
return images, err
}
reader, err := fh.Reader()
if err != nil {
return images, err
}
reader.Read(images[file.Hash])
}
}
}
return images, nil
}
func (cb *clipboard) Export(req pb.RpcBlockExportRequest) (path string, err error) {
s := cb.blocksToState(req.Blocks)
htmlData := html.NewHTMLConverter(cb.anytype, s).Export()

View file

@ -1,8 +1,6 @@
package editor
import (
"fmt"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/basic"
dataview "github.com/anytypeio/go-anytype-middleware/core/block/editor/dataview"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/smartblock"
@ -18,8 +16,6 @@ import (
"github.com/anytypeio/go-anytype-middleware/util/slice"
)
var ErrAlreadyHasDataviewBlock = fmt.Errorf("already has the dataview block")
type Set struct {
smartblock.SmartBlock
basic.CommonOperations

View file

@ -1,52 +0,0 @@
package editor
import (
"fmt"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/smartblock"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
)
func NewUninitialized(sbType model.SmartBlockType) smartblock.SmartBlock {
switch sbType {
case model.SmartBlockType_Page, model.SmartBlockType_Date:
return &Page{}
case model.SmartBlockType_Archive:
return &Archive{}
case model.SmartBlockType_Home:
return &Dashboard{}
case model.SmartBlockType_Set:
return &Set{}
case model.SmartBlockType_ProfilePage, model.SmartBlockType_AnytypeProfile:
return &Profile{}
case model.SmartBlockType_STObjectType,
model.SmartBlockType_BundledObjectType:
return &ObjectType{}
case model.SmartBlockType_BundledRelation:
return &Set{}
case model.SmartBlockType_SubObject:
return &SubObject{}
case model.SmartBlockType_File:
return &Files{}
case model.SmartBlockType_MarketplaceType:
return &MarketplaceType{}
case model.SmartBlockType_MarketplaceRelation:
return &MarketplaceRelation{}
case model.SmartBlockType_MarketplaceTemplate:
return &MarketplaceTemplate{}
case model.SmartBlockType_Template:
return &Template{}
case model.SmartBlockType_BundledTemplate:
return &Template{}
case model.SmartBlockType_Breadcrumbs:
return &Breadcrumbs{}
case model.SmartBlockType_Workspace:
return &Workspaces{}
case model.SmartBlockType_AccountOld:
return &ThreadDB{}
case model.SmartBlockType_Widget:
return &WidgetObject{}
default:
panic(fmt.Errorf("unexpected smartblock type: %v", sbType))
}
}

View file

@ -43,8 +43,6 @@ type ApplyFlag int
var (
ErrSimpleBlockNotFound = errors.New("simple block not found")
ErrCantInitExistingSmartblockWithNonEmptyState = errors.New("can't init existing smartblock with non-empty state")
ErrRelationOptionNotFound = errors.New("relation option not found")
ErrRelationNotFound = errors.New("relation not found")
ErrIsDeleted = errors.New("smartblock is deleted")
)
@ -1198,41 +1196,6 @@ func (sb *smartBlock) AddHook(f HookCallback, events ...Hook) {
}
}
func mergeAndSortRelations(objTypeRelations []*model.Relation, extraRelations []*model.Relation, aggregatedRelations []*model.Relation, details *types.Struct) []*model.Relation {
var m = make(map[string]int, len(extraRelations))
var rels = make([]*model.Relation, 0, len(objTypeRelations)+len(extraRelations))
for i, rel := range extraRelations {
m[rel.Key] = i
rels = append(rels, pbtypes.CopyRelation(rel))
}
for _, rel := range objTypeRelations {
if _, exists := m[rel.Key]; exists {
continue
}
rels = append(rels, pbtypes.CopyRelation(rel))
m[rel.Key] = len(rels) - 1
}
for _, rel := range aggregatedRelations {
if i, exists := m[rel.Key]; exists {
// overwrite name that we've got from DS
if rels[i].Name != rel.Name {
rels[i].Name = rel.Name
}
continue
}
rels = append(rels, pbtypes.CopyRelation(rel))
m[rel.Key] = len(rels) - 1
}
if details == nil || details.Fields == nil {
return rels
}
return rels
}
func (sb *smartBlock) baseRelations() []*model.Relation {
rels := []*model.Relation{bundle.MustGetRelation(bundle.RelationKeyId), bundle.MustGetRelation(bundle.RelationKeyLayout), bundle.MustGetRelation(bundle.RelationKeyIconEmoji), bundle.MustGetRelation(bundle.RelationKeyName)}
for _, rel := range rels {

View file

@ -13,7 +13,6 @@ import (
var (
maxChildrenThreshold = 40
divSize = maxChildrenThreshold / 2
)
func (s *State) Normalize(withLayouts bool) (err error) {

View file

@ -33,7 +33,6 @@ const (
HeaderLayoutID = "header"
TitleBlockID = "title"
DescriptionBlockID = "description"
DataviewBlockID = "dataview"
DataviewTemplatesBlockID = "templates"
FeaturedRelationsID = "featuredRelations"
@ -287,13 +286,6 @@ func (s *State) IsChild(parentId, childId string) bool {
}
}
func (s *State) PickOriginParentOf(id string) (res simple.Block) {
if s.parent != nil {
return s.parent.PickParentOf(id)
}
return
}
func (s *State) getStringBuf() []string {
if s.parent != nil {
return s.parent.getStringBuf()

View file

@ -44,20 +44,6 @@ var WithEmpty = StateTransformer(func(s *state.State) {
})
var WithObjectTypes = func(otypes []string) StateTransformer {
return func(s *state.State) {
if len(s.ObjectTypes()) == 0 {
s.SetObjectTypes(otypes)
}
}
}
var WithForcedObjectTypes = func(otypes []string) StateTransformer {
return func(s *state.State) {
s.SetObjectTypes(otypes)
}
}
// WithNoObjectTypes is a special case used only for Archive
var WithNoObjectTypes = func() StateTransformer {
return func(s *state.State) {
@ -292,26 +278,6 @@ var WithAddedFeaturedRelation = func(key bundle.RelationKey) StateTransformer {
}
}
var WithAddedFeaturedRelations = func(keys ...string) StateTransformer {
return func(s *state.State) {
currentVal := pbtypes.GetStringList(s.Details(), bundle.RelationKeyFeaturedRelations.String())
keys = slice.Filter(keys, func(key string) bool {
if slice.FindPos(currentVal, key) > -1 {
return false
} else {
return true
}
})
if len(keys) > 0 {
s.SetDetail(bundle.RelationKeyFeaturedRelations.String(), pbtypes.StringList(append(currentVal, keys...)))
}
return
}
}
var WithCreatorRemovedFromFeaturedRelations = StateTransformer(func(s *state.State) {
fr := pbtypes.GetStringList(s.Details(), bundle.RelationKeyFeaturedRelations.String())

View file

@ -66,18 +66,12 @@ const (
var (
ErrBlockNotFound = errors.New("block not found")
ErrBlockAlreadyOpen = errors.New("block already open")
ErrUnexpectedBlockType = errors.New("unexpected block type")
ErrUnknownObjectType = fmt.Errorf("unknown object type")
)
var log = logging.Logger("anytype-mw-service")
var (
blockCacheTTL = time.Minute
blockCleanupTimeout = time.Second * 30
)
var (
// quick fix for limiting file upload goroutines
uploadFilesLimiter = make(chan struct{}, 8)

View file

@ -23,7 +23,6 @@ var (
ErrRelationExists = fmt.Errorf("relation exists")
ErrViewNotFound = errors.New("view not found")
ErrRelationNotFound = fmt.Errorf("relation not found")
ErrOptionNotExists = errors.New("option not exists")
)
func init() {
@ -310,15 +309,6 @@ func (s *Dataview) SetView(viewID string, view model.BlockContentDataviewView) e
return nil
}
func (l *Dataview) getActiveView() *model.BlockContentDataviewView {
for i, view := range l.GetDataview().Views {
if view.Id == l.content.ActiveView {
return l.GetDataview().Views[i]
}
}
return nil
}
func (l *Dataview) FillSmartIds(ids []string) []string {
for _, rl := range l.content.RelationLinks {
ids = append(ids, addr.RelationKeyToIdPrefix+rl.Key)
@ -505,13 +495,3 @@ func (s *Dataview) UpdateRelationOld(relationKey string, rel model.Relation) err
return nil
}
func (l *Dataview) relationsWithObjectFormat() []string {
var relationsWithObjFormat []string
for _, rel := range l.GetDataview().Relations {
if rel.Format == model.RelationFormat_file || rel.Format == model.RelationFormat_object {
relationsWithObjFormat = append(relationsWithObjFormat, rel.Key)
}
}
return relationsWithObjFormat
}

View file

@ -22,13 +22,6 @@ const (
EdgeTypeLink
)
type linkInfo struct {
target string
edgeType edgeType
name string
full string
}
type Node struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`

View file

@ -123,16 +123,6 @@ func (b *treeBuilder) writeChanges(logs []core.SmartblockLog) (err error) {
return
}
func createFileWithDateInZip(zw *zip.Writer, name string, modified time.Time) (io.Writer, error) {
header := &zip.FileHeader{
Name: name,
Method: zip.Deflate,
Modified: modified,
}
return zw.CreateHeader(header)
}
func (b *treeBuilder) writeChange(id string) (nextIds []string) {
if _, ok := b.changes[id]; ok {
return

View file

@ -18,7 +18,6 @@ import (
"github.com/anytypeio/go-anytype-middleware/pkg/lib/core/smartblock"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/database"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/localstore/objectstore"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
"github.com/anytypeio/go-anytype-middleware/util/pbtypes"
"github.com/anytypeio/go-anytype-middleware/util/slice"
@ -28,8 +27,6 @@ const CName = "history"
const versionGroupInterval = time.Minute * 5
var log = logging.Logger("anytype-mw-history")
func New() History {
return new(history)
}

View file

@ -5,14 +5,11 @@ import (
"time"
"github.com/anytypeio/go-anytype-middleware/app"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
"github.com/cheggaaa/mb"
)
const CName = "recordsbatcher"
var log = logging.Logger("anytype-recordsbatcher")
type recordsBatcher struct {
batcher *mb.MB
packDelay time.Duration // delay for better packing of msgs

View file

@ -7,7 +7,6 @@ import (
"strings"
"sync"
"github.com/globalsign/mgo/bson"
"github.com/gogo/protobuf/types"
"github.com/ipfs/go-datastore/query"
@ -24,11 +23,8 @@ import (
const CName = "relation"
const blockServiceCName = "blockService"
var (
ErrNotFound = errors.New("relation not found")
ErrExists = errors.New("relation with given key already exists")
log = logging.Logger("anytype-relations")
)
@ -218,12 +214,6 @@ type fetchOptions struct {
type FetchOption func(options *fetchOptions)
func WithWorkspaceId(id string) FetchOption {
return func(options *fetchOptions) {
options.workspaceId = &id
}
}
func (s *service) FetchKey(key string, opts ...FetchOption) (relation *relationutils.Relation, err error) {
s.mu.RLock()
defer s.mu.RUnlock()
@ -269,34 +259,6 @@ func (s *service) fetchKey(key string, opts ...FetchOption) (relation *relationu
return nil, ErrNotFound
}
func (s *service) fetchOptionsByKey(key string) (relation *relationutils.Relation, err error) {
q := database.Query{
Filters: []*model.BlockContentDataviewFilter{
{
Condition: model.BlockContentDataviewFilter_Equal,
RelationKey: bundle.RelationKeyRelationKey.String(),
Value: pbtypes.String(key),
},
{
Condition: model.BlockContentDataviewFilter_Equal,
RelationKey: bundle.RelationKeyType.String(),
Value: pbtypes.String(bundle.TypeKeyRelationOption.String()),
},
},
}
f, err := database.NewFilters(q, nil, nil)
if err != nil {
return
}
records, err := s.objectStore.QueryRaw(query.Query{
Filters: []query.Filter{f},
})
for _, rec := range records {
return relationutils.RelationFromStruct(rec.Details), nil
}
return nil, ErrNotFound
}
func (s *service) ValidateFormat(key string, v *types.Value) error {
r, err := s.FetchKey(key)
if err != nil {
@ -425,7 +387,3 @@ func (s *service) validateOptions(rel *relationutils.Relation, v []string) error
// TODO:
return nil
}
func generateRelationKey() string {
return bson.NewObjectId().Hex()
}

View file

@ -2,21 +2,9 @@ package core
import (
"math/rand"
"path/filepath"
"time"
)
const ipfsUrlScheme = "ipfs://"
func init() {
rand.Seed(time.Now().UnixNano())
}
func ipfsFileURL(hash string, originalFileName string) string {
url := ipfsUrlScheme + hash
if originalFileName != "" {
url += "/" + filepath.Base(originalFileName)
}
return url
}

View file

@ -27,7 +27,6 @@ import (
pstore "github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/p2p/discovery/mdns"
"github.com/textileio/go-threads/core/net"
"io"
"os"
"path/filepath"
"strings"
@ -60,15 +59,11 @@ type Service interface {
FileByHash(ctx context.Context, hash string) (File, error)
FileAdd(ctx context.Context, opts ...files.AddOption) (File, error)
FileAddWithBytes(ctx context.Context, content []byte, filename string) (File, error) // deprecated
FileAddWithReader(ctx context.Context, content io.ReadSeeker, filename string) (File, error) // deprecated
FileGetKeys(hash string) (*files.FileKeys, error)
FileStoreKeys(fileKeys ...files.FileKeys) error
ImageByHash(ctx context.Context, hash string) (Image, error)
ImageAdd(ctx context.Context, opts ...files.AddOption) (Image, error)
ImageAddWithBytes(ctx context.Context, content []byte, filename string) (Image, error) // deprecated
ImageAddWithReader(ctx context.Context, content io.ReadSeeker, filename string) (Image, error) // deprecated
GetAllWorkspaces() ([]string, error)
GetWorkspaceIdForObject(objectId string) (string, error)

View file

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/ipfs/go-cid"
"io"
"time"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/files"
@ -165,11 +164,3 @@ func (a *Anytype) FileAdd(ctx context.Context, options ...files.AddOption) (File
return f, nil
}
func (a *Anytype) FileAddWithReader(ctx context.Context, content io.ReadSeeker, filename string) (File, error) {
return a.FileAdd(ctx, files.WithReader(content), files.WithName(filename))
}
func (a *Anytype) FileAddWithBytes(ctx context.Context, content []byte, filename string) (File, error) {
return a.FileAdd(ctx, files.WithBytes(content), files.WithName(filename))
}

View file

@ -5,7 +5,6 @@ import (
"fmt"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/files"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/storage"
"io"
)
var ErrImageNotFound = fmt.Errorf("image not found")
@ -86,11 +85,3 @@ func (a *Anytype) ImageAdd(ctx context.Context, options ...files.AddOption) (Ima
return img, nil
}
func (a *Anytype) ImageAddWithBytes(ctx context.Context, content []byte, filename string) (Image, error) {
return a.ImageAdd(ctx, files.WithBytes(content), files.WithName(filename))
}
func (a *Anytype) ImageAddWithReader(ctx context.Context, content io.ReadSeeker, filename string) (Image, error) {
return a.ImageAdd(ctx, files.WithReader(content), files.WithName(filename))
}

View file

@ -1,9 +0,0 @@
package core
import (
"io"
)
func (a *Anytype) IpfsReaderAtPath(pth string) (io.ReadCloser, error) {
return nil, nil
}

View file

@ -22,11 +22,6 @@ import (
"github.com/anytypeio/go-anytype-middleware/pkg/lib/vclock"
)
const (
snippetMinSize = 50
snippetMaxSize = 300
)
type ProfileThreadEncryptionKeys struct {
ServiceKey []byte
ReadKey []byte
@ -77,12 +72,6 @@ type SmartBlockChange struct {
Meta *SmartBlockMetaChange
}
type SmartBlockVersion struct {
State vclock.VClock
Snapshot SmartBlockSnapshot
Changes []SmartBlockChange
}
type SmartBlock interface {
ID() string
Type() smartblock.SmartBlockType
@ -116,24 +105,6 @@ func (block *smartBlock) Creator() (string, error) {
return "", fmt.Errorf("to be implemented")
}
func (block *smartBlock) GetLastDownloadedVersion() (*SmartBlockVersion, error) {
snapshot, err := block.GetLastSnapshot()
if err != nil {
return nil, err
}
return &SmartBlockVersion{
State: snapshot.State(),
Snapshot: snapshot,
Changes: []SmartBlockChange{},
}, nil
}
func (block *smartBlock) PushChanges(changes []*SmartBlockChange) (state vclock.VClock, err error) {
// todo: to be implemented
return vclock.Undef, fmt.Errorf("to be implemented")
}
func (block *smartBlock) GetThread() thread.Info {
return block.thread
}
@ -330,13 +301,6 @@ func (block *smartBlock) SubscribeForRecords(ch chan SmartblockRecordEnvelope) (
return cancel, nil
}
func (block *smartBlock) SubscribeForChanges(since vclock.VClock, ch chan SmartBlockChange) (cancel func(), err error) {
chCloseFn := func() { close(ch) }
// todo: to be implemented
return chCloseFn, nil
}
func (block *smartBlock) SubscribeClientEvents(events chan<- proto.Message) (cancelFunc func(), err error) {
// todo: to be implemented
return func() { close(events) }, nil

View file

@ -22,7 +22,6 @@ const (
SmartBlockTypeProfilePage = SmartBlockType(model.SmartBlockType_ProfilePage)
SmartBlockTypeHome = SmartBlockType(model.SmartBlockType_Home)
SmartBlockTypeArchive = SmartBlockType(model.SmartBlockType_Archive)
SmartBlockTypeDatabase = SmartBlockType(model.SmartBlockType_Database)
SmartBlockTypeSet = SmartBlockType(model.SmartBlockType_Set)
SmartBlockTypeObjectType = SmartBlockType(model.SmartBlockType_STObjectType)
SmartBlockTypeFile = SmartBlockType(model.SmartBlockType_File)

View file

@ -11,26 +11,8 @@ import (
)
var ErrRepoExists = fmt.Errorf("repo not empty, reinitializing would overwrite your account")
var ErrRepoDoesNotExist = fmt.Errorf("repo does not exist, initialization is required")
var ErrMigrationRequired = fmt.Errorf("repo needs migration")
var ErrRepoCorrupted = fmt.Errorf("repo is corrupted")
func WalletListLocalAccounts(rootPath string) ([]string, error) {
repos, err := ioutil.ReadDir(rootPath)
if err != nil {
return nil, err
}
var accounts []string
for _, f := range repos {
if len(f.Name()) == 48 {
accounts = append(accounts, f.Name())
}
}
return accounts, nil
}
func WalletGenerateMnemonic(wordCount int) (string, error) {
w, err := wallet.WalletFromWordCount(wordCount)
if err != nil {

View file

@ -72,7 +72,6 @@ func New() *Service {
return &Service{}
}
var ErrMissingMetaLink = fmt.Errorf("meta link not in node")
var ErrMissingContentLink = fmt.Errorf("content link not in node")
const MetaLinkName = "meta"

View file

@ -1,7 +1,6 @@
package files
import (
"bytes"
"context"
"fmt"
"io"
@ -29,36 +28,12 @@ func WithReader(r io.ReadSeeker) AddOption {
}
}
func WithBytes(b []byte) AddOption {
return func(args *AddOptions) {
args.Reader = bytes.NewReader(b)
}
}
func WithCid(cid string) AddOption {
return func(args *AddOptions) {
args.Use = cid
}
}
func WithMedia(media string) AddOption {
return func(args *AddOptions) {
args.Media = media
}
}
func WithName(name string) AddOption {
return func(args *AddOptions) {
args.Name = name
}
}
func WithPlaintext(plaintext bool) AddOption {
return func(args *AddOptions) {
args.Plaintext = plaintext
}
}
func (s *Service) NormalizeOptions(ctx context.Context, opts *AddOptions) error {
if opts.Use != "" {
ref, err := ipfspath.ParsePath(opts.Use)

View file

@ -6,24 +6,19 @@ import (
"github.com/anytypeio/go-anytype-middleware/metrics"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/ipfs/helpers/resolver"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-merkledag"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/net/swarm"
ma "github.com/multiformats/go-multiaddr"
"io"
"io/ioutil"
"net"
gopath "path"
"time"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/crypto/symmetric"
files "github.com/ipfs/go-ipfs-files"
ipld "github.com/ipfs/go-ipld-format"
ipfspath "github.com/ipfs/go-path"
uio "github.com/ipfs/go-unixfs/io"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
mh "github.com/multiformats/go-multihash"
@ -53,27 +48,6 @@ func DataAtPath(ctx context.Context, node ipfs.IPFS, pth string) (cid.Cid, symme
return resolvedPath.Cid(), r, nil
}
// DataAtCid return bytes under an ipfs path
func DataAtCid(ctx context.Context, node ipfs.IPFS, cid cid.Cid) ([]byte, error) {
f, err := node.GetFile(ctx, cid)
if err != nil {
return nil, err
}
defer f.Close()
var file files.File
switch f := f.(type) {
case files.File:
file = f
case files.Directory:
return nil, iface.ErrIsDir
default:
return nil, iface.ErrNotSupported
}
return ioutil.ReadAll(file)
}
func LinksAtCid(ctx context.Context, dag ipld.DAGService, pathCid string) ([]*ipld.Link, error) {
pathCidParsed, err := cid.Parse(pathCid)
if err != nil {
@ -132,26 +106,6 @@ func ResolvePath(ctx context.Context, dag ipld.DAGService, p path.Path) (path.Re
return path.NewResolvedPath(ipath, node, root, gopath.Join(rest...)), nil
}
// AddDataToDirectory adds reader bytes to a virtual dir
func AddDataToDirectory(ctx context.Context, node ipfs.IPFS, dir uio.Directory, fname string, reader io.Reader) (*cid.Cid, error) {
id, err := AddData(ctx, node, reader, false)
if err != nil {
return nil, err
}
n, err := node.Get(ctx, *id)
if err != nil {
return nil, err
}
err = dir.AddChild(ctx, fname, n)
if err != nil {
return nil, err
}
return id, nil
}
// AddLinkToDirectory adds a link to a virtual dir
func AddLinkToDirectory(ctx context.Context, dag ipld.DAGService, dir uio.Directory, fname string, pth string) error {
id, err := cid.Decode(pth)
@ -170,36 +124,11 @@ func AddLinkToDirectory(ctx context.Context, dag ipld.DAGService, dir uio.Direct
return dir.AddChild(ctx, fname, nd)
}
// AddData takes a reader and adds it, optionally pins it, optionally only hashes it
func AddData(ctx context.Context, node ipfs.IPFS, reader io.Reader, pin bool) (*cid.Cid, error) {
pth, err := node.AddFile(ctx, files.NewReaderFile(reader), nil)
log.Debugf("AddData: %s", pth.Cid().String())
if err != nil {
return nil, err
}
if pin {
/* err = api.Pin().Add(ctx, pth, options.Pin.Recursive(false))
if err != nil {
return nil, err
}*/
}
id := pth.Cid()
return &id, nil
}
// NodeAtLink returns the node behind an ipld link
func NodeAtLink(ctx context.Context, dag ipld.DAGService, link *ipld.Link) (ipld.Node, error) {
return link.GetNode(ctx, dag)
}
// NodeAtCid returns the node behind a cid
func NodeAtCid(ctx context.Context, dag ipld.DAGService, id cid.Cid) (ipld.Node, error) {
return dag.Get(ctx, id)
}
type Node struct {
Links []Link
Data string
@ -210,24 +139,6 @@ type Link struct {
Size uint64
}
// ResolveLinkByNames resolves a link in a node from a list of valid names
// Note: This exists for b/c w/ the "f" -> "meta" and "d" -> content migration
func ResolveLinkByNames(nd ipld.Node, names []string) (*ipld.Link, error) {
for _, n := range names {
link, _, err := nd.ResolveLink([]string{n})
if err != nil {
if err == merkledag.ErrLinkNotFound {
continue
}
return nil, err
}
if link != nil {
return link, nil
}
}
return nil, nil
}
func PermanentConnection(ctx context.Context, addr ma.Multiaddr, host host.Host, retryInterval time.Duration, grpcConnected func() bool) error {
addrInfo, err := peer.AddrInfoFromP2pAddr(addr)
if err != nil {

View file

@ -35,21 +35,14 @@ type ResolveOnce func(ctx context.Context, ds ipld.NodeGetter, nd ipld.Node, nam
// Resolver provides path resolution to IPFS
// It has a pointer to a DAGService, which is uses to resolve nodes.
// TODO: now that this is more modular, try to unify this code with the
// the resolvers in namesys
//
// the resolvers in namesys
type Resolver struct {
DAG ipld.NodeGetter
ResolveOnce ResolveOnce
}
// NewBasicResolver constructs a new basic resolver.
func NewBasicResolver(ds ipld.DAGService) *Resolver {
return &Resolver{
DAG: ds,
ResolveOnce: ResolveSingle,
}
}
// ResolveToLastNode walks the given path and returns the cid of the last node
// referenced by the path
func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid.Cid, []string, error) {

View file

@ -3,7 +3,6 @@ package ipfs
import (
"context"
"github.com/anytypeio/go-anytype-middleware/app"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
cid "github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
ipld "github.com/ipfs/go-ipld-format"
@ -15,8 +14,6 @@ import (
const CName = "ipfs"
var log = logging.Logger("anytype-core-ipfs")
const (
IpfsPrivateNetworkKey = `/key/swarm/psk/1.0.0/
/base16/

View file

@ -287,10 +287,6 @@ func (ln *liteNet) Close() (err error) {
return nil
}
func (ln *liteNet) WaitBootstrapFinish() (success bool) {
panic("implement me")
}
func (i *liteNet) Session(ctx context.Context) ipld.NodeGetter {
return i.Peer.Session(ctx)
}

View file

@ -43,11 +43,6 @@ func ExtractVirtualSourceType(id string) (model.SmartBlockType, error) {
return 0, fmt.Errorf("sb type '%s' not found", sbTypeName)
}
// returns the
func GetVirtualCollectionObjectId(collectionName, key string) string {
return collectionName + SubObjectCollectionIdSeparator + key
}
func ConvertBundledObjectIdToInstalledId(bundledId string) (string, error) {
if strings.HasPrefix(bundledId, BundledRelationURLPrefix) {
return RelationKeyToIdPrefix + strings.TrimPrefix(bundledId, BundledRelationURLPrefix), nil

View file

@ -288,11 +288,6 @@ type ObjectStore interface {
GetThreadQueueState() (map[string]map[string]struct{}, map[string]map[string]struct{}, error)
}
type relationOption struct {
relationKey string
optionId string
}
type relationObjectType struct {
relationKeys []string
objectTypes []string
@ -313,11 +308,6 @@ type filterSmartblockTypes struct {
not bool
}
type RelationWithObjectType struct {
objectType string
relation *model.Relation
}
func (m *filterSmartblockTypes) Filter(e query.Entry) bool {
keyParts := strings.Split(e.Key, "/")
id := keyParts[len(keyParts)-1]
@ -1938,27 +1928,6 @@ func (m *dsObjectStore) updateDetails(txn noctxds.Txn, id string, oldDetails *mo
return nil
}
func storeOptions(txn noctxds.Txn, options []*model.RelationOption) error {
var err error
for _, opt := range options {
err = storeOption(txn, opt)
if err != nil {
return err
}
}
return nil
}
func storeOption(txn noctxds.Txn, option *model.RelationOption) error {
b, err := proto.Marshal(option)
if err != nil {
return err
}
optionKey := relationsOptionsBase.ChildString(option.Id)
return txn.Put(optionKey, b)
}
func (m *dsObjectStore) Prefix() string {
return pagesPrefix
}
@ -2047,15 +2016,6 @@ func (m *dsObjectStore) listRelations(txn noctxds.Txn, limit int) ([]*model.Rela
return rels, nil
}
func isObjectBelongToType(txn noctxds.Txn, id, objType string) (bool, error) {
objTypeCompact, err := objTypeCompactEncode(objType)
if err != nil {
return false, err
}
return localstore.HasPrimaryKeyByIndexParts(txn, pagesPrefix, indexObjectTypeObject.Name, []string{objTypeCompact}, "", false, id)
}
/* internal */
// getObjectDetails returns empty(not nil) details when not found in the DS
func getObjectDetails(txn noctxds.Txn, id string) (*model.ObjectDetails, error) {
@ -2100,20 +2060,6 @@ func hasObjectId(txn noctxds.Txn, id string) (bool, error) {
}
}
// getSetRelations returns the list of relations last time indexed for the set's dataview
func getSetRelations(txn noctxds.Txn, id string) ([]*model.Relation, error) {
var relations model.Relations
if val, err := txn.Get(setRelationsBase.ChildString(id)); err != nil {
if err != ds.ErrNotFound {
return nil, fmt.Errorf("failed to get relations: %w", err)
}
} else if err := proto.Unmarshal(val, &relations); err != nil {
return nil, fmt.Errorf("failed to unmarshal relations: %w", err)
}
return relations.GetRelations(), nil
}
// getObjectRelations returns the list of relations last time indexed for the object
func getObjectRelations(txn noctxds.Txn, id string) ([]*model.Relation, error) {
var relations model.Relations
@ -2128,28 +2074,6 @@ func getObjectRelations(txn noctxds.Txn, id string) ([]*model.Relation, error) {
return relations.GetRelations(), nil
}
func getOption(txn noctxds.Txn, optionId string) (*model.RelationOption, error) {
var opt model.RelationOption
if val, err := txn.Get(relationsOptionsBase.ChildString(optionId)); err != nil {
log.Debugf("getOption %s: not found", optionId)
if err != ds.ErrNotFound {
return nil, fmt.Errorf("failed to get option from localstore: %w", err)
}
} else if err := proto.Unmarshal(val, &opt); err != nil {
return nil, fmt.Errorf("failed to unmarshal option: %w", err)
}
return &opt, nil
}
func getObjectTypeFromDetails(det *types.Struct) ([]string, error) {
if !pbtypes.HasField(det, bundle.RelationKeyType.String()) {
return nil, fmt.Errorf("type not found in details")
}
return pbtypes.GetStringList(det, bundle.RelationKeyType.String()), nil
}
func (m *dsObjectStore) getObjectInfo(txn noctxds.Txn, id string) (*model.ObjectInfo, error) {
sbt, err := smartblock.SmartBlockTypeFromID(id)
if err != nil {

View file

@ -19,7 +19,6 @@ import (
var (
ErrDuplicateKey = fmt.Errorf("duplicate key")
ErrNotFound = fmt.Errorf("not found")
errTxnTooBig = fmt.Errorf("Txn is too big to fit into one request")
)
var (
@ -249,21 +248,6 @@ func AddIndexesWithTxn(store Indexable, txn ds.Txn, newVal interface{}, newValPr
return nil
}
func AddIndexes(store Indexable, ds ds.TxnDatastore, newVal interface{}, newValPrimary string) error {
txn, err := ds.NewTransaction(false)
if err != nil {
return err
}
defer txn.Discard()
err = AddIndexesWithTxn(store, txn, newVal, newValPrimary)
if err != nil {
return err
}
return txn.Commit()
}
func RemoveIndexes(store Indexable, ds ds.TxnDatastore, val interface{}, valPrimary string) error {
txn, err := ds.NewTransaction(false)
if err != nil {
@ -333,22 +317,6 @@ func GetKeysByIndexParts(txn ds.Txn, prefix string, keyIndexName string, keyInde
return GetKeys(txn, key.String(), limit)
}
func QueryByIndexParts(txn ds.Txn, prefix string, keyIndexName string, keyIndexValue []string, separator string, hash bool, limit int) (query.Results, error) {
key := getDsKeyByIndexParts(prefix, keyIndexName, keyIndexValue, separator, hash)
return txn.Query(query.Query{
Prefix: key.String(),
Limit: limit,
KeysOnly: false,
})
}
func HasPrimaryKeyByIndexParts(txn ds.Txn, prefix string, keyIndexName string, keyIndexValue []string, separator string, hash bool, primaryIndex string) (exists bool, err error) {
key := getDsKeyByIndexParts(prefix, keyIndexName, keyIndexValue, separator, hash).ChildString(primaryIndex)
return txn.Has(key)
}
func CountAllKeysFromResults(results query.Results) (int, error) {
var count int
for {

View file

@ -103,22 +103,6 @@ func Logger(system string) *LWrapper {
return &LWrapper{logger.SugaredLogger}
}
func SetLoggingFilepath(logPath string) {
cfg := defaultCfg
cfg.Format = logging.PlaintextOutput
cfg.File = filepath.Join(logPath, "anytype.log")
logging.SetupLogging(cfg)
}
func SetLoggingFormat(format logging.LogFormat) {
cfg := getLoggingConfig()
cfg.Format = format
logging.SetupLogging(cfg)
}
func ApplyLevels(str string) {
m.Lock()
logLevelsStr = str

View file

@ -8,44 +8,18 @@ import (
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/storage"
)
// ErrFileValidationFailed indicates dag schema validation failed
var ErrFileValidationFailed = fmt.Errorf("file failed schema validation")
// ErrEmptySchema indicates a schema is empty
var ErrEmptySchema = fmt.Errorf("schema does not create any files")
// ErrLinkOrderNotSolvable
var ErrLinkOrderNotSolvable = fmt.Errorf("link order is not solvable")
// ErrSchemaInvalidMill indicates a schema has an invalid mill entry
var ErrSchemaInvalidMill = fmt.Errorf("schema contains an invalid mill")
// ErrMissingJsonSchema indicates json schema is missing
var ErrMissingJsonSchema = fmt.Errorf("json mill requires a json schema")
// ErrBadJsonSchema indicates json schema is invalid
var ErrBadJsonSchema = fmt.Errorf("json schema is not valid")
// FileTag indicates the link should "use" the input file as source
const FileTag = ":file"
// SingleFileTag is a magic key indicating that a directory is actually a single file
const SingleFileTag = ":single"
// ValidateMill is false if mill is not one of the built in tags
func ValidateMill(mill string) bool {
switch mill {
case
"/schema",
"/blob",
"/image/resize",
"/image/exif",
"/json":
return true
}
return false
}
// LinkByName finds a link w/ one of the given names in the provided list
func LinkByName(links []*ipld.Link, names []string) *ipld.Link {
for _, l := range links {

View file

@ -4,14 +4,11 @@ import (
"fmt"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/bundle"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/database/filter"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
"github.com/anytypeio/go-anytype-middleware/util/pbtypes"
"strings"
)
var log = logging.Logger("anytype-core-schema")
// Schema used to subset compatible objects by some common relations
type Schema interface {
Filters() filter.Filter

View file

@ -1,15 +0,0 @@
package structs
import "github.com/gogo/protobuf/types"
func String(s string) *types.Value {
return &types.Value{Kind: &types.Value_StringValue{StringValue: s}}
}
func Float64(i float64) *types.Value {
return &types.Value{Kind: &types.Value_NumberValue{NumberValue: i}}
}
func Bool(b bool) *types.Value {
return &types.Value{Kind: &types.Value_BoolValue{BoolValue: b}}
}

View file

@ -16,9 +16,6 @@ import (
const nodeConnectionTimeout = time.Second * 15
const ThreadInfoCollectionName = "threads"
const MetaCollectionName = "meta"
const CreatorCollectionName = "creator"
const HighlightedCollectionName = "highlighted"
type ThreadDBInfo struct {
ID db.InstanceID `json:"_id"`

View file

@ -7,7 +7,6 @@ import (
const (
DefaultPriority = iota
HighPriority
MaxPriority
)
type Operation interface {

View file

@ -13,9 +13,6 @@ import (
"github.com/textileio/go-threads/core/thread"
)
var ErrFailedToPullThread = fmt.Errorf("failed to pull thread")
var ErrFailedToProcessNewHead = fmt.Errorf("failed to process new page head")
func (s *service) pullThread(ctx context.Context, id thread.ID) (headsChanged bool, err error) {
thrd, err := s.t.GetThread(context.Background(), id)
if err != nil {

View file

@ -33,10 +33,6 @@ func NewTxnBatch(ds DatastoreTxnBatching) DatastoreTxnBatching {
return &NoCloserDatastoreTxnBatching{ds}
}
func NewTxnExtended(ds keytransform.TxnDatastoreExtended) keytransform.TxnDatastoreExtended {
return &NoCloserDatastoreExtended{ds}
}
func (ncd NoCloserDatastoreBatching) Close() error {
return nil
}

View file

@ -2,13 +2,10 @@ package util
import (
"fmt"
textutil "github.com/anytypeio/go-anytype-middleware/util/text"
"github.com/libp2p/go-libp2p/core/peer"
"strings"
"unicode"
"unicode/utf8"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
"github.com/textileio/go-threads/core/thread"
)
@ -74,15 +71,6 @@ func MultiAddressHasReplicator(addrs []ma.Multiaddr, multiaddr ma.Multiaddr) boo
return false
}
func MultiAddressesContains(addrs []ma.Multiaddr, addr ma.Multiaddr) bool {
for _, a := range addrs {
if a.Equal(addr) {
return true
}
}
return false
}
func MultiAddressesToStrings(addrs []ma.Multiaddr) []string {
var s []string
for _, addr := range addrs {
@ -101,38 +89,6 @@ func ThreadIdsToStings(ids []thread.ID) []string {
return s
}
func TruncateText(text string, length int) string {
var ellipsis = " …"
if textutil.UTF16RuneCountString(text) <= length {
return text
}
var lastWordIndex, lastNonSpace, currentLen, endTextPos int
for i, r := range text {
currentLen++
if unicode.IsSpace(r) {
lastWordIndex = lastNonSpace
} else if unicode.In(r, unicode.Han, unicode.Hangul, unicode.Hiragana, unicode.Katakana) {
lastWordIndex = i
} else {
lastNonSpace = i + utf8.RuneLen(r)
}
if currentLen > length {
if lastWordIndex == 0 {
endTextPos = i
} else {
endTextPos = lastWordIndex
}
out := text[0:endTextPos]
return out + ellipsis
}
}
return text
}
// UniqueStrings returns the new slice without duplicates, while preserving the order.
// The second and further occurrences are considered a duplicate
func UniqueStrings(items []string) []string {

View file

@ -34,12 +34,6 @@ type VClock struct {
var Undef = VClock{}
// New returns a new vector clock
// VClock is thread safe
func New() VClock {
return VClock{mutex: &sync.RWMutex{}, m: make(map[string]uint64)}
}
func NewFromMap(m map[string]uint64) VClock {
if m == nil {
return Undef
@ -51,8 +45,8 @@ func (vc VClock) IsNil() bool {
return vc.m == nil
}
//Merge takes the max of all clock values in other and updates the
//values of the callee
// Merge takes the max of all clock values in other and updates the
// values of the callee
func (vc VClock) Merge(other VClock) {
if vc.IsNil() {
// Undef is used only for indicating of non-set vclock
@ -72,7 +66,7 @@ func (vc VClock) Merge(other VClock) {
}
}
//MarshalBinary returns an encoded vector clock
// MarshalBinary returns an encoded vector clock
func (vc VClock) MarshalBinary() ([]byte, error) {
if vc.IsNil() {
// vclock is Undef
@ -90,16 +84,6 @@ func (vc VClock) MarshalBinary() ([]byte, error) {
return b.Bytes(), nil
}
//UnmarshalBinary decodes a vector clock
func UnmarshalBinary(data []byte) (vc VClock, err error) {
b := new(bytes.Buffer)
b.Write(data)
clock := New()
dec := gob.NewDecoder(b)
err = dec.Decode(&clock)
return clock, err
}
func (vc VClock) String() string {
if vc.IsNil() {
// vclock is Undef

View file

@ -21,24 +21,6 @@ type pubKey struct {
crypto.PubKey
}
func NewPubKey(t KeypairType, pk crypto.PubKey) (PubKey, error) {
if t != KeypairTypeAccount && t != KeypairTypeDevice {
return nil, fmt.Errorf("incorrect KeypairType")
}
pubk := pubKey{
keyType: t,
PubKey: pk,
}
_, err := getAddress(t, pk)
if err != nil {
return nil, err
}
return pubk, nil
}
func NewPubKeyFromAddress(t KeypairType, address string) (PubKey, error) {
if t != KeypairTypeAccount && t != KeypairTypeDevice {
return nil, fmt.Errorf("incorrect KeypairType")

View file

@ -6,8 +6,6 @@ import (
"math/rand"
"unicode"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/state"
"github.com/anytypeio/go-anytype-middleware/core/block/simple"
"github.com/anytypeio/go-anytype-middleware/pb"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/bundle"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
@ -15,17 +13,6 @@ import (
"github.com/gogo/protobuf/types"
)
func State(s *state.State) (res *state.State) {
// blocks
res = s.Copy()
s.Iterate(func(b simple.Block) (isContinue bool) {
b.Model().Content = Block(b.Model()).Content
return true
})
s.SetDetails(Struct(s.Details()))
return
}
func Change(ch *pb.Change) (res *pb.Change) {
resB, _ := ch.Marshal()
res = &pb.Change{}

View file

@ -6,16 +6,6 @@ import (
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
)
func AllBlocksToCode(blocks []*model.Block) (blocksOut []*model.Block) {
for i, b := range blocks {
if t := b.GetText(); t != nil {
blocks[i].GetText().Style = model.BlockContentText_Code
}
}
return PreprocessBlocks(blocks)
}
func PreprocessBlocks(blocks []*model.Block) (blocksOut []*model.Block) {
blocksOut = []*model.Block{}

View file

@ -21,7 +21,6 @@ import (
"github.com/anytypeio/go-anytype-middleware/pkg/lib/bundle"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/core/smartblock"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/localstore/addr"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/threads"
"github.com/anytypeio/go-anytype-middleware/util/pbtypes"
@ -32,8 +31,6 @@ const CName = "builtintemplate"
//go:embed data/bundled_templates.zip
var templatesZip []byte
var log = logging.Logger("anytype-mw-builtintemplate")
func New() BuiltinTemplate {
return new(builtinTemplate)
}

View file

@ -7,32 +7,11 @@ import (
"github.com/logrusorgru/aurora"
)
func Message(format string, args ...interface{}) {
if len(format) > 0 {
fmt.Println(aurora.Sprintf(aurora.BrightBlack("> "+format), args...))
}
}
func Success(format string, args ...interface{}) {
fmt.Println(aurora.Sprintf(aurora.Green("> Success! %s"),
aurora.Sprintf(aurora.BrightBlack(format), args...)))
}
func Warn(format string, args ...interface{}) {
fmt.Println(aurora.Sprintf(aurora.Magenta("> Warning! %s"),
aurora.Sprintf(aurora.BrightBlack(format), args...)))
}
func Error(format string, args ...interface{}) {
fmt.Println(aurora.Sprintf(aurora.Yellow("> Error! %s"),
aurora.Sprintf(aurora.BrightBlack(format), args...)))
}
func End(format string, args ...interface{}) {
Message(format, args...)
os.Exit(0)
}
func Fatal(format string, args ...interface{}) {
fmt.Println(aurora.Sprintf(aurora.Red("> Fatal! %s"),
aurora.Sprintf(aurora.BrightBlack(format), args...)))

View file

@ -1,3 +0,0 @@
package util
const SubIdSeparator = ":"

View file

@ -160,20 +160,6 @@ func RelationsDiff(rels1, rels2 []*model.Relation) (added []*model.Relation, upd
return
}
func RelationsEqual(rels1 []*model.Relation, rels2 []*model.Relation) (equal bool) {
if len(rels1) != len(rels2) {
return false
}
for i := 0; i < len(rels2); i++ {
if !RelationEqual(rels1[i], rels2[i]) {
return false
}
}
return true
}
func RelationEqualOmitDictionary(rel1 *model.Relation, rel2 *model.Relation) (equal bool) {
if rel1 == nil && rel2 != nil {
return false
@ -219,31 +205,6 @@ func RelationEqualOmitDictionary(rel1 *model.Relation, rel2 *model.Relation) (eq
return true
}
// RelationCompatible returns if provided relations are compatible in terms of underlying data format
// e.g. it is ok if relation can have a different name and selectDict, while having the same key and format
func RelationCompatible(rel1 *model.Relation, rel2 *model.Relation) (equal bool) {
if rel1 == nil && rel2 != nil {
return false
}
if rel2 == nil && rel1 != nil {
return false
}
if rel2 == nil && rel1 == nil {
return true
}
if rel1.Key != rel2.Key {
return false
}
if rel1.Format != rel2.Format {
return false
}
// todo: should we compare objectType here?
return true
}
func RelationEqual(rel1 *model.Relation, rel2 *model.Relation) (equal bool) {
if !RelationEqualOmitDictionary(rel1, rel2) {
return false
@ -266,75 +227,6 @@ func RelationSelectDictEqual(dict1, dict2 []*model.RelationOption) bool {
return true
}
func RelationSelectDictDiff(dict1, dict2 []*model.RelationOption) (added []*model.RelationOption, updated []*model.RelationOption, removed []string) {
for i := 0; i < len(dict2); i++ {
if opt := GetOption(dict1, dict2[i].Id); opt == nil {
added = append(added, dict2[i])
continue
} else {
if !OptionEqual(opt, dict2[i]) {
updated = append(updated, dict2[i])
continue
}
}
}
for i := 0; i < len(dict1); i++ {
if r := GetOption(dict2, dict1[i].Id); r == nil {
removed = append(removed, dict1[i].Id)
continue
}
}
return
}
func RelationSelectDictDiffOmitScope(dict1, dict2 []*model.RelationOption) (added []*model.RelationOption, updated []*model.RelationOption, removed []string) {
for i := 0; i < len(dict2); i++ {
if opt := GetOption(dict1, dict2[i].Id); opt == nil {
added = append(added, dict2[i])
continue
} else {
if !OptionEqualOmitScope(opt, dict2[i]) {
updated = append(updated, dict2[i])
continue
}
}
}
for i := 0; i < len(dict1); i++ {
if r := GetOption(dict2, dict1[i].Id); r == nil {
removed = append(removed, dict1[i].Id)
continue
}
}
return
}
func OptionEqualOmitScope(opt1, opt2 *model.RelationOption) bool {
if (opt1 == nil) && (opt2 != nil) {
return false
}
if (opt1 != nil) && (opt2 == nil) {
return false
}
if opt1 == nil && opt2 == nil {
return true
}
if opt1.Id != opt2.Id {
return false
}
if opt1.Text != opt2.Text {
return false
}
if opt1.Color != opt2.Color {
return false
}
return true
}
func OptionEqual(opt1, opt2 *model.RelationOption) bool {
if (opt1 == nil) && (opt2 != nil) {
return false
@ -496,18 +388,3 @@ func SortedRange(s *types.Struct, f func(k string, v *types.Value)) {
f(k, s.Fields[k])
}
}
func RelationOptionsFilter(options []*model.RelationOption, f func(option *model.RelationOption) bool) []*model.RelationOption {
if len(options) == 0 {
return nil
}
res := make([]*model.RelationOption, 0, len(options))
for i := range options {
if f(options[i]) {
res = append(res, options[i])
}
}
return res
}

View file

@ -29,23 +29,6 @@ func CopyBlock(in *model.Block) (out *model.Block) {
return
}
// CopyStructMap copies pb struct map, while reusing map values' pointers
func CopyStructMap(in *types.Struct) (out *types.Struct) {
if in == nil {
return nil
}
if in.Fields == nil {
return &types.Struct{}
}
out = &types.Struct{Fields: make(map[string]*types.Value, len(in.Fields))}
for k, v := range in.Fields {
out.Fields[k] = v
}
return
}
func CopyStruct(in *types.Struct) (out *types.Struct) {
if in == nil {
return nil
@ -82,13 +65,6 @@ func CopyVal(in *types.Value) (out *types.Value) {
return
}
func CopyRelationLink(in *model.RelationLink) (out *model.RelationLink) {
return &model.RelationLink{
Key: in.Key,
Format: in.Format,
}
}
func CopyRelation(in *model.Relation) (out *model.Relation) {
if in == nil {
return nil
@ -154,28 +130,6 @@ func CopyRelations(in []*model.Relation) (out []*model.Relation) {
return outWrapped.Relations
}
func CopyOptions(in []*model.RelationOption) (out []*model.RelationOption) {
if in == nil {
return nil
}
for _, inO := range in {
inCopy := *inO
out = append(out, &inCopy)
}
return
}
func CopyRelationsToMap(in []*model.Relation) (out map[string]*model.Relation) {
out = make(map[string]*model.Relation, len(in))
rels := CopyRelations(in)
for _, rel := range rels {
out[rel.Key] = rel
}
return
}
func CopyFilter(in *model.BlockContentDataviewFilter) (out *model.BlockContentDataviewFilter) {
buf := bytesPool.Get().([]byte)
size := in.Size()
@ -189,28 +143,6 @@ func CopyFilter(in *model.BlockContentDataviewFilter) (out *model.BlockContentDa
return
}
func RelationsFilterKeys(in []*model.Relation, keys []string) (out []*model.Relation) {
for i, inRel := range in {
if slice.FindPos(keys, inRel.Key) >= 0 {
out = append(out, in[i])
}
}
return
}
func StructNotNilKeys(st *types.Struct) (keys []string) {
if st == nil || st.Fields == nil {
return nil
}
for k, v := range st.Fields {
if v != nil {
keys = append(keys, k)
}
}
return
}
func EventsToSliceChange(changes []*pb.EventBlockDataviewSliceChange) []slice.Change {
sliceOpMap := map[pb.EventBlockDataviewSliceOperation]slice.DiffOperation{
pb.EventBlockDataview_SliceOperationNone: slice.OperationNone,

View file

@ -25,12 +25,6 @@ func Float64(v float64) *types.Value {
}
}
func Null() *types.Value {
return &types.Value{
Kind: &types.Value_NullValue{NullValue: types.NullValue_NULL_VALUE},
}
}
func String(v string) *types.Value {
return &types.Value{
Kind: &types.Value_StringValue{StringValue: v},
@ -238,39 +232,6 @@ func HasRelationLink(rels []*model.RelationLink, key string) bool {
return false
}
func MergeRelations(rels1 []*model.Relation, rels2 []*model.Relation) []*model.Relation {
if rels1 == nil {
return rels2
}
if rels2 == nil {
return rels1
}
rels := make([]*model.Relation, 0, len(rels2)+len(rels1))
for _, rel := range rels2 {
rels = append(rels, rel)
}
for _, rel := range rels1 {
if HasRelation(rels, rel.Key) {
continue
}
rels = append(rels, rel)
}
return rels
}
func GetObjectType(ots []*model.ObjectType, url string) *model.ObjectType {
for i, ot := range ots {
if ot.Url == url {
return ots[i]
}
}
return nil
}
func GetRelation(rels []*model.Relation, key string) *model.Relation {
for i, rel := range rels {
if rel.Key == key {
@ -281,26 +242,6 @@ func GetRelation(rels []*model.Relation, key string) *model.Relation {
return nil
}
func GetOption(opts []*model.RelationOption, id string) *model.RelationOption {
for i, opt := range opts {
if opt.Id == id {
return opts[i]
}
}
return nil
}
func HasOption(opts []*model.RelationOption, id string) bool {
for _, opt := range opts {
if opt.Id == id {
return true
}
}
return false
}
func Get(st *types.Struct, keys ...string) *types.Value {
for i, key := range keys {
if st == nil || st.Fields == nil {
@ -315,15 +256,6 @@ func Get(st *types.Struct, keys ...string) *types.Value {
return nil
}
func GetRelationKeys(rels []*model.Relation) []string {
var keys []string
for _, rel := range rels {
keys = append(keys, rel.Key)
}
return keys
}
func GetRelationListKeys(rels []*model.RelationLink) []string {
var keys []string
for _, rel := range rels {
@ -333,60 +265,6 @@ func GetRelationListKeys(rels []*model.RelationLink) []string {
return keys
}
func GetOptionIds(opts []*model.RelationOption) []string {
var keys []string
for _, opt := range opts {
keys = append(keys, opt.Id)
}
return keys
}
func MergeRelationsDicts(rels1 []*model.Relation, rels2 []*model.Relation) []*model.Relation {
rels := CopyRelations(rels1)
for _, rel2 := range rels2 {
var found bool
for i, rel := range rels {
if rel.Key == rel2.Key {
rel2Copy := CopyRelation(rel2)
rels[i].SelectDict = rel2Copy.SelectDict
rels[i].Name = rel2Copy.Name
found = true
break
}
}
if !found {
rels = append(rels, CopyRelation(rel2))
}
}
return rels
}
// MergeOptionsPreserveScope adds and updates options from opts2 into opts1 based on the ID
// in case opts2 doesn't have id that opts1 have it doesn't remove the existing one
// in case opts2 has the key that opts1 already have it updates everything except scope
func MergeOptionsPreserveScope(opts1 []*model.RelationOption, opts2 []*model.RelationOption) []*model.RelationOption {
opts := CopyOptions(opts1)
for _, opt2 := range opts2 {
var found bool
for i, opt := range opts {
if opt.Id == opt2.Id {
opts[i].Text = opt2.Text
opts[i].Color = opt2.Color
found = true
break
}
}
if !found {
opt2Copy := *opt2
opts = append(opts, &opt2Copy)
}
}
return opts
}
// StructToMap converts a types.Struct to a map from strings to Go types.
// StructToMap panics if s is invalid.
func StructToMap(s *types.Struct) map[string]interface{} {
@ -400,59 +278,6 @@ func StructToMap(s *types.Struct) map[string]interface{} {
return m
}
func StructIsEmpty(s *types.Struct) bool {
return s == nil || len(s.Fields) == 0
}
func GetMapOfKeysAndValuesFromStruct(collection *types.Struct) map[string]*types.Value {
keyMap := map[string]*types.Value{}
if collection == nil {
return keyMap
}
keyStack := []string{""}
collStack := []*types.Struct{collection}
for len(collStack) != 0 {
coll := collStack[len(collStack)-1]
lastKey := keyStack[len(keyStack)-1]
keyStack = keyStack[:len(keyStack)-1]
collStack = collStack[:len(collStack)-1]
for k, v := range coll.Fields {
subColl, ok := v.Kind.(*types.Value_StructValue)
updatedKey := lastKey
if updatedKey != "" {
updatedKey += "/"
}
updatedKey += k
if !ok {
keyMap[updatedKey] = v
continue
}
collStack = append(collStack, subColl.StructValue)
keyStack = append(keyStack, updatedKey)
}
}
return keyMap
}
func CompareKeyMaps(before map[string]*types.Value, after map[string]*types.Value) (keysSet []string, keysRemoved []string) {
for k, afterValue := range after {
beforeValue, exists := before[k]
if exists && afterValue.Equal(beforeValue) {
continue
}
keysSet = append(keysSet, k)
}
for k := range before {
if _, exists := after[k]; exists {
continue
}
keysRemoved = append(keysRemoved, k)
}
return
}
func ValueToInterface(v *types.Value) interface{} {
switch k := v.Kind.(type) {
case *types.Value_NullValue:
@ -476,18 +301,6 @@ func ValueToInterface(v *types.Value) interface{} {
}
}
func RelationFormatCanHaveListValue(format model.RelationFormat) bool {
switch format {
case model.RelationFormat_tag,
model.RelationFormat_file,
model.RelationFormat_object,
model.RelationFormat_number:
return true
default:
return false
}
}
func RelationIdToKey(id string) (string, error) {
if strings.HasPrefix(id, addr.RelationKeyToIdPrefix) {
return strings.TrimPrefix(id, addr.RelationKeyToIdPrefix), nil
@ -501,16 +314,6 @@ func RelationIdToKey(id string) (string, error) {
return "", fmt.Errorf("incorrect id format")
}
func Delete(st *types.Struct, key string) (ok bool) {
if st != nil && st.Fields != nil {
if _, ok := st.Fields[key]; ok {
delete(st.Fields, key)
return true
}
}
return false
}
type Getter interface {
Get(key string) *types.Value
}

View file

@ -1,9 +1,6 @@
package text
import (
"crypto/md5"
"fmt"
"strings"
"unicode"
"unicode/utf16"
)
@ -54,9 +51,3 @@ func StrToUTF16(str string) []uint16 {
func UTF16ToStr(b []uint16) string {
return string(utf16.Decode(b))
}
func SliceHash(keys []string) string {
s := strings.Join(keys, "_")
sum := md5.Sum([]byte(s))
return fmt.Sprintf("%x", sum)
}

View file

@ -5,8 +5,6 @@ import (
"os"
"regexp"
"strings"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
)
var (
@ -19,22 +17,6 @@ var (
winFilepathPrefixRegex = regexp.MustCompile(`^[a-zA-Z]:[\\\/]`)
)
func ValidateEmail(email string) bool {
if len(email) == 0 {
return false
}
return noPrefixEmailRegexp.MatchString(email)
}
func ValidatePhone(phone string) bool {
if len(phone) == 0 {
return false
}
return noPrefixTelRegexp.MatchString(phone)
}
// ProcessURI tries to verify the web URI and return the normalized URI
func ProcessURI(url string) (urlOut string, err error) {
if len(url) == 0 {
@ -61,21 +43,3 @@ func ProcessURI(url string) (urlOut string, err error) {
return url, fmt.Errorf("not a uri")
}
func ProcessAllURI(blocks []*model.Block) []*model.Block {
for bI, _ := range blocks {
if blocks[bI].GetText() != nil && blocks[bI].GetText().Marks != nil && len(blocks[bI].GetText().Marks.Marks) > 0 {
marks := blocks[bI].GetText().Marks.Marks
for mI, _ := range marks {
if marks[mI].Type == model.BlockContentTextMark_Link {
marks[mI].Param, _ = ProcessURI(marks[mI].Param)
}
}
blocks[bI].GetText().Marks.Marks = marks
}
}
return blocks
}