@eryx/schema/struct Module

JSON

Struct (table) schema primitives. Supports field validation, unknown-key policies, schema transforms, and shape composition. This module is the primary tool for object-like contracts where each key has its own schema and unknown-key behavior must be explicit.

Summary

Functions

schema.strict<T>(struct: TableSchema<T>)TableSchema<T>
schema.strip<T>(struct: TableSchema<T>)TableSchema<T>
schema.passthrough<T>(struct: TableSchema<T>)TableSchema<T>
schema.catchall<T>(struct: TableSchema<T>, child: t.Schema<any>)TableSchema<T>
schema.partial<T>(struct: TableSchema<T>)TableSchema<any>
schema.pick<T>(struct: TableSchema<T>, keys: { string })TableSchema<any>
schema.omit<T>(struct: TableSchema<T>, keys: { string })TableSchema<any>
schema.required<T>(struct: TableSchema<T>, keys: { string }?)TableSchema<any>
schema.readonly<T>(struct: TableSchema<T>)TableSchema<T>
schema.freeze<T>(struct: TableSchema<T>)TableSchema<T>
schema.extend<T, U>(first: TableSchema<T>, second: U)TableSchema<mergeTables<T, extractTableSchema<U>>>

API Reference

Functions

schema.strict

Set unknown-key handling to strict mode. Unknown keys fail parsing. Use strict mode for closed contracts, API request validation, and places where extra fields likely indicate caller errors.

schema.strict<T>(struct: TableSchema<T>)TableSchema<T>

Returns

TableSchema<T>

A new table schema in strict mode.

schema.strip

Set unknown-key handling to strip mode. Unknown keys are accepted but removed from parsed output. Use strip mode at permissive boundaries when forward compatibility is desired but unknown fields should not propagate internally.

schema.strip<T>(struct: TableSchema<T>)TableSchema<T>

Returns

TableSchema<T>

A new table schema in strip mode.

schema.passthrough

Set unknown-key handling to passthrough mode. Unknown keys are accepted and retained in parsed output. Use passthrough mode when extension fields are expected and should remain available to callers or downstream systems.

schema.passthrough<T>(struct: TableSchema<T>)TableSchema<T>

Returns

TableSchema<T>

A new table schema in passthrough mode.

schema.catchall

Validate unknown keys using a catchall schema. Catchall applies schema validation to keys not listed in fields. Combine with strip/passthrough depending on whether validated extras should be dropped or retained in parsed output.

schema.catchall<T>(struct: TableSchema<T>, child: t.Schema<any>)TableSchema<T>

Parameters

child: t.Schema<any>

Schema applied to unknown keys when catchall is enabled.

Returns

TableSchema<T>

A new table schema with catchall validation.

schema.partial

Make all fields optional. Ideal for PATCH-style inputs and partial update payloads. Existing optional fields remain optional; required fields are wrapped.

schema.partial<T>(struct: TableSchema<T>)TableSchema<any>

Returns

TableSchema<any>

A new table schema with optionalized fields.

schema.pick

Keep only the selected field keys. Useful for endpoint/view-specific projections built from a shared base shape.

schema.pick<T>(struct: TableSchema<T>, keys: { string })TableSchema<any>

Parameters

keys: { string }

Field names to keep in the resulting schema.

Returns

TableSchema<any>

A new table schema containing picked fields.

schema.omit

Drop the selected field keys. Useful for deriving public-facing shapes from internal objects.

schema.omit<T>(struct: TableSchema<T>, keys: { string })TableSchema<any>

Parameters

keys: { string }

Field names to remove from the resulting schema.

Returns

TableSchema<any>

A new table schema without omitted fields.

schema.required

Make fields required by unwrapping optional wrappers. If keys are omitted, all fields are made required. Use keyed required mode to tighten selected fields while preserving the rest of a partial schema.

schema.required<T>(struct: TableSchema<T>, keys: { string }?)TableSchema<any>

Parameters

keys: { string }?

Optional subset of fields to force as required.

Returns

TableSchema<any>

A new table schema with required fields.

schema.readonly

Freeze parsed output tables so downstream code cannot mutate them. Useful when parsed data should be treated as immutable configuration or value objects.

schema.readonly<T>(struct: TableSchema<T>)TableSchema<T>

Returns

TableSchema<T>

A new table schema that freezes parsed results.

schema.freeze

Alias for readonly table output. Provided for naming parity with libraries that expose freeze.

schema.freeze<T>(struct: TableSchema<T>)TableSchema<T>

Returns

TableSchema<T>

A new table schema that freezes parsed results.

schema.extend

Merge fields from two table schemas. When keys overlap, the second schema's field definition wins. The resulting schema keeps policy metadata from the first schema. Use this to build layered shapes from reusable fragments.

schema.extend<T, U>(first: TableSchema<T>, second: U)TableSchema<mergeTables<T, extractTableSchema<U>>>

Parameters

first: TableSchema<T>

Left/base table schema whose policies are retained.

second: U

Right/extension table schema whose fields are merged in.

Returns

TableSchema<mergeTables<T, extractTableSchema<U>>>

A merged table schema.