Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add built-in version schema and coercion #11

Open
tingerrr opened this issue May 30, 2024 · 8 comments · May be fixed by #43
Open

Add built-in version schema and coercion #11

tingerrr opened this issue May 30, 2024 · 8 comments · May be fixed by #43
Labels
coercions Issue or PR relating to valkyrie coercions enhancement New feature or request help wanted Extra attention is needed schema Issue or PR relating to valkyrie schema
Milestone

Comments

@tingerrr
Copy link
Member

Add a schema and coercion for the verison type, the coercion should attempt parsing a string into a version before it is validated.

Currently, coercions seem to be infallible pre- or post-transformers, at least in semantics, perhaps a relaxation of this could allow parsing conversions like these to simply be pre-transformers.

@tingerrr tingerrr added enhancement New feature or request coercions Issue or PR relating to valkyrie coercions schema Issue or PR relating to valkyrie schema labels May 30, 2024
@jamesrswift
Copy link
Member

Are we talking about semver version strings?

On coercions, they can fail if they return none as that throws spanners into the gears further down which would result in a failure. In that sense therefore, perhaps a version schema could instead be a string schema with a semver coercion that fails if its too far out of spec?

@jamesrswift jamesrswift added this to the 0.2.1 milestone May 30, 2024
@tingerrr
Copy link
Member Author

I'm not sure, I just think we should have some way of allowing users to go from "0.1.0" to version(0, 1, 0) in an ergonomic way with good error messages.

Parsing author strings into a name email pair would also be a candidate for this kind of parsing coercion.

@jamesrswift
Copy link
Member

You had me checking if there was a type for version and I don't know how I've missed it this entire time but there apparently is! I'll read up on it but it sounds like it should be an easy addition

@tingerrr
Copy link
Member Author

I think this may be valid for #10 too, to allow restricting versions to some semver range.

See also #13 in general for some others.

@jamesrswift
Copy link
Member

jamesrswift commented Jun 2, 2024

Version schema generator is implemented by #18. I'll make a separate PR for creating the coercions for these individually as they'll likely need a lot more thought and tailoring.

With respect to #10, I think the assertions worth adding are minimum version and maximum version, though I think an assertion that may be more commonly used is a string representation like that which npm uses.

@tingerrr
Copy link
Member Author

tingerrr commented Jun 2, 2024

With respect to #10, I think the assertions worth adding are minimum version and maximum version, though I think an assertion that may be more commonly used is a string representation like that which npm uses.

I think the usage of ^ and ~ may be too much for Typst as there is no version resolver for it at the moment, we can likely restrict it to

version_requirement ::= { '>=' | '<=' } major [ '.' minor [ '.' patch ] ]

Nothing too fancy, it should be noted that this is a version requirement, not a version itself.

@jamesrswift
Copy link
Member

For coercion of version, can you give some examples of inputs you'd expect a coercion function to correctly convert to version?

@tingerrr
Copy link
Member Author

tingerrr commented Jun 3, 2024

Assuming fallibility is allowed, it would be the inverse of str(version(..args)):

  • parse-version("0") -> ok
  • parse-version("0.0") -> ok
  • parse-version("0.0.0") -> ok
  • parse-version("=0.0.0") -> err
  • parse-version(">=0.0.0") -> err
  • parse-version("0.x.0") -> err
  • parse-version("") -> err

Some of these are plain invalid, others are version requirements, not versions.

@jamesrswift jamesrswift added the help wanted Extra attention is needed label Jul 12, 2024
@jamesrswift jamesrswift modified the milestones: 0.2.1, v0.2.2 Jul 14, 2024
@jamesrswift jamesrswift linked a pull request Jul 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coercions Issue or PR relating to valkyrie coercions enhancement New feature or request help wanted Extra attention is needed schema Issue or PR relating to valkyrie schema
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants