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.
@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
API Reference
Functions
schema.strict
Returns
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.
Returns
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.
Returns
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.
Parameters
Schema applied to unknown keys when catchall is enabled.
Returns
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.
Returns
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.
Parameters
Field names to keep in the resulting schema.
Returns
A new table schema containing picked fields.
schema.omit
Drop the selected field keys. Useful for deriving public-facing shapes from internal objects.
Parameters
Field names to remove from the resulting schema.
Returns
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.
Parameters
Optional subset of fields to force as required.
Returns
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.
Returns
A new table schema that freezes parsed results.
schema.freeze
Alias for readonly table output.
Provided for naming parity with libraries that expose freeze.
Returns
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.
Parameters
Left/base table schema whose policies are retained.
Right/extension table schema whose fields are merged in.
Returns
A merged table schema.