Skip to main content Link Search Menu Expand Document (external link)

Redacted.ts overview

The Redacted module provides functionality for handling sensitive information securely within your application. By using the Redacted data type, you can ensure that sensitive values are not accidentally exposed in logs or error messages.

Since v3.3.0


Exports Grouped by Category


constructors

make

This function creates a Redacted<A> instance from a given value A, securely hiding its content.

Example

import { Redacted } from "effect"

const API_KEY = Redacted.make("1234567890")

Signature

declare const make: <A>(value: A) => Redacted<A>

Source

Since v3.3.0

equivalence

getEquivalence

Generates an equivalence relation for Redacted<A> values based on an equivalence relation for the underlying values A. This function is useful for comparing Redacted instances without exposing their contents.

Example

import * as assert from "node:assert"
import { Redacted, Equivalence } from "effect"

const API_KEY1 = Redacted.make("1234567890")
const API_KEY2 = Redacted.make("1-34567890")
const API_KEY3 = Redacted.make("1234567890")

const equivalence = Redacted.getEquivalence(Equivalence.string)

assert.equal(equivalence(API_KEY1, API_KEY2), false)
assert.equal(equivalence(API_KEY1, API_KEY3), true)

Signature

declare const getEquivalence: <A>(isEquivalent: Equivalence.Equivalence<A>) => Equivalence.Equivalence<Redacted<A>>

Source

Since v3.3.0

getters

value

Retrieves the original value from a Redacted instance. Use this function with caution, as it exposes the sensitive data.

Example

import * as assert from "node:assert"
import { Redacted } from "effect"

const API_KEY = Redacted.make("1234567890")

assert.equal(Redacted.value(API_KEY), "1234567890")

Signature

declare const value: <A>(self: Redacted<A>) => A

Source

Since v3.3.0

models

Redacted (interface)

Signature

export interface Redacted<out A = string> extends Redacted.Variance<A>, Equal.Equal, Pipeable {}

Source

Since v3.3.0

refinements

isRedacted

Signature

declare const isRedacted: (u: unknown) => u is Redacted<unknown>

Source

Since v3.3.0

symbols

RedactedTypeId

Signature

declare const RedactedTypeId: unique symbol

Source

Since v3.3.0

RedactedTypeId (type alias)

Signature

type RedactedTypeId = typeof RedactedTypeId

Source

Since v3.3.0

unsafe

unsafeWipe

Erases the underlying value of a Redacted instance, rendering it unusable. This function is intended to ensure that sensitive data does not remain in memory longer than necessary.

Example

import * as assert from "node:assert"
import { Redacted } from "effect"

const API_KEY = Redacted.make("1234567890")

assert.equal(Redacted.value(API_KEY), "1234567890")

Redacted.unsafeWipe(API_KEY)

assert.throws(() => Redacted.value(API_KEY), new Error("Unable to get redacted value"))

Signature

declare const unsafeWipe: <A>(self: Redacted<A>) => boolean

Source

Since v3.3.0

utils

Redacted (namespace)

Source

Since v3.3.0

Variance (interface)

Signature

export interface Variance<out A> {
  readonly [RedactedTypeId]: {
    readonly _A: Covariant<A>
  }
}

Source

Since v3.3.0

Value (type alias)

Signature

type Value<T> = [T] extends [Redacted<infer _A>] ? _A : never

Source

Since v3.3.0