typedriver 0.8.4 → 0.8.5

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.
Files changed (37) hide show
  1. package/build/compile.mjs +4 -4
  2. package/build/errors/error-to-issue.d.mts +3 -0
  3. package/build/errors/error-to-issue.mjs +14 -0
  4. package/build/{errors.d.mts → errors/exceptions.d.mts} +6 -1
  5. package/build/{errors.mjs → errors/exceptions.mjs} +8 -1
  6. package/build/errors/index.d.mts +3 -0
  7. package/build/errors/index.mjs +4 -0
  8. package/build/errors/issue-to-error.d.mts +3 -0
  9. package/build/errors/issue-to-error.mjs +20 -0
  10. package/build/index.d.mts +3 -4
  11. package/build/index.mjs +8 -4
  12. package/build/validator.d.mts +32 -1
  13. package/build/validator.mjs +17 -0
  14. package/build/validators/json-schema/validator.d.mts +14 -0
  15. package/build/{json-schema → validators/json-schema}/validator.mjs +12 -23
  16. package/build/{standard-json-schema → validators/standard-json-schema}/resolve.d.mts +1 -1
  17. package/build/{standard-json-schema → validators/standard-json-schema}/resolve.mjs +1 -0
  18. package/build/validators/standard-json-schema/validator.d.mts +14 -0
  19. package/build/{standard-json-schema → validators/standard-json-schema}/validator.mjs +12 -18
  20. package/build/{standard-schema → validators/standard-schema}/validator.d.mts +3 -3
  21. package/build/{standard-schema → validators/standard-schema}/validator.mjs +10 -8
  22. package/build/{typescript → validators/typescript}/validator.d.mts +2 -2
  23. package/build/{typescript → validators/typescript}/validator.mjs +12 -6
  24. package/package.json +6 -27
  25. package/readme.md +103 -55
  26. package/build/json-schema/index.d.mts +0 -1
  27. package/build/json-schema/index.mjs +0 -1
  28. package/build/json-schema/validator.d.mts +0 -31
  29. package/build/locale.d.mts +0 -6
  30. package/build/locale.mjs +0 -7
  31. package/build/standard-json-schema/index.d.mts +0 -1
  32. package/build/standard-json-schema/index.mjs +0 -1
  33. package/build/standard-json-schema/validator.d.mts +0 -26
  34. package/build/standard-schema/index.d.mts +0 -1
  35. package/build/standard-schema/index.mjs +0 -1
  36. package/build/typescript/index.d.mts +0 -1
  37. package/build/typescript/index.mjs +0 -1
package/build/compile.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { IsJsonSchema, IsStandardSchemaV1, IsStandardJsonSchemaV1, IsTypeScript } from './guard/index.mjs';
3
- import { JsonSchemaValidator } from './json-schema/validator.mjs';
4
- import { StandardJsonSchemaValidator } from './standard-json-schema/validator.mjs';
5
- import { StandardSchemaValidator } from './standard-schema/validator.mjs';
6
- import { TypeScriptValidator } from './typescript/validator.mjs';
3
+ import { JsonSchemaValidator } from './validators/json-schema/validator.mjs';
4
+ import { StandardJsonSchemaValidator } from './validators/standard-json-schema/validator.mjs';
5
+ import { StandardSchemaValidator } from './validators/standard-schema/validator.mjs';
6
+ import { TypeScriptValidator } from './validators/typescript/validator.mjs';
7
7
  function FromStandardSchema(schema) {
8
8
  return new StandardSchemaValidator(schema);
9
9
  }
@@ -0,0 +1,3 @@
1
+ import { StandardSchemaV1 } from '../_standard/standard-schema.mjs';
2
+ import { TLocalizedValidationError } from 'typebox/error';
3
+ export declare function errorToIssue(error: TLocalizedValidationError): StandardSchemaV1.Issue;
@@ -0,0 +1,14 @@
1
+ // deno-fmt-ignore-file
2
+ import { Guard } from 'typebox/guard';
3
+ // ------------------------------------------------------------------
4
+ // Issues
5
+ // ------------------------------------------------------------------
6
+ function pathSegments(pointer) {
7
+ if (Guard.IsEqual(pointer.length, 0))
8
+ return [];
9
+ return pointer.slice(1).split('/').map((segment) => segment.replace(/~1/g, '/').replace(/~0/g, '~'));
10
+ }
11
+ export function errorToIssue(error) {
12
+ const path = pathSegments(error.instancePath);
13
+ return { path, message: error.message };
14
+ }
@@ -1,6 +1,11 @@
1
1
  export declare class ParseError extends globalThis.Error {
2
+ value: unknown;
2
3
  readonly errors: object[];
3
- constructor(errors: object[]);
4
+ readonly cause: {
5
+ errors: object[];
6
+ value: unknown;
7
+ };
8
+ constructor(value: unknown, errors: object[]);
4
9
  }
