<S extends Constraint>(schema: S): middlewareDecoding<
S,
S["DecodingServices"]
>Middleware that wraps decoded errors in Redacted, preventing sensitive
schema details from leaking in error messages.
export function function redact<S extends Constraint>(
schema: S
): middlewareDecoding<S, S["DecodingServices"]>
Middleware that wraps decoded errors in Redacted, preventing sensitive
schema details from leaking in error messages.
redact<function (type parameter) S in redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]>S extends Constraint>(schema: S extends Constraintschema: function (type parameter) S in redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]>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 redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]>S, function (type parameter) S in redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]>S["DecodingServices"]> {
return 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 redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]>S, function (type parameter) S in redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]>S["DecodingServices"]>(import EffectEffect.const mapErrorEager: {
<E, E2>(f: (e: E) => E2): <A, R>(
self: Effect<A, E, R>
) => Effect<A, E2, R>
<A, E, R, E2>(
self: Effect<A, E, R>,
f: (e: E) => E2
): Effect<A, E2, R>
}
mapErrorEager(import SchemaIssueSchemaIssue.function redact(issue: Issue): Issueredact))(schema: S extends Constraintschema)
}