Middleware<T, E, RDE, RDT, RET, REE>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.
decodereceives anEffect<Option<E>, Issue, RDE>and returnsEffect<Option<T>, Issue, RDT>.encodereceives anEffect<Option<T>, Issue, RET>and returnsEffect<Option<E>, Issue, REE>.flip()swaps the decode and encode functions, producing aMiddleware<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
)export class class Middleware<in out T, in out E, RDE, RDT, RET, REE>class Middleware {
_tag: 'Middleware';
decode: (effect: Effect.Effect<Option.Option<E>, SchemaIssue.Issue, RDE>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RDT>;
encode: (effect: Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RET>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<E>, SchemaIssue.Issue, REE>;
flip: () => Middleware<E, T, RET, REE, RDE, RDT>;
}
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<in out function (type parameter) T in Middleware<in out T, in out E, RDE, RDT, RET, REE>T, in out function (type parameter) E in Middleware<in out T, in out E, RDE, RDT, RET, REE>E, function (type parameter) RDE in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDE, function (type parameter) RDT in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDT, function (type parameter) RET in Middleware<in out T, in out E, RDE, RDT, RET, REE>RET, function (type parameter) REE in Middleware<in out T, in out E, RDE, RDT, RET, REE>REE> {
readonly Middleware<in out T, in out E, RDE, RDT, RET, REE>._tag: "Middleware"_tag = "Middleware"
readonly Middleware<in out T, in out E, RDE, RDT, RET, REE>.decode: (effect: Effect.Effect<Option.Option<E>, SchemaIssue.Issue, RDE>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RDT>decode: (
effect: Effect.Effect<
Option.Option<E>,
SchemaIssue.Issue,
RDE
>
(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 OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) E in Middleware<in out T, in out E, RDE, RDT, RET, REE>E>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) RDE in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDE>,
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.type SchemaAST.ParseOptions = /*unresolved*/ anyParseOptions
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) T in Middleware<in out T, in out E, RDE, RDT, RET, REE>T>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) RDT in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDT>
readonly Middleware<in out T, in out E, RDE, RDT, RET, REE>.encode: (effect: Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RET>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<E>, SchemaIssue.Issue, REE>encode: (
effect: Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
RET
>
(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 OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) T in Middleware<in out T, in out E, RDE, RDT, RET, REE>T>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) RET in Middleware<in out T, in out E, RDE, RDT, RET, REE>RET>,
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.type SchemaAST.ParseOptions = /*unresolved*/ anyParseOptions
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) E in Middleware<in out T, in out E, RDE, RDT, RET, REE>E>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) REE in Middleware<in out T, in out E, RDE, RDT, RET, REE>REE>
constructor(
decode: (
effect: Effect.Effect<
Option.Option<E>,
SchemaIssue.Issue,
RDE
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
RDT
>
decode: (
effect: Effect.Effect<
Option.Option<E>,
SchemaIssue.Issue,
RDE
>
(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 OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) E in Middleware<in out T, in out E, RDE, RDT, RET, REE>E>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) RDE in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDE>,
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.type SchemaAST.ParseOptions = /*unresolved*/ anyParseOptions
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) T in Middleware<in out T, in out E, RDE, RDT, RET, REE>T>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) RDT in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDT>,
encode: (
effect: Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
RET
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<E>,
SchemaIssue.Issue,
REE
>
encode: (
effect: Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
RET
>
(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 OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) T in Middleware<in out T, in out E, RDE, RDT, RET, REE>T>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) RET in Middleware<in out T, in out E, RDE, RDT, RET, REE>RET>,
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.type SchemaAST.ParseOptions = /*unresolved*/ anyParseOptions
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) E in Middleware<in out T, in out E, RDE, RDT, RET, REE>E>, import SchemaIssueSchemaIssue.type SchemaIssue.Issue = /*unresolved*/ anyIssue, function (type parameter) REE in Middleware<in out T, in out E, RDE, RDT, RET, REE>REE>
) {
this.Middleware<in out T, in out E, RDE, RDT, RET, REE>.decode: (effect: Effect.Effect<Option.Option<E>, SchemaIssue.Issue, RDE>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RDT>decode = decode: (
effect: Effect.Effect<
Option.Option<E>,
SchemaIssue.Issue,
RDE
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
RDT
>
decode
this.Middleware<in out T, in out E, RDE, RDT, RET, REE>.encode: (effect: Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RET>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<E>, SchemaIssue.Issue, REE>encode = encode: (
effect: Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
RET
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<E>,
SchemaIssue.Issue,
REE
>
encode
}
function Middleware(): Middleware<E, T, RET, REE, RDE, RDT>flip(): class Middleware<in out T, in out E, RDE, RDT, RET, REE>class Middleware {
_tag: 'Middleware';
decode: (effect: Effect.Effect<Option.Option<E>, SchemaIssue.Issue, RDE>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RDT>;
encode: (effect: Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RET>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<E>, SchemaIssue.Issue, REE>;
flip: () => Middleware<E, T, RET, REE, RDE, RDT>;
}
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<function (type parameter) E in Middleware<in out T, in out E, RDE, RDT, RET, REE>E, function (type parameter) T in Middleware<in out T, in out E, RDE, RDT, RET, REE>T, function (type parameter) RET in Middleware<in out T, in out E, RDE, RDT, RET, REE>RET, function (type parameter) REE in Middleware<in out T, in out E, RDE, RDT, RET, REE>REE, function (type parameter) RDE in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDE, function (type parameter) RDT in Middleware<in out T, in out E, RDE, RDT, RET, REE>RDT> {
return new constructor Middleware<E, T, RET, REE, RDE, RDT>(decode: (effect: Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RET>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<E>, SchemaIssue.Issue, REE>, encode: (effect: Effect.Effect<Option.Option<E>, SchemaIssue.Issue, RDE>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RDT>): Middleware<E, T, RET, REE, RDE, RDT>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(this.Middleware<in out T, in out E, RDE, RDT, RET, REE>.encode: (effect: Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RET>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<E>, SchemaIssue.Issue, REE>encode, this.Middleware<in out T, in out E, RDE, RDT, RET, REE>.decode: (effect: Effect.Effect<Option.Option<E>, SchemaIssue.Issue, RDE>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, RDT>decode)
}
}