<T>(): <To extends Constraint>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>
}
) => SchemaAST.LinkConstructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
export function function link<T>(): <
To extends Constraint
>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
) => SchemaAST.Link
Constructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
link<function (type parameter) T in link<T>(): <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}) => SchemaAST.Link
T>() {
return <function (type parameter) To in <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}): SchemaAST.Link
To extends Constraint>(
encodeTo: To extends ConstraintencodeTo: function (type parameter) To in <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}): SchemaAST.Link
To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
(property) decode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: T) => T2) => SchemaGetter.Getter<T2, NoInfer<To['Type']>, never>;
compose: (other: SchemaGetter.Getter<T2, T, R2>) => SchemaGetter.Getter<T2, NoInfer<To['Type']>, R2>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
decode: import SchemaGetterSchemaGetter.class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<function (type parameter) T in link<T>(): <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}) => SchemaAST.Link
T, type NoInfer<T> = intrinsicMarker for non-inference type position
NoInfer<function (type parameter) To in <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}): SchemaAST.Link
To["Type"]>>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
(property) encode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: NoInfer<To['Type']>) => T2) => SchemaGetter.Getter<T2, T, never>;
compose: (other: SchemaGetter.Getter<T2, NoInfer<To['Type']>, R2>) => SchemaGetter.Getter<T2, T, R2>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
encode: import SchemaGetterSchemaGetter.class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<type NoInfer<T> = intrinsicMarker for non-inference type position
NoInfer<function (type parameter) To in <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}): SchemaAST.Link
To["Type"]>, function (type parameter) T in link<T>(): <To extends Constraint>(encodeTo: To, transformation: {
readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>;
readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, T>;
}) => SchemaAST.Link
T>
}
): import SchemaASTSchemaAST.class Linkclass Link {
to: AST;
transformation: SchemaTransformation.Transformation<any, any, any, any> | SchemaTransformation.Middleware<any, any, any, any, any, any>;
}
Represents a single step in an
Encoding
chain.
Details
A link pairs a target
AST
with a Transformation or Middleware
that converts values between the current node and the target.
to — the AST node on the other side of this transformation step.
transformation — the bidirectional conversion logic (decode/encode).
Links are composed into a non-empty array (
Encoding
) attached to
AST nodes that have a different encoded representation.
Link => {
return new import SchemaASTSchemaAST.constructor Link(to: SchemaAST.AST, transformation: SchemaTransformation.Transformation<any, any, any, any> | SchemaTransformation.Middleware<any, any, any, any, any, any>): SchemaAST.LinkRepresents a single step in an
Encoding
chain.
Details
A link pairs a target
AST
with a Transformation or Middleware
that converts values between the current node and the target.
to — the AST node on the other side of this transformation step.
transformation — the bidirectional conversion logic (decode/encode).
Links are composed into a non-empty array (
Encoding
) attached to
AST nodes that have a different encoded representation.
Link(encodeTo: To extends ConstraintencodeTo.Constraint["ast"]: SchemaAST.ASTast, import SchemaTransformationSchemaTransformation.const make: <
T,
E,
RD = never,
RE = never
>(options: {
readonly decode: SchemaGetter.Getter<T, E, RD>
readonly encode: SchemaGetter.Getter<E, T, RE>
}) => Transformation<T, E, RD, RE>
Constructs a Transformation from an object with decode and encode
Getters. If the input is already a Transformation, returns it as-is.
When to use
Use when you already have schema getter instances and want to pair them into
a schema transformation.
- You want idempotent wrapping (won't double-wrap).
Details
- Returns the input unchanged if it is already a
Transformation.
Example (Wrapping existing getters)
import { SchemaGetter, SchemaTransformation } from "effect"
const t = SchemaTransformation.make({
decode: SchemaGetter.transform<number, string>((s) => Number(s)),
encode: SchemaGetter.transform<string, number>((n) => String(n))
})
make(transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
transformation))
}
}