<A extends AST>(
from: AST,
to: A,
transformation: SchemaTransformation.Transformation<any, any, any, any>
): AAttaches a Transformation to the to AST, making it decode from the
from AST and encode back to it.
Details
This is the low-level primitive behind Schema.transform and
Schema.transformOrFail. It appends a Link to the to node's
encoding chain.
- Returns a new AST with the same type as
to.
export function function decodeTo<A extends AST>(
from: AST,
to: A,
transformation: SchemaTransformation.Transformation<
any,
any,
any,
any
>
): A
Attaches a Transformation to the to AST, making it decode from the
from AST and encode back to it.
Details
This is the low-level primitive behind Schema.transform and
Schema.transformOrFail. It appends a
Link
to the to node's
encoding chain.
- Returns a new AST with the same type as
to.
decodeTo<function (type parameter) A in decodeTo<A extends AST>(from: AST, to: A, transformation: SchemaTransformation.Transformation<any, any, any, any>): AA extends type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST>(
from: ASTfrom: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST,
to: A extends ASTto: function (type parameter) A in decodeTo<A extends AST>(from: AST, to: A, transformation: SchemaTransformation.Transformation<any, any, any, any>): AA,
transformation: SchemaTransformation.Transformation<
any,
any,
any,
any
>
(parameter) transformation: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<any, any, any, any>;
compose: (other: SchemaTransformation.Transformation<T2, any, RD2, RE2>) => SchemaTransformation.Transformation<T2, any, any, any>;
}
transformation: import SchemaTransformationSchemaTransformation.class Transformation<in out T, in out E, RD = never, RE = never>class Transformation {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<E, T, RE, RD>;
compose: <T2, RD2, RE2>(other: Transformation<T2, T, RD2, RE2>) => Transformation<T2, E, RD | RD2, RE | RE2>;
}
Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation<any, any, any, any>
): function (type parameter) A in decodeTo<A extends AST>(from: AST, to: A, transformation: SchemaTransformation.Transformation<any, any, any, any>): AA {
return function appendTransformation<
A extends AST
>(
from: AST,
transformation:
| SchemaTransformation.Transformation<
any,
any,
any,
any
>
| SchemaTransformation.Middleware<
any,
any,
any,
any,
any,
any
>,
to: A
): A
appendTransformation(from: ASTfrom, transformation: SchemaTransformation.Transformation<
any,
any,
any,
any
>
(parameter) transformation: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<any, any, any, any>;
compose: (other: SchemaTransformation.Transformation<T2, any, RD2, RE2>) => SchemaTransformation.Transformation<T2, any, any, any>;
}
transformation, to: A extends ASTto)
}