File tree Expand file tree Collapse file tree 6 files changed +33
-11
lines changed Expand file tree Collapse file tree 6 files changed +33
-11
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,23 @@ import (
26
26
"cuelang.org/go/internal/core/runtime"
27
27
)
28
28
29
+ // An InstanceOrValue is implemented by Value and *Instance.
30
+ //
31
+ // This is a placeholder type that is used to allow Instance-based APIs to
32
+ // transition to Value-based APIs. The goals is to get rid of the Instance
33
+ // type before v1.0.0.
34
+ type InstanceOrValue interface {
35
+ Value () Value
36
+
37
+ internal ()
38
+ }
39
+
40
+ func (Value ) internal () {}
41
+ func (* Instance ) internal () {}
42
+
43
+ // Value implements value.Instance.
44
+ func (v hiddenValue ) Value () Value { return v }
45
+
29
46
// An Instance defines a single configuration based on a collection of
30
47
// underlying CUE files.
31
48
type Instance struct {
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ import (
40
40
//
41
41
// The generated CUE schema is guaranteed to deem valid any value that is
42
42
// a valid instance of the source JSON schema.
43
- func Extract (data * cue.Instance , cfg * Config ) (f * ast.File , err error ) {
43
+ func Extract (data cue.InstanceOrValue , cfg * Config ) (f * ast.File , err error ) {
44
44
d := & decoder {cfg : cfg }
45
45
46
46
f = d .decode (data .Value ())
Original file line number Diff line number Diff line change @@ -194,7 +194,9 @@ func (c *Controller) addErr(err error, msg string) {
194
194
}
195
195
196
196
// New creates a Controller for a given Instance and TaskFunc.
197
- func New (cfg * Config , inst * cue.Instance , f TaskFunc ) * Controller {
197
+ //
198
+ // The instance value can either be a *cue.Instance or a cue.Value.
199
+ func New (cfg * Config , inst cue.InstanceOrValue , f TaskFunc ) * Controller {
198
200
v := inst .Value ()
199
201
ctx := eval .NewContext (value .ToInternal (v ))
200
202
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import (
24
24
"testing"
25
25
26
26
"cuelang.org/go/cue"
27
+ "cuelang.org/go/cue/cuecontext"
27
28
"cuelang.org/go/cue/errors"
28
29
"cuelang.org/go/cue/format"
29
30
"cuelang.org/go/internal/cuetest"
@@ -43,10 +44,11 @@ func TestFlow(t *testing.T) {
43
44
test .Run (t , func (t * cuetxtar.Test ) {
44
45
a := t .ValidInstances ()
45
46
46
- inst := cue . Build ( a )[ 0 ]
47
- if inst . Err != nil {
48
- t .Fatal (inst . Err )
47
+ insts , err := cuecontext . New (). BuildInstances ( a )
48
+ if err != nil {
49
+ t .Fatal (err )
49
50
}
51
+ v := insts [0 ]
50
52
51
53
seqNum = 0
52
54
@@ -76,7 +78,7 @@ func TestFlow(t *testing.T) {
76
78
UpdateFunc : updateFunc ,
77
79
}
78
80
79
- c := flow .New (cfg , inst , taskFunc )
81
+ c := flow .New (cfg , v , taskFunc )
80
82
81
83
w := t .Writer ("errors" )
82
84
if err := c .Run (context .Background ()); err != nil {
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ type Config struct {
71
71
// as can be derived from the evaluated values in inst.
72
72
// Trimming is done on a best-effort basis and only when the removed field
73
73
// is clearly implied by another field, rather than equal sibling fields.
74
- func Files (files []* ast.File , inst * cue.Instance , cfg * Config ) error {
74
+ func Files (files []* ast.File , inst cue.InstanceOrValue , cfg * Config ) error {
75
75
r , v := value .ToInternal (inst .Value ())
76
76
77
77
t := & trimmer {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
20
20
"cuelang.org/go/cue"
21
21
"cuelang.org/go/cue/ast"
22
+ "cuelang.org/go/cue/cuecontext"
22
23
"cuelang.org/go/cue/errors"
23
24
"cuelang.org/go/cue/format"
24
25
"cuelang.org/go/cue/parser"
@@ -255,12 +256,12 @@ foo: entry: {
255
256
if err != nil {
256
257
t .Fatal (err )
257
258
}
258
- r := cue. Runtime {}
259
- inst , err := r .CompileFile (f )
260
- if err != nil {
259
+ r := cuecontext . New ()
260
+ v := r .BuildFile (f )
261
+ if err := v . Err (); err != nil {
261
262
t .Fatal (err )
262
263
}
263
- err = Files ([]* ast.File {f }, inst , & Config {Trace : false })
264
+ err = Files ([]* ast.File {f }, v , & Config {Trace : false })
264
265
if err != nil {
265
266
t .Fatal (err )
266
267
}
You can’t perform that action at this time.
0 commit comments