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

Update TypeBox to 0.26.4 #64

Merged
merged 6 commits into from
Mar 28, 2023
Merged

Update TypeBox to 0.26.4 #64

merged 6 commits into from
Mar 28, 2023

Conversation

sinclairzx81
Copy link
Contributor

@sinclairzx81 sinclairzx81 commented Mar 26, 2023

This PR updates TypeBox to 0.26.4 and re-exports the Type.* builder on the provider. This PR should resolve the following two issues.

Updates:

  • Update TypeBox 0.26.4
  • Update TypeScript 5.0.2
  • Moved TypeBox from peerDependencies to dependencies
  • Export Type module via barrel export on Provider
  • Update readme to show Type import on Provider.
  • Update TypeBoxValidatorCompiler with new automatic value coercion for headers, querystring and params only (this is new functionality available in 0.26.0)
  • Added tests for TypeBoxValidatorCompiler value coercion.

Notes:

@mcollina @RafaelGSS Currently all unit tests are passing, however the code coverage checks are reporting below threshold when re-exporting TypeBox on the Provider. I'm not sure the best way to configure the threshold, or have the coverage checks ignore the TypeBox re-export. Will mark this PR as editable for other contributors to take a look at.

@RafaelGSS (Edit) I've temporarily disabled code coverage to enable these tests to complete. The configuration was handled via updating the NPM script using tap's --no-check-coverage command line option. Not sure if there's a better way to handle this. The tap documentation seems to suggest coverage is either fully opt-in or opt-out, and couldn't see a way to reduce the coverage threshold. Am open to suggestions on a better resolution to this.

Submitting for review

README.md Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 6fd0862 into fastify:main Mar 28, 2023
"fastify": "^4.0.0"
},
"dependencies": {
"@sinclair/typebox": "^0.26.4"
Copy link

@rvitaliy rvitaliy Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this dependency is moved from peerDependencies to dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvitaliy See rationales on issue #53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i see the issue discussion, personally disagree with this approach.
a dependency should never exposed from a wrapper library.
@sinclair/typebox is "unstable" since they don't tag a stable version (>=1.0.0) yet so they minor can mutate public interface, but hotfix must don't change them. so the solution is to allow only versions that we know are compatible with this package.

using Tilde instead of Caret Ranges https://github.com/npm/node-semver#tilde-ranges-123-12-1 to indicate what version of @sinclair/typebox this library support.
in this way if @sinclair/typebox change public interfaces during upgrade from 0.25.* to 0.26.* this library trigger an alert when final user install an incompatible version and the library have more control about the supported version.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i read the documentation again, the Caret Ranges under the stable version works like Tilde so you already have the control about supported version
Screenshot 2023-03-29 at 10 18 31

@mcollina mcollina mentioned this pull request Mar 29, 2023
2 tasks
@benevbright
Copy link

@sinclairzx81 seems like querystring now can be converted to number and boolean. Correct? Thanks. 👍

@sinclairzx81
Copy link
Contributor Author

@benevbright Hi. Yeah, value conversion should be supported for the TypeBoxValidationCompiler as of this PR. This has been enabled for header, querystring and params only. Http body will still require the caller to pass valid data. Hope this helps :)

@benevbright
Copy link

benevbright commented Apr 5, 2023

@sinclairzx81 one thing is that default seems not working anymore.

querystring: Type.Object({
  aaa: Type.Boolean({ default: false }),
  bbb: Type.Boolean({ default: false }),
})

FastifyInstance instance still expects me to add these properties that has default. Before I didn't need. (with Ajv)

@sinclairzx81
Copy link
Contributor Author

@benevbright Hi,

The update only implemented value coercion (so aaa and bbb would be required as querystring arguments using the schema above. This update will try and convert anything that looks boolean like specified for these properties). For default values, these are not supported on this (or previous) releases, but may be supported in future (possibly behind a configuration flag).

If you need default value assignment, you can use Ajv with the useDefaults option enabled.
Hope this helps!
S

@benevbright
Copy link

yeap. sorry. I meant it works when using Ajv. Allright. Clear! Thanks again. @sinclairzx81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants