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

Config overview

Added in v2.0.0


Table of contents


constructors

all

Constructs a config from a tuple / struct / arguments of configs.

Signature

export declare const all: <const Arg extends Iterable<Config<any>> | Record<string, Config<any>>>(
  arg: Arg
) => Config<
  [Arg] extends [readonly Config<any>[]]
    ? { -readonly [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never }
    : [Arg] extends [Iterable<Config<infer A>>]
      ? A[]
      : [Arg] extends [Record<string, Config<any>>]
        ? { -readonly [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never }
        : never
>

Added in v2.0.0

array

Constructs a config for an array of values.

Signature

export declare const array: <A>(config: Config<A>, name?: string) => Config<readonly A[]>

Added in v2.0.0

boolean

Constructs a config for a boolean value.

Signature

export declare const boolean: (name?: string) => Config<boolean>

Added in v2.0.0

chunk

Constructs a config for a sequence of values.

Signature

export declare const chunk: <A>(config: Config<A>, name?: string) => Config<Chunk.Chunk<A>>

Added in v2.0.0

date

Constructs a config for a date value.

Signature

export declare const date: (name?: string) => Config<Date>

Added in v2.0.0

duration

Constructs a config for a duration value.

Signature

export declare const duration: (name?: string) => Config<Duration.Duration>

Added in v2.5.0

fail

Constructs a config that fails with the specified message.

Signature

export declare const fail: (message: string) => Config<never>

Added in v2.0.0

hashMap

Constructs a config for a sequence of values.

Signature

export declare const hashMap: <A>(config: Config<A>, name?: string) => Config<HashMap.HashMap<string, A>>

Added in v2.0.0

hashSet

Constructs a config for a sequence of values.

Signature

export declare const hashSet: <A>(config: Config<A>, name?: string) => Config<HashSet.HashSet<A>>

Added in v2.0.0

integer

Constructs a config for a integer value.

Signature

export declare const integer: (name?: string) => Config<number>

Added in v2.0.0

literal

Constructs a config for a literal value.

Signature

export declare const literal: <Literals extends readonly LiteralValue[]>(
  ...literals: Literals
) => (name?: string) => Config<Literals[number]>

Example

import { Config } from "effect"

const config = Config.literal("http", "https")("PROTOCOL")

Added in v2.0.0

logLevel

Constructs a config for a LogLevel value.

Signature

export declare const logLevel: (name?: string) => Config<LogLevel.LogLevel>

Added in v2.0.0

number

Constructs a config for a float value.

Signature

export declare const number: (name?: string) => Config<number>

Added in v2.0.0

primitive

Constructs a new primitive config.

Signature

export declare const primitive: <A>(
  description: string,
  parse: (text: string) => Either.Either<A, ConfigError.ConfigError>
) => Config<A>

Added in v2.0.0

secret

Constructs a config for a secret value.

Signature

export declare const secret: (name?: string) => Config<Secret.Secret>

Added in v2.0.0

string

Constructs a config for a string value.

Signature

export declare const string: (name?: string) => Config<string>

Added in v2.0.0

succeed

Constructs a config which contains the specified value.

Signature

export declare const succeed: <A>(value: A) => Config<A>

Added in v2.0.0

suspend

Lazily constructs a config.

Signature

export declare const suspend: <A>(config: LazyArg<Config<A>>) => Config<A>

Added in v2.0.0

sync

Constructs a config which contains the specified lazy value.

Signature

export declare const sync: <A>(value: LazyArg<A>) => Config<A>

Added in v2.0.0

unwrap

Constructs a config from some configuration wrapped with the Wrap<A> utility type.

For example:

import { Config, unwrap } from "./Config"

interface Options { key: string }

const makeConfig = (config: Config.Wrap<Options>): Config<Options> => unwrap(config)

Signature

export declare const unwrap: <A>(wrapped: Config.Wrap<A>) => Config<A>

Added in v2.0.0

mapping

map

Returns a config whose structure is the same as this one, but which produces a different value, constructed using the specified function.

Signature

export declare const map: {
  <A, B>(f: (a: A) => B): (self: Config<A>) => Config<B>
  <A, B>(self: Config<A>, f: (a: A) => B): Config<B>
}

Added in v2.0.0

models

Config (interface)

A Config describes the structure of some configuration data.

Signature

export interface Config<out A> extends Config.Variance<A>, Effect.Effect<A, ConfigError.ConfigError> {}

Added in v2.0.0

LiteralValue (type alias)

Signature

export type LiteralValue = string | number | boolean | null | bigint

Added in v2.0.0

refinements

isConfig

This function returns true if the specified value is an Config value, false otherwise.

This function can be useful for checking the type of a value before attempting to operate on it as an Config value. For example, you could use isConfig to check the type of a value before using it as an argument to a function that expects an Config value.

Signature

export declare const isConfig: (u: unknown) => u is Config<unknown>

Added in v2.0.0

symbols

ConfigTypeId

Signature

export declare const ConfigTypeId: typeof ConfigTypeId

Added in v2.0.0

ConfigTypeId (type alias)

Signature

export type ConfigTypeId = typeof ConfigTypeId

Added in v2.0.0

utils

Config (namespace)

Added in v2.0.0

Primitive (interface)

Signature

export interface Primitive<out A> extends Config<A> {
  readonly description: string
  parse(text: string): Either.Either<A, ConfigError.ConfigError>
}

Added in v2.0.0

Variance (interface)

Signature

export interface Variance<out A> {
  readonly [ConfigTypeId]: {
    readonly _A: Types.Covariant<A>
  }
}

Added in v2.0.0

Wrap (type alias)

Wraps a nested structure, converting all primitives to a Config.

Config.Wrap<{ key: string }> becomes { key: Config<string> }

To create the resulting config, use the unwrap constructor.

Signature

export type Wrap<A> =
  | (A extends Record<string, any>
      ? {
          [K in keyof A]: Wrap<A[K]>
        }
      : never)
  | Config<A>

Added in v2.0.0

mapAttempt

Returns a config whose structure is the same as this one, but which may produce a different value, constructed using the specified function, which may throw exceptions that will be translated into validation errors.

Signature

export declare const mapAttempt: {
  <A, B>(f: (a: A) => B): (self: Config<A>) => Config<B>
  <A, B>(self: Config<A>, f: (a: A) => B): Config<B>
}

Added in v2.0.0

mapOrFail

Returns a new config whose structure is the samea as this one, but which may produce a different value, constructed using the specified fallible function.

Signature

export declare const mapOrFail: {
  <A, B>(f: (a: A) => Either.Either<B, ConfigError.ConfigError>): (self: Config<A>) => Config<B>
  <A, B>(self: Config<A>, f: (a: A) => Either.Either<B, ConfigError.ConfigError>): Config<B>
}

Added in v2.0.0

nested

Returns a config that has this configuration nested as a property of the specified name.

Signature

export declare const nested: {
  (name: string): <A>(self: Config<A>) => Config<A>
  <A>(self: Config<A>, name: string): Config<A>
}

Added in v2.0.0

option

Returns an optional version of this config, which will be None if the data is missing from configuration, and Some otherwise.

Signature

export declare const option: <A>(self: Config<A>) => Config<Option.Option<A>>

Added in v2.0.0

orElse

Returns a config whose structure is preferentially described by this config, but which falls back to the specified config if there is an issue reading from this config.

Signature

export declare const orElse: {
  <A2>(that: LazyArg<Config<A2>>): <A>(self: Config<A>) => Config<A2 | A>
  <A, A2>(self: Config<A>, that: LazyArg<Config<A2>>): Config<A | A2>
}

Added in v2.0.0

orElseIf

Returns configuration which reads from this configuration, but which falls back to the specified configuration if reading from this configuration fails with an error satisfying the specified predicate.

Signature

export declare const orElseIf: {
  <A2>(options: {
    readonly if: Predicate<ConfigError.ConfigError>
    readonly orElse: LazyArg<Config<A2>>
  }): <A>(self: Config<A>) => Config<A>
  <A, A2>(
    self: Config<A>,
    options: { readonly if: Predicate<ConfigError.ConfigError>; readonly orElse: LazyArg<Config<A2>> }
  ): Config<A>
}

Added in v2.0.0

repeat

Returns a config that describes a sequence of values, each of which has the structure of this config.

Signature

export declare const repeat: <A>(self: Config<A>) => Config<A[]>

Added in v2.0.0

validate

Returns a config that describes the same structure as this one, but which performs validation during loading.

Signature

export declare const validate: {
  <A, B extends A>(options: {
    readonly message: string
    readonly validation: Refinement<A, B>
  }): (self: Config<A>) => Config<B>
  <A>(options: { readonly message: string; readonly validation: Predicate<A> }): (self: Config<A>) => Config<A>
  <A, B extends A>(
    self: Config<A>,
    options: { readonly message: string; readonly validation: Refinement<A, B> }
  ): Config<B>
  <A>(self: Config<A>, options: { readonly message: string; readonly validation: Predicate<A> }): Config<A>
}

Added in v2.0.0

withDefault

Returns a config that describes the same structure as this one, but has the specified default value in case the information cannot be found.

Signature

export declare const withDefault: {
  <const A2>(def: A2): <A>(self: Config<A>) => Config<A2 | A>
  <A, const A2>(self: Config<A>, def: A2): Config<A | A2>
}

Added in v2.0.0

withDescription

Adds a description to this configuration, which is intended for humans.

Signature

export declare const withDescription: {
  (description: string): <A>(self: Config<A>) => Config<A>
  <A>(self: Config<A>, description: string): Config<A>
}

Added in v2.0.0

zipping

zip

Returns a config that is the composition of this config and the specified config.

Signature

export declare const zip: {
  <B>(that: Config<B>): <A>(self: Config<A>) => Config<[A, B]>
  <A, B>(self: Config<A>, that: Config<B>): Config<[A, B]>
}

Added in v2.0.0

zipWith

Returns a config that is the composes this config and the specified config using the provided function.

Signature

export declare const zipWith: {
  <B, A, C>(that: Config<B>, f: (a: A, b: B) => C): (self: Config<A>) => Config<C>
  <A, B, C>(self: Config<A>, that: Config<B>, f: (a: A, b: B) => C): Config<C>
}

Added in v2.0.0