generic

package
v3.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KindNil  = Kind("")
	KindRoot = Kind("<root>")
)
View Source
var (
	NilNode   = &Node{isNil: true}
	NilParent = NilNode
)
View Source
var DefaultPageSize = int(25)
View Source
var NilID = NodeID("")

Functions

func NewError

func NewError[T error](message string, args ...any) T

func NodeCompare

func NodeCompare(ctx context.Context, a, b NodeInterface) bool

func NodeCopy

func NodeCopy(ctx context.Context, origin, destination NodeInterface, destinationID NodeID, options *UnifyOptions)

func NodeMirror

func NodeMirror(ctx context.Context, origin, destination NodeInterface, options *MirrorOptions)

func NodeParallelApply

func NodeParallelApply(ctx context.Context, origin NodeInterface, path Path, destination NodeInterface, options *ParallelApplyOptions) bool

func NodeUnify

func NodeUnify(ctx context.Context, origin NodeInterface, originPath Path, destination NodeInterface, destinationPath Path, options *UnifyOptions)

func NodeUnifyPath

func NodeUnifyPath(ctx context.Context, origin NodeInterface, originPath, path, destinationPath Path, options *UnifyOptions) bool

func PathAbsoluteString

func PathAbsoluteString(current, destination string) string

func PathRelativeString added in v3.2.0

func PathRelativeString(current, destination string) string

func RegisterFactory

func RegisterFactory(name string, factory TreeFactory)

func RemapReferences

func RemapReferences(ctx context.Context, node NodeInterface, f f3.Interface)

func SetMappedID

func SetMappedID(ctx context.Context, origin, destination NodeInterface, options *UnifyOptions)

func TreeCompare

func TreeCompare(ctx context.Context, aTree TreeInterface, aPath Path, bTree TreeInterface, bPath Path) bool

func TreeMirror

func TreeMirror(ctx context.Context, originTree, destinationTree TreeInterface, path Path, options *MirrorOptions)

func TreeParallelApply

func TreeParallelApply(ctx context.Context, origin TreeInterface, path Path, destination TreeInterface, options *ParallelApplyOptions) bool

func TreePartialMirror

func TreePartialMirror(ctx context.Context, originTree TreeInterface, originPath Path, destinationTree TreeInterface, destinationPath Path, options *MirrorOptions)

func TreeUnify

func TreeUnify(ctx context.Context, origin, destination TreeInterface, options *UnifyOptions)

func TreeUnifyPath

func TreeUnifyPath(ctx context.Context, origin TreeInterface, path Path, destination TreeInterface, options *UnifyOptions) bool

Types

type ApplyFunc

type ApplyFunc func(ctx context.Context, parentPath, path Path, node NodeInterface)

type ApplyOptions

type ApplyOptions struct {
	// contains filtered or unexported fields
}

func NewApplyOptions

func NewApplyOptions(fun ApplyFunc) *ApplyOptions

func (*ApplyOptions) SetSearch

func (o *ApplyOptions) SetSearch(search ApplySearch) *ApplyOptions

func (*ApplyOptions) SetWhere

func (o *ApplyOptions) SetWhere(where ApplyWhere) *ApplyOptions

type ApplySearch

type ApplySearch bool
const (
	ApplySearchByName ApplySearch = true
	ApplySearchByID   ApplySearch = false
)

type ApplyWhere

type ApplyWhere bool
const (
	ApplyEachNode ApplyWhere = true
	ApplyLastNode ApplyWhere = false
)

type ChildrenSlice

type ChildrenSlice []NodeInterface

func NewChildrenSlice

func NewChildrenSlice(len int) ChildrenSlice

func (ChildrenSlice) Len

func (o ChildrenSlice) Len() int

func (ChildrenSlice) Less

func (o ChildrenSlice) Less(i, j int) bool

func (ChildrenSlice) Swap

func (o ChildrenSlice) Swap(i, j int)

