Schema Projections
Sometimes, you may want to create a new schema based on an existing one, focusing specifically on either its Type
or Encoded
aspect. The Schema module provides several functions to make this possible.
The Schema.typeSchema
function is used to extract the Type
portion of a schema, resulting in a new schema that retains only the type-specific properties from the original schema. This excludes any initial encoding or transformation logic applied to the original schema.
Function Signature
Example (Extracting Only Type-Specific Properties)
The Schema.encodedSchema
function enables you to extract the Encoded
portion of a schema, creating a new schema that matches the original properties but omits any refinements or transformations applied to the schema.
Function Signature
Example (Extracting Encoded Properties Only)
The Schema.encodedBoundSchema
function is similar to Schema.encodedSchema
but preserves the refinements up to the first transformation point in the
original schema.
Function Signature
The term “bound” in this context refers to the boundary up to which refinements are preserved when extracting the encoded form of a schema. It essentially marks the limit to which initial validations and structure are maintained before any transformations are applied.
Example (Retaining Initial Refinements Only)