Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Semver as a basic type like number or string #407

Closed
verdverm opened this issue May 23, 2020 · 6 comments
Closed

Semver as a basic type like number or string #407

verdverm opened this issue May 23, 2020 · 6 comments
Labels
FeatureRequest New feature or request

Comments

@verdverm
Copy link
Contributor

Configuration is often dealing with versions and there is not an easy way to compare version identifiers during validation and evaluation.

Having a semver basic type (not sure the right term here) like number and string.

schema: {
  version: semver
}

foo: schema & {
  version: v0.3.4
}

range: {
  version: >v0.3.0 & < v1.0.0
}

fail: {
   version: >v0.4.0
}

ex1: foo & range // => foo
ex2: foo & config // => _|_

This seems like a good library to use: https://pkg.go.dev/golang.org/x/[email protected]/semver

@verdverm verdverm added the FeatureRequest New feature or request label May 23, 2020
@rvadhavk
Copy link

rvadhavk commented Jun 3, 2020

I don't think this should be a bulitin. It'd be better to have a generic method of creating user-defined types with these semantics. Like maybe define the comparison operator on lists be a lexicographic ordering.

@rvadhavk
Copy link

rvadhavk commented Jun 4, 2020

Another similar problem is expressing date and time ranges, which I don't think is currently possible in cue (unless you just using unix epoch seconds or something).

@verdverm
Copy link
Contributor Author

verdverm commented Jun 4, 2020

I think you are right, so I'll update this to be semver as a built in package in Cue.

See the 'pkg/**' packages available. There are things for dates, ips, and more. Semver comparison can likely fit here via functions.

I'm not sure there is a path for user defined types which can be used in builin operations like < and other Boolean ops. @mpvl ?

@myitcv
Copy link
Contributor

myitcv commented Jun 5, 2020

The simplicity of not allowing re-definition of < and friends is, I think, a massive benefit that outweighs the cost of complexity, readability that allowing it would introduce.

Instead, this situation (and many others) sound like a use case for the previously proposed constrain() build in.

@mpvl
Copy link
Contributor

mpvl commented Jan 14, 2021

@rvadhavk: time.Time enforces a proper string type and you can just use string comparison for ordering. There is no need to redefine <, it is just regular string ordering.

Semver can easily be expressed as a fairly simple regexp. The only thing I can imagine that would be useful is numeric sorting (e.g. using x/text/collate). Again, this can be solved with a more generic package. I don't think it warrants a builtin package. It can easily be provided as a native CUE package externally. I don't think semver is at the same level of standardization as ip or dates.

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#407.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants