Skip to content

Commit

Permalink
🧹 soft-deprecate semver in favor of version
Browse files Browse the repository at this point in the history
The soft part of this deprecation is that we don't show a deprecation
warning anywhere at all. So semver is still technically included, since
we released it in v9.x, but we will deprecate it formally with the next
major release.
  • Loading branch information
arlimus committed Feb 10, 2025
1 parent e236824 commit 0f080e2
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 107 deletions.
2 changes: 1 addition & 1 deletion cli/printer/mql.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func (print *Printer) Data(typ types.Type, data interface{}, codeID string, bund
case types.Block:
return print.refMap(typ, data.(map[string]interface{}), codeID, bundle, indent)

case types.Semver:
case types.Version:
return print.Secondary(data.(string))

case types.ArrayLike:
Expand Down
60 changes: 30 additions & 30 deletions llx/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ func init() {
string("!=" + types.Float): {f: stringNotFloatV2, Label: "!="},
string("==" + types.Dict): {f: stringCmpDictV2, Label: "=="},
string("!=" + types.Dict): {f: stringNotDictV2, Label: "!="},
string("==" + types.Semver): {f: semverCmpSemver, Label: "=="},
string("!=" + types.Semver): {f: semverNotSemver, Label: "!="},
string("==" + types.Version): {f: versionCmpVersion, Label: "=="},
string("!=" + types.Version): {f: versionNotVersion, Label: "!="},
string("==" + types.ArrayLike): {f: chunkEqFalseV2, Label: "=="},
string("!=" + types.ArrayLike): {f: chunkNeqTrueV2, Label: "!="},
string("==" + types.Array(types.String)): {f: stringCmpStringarrayV2, Label: "=="},
Expand All @@ -295,10 +295,10 @@ func init() {
string("<=" + types.Dict): {f: stringLTEDictV2, Label: "<="},
string(">" + types.Dict): {f: stringGTDictV2, Label: ">"},
string(">=" + types.Dict): {f: stringGTEDictV2, Label: ">="},
string("<" + types.Semver): {f: semverLTsemver, Label: "<"},
string(">" + types.Semver): {f: semverGTsemver, Label: ">"},
string("<=" + types.Semver): {f: semverLTEsemver, Label: "<="},
string(">=" + types.Semver): {f: semverGTEsemver, Label: ">="},
string("<" + types.Version): {f: versionLTversion, Label: "<"},
string(">" + types.Version): {f: versionGTversion, Label: ">"},
string("<=" + types.Version): {f: versionLTEversion, Label: "<="},
string(">=" + types.Version): {f: versionGTEversion, Label: ">="},
string("&&" + types.Bool): {f: stringAndBoolV2, Label: "&&"},
string("||" + types.Bool): {f: stringOrBoolV2, Label: "||"},
string("&&" + types.Int): {f: stringAndIntV2, Label: "&&"},
Expand Down Expand Up @@ -461,8 +461,8 @@ func init() {
string("!=" + types.String): {f: dictNotStringV2, Label: "!="},
string("==" + types.Regex): {f: dictCmpRegexV2, Label: "=="},
string("!=" + types.Regex): {f: dictNotRegexV2, Label: "!="},
string("==" + types.Semver): {f: semverCmpSemver, Label: "=="},
string("!=" + types.Semver): {f: semverNotSemver, Label: "!="},
string("==" + types.Version): {f: versionCmpVersion, Label: "=="},
string("!=" + types.Version): {f: versionNotVersion, Label: "!="},
string("==" + types.ArrayLike): {f: dictCmpArrayV2, Label: "=="},
string("!=" + types.ArrayLike): {f: dictNotArrayV2, Label: "!="},
string("==" + types.Array(types.String)): {f: dictCmpStringarrayV2, Label: "=="},
Expand Down Expand Up @@ -491,10 +491,10 @@ func init() {
string("<=" + types.Dict): {f: dictLTEDictV2, Label: "<="},
string(">" + types.Dict): {f: dictGTDictV2, Label: ">"},
string(">=" + types.Dict): {f: dictGTEDictV2, Label: ">="},
string("<" + types.Semver): {f: semverLTsemver, Label: "<"},
string(">" + types.Semver): {f: semverGTsemver, Label: ">"},
string("<=" + types.Semver): {f: semverLTEsemver, Label: "<="},
string(">=" + types.Semver): {f: semverGTEsemver, Label: ">="},
string("<" + types.Version): {f: versionLTversion, Label: "<"},
string(">" + types.Version): {f: versionGTversion, Label: ">"},
string("<=" + types.Version): {f: versionLTEversion, Label: "<="},
string(">=" + types.Version): {f: versionGTEversion, Label: ">="},
string("&&" + types.Bool): {f: dictAndBoolV2, Label: "&&"},
string("||" + types.Bool): {f: dictOrBoolV2, Label: "||"},
string("&&" + types.Int): {f: dictAndIntV2, Label: "&&"},
Expand Down Expand Up @@ -565,24 +565,24 @@ func init() {
// We have not yet decided if and how these may be exposed to users
"notEmpty": {f: dictNotEmptyV2},
},
types.Semver: {
string("==" + types.Nil): {f: stringCmpNilV2, Label: "=="},
string("!=" + types.Nil): {f: stringNotNilV2, Label: "!="},
string("==" + types.Empty): {f: stringCmpEmptyV2, Label: "=="},
string("!=" + types.Empty): {f: stringNotEmptyV2, Label: "!="},
string("==" + types.Semver): {f: semverCmpSemver, Label: "=="},
string("!=" + types.Semver): {f: semverNotSemver, Label: "!="},
string("<" + types.Semver): {f: semverLTsemver, Label: "<"},
string(">" + types.Semver): {f: semverGTsemver, Label: ">"},
string("<=" + types.Semver): {f: semverLTEsemver, Label: "<="},
string(">=" + types.Semver): {f: semverGTEsemver, Label: ">="},
string("==" + types.String): {f: semverCmpSemver, Label: "=="},
string("!=" + types.String): {f: semverNotSemver, Label: "!="},
string("<" + types.String): {f: semverLTsemver, Label: "<"},
string(">" + types.String): {f: semverGTsemver, Label: ">"},
string("<=" + types.String): {f: semverLTEsemver, Label: "<="},
string(">=" + types.String): {f: semverGTEsemver, Label: ">="},
"epoch": {f: semverEpoch},
types.Version: {
string("==" + types.Nil): {f: stringCmpNilV2, Label: "=="},
string("!=" + types.Nil): {f: stringNotNilV2, Label: "!="},
string("==" + types.Empty): {f: stringCmpEmptyV2, Label: "=="},
string("!=" + types.Empty): {f: stringNotEmptyV2, Label: "!="},
string("==" + types.Version): {f: versionCmpVersion, Label: "=="},
string("!=" + types.Version): {f: versionNotVersion, Label: "!="},
string("<" + types.Version): {f: versionLTversion, Label: "<"},
string(">" + types.Version): {f: versionGTversion, Label: ">"},
string("<=" + types.Version): {f: versionLTEversion, Label: "<="},
string(">=" + types.Version): {f: versionGTEversion, Label: ">="},
string("==" + types.String): {f: versionCmpVersion, Label: "=="},
string("!=" + types.String): {f: versionNotVersion, Label: "!="},
string("<" + types.String): {f: versionLTversion, Label: "<"},
string(">" + types.String): {f: versionGTversion, Label: ">"},
string("<=" + types.String): {f: versionLTEversion, Label: "<="},
string(">=" + types.String): {f: versionGTEversion, Label: ">="},
"epoch": {f: versionEpoch},
},
types.ArrayLike: {
"[]": {f: arrayGetIndexV2},
Expand Down
23 changes: 13 additions & 10 deletions llx/builtin_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ func init() {
"return": returnCallV2,
"createResource": globalCreateResource,
// type-conversions
"string": stringCall,
"$regex": regexCall, // TODO: support both the regex resource and the internal typemap!
"float": floatCall,
"int": intCall,
"bool": boolCall,
"dict": dictCall,
"semver": semverCall,
"string": stringCall,
"$regex": regexCall, // TODO: support both the regex resource and the internal typemap!
"float": floatCall,
"int": intCall,
"bool": boolCall,
"dict": dictCall,
"version": versionCall,
// FIXME: DEPRECATED, remove in v13.0 vv
"semver": versionCall, // deprecated
// ^^
}
}

Expand Down Expand Up @@ -193,17 +196,17 @@ func typeofCallV2(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64,
return StringData(res.Type.Label()), 0, nil
}

func semverCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error) {
func versionCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error) {
if len(f.Args) != 1 {
return nil, 0, errors.New("Called `semver` with " + strconv.Itoa(len(f.Args)) + " arguments, expected one")
return nil, 0, errors.New("Called `version` with " + strconv.Itoa(len(f.Args)) + " arguments, expected one")
}

res, dref, err := e.resolveValue(f.Args[0], ref)
if err != nil || dref != 0 || res == nil {
return res, dref, err
}

return &RawData{Type: types.Semver, Value: res.Value}, 0, nil
return &RawData{Type: types.Version, Value: res.Value}, 0, nil
}

func stringCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error) {
Expand Down
30 changes: 15 additions & 15 deletions llx/builtin_semver.go → llx/builtin_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,59 +80,59 @@ func (v Version) Compare(o Version) int {
return v.Version.Compare(o.Version)
}

func semverLT(left interface{}, right interface{}) *RawData {
func versionLT(left interface{}, right interface{}) *RawData {
l := NewVersion(left.(string))
r := NewVersion(right.(string))
return BoolData(l.Compare(r) < 0)
}

func semverGT(left interface{}, right interface{}) *RawData {
func versionGT(left interface{}, right interface{}) *RawData {
l := NewVersion(left.(string))
r := NewVersion(right.(string))
return BoolData(l.Compare(r) > 0)
}

func semverLTE(left interface{}, right interface{}) *RawData {
func versionLTE(left interface{}, right interface{}) *RawData {
l := NewVersion(left.(string))
r := NewVersion(right.(string))
return BoolData(l.Compare(r) <= 0)
}

func semverGTE(left interface{}, right interface{}) *RawData {
func versionGTE(left interface{}, right interface{}) *RawData {
l := NewVersion(left.(string))
r := NewVersion(right.(string))
return BoolData(l.Compare(r) >= 0)
}

func semverCmpSemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
func versionCmpVersion(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, func(left, right interface{}) *RawData {
return BoolData(left.(string) == right.(string))
})
}

func semverNotSemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
func versionNotVersion(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, func(left, right interface{}) *RawData {
return BoolData(left.(string) != right.(string))
})
}

func semverLTsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverLT)
func versionLTversion(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, versionLT)
}

func semverGTsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverGT)
func versionGTversion(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, versionGT)
}

func semverLTEsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverLTE)
func versionLTEversion(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, versionLTE)
}

func semverGTEsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverGTE)
func versionGTEversion(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, versionGTE)
}

