middlewareDecoding<S, RD>Intercepts the decoding pipeline of a schema.
Details
The provided function receives the current decoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RD),
recovering from errors, or augmenting the result.
Example (Logging decode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareDecoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
)
)export interface interface middlewareDecoding<S extends Constraint, RD>Intercepts the decoding pipeline of a schema.
Details
The provided function receives the current decoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RD),
recovering from errors, or augmenting the result.
Example (Logging decode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareDecoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
)
)
Type-level representation returned by
middlewareDecoding
.
middlewareDecoding<function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S extends Constraint, function (type parameter) RD in middlewareDecoding<S extends Constraint, RD>RD> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["ast"],
interface middlewareDecoding<S extends Constraint, RD>Intercepts the decoding pipeline of a schema.
Details
The provided function receives the current decoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RD),
recovering from errors, or augmenting the result.
Example (Logging decode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareDecoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
)
)
Type-level representation returned by
middlewareDecoding
.
middlewareDecoding<function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S, function (type parameter) RD in middlewareDecoding<S extends Constraint, RD>RD>,
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~type.parameters"],
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~type.mutability"],
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~type.optionality"],
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~type.constructor.default"],
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~encoded.mutability"],
function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~encoded.optionality"]
>
{
readonly "Type": function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["Type"]
readonly "Encoded": function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["Encoded"]
readonly "DecodingServices": function (type parameter) RD in middlewareDecoding<S extends Constraint, RD>RD
readonly "EncodingServices": function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["EncodingServices"]
readonly "~type.make.in": function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~type.make.in"]
readonly "~type.make": function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["~type.make"]
readonly "Iso": function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S["Iso"]
readonly middlewareDecoding<S extends Constraint, RD>.schema: S extends Constraintschema: function (type parameter) S in middlewareDecoding<S extends Constraint, RD>S
}
/**
* Intercepts the decoding pipeline of a schema.
*
* **Details**
*
* The provided function receives the current decoding `Effect` and `ParseOptions`,
* and returns a new `Effect` — potentially adding service requirements (`RD`),
* recovering from errors, or augmenting the result.
*
* **Example** (Logging decode failures)
*
* ```ts
* import { Effect, Schema } from "effect"
*
* const Logged = Schema.String.pipe(
* Schema.middlewareDecoding((effect) =>
* Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
* )
* )
* ```
*
* @see {@link catchDecoding} for a simpler error-recovery variant
* @category decoding
* @since 4.0.0
*/
export function function middlewareDecoding<
S extends Constraint,
RD
>(
decode: (
effect: Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
S["DecodingServices"]
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
RD
>
): (schema: S) => middlewareDecoding<S, RD>
Intercepts the decoding pipeline of a schema.
Details
The provided function receives the current decoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RD),
recovering from errors, or augmenting the result.
Example (Logging decode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareDecoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
)
)
middlewareDecoding<function (type parameter) S in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>S extends Constraint, function (type parameter) RD in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>RD>(
decode: (
effect: Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
S["DecodingServices"]
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
RD
>
decode: (
effect: Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
S["DecodingServices"]
>
(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) S in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>S["Type"]>, import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue, function (type parameter) S in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>S["DecodingServices"]>,
options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options: import SchemaASTSchemaAST.ParseOptions
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) S in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>S["Type"]>, import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue, function (type parameter) RD in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>RD>
) {
return (schema: S extends Constraintschema: function (type parameter) S in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>S): interface middlewareDecoding<S extends Constraint, RD>Intercepts the decoding pipeline of a schema.
Details
The provided function receives the current decoding Effect and ParseOptions,
and returns a new Effect — potentially adding service requirements (RD),
recovering from errors, or augmenting the result.
Example (Logging decode failures)
import { Effect, Schema } from "effect"
const Logged = Schema.String.pipe(
Schema.middlewareDecoding((effect) =>
Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
)
)
Type-level representation returned by
middlewareDecoding
.
middlewareDecoding<function (type parameter) S in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>S, function (type parameter) RD in middlewareDecoding<S extends Constraint, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>, options: SchemaAST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>RD> =>
const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(
import SchemaASTSchemaAST.function middlewareDecoding(
ast: AST,
middleware: SchemaTransformation.Middleware<
any,
any,
any,
any,
any,
any
>
): AST
middlewareDecoding(schema: S extends Constraintschema.Constraint["ast"]: SchemaAST.ASTast, new import SchemaTransformationSchemaTransformation.constructor Middleware<any, any, any, any, any, any>(decode: (effect: Effect.Effect<StandardJSONSchemaV1<any>, SchemaIssue.Issue, any>, options: SchemaAST.ParseOptions) => Effect.Effect<StandardJSONSchemaV1<any>, SchemaIssue.Issue, any>, encode: (effect: Effect.Effect<StandardJSONSchemaV1<any>, SchemaIssue.Issue, any>, options: SchemaAST.ParseOptions) => Effect.Effect<StandardJSONSchemaV1<any>, SchemaIssue.Issue, any>): SchemaTransformation.Middleware<...>Middleware that wraps the entire parsing Effect pipeline for both
decode and encode directions.
When to use
Use when you need a schema middleware to catch or recover from parsing
errors (e.g. Schema.catchDecoding), run side effects around the parsing
pipeline, or access the full Effect rather than a single decoded value.
Details
Unlike Transformation, which operates on individual values via Getter,
Middleware receives the full Effect produced by the inner schema and can
intercept, modify, retry, or replace it.
decode receives an Effect<Option<E>, Issue, RDE> and returns
Effect<Option<T>, Issue, RDT>.
encode receives an Effect<Option<T>, Issue, RET> and returns
Effect<Option<E>, Issue, REE>.
flip() swaps the decode and encode functions, producing a
Middleware<E, T, ...>.
Typically constructed indirectly via Schema.middlewareDecoding or
Schema.middlewareEncoding rather than instantiating this class directly.
Example (Creating a middleware that falls back on decode failure)
import { Effect, Option, SchemaTransformation } from "effect"
const fallback = new SchemaTransformation.Middleware(
(effect) => Effect.catch(effect, () => Effect.succeed(Option.some("fallback"))),
(effect) => effect
)
Middleware(decode: (
effect: Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
S["DecodingServices"]
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option_.Option<S["Type"]>,
SchemaIssue.Issue,
RD
>
decode, import identityidentity)),
{ schema: S extends Constraintschema }
)
}