typedriver 0.8.9 → 0.8.11

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.
@@ -1,12 +1,6 @@
1
- import Type from 'typebox';
2
- import { type StandardSchemaV1, type StandardJSONSchemaV1 } from '@standard-schema/spec';
1
+ import { type Static } from './static.mjs';
3
2
  import { Validator } from './validator.mjs';
4
- type TFromStandardSchema<Input extends StandardSchemaV1, Output extends unknown = StandardSchemaV1.InferInput<Input>, Result extends Validator = Validator<Input, Output>> = Result;
5
- type TFromStandardJsonSchema<Input extends StandardSchemaV1 & StandardJSONSchemaV1, Output extends unknown = StandardSchemaV1.InferInput<Input>, Result extends Validator = Validator<Input, Output>> = Result;
6
- type TFromJsonSchema<Input extends Type.TSchema, Output extends unknown = Type.Static<Input>, Result extends Validator = Validator<Input, Output>> = Result;
7
- type TFromTypeScript<Input extends string, Schema extends Type.TSchema = Type.TScript<{}, Input>, Output extends unknown = Type.Static<Schema>, Result extends Validator = Validator<Input, Output>> = Result;
8
3
  /** Compiles a schema into a typed Validator */
9
- export type TCompile<Schema extends unknown> = (Schema extends string ? TFromTypeScript<Schema> : Schema extends StandardSchemaV1 ? (Schema extends StandardJSONSchemaV1 ? TFromStandardJsonSchema<Schema> : TFromStandardSchema<Schema>) : Schema extends Type.TSchema ? TFromJsonSchema<Schema> : TFromJsonSchema<{}>);
4
+ export type TCompile<Input, Output extends unknown = Static<Input>, Result extends Validator<Input, Output> = Validator<Input, Output>> = Result;
10
5
  /** Compiles a schema into a typed Validator */
11
- export declare function compile<const Schema extends unknown>(schema: Schema): TCompile<Schema>;
12
- export {};
6
+ export declare function compile<const Input, Output extends Validator = TCompile<Input>>(input: Input): Output;
package/build/compile.mjs CHANGED
@@ -4,24 +4,22 @@ import { JsonSchemaValidator } from './validators/json-schema/validator.mjs';
4
4
  import { StandardJsonSchemaValidator } from './validators/standard-json-schema/validator.mjs';
5
5
  import { StandardSchemaValidator } from './validators/standard-schema/validator.mjs';
6
6
  import { TypeScriptValidator } from './validators/typescript/validator.mjs';
