typedriver 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/json-schema/validator.d.mts +1 -0
- package/build/json-schema/validator.mjs +6 -0
- package/build/locale.mjs +1 -3
- package/build/standard-json-schema/validator.d.mts +1 -0
- package/build/standard-json-schema/validator.mjs +6 -0
- package/build/standard-schema/validator.d.mts +1 -0
- package/build/standard-schema/validator.mjs +6 -0
- package/build/typescript/validator.d.mts +1 -0
- package/build/typescript/validator.mjs +6 -0
- package/build/validator.d.mts +2 -0
- package/package.json +1 -1
- package/readme.md +84 -27
|
@@ -24,6 +24,7 @@ export declare class JsonSchemaValidator<Input extends Type.TSchema, Output exte
|
|
|
24
24
|
schema(): Input;
|
|
25
25
|
isJsonSchema(): boolean;
|
|
26
26
|
toJsonSchema(): unknown;
|
|
27
|
+
isAccelerated(): boolean;
|
|
27
28
|
check(value: unknown): value is Output;
|
|
28
29
|
parse(value: unknown): Output;
|
|
29
30
|
errors(value: unknown): object[];
|
|
@@ -41,6 +41,12 @@ export class JsonSchemaValidator extends Validator {
|
|
|
41
41
|
return this.input;
|
|
42
42
|
}
|
|
43
43
|
// ----------------------------------------------------------------
|
|
44
|
+
// Accelerated
|
|
45
|
+
// ----------------------------------------------------------------
|
|
46
|
+
isAccelerated() {
|
|
47
|
+
return this.validator.IsEvaluated();
|
|
48
|
+
}
|
|
49
|
+
// ----------------------------------------------------------------
|
|
44
50
|
// Validation
|
|
45
51
|
// ----------------------------------------------------------------
|
|
46
52
|
check(value) {
|
package/build/locale.mjs
CHANGED
|
@@ -2,8 +2,6 @@ import { System } from 'typebox/system';
|
|
|
2
2
|
const Locale = System.Locale;
|
|
3
3
|
/** Sets the locale for which errors are generated. */
|
|
4
4
|
export function locale(locale) {
|
|
5
|
-
const F = locale in System.Locale
|
|
6
|
-
? System.Locale[locale]
|
|
7
|
-
: System.Locale.en_US;
|
|
5
|
+
const F = locale in System.Locale ? System.Locale[locale] : System.Locale.en_US;
|
|
8
6
|
System.Locale.Set(F);
|
|
9
7
|
}
|
|
@@ -19,6 +19,7 @@ export declare class StandardJsonSchemaValidator<Input extends StandardJSONSchem
|
|
|
19
19
|
schema(): Input;
|
|
20
20
|
isJsonSchema(): boolean;
|
|
21
21
|
toJsonSchema(): unknown;
|
|
22
|
+
isAccelerated(): boolean;
|
|
22
23
|
check(value: unknown): value is Output;
|
|
23
24
|
parse(value: unknown): Output;
|
|
24
25
|
errors(value: unknown): object[];
|
|
@@ -38,6 +38,12 @@ export class StandardJsonSchemaValidator extends Validator {
|
|
|
38
38
|
return this.validator.Type();
|
|
39
39
|
}
|
|
40
40
|
// ----------------------------------------------------------------
|
|
41
|
+
// Accelerated
|
|
42
|
+
// ----------------------------------------------------------------
|
|
43
|
+
isAccelerated() {
|
|
44
|
+
return this.validator.IsEvaluated();
|
|
45
|
+
}
|
|
46
|
+
// ----------------------------------------------------------------
|
|
41
47
|
// Validation
|
|
42
48
|
// ----------------------------------------------------------------
|
|
43
49
|
check(value) {
|
|
@@ -6,6 +6,7 @@ export declare class StandardSchemaValidator<Input extends StandardSchemaV1, Out
|
|
|
6
6
|
schema(): Input;
|
|
7
7
|
isJsonSchema(): boolean;
|
|
8
8
|
toJsonSchema(): unknown;
|
|
9
|
+
isAccelerated(): boolean;
|
|
9
10
|
check(value: unknown): value is Output;
|
|
10
11
|
parse(value: unknown): Output;
|
|
11
12
|
errors(value: unknown): object[];
|
|
@@ -22,6 +22,12 @@ export class StandardSchemaValidator extends Validator {
|
|
|
22
22
|
return {};
|
|
23
23
|
}
|
|
24
24
|
// ----------------------------------------------------------------
|
|
25
|
+
// Accelerated
|
|
26
|
+
// ----------------------------------------------------------------
|
|
27
|
+
isAccelerated() {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// ----------------------------------------------------------------
|
|
25
31
|
// Validation
|
|
26
32
|
// ----------------------------------------------------------------
|
|
27
33
|
check(value) {
|
|
@@ -8,6 +8,7 @@ export declare class TypeScriptValidator<Input extends string, Schema extends Ty
|
|
|
8
8
|
schema(): Input;
|
|
9
9
|
isJsonSchema(): boolean;
|
|
10
10
|
toJsonSchema(): unknown;
|
|
11
|
+
isAccelerated(): boolean;
|
|
11
12
|
check(value: unknown): value is Output;
|
|
12
13
|
parse(value: unknown): Output;
|
|
13
14
|
errors(value: unknown): object[];
|
|
@@ -26,6 +26,12 @@ export class TypeScriptValidator extends Validator {
|
|
|
26
26
|
return this.jsonschema;
|
|
27
27
|
}
|
|
28
28
|
// ----------------------------------------------------------------
|
|
29
|
+
// Accelerated
|
|
30
|
+
// ----------------------------------------------------------------
|
|
31
|
+
isAccelerated() {
|
|
32
|
+
return this.validator.IsEvaluated();
|
|
33
|
+
}
|
|
34
|
+
// ----------------------------------------------------------------
|
|
29
35
|
// Validation
|
|
30
36
|
// ----------------------------------------------------------------
|
|
31
37
|
check(value) {
|
package/build/validator.d.mts
CHANGED
|
@@ -12,4 +12,6 @@ export declare abstract class Validator<Input extends unknown = unknown, Output
|
|
|
12
12
|
abstract isJsonSchema(): boolean;
|
|
13
13
|
/** Return the validator Json Schema representation. */
|
|
14
14
|
abstract toJsonSchema(): unknown;
|
|
15
|
+
/** Returns true if this validator is JIT accelerated */
|
|
16
|
+
abstract isAccelerated(): boolean;
|
|
15
17
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -23,9 +23,9 @@ $ npm install typedriver
|
|
|
23
23
|
|
|
24
24
|
## Example
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Framework Compiler System for JSON Schema, Standard Schema and TypeScript
|
|
27
27
|
|
|
28
|
-
Ref: [TypeScript](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoAqBPADgUwMoDGATgJbYAuqYStd9D4ypAttgPbEWgDeoh7NqQA2uUAF9QAM2KDQAcgo5cAEzIA3XMXnJkAgHYBnbgDVchCpwDMoALz9B2EbgAUAAx7JQoAB4AuUH0AVxYAIy0AGi9QTADgsMjogC84kPDiZHE3AEpdFXNhAENiMQNjUHVC4SDcAKD9AGt9dgB3fV0y7g5DUgpSdn07UDMLawA6bGLDV0rq3GzvRaXFtE7Qbt7+-QDPZb39g8OjpbRvf0C0xOPrm5vTmNSE4ijb17eTsG8Ui6fo9--rmhJPYxqCgA) | [
|
|
28
|
+
Ref: [TypeScript](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoAqBPADgUwMoDGATgJbYAuqYStd9D4ypAttgPbEWgDeoh7NqQA2uUAF9QAM2KDQAcgo5cAEzIA3XMXnJkAgHYBnbgDVchCpwDMoALz9B2EbgAUAAx7JQoAB4AuUH0AVxYAIy0AGi9QTADgsMjogC84kPDiZHE3AEpdFXNhAENiMQNjUHVC4SDcAKD9AGt9dgB3fV0y7g5DUgpSdn07UDMLawA6bGLDV0rq3GzvRaXFtE7Qbt7+-QDPZb39g8OjpbRvf0C0xOPrm5vTmNSE4ijb17eTsG8Ui6fo9--rmhJPYxqCgA) | [JSON Schema](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoBSBnA9gO1AMoDGAFgKYC2AhqmEvQ40+MgJYUAO2ATgC6gBvUEWydWAGzKgAvqABm3UaADkvAJ4cyAE26sAbmW7LkyEbkz8AamSK8eAZlABeYaI4SyACgHJQodZoAXCrYAEYAVja8ygA0vqDcZACOAK6siVrBANrKAB6xKmoFygBeygC6cX4cipp8rGSYwT5+frnN-hpkwcq4KRShhsoyVa1qHQHdKn0DQyPxfiUTXT0zg0Yy8dLI0gCUJlo24lSJrub8elTiKVMpuADWuNgA7rgmZhagXJisvKx4zlA1lsDgAdBwTpgvJdrmRdq0EYi0B9+N9fv9cM0Foicbi8fiCaA0G1gmtDKNCZSqYTiaBxqAydwKdSWayiWBFqT+utsWy+QS0LIXKCRUA) | [TypeBox](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoBSBnA9gO1AMoDGAFgKYC2AhgFygAqAngA5kBC2AHqmEn-wMHhkASwrNsAJwAuoAN6gi2cSIA2ZUAF9QAM0nLQAcmksyAE0kiAbmUmHR4qbKatd+ikZOsARl0OgA5GQlXExZADUyImkpAGZQAF5FZWY1MgAKFzIAOgB5bwArKOl0uWQAzjos7IA5AFcKb1t0gEoAGnLQRirTWoamyVaOgIAvHtY+xuaW5E0WmeQzKNUqSQ0QsNArKlU6sjo63ABrXGwAd1wgjdkJTBFpETxE0EjouOzmVcwM7d2yFoCgKBgLQ11At3uj1wdDKwLh8IRiKRQLQFTouH6tmGyJxuJxqK66MxkmxeLJ5ICBLGoAxU0knQpjPxYG0SWy7KAA) | [Zod](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoDKAXAhgOwCbYBO+GAxgBYCmAttgFygBaA9vqmEl9z7+MgEsaABxZFMoAN6gyLEQIA2VUAF9QAMyJzQAckwBPYVXxEBANypEdyQSLESAVKGwBnUAC8NWmrvdtryLK4LhIAalRkmGIAzKAAvDJywopUABTuAHQsAEYAVhGYqZLIoKAAHoyZuACuNNmWqQCUADQloPqVGTV1DS1t7p3d9URNyCqNjTb4EQrEykEhoGbYCtVUjNW4ANa4LADuuDYLEqIuApgCLLjxoOGRMRnCxC5py6tUjaVf319ox6Cnc6XXCMYo-cEQyFQ6HfNClCqgIaWVow1FotFw9qMJFEFHo-EE35gUoDRG1YZtQlU1FoNQJDIMoA) | [Valibot](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoDKAXAhgOwCbYBO+GAxgBYCmAttgFygBq2ANgJYBGA9pqmEkFDhI8MnY0ADtyKZQAb1BluU9qyqgAvqABmRFaADkmAJ6Sq+IuwBuVIoeTipMuQCpQ2AM6hru-TSNrNi5eB2RlXE85JioyTBkAZlAAXiUVSTUqAAprADpuTgArWMws+WRQUAAPRjzcAFcaTjssgEoAGgrQE1rchqaWjq6AL17+5qI25E1W1sd8WNZiDQionzZ6qkZ63ABrXG4Ad1xHVblpT3ZMdm5cFOYSxNzJYk9soNZN1sqf35+0M6gC5XG64RjlP6QqHQmGw35oSo1UDjOydOHojEYhHdRgoohozGEon-MCVUbIxoTLrEmnotDaVK5JlAA) | [ArkType](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoDKAXAhgOwCbYBO+GAxgBYCmAttgFygCCRA1gCoCeADlamEkFDhI8MgCWNbgHsimUAG9QZaVPEAbKqAC+oAGZFVoAOSYeVfEXEA3KkWPIJU2fKVneO-YZonird1QOyCq4AM7yAGpUZJiyAMygALzKqtwaVAAUARkKyKCgAB6MxrgArjQARnbGADR5oJzFZZXVdfkAXk3lVfbI2gCU-Y740erEWiHhoNbY6qVUjKW4rLjSAO64jpPyMqHimOLSuEmgUTHxAHTcxKGZM3NU-fnPL89o26C7+4e4jLmvAMBQOBIJeaHyRVAzR6bVBcPhcPBDUY0LssIRGMx+SRnSh3Ts9SxRMRYF0yQuFKAA) | [Effect](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoDKAXAhgOwCbYBO+GAxgBYCmAttgFygCiAZi1WZqmEr3-wPDIAljQAOAeyKZQAb1BkJ44QBsqoAL6gWRJaADkmAJ5iq+IsIBuVIvpHipM+ekq1sm7bpoGqbDpjtkRVwAZxkANX8pAGZQAF4FJTFVKgAKF2o6ADowvEISDLdwgEZ012ysIgBXTlTZZFBQAA9GQuyAOSqaACMbABoG0CNW8uwszp7+wYAvEcyxid6iZA0ASnXkZHwOFWJ1YLDQS2wVKqpGKtwAa1wJAHdcTYOZSRDhTGEJXHjQSM4YrJiYghNLHU5UVaNKHQqFoZ6gV7vT64Rj1GHojGYrHY6FoRpEKjYfBfFRGZqMXBdJYDHG0ul0vGgAlEklk4agSmTIg0+m8vmwsD4wnE3Ck0CzDlUmyDfmy2loLQJLLKoA) | [Arri](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoDKAXAhgOwCbYBO+GAxgBYCmAttgFygCCRRAlqmEtz73+MjY0ADgHsimUAG9QZUSLYAbKqAC+oAGZF5oAOSYAnsKr52ANypFdgkeMkzsazdpp6AAsXZFhZYAGdKWmxrZDlcP0kANSoyTHEAZlAAXll5YSUqAApsADpRACMAKxjMTKlkUFAAD0Zc3ABXGnzLTIBKABoK0ANanIamlo6ugC9e-uaiNuRVVtbkZHwYxWIVMIjQM2xFeqpGetwAa1xRAHdcebXJMT82TDZRXGTQaNiEnOFiPyzN7apWyoBgIBaEuoGut3uuEY5SBsLh8IRiMBaEqNVA40snSR2JxOJR3UYGKIWNxpLJwLAlVG6MaEy65IZ2LQ6hSOTZQA) | [Sury](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YpAoEoDKAXAhgOwCbYBO+GAxgBYCmAttgFwYCuRAnqmEl9z7+MgEsaABwD2RTKADeoMqJECANlVABfUADMi80AHJMrYVXxEBANypFdgkeMkAqUNgDOGTdpp7nLVrtD+AwKDg-zQAFgA6AGZQAGsAIVAAChoBXFAAalAAcwAvAWEASmRkOVxnSQA1KjJMcRiAXll5YSUqJPQI50pabCSpZH8AD0ZO3CYaACNLABpB0FZRiPGp2fncpZXpojnVQuLkfBrFYhUyitAzbEUmKkYmXFjcUQB3XBLzyTFnAUwBUXSTWqtXqEWExGc7SuNyohRCQTQn1A31+-1wjAG8Kx2JxOLQw0YWzWuJJpOx+IWhIm2zmZLp9NAFI2oCJRHmDI55LA6iaET5QA)
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
@@ -48,19 +48,29 @@ const position = Vector3.parse(value) // const position: {
|
|
|
48
48
|
|
|
49
49
|
## Overview
|
|
50
50
|
|
|
51
|
-
TypeDriver is a validation middleware that enables frameworks to incorporate
|
|
51
|
+
TypeDriver is a high-performance validation middleware that enables frameworks to incorporate both JSON Schema and Standard Schema specifications into framework interfaces (for example, HTTP route handlers, RPC endpoints, etc.). It provides a unified validation and type inference system to simplify integrating runtime types, and offers a TypeScript DSL compiler and inference system as standard.
|
|
52
52
|
|
|
53
|
-
> TypeDriver
|
|
53
|
+
> TypeDriver unifies heterogeneous runtime schema systems based on JSON Schema and Standard Schema into a single system that preserves static type inference, runtime validation, and schema reflection, while remaining compatible with multiple schema ecosystems.
|
|
54
54
|
|
|
55
|
-
TypeDriver provides high
|
|
55
|
+
TypeDriver provides high-performance validation for JSON Schema Drafts 3 through 2020-12. Internally, it uses TypeBox for schema validation and type inference, and Standard Schema for remote library integration. The TypeScript DSL provides runtime and type-level TypeScript emulation in support of TS 7 native compiler.
|
|
56
56
|
|
|
57
|
+
License MIT
|
|
57
58
|
|
|
59
|
+
## Features
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
- Designed Specifically for Framework Integration
|
|
62
|
+
- Integrated TypeScript DSL for TS7 Native (supported in TS5 and above)
|
|
63
|
+
- Unified Validation for JSON Schema and Standard Schema
|
|
64
|
+
- Unified Inference for JSON Schema and Standard Schema
|
|
65
|
+
- High Performance Validation Compiler (performance approx 2x Ajv)
|
|
66
|
+
- Acceleration support for Standard JSON Schema
|
|
67
|
+
- JSON Schema Reflect for OpenAPI, MCP and IDL Based Systems
|
|
68
|
+
- Localization Support for 40+ languages
|
|
60
69
|
|
|
61
70
|
## Contents
|
|
62
71
|
|
|
63
72
|
- [Overview](#Overview)
|
|
73
|
+
- [Features](#Features)
|
|
64
74
|
- [Framework](#Framework)
|
|
65
75
|
- [Compile](#Compile)
|
|
66
76
|
- [Check](#Check)
|
|
@@ -69,13 +79,14 @@ License MIT
|
|
|
69
79
|
- [Static](#Static)
|
|
70
80
|
- [Reflect](#Schema)
|
|
71
81
|
- [Locale](#Locale)
|
|
82
|
+
- [Accelerate](#Accelerate)
|
|
72
83
|
- [Contribute](#Contribute)
|
|
73
84
|
|
|
74
85
|
## Framework
|
|
75
86
|
|
|
76
87
|
TypeDriver is designed for framework integration to allow multiple type safe libraries to be hosted on framework interfaces. It provides a simple infrastructure to connect type inference and validation to the framework. The following shows a simple design for a route function ...
|
|
77
88
|
|
|
78
|
-
[
|
|
89
|
+
Ref: [TypeScript](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YyAoEoAiBTAzgSwOYB2qYSZ5FcyADgPbYAuAFAOTAsA0oA3sqKACNaAEwCeALlAADXv34APSYQCuAWwGYAThz5yJoFeq065oAF5K1GzboC+U5La5NNmAI7KcDAJSgAvAB8PLoAxrSEjDyg8lyiXGagtv6grh5eAHRCYqBoDKLUmODYAIYAZpgAhI7eyCQQlA2N8HUAYprFqpgA7rSaANZ1TUPDyLiqdJoMUXkFoADKDMUMuCFcYeO4ADaYiaClmrSqoCwzmMKauABuWiy1mPITU7iEDFqlxSE7AEq0yq8A8tRluFsAAeABCIlEoHur0IwmwoGUhD6hFoXUIyWRqPRhCCskEUMkkLEjmQ90eoFOoB+f0wAGFiptNgIPn1QQAFJYACxh8jhCNAjAuhHwXEBwIifIFiNpAKBuBBQT8oCYuhc7k8jEk3CRmk2ki5DG5XCy+gWSxWoIlioiAG0WGaWABdIK2XyBUCXWi4YTIGoU3pTUrIkKS0B0RicnnSzDwxHC55i0BhCJTG0g2Pxmm-eWS7BcXSM5mskJ9ZJyhlMlls6PG8UKpXIAJMag8w08ri0RsRSQZiJraulvqSYs1su+AmpyJmgD6lyZvqWvWS62oW0wTG7+YdTudNX4uREtEk6TPoDG1G2nReKVzO02tHwKzJQA) | [JSON Schema](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YyAoEoAiBTAzgSwOYB2qYSZ5FcyADgPbYAuAFAOTAsA0oA3sqKACNaAEwCeALh59+oBqOqZJLWgIBWmAMYNO0-gCdMARwCuuA8MkBtFgA9OoFqPssAXiwC6HXaGp7aCvQZcHEleGRkbUNl5RQdCYwBbAUw9FlAAXy9w-gkeaIUleKSUtMzvfhcouQK4xOTUjKyZdOkWzNAmAxMcBgBKUABeAD4pfg1aQkY8my5RLhcMwdAu4x6AOiExUDRqzHBsAEMAM0wAQmR03uQSCEo7+-gbgDE9A4TMAHdaPQBrG4eAYDkLgEnRAnldqAAMoMA5BDRccag3AAG0wiyOfgSDl2wj0uAAbiVrpgbGCGKBcIQGCkjgcNOiAEq0Yw0gDy1CCE2wAB4AEIiUSgUk0wjCbCgYyEH6EWgfQhLKUyuWEEZhQSCyQCsQXZCk8n5JksmkAYQOKJRAnpPx5AAU4QALYU2UXi0CMfGEfBcDlcybO10S5mszC+3DckYDDrSTpGVaMKLGPQoyT2hgOribXIwuG4DQ8sPc6xZjwjS6DEYE2i4YTIK7674Uo5SrThhV0Rh2x0BzBiiUeqne0DjSYUwv+kW9t3B9mctvYLjSM0Wq0aH5LGeYZeW61d9M+ucR5BDJjUR2px1cfx+7CSccL4fmndryTb1c-frqkdTLMAfQJ5o1nC3xLEi1CopgTDXvOxaCh4Vz8DsIi0JIaxoZSoJou81LLMa6IorQ+B5rqQA) | [Standard Schema](https://www.typescriptlang.org/play/?target=99&module=7#code/PTAEFpK6dv4YyAoEoAiBTAzgSwOYB2qYSZ5FcyuAtgA4D2ATgC6gBUoAhtqAF6gAZkwY1QAcj4MAJuOTJG2FgApxwcQBpQAb2ShQAIxkBPAFz8AdAwMArTAGMVu-foAe5vhcIBXGgcxMygCUGnouZpY+fgHBoS78Hl6+-oEhYQC+QcjpWspMmACO3jgsQaAAvAB8OmH2DIRKOqCuWsZaAukVoPlFJRZG0sagaCzGdJjg2FyCmACE2VkkEJQrq-BLAGJMXDSYAO7MANZLa6dn1PTMbNqgo+OgAMosXCy49lp19LgANpigncJRBI7phpExcAA3AJyZCYVyMVigXCEFgBQRcex-ABKDG8qIA8nRXvVsAAeABCJlAcNRhGkvG8hEOhAYe0IXUZzNZhGqzkMJnMlMG2Vh8KutzG2NxqIAwlxvt8DBjDqSAAovAAW1NctPpoCU4MI+C0hOJDW1ut4OLxmFNuBJ1XKoGUYTyhWKSnMN28TG+5nVLA1WgGESeLzepLtJIA2uIQ+IALrVTIVaoQhi4aTILJwhFsQSMxz29mKFhqzUWzB03gG5HG0B1BpsKPmmlVvXWglE4vYLRhOUKpX2Q5dTuYAeK5XlwMm7sO5CVZR0TX+zVaBhzhrmFu9hvyyfD8wToeHMp8xuNEMAfQh8szL2YXU+dB+mGUG7N2Fj8YTWX0IxkBhzAsECkXoX5dhRbppT+b4GHwN4RSAA)
|
|
79
90
|
|
|
80
91
|
```typescript
|
|
81
92
|
post('/', {
|
|
@@ -89,7 +100,12 @@ post('/', {
|
|
|
89
100
|
})
|
|
90
101
|
```
|
|
91
102
|
|
|
92
|
-
Where the above design is achieved with the following
|
|
103
|
+
Where the above design is achieved with the following TS definitions (Expand to View)
|
|
104
|
+
|
|
105
|
+
<details>
|
|
106
|
+
|
|
107
|
+
<summary>TypeDriver Route Definition</summary>
|
|
108
|
+
|
|
93
109
|
|
|
94
110
|
```typescript
|
|
95
111
|
import { type Static, compile } from 'typedriver'
|
|
@@ -108,15 +124,17 @@ export function post<Path extends string, const Options extends RouteOptions,
|
|
|
108
124
|
}
|
|
109
125
|
```
|
|
110
126
|
|
|
127
|
+
</details>
|
|
128
|
+
|
|
111
129
|
## Compile
|
|
112
130
|
|
|
113
|
-
TypeDriver consists of a
|
|
131
|
+
TypeDriver consists of a single compile(...) function that accepts JSON Schema, Standard Schema or TypeScript definition and returns a Validator instance.
|
|
114
132
|
|
|
115
133
|
```typescript
|
|
116
134
|
import { compile } from 'typedriver'
|
|
117
135
|
```
|
|
118
136
|
|
|
119
|
-
|
|
137
|
+
TypeScript [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV1AOwGd4A1LMhjQAzHAC8KNGExYAFAAMErOHAAeALjicAriABGzFXApbdBo6oBeZvYaitcCgJSq37j56-ef7gPR+Ujz8gsJQIlp8AIYYwDRRYQA8AHSpADSIxr7ZObluAW6a2nbMaVl5FZX5gaqmxRZQZVXNlQXWtg1NLd3ZBbgAfOxcvHCQ3MAwwBCcEnACQqLJYFFQ3PJIxkUADF11AIxdNnBbjs5AA)
|
|
120
138
|
|
|
121
139
|
```typescript
|
|
122
140
|
const Vector3 = compile(`{
|
|
@@ -126,7 +144,7 @@ const Vector3 = compile(`{
|
|
|
126
144
|
}`)
|
|
127
145
|
```
|
|
128
146
|
|
|
129
|
-
|
|
147
|
+
JSON Schema [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV1AOwGd4A1LMhjQAzHAC8KNGExYAFEjhLlK1WtUB6DVJ79BwqCIBccPgEMMwGmYMAeAHSOANIlZLK1E6QgAjAFb6pC7qIaFhWsoAHiacAK4gPsxObnBQWACOscBpNCYA2qSRQWQUxaQAXqQAusFhdXARShQx8YlQyUpgxNSwwFjcJor1w+HaSuUtCcwpStGIcB5YXnFTLHi1I6ERuAB8M3DN84vLrcyk6-sTR1RLZCtt57gpT7gAlOxcvHCQ3MAwwBBOBJTPpRPYwGYoNx5EgUnMAAwdA4mACMSKu8NYbyAA)
|
|
130
148
|
|
|
131
149
|
```typescript
|
|
132
150
|
const Vector3 = compile({
|
|
@@ -140,7 +158,7 @@ const Vector3 = compile({
|
|
|
140
158
|
})
|
|
141
159
|
```
|
|
142
160
|
|
|
143
|
-
|
|
161
|
+
Standard Schema [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV0SWOAKjgEMAznABehYiDIiINNq1QA7QfABqWZDGgBmOAF4UaMJiwAKEQDoIAIwBW6mCaRxnL12+cB6DwaWr72gC44FX4MYBp+TSgAHnM4gBpEVmcADyCLBQBXECtmEwBKRPdiktK3Lxc0uCyc5njkuAp08xrcqAKisq7uuArnJurstvrnEWbWvMKe6dK+0SCJqFZcfPyZ9Y3e71wAPnZFZThIQWAYYAgFPWD-KC1zMH4oQVMkBqqABhHGoIBGL7G4O9lvkgA)
|
|
144
162
|
|
|
145
163
|
```typescript
|
|
146
164
|
import * as z from 'zod'
|
|
@@ -192,12 +210,12 @@ const errors = Vector3.errors(value)
|
|
|
192
210
|
|
|
193
211
|
## Static
|
|
194
212
|
|
|
195
|
-
|
|
213
|
+
TypeDriver provides type infernece for JSON Schema, Standard Schema or TypeScript | [Example](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAbzjAnmApnAyjAhjYAYzgF84AzKCEOAclQwBMpgA3dKWgKC4Hpe4ASQB25DsjToAzhSo1cAGwXIAFsGEBzKQEIeDTAEE4AXmx4ChADwADJFzhwAHgC44wgK4gARhwA09uBRXD28-AIAvYM8fKC4SawA+PUk4ACETM3wiSwQA-VdaCC8AK3RCGFp-Byh0AEd3YBrGVwBtWkdKuhRO2nDaAF0quDAqDFhgaVdchwcXRAkMApCY2lIhhyD5-LpljlWSdbhIrckl6L21gJI4pK5QSFg4ACo4XBlw2Wo6cIhGbi5CBBhFJ4ABhDLhAB0RVK5QAFNMnK4obsoHCAJRDTYo85ozERZGQ1EY-wkdFcfRwcGmHBZKz6CDkKm3IA)
|
|
196
214
|
|
|
197
215
|
```typescript
|
|
198
216
|
import { type Static } from 'typedriver'
|
|
199
217
|
|
|
200
|
-
//
|
|
218
|
+
// TypeScript
|
|
201
219
|
|
|
202
220
|
type A = Static<`{
|
|
203
221
|
x: number,
|
|
@@ -205,6 +223,8 @@ type A = Static<`{
|
|
|
205
223
|
z: number
|
|
206
224
|
}`>
|
|
207
225
|
|
|
226
|
+
// JSON Schema
|
|
227
|
+
|
|
208
228
|
type B = Static<{
|
|
209
229
|
type: 'object',
|
|
210
230
|
required: ['x', 'y', 'z'],
|
|
@@ -215,6 +235,8 @@ type B = Static<{
|
|
|
215
235
|
}
|
|
216
236
|
}>
|
|
217
237
|
|
|
238
|
+
// Standard Schema
|
|
239
|
+
|
|
218
240
|
import * as z from 'zod'
|
|
219
241
|
|
|
220
242
|
const C = z.object({
|
|
@@ -229,19 +251,19 @@ type C = Static<typeof C>
|
|
|
229
251
|
|
|
230
252
|
## Reflect
|
|
231
253
|
|
|
232
|
-
Validators can reflect back a
|
|
254
|
+
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.
|
|
233
255
|
|
|
234
256
|
```typescript
|
|
235
257
|
import { compile, type Static } from 'typedriver'
|
|
236
258
|
|
|
237
259
|
const validator = compile(...)
|
|
238
260
|
|
|
239
|
-
validator.
|
|
240
|
-
//
|
|
241
|
-
// compiled with
|
|
261
|
+
validator.isJSONSchema() // Returns true if the validator can be converted to
|
|
262
|
+
// JSON Schema. This is true when the validator was
|
|
263
|
+
// compiled with JSON Schema or TypeScript, but false
|
|
242
264
|
// if it was compiled with Standard Schema.
|
|
243
265
|
|
|
244
|
-
validator.
|
|
266
|
+
validator.toJSONSchema() // Returns the JSON Schema for the validator. If the
|
|
245
267
|
// validator was compiled with Standard Schema, an
|
|
246
268
|
// empty {} is returned to indicate an unknown
|
|
247
269
|
// runtime schema.
|
|
@@ -261,13 +283,14 @@ import { compile, locale } from 'typedriver'
|
|
|
261
283
|
|
|
262
284
|
// Supported Locales
|
|
263
285
|
|
|
264
|
-
type LocaleString =
|
|
265
|
-
| "ar_001" | "bn_BD"
|
|
266
|
-
| "es_AR"
|
|
267
|
-
| "ha_NG"
|
|
268
|
-
| "ms_MY"
|
|
269
|
-
| "sv_SE"
|
|
270
|
-
| "yo_NG"
|
|
286
|
+
type LocaleString = (
|
|
287
|
+
| "ar_001" | "bn_BD" | "cs_CZ" | "de_DE" | "el_GR" | "en_US" | "es_419"
|
|
288
|
+
| "es_AR" | "es_ES" | "es_MX" | "fa_IR" | "fil_PH" | "fr_CA" | "fr_FR"
|
|
289
|
+
| "ha_NG" | "hi_IN" | "hu_HU" | "id_ID" | "it_IT" | "ja_JP" | "ko_KR"
|
|
290
|
+
| "ms_MY" | "nl_NL" | "pl_PL" | "pt_BR" | "pt_PT" | "ro_RO" | "ru_RU"
|
|
291
|
+
| "sv_SE" | "sw_TZ" | "th_TH" | "tr_TR" | "uk_UA" | "ur_PK" | "vi_VN"
|
|
292
|
+
| "yo_NG" | "zh_Hans" | "zh_Hant"
|
|
293
|
+
)
|
|
271
294
|
|
|
272
295
|
locale('en_US') // Set: English | US (Default)
|
|
273
296
|
|
|
@@ -289,8 +312,42 @@ console.log(compile('string').errors(42)) // [{
|
|
|
289
312
|
// message: "string이어야 합니다"
|
|
290
313
|
// }]
|
|
291
314
|
```
|
|
292
|
-
Localization support is only available for
|
|
315
|
+
Localization support is only available for JSON Schema.
|
|
316
|
+
|
|
317
|
+
## Accelerate
|
|
318
|
+
|
|
319
|
+
TypeDriver provides acceleration support for libraries that implement the Standard JSON Schema specification. This is a new specification that enables runtime type libraries to be integrated into TypeBox validation infrastructure. This project tracks upstream implementations of this specification and maintains a benchmark measuring compariative performance with and without compile(...).
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
$ deno task bench
|
|
323
|
+
```
|
|
324
|
+
Benchmark 16M Parse Operations of this Structure
|
|
325
|
+
```typescript
|
|
326
|
+
const Vector3 = compile(`{
|
|
327
|
+
x: number,
|
|
328
|
+
y: number,
|
|
329
|
+
z: number
|
|
330
|
+
}`)
|
|
331
|
+
```
|
|
293
332
|
|
|
333
|
+
Accelerated Indicates Support for Standard JSON Schema
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
┌────────────┬────────────┬─────────────┬──────────────┬──────────────┬─────────────────┐
|
|
337
|
+
│ (idx) │ iterations │ accelerated │ default(...) │ compile(...) │ result │
|
|
338
|
+
├────────────┼────────────┼─────────────┼──────────────┼──────────────┼─────────────────┤
|
|
339
|
+
│ typescript │ 16000000 │ true │ " ------" │ " 30 ms" │ " ------" │
|
|
340
|
+
│ jsonschema │ 16000000 │ true │ " ------" │ " 29 ms" │ " ------" │
|
|
341
|
+
│ arktype │ 16000000 │ true │ " 537 ms" │ " 30 ms" │ "94.41% faster" │
|
|
342
|
+
│ arri │ 16000000 │ false │ " 3086 ms" │ " 3049 ms" │ "1.20% faster" │
|
|
343
|
+
│ effect │ 16000000 │ false │ "24183 ms" │ "23886 ms" │ "1.23% faster" │
|
|
344
|
+
│ sury │ 16000000 │ false │ " 153 ms" │ " 166 ms" │ "8.33% slower" │
|
|
345
|
+
│ valibot │ 16000000 │ false │ " 3632 ms" │ " 3515 ms" │ "3.21% faster" │
|
|
346
|
+
│ zod │ 16000000 │ false │ " 575 ms" │ " 603 ms" │ "4.93% slower" │
|
|
347
|
+
└────────────┴────────────┴─────────────┴──────────────┴──────────────┴─────────────────┘
|
|
348
|
+
|
|
349
|
+
Last Run: Thu Dec 04 2025
|
|
350
|
+
```
|
|
294
351
|
|
|
295
352
|
## Contribute
|
|
296
353
|
|