Vize

standard-schema

Whether a value implements the Standard Schema v1 protocol.

Package @vizejs/composable/standard-schema
Own the source vize lib pull composable:standard-schema
Runtime exports formatSchemaPath, isStandardSchema, validateStandardSchema
Gzip budget 1024 B

Usage

import { formatSchemaPath, isStandardSchema, validateStandardSchema } from "@vizejs/composable/standard-schema";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
isStandardSchema state experimental safe not-applicable none web, server, worker, native, desktop, terminal — —
formatSchemaPath state experimental safe not-applicable none web, server, worker, native, desktop, terminal — —
validateStandardSchema state experimental safe not-applicable none web, server, worker, native, desktop, terminal — formatSchemaPath

API

isStandardSchema

Whether a value implements the Standard Schema v1 protocol.

function isStandardSchema(candidate: unknown): candidate is StandardSchemaV1

formatSchemaPath

Convert a Standard Schema issue path to a dotted path. { key } segments are unwrapped; symbols use their description.

function formatSchemaPath(path: readonly StandardSchemaPathSegment[] | undefined): string

validateStandardSchema

Validate a value with a Standard Schema and normalize the result. Synchronous and asynchronous schemas are handled identically. Throwing schemas propagate their error. Pure: safe on the server.

async function validateStandardSchema<Output>( schema: StandardSchemaV1<unknown, Output>, value: unknown, ): Promise<NormalizedSchemaResult<Output>>
const result = await validateStandardSchema(zodSchema, formValues);
if (result.status === "invalid") console.log(result.issues);

Types

StandardSchemaIssue

One validation issue reported by a Standard Schema.

Member Type Description
message string Human-readable message.
path? readonly StandardSchemaPathSegment[] | undefined Location of the issue inside the validated value; absent for root issues.

StandardSchemaSuccess

Successful Standard Schema result.

Member Type Description
value Output Parsed (possibly transformed) output.
issues? undefined Always absent on success.

StandardSchemaFailure

Failed Standard Schema result.

Member Type Description
issues readonly StandardSchemaIssue[] Non-empty list of issues.

StandardSchemaProps

The ~standard property of a Standard Schema v1 validator.

Member Type Description
version 1 Protocol version.
vendor string Library that produced the schema.
validate ( value: unknown, ) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>> Validate an unknown value, synchronously or asynchronously.
types? { readonly input: Input; readonly output: Output } | undefined Type-only carrier of the input and output types.

StandardSchemaV1

Any Standard Schema v1 validator.

Member Type Description
~standard StandardSchemaProps<Input, Output> Standard Schema protocol entry point.

NormalizedSchemaIssue

Issue normalized to a dotted path ("" for the root).

Member Type Description
path string Dotted path such as address.city or items.0.name; "" for the root.
message string Human-readable message.