func semverEpoch(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
func versionEpoch(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
if bind.Value == nil {
return &RawData{Type: types.Int, Error: bind.Error}, 0, nil
}
Expand Down
6 changes: 3 additions & 3 deletions llx/data_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
types.Score: score2result,
types.Empty: empty2result,
types.Block: block2result,
types.Semver: string2result,
types.Version: string2result,
types.ArrayLike: array2result,
types.MapLike: map2result,
types.ResourceLike: resource2result,
Expand All @@ -60,7 +60,7 @@ func init() {
types.Score: pscore2raw,
types.Empty: pempty2raw,
types.Block: pblock2rawV2,
types.Semver: pstring2raw,
types.Version: pstring2raw,
types.ArrayLike: parray2raw,
types.MapLike: pmap2raw,
types.ResourceLike: presource2raw,
Expand Down Expand Up @@ -189,7 +189,7 @@ func string2result(value interface{}, typ types.Type) (*Primitive, error) {
return nil, errInvalidConversion(value, typ)
}
p := StringPrimitive(v)
// special case for semver
// special case for version
p.Type = string(typ)
return p, nil
}
Expand Down
8 changes: 4 additions & 4 deletions llx/data_conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"go.mondoo.com/cnquery/v11/types"
)

func TestSemver_Conversions(t *testing.T) {
func TestVersion_Conversions(t *testing.T) {
sv := llx.StringPrimitive("1.2.3")
sv.Type = string(types.Semver)
sv.Type = string(types.Version)
rd := sv.RawData()
require.NoError(t, rd.Error, "no error converting semver to raw data")
require.Equal(t, "1.2.3", rd.Value, "semver to raw data is the same")
require.NoError(t, rd.Error, "no error converting version to raw data")
require.Equal(t, "1.2.3", rd.Value, "version to raw data is the same")
}
6 changes: 3 additions & 3 deletions llx/rawdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func TestRawData_JSON(t *testing.T) {
}
}

func TestRawData_Semver_Result(t *testing.T) {
d := &RawData{Type: types.Semver, Value: "1.2.3"}
func TestRawData_Version_Result(t *testing.T) {
d := &RawData{Type: types.Version, Value: "1.2.3"}
r := d.Result()
assert.Equal(t, string(types.Semver), r.Data.Type)
assert.Equal(t, string(types.Version), r.Data.Type)
assert.EqualValues(t, "1.2.3", r.Data.Value)
}
2 changes: 1 addition & 1 deletion mqlc/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func init() {
"keys": {typ: stringArrayType, signature: FunctionSignature{}},
"values": {typ: dictArrayType, signature: FunctionSignature{}},
},
types.Semver: {
types.Version: {
"epoch": {typ: intType, signature: FunctionSignature{}},
},
types.ArrayLike: {
Expand Down
17 changes: 10 additions & 7 deletions mqlc/typemaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ var typeConversions map[string]fieldCompiler

func init() {
typeConversions = map[string]fieldCompiler{
"bool": compileTypeConversion("bool", types.Bool),
"int": compileTypeConversion("int", types.Int),
"float": compileTypeConversion("float", types.Float),
"string": compileTypeConversion("string", types.String),
"regex": compileTypeConversion("$regex", types.Regex),
"dict": compileTypeConversion("dict", types.Dict),
"semver": compileTypeConversion("semver", types.Semver),
"bool": compileTypeConversion("bool", types.Bool),
"int": compileTypeConversion("int", types.Int),
"float": compileTypeConversion("float", types.Float),
"string": compileTypeConversion("string", types.String),
"regex": compileTypeConversion("$regex", types.Regex),
"dict": compileTypeConversion("dict", types.Dict),
"version": compileTypeConversion("version", types.Version),
// FIXME: DEPRECATED, remove in v13.0 vv
"semver": compileTypeConversion("semver", types.Version), // deprecated
//
}
}

Expand Down
Loading

0 comments on commit 0f080e2

Please sign in to comment.