High Performance Driver for Runtime Type System Integration
npm install typedriverA High Performance Driver for Runtime Type System Integration



 
``bash`
$ npm install typedriver
Multi-Library Type Compiler and Inference System for High Performance Frameworks
`typescript
import compile from 'typedriver'
const Vector3 = compile({
x: number,
y: number,
z: number
})
const position = Vector3.parse(value) // const position: {
// x: number,
// y: number,
// z: number
// } = ...
`
Compiles: TypeScript | JSON Schema | TypeBox | Effect | Zod | ArkType | Valibot | Arri | Sury ... and more
TypeDriver is a multi-library compiler and type-inference middleware designed to integrate JSON Schema and Standard Schema validation into framework I/O interfaces such as HTTP routes and RPC endpoints. It provides high-performance compiler support for a wide range of ecosystem libraries and offers first-class TypeScript and JSON Schema validation and type inference as standard.
License MIT
- Overview
- Features
- Framework
- Compile
- Check
- Parse
- Errors
- Locales
- Static
- Script
- Reflect
- Extensions
- Accelerate
- Compression
- Contribute
TypeDriver provides a comprehensive set of features for integrating type-safe validation across multiple schema ecosystems:
- Single function to compile multiple schematics into validators.
- Single type for inferring TypeScript types from multiple schematics.
- Integrated TypeScript DSL for TS7-native (supported in TS5+).
- Validation support for JSON Schema Drafts 3 through 2020-12.
- Supports Standard Schema and Standard JSON Schema (with acceleration)
- High-performance JIT compiler for improved application start up.
- High-performance runtime validation (approx 2x Ajv check performance)
- JIT compile fallback for content-security restrictive edge environments (e.g. Cloudflare)
- Schema extension model for custom type safe builder API's.
- JSON Schema reflect API for OpenAPI, MCP, and IDL-Based Systems
- Error formats for JSON Schema and Standard Schema Based Systems
- Includes localized error messages (i18n) as standard.
TypeDriver is designed for framework integration. It provides a simple infrastructure to connect type inference and validation to framework interfaces.
Ref: TypeScript | JSON Schema | Standard Schema
`typescript
// Next Generation Inference System Based on TypeScript DSL (TS7)
route('/', {
body: {
x: number,
y: number,
z: number
}`
}, (request) => {
const { x, y, z } = request.body // type-safe!
})
The above interface design is achieved with the following TypeScript definitions
`typescript
import { type Static, compile } from 'typedriver'
export interface RouteOptions
{Compile
TypeDriver consists of a single compile(...) function that accepts JSON Schema, Standard Schema or TypeScript definition and returns a Validator instance.
`typescript
import compile from 'typedriver'
` Ref: TypeScript
`typescript
const Vector3 = compile({)
` Ref: JSON Schema
`typescript
const Vector3 = compile({
type: 'object',
required: ['x', 'y', 'z'],
properties: {
x: { type: 'number' },
y: { type: 'number' },
z: { type: 'number' }
}
})
` Ref: Standard Schema
`typescript
import * as z from 'zod'const Vector3 = compile(z.object({
x: z.number(),
y: z.number(),
z: z.number(),
}))
`
Validator
The compile(...) function returns Validator instances to Check, Parse and report Errors for JavaScript values.
Check
The check(...) returns a boolean result.
`typescript
// Vector3.check(value: unknown): value is Vector3if(Vector3.check(value)) {
const { x, y, z } = value // safe
}
`Parse
The parse(...) function returns if valid, otherwise throws.
`typescript
// Vector3.parse(value: unknown): Vector3const { x, y, z } = Vector3.parse(value)
`Errors
The errors(...) function returns error diagnostics for values (use after failed check only)
`typescript
// Vector3.errors(value: unknown): TLocalizedValidationError[]const errors = Vector3.errors(value)
`The errors(...) function can generate both JSON Schema and Standard Schema error formats.
`typescript
const errors = Vector3.errors({ x: 1, y: true }, {
format: 'json-schema'
})const issues = Vector3.errors({ x: 1, y: true }, {
format: 'standard-schema'
})
`
Generated Errors and Issues
`typescript
// TLocalizedValidationError[]const errors = [{
keyword: "required",
schemaPath: "#",
instancePath: "",
params: { requiredProperties: [ "z" ] },
message: "must have required properties z"
},
{
keyword: "type",
schemaPath: "#/properties/y",
instancePath: "/y",
params: { type: "number" },
message: "must be number"
}]
// StandardSchemaV1.Issue[]
const issues = [
{ path: [], message: "must have required properties z" },
{ path: [ "y" ], message: "must be number" }
]
`
Locales
TypeDriver provides localized translations for multiple languages and locales, using BCP 47-compliant locale identifiers expressed with underscores (_) in place of hyphens (-). These can be passed to the errors(...) function in the following way.
`typescript
const issues = Vector3.errors({ x: 1, y: true }, {
format: 'standard-schema',
locale: 'ko_KR'
})
`
Generated Localization
`typescript// StandardSchemaV1.Issue[]
const issues = [
{ path: [], message: "필수 속성 z을(를) 가지고 있어야 합니다" },
{ path: [ "y" ], message: "number이어야 합니다" }
]
`
Supported Locales
`typescript
type LocaleString = (
| "ar_001" | "bn_BD" | "cs_CZ" | "de_DE" | "el_GR" | "en_US" | "es_419"
| "es_AR" | "es_ES" | "es_MX" | "fa_IR" | "fil_PH" | "fr_CA" | "fr_FR"
| "ha_NG" | "hi_IN" | "hu_HU" | "id_ID" | "it_IT" | "ja_JP" | "ko_KR"
| "ms_MY" | "nl_NL" | "pl_PL" | "pt_BR" | "pt_PT" | "ro_RO" | "ru_RU"
| "sv_SE" | "sw_TZ" | "th_TH" | "tr_TR" | "uk_UA" | "ur_PK" | "vi_VN"
| "yo_NG" | "zh_Hans" | "zh_Hant"
)
`
Localization support is only available for JSON Schema
Static
TypeDriver provides unified type inference for JSON Schema, Standard Schema and TypeScript | Reference
`typescript
import { type Static } from 'typedriver'// TypeScript
type A = Static<
{ >// JSON Schema
type B = Static<{
type: 'object',
required: ['x', 'y', 'z'],
properties: {
x: { type: 'number' },
y: { type: 'number' },
z: { type: 'number' },
}
}>
// Standard Schema
import * as z from 'zod'
type C = Static
const C = z.object({
x: z.number(),
y: z.number(),
z: z.number(),
})
`Script
The TypeScript DSL is a runtime and type-level emulation of TypeScript. This feature is based on TypeBox's ability to transform TypeScript syntax into JSON Schema. The DSL supports most TypeScript definitions, as well as type-level constraints expressed using JSON Schema keywords.
> ⚠️ The name
Options is subject to change. Because Options is a commonly used type name, it may not be appropriate for schema constraint augmentation. As a result, Options should be considered an experimental feature. TypeBox and TypeDriver are open to suggestions for a more suitable name for this type.`typescript
const ClampedVector3 = compile({)const JsonSchema = ClampedVector3.toJsonSchema()
// const JsonSchema = {
// type: "object",
// required: [ "x", "y", "z" ],
// properties: {
// x: { type: "number", minimum: 0, maximum: 1 },
// y: { type: "number", minimum: 0, maximum: 1 },
// z: { type: "number", minimum: 0, maximum: 1 }
// }
// }
`Refer to TypeBox for additional information on this feature.
Reflect
Validators can reflect back a JSON Schema representation if the underlying type supports it. This is true for all TypeScript and JSON Schema source types. Reflect can be used for OpenAPI metadata publishing, or RPC systems that need to publish JSON based IDL (interface definition language) to remote callers. Validators provide two functions for this.
`typescript
import compile, { type Static } from 'typedriver'const validator = compile(...)
validator.isJSONSchema() // Returns true if the validator can be converted to
// JSON Schema. This is true when the validator was
// compiled with JSON Schema or TypeScript, but false
// if it was compiled with Standard Schema.
validator.toJSONSchema() // Returns the JSON Schema for the validator. If the
// validator was compiled with Standard Schema, an
// empty {} is returned to indicate an unknown
// runtime schema.
`
The original source type used for compilation can also be returned via`typescript
validator.schema() // will return the schematic used for compile.
`Extensions
TypeDriver supports the creation of framework specific type builder API. This can be achieved by creating functions that return statically observable JSON Schema. These schematics can be passed directly to compile(...) and Static. TypeDriver will derive the correct TypeScript type based on the schema returned.
`typescript
import { type Static } from 'typedriver'interface TEmail {
type: 'string'
}
export function email(): TEmail {
return { type: 'string', format: 'email' }
}
// ... Usage
const T = email() // const T: TEmail = {
// type: 'string',
// format: 'email'
// }
type T = Static // type T = string
`Accelerate
TypeDriver provides acceleration support for libraries that implement the Standard JSON Schema specification.
`bash
$ deno task bench
`
Benchmark 16M Parse Operations of this Structure | We Measure Time To Complete
`typescript
const Vector3 = compile({)
`Accelerated Indicates Support for Standard JSON Schema
`bash
┌────────────┬────────────┬─────────────┬────────────────┬───────────────┬──────────────┐
│ (idx) │ iterations │ accelerated │ standard (...) │ compile (...) │ performance │
├────────────┼────────────┼─────────────┼────────────────┼───────────────┼──────────────┤
│ typescript │ 16000000 │ true │ " 30 ms" │ " 29 ms" │ " 1.02 ×" │
│ jsonschema │ 16000000 │ true │ " 29 ms" │ " 29 ms" │ " 1.00 ×" │
│ zod │ 16000000 │ true │ " 571 ms" │ " 28 ms" │ " 20.43 ×" │
│ arktype │ 16000000 │ true │ " 483 ms" │ " 30 ms" │ " 16.10 ×" │
│ valibot │ 16000000 │ true │ " 3239 ms" │ " 28 ms" │ " 113.72 ×" │
└────────────┴────────────┴─────────────┴────────────────┴───────────────┴──────────────┘Last Run: Sat Dec 20 2025
`Compression
TypeDriver is intended for server-side validation in Node, Deno and Bun runtimes, but can be used in Browsers also. TypeDriver depends on most of TypeBox's internal compiler and TS emulation infrastructure. The following shows the compression metrics for bundled, minified and gzipped. TypeDriver uses esbuild for bundling and Deno local gzipped compression.
`bash
$ deno task metrics
`
Compression Rates
`bash
┌───────┬─────────────────────────┬─────────────┬─────────────┬────────────┐
│ (idx) │ path │ bundled │ minified │ gzipped │
├───────┼─────────────────────────┼─────────────┼─────────────┼────────────┤
│ 0 │ "./task/metrics/all.ts" │ "579.74 KB" │ "286.01 KB" │ "55.14 KB" │
└───────┴─────────────────────────┴─────────────┴─────────────┴────────────┘
``TypeDriver is open to community contribution. Please ensure you submit an issue before submitting a pull request. This project prefers open community discussion before accepting new features.