structural

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

README

structural

Structural diff, merge, patch, pick, and mask helpers for CUE.

MVS will make using cue modules easier.

Index

support for both Cue and Go vals/structs

  1. Usage
  2. equal
  3. diff
  4. merge
  5. patch
  6. pick
  7. mask
  8. Developing

Usage

structural is most easily used with cue modules, see https://github.com/hofstadter-io/mvs.

Initialize a cue module
mvs init cue github.com/<namespace>/<project>
Add structural to your cue.mods file:
require github.com/hofstadter-io/structural v0.0.3
Update your dependencies:
mvs vendor
After creating example.cue (see below) run the following:
cue eval example.cue
cue export example.cue

Look for a "same" field == true

example.cue
import "github.com/hofstadter-io/structural"

A :: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
}
B :: {
	b: "b"
	c: "c"
	N: {x: "x", z: "z"}
}

diff: {
  same: (ex & an) != _|_
  ex: (structural.Diff & {Orig: A, New: B}).Result
  an: {
    "[]": {
      removed: {
        a: "a"
      }
      added: {
        c: "c"
      }
    }
    "[\"N\"]": {
      removed: {
        y: "y"
      }
      added: {
        z: "z"
      }
    }
  }
}

merge: {
  same: (ex & an) != _|_
  ex: (structural.Merge & {Orig: A, New: B}).Result
  an: {
    a: "a"
    b: "b"
    c: "c"
    N: {
      x: "x"
      y: "y"
      z: "z"
    }
  }
}

Diff

Diff :: {
	// Arguments
	Orig: {...}
	New:  {...}

	Result: {...}
}
A :: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
}
Z :: {
	a: "a"
	b: "b"
	N: "N"
}
x: (structural.Diff & {Orig: A, New: Z}).Result
x: {
	changed: {
	  N: {
	    from: {
	      x: "x"
	      y: "y"
	    }
	    to: "N"
	  }
	}
}

Merge

Merge :: {
	// Arguments
	Orig: {...}
	New:  {...}

	Result: {...}
A :: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
}
B :: {
	b: "b"
	c: "c"
	N: {x: "x", z: "z"}
}
x: (structural.Merge & {Orig: A, New: B}).Result
x: {
  a: "a"
  b: "b"
  c: "c"
  N: {
    x: "x"
    y: "y"
    z: "z"
  }
}

Patch

Patch :: {
	// Arguments
	Orig: {...}
	Diff: {...}

	Result: {...}
}
x: (structural.Patch & {Orig: {a: "a", b: "b", y: "y", N: {x: "x"}},
												 Diff: {inplace: {N: {changed: {x: {from: "x", to: "xx"}}}}, changed: {y: {from: "y", to: "yy"}}, removed: {b: "b"}, added: {z: "z"}}}).Result
x: {a: "a", y: "yy", N: {x: "xx"}, z: "z"}

Pick

Pick :: {
	// Arguments
  Orig: {...}
  Pick: {...}

  Result: {...}
}
X:: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
	l: [1, 2, 3, 4, 5]
}
x: (structural.Pick & {Orig: X, Pick: { b: string, N: {x: string}, l: [1, 1, 3] }}).Result
x: {
  b: "b"
  N: {
    x: "x"
  }
  l: [1, 3]
}

Mask

Mask :: {
	// Arguments
  Orig: {...}
  Mask: {...}

  Result: {...}
}
X:: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
	l: [1, 2, 3, 4, 5]
}
x: (structural.Mask & {Orig: X, Mask: { b: string, N: {x: string}, l: [1, 1, 3] }}).Result
x: {
	a: "a"
	N: {
		y: "y"
	}
	l: [2, 4, 5]
}

Developing

There isn't much special, you just need cue installed.

Running tests
cue test

See the test directory for more specifics and examples.

This runs the test command in test_tool.cue which is nothing more than "cue export test/*.cue"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CueDiff

func CueDiff(sorig, snew string) (string, error)

func CueMask

func CueMask(sorig, smask string) (string, error)

func CueMerge

func CueMerge(sorig, snew string) (string, error)

func CuePick

func CuePick(sorig, spick string) (string, error)

func CueQuery

func CueQuery(squery, sdata string) (string, error)

func Diff

func Diff(theirs, ours interface{}) (interface{}, error)

func DiffCue

func DiffCue(theirs, ours cue.Value) (cue.Value, error)

func DiffGo

func DiffGo(theirs, ours interface{}) (interface{}, error)

func Drop

func Drop(orig, drop interface{}) (interface{}, error)

func DropCue

func DropCue(orig, drop cue.Value) (cue.Value, error)

func DropGo

func DropGo(orig, drop interface{}) (interface{}, error)

func ExprFromValue

func ExprFromValue(v cue.Value) *pvExpr

func Merge

func Merge(orig, last interface{}) (interface{}, error)

func MergeCue

func MergeCue(orig, last cue.Value) (cue.Value, error)

func MergeGo

func MergeGo(orig, last interface{}) (interface{}, error)

func NewpvList

func NewpvList() *pvList

func NewpvStruct

func NewpvStruct() *pvStruct

func Patch

func Patch(orig, patch interface{}) (interface{}, error)

func PatchCue

func PatchCue(orig, patch cue.Value) (cue.Value, error)

func PatchGo

func PatchGo(orig, patch interface{}) (interface{}, error)

func Pick

func Pick(orig, pick interface{}) (interface{}, error)

func PickCue

func PickCue(orig, pick cue.Value) (cue.Value, error)

func PickGo

func PickGo(orig, pick interface{}) (interface{}, error)

func PrintCueValue

func PrintCueValue(val cue.Value) error

Types

type CueRuntime

type CueRuntime struct {
	Entrypoints []string

	CueRT *cue.Runtime
	BIS   []*build.Instance

	FieldOpts      []cue.Option
	CueInstance    *cue.Instance
	TopLevelValue  cue.Value
	TopLevelStruct *cue.Struct
}

func NewCueRuntime

func NewCueRuntime() *CueRuntime

func (*CueRuntime) LoadCue

func (CR *CueRuntime) LoadCue(entrypoints []string) []error

func (*CueRuntime) PrintValue

func (CR *CueRuntime) PrintValue() error

type DiffOp

type DiffOp struct {
	Op        string
	Path      string
	Value     interface{}
	PrevValue interface{}
}

Directories

Path Synopsis
cmd
st

Jump to

Keyboard shortcuts

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