type ErrorNodeNotFound

type ErrorNodeNotFound error

type ErrorRemapReferencesRelative added in v3.3.1

type ErrorRemapReferencesRelative error

type FactoryFun

type FactoryFun func(ctx context.Context, kind Kind) NodeInterface

type Kind

type Kind string

type MapIDInterface

type MapIDInterface interface {
	GetMappedID() NodeID
	SetMappedID(NodeID)
}

type MirrorOptions

type MirrorOptions struct {
	// contains filtered or unexported fields
}

func NewMirrorOptions

func NewMirrorOptions() *MirrorOptions

func (*MirrorOptions) SetNoRemap

func (o *MirrorOptions) SetNoRemap(noremap bool) *MirrorOptions

type Node

type Node struct {
	logger.Logger
	// contains filtered or unexported fields
}

func (*Node) Apply

func (o *Node) Apply(ctx context.Context, parentPath, path Path, options *ApplyOptions) bool

func (*Node) ApplyAndGet

func (o *Node) ApplyAndGet(ctx context.Context, path Path, options *ApplyOptions) bool

func (*Node) CreateChild

func (o *Node) CreateChild(ctx context.Context) NodeInterface

func (*Node) Delete

func (o *Node) Delete(ctx context.Context) NodeInterface

func (*Node) DeleteChild

func (o *Node) DeleteChild(id NodeID) NodeInterface

func (*Node) Equals

func (o *Node) Equals(ctx context.Context, other NodeInterface) bool

func (*Node) Find

func (o *Node) Find(path Path) NodeInterface

func (*Node) FindAndGet

func (o *Node) FindAndGet(ctx context.Context, path Path) NodeInterface

func (*Node) FromFormat

func (o *Node) FromFormat(f f3.Interface) NodeInterface

func (*Node) Get

func (o *Node) Get(ctx context.Context) NodeInterface

func (*Node) GetChild

func (o *Node) GetChild(id NodeID) NodeInterface

func (*Node) GetChildren

func (o *Node) GetChildren() ChildrenSlice

func (*Node) GetCurrentPath

func (o *Node) GetCurrentPath() Path

func (*Node) GetDriver

func (o *Node) GetDriver() NodeDriverInterface

func (*Node) GetID

func (o *Node) GetID() NodeID

func (*Node) GetIDFromName

func (o *Node) GetIDFromName(ctx context.Context, name string) NodeID

func (*Node) GetIsNil

func (o *Node) GetIsNil() bool

func (*Node) GetIsSync

func (o *Node) GetIsSync() bool

func (*Node) GetKind

func (o *Node) GetKind() Kind

func (*Node) GetMappedID

func (o *Node) GetMappedID() NodeID

func (*Node) GetNodeChildren

func (o *Node) GetNodeChildren() NodeChildren

func (*Node) GetParent

func (o *Node) GetParent() NodeInterface

func (*Node) GetSelf

func (o *Node) GetSelf() NodeInterface

func (*Node) GetTree

func (o *Node) GetTree() TreeInterface

func (*Node) Init

func (o *Node) Init(self NodeInterface) NodeInterface

func (*Node) List

func (o *Node) List(ctx context.Context) ChildrenSlice

func (*Node) ListPage

func (o *Node) ListPage(ctx context.Context, page int) ChildrenSlice

func (*Node) LookupMappedID

func (o *Node) LookupMappedID(id NodeID) NodeID

func (*Node) MustFind

func (o *Node) MustFind(path Path) NodeInterface

func (*Node) NewFormat

func (o *Node) NewFormat() f3.Interface

func (*Node) SetChild

func (o *Node) SetChild(child NodeInterface) NodeInterface

func (*Node) SetChildren

func (o *Node) SetChildren(children NodeChildren)

func (*Node) SetDriver

func (o *Node) SetDriver(driver NodeDriverInterface)

func (*Node) SetID

func (o *Node) SetID(id NodeID)

func (*Node) SetIsNil

func (o *Node) SetIsNil(isNil bool)

func (*Node) SetIsSync

func (o *Node) SetIsSync(sync bool)

func (*Node) SetKind

func (o *Node) SetKind(kind Kind)

func (*Node) SetMappedID

func (o *Node) SetMappedID(mapped NodeID)

func (*Node) SetParent

func (o *Node) SetParent(parent NodeInterface)

func (*Node) SetSelf

func (o *Node) SetSelf(self NodeInterface)

func (*Node) SetTree

func (o *Node) SetTree(tree TreeInterface)

func (*Node) String

func (o *Node) String() string

func (*Node) ToFormat

func (o *Node) ToFormat() f3.Interface

func (*Node) Upsert

func (o *Node) Upsert(ctx context.Context) NodeInterface

func (*Node) Walk

func (o *Node) Walk(ctx context.Context, parent Path, options *WalkOptions)

func (*Node) WalkAndGet

func (o *Node) WalkAndGet(ctx context.Context, parent Path, options *WalkOptions)

type NodeAccessorsInterface

type NodeAccessorsInterface interface {
	SetIsNil(bool)
	GetIsNil() bool

	SetIsSync(bool)
	GetIsSync() bool

	GetParent() NodeInterface
	SetParent(NodeInterface)

	GetKind() Kind
	SetKind(Kind)

	GetID() NodeID
	SetID(NodeID)

	GetTree() TreeInterface
	SetTree(TreeInterface)

	GetNodeChildren() NodeChildren
	GetChildren() ChildrenSlice
	SetChildren(NodeChildren)

	GetDriver() NodeDriverInterface
	SetDriver(NodeDriverInterface)
}

type NodeChildren

type NodeChildren map[NodeID]NodeInterface

func NewNodeChildren

func NewNodeChildren() NodeChildren

type NodeDriverInterface

type NodeDriverInterface interface {
	logger.MessageInterface

	MapIDInterface

	IsNull() bool

	GetNode() NodeInterface
	SetNode(NodeInterface)

	SetTreeDriver(treeDriver TreeDriverInterface)
	GetTreeDriver() TreeDriverInterface

	ListPage(context.Context, int) ChildrenSlice
	GetIDFromName(context.Context, string) NodeID

	Equals(context.Context, NodeInterface) bool

	Get(context.Context) bool
	Put(context.Context) NodeID
	Patch(context.Context)
	Delete(context.Context)

	NewFormat() f3.Interface
	FromFormat(f3.Interface)
	ToFormat() f3.Interface

	LookupMappedID(NodeID) NodeID

	String() string
}

func NewNullDriver

func NewNullDriver() NodeDriverInterface

type NodeDriverProxyInterface

type NodeDriverProxyInterface interface {
	MapIDInterface
	ListPage(context.Context, int) ChildrenSlice
	GetIDFromName(context.Context, string) NodeID

	Equals(context.Context, NodeInterface) bool

	Get(context.Context) NodeInterface
	Upsert(context.Context) NodeInterface
	Delete(context.Context) NodeInterface

	NewFormat() f3.Interface
	FromFormat(f3.Interface) NodeInterface
	ToFormat() f3.Interface

	LookupMappedID(NodeID) NodeID
}

type NodeID

type NodeID string

func GetMappedID

func GetMappedID(ctx context.Context, origin, destinationParent NodeInterface, options *UnifyOptions) NodeID

type NodeInterface

func NewNode

func NewNode() NodeInterface

func NewNodeFromID

func NewNodeFromID[T any](id T) NodeInterface

func NodeUnifyOne

func NodeUnifyOne(ctx context.Context, origin NodeInterface, originPath, path, destinationPath Path, options *UnifyOptions) NodeInterface

type NodeTreeInterface

