v0.4.0-beta.1
This release fixes some bugs, improves some errors and adds API. This version also drops support for some old constructs that have not been supported in the CUE tool for some time now. The main reason to start being more “aggressive” about this is to avoid surprises as we’re inching towards a full backwards compatibility guarantee. Note that “aggressive” is probably a strong word, these constructs have not been supported for over a year.
Language additions
Value aliases
CUE now allows value aliases, as suggested in various proposals and remarks. This allows, for instance, users to rewrite:
foo: {
a: b + c
b: int
c: int
}
bar: foo & {b: 1, c: 2}as
foo: X={
a: X.b + X.c
}
bar: foo & {b: 1, c: 2}In this case the benefit may be small, but there are various cases where not having this ability results in significant inconvenience. Also the query proposal, the UX design around the usage of the proposed must builtin, as well as various other patterns, rely on this ability.
Note the subtle but important difference between this and using field aliases. Using a field alias here, say X=foo: a: X.b + X.c would be equivalent to foo: a: foo.b + foo.c. As a result, in bar: foo, X.b would still be bound to the original location and not resolve to any b specified in bar.
Which one to use depends on the application. As a general rule, field aliases should be used when defining “types”, whereas value aliases should be used when defining “values”. An example of where one wants to use field aliases:
List="my-list-type": {
value: _
next: List
}Here, using a value alias would result in a list where every value must be the same. This is probably the most subtle aspect of CUE. The guideline of using values aliases when defining values, and field aliases when defining types, however, should give users a good steer on the matter.
Tooling
Tag variables to inject contextual system values
The injection mechanism now allows injecting specific variables, such as current time, username, or hostname, or a random number, into fields marked with a @tag attribute. For instance:
import "path"
_os: string @tag(os,var=os)
path.Base(dir, _os)allows for an OS-specific Base operation. Except for cue cmd, the var will only be injected when the -T is explicitly specified on the command line.
This approach 1) allows packages to remain hermetic, 2) allows using such functionality without having to resort to cue cmd, and 3) avoids introducing another injection point.
See cue help injection for more details.
Binary file type
The cue tool now supports binary files. These are very much like the supported “text” files, but translate the file contents to a CUE binary literal, rather than a text literal.
There are no default file extensions to recognize a binary file. The binary: file qualifier can be used to read a file as binary. See cue help filetypes for more info.
To make loading binary files in bulk more useful when importing, the import command now supports the --ext flag, allowing certain file types to be interpreted as a certain format. This also works for other types. See cue help import for more info.
--force/-f
This flag is now allowed for any command that outputs files.
API additions
Context.NewList
Uses can now construct a new list cue.Value with Context.NewList. This is defined on Context to allow the creation of empty lists, which still need to be associated with a Context.
Value.FillPath
FillPath now accepts list indices. The Go-to-CUE are now documented in more detail.
Fillpath now also accepts the selectors AnyString and AnyIndex, which allows setting pattern constraints. For instance, v.FillPath(cue.MakePath(cue.Str("a"), cue.AnyString, x), adds a: [string]: x to v.
It also allows setting optional fields. For instance, v.FillPath(cue.MakePath(cue.Str("b").Optional()), 1) will add b?: 1 to v, using the usual rules for unifying such fields.
Context.Encode
The documentation of this method has been significantly improved. This also fixes some bugs that were uncovered in the process.
These are now also two additional options: InferBuiltins and ImportPath. These were exposed to support the cue command in using the new API, but thus also allows other tool writers to use the same kind of functionality.
CUE package additions
crypto/hmac
The new package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198.
uuid
The new package uuid defines functionality for creating UUIDs as defined in RFC 4122.
Currently only Version 5 (SHA1) and Version 3 (MD5) are supported. The new tag variable injection mechanism that was introduced in this release, however, also opens up the possibility to include other versions, if needed.
Backwards incompatible changes
Dropped support for old-style aliases
Aliases of the style X = 4 (now let X = 4) have been deprecated since v0.1.4. However, by setting the version or in API use, these aliases would still work. Support for them has been fully removed. Down the line, this syntax can be reused as value aliases as well, relaxing the places where value aliases can be used.
For the time being, cue fix can still be used to rewrite old-style aliases to their let equivalent. There was a bug that missed the detection of some forms of the deprecated alias type. This has now been fixed.
Dropped support for old-style comprehensions
Support for the old-style comprehensions (e.g. [ x+1 for x in foo]) has now been fully removed. Use an older version of CUE to rewrite such old-style comprehensions using cue fmt or cue fix.
Removed ast.TemplateLabel type from API
This has not been parsed, supported, or used for ages. The type has now been removed from the API.
Value.Expr
Value.Expr now translates the or and and builtins as if they were native | or & constructs. This fixes a bug in encoding/openapi and is likely to prevent many issues. If one was relying on detecting the use of these builtins, however, this now will no longer work.
Value.Decode
This method was reimplemented to not use Value.MarshalJSON. This fixes many bugs, but may cause issues if users were relying on old behavior. The new implementation still strictly adheres to the JSON encoding spec when this makes sense, but deviates in some important aspects. For instance, numbers like 1 are now integers in CUE, rather than float. Also binary values are now handled correctly.
Bug fixes
- hidden references used on the command line now resolve to hidden fields in the package under evaluation
- equality of null value
All changes
46 changesby area
ci6
cidebug tip trigger failurescifix broken tip and new version triggerscifix tip and new version curl and env problemscifix tip triggers with proper quotingcimore debugging of tip triggerscitrigger unity and cuelang.org builds/equivalent on tip/new versions
cmd5
cmd/cue/cmddo not silently ignore unknown filetypescmd/cue/cmdfix resolution of hidden values across toolscmd/cue/cmdmove tag flags handling to central locationcmd/cue/cmdsupport binary file typecmd/cuesupport --force for all commands that allow output flags
cue23
cue/astfully remove support for old-style comprehensionscue/astremove support for TemplateLabelcue/loadprovide reason for exclusion of filescue/loadremove unused codecue/loadsupport injection of system variablescue/parserallow pattern constraints unconditionallycue/parserbetter error messages for use of deprecated constructscue/testdata, doc, pkgfix some it's/its typoscueValue.Expr: process or and and builtins semantically.cueadd InferBuiltins EncodeOptioncueadd NewListcuealign import with top-level package for -ecueallow setting list elements in FillPathcuebetter document Context.Encode and friendscuehoist attribute-related functionality to separate filecuemore path cleanupcuemove Decode to separate filecueprepare API implementation for structure sharingcueproperly decode "any" labelscuereimplement Decode to not use MarshalJSONcueremove use of isDefcuesupport optional fields for FillPathcueundeprecate Iterator.Label
internal4
internal/core/adtfix null values equalityinternal/core/adtuse Closed for checking recursive closednessinternal/core/compledrop support for old-style aliasesinternal/coresupport field value aliases
pkg4
pkg/crypto/hmacadd crypto/hmac supportpkg/crypto/hmacfix package documentationpkg/timefix documentation bug in Unixpkg/uuidimplementation of hermetic UUID functions
Other4
doc/ref/spec.mdintroduction of value aliasesdoc/ref/spec.mdremove "dead code"docsadd link to Code of Conduct to CONTRIBUTING guidegithubadd bug report template link to repro advice
Downloads
Every file this release published on GitHub, with its SHA-256. Most people install CUE as Installing CUE describes, which also shows how to check a download.
Archives
| Platform | File and SHA-256 |
|---|---|
| macOS, Intel | cue_3949038e2eab93ab066874ede21910d64f46ac89520a7a873a6e871d94769947 |
| Linux, x86-64 | cue_187bddf61b87f14c735e2404a5f3fa08dba949457e17104bf248b1d1a7e267dd |
| Linux, Arm64 | cue_676ee508fe1908fd84b59959d3150f3b5b0248d73a7fda95d768a2f7ab1c4062 |
| Windows, x86-64 | cue_5f443bde940beeb34798822797e32f2ba2c2e283e97be9fdc34083017efe6e4b |
SHA-256 checksums for all of these: checksums.txt