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

TypeBox 0.25.0 #271

Merged
merged 30 commits into from Oct 28, 2022
Merged

TypeBox 0.25.0 #271

merged 30 commits into from Oct 28, 2022

Conversation

sinclairzx81
Copy link
Owner

@sinclairzx81 sinclairzx81 commented Oct 28, 2022

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 Date without constraints but provides 4 range constraint options tied to the timestamp as given by date.getTime(). Because timestamp is numeric, TypeBox uses similar constraints to TNumber and TInteger.

The following constraints are supported.

const T = Type.Date({
   minimumExclusiveTimestamp: 0,
   maximumExclusiveTimestamp: 0,
   minimumTimestamp: 0,
   maximumTimestamp: 0,
})

Note: TypeBox does not factor timezone information encoded in the date, and will only validate based on UTC+0 offsets from the Unix Epoch on January 1st 1970 which is the UTC offset given by date.getTime(). As .getTime() is uniform across timezones, users should configure constraints to match constraint ranges relative to UTC+0.

Documentation

The documention for Type.Date() has been added to the Extended type 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 both Type.Date() and Type.Uint8Array() have been included in the project readme.

In addition, the prefixed Standard and Extended JSDoc 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.

Note: The TypeCompiler and Value API's have been upgraded to support Type.Date() by default.

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 a Type.Temporal()). The representations now include the additional properties of instanceOf and typeOf (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.0 onwards, the recommendation for custom schemas created with Type.Unsafe() will be to adopt the conventions used for the TypeBox extended types Type.Date() and Type.Undefined(). This with the intent to provide concise and extensible configuration setup for TypeBox + Ajv.

@sinclairzx81 sinclairzx81 changed the title Type.Date() TypeBox 0.25.0 Oct 28, 2022
@sinclairzx81 sinclairzx81 merged commit 16f6551 into master Oct 28, 2022
@sinclairzx81 sinclairzx81 deleted the date branch October 28, 2022 20:55
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.

None yet

1 participant