RedactedFromValue<S>Decodes a value and wraps it in Redacted<A>. Unlike Redacted which
expects the input to already be a Redacted instance, this schema decodes
the raw value and wraps it.
export interface interface RedactedFromValue<S extends Constraint>Decodes a value and wraps it in Redacted<A>. Unlike
Redacted
which
expects the input to already be a Redacted instance, this schema decodes
the raw value and wraps it.
Type-level representation returned by
RedactedFromValue
.
RedactedFromValue<function (type parameter) S in RedactedFromValue<S extends Constraint>S extends Constraint>
extends interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<interface Redacted<S extends Constraint>Schema for values that hide sensitive information from error output and
inspection.
Details
If the wrapped schema fails, the issue will be redacted to prevent both
the actual value and the schema details from being exposed.
Options:
label: When provided, the schema will behave as follows:
- Values will be validated against the label in addition to the wrapped schema
- The default JSON serializer will deserialize into a
Redacted instance with the label
- The arbitrary generator will produce a
Redacted instance with the label
- The formatter will return the label
disallowJsonEncode: When set to true, when attempting to encode a Redacted instance
into JSON, it will fail with an error. This is useful when the wrapped schema is
sensitive and should not be exposed in JSON.
Type-level representation returned by
Redacted
.
Redacted<interface toType<S extends Constraint>Type-level representation returned by
toType
.
Extracts the type-side schema: sets Encoded to equal the decoded Type,
discarding the encoding transformation path.
toType<function (type parameter) S in RedactedFromValue<S extends Constraint>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 RedactedFromValue<S extends Constraint>S, function (type parameter) S in RedactedFromValue<S extends Constraint>S["DecodingServices"]>>
{
readonly "Rebuild": interface RedactedFromValue<S extends Constraint>Decodes a value and wraps it in Redacted<A>. Unlike
Redacted
which
expects the input to already be a Redacted instance, this schema decodes
the raw value and wraps it.
Type-level representation returned by
RedactedFromValue
.
RedactedFromValue<function (type parameter) S in RedactedFromValue<S extends Constraint>S>
}
/**
* Middleware that wraps decoded errors in `Redacted`, preventing sensitive
* schema details from leaking in error messages.
*
* @category Redacted
* @since 4.0.0
*/
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.mapErrorEager(import SchemaIssueSchemaIssue.function redact(issue: Issue): Issueredact))(schema: S extends Constraintschema)
}
/**
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
* expects the input to already be a `Redacted` instance, this schema decodes
* the raw value and wraps it.
*
* @see {@link Redacted} for schemas whose input is already a `Redacted` value.
* @category Redacted
* @since 4.0.0
*/
export function function RedactedFromValue<
S extends Constraint
>(
value: S,
options?: {
readonly label?: string | undefined
readonly disallowEncode?: boolean | undefined
}
): RedactedFromValue<S>
Decodes a value and wraps it in Redacted<A>. Unlike
Redacted
which
expects the input to already be a Redacted instance, this schema decodes
the raw value and wraps it.
RedactedFromValue<function (type parameter) S in RedactedFromValue<S extends Constraint>(value: S, options?: {
readonly label?: string | undefined;
readonly disallowEncode?: boolean | undefined;
}): RedactedFromValue<S>
S extends Constraint>(value: S extends Constraintvalue: function (type parameter) S in RedactedFromValue<S extends Constraint>(value: S, options?: {
readonly label?: string | undefined;
readonly disallowEncode?: boolean | undefined;
}): RedactedFromValue<S>
S, options: | {
readonly label?: string | undefined
readonly disallowEncode?:
| boolean
| undefined
}
| undefined
options?: {
readonly label?: string | undefinedlabel?: string | undefined
readonly disallowEncode?: boolean | undefineddisallowEncode?: boolean | undefined
}): interface RedactedFromValue<S extends Constraint>Decodes a value and wraps it in Redacted<A>. Unlike
Redacted
which
expects the input to already be a Redacted instance, this schema decodes
the raw value and wraps it.
Type-level representation returned by
RedactedFromValue
.
RedactedFromValue<function (type parameter) S in RedactedFromValue<S extends Constraint>(value: S, options?: {
readonly label?: string | undefined;
readonly disallowEncode?: boolean | undefined;
}): RedactedFromValue<S>
S> {
return 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(value: S extends Constraintvalue).pipe(
function decodeTo<Redacted<toType<S>>, Constraint, never, never>(to: Redacted<toType<S>>, transformation: {
readonly decode: SchemaGetter.Getter<Redacted_.Redacted<S["Encoded"]>, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, Redacted_.Redacted<S["Encoded"]>, never>;
}): (from: Constraint) => decodeTo<Redacted<toType<S>>, Constraint, never, never> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(
function Redacted<S extends Constraint>(
value: S,
options?: {
readonly label?: string | undefined
readonly disallowJsonEncode?:
| boolean
| undefined
}
): Redacted<S>
Schema for values that hide sensitive information from error output and
inspection.
Details
If the wrapped schema fails, the issue will be redacted to prevent both
the actual value and the schema details from being exposed.
Options:
label: When provided, the schema will behave as follows:
- Values will be validated against the label in addition to the wrapped schema
- The default JSON serializer will deserialize into a
Redacted instance with the label
- The arbitrary generator will produce a
Redacted instance with the label
- The formatter will return the label
disallowJsonEncode: When set to true, when attempting to encode a Redacted instance
into JSON, it will fail with an error. This is useful when the wrapped schema is
sensitive and should not be exposed in JSON.
Redacted(const toType: toTypeLambda
;<S>(self: S) => toType<S>
Type-level representation returned by
toType
.
Extracts the type-side schema: sets Encoded to equal the decoded Type,
discarding the encoding transformation path.
toType(value: S extends Constraintvalue), {
label?: string | undefinedlabel: options: | {
readonly label?: string | undefined
readonly disallowEncode?:
| boolean
| undefined
}
| undefined
options?.label?: string | undefinedlabel,
disallowJsonEncode?: boolean | undefineddisallowJsonEncode: options: | {
readonly label?: string | undefined
readonly disallowEncode?:
| boolean
| undefined
}
| undefined
options?.disallowEncode?: boolean | undefineddisallowEncode
}),
{
decode: SchemaGetter.Getter<
Redacted_.Redacted<S["Type"]>,
NoInfer<S["Type"]>,
never
>
(property) decode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: Redacted_.Redacted<S['Type']>) => T2) => SchemaGetter.Getter<T2, NoInfer<S['Type']>, never>;
compose: (other: SchemaGetter.Getter<T2, Redacted_.Redacted<S['Type']>, R2>) => SchemaGetter.Getter<T2, NoInfer<S['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.function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(Schema.Number, {
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
})
)
transform((t: unknownt) => import Redacted_Redacted_.make(t: unknownt, { label: string | undefinedlabel: options: | {
readonly label?: string | undefined
readonly disallowEncode?:
| boolean
| undefined
}
| undefined
options?.label?: string | undefinedlabel })),
encode: SchemaGetter.Getter<
NoInfer<S["Type"]>,
NoInfer<Redacted_.Redacted<S["Type"]>>,
never
>
(property) encode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: NoInfer<S['Type']>) => T2) => SchemaGetter.Getter<T2, NoInfer<Redacted_.Redacted<S['Type']>>, never>;
compose: (other: SchemaGetter.Getter<T2, NoInfer<S['Type']>, R2>) => SchemaGetter.Getter<T2, NoInfer<Redacted_.Redacted<S['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; <…;
}
encode: options: | {
readonly label?: string | undefined
readonly disallowEncode?:
| boolean
| undefined
}
| undefined
options?.disallowEncode?: boolean | undefineddisallowEncode ?
import SchemaGetterSchemaGetter.function forbidden<T, E>(
message: (oe: Option.Option<E>) => string
): Getter<T, E>
Creates a getter that always fails with a Forbidden issue.
When to use
Use when you need a schema getter to disallow a field or direction
(encode/decode) entirely.
- You want a clear "forbidden" error message in schema validation output.
Details
- Always fails with
SchemaIssue.Forbidden.
- The message function receives the
Option<E> input for context.
Example (Forbidding a decode direction)
import { SchemaGetter } from "effect"
const noEncode = SchemaGetter.forbidden<string, number>(
() => "encoding is not supported"
)
forbidden((oe: Option_.Option<
NoInfer<Redacted_.Redacted<S["Type"]>>
>
oe) =>
"Cannot encode Redacted" +
(import Option_Option_.isSome(oe: Option_.Option<
NoInfer<Redacted_.Redacted<S["Type"]>>
>
oe) && typeof oe: Option_.Some<
NoInfer<Redacted_.Redacted<S["Type"]>>
>
(parameter) oe: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
oe.value.label === "string" ? ` with label: "${oe: Option_.Some<
NoInfer<Redacted_.Redacted<S["Type"]>>
>
(parameter) oe: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
oe.value.label}"` : "")
) :
import SchemaGetterSchemaGetter.function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(Schema.Number, {
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
})
)
transform(import Redacted_Redacted_.value)
}
)
)
}