# @askrjs/schema

> Published API exports for @askrjs/schema.

Source: [https://askrjs.com/docs/reference/api/schema/root](https://askrjs.com/docs/reference/api/schema/root)

Status: stable. Packages: @askrjs/schema.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 9 exports from the declarations shipped by @askrjs/schema.

### `InferSchema`

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

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

### `Issue`

```ts
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"`.

### `JsonSchema`

```ts
JsonSchema: Readonly<Record<string, unknown>>
```

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

### `ObjectSchema`

```ts
ObjectSchema: any
```

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

- `kind`: readonly kind: "object";

### `OptionalSchema`

```ts
OptionalSchema: any
```

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

- `__optional`: readonly __optional: true;

### `SafeParseResult`

```ts
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.

### `schema`

```ts
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.

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

### `Schema`

```ts
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.

### `StringFormat`

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

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

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/otel/root/index.md) | [Next](https://askrjs.com/docs/reference/api/server/root/index.md)
