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.
- package/build/compile.d.mts +3 -9
- package/build/compile.mjs +14 -16
- package/build/index.d.mts +1 -0
- package/build/index.mjs +4 -0
- package/build/static.d.mts +4 -4
- package/package.json +1 -1
- package/readme.md +26 -30
package/build/compile.d.mts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
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<
|
|
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
|
|
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
|
-
|
|
8
|
-
|
|
7
|
+
// ------------------------------------------------------------------
|
|
8
|
+
// Validators
|
|
9
|
+
// ------------------------------------------------------------------
|
|
10
|
+
function CreateStandardSchemaV1Validator(input) {
|
|
11
|
+
return IsStandardJsonSchemaV1(input) ? new StandardJsonSchemaValidator(input) : new StandardSchemaValidator(input);
|
|
9
12
|
}
|
|
10
|
-
function
|
|
11
|
-
return new
|
|
13
|
+
function CreateJsonSchemaValidator(input) {
|
|
14
|
+
return new JsonSchemaValidator(input);
|
|
12
15
|
}
|
|
13
|
-
function
|
|
14
|
-
return new
|
|
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(
|
|
21
|
-
return (IsTypeScript(
|
|
22
|
-
IsStandardSchemaV1(
|
|
23
|
-
?
|
|
24
|
-
|
|
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';
|
package/build/static.d.mts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
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
|
|
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
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- Schema
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
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://
|
|
398
|
+
Ref: [Advanced Framework Types](https://tsplay.dev/mMkoZw)
|
|
406
399
|
|
|
407
400
|
```typescript
|
|
408
|
-
import
|
|
401
|
+
import { type Static } from 'typedriver'
|
|
409
402
|
|
|
410
|
-
interface
|
|
403
|
+
interface TEmail {
|
|
411
404
|
type: 'string'
|
|
412
405
|
}
|
|
413
|
-
export function
|
|
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 =
|
|
412
|
+
const T = email() // const T: TEmail = {
|
|
413
|
+
// type: 'string',
|
|
414
|
+
// format: 'email'
|
|
415
|
+
// }
|
|
420
416
|
|
|
421
|
-
type T = Static<typeof T> // type T =
|
|
417
|
+
type T = Static<typeof T> // type T = string
|
|
422
418
|
```
|
|
423
419
|
|
|
424
420
|
## Accelerate
|