typedriver 0.8.8 → 0.8.10
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/errors/normal-issue.d.mts +1 -1
- package/build/guard/standard-json-schema.d.mts +1 -1
- package/build/guard/standard-schema.d.mts +1 -1
- package/build/static.d.mts +5 -5
- package/build/validators/standard-json-schema/resolve.d.mts +1 -1
- package/build/validators/standard-json-schema/validator.d.mts +1 -1
- package/build/validators/standard-schema/validator.d.mts +1 -1
- package/package.json +3 -2
- package/readme.md +12 -15
- package/build/_standard/standard-schema.d.mts +0 -120
- package/build/_standard/standard-schema.mjs +0 -1
package/build/compile.d.mts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type StandardSchemaV1, type StandardJSONSchemaV1 } from './_standard/standard-schema.mjs';
|
|
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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from '
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { TStandardSchemaError } from '../validator.mjs';
|
|
3
3
|
/** (Internal) Normalize a StandardSchemaV1.Issue as TStandardSchemaError. */
|
|
4
4
|
export declare function normalIssue(issue: StandardSchemaV1.Issue): TStandardSchemaError;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StandardSchemaV1, StandardJSONSchemaV1 } from '
|
|
1
|
+
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
export declare function IsStandardJsonSchemaV1(value: unknown): value is StandardSchemaV1 & StandardJSONSchemaV1;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from '
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
export declare function IsStandardSchemaV1(value: unknown): value is StandardSchemaV1;
|
package/build/static.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TSchema, type TScript, type Static as TStatic } from 'typebox';
|
|
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 {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { StandardJSONSchemaV1 } from '
|
|
1
|
+
import { StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
/** (Internal) Resolves a JsonSchema representation (need discovery mechanism here) */
|
|
3
3
|
export declare function resolveJsonSchema(input: StandardJSONSchemaV1): Record<string, unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StandardJSONSchemaV1, StandardSchemaV1 } from '
|
|
1
|
+
import { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Validator, type TErrorOptions, type TErrorResult } from '../../validator.mjs';
|
|
3
3
|
export declare class StandardJsonSchemaValidator<Input extends StandardJSONSchemaV1 & StandardSchemaV1, Output extends unknown = StandardSchemaV1.InferOutput<Input>> extends Validator<Input, Output> {
|
|
4
4
|
private readonly input;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from '
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Validator, type TErrorOptions, type TErrorResult } from '../../validator.mjs';
|
|
3
3
|
export declare class StandardSchemaValidator<Input extends StandardSchemaV1, Output extends unknown = StandardSchemaV1.InferOutput<Input>> extends Validator<Input, Output> {
|
|
4
4
|
private readonly input;
|
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.
|
|
4
|
+
"version": "0.8.10",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"json-schema",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"url": "https://github.com/sinclairzx81/typedriver"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"
|
|
17
|
+
"@standard-schema/spec": "1.1.0",
|
|
18
|
+
"typebox": "^1.0.64"
|
|
18
19
|
},
|
|
19
20
|
"type": "module",
|
|
20
21
|
"types": "./build/index.d.mts",
|
package/readme.md
CHANGED
|
@@ -423,7 +423,7 @@ type T = Static<typeof T> // type T = number
|
|
|
423
423
|
|
|
424
424
|
## Accelerate
|
|
425
425
|
|
|
426
|
-
TypeDriver provides acceleration support for libraries that implement the
|
|
426
|
+
TypeDriver provides acceleration support for libraries that implement the Standard JSON Schema specification.
|
|
427
427
|
|
|
428
428
|
```bash
|
|
429
429
|
$ deno task bench
|
|
@@ -440,20 +440,17 @@ const Vector3 = compile(`{
|
|
|
440
440
|
Accelerated Indicates Support for Standard JSON Schema
|
|
441
441
|
|
|
442
442
|
```bash
|
|
443
|
-
|
|
444
|
-
│ (idx) │ iterations │ accelerated │
|
|
445
|
-
|
|
446
|
-
│ typescript │ 16000000 │ true │ "
|
|
447
|
-
│ jsonschema │ 16000000 │ true │ "
|
|
448
|
-
│
|
|
449
|
-
│
|
|
450
|
-
│
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
└────────────┴────────────┴─────────────┴──────────────┴──────────────┴─────────────────┘
|
|
455
|
-
|
|
456
|
-
Last Run: Thu Dec 04 2025
|
|
443
|
+
┌────────────┬────────────┬─────────────┬────────────────┬───────────────┬──────────────┐
|
|
444
|
+
│ (idx) │ iterations │ accelerated │ standard (...) │ compile (...) │ performance │
|
|
445
|
+
├────────────┼────────────┼─────────────┼────────────────┼───────────────┼──────────────┤
|
|
446
|
+
│ typescript │ 16000000 │ true │ " 30 ms" │ " 29 ms" │ " 1.02 ×" │
|
|
447
|
+
│ jsonschema │ 16000000 │ true │ " 29 ms" │ " 29 ms" │ " 1.00 ×" │
|
|
448
|
+
│ zod │ 16000000 │ true │ " 571 ms" │ " 28 ms" │ " 20.43 ×" │
|
|
449
|
+
│ arktype │ 16000000 │ true │ " 483 ms" │ " 30 ms" │ " 16.10 ×" │
|
|
450
|
+
│ valibot │ 16000000 │ true │ " 3239 ms" │ " 28 ms" │ " 113.72 ×" │
|
|
451
|
+
└────────────┴────────────┴─────────────┴────────────────┴───────────────┴──────────────┘
|
|
452
|
+
|
|
453
|
+
Last Run: Sat Dec 20 2025
|
|
457
454
|
```
|
|
458
455
|
|
|
459
456
|
## Compression
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
2
|
-
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
3
|
-
/** The Standard properties. */
|
|
4
|
-
readonly '~standard': StandardTypedV1.Props<Input, Output>;
|
|
5
|
-
}
|
|
6
|
-
export declare namespace StandardTypedV1 {
|
|
7
|
-
/** The Standard Typed properties interface. */
|
|
8
|
-
export interface Props<Input = unknown, Output = Input> {
|
|
9
|
-
/** The version number of the standard. */
|
|
10
|
-
readonly version: 1;
|
|
11
|
-
/** The vendor name of the schema library. */
|
|
12
|
-
readonly vendor: string;
|
|
13
|
-
/** Inferred types associated with the schema. */
|
|
14
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
15
|
-
}
|
|
16
|
-
/** The Standard Typed types interface. */
|
|
17
|
-
export interface Types<Input = unknown, Output = Input> {
|
|
18
|
-
/** The input type of the schema. */
|
|
19
|
-
readonly input: Input;
|
|
20
|
-
/** The output type of the schema. */
|
|
21
|
-
readonly output: Output;
|
|
22
|
-
}
|
|
23
|
-
/** Infers the input type of a Standard Typed. */
|
|
24
|
-
export type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
25
|
-
/** Infers the output type of a Standard Typed. */
|
|
26
|
-
export type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
27
|
-
export {};
|
|
28
|
-
}
|
|
29
|
-
/** The Standard Schema interface. */
|
|
30
|
-
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
31
|
-
/** The Standard Schema properties. */
|
|
32
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
33
|
-
}
|
|
34
|
-
export declare namespace StandardSchemaV1 {
|
|
35
|
-
/** The Standard Schema properties interface. */
|
|
36
|
-
export interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
37
|
-
/** Validates unknown input values. */
|
|
38
|
-
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
39
|
-
}
|
|
40
|
-
/** The result interface of the validate function. */
|
|
41
|
-
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
42
|
-
/** The result interface if validation succeeds. */
|
|
43
|
-
export interface SuccessResult<Output> {
|
|
44
|
-
/** The typed output value. */
|
|
45
|
-
readonly value: Output;
|
|
46
|
-
/** A falsy value for `issues` indicates success. */
|
|
47
|
-
readonly issues?: undefined;
|
|
48
|
-
}
|
|
49
|
-
export interface Options {
|
|
50
|
-
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
51
|
-
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
52
|
-
}
|
|
53
|
-
/** The result interface if validation fails. */
|
|
54
|
-
export interface FailureResult {
|
|
55
|
-
/** The issues of failed validation. */
|
|
56
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
57
|
-
}
|
|
58
|
-
/** The issue interface of the failure output. */
|
|
59
|
-
export interface Issue {
|
|
60
|
-
/** The error message of the issue. */
|
|
61
|
-
readonly message: string;
|
|
62
|
-
/** The path of the issue, if any. */
|
|
63
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
64
|
-
}
|
|
65
|
-
/** The path segment interface of the issue. */
|
|
66
|
-
export interface PathSegment {
|
|
67
|
-
/** The key representing a path segment. */
|
|
68
|
-
readonly key: PropertyKey;
|
|
69
|
-
}
|
|
70
|
-
/** The Standard types interface. */
|
|
71
|
-
export interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
72
|
-
}
|
|
73
|
-
/** Infers the input type of a Standard. */
|
|
74
|
-
export type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
75
|
-
/** Infers the output type of a Standard. */
|
|
76
|
-
export type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
77
|
-
export {};
|
|
78
|
-
}
|
|
79
|
-
/** The Standard JSON Schema interface. */
|
|
80
|
-
export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
81
|
-
/** The Standard JSON Schema properties. */
|
|
82
|
-
readonly '~standard': StandardJSONSchemaV1.Props<Input, Output>;
|
|
83
|
-
}
|
|
84
|
-
export declare namespace StandardJSONSchemaV1 {
|
|
85
|
-
/** The Standard JSON Schema properties interface. */
|
|
86
|
-
export interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
87
|
-
/** Methods for generating the input/output JSON Schema. */
|
|
88
|
-
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
89
|
-
}
|
|
90
|
-
/** The Standard JSON Schema converter interface. */
|
|
91
|
-
export interface Converter {
|
|
92
|
-
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
93
|
-
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
94
|
-
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
95
|
-
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The target version of the generated JSON Schema.
|
|
99
|
-
*
|
|
100
|
-
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
101
|
-
*
|
|
102
|
-
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
103
|
-
*/
|
|
104
|
-
export type Target = 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | ({} & string);
|
|
105
|
-
/** The options for the input/output methods. */
|
|
106
|
-
export interface Options {
|
|
107
|
-
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
108
|
-
readonly target: Target;
|
|
109
|
-
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
110
|
-
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
111
|
-
}
|
|
112
|
-
/** The Standard types interface. */
|
|
113
|
-
export interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
114
|
-
}
|
|
115
|
-
/** Infers the input type of a Standard. */
|
|
116
|
-
export type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
117
|
-
/** Infers the output type of a Standard. */
|
|
118
|
-
export type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
119
|
-
export {};
|
|
120
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|