You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
As of TypeBox 0.24.0, this library now offers a specialized TypeCompiler that builds highly optimized validation routines specifically for TypeBox types. To allow users to make use of the compiler, this proposal seeks to expose an TypeBoxValidatorCompiler export that users can optionally set to override the default AJV compiler.
The TypeBoxValidatorCompiler import should viewed as optional an extra from a user (and documentation) standpoint. The compiler itself only builds for a subset of the JSON schema specification. Without configuration, this provider will continue to work with AJV.
The following are comparative performance benchmarks measured against TypeBox and AJV for a variety of TypeBox types. Each test iterates several million times and measures the elapsed time to complete benchmark.
The following should be the full implementation of the TypeBoxValidatorCompiler. However additional updates may include formatting validation errors to present better as HTTP response messages.
importFastifyfrom'fastify'import{FastifySchemaCompiler,FastifyTypeProvider}from"fastify"import{TypeCompiler}from'@sinclair/typebox/compiler'import{Type,Static,TSchema}from'@sinclair/typebox'export*from'@sinclair/typebox'// review: Ensure Type, Static and other associative types are exported/** TypeBoxValidatorCompiler */exportconstTypeBoxValidatorCompiler: FastifySchemaCompiler<TSchema>=({ schema })=>{constTypeCheck=TypeCompiler.Compile(schema)return(data): any=>{if(TypeCheck.Check(data))return// okconsterrors=[...TypeCheck.Errors(data)]throwError(errors.map(({ message, path })=>`${message} for ${path}`).join('. '))}}/** TypeBoxTypeProvider */exportinterfaceTypeBoxTypeProviderextendsFastifyTypeProvider{output: this['input']extendsTSchema ? Static<this['input']> : never}
The text was updated successfully, but these errors were encountered:
Prerequisites
🚀 Feature Proposal
As of TypeBox 0.24.0, this library now offers a specialized TypeCompiler that builds highly optimized validation routines specifically for TypeBox types. To allow users to make use of the compiler, this proposal seeks to expose an
TypeBoxValidatorCompiler
export that users can optionally set to override the default AJV compiler.The anticipated usage may look as follows.
Additional Information on the compiler can be found https://github.com/sinclairzx81/typebox#Compiler
Submitting for consideration
Motivation
The following are comparative performance benchmarks measured against TypeBox and AJV for a variety of TypeBox types. Each test iterates several million times and measures the elapsed time to complete benchmark.
The Results
Example
The following should be the full implementation of the
TypeBoxValidatorCompiler
. However additional updates may include formatting validation errors to present better as HTTP response messages.The text was updated successfully, but these errors were encountered: