1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-10 18:10:54 +09:00
any-sync/commonspace/object/tree/treestorage/treestorage.go
2024-08-15 12:46:20 +02:00

42 lines
1.4 KiB
Go

//go:generate mockgen -destination mock_treestorage/mock_treestorage.go github.com/anyproto/any-sync/commonspace/object/tree/treestorage TreeStorage
package treestorage
import (
"context"
"errors"
"github.com/anyproto/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 Exporter interface {
TreeStorage(root *treechangeproto.RawTreeChangeWithId) (TreeStorage, error)
}
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
AddRawChangesSetHeads(changes []*treechangeproto.RawTreeChangeWithId, heads []string) error
GetAllChangeIds() ([]string, error)
GetRawChange(ctx context.Context, id string) (*treechangeproto.RawTreeChangeWithId, error)
GetAppendRawChange(ctx context.Context, buf []byte, id string) (*treechangeproto.RawTreeChangeWithId, error)
HasChange(ctx context.Context, id string) (bool, error)
Delete() error
}