2023-01-15 15:49:09 +01:00

36 lines
1.2 KiB
Go

//go:generate mockgen -destination mock_treestorage/mock_treestorage.go github.com/anytypeio/any-sync/commonspace/object/tree/treestorage TreeStorage
package treestorage
import (
"context"
"errors"
"github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto"
)
var (
ErrUnknownTreeId = errors.New("tree does not exist")
ErrTreeExists = errors.New("tree already exists")
ErrUnknownChange = errors.New("change doesn't exist")
)
type TreeStorageCreatePayload struct {
RootRawChange *treechangeproto.RawTreeChangeWithId
Changes []*treechangeproto.RawTreeChangeWithId
Heads []string
}
type TreeStorageCreatorFunc = func(payload TreeStorageCreatePayload) (TreeStorage, error)
type TreeStorage interface {
Id() string
Root() (*treechangeproto.RawTreeChangeWithId, error)
Heads() ([]string, error)
SetHeads(heads []string) error
AddRawChange(change *treechangeproto.RawTreeChangeWithId) error
TransactionAdd(changes []*treechangeproto.RawTreeChangeWithId, heads []string) error
GetRawChange(ctx context.Context, id string) (*treechangeproto.RawTreeChangeWithId, error)
HasChange(ctx context.Context, id string) (bool, error)
Delete() error
}