Documentation
¶
Overview ¶
Package mergeop provides match and patch operations for Tony documents.
Operations are invoked via tags (e.g., !or, !and, !nullify) and work on ir.Node trees. Operations fall into two categories:
- Match: Validate/query documents (return bool)
- Patch: Transform documents (return modified node)
Contexts ¶
Operations belong to execution contexts:
- Match: Validation (!or, !and, !not, !type, !glob, !has-path, etc.)
- Patch: Transformation (!nullify, !insert, !delete, !replace, etc.)
- Eval: Evaluation (!eval, !exec, !file, etc.)
- Diff: Diffing (!strdiff, !arraydiff)
Match Operations ¶
Match operations validate or query documents:
// Check if kind is ConfigMap or Secret
matchNode := &ir.Node{
Tag: "!or",
Type: ir.ArrayType,
Values: []*ir.Node{
ir.FromString("ConfigMap"),
ir.FromString("Secret"),
},
}
op := mergeop.Lookup("or")
matched, _ := op.Match(doc, matchFunc)
Patch Operations ¶
Patch operations transform documents:
// Set field to null
patchNode := &ir.Node{Tag: "!nullify", Type: ir.NullType}
op := mergeop.Lookup("nullify")
patched, _ := op.Patch(doc, matchFunc, patchFunc, diffFunc)
Tag Composition ¶
Tags compose to create specific operations:
- !all.has-path "foo": All items must have path "foo"
- !not.or: Negation of OR
- !subtree.field.glob "x-*": Find matching fields in subtree
Operation Interface ¶
type Op interface {
Match(doc *ir.Node, f MatchFunc) (bool, error)
Patch(doc *ir.Node, mf MatchFunc, pf PatchFunc, df DiffFunc) (*ir.Node, error)
String() string
}
Operations implement Match() or Patch() or both. Use IsMatch() and IsPatch() to check which are supported.
Registration ¶
op := mergeop.Lookup("or") // Lookup by name
allOps := mergeop.Symbols() // List all operations
mergeop.Register(myCustomOp) // Register custom operation
Related Packages ¶
- github.com/signadot/tony-format/go-tony/ir - IR representation
- github.com/signadot/tony-format/go-tony/schema - Schema system
Index ¶
- Variables
- func QuoteY(node *ir.Node) (*ir.Node, error)
- func Register(s Symbol) error
- func SplitChild(opDoc *ir.Node) (tag string, args []string, child *ir.Node, err error)
- func UnquoteY(node *ir.Node) (*ir.Node, error)
- type MatchFunc
- type Name
- type Op
- type PatchFunc
- type Symbol
- func AddTag() Symbol
- func All() Symbol
- func And() Symbol
- func ArrayDiff() Symbol
- func Delete() Symbol
- func Dive() Symbol
- func Embed() Symbol
- func Field() Symbol
- func Glob() Symbol
- func HasPath() Symbol
- func If() Symbol
- func Insert() Symbol
- func JSONPatch() Symbol
- func KeyedList() Symbol
- func Let() Symbol
- func Lookup(s string) Symbol
- func Not() Symbol
- func Nullify() Symbol
- func Or() Symbol
- func Pass() Symbol
- func Pipe() Symbol
- func Quote() Symbol
- func RemoveTag() Symbol
- func Rename() Symbol
- func Replace() Symbol
- func Retag() Symbol
- func StrDiff() Symbol
- func Subtree() Symbol
- func Symbols() []Symbol
- func Tag() Symbol
- func Type() Symbol
- func Unquote() Symbol
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrSymbolExists = errors.New("symbol exists")
Functions ¶
func SplitChild ¶
Types ¶
Source Files
¶
- addtag.go
- all.go
- and.go
- arraydiff.go
- delete.go
- dive.go
- doc.go
- embed.go
- field.go
- glob.go
- has_path.go
- if.go
- insert.go
- jsonpatch.go
- keyed_list.go
- let.go
- match.go
- not.go
- nullify.go
- op.go
- or.go
- pass.go
- patch.go
- pipe.go
- quote.go
- register.go
- rename.go
- replace.go
- retag.go
- rmtag.go
- split_child.go
- strdiff.go
- subtree.go
- symbol.go
- tag.go
- type.go
- unquote.go
Click to show internal directories.
Click to hide internal directories.