Askr documentation
Generated API snapshot

@askrjs/schema

Exports from the declarations published in @askrjs/schema. Signatures reflect the published artifact.

Exports

This entrypoint publishes 9 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

InferSchematype

InferSchema: T extends Schema<infer Value> ? Value : never

Infers the parsed value type of a {@link Schema}.

Issuetype

Issue: any

A single validation failure produced by {@link Schema.safeParse}.

path
Location of the offending value, as a sequence of object keys and/or array indices.
message
Human-readable description of the failure.
code
Stable machine-readable failure code, e.g. `"invalid_type"` or `"too_small"`.

JsonSchematype

JsonSchema: Readonly<Record<string, unknown>>

A frozen, deterministic JSON Schema (draft 2020-12) object produced by a {@link Schema}.

ObjectSchematype

ObjectSchema: any

An executable schema whose successful value is always a plain object.

kind
readonly kind: "object";

OptionalSchematype

OptionalSchema: any

A {@link Schema} produced by {@link schema.optional} that permits `undefined` values.

__optional
readonly __optional: true;

SafeParseResulttype

SafeParseResult: {
  readonly success: true;
  readonly data: T;
} | {
  readonly success: false;
  readonly issues: readonly Issue[];
}

The outcome of parsing a value: either the validated data, or the list of issues found.

schematype

schema: Readonly<{ string: typeof string; uuid: (options?: StringOptions) => Schema<string>; email: (options?: StringOptions) => Schema<string>; uri: (options?: StringOptions) => Schema<string>; date: (options?: StringOptions) => Schema<string>; dateTime: (options?: StringOptions) => Schema<string>; byte: (options?: StringOptions) => Schema<string>; binary: (options?: StringOptions) => Schema<string>; number: (options?: NumberOptions) => Schema<number>; integer: (options?: NumberOptions) => Schema<number>; boolean: (options?: CommonOptions) => Schema<boolean>; null: (options?: CommonOptions) => Schema<null>; object: typeof object; array: typeof array; record: <T>(values: Schema<T>, options?: CommonOptions) => ObjectSchema<Record<string, T>>; enum: <const T extends readonly (string | number | boolean)[]>(values: T, options?: CommonOptions) => Schema<T[number]>; literal: <const T extends string | number | boolean | null>(value: T, options?: CommonOptions) => Schema<T>; optional: <T>(value: Schema<T>) => OptionalSchema<T>; nullable: <T extends Schema>(value: T) => NullableSchema<T>; oneOf: <const T extends readonly Schema[]>(...values: T) => Schema<InferSchema<T[number]>>; anyOf: <const T extends readonly Schema[]>(...values: T) => Schema<InferSchema<T[number]>>; allOf: <const T extends readonly Schema[]>(...values: T) => Schema<UnionToIntersection<InferSchema<T[number]>>>; raw: <T>(jsonSchema: JsonSchema, safeParse: (value: unknown) => SafeParseResult<T>) => Schema<T>; }>

The public schema builder namespace: create executable schemas whose {@link Schema.safeParse} validates a value and whose `jsonSchema` field is a deterministic JSON Schema (draft 2020-12) projection suitable for OpenAPI documents.

const user = schema.object({ id: schema.uuid(), name: schema.string({ minLength: 1 }) });
const result = user.safeParse({ id: "...", name: "Ada" });

Schematype

Schema: any

An executable schema: carries its JSON Schema projection and a runtime parser.

jsonSchema
The deterministic JSON Schema (draft 2020-12) projection of this schema.
__type
Phantom type marker only; never set at runtime.
safeParse
Validates `value`, returning either the parsed data or a list of issues.

StringFormattype

StringFormat: "uuid" | "email" | "uri" | "date" | "date-time" | "byte" | "binary"

Supported `format` values for {@link schema.string} and its format-specific shorthands.