master
go 58 lines 1.71 KB
Raw
1 package iface
2
3 import (
4 "context"
5
6 "github.com/ipfs/boxo/path"
7 "github.com/ipfs/kubo/core/coreiface/options"
8 )
9
10 // ChangeType denotes type of change in ObjectChange
11 type ChangeType int
12
13 const (
14 // DiffAdd is set when a link was added to the graph
15 DiffAdd ChangeType = iota
16
17 // DiffRemove is set when a link was removed from the graph
18 DiffRemove
19
20 // DiffMod is set when a link was changed in the graph
21 DiffMod
22 )
23
24 // ObjectChange represents a change ia a graph
25 type ObjectChange struct {
26 // Type of the change, either:
27 // * DiffAdd - Added a link
28 // * DiffRemove - Removed a link
29 // * DiffMod - Modified a link
30 Type ChangeType
31
32 // Path to the changed link
33 Path string
34
35 // Before holds the link path before the change. Note that when a link is
36 // added, this will be nil.
37 Before path.ImmutablePath
38
39 // After holds the link path after the change. Note that when a link is
40 // removed, this will be nil.
41 After path.ImmutablePath
42 }
43
44 // ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
45 // for manipulating MerkleDAG data structures.
46 type ObjectAPI interface {
47 // AddLink adds a link under the specified path. child path can point to a
48 // subdirectory within the patent which must be present (can be overridden
49 // with WithCreate option).
50 AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.ImmutablePath, error)
51
52 // RmLink removes a link from the node
53 RmLink(ctx context.Context, base path.Path, link string, opts ...options.ObjectRmLinkOption) (path.ImmutablePath, error)
54
55 // Diff returns a set of changes needed to transform the first object into the
56 // second.
57 Diff(context.Context, path.Path, path.Path) ([]ObjectChange, error)
58 }