mergeop

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

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
  • github.com/signadot/tony-format/go-tony/ir - IR representation
  • github.com/signadot/tony-format/go-tony/schema - Schema system

Index

Constants

This section is empty.

Variables

View Source
var ErrSymbolExists = errors.New("symbol exists")

Functions

func QuoteY

func QuoteY(node *ir.Node) (*ir.Node, error)

func Register

func Register(s Symbol) error

func SplitChild

func SplitChild(opDoc *ir.Node) (tag string, args []string, child *ir.Node, err error)

func UnquoteY

func UnquoteY(node *ir.Node) (*ir.Node, error)

Types

type MatchFunc

type MatchFunc func(*ir.Node, *ir.Node) (bool, error)

type Name

type Name interface {
	String() string
	IsMatch() bool
	IsPatch() bool
}

type Op

type Op interface {
	Match(doc *ir.Node, f MatchFunc) (bool, error)
	Patch(doc *ir.Node, mf MatchFunc, pf PatchFunc, df libdiff.DiffFunc) (*ir.Node, error)
	String() string
}

type PatchFunc

type PatchFunc func(*ir.Node, *ir.Node) (*ir.Node, error)

type Symbol

type Symbol interface {
	Name
	Instance(child *ir.Node, args []string) (Op, error)
}

func AddTag

func AddTag() Symbol

func All

func All() Symbol

func And

func And() Symbol

func ArrayDiff

func ArrayDiff() Symbol

func Delete

func Delete() Symbol

func Dive

func Dive() Symbol

func Embed

func Embed() Symbol

func Field

func Field() Symbol

func Glob

func Glob() Symbol

func HasPath added in v0.0.11

func HasPath() Symbol

func If

func If() Symbol

func Insert

func Insert() Symbol

func JSONPatch

func JSONPatch() Symbol

func KeyedList

func KeyedList() Symbol

func Let

func Let() Symbol

func Lookup

func Lookup(s string) Symbol

func Not

func Not() Symbol

func Nullify

func Nullify() Symbol

func Or

func Or() Symbol

func Pass

func Pass() Symbol

func Pipe

func Pipe() Symbol

func Quote

func Quote() Symbol

func RemoveTag

func RemoveTag() Symbol

func Rename

func Rename() Symbol

func Replace

func Replace() Symbol

func Retag

func Retag() Symbol

func StrDiff

func StrDiff() Symbol

func Subtree

func Subtree() Symbol

func Symbols

func Symbols() []Symbol

func Tag

func Tag() Symbol

func Type

func Type() Symbol

func Unquote

func Unquote() Symbol

Jump to

Keyboard shortcuts

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