standard_schema.ts

Standard Schema support, kept out of schema.ts so schemas don't carry a ~standard property they'd pay for in bytes and in a second object shape. Wrap a schema with to_standard_schema where a library asks for one.

@see https://standardschema.dev/

view source

Declarations
#

5 declarations

StandardSchemaV1
#

standard_schema.ts view source

StandardSchemaV1<TInput, TOutput> import type {StandardSchemaV1} from '@fuzdev/fuz_schema/standard_schema.js';

The Standard Schema v1 interface, copied from the spec as it recommends so there's no dependency on @standard-schema/spec.

generics

StandardSchemaV1<TInput = unknown, TOutput = TInput>
TInput
default unknown
TOutput
default TInput

~standard

type StandardSchemaV1Props<TInput, TOutput>

readonly

StandardSchemaV1Issue
#

standard_schema.ts view source

StandardSchemaV1Issue import type {StandardSchemaV1Issue} from '@fuzdev/fuz_schema/standard_schema.js';

message

type string

readonly

path?

type readonly (PropertyKey | { readonly key: PropertyKey; })[]

readonly

StandardSchemaV1Props
#

standard_schema.ts view source

StandardSchemaV1Props<TInput, TOutput> import type {StandardSchemaV1Props} from '@fuzdev/fuz_schema/standard_schema.js';

generics

StandardSchemaV1Props<TInput = unknown, TOutput = TInput>
TInput
default unknown
TOutput
default TInput

version

type 1

readonly

vendor

type string

readonly

validate

type (value: unknown): StandardSchemaV1Result<TOutput> | Promise<StandardSchemaV1Result<TOutput>>

readonly

value

type unknown

types?

type { readonly input: TInput; readonly output: TOutput; }

readonly

StandardSchemaV1Result
#

standard_schema.ts view source

StandardSchemaV1Result<TOutput>

type { readonly value: TOutput; readonly issues?: undefined; } | { readonly issues: readonly StandardSchemaV1Issue[]; }

import type {StandardSchemaV1Result} from '@fuzdev/fuz_schema/standard_schema.js';

generics

StandardSchemaV1Result<TOutput>
TOutput

to_standard_schema
#

standard_schema.ts view source

<T extends AnySchema>(schema: T): StandardSchemaV1<InferInput<T>, Infer<T>> import {to_standard_schema} from '@fuzdev/fuz_schema/standard_schema.js';

Wraps schema in a Standard Schema, for passing to libraries that accept one. The result is not itself a Schema, so it can't be nested in other schemas.

schema

type T

returns

StandardSchemaV1<InferInput<T>, Infer<T>>

generics

to_standard_schema<T extends AnySchema>
T
constraint AnySchema

Depends on
#