7
- function FromStandardSchema(schema) {
8
- return new StandardSchemaValidator(schema);
7
+ // ------------------------------------------------------------------
8
+ // Validators
9
+ // ------------------------------------------------------------------
10
+ function CreateStandardSchemaV1Validator(input) {
11
+ return IsStandardJsonSchemaV1(input) ? new StandardJsonSchemaValidator(input) : new StandardSchemaValidator(input);
9
12
  }
10
- function FromStandardJsonSchema(schema) {
11
- return new StandardJsonSchemaValidator(schema);
13
+ function CreateJsonSchemaValidator(input) {
14
+ return new JsonSchemaValidator(input);
12
15
  }
13
- function FromJsonSchema(schema) {
14
- return new JsonSchemaValidator(schema);
15
- }
16
- function FromTypeScript(script) {
17
- return new TypeScriptValidator(script);
16
+ function CreateTypeScriptValidator(input) {
17
+ return new TypeScriptValidator(input);
18
18
  }
19
19
  /** Compiles a schema into a typed Validator */
20
- export function compile(schema) {
21
- return (IsTypeScript(schema) ? FromTypeScript(schema) :
22
- IsStandardSchemaV1(schema) ? (IsStandardJsonSchemaV1(schema)
23
- ? FromStandardJsonSchema(schema)
24
- : FromStandardSchema(schema)) :
25
- IsJsonSchema(schema) ? FromJsonSchema(schema) :
26
- FromJsonSchema({}));
20
+ export function compile(input) {
21
+ return (IsTypeScript(input) ? CreateTypeScriptValidator(input) :
22
+ IsStandardSchemaV1(input) ? CreateStandardSchemaV1Validator(input) :
23
+ IsJsonSchema(input) ? CreateJsonSchemaValidator(input) :
24
+ CreateJsonSchemaValidator({}));
27
25
  }
package/build/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ export { Type } from 'typebox';
1
2
  export { type TCompile, compile } from './compile.mjs';
2
3
  export { type Static } from './static.mjs';
3
4
  export { Validator, type TErrorFormat, type TErrorLocale, type TErrorOptions, type TErrorResult, type TJsonSchemaError, type TStandardSchemaError, } from './validator.mjs';
package/build/index.mjs CHANGED
@@ -1,5 +1,9 @@
1
1
  // deno-fmt-ignore-file
2
2
  // ------------------------------------------------------------------
3
+ // Type
4
+ // ------------------------------------------------------------------
5
+ export { Type } from 'typebox';
6
+ // ------------------------------------------------------------------
3
7
  // Compile
4
8
  // ------------------------------------------------------------------
5
9
  export { compile } from './compile.mjs';
@@ -1,10 +1,10 @@
1
+ import { type TSchema, type TScript, type Static as TStatic } from 'typebox';
1
2
  import { type StandardSchemaV1 } from '@standard-schema/spec';
2
3
  import { type Validator } from './validator.mjs';
3
- import Type from 'typebox';
4
4
  type StaticValidator<_Input extends unknown, Output extends unknown> = (Output);
5
- type StaticTypeScript<Input extends string, Schema extends Type.TSchema = Type.TScript<{}, Input>, Output extends unknown = Type.Static<Schema>> = Output;
5
+ type StaticTypeScript<Input extends string, Schema extends TSchema = TScript<{}, Input>, Output extends unknown = TStatic<Schema>> = Output;
6
6
  type StaticStandardSchema<Input extends StandardSchemaV1, Output extends unknown = StandardSchemaV1.InferOutput<Input>> = Output;
7
- type StaticJsonSchema<Input extends Type.TSchema, Output extends unknown = Type.Static<Input>> = Output;
8
- type StaticInput<Input extends unknown> = (Input extends Validator<infer Input extends unknown, infer Output extends unknown> ? StaticValidator<Input, Output> : Input extends string ? StaticTypeScript<Input> : Input extends StandardSchemaV1 ? StaticStandardSchema<Input> : Input extends Type.TSchema ? StaticJsonSchema<Input> : unknown);
7
+ type StaticJsonSchema<Input extends TSchema, Output extends unknown = TStatic<Input>> = Output;
8
+ type StaticInput<Input extends unknown> = (Input extends Validator<infer Input extends unknown, infer Output extends unknown> ? StaticValidator<Input, Output> : Input extends string ? StaticTypeScript<Input> : Input extends StandardSchemaV1 ? StaticStandardSchema<Input> : Input extends TSchema ? StaticJsonSchema<Input> : unknown);
9
9
  export type Static<Input, Output = StaticInput<Input>> = Output;
10
10
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typedriver",
3
3
  "description": "High Performance Driver for Runtime Type System Integration",
4
- "version": "0.8.9",
4
+ "version": "0.8.11",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "json-schema",
package/readme.md CHANGED
@@ -45,9 +45,7 @@ Compiles: [TypeScript](https://www.typescriptlang.org/play/?target=99&module=7#c
45
45
 
46
46
  ## Overview
47
47
 
48
- TypeDriver is a validation compiler and type-inference middleware designed to integrate JSON Schema and Standard Schema compliant validation into framework interfaces such as HTTP routes and RPC endpoints. It also functions as a validation optimizer built to accelerate high-throughput messaging systems.
49
-
50
- This project is designed to unify 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.
48
+ 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.
51
49
 
52
50
  License MIT
53
51
 
@@ -71,25 +69,20 @@ License MIT
71
69
 
72
70
  ## Features
73
71
 
74
- - Framework Integration
75
- - Designed specifically for [type-safe](#Framework) I/O interfaces.
76
- - One function to [compile](#compile) schematics into Validators.
77
- - One type to [infer](#Static) schematics into TypeScript types.
78
- - Schema [extension](#Extensions) model for Framework specific runtime type API
79
- - Schema Support
80
- - TypeScript [DSL](#Script) for TS7-native (supported in TS5+).
81
- - Scalable JSON Schema type inference ([demo](https://tsplay.dev/wjrYMw))
82
- - Supports JSON Schema Drafts 3 through 2020-12.
83
- - Full support for Standard Schema
84
- - Validation Compiler
85
- - High-performance JIT compiler for faster application start up.
86
- - High-performance runtime validation (approx 2x Ajv performance)
87
- - Automatic [acceleration](#Accelerate) for libraries supporting Standard JSON Schema.
88
- - Automatic JIT fallback for [content-security](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) restrictive environments (Cloudflare)
89
- - Tooling and Interoperability
90
- - JSON Schema [reflect](#Reflect) API for OpenAPI, MCP, and IDL-Based Systems
91
- - Error [formats](#Errors) for JSON Schema and Standard Schema Based Systems
92
- - Includes [localized](#Locales) error messages (i18n) as standard.
72
+ TypeDriver provides a comprehensive set of features for integrating type-safe validation across multiple schema ecosystems:
73
+
74
+ - Single [function](#Compile) to compile multiple schematics into validators.
75
+ - Single [type](#Static) for inferring TypeScript types from multiple schematics.
76
+ - Integrated TypeScript [DSL](#Script) for TS7-native (supported in TS5+).
77
+ - Validation support for JSON Schema Drafts 3 through 2020-12.
78
+ - Supports Standard Schema and Standard JSON Schema (with [acceleration](#Accelerate))
79
+ - High-performance JIT compiler for improved application start up.
80
+ - High-performance runtime validation (approx 2x Ajv check performance)
81
+ - JIT compile fallback for [content-security](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) restrictive edge environments (e.g. Cloudflare)
82
+ - Schema [extension](#Extensions) model for custom type safe builder API's.
83
+ - JSON Schema [reflect](#Reflect) API for OpenAPI, MCP, and IDL-Based Systems
84
+ - Error [formats](#Errors) for JSON Schema and Standard Schema Based Systems
85
+ - Includes [localized](#Locales) error messages (i18n) as standard.
93
86
 
94
87
  ## Framework
95
88
 
@@ -400,25 +393,28 @@ validator.schema() // will return the schematic used for compile.
400
393
 
401
394
  ## Extensions
402
395
 
403
- TypeDriver enables Frameworks to define custom Runtime Types specific to the Framework. This can be achieved by creating functions that return statically observable JSON Schema. These schematics can be passed to compile(...) and Static and used like any other type.
396
+ 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.
404
397
 
405
- Ref: [Framework Types](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAbzgYwuYAbApgGjjATzCzgGUYBDGYZOAXzgDMo04ByQ4gEymADcsUNgChhAejFwAtDNlz5CxUuUrVU8ZICqAZwoBzLBulqTps2uGoAdtvgA1LMhjQAzHAC8KNGExYAFBAARgBWjjB+CMJwcAAeAFxwVgCuIIGCfgCUOFFwBAnJqelZOQBe+SlpUJnCdBkZopwkDk6uHmSU1MgAPI0QjHDNzlAuAHyiEsbmU9MmRppWwBBWACoQy0lg2Ak6WFz4EHAAojEwUBROcAAKLMSwBADSWATaTCwgVzeC1FjaRjP-AIUwkacHmixWEAAklYYIJtGFwV1NCM2n5NHAsCcsFYuC8KFYCHAAPxwPzxUEZDwovgQYB7fJYARQSmY2E4l5khLAKyMQRwSGU9zU2l7EmQuAMpnAogkAAyFFsAHlGEiUZ4wUtVtDYVB4U5EaCMVj2XB8YSSZyKVS4DS6RLEoy+SjWdjcaTydzeVA4LLBcK7STZfarI6oNLiKCFpq1htsEi8PLbG1EzBlaq1XAANqaAC6RrZbszIaZeZJmbzCUzADoaxqIetNlgusdkBgklwm5oEwqYCMRt3bDnxpJAaPAUYAGJnEBYADu0AA1oqQmE-mP11NwyQAEpYACOSWAUF2AEEoGcCF1rhBbt8Xi6TbvUFAuF1bLwrHo8EkrAurBBZysfscmvW8Hiee9jTdd9uT0NpjlOc4YC6Bcnj6D4by+YAfjwGDP2A6JdwPI9T3PChCXVKN61jJtQK+cDnjGDMiMPY8uDPC9hExSBYDgbkdUYc4SCnCgZ3nKAlxXJwr0+WBsMggsXifaBXzwr84B-P8AKAlFImiRoEjYIJQicNg8ByMBZLvBI6LknC4ByY9iLYhIWJI9iyMvWy7zGOguJiHj4EYH99SWOBjLCLprCTbz5PzV0lMcFS31OWDv1-f9AL7PxLMwuztBsqz5IyBIRLExdlxM5DYp+XTHKwGAkigKxEHwGVDIi0y8Cc1jdgSSqwirVDnhyoqfiyOBctvOKGAVB0pT8iYN2W0xJ2nOdFwAOQqQQ1xW-alGEfjBEE5BhPW8SF22wpvT0triEMgpKhEPzuOgIKQuoMKnqKUqLq2nbboc6Jj0a5rWoM9gfqEegaiAA)
398
+ Ref: [Advanced Framework Types](https://tsplay.dev/mMkoZw)
406
399
 
407
400
  ```typescript
408
- import compile, { type Static } from 'typedriver'
401
+ import { type Static } from 'typedriver'
409
402
 
410
- interface FrameworkString {
403
+ interface TEmail {
411
404
  type: 'string'
412
405
  }
413
- export function number(): FrameworkString {
414
- return { type: 'string' }
406
+ export function email(): TEmail {
407
+ return { type: 'string', format: 'email' }
415
408
  }
416
409
 
417
410
  // ... Usage
418
411
 
419
- const T = number() // const T: FrameworkString = { type: 'number' }
412
+ const T = email() // const T: TEmail = {
413
+ // type: 'string',
414
+ // format: 'email'
415
+ // }
420
416
 
421
- type T = Static<typeof T> // type T = number
417
+ type T = Static<typeof T> // type T = string
422
418
  ```
423
419
 
424
420
  ## Accelerate