5
10
  export declare class UnknownError extends globalThis.Error {
6
11
  constructor(message: string);
@@ -1,8 +1,15 @@
1
1
  // deno-fmt-ignore-file
2
2
  export class ParseError extends globalThis.Error {
3
- constructor(errors) {
3
+ constructor(value, errors) {
4
4
  super('ParseError');
5
+ this.value = value;
5
6
  this.errors = errors;
7
+ Object.defineProperty(this, 'cause', {
8
+ value: { errors, value },
9
+ writable: false,
10
+ configurable: false,
11
+ enumerable: false
12
+ });
6
13
  }
7
14
  }
8
15
  export class UnknownError extends globalThis.Error {
@@ -0,0 +1,3 @@
1
+ export * from './exceptions.mjs';
2
+ export * from './error-to-issue.mjs';
3
+ export * from './issue-to-error.mjs';
@@ -0,0 +1,4 @@
1
+ // deno-fmt-ignore-file
2
+ export * from './exceptions.mjs';
3
+ export * from './error-to-issue.mjs';
4
+ export * from './issue-to-error.mjs';
@@ -0,0 +1,3 @@
1
+ import { StandardSchemaV1 } from '../_standard/standard-schema.mjs';
2
+ import { TLocalizedValidationError } from 'typebox/error';
3
+ export declare function issueToError(issue: StandardSchemaV1.Issue): TLocalizedValidationError;
@@ -0,0 +1,20 @@
1
+ // deno-fmt-ignore-file
2
+ import { Guard } from 'typebox/guard';
3
+ // ------------------------------------------------------------------
4
+ // Issues
5
+ // ------------------------------------------------------------------
6
+ function jsonPointer(segments) {
7
+ return `#${segments.join('/')}`;
8
+ }
9
+ export function issueToError(issue) {
10
+ const instancePath = Guard.HasPropertyKey(issue, 'path') && Guard.IsArray(issue.path)
11
+ ? jsonPointer(issue.path)
12
+ : jsonPointer([]);
13
+ return {
14
+ instancePath,
15
+ schemaPath: '#',
16
+ keyword: 'type',
17
+ message: issue.message,
18
+ params: { type: 'standard-schema' }
19
+ };
20
+ }
package/build/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './locale.mjs';
2
- export * from './compile.mjs';
3
- export * from './validator.mjs';
4
- export * from './static.mjs';
1
+ export { type TCompile, compile } from './compile.mjs';
2
+ export { type Static } from './static.mjs';
3
+ export { Validator, type TErrorFormat, type TErrorLocale, type TErrorOptions, type TErrorResult } from './validator.mjs';
package/build/index.mjs CHANGED
@@ -1,5 +1,9 @@
1
1
  // deno-fmt-ignore-file
2
- export * from './locale.mjs';
3
- export * from './compile.mjs';
4
- export * from './validator.mjs';
5
- export * from './static.mjs';
2
+ // ------------------------------------------------------------------
3
+ // Compile
4
+ // ------------------------------------------------------------------
5
+ export { compile } from './compile.mjs';
6
+ // ------------------------------------------------------------------
7
+ // Validator
8
+ // ------------------------------------------------------------------
9
+ export { Validator } from './validator.mjs';
@@ -1,3 +1,33 @@
1
+ import { System } from 'typebox/system';
2
+ import { TLocalizedValidationError } from 'typebox/error';
3
+ import { StandardSchemaV1 } from './_standard/standard-schema.mjs';
4
+ export type TErrorFormat = 'json-schema' | 'standard-schema';
5
+ declare const Locale: typeof System.Locale;
6
+ export type TErrorLocale = (Exclude<keyof typeof Locale, 'Get' | 'Set' | 'Reset'> & ({} & string));
7
+ /** Internal */
8
+ export declare function resolveErrorOptions(options?: Partial<TErrorOptions>): TErrorOptions;
9
+ export interface TErrorOptions {
10
+ /**
11
+ * Specifies the error message generation format.
12
+ *
13
+ * Supported values are `json-schema` and `standard-schema`.
14
+ *
15
+ * Default: `json-schema`
16
+ */
17
+ format: TErrorFormat;
18
+ /**
19
+ * Specifies the locale used when generating error messages.
20
+ *
21
+ * This setting applies only when used with TypeScript, JSON Schema,
22
+ * or implementations that follow the Standard JSON Schema specification.
23
+ * When the compiled type is Standard Schema only, the error message
24
+ * will be whatever is returned from that library.
25
+ *
26
+ * Default: `en_US`
27
+ */
28
+ locale: TErrorLocale;
29
+ }
30
+ export type TErrorResult<Options extends Partial<TErrorOptions>> = (Options['format'] extends 'standard-schema' ? StandardSchemaV1.Issue[] : TLocalizedValidationError[]);
1
31
  /** Abstract Base for all Validator types. */
2
32
  export declare abstract class Validator<Input extends unknown = unknown, Output extends unknown = unknown> {
3
33
  /** Returns the schema used to construct this validator */
@@ -7,7 +37,7 @@ export declare abstract class Validator<Input extends unknown = unknown, Output
7
37
  /** Parses a value and throws if invalid */
8
38
  abstract parse(value: unknown): Output;
9
39
  /** Returns errors for the given value */
10
- abstract errors(value: unknown): object[];
40
+ abstract errors<Options extends Partial<TErrorOptions>>(value: unknown, options?: Options): TErrorResult<Options>;
11
41
  /** True if the validator has a Json Schema representation */
12
42
  abstract isJsonSchema(): boolean;
13
43
  /** Return the validator Json Schema representation. */
@@ -15,3 +45,4 @@ export declare abstract class Validator<Input extends unknown = unknown, Output
15
45
  /** Returns true if this validator is JIT accelerated */
16
46
  abstract isAccelerated(): boolean;
17
47
  }
48
+ export {};
@@ -1,4 +1,21 @@
1
1
  // deno-fmt-ignore-file
2
+ import { System } from 'typebox/system';
3
+ // ------------------------------------------------------------------
4
+ // TErrorLocale
5
+ // ------------------------------------------------------------------
6
+ const Locale = System.Locale;
7
+ // ------------------------------------------------------------------
8
+ // TErrorOptions
9
+ // ------------------------------------------------------------------
10
+ /** Internal */
11
+ export function resolveErrorOptions(options) {
12
+ const defaults = { format: 'json-schema', locale: 'en_US' };
13
+ const resolved = options ?? {};
14
+ return { ...defaults, ...resolved };
15
+ }
16
+ // ------------------------------------------------------------------
17
+ // Validator
18
+ // ------------------------------------------------------------------
2
19
  /** Abstract Base for all Validator types. */
3
20
  export class Validator {
4
21
  }
@@ -0,0 +1,14 @@
1
+ import { Validator, type TErrorOptions, type TErrorResult } from '../../validator.mjs';
2
+ import Type from 'typebox';
3
+ export declare class JsonSchemaValidator<Input extends Type.TSchema, Output extends unknown = Type.Static<Input>> extends Validator<Input, Output> {
4
+ private readonly input;
5
+ private readonly validator;
6
+ constructor(input: Input);
7
+ schema(): Input;
8
+ isJsonSchema(): boolean;
9
+ toJsonSchema(): unknown;
10
+ isAccelerated(): boolean;
11
+ check(value: unknown): value is Output;
12
+ parse(value: unknown): Output;
13
+ errors<Options extends Partial<TErrorOptions>>(value: unknown, options?: Options): TErrorResult<Options>;
14
+ }
@@ -1,24 +1,8 @@
1
1
  // deno-fmt-ignore-file
2
+ import { System } from 'typebox/system';
2
3
  import { Validator as TBValidator } from 'typebox/compile';
3
- import { ParseError } from '../errors.mjs';
4
- import { Validator } from '../validator.mjs';
5
- /**
6
- * High-performance Json Schema validator that uses library-specific
7
- * inference mechanisms. The validator assumes the source library
8
- * produces accurate schematics that encode the runtime
9
- * representations of its types.
10
- *
11
- * In TypeBox terminology, this falls under the TUnsafe<T> category.
12
- * Preferably, TypeScript types "should" be derived from the
13
- * schematics rather than assumed.
14
- *
15
- * Note:
16
- *
17
- * Standard JSON Schema does not advertise which Draft versions it
18
- * supports, and the resolver is using try/catch resolution. This
19
- * should be brought up in RFC feedback, not by me of course, I don't
20
- * know anything about Json Schema.
21
- */
4
+ import { ParseError, errorToIssue } from '../../errors/index.mjs';
5
+ import { Validator, resolveErrorOptions } from '../../validator.mjs';
22
6
  export class JsonSchemaValidator extends Validator {
23
7
  constructor(input) {
24
8
  super();
@@ -41,7 +25,7 @@ export class JsonSchemaValidator extends Validator {
41
25
  return this.input;
42
26
  }
43
27
  // ----------------------------------------------------------------
44
- // Accelerated
28
+ // Acceleration
45
29
  // ----------------------------------------------------------------
46
30
  isAccelerated() {
47
31
  return this.validator.IsEvaluated();
@@ -54,10 +38,15 @@ export class JsonSchemaValidator extends Validator {
54
38
  }
55
39
  parse(value) {
56
40
  if (!this.validator.Check(value))
57
- throw new ParseError(this.errors(value));
41
+ throw new ParseError(value, this.errors(value));
58
42
  return value;
59
43
  }
60
- errors(value) {
61
- return this.validator.Errors(value);
44
+ errors(value, options) {
45
+ const config = resolveErrorOptions(options);
46
+ System.Locale.Set(System.Locale[config.locale]);
47
+ const errors = this.validator.Errors(value);
48
+ return (config.format === 'standard-schema'
49
+ ? errors.map(error => errorToIssue(error))
50
+ : errors);
62
51
  }
63
52
  }
@@ -1,2 +1,2 @@
1
- import { StandardJSONSchemaV1 } from '../_standard/standard-schema.mjs';
1
+ import { StandardJSONSchemaV1 } from '../../_standard/standard-schema.mjs';
2
2
  export declare function ResolveJsonSchema(input: StandardJSONSchemaV1): Record<string, unknown>;
@@ -24,6 +24,7 @@ function AsDraft2020_12(input) {
24
24
  return undefined;
25
25
  }
26
26
  }
27
+ // Why doesn't the api provide a discovery mechanism?
27
28
  export function ResolveJsonSchema(input) {
28
29
  const jsonschema = AsDraft2020_12(input) ?? AsDraft7(input) ?? AsOpenAPI3_0(input);
29
30
  if (Guard.IsUndefined(jsonschema))
@@ -0,0 +1,14 @@
1
+ import { StandardJSONSchemaV1, StandardSchemaV1 } from '../../_standard/standard-schema.mjs';
2
+ import { Validator, type TErrorOptions, type TErrorResult } from '../../validator.mjs';
3
+ export declare class StandardJsonSchemaValidator<Input extends StandardJSONSchemaV1 & StandardSchemaV1, Output extends unknown = StandardSchemaV1.InferOutput<Input>> extends Validator<Input, Output> {
4
+ private readonly input;
5
+ private readonly validator;
6
+ constructor(input: Input);
7
+ schema(): Input;
8
+ isJsonSchema(): boolean;
9
+ toJsonSchema(): unknown;
10
+ isAccelerated(): boolean;
11
+ check(value: unknown): value is Output;
12
+ parse(value: unknown): Output;
13
+ errors<Options extends Partial<TErrorOptions>>(value: unknown, options?: Options): TErrorResult<Options>;
14
+ }
@@ -1,20 +1,9 @@
1
1
  // deno-fmt-ignore-file
2
- import { ParseError } from '../errors.mjs';
3
- import { Validator } from '../validator.mjs';
2
+ import { System } from 'typebox/system';
3
+ import { Validator, resolveErrorOptions } from '../../validator.mjs';
4
+ import { ParseError, errorToIssue } from '../../errors/index.mjs';
4
5
  import { Validator as TBValidator } from 'typebox/compile';
5
6
  import { ResolveJsonSchema } from './resolve.mjs';
6
- /**
7
- * High-performance Json Schema validator that uses library-specific
8
- * inference mechanisms. The validator assumes the source library
9
- * produces accurate schematics that encode the runtime
10
- * representations of its types.
11
- *
12
- * Note:
13
- *
14
- * Standard JSON Schema does not advertise which Draft versions it
15
- * supports, and the resolver is using try/catch resolution. This
16
- * should be brought up in RFC feedback.
17
- */
18
7
  export class StandardJsonSchemaValidator extends Validator {
19
8
  constructor(input) {
20
9
  super();
@@ -38,7 +27,7 @@ export class StandardJsonSchemaValidator extends Validator {
38
27
  return this.validator.Type();
39
28
  }
40
29
  // ----------------------------------------------------------------
41
- // Accelerated
30
+ // Acceleration
42
31
  // ----------------------------------------------------------------
43
32
  isAccelerated() {
44
33
  return this.validator.IsEvaluated();
@@ -51,10 +40,15 @@ export class StandardJsonSchemaValidator extends Validator {
51
40
  }
52
41
  parse(value) {
53
42
  if (!this.validator.Check(value))
54
- throw new ParseError(this.errors(value));
43
+ throw new ParseError(value, this.errors(value));
55
44
  return value;
56
45
  }
57
- errors(value) {
58
- return this.validator.Errors(value);
46
+ errors(value, options) {
47
+ const config = resolveErrorOptions(options);
48
+ System.Locale.Set(System.Locale[config.locale]);
49
+ const errors = this.validator.Errors(value);
50
+ return (config.format === 'standard-schema'
51
+ ? errors.map(error => errorToIssue(error))
52
+ : errors);
59
53
  }
60
54
  }
@@ -1,5 +1,5 @@
1
- import { StandardSchemaV1 } from '../_standard/standard-schema.mjs';
2
- import { Validator } from '../validator.mjs';
1
+ import { StandardSchemaV1 } from '../../_standard/standard-schema.mjs';
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;
5
5
  constructor(input: Input);
@@ -9,5 +9,5 @@ export declare class StandardSchemaValidator<Input extends StandardSchemaV1, Out
9
9
  isAccelerated(): boolean;
10
10
  check(value: unknown): value is Output;
11
11
  parse(value: unknown): Output;
12
- errors(value: unknown): object[];
12
+ errors<Options extends Partial<TErrorOptions>>(value: unknown, options?: Options): TErrorResult<Options>;
13
13
  }
@@ -1,6 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
- import { ParseError, UnknownError } from '../errors.mjs';
3
- import { Validator } from '../validator.mjs';
2
+ import { ParseError, UnknownError, issueToError } from '../../errors/index.mjs';
3
+ import { Validator, resolveErrorOptions } from '../../validator.mjs';
4
4
  export class StandardSchemaValidator extends Validator {
5
5
  constructor(input) {
6
6
  super();
@@ -22,7 +22,7 @@ export class StandardSchemaValidator extends Validator {
22
22
  return {};
23
23
  }
24
24
  // ----------------------------------------------------------------
25
- // Accelerated
25
+ // Acceleration
26
26
  // ----------------------------------------------------------------
27
27
  isAccelerated() {
28
28
  return false;
@@ -37,15 +37,17 @@ export class StandardSchemaValidator extends Validator {
37
37
  parse(value) {
38
38
  const result = this.input['~standard'].validate(value);
39
39
  if ('issues' in result)
40
- throw new ParseError(result.issues || []);
40
+ throw new ParseError(value, result.issues ?? []);
41
41
  if ('value' in result)
42
42
  return result.value;
43
43
  throw new UnknownError('Invalid result');
44
44
  }
45
- errors(value) {
45
+ errors(value, options) {
46
46
  const result = this.input['~standard'].validate(value);
47
- if ('issues' in result)
48
- return result.issues || [];
49
- return [];
47
+ const issues = (('issues' in result) ? result.issues : []);
48
+ const config = resolveErrorOptions(options);
49
+ return (config.format === 'json-schema'
50
+ ? issues.map(issue => issueToError(issue))
51
+ : issues.map(issue => ({ path: issue.path, message: issue.message })));
50
52
  }
51
53
  }
@@ -1,4 +1,4 @@
1
- import { Validator } from '../validator.mjs';
1
+ import { Validator, type TErrorOptions, type TErrorResult } from '../../validator.mjs';
2
2
  import Type from 'typebox';
3
3
  export declare class TypeScriptValidator<Input extends string, Schema extends Type.TSchema = Type.TScript<{}, Input>, Output extends unknown = Type.Static<Schema>> extends Validator<Input, Output> {
4
4
  private readonly validator;
@@ -11,5 +11,5 @@ export declare class TypeScriptValidator<Input extends string, Schema extends Ty
11
11
  isAccelerated(): boolean;
12
12
  check(value: unknown): value is Output;
13
13
  parse(value: unknown): Output;
14
- errors(value: unknown): object[];
14
+ errors<Options extends Partial<TErrorOptions>>(value: unknown, options?: Options): TErrorResult<Options>;
15
15
  }
@@ -1,7 +1,8 @@
1
1
  // deno-fmt-ignore-file
2
+ import { System } from 'typebox/system';
2
3
  import { Validator as TBValidator } from 'typebox/compile';
3
- import { Validator } from '../validator.mjs';
4
- import { ParseError } from '../errors.mjs';
4
+ import { ParseError, errorToIssue } from '../../errors/index.mjs';
5
+ import { Validator, resolveErrorOptions } from '../../validator.mjs';
5
6
  import Type from 'typebox';
6
7
  export class TypeScriptValidator extends Validator {
7
8
  constructor(script) {
@@ -26,7 +27,7 @@ export class TypeScriptValidator extends Validator {
26
27
  return this.jsonschema;
27
28
  }
28
29
  // ----------------------------------------------------------------
29
- // Accelerated
30
+ // Acceleration
30
31
  // ----------------------------------------------------------------
31
32
  isAccelerated() {
32
33
  return this.validator.IsEvaluated();
@@ -39,10 +40,15 @@ export class TypeScriptValidator extends Validator {
39
40
  }
40
41
  parse(value) {
41
42
  if (!this.validator.Check(value))
42
- throw new ParseError(this.errors(value));
43
+ throw new ParseError(value, this.errors(value));
43
44
  return value;
44
45
  }
45
- errors(value) {
46
- return this.validator.Errors(value);
46
+ errors(value, options) {
47
+ const config = resolveErrorOptions(options);
48
+ System.Locale.Set(System.Locale[config.locale]);
49
+ const errors = this.validator.Errors(value);
50
+ return (config.format === 'standard-schema'
51
+ ? errors.map(error => errorToIssue(error))
52
+ : errors);
47
53
  }
48
54
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typedriver",
3
3
  "description": "Unified Runtime Validation and Inference Driver for TypeScript",
4
- "version": "0.8.4",
4
+ "version": "0.8.5",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "json-schema",
@@ -20,25 +20,13 @@
20
20
  "types": "./build/index.d.mts",
21
21
  "module": "./build/index.mjs",
22
22
  "exports": {
23
- "./standard-schema": {
24
- "import": "./build/standard-schema/index.mjs",
25
- "default": "./build/standard-schema/index.mjs"
26
- },
27
23
  "./guard": {
28
24
  "import": "./build/guard/index.mjs",
29
25
  "default": "./build/guard/index.mjs"
30
26
  },
31
- "./json-schema": {
32
- "import": "./build/json-schema/index.mjs",
33
- "default": "./build/json-schema/index.mjs"
34
- },
35
- "./standard-json-schema": {
36
- "import": "./build/standard-json-schema/index.mjs",
37
- "default": "./build/standard-json-schema/index.mjs"
38
- },
39
- "./typescript": {
40
- "import": "./build/typescript/index.mjs",
41
- "default": "./build/typescript/index.mjs"
27
+ "./errors": {
28
+ "import": "./build/errors/index.mjs",
29
+ "default": "./build/errors/index.mjs"
42
30
  },
43
31
  ".": {
44
32
  "import": "./build/index.mjs",
@@ -47,20 +35,11 @@
47
35
  },
48
36
  "typesVersions": {
49
37
  "*": {
50
- "standard-schema": [
51
- "./build/standard-schema/index.d.mts"
52
- ],
53
38
  "guard": [
54
39
  "./build/guard/index.d.mts"
55
40
  ],
56
- "json-schema": [
57
- "./build/json-schema/index.d.mts"
58
- ],
59
- "standard-json-schema": [
60
- "./build/standard-json-schema/index.d.mts"
61
- ],
62
- "typescript": [
63
- "./build/typescript/index.d.mts"
41
+ "errors": [
42
+ "./build/errors/index.d.mts"
64
43
  ],
65
44
  ".": [
66
45
  "./build/index.d.mts"
package/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <h1>TypeDriver</h1>
4
4
 
5
- <p>Integration Middlware for High Performance Runtime Validation</p>
5
+ <p>Integration Middleware for High Performance Runtime Validation</p>
6
6
 
7
7
  <img src="typedriver.png" />
8
8
 
@@ -58,14 +58,15 @@ License MIT
58
58
 
59
59
  ## Features
60
60
 
61
- - Designed Specifically for Framework Integration
62
- - Integrated TypeScript DSL for TS7 Native (supported in TS5 and above)
61
+ - Built Specifically for Framework Integration
62
+ - TypeScript DSL for TS7 Native (supported in TS5 and above)
63
63
  - Unified Validation for JSON Schema and Standard Schema
64
64
  - Unified Inference for JSON Schema and Standard Schema
65
65
  - High Performance Validation Compiler (performance approx 2x Ajv)
66
66
  - Acceleration support for Standard JSON Schema
67
67
  - JSON Schema Reflect for OpenAPI, MCP and IDL Based Systems
68
- - Localization Support for 40+ languages
68
+ - Error Formats for JSON Schema and Standard Schema Based Reporting
69
+ - Error Message Localization (i18n)
69
70
 
70
71
  ## Contents
71
72
 
@@ -76,20 +77,20 @@ License MIT
76
77
  - [Check](#Check)
77
78
  - [Parse](#Parse)
78
79
  - [Errors](#Errors)
80
+ - [Locales](#Locales)
79
81
  - [Static](#Static)
80
82
  - [Reflect](#Schema)
81
- - [Locale](#Locale)
82
83
  - [Accelerate](#Accelerate)
83
84
  - [Contribute](#Contribute)
84
85
 
85
86
  ## Framework
86
87
 
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 ...
88
+ TypeDriver is designed for framework integration. It provides a simple infrastructure to connect type inference and validation to framework interfaces.
88
89
 
89
90
  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)
90
91
 
91
92
  ```typescript
92
- post('/', {
93
+ route('/', {
93
94
  body: `{
94
95
  x: number,
95
96
  y: number,
@@ -100,11 +101,11 @@ post('/', {
100
101
  })
101
102
  ```
102
103
 
103
- Where the above design is achieved with the following TS definitions (Expand to View)
104
+ Where the above interface design is achieved with the following TS definitions
104
105
 
105
106
  <details>
106
107
 
107
- <summary>TypeDriver Route Definition</summary>
108
+ <summary>Route Interface Definition (Expand)</summary>
108
109
 
109
110
 
110
111
  ```typescript
@@ -116,7 +117,7 @@ export interface RouteOptions<Body extends unknown = unknown> {
116
117
  export type RouteCallback<Path extends string, Options extends RouteOptions> = (
117
118
  (request: { url: Path, body: Static<Options['body']> }) => void
118
119
  )
119
- export function post<Path extends string, const Options extends RouteOptions,
120
+ export function route<Path extends string, const Options extends RouteOptions,
120
121
  Callback = RouteCallback<Path, Options>
121
122
  >(path: Path, options: Options, callback: Callback) {
122
123
  const body_validator = compile(options['body'])
@@ -134,7 +135,7 @@ TypeDriver consists of a single compile(...) function that accepts JSON Schema,
134
135
  import { compile } from 'typedriver'
135
136
  ```
136
137
 
137
- TypeScript [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV1AOwGd4A1LMhjQAzHAC8KNGExYAFAAMErOHAAeALjicAriABGzFXApbdBo6oBeZvYaitcCgJSq37j56-ef7gPR+Ujz8gsJQIlp8AIYYwDRRYQA8AHSpADSIxr7ZObluAW6a2nbMaVl5FZX5gaqmxRZQZVXNlQXWtg1NLd3ZBbgAfOxcvHCQ3MAwwBCcEnACQqLJYFFQ3PJIxkUADF11AIxdNnBbjs5AA)
138
+ Ref: [TypeScript](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV1AOwGd4A1LMhjQAzHAC8KNGExYAFAAMErOHAAeALjicAriABGzFXApbdBo6oBeZvYaitcCgJSq37j56-ef7gPR+Ujz8gsJQIlp8AIYYwDRRYQA8AHSpADSIxr7ZObluAW6a2nbMaVl5FZX5gaqmxRZQZVXNlQXWtg1NLd3ZBbgAfOxcvHCQ3MAwwBCcEnACQqLJYFFQ3PJIxkUADF11AIxdNnBbjs5AA)
138
139
 
139
140
  ```typescript
140
141
  const Vector3 = compile(`{
@@ -144,7 +145,7 @@ const Vector3 = compile(`{
144
145
  }`)
145
146
  ```
146
147
 
147
- JSON Schema [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV1AOwGd4A1LMhjQAzHAC8KNGExYAFEjhLlK1WtUB6DVJ79BwqCIBccPgEMMwGmYMAeAHSOANIlZLK1E6QgAjAFb6pC7qIaFhWsoAHiacAK4gPsxObnBQWACOscBpNCYA2qSRQWQUxaQAXqQAusFhdXARShQx8YlQyUpgxNSwwFjcJor1w+HaSuUtCcwpStGIcB5YXnFTLHi1I6ERuAB8M3DN84vLrcyk6-sTR1RLZCtt57gpT7gAlOxcvHCQ3MAwwBBOBJTPpRPYwGYoNx5EgUnMAAwdA4mACMSKu8NYbyAA)
148
+ Ref: [JSON Schema](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV1AOwGd4A1LMhjQAzHAC8KNGExYAFEjhLlK1WtUB6DVJ79BwqCIBccPgEMMwGmYMAeAHSOANIlZLK1E6QgAjAFb6pC7qIaFhWsoAHiacAK4gPsxObnBQWACOscBpNCYA2qSRQWQUxaQAXqQAusFhdXARShQx8YlQyUpgxNSwwFjcJor1w+HaSuUtCcwpStGIcB5YXnFTLHi1I6ERuAB8M3DN84vLrcyk6-sTR1RLZCtt57gpT7gAlOxcvHCQ3MAwwBBOBJTPpRPYwGYoNx5EgUnMAAwdA4mACMSKu8NYbyAA)
148
149
 
149
150
  ```typescript
150
151
  const Vector3 = compile({
@@ -158,7 +159,7 @@ const Vector3 = compile({
158
159
  })
159
160
  ```
160
161
 
161
- Standard Schema [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV0SWOAKjgEMAznABehYiDIiINNq1QA7QfABqWZDGgBmOAF4UaMJiwAKEQDoIAIwBW6mCaRxnL12+cB6DwaWr72gC44FX4MYBp+TSgAHnM4gBpEVmcADyCLBQBXECtmEwBKRPdiktK3Lxc0uCyc5njkuAp08xrcqAKisq7uuArnJurstvrnEWbWvMKe6dK+0SCJqFZcfPyZ9Y3e71wAPnZFZThIQWAYYAgFPWD-KC1zMH4oQVMkBqqABhHGoIBGL7G4O9lvkgA)
162
+ Ref: [Standard Schema](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuYAbApnAvnAMyjTgHIYBPMLAEymADcspSAoV0SWOAKjgEMAznABehYiDIiINNq1QA7QfABqWZDGgBmOAF4UaMJiwAKEQDoIAIwBW6mCaRxnL12+cB6DwaWr72gC44FX4MYBp+TSgAHnM4gBpEVmcADyCLBQBXECtmEwBKRPdiktK3Lxc0uCyc5njkuAp08xrcqAKisq7uuArnJurstvrnEWbWvMKe6dK+0SCJqFZcfPyZ9Y3e71wAPnZFZThIQWAYYAgFPWD-KC1zMH4oQVMkBqqABhHGoIBGL7G4O9lvkgA)
162
163
 
163
164
  ```typescript
164
165
  import * as z from 'zod'
@@ -200,14 +201,101 @@ const { x, y, z } = Vector3.parse(value)
200
201
 
201
202
  ## Errors
202
203
 
203
- The errors(...) function returns diagnostics (use only after failed check)
204
+ The errors(...) function returns error diagnostics for values (use after failed check only)
204
205
 
205
206
  ```typescript
206
- // Vector3.errors(value: unknown): object[]
207
+ // Vector3.errors(value: unknown): TLocalizedValidationError[]
207
208
 
208
209
  const errors = Vector3.errors(value)
209
210
  ```
210
211
 
212
+ The errors(...) function can generate both JSON Schema and Standard Schema error formats.
213
+
214
+ ```typescript
215
+ const errors = Vector3.errors({ x: 1, y: true }, {
216
+ format: 'json-schema'
217
+ })
218
+
219
+ const issues = Vector3.errors({ x: 1, y: true }, {
220
+ format: 'standard-schema'
221
+ })
222
+ ```
223
+
224
+ <details>
225
+
226
+ <summary>Generated Errors and Issues</summary>
227
+
228
+ ```typescript
229
+ // TLocalizedValidationError[]
230
+
231
+ const errors = [{
232
+ keyword: "required",
233
+ schemaPath: "#",
234
+ instancePath: "",
235
+ params: { requiredProperties: [ "z" ] },
236
+ message: "must have required properties z"
237
+ },
238
+ {
239
+ keyword: "type",
240
+ schemaPath: "#/properties/y",
241
+ instancePath: "/y",
242
+ params: { type: "number" },
243
+ message: "must be number"
244
+ }]
245
+
246
+ // StandardSchemaV1.Issue[]
247
+
248
+ const issues = [
249
+ { path: [], message: "must have required properties z" },
250
+ { path: [ "y" ], message: "must be number" }
251
+ ]
252
+ ```
253
+ </details>
254
+
255
+ ## Locales
256
+
257
+ TypeDriver has translations for many different languages and locales.
258
+
259
+ ```typescript
260
+ const issues = Vector3.errors({ x: 1, y: true }, {
261
+ format: 'standard-schema',
262
+ locale: 'ko_KR'
263
+ })
264
+ ```
265
+
266
+ <details>
267
+
268
+ <summary>Generated Localization</summary>
269
+
270
+ ```typescript
271
+
272
+ // StandardSchemaV1.Issue[]
273
+
274
+ const issues = [
275
+ { path: [], message: "필수 속성 z을(를) 가지고 있어야 합니다" },
276
+ { path: [ "y" ], message: "number이어야 합니다" }
277
+ ]
278
+ ```
279
+ </details>
280
+
281
+ <details>
282
+
283
+ <summary>Supported Locales</summary>
284
+
285
+ ```typescript
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
+ )
294
+ ```
295
+ </details>
296
+
297
+ Localization support is only available for JSON Schema
298
+
211
299
  ## Static
212
300
 
213
301
  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)
@@ -274,46 +362,6 @@ The source type used for compilation can also be returned via
274
362
  validator.schema() // will return the schematic used for compile.
275
363
  ```
276
364
 
277
- ## Locale
278
-
279
- TypeDriver provides (i18n) error message translations for many languages and locales. Locales are defined as [IETF BCP 47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) localization codes. Additional localizations can be submitted to the TypeBox project.
280
-
281
- ```typescript
282
- import { compile, locale } from 'typedriver'
283
-
284
- // Supported Locales
285
-
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
- )
294
-
295
- locale('en_US') // Set: English | US (Default)
296
-
297
- console.log(compile('string').errors(42)) // [{
298
- // keyword: "type",
299
- // schemaPath: "#",
300
- // instancePath: "",
301
- // params: { type: "string" },
302
- // message: "must be string"
303
- // }]
304
-
305
- locale('ko_KR') // Set: Korean | South Korea
306
-
307
- console.log(compile('string').errors(42)) // [{
308
- // keyword: "type",
309
- // schemaPath: "#",
310
- // instancePath: "",
311
- // params: { type: "string" },
312
- // message: "string이어야 합니다"
313
- // }]
314
- ```
315
- Localization support is only available for JSON Schema.
316
-
317
365
  ## Accelerate
318
366
 
319
367
  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(...).
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1,31 +0,0 @@
1
- import { Validator } from '../validator.mjs';
2
- import Type from 'typebox';
3
- /**
4
- * High-performance Json Schema validator that uses library-specific
5
- * inference mechanisms. The validator assumes the source library
6
- * produces accurate schematics that encode the runtime
7
- * representations of its types.
8
- *
9
- * In TypeBox terminology, this falls under the TUnsafe<T> category.
10
- * Preferably, TypeScript types "should" be derived from the
11
- * schematics rather than assumed.
12
- *
13
- * Note:
14
- *
15
- * Standard JSON Schema does not advertise which Draft versions it
16
- * supports, and the resolver is using try/catch resolution. This
17
- * should be brought up in RFC feedback, not by me of course, I don't
18
- * know anything about Json Schema.
19
- */
20
- export declare class JsonSchemaValidator<Input extends Type.TSchema, Output extends unknown = Type.Static<Input>> extends Validator<Input, Output> {
21
- private readonly input;
22
- private readonly validator;
23
- constructor(input: Input);
24
- schema(): Input;
25
- isJsonSchema(): boolean;
26
- toJsonSchema(): unknown;
27
- isAccelerated(): boolean;
28
- check(value: unknown): value is Output;
29
- parse(value: unknown): Output;
30
- errors(value: unknown): object[];
31
- }
@@ -1,6 +0,0 @@
1
- import { System } from 'typebox/system';
2
- declare const Locale: typeof System.Locale;
3
- type LocaleString = Exclude<keyof typeof Locale, 'Get' | 'Set' | 'Reset'> & ({} & string);
4
- /** Sets the locale for which errors are generated. */
5
- export declare function locale(locale: LocaleString): void;
6
- export {};
package/build/locale.mjs DELETED
@@ -1,7 +0,0 @@
1
- import { System } from 'typebox/system';
2
- const Locale = System.Locale;
3
- /** Sets the locale for which errors are generated. */
4
- export function locale(locale) {
5
- const F = locale in System.Locale ? System.Locale[locale] : System.Locale.en_US;
6
- System.Locale.Set(F);
7
- }
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1,26 +0,0 @@
1
- import { StandardJSONSchemaV1, StandardSchemaV1 } from '../_standard/standard-schema.mjs';
2
- import { Validator } from '../validator.mjs';
3
- /**
4
- * High-performance Json Schema validator that uses library-specific
5
- * inference mechanisms. The validator assumes the source library
6
- * produces accurate schematics that encode the runtime
7
- * representations of its types.
8
- *
9
- * Note:
10
- *
11
- * Standard JSON Schema does not advertise which Draft versions it
12
- * supports, and the resolver is using try/catch resolution. This
13
- * should be brought up in RFC feedback.
14
- */
15
- export declare class StandardJsonSchemaValidator<Input extends StandardJSONSchemaV1 & StandardSchemaV1, Output extends unknown = StandardSchemaV1.InferOutput<Input>> extends Validator<Input, Output> {
16
- private readonly input;
17
- private readonly validator;
18
- constructor(input: Input);
19
- schema(): Input;
20
- isJsonSchema(): boolean;
21
- toJsonSchema(): unknown;
22
- isAccelerated(): boolean;
23
- check(value: unknown): value is Output;
24
- parse(value: unknown): Output;
25
- errors(value: unknown): object[];
26
- }
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1 +0,0 @@
1
- export * from './validator.mjs';
@@ -1 +0,0 @@
1
- export * from './validator.mjs';