(redactable: Redactable): unknownReturns the result of calling [symbolRedactable] on a value that is
already known to be Redactable.
When to use
Use when you need to read the redacted representation from a value already
verified as Redactable.
Details
This function reads the current fiber's Context from the global fiber
reference and passes it to the redaction method.
Gotchas
If no fiber is active, an empty Context is passed to the redaction method.
export function function getRedacted(
redactable: Redactable
): unknown
Returns the result of calling [symbolRedactable] on a value that is
already known to be
Redactable
.
When to use
Use when you need to read the redacted representation from a value already
verified as Redactable.
Details
This function reads the current fiber's Context from the global fiber
reference and passes it to the redaction method.
Gotchas
If no fiber is active, an empty Context is passed to the redaction method.
getRedacted(redactable: Redactableredactable: Redactable): unknown {
return redactable: Redactableredactable[const symbolRedactable: typeof symbolRedactableDefines the symbol used to identify objects that implement the
Redactable
protocol.
When to use
Use as the property key when implementing the Redactable protocol.
Details
Add a method under this key to make an object redactable. The method receives
the current Context and must return the replacement value. The symbol is
registered globally via Symbol.for("~effect/Redactable"), so it is
identical across multiple copies of the library at runtime.
Example (Masking an API key)
import { Context, Redactable } from "effect"
class ApiKey {
constructor(readonly raw: string) {}
[Redactable.symbolRedactable](_ctx: Context.Context<never>) {
return this.raw.slice(0, 4) + "..."
}
}
symbolRedactable]((module globalThisglobalThis as any)[const currentFiberTypeId: "~effect/Fiber/currentFiber"currentFiberTypeId]?.context ?? const emptyContext: Context.Context<never>const emptyContext: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
emptyContext)
}