Structural diff, merge, patch, pick, and mask helpers for CUE.
MVS will make using cue modules easier.
support for both Cue and Go vals/structs
structural
is most easily used with cue modules,
see https://github.com/hofstadter-io/mvs.
mvs init cue github.com/<namespace>/<project>
require github.com/hofstadter-io/structural v0.0.3
mvs vendor
cue eval example.cue
cue export example.cue
Look for a "same" field == true
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 :: {
// 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 :: {
// 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 :: {
// 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 :: {
// 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 :: {
// 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]
}
There isn't much special, you just need cue installed.
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"