Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
Type.Date()to TypeBox and formalizes Extended Type representations. This PR constitutes a minor semver release.Type.Date()
The new Date type will validate via
instanceof Datewithout constraints but provides 4 range constraint options tied to thetimestampas given bydate.getTime(). Becausetimestampis numeric, TypeBox uses similar constraints toTNumberandTInteger.The following constraints are supported.
Note: TypeBox does not factor timezone information encoded in the date, and will only validate based on
UTC+0offsets from the Unix Epoch on January 1st 1970 which is the UTC offset given bydate.getTime(). As.getTime()is uniform across timezones, users should configure constraints to match constraint ranges relative toUTC+0.Documentation
The documention for
Type.Date()has been added to theExtendedtype section as it will require configuration before use in Ajv. Due to the configuration requirement and the high likelihood of this type being used in non-configured environments, additional documentation for configuring bothType.Date()andType.Uint8Array()have been included in the project readme.In addition, the prefixed
StandardandExtendedJSDoc comments make a return for intellisense enabled editors (such as vscode). This to make more clear which types can be used safely without configuration and which cannot.Extended Schema Representation
This PR also updates the schema representations for Extended types. These updates are inline with adding
Type.Date()as well as making provisions for potential future types (such aType.Temporal()). The representations now include the additional properties ofinstanceOfandtypeOf(which are used as configurable hooks for Ajv and other validators). Due to the change in representations for these types, this will require a minor semver revision.From
0.25.0onwards, the recommendation for custom schemas created withType.Unsafe()will be to adopt the conventions used for the TypeBox extended typesType.Date()andType.Undefined(). This with the intent to provide concise and extensible configuration setup for TypeBox + Ajv.