type NodeTreeInterface interface {
	GetChild(NodeID) NodeInterface
	GetIDFromName(context.Context, string) NodeID
	SetChild(NodeInterface) NodeInterface
	DeleteChild(NodeID) NodeInterface
	CreateChild(context.Context) NodeInterface

	MustFind(Path) NodeInterface
	Find(Path) NodeInterface
	FindAndGet(context.Context, Path) NodeInterface

	GetCurrentPath() Path

	Walk(ctx context.Context, parent Path, options *WalkOptions)
	WalkAndGet(ctx context.Context, parent Path, options *WalkOptions)
	Apply(ctx context.Context, parent, path Path, options *ApplyOptions) bool
	ApplyAndGet(ctx context.Context, path Path, options *ApplyOptions) bool

	List(context.Context) ChildrenSlice
}

type NullDriver

type NullDriver struct {
	logger.Logger
	// contains filtered or unexported fields
}

func (*NullDriver) Delete

func (o *NullDriver) Delete(context.Context)

func (*NullDriver) Equals

func (*NullDriver) FromFormat

func (o *NullDriver) FromFormat(f3.Interface)

func (*NullDriver) Get

func (o *NullDriver) Get(context.Context) bool

func (*NullDriver) GetIDFromName

func (o *NullDriver) GetIDFromName(ctx context.Context, name string) NodeID

func (*NullDriver) GetMappedID

func (o *NullDriver) GetMappedID() NodeID

func (*NullDriver) GetNode

func (o *NullDriver) GetNode() NodeInterface

func (*NullDriver) GetTreeDriver

func (o *NullDriver) GetTreeDriver() TreeDriverInterface

func (*NullDriver) IsNull

func (o *NullDriver) IsNull() bool

func (*NullDriver) ListPage

func (o *NullDriver) ListPage(context.Context, int) ChildrenSlice

func (*NullDriver) LookupMappedID

func (o *NullDriver) LookupMappedID(NodeID) NodeID

func (*NullDriver) NewFormat

func (o *NullDriver) NewFormat() f3.Interface

func (*NullDriver) Patch

func (o *NullDriver) Patch(context.Context)

func (*NullDriver) Put

func (o *NullDriver) Put(context.Context) NodeID

func (*NullDriver) SetMappedID

func (o *NullDriver) SetMappedID(mapped NodeID)

func (*NullDriver) SetNode

func (o *NullDriver) SetNode(node NodeInterface)

func (*NullDriver) SetTreeDriver

func (o *NullDriver) SetTreeDriver(treeDriver TreeDriverInterface)

func (*NullDriver) String

func (o *NullDriver) String() string

func (*NullDriver) ToFormat

func (o *NullDriver) ToFormat() f3.Interface

type NullTreeDriver

type NullTreeDriver struct {
	logger.Logger
	// contains filtered or unexported fields
}

func (*NullTreeDriver) AllocateID

func (o *NullTreeDriver) AllocateID() bool

func (*NullTreeDriver) Diff

func (*NullTreeDriver) Factory

func (o *NullTreeDriver) Factory(ctx context.Context, kind Kind) NodeDriverInterface

func (*NullTreeDriver) GetPageSize

func (o *NullTreeDriver) GetPageSize() int

func (*NullTreeDriver) GetTree

func (o *NullTreeDriver) GetTree() TreeInterface

func (*NullTreeDriver) Init

func (o *NullTreeDriver) Init()

func (*NullTreeDriver) SetPageSize

func (o *NullTreeDriver) SetPageSize(pageSize int)

func (*NullTreeDriver) SetTree

func (o *NullTreeDriver) SetTree(tree TreeInterface)

type ParallelApplyFunc

type ParallelApplyFunc func(ctx context.Context, origin, destination NodeInterface)

type ParallelApplyOptions

type ParallelApplyOptions struct {
	// contains filtered or unexported fields
}

func NewParallelApplyOptions

func NewParallelApplyOptions(fun ParallelApplyFunc) *ParallelApplyOptions

func (*ParallelApplyOptions) SetNoRemap

func (o *ParallelApplyOptions) SetNoRemap(noremap bool) *ParallelApplyOptions

func (*ParallelApplyOptions) SetWhere

type Path

type Path interface {
	Length() int
	PathString() PathString
	PathMappedString() PathString
	String() string
	Append(child NodeInterface) Path
	RemoveFirst() Path
	PopFirst() (NodeInterface, Path)
	Pop() (NodeInterface, Path)
	RemoveLast() Path
	Empty() bool
	First() NodeInterface
	Last() NodeInterface
	All() []NodeInterface
}

func NewPath

func NewPath(nodes ...NodeInterface) Path

func NewPathFromString

func NewPathFromString(pathString string) Path

func NodeCollectReferences

func NodeCollectReferences(ctx context.Context, node NodeInterface) []Path

func PathAbsolute

func PathAbsolute(current, destination string) Path

func TreeCollectReferences

func TreeCollectReferences(ctx context.Context, tree TreeInterface, path Path) []Path

func TreePathRemap

func TreePathRemap(ctx context.Context, origin TreeInterface, path Path, destination TreeInterface) Path

type PathImplementation

type PathImplementation []NodeInterface

func (PathImplementation) All

func (PathImplementation) Append

func (o PathImplementation) Append(child NodeInterface) Path

func (PathImplementation) Empty

func (o PathImplementation) Empty() bool

func (PathImplementation) First

func (PathImplementation) Last

func (PathImplementation) Length

func (o PathImplementation) Length() int

func (PathImplementation) PathMappedString

func (o PathImplementation) PathMappedString() PathString

func (PathImplementation) PathString

func (o PathImplementation) PathString() PathString

func (PathImplementation) Pop

func (PathImplementation) PopFirst

func (o PathImplementation) PopFirst() (NodeInterface, Path)

func (PathImplementation) RemoveFirst

func (o PathImplementation) RemoveFirst() Path

func (PathImplementation) RemoveLast

func (o PathImplementation) RemoveLast() Path

func (PathImplementation) String

func (o PathImplementation) String() string

type PathString

type PathString []string

func (PathString) Empty

func (o PathString) Empty() bool

func (PathString) Join

func (o PathString) Join() string

type Tree

type Tree struct {
	logger.Logger
	// contains filtered or unexported fields
}

func (*Tree) AllocateID

func (o *Tree) AllocateID() bool

func (*Tree) Apply

func (o *Tree) Apply(ctx context.Context, path Path, options *ApplyOptions) bool

func (*Tree) ApplyAndGet

func (o *Tree) ApplyAndGet(ctx context.Context, path Path, options *ApplyOptions) bool

func (*Tree) Clear

func (o *Tree) Clear(ctx context.Context)

func (*Tree) Diff

func (o *Tree) Diff(a, b NodeInterface) string

func (*Tree) Exists

func (o *Tree) Exists(ctx context.Context, path Path) bool

func (*Tree) Factory

func (o *Tree) Factory(ctx context.Context, kind Kind) NodeInterface

func (*Tree) Find

func (o *Tree) Find(path Path) NodeInterface

func (*Tree) FindAndGet

func (o *Tree) FindAndGet(ctx context.Context, path Path) NodeInterface

func (*Tree) GetChildrenKind

func (o *Tree) GetChildrenKind(parentKind Kind) Kind

func (*Tree) GetDriver

func (o *Tree) GetDriver() TreeDriverInterface

func (*Tree) GetOptions

func (o *Tree) GetOptions() options.Interface

func (*Tree) GetPageSize

func (o *Tree) GetPageSize() int

func (*Tree) GetRoot

func (o *Tree) GetRoot() NodeInterface

func (*Tree) GetSelf

func (o *Tree) GetSelf() TreeInterface

func (*Tree) Init

func (o *Tree) Init(self TreeInterface, opts options.Interface) TreeInterface

func (*Tree) MustFind

func (o *Tree) MustFind(path Path) NodeInterface

func (*Tree) Register

func (o *Tree) Register(kind Kind, factory FactoryFun)

func (*Tree) SetDriver

func (o *Tree) SetDriver(driver TreeDriverInterface)

func (*Tree) SetOptions

func (o *Tree) SetOptions(opts options.Interface)

func (*Tree) SetRoot

func (o *Tree) SetRoot(root NodeInterface)

func (*Tree) SetSelf

func (o *Tree) SetSelf(self TreeInterface)

func (*Tree) Walk

func (o *Tree) Walk(ctx context.Context, options *WalkOptions)

func (*Tree) WalkAndGet

func (o *Tree) WalkAndGet(ctx context.Context, options *WalkOptions)

type TreeDriverInterface

type TreeDriverInterface interface {
	logger.Interface

	GetTree() TreeInterface
	SetTree(TreeInterface)

	GetPageSize() int
	SetPageSize(int)

	AllocateID() bool

	Init()

	Diff(a, b NodeDriverInterface) string

	Factory(ctx context.Context, kind Kind) NodeDriverInterface
}

func NewNullTreeDriver

func NewNullTreeDriver() TreeDriverInterface

type TreeFactory

type TreeFactory func(ctx context.Context, opts options.Interface) TreeInterface

func GetFactory

func GetFactory(name string) TreeFactory

type TreeInterface

type TreeInterface interface {
	logger.Interface

	Init(TreeInterface, options.Interface) TreeInterface

	GetOptions() options.Interface
	SetOptions(options.Interface)

	GetSelf() TreeInterface
	SetSelf(TreeInterface)

	SetRoot(NodeInterface)
	GetRoot() NodeInterface

	SetLogger(logger.Interface)
	GetLogger() logger.Interface

	GetDriver() TreeDriverInterface
	SetDriver(TreeDriverInterface)

	GetChildrenKind(Kind) Kind

	GetPageSize() int

	AllocateID() bool

	Clear(context.Context)

	Diff(a, b NodeInterface) string

	MustFind(Path) NodeInterface
	Find(Path) NodeInterface
	FindAndGet(context.Context, Path) NodeInterface
	Exists(context.Context, Path) bool

	Walk(context.Context, *WalkOptions)
	WalkAndGet(context.Context, *WalkOptions)
	Apply(context.Context, Path, *ApplyOptions) bool
	ApplyAndGet(context.Context, Path, *ApplyOptions) bool

	Register(kind Kind, factory FactoryFun)
	Factory(ctx context.Context, kind Kind) NodeInterface
}

func NewTree

func NewTree(opts options.Interface) TreeInterface

type UnifyDeleteFunc

type UnifyDeleteFunc func(ctx context.Context, destination NodeInterface, destinationParent Path)

type UnifyOptions

type UnifyOptions struct {
	// contains filtered or unexported fields
}

func NewUnifyOptions

func NewUnifyOptions(destinationTree TreeInterface) *UnifyOptions

func (*UnifyOptions) SetDelete

func (o *UnifyOptions) SetDelete(delete UnifyDeleteFunc) *UnifyOptions

func (*UnifyOptions) SetNoRemap

func (o *UnifyOptions) SetNoRemap(noremap bool) *UnifyOptions

func (*UnifyOptions) SetUpsert

func (o *UnifyOptions) SetUpsert(upsert UnifyUpsertFunc) *UnifyOptions

type UnifyUpsertFunc

type UnifyUpsertFunc func(ctx context.Context, origin NodeInterface, originParent Path, destination NodeInterface, destinationParent Path)

type WalkFunc

type WalkFunc func(context.Context, Path, NodeInterface)

type WalkOptions

type WalkOptions struct {
	// contains filtered or unexported fields
}

func NewWalkOptions

func NewWalkOptions(fun WalkFunc) *WalkOptions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL