Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Config

44 exports Since v2.0.0 Source

Constructors

Since v2.0.0

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

Signature

declare const all: <Arg extends Iterable<Config<any>> | Record<string, Config<any>>>(arg: Arg) => Config<[Arg] extends [ReadonlyArray<Config<any>>] ? { [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never } : [Arg] extends [Iterable<Config<infer A>>] ? Array<A> : [Arg] extends [Record<string, Config<any>>] ? { [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never } : never>
Since v2.0.0

Constructs a config for an array of values.

Signature

declare const array: <A>(config: Config<A>, name?: string) => Config<Array<A>>
Since v2.0.0

Constructs a config for a boolean value.

Signature

declare const boolean: (name?: string) => Config<boolean>
Since v3.16.0

Constructs a config for a branded value.

Signature

declare const branded: {
<A, B extends Brand<any>>(constructor: Constructor<B>): (config: Config<A>) => Config<B>;
<B extends Branded<string, any>>(name: string | undefined, constructor: Constructor<B>): Config<B>;
<A, B extends Brand<any>>(config: Config<A>, constructor: Constructor<B>): Config<B>;
}
Since v2.0.0

Constructs a config for a sequence of values.

Signature

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

Constructs a config for a date value.

Signature

declare const date: (name?: string) => Config<Date>
Since v2.5.0

Constructs a config for a duration value.

Signature

declare const duration: (name?: string) => Config<Duration.Duration>
Since v2.0.0

Constructs a config that fails with the specified message.

Signature

declare const fail: (message: string) => Config<never>
Since v2.0.0

Constructs a config for a sequence of values.

Signature

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

Constructs a config for a sequence of values.

Signature

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

Constructs a config for a integer value.

Signature

declare const integer: (name?: string) => Config<number>
Since v2.0.0

Constructs a config for a literal value.

Signature

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

Example

import { Config } from "effect"
const config = Config.literal("http", "https")("PROTOCOL")
Since v2.0.0

Constructs a config for a LogLevel value.

Signature

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

Constructs a config for a non-empty string value.

Signature

declare const nonEmptyString: (name?: string) => Config<string>
Since v2.0.0

Constructs a config for a float value.

Signature

declare const number: (name?: string) => Config<number>
Since v3.16.0

Constructs a config for a network port [1, 65535].

Signature

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

Constructs a new primitive config.

Signature

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

Constructs a config for a redacted value.

Signature

declare const redacted: {
(name?: string): Config<Redacted<string>>;
<A>(config: Config<A>): Config<Redacted<A>>;
}
Since v2.0.0

Constructs a config for a secret value.

Signature

declare const secret: (name?: string) => Config<Secret.Secret>
Since v2.0.0

Constructs a config for a string value.

Signature

declare const string: (name?: string) => Config<string>
Since v2.0.0

Constructs a config which contains the specified value.

Signature

declare const succeed: <A>(value: A) => Config<A>
Since v2.0.0

Lazily constructs a config.

Signature

declare const suspend: <A>(config: LazyArg<Config<A>>) => Config<A>
Since v2.0.0

Constructs a config which contains the specified lazy value.

Signature

declare const sync: <A>(value: LazyArg<A>) => Config<A>
Since v2.0.0

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

For example:

Signature

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

Example

import { Config, unwrap } from "./Config"
interface Options { key: string }
const makeConfig = (config: Config.Wrap<Options>): Config<Options> => unwrap(config)
Since v3.11.0

Constructs a config for an URL value.

Signature

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

Mapping

Since v2.0.0

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

Signature

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>;
}

Models

Config

interface
Since v2.0.0

A Config describes the structure of some configuration data.

Signature

interface Config<out A> extends Variance<A>, Effect<A, ConfigError.ConfigError> {}
Since v2.0.0

Signature

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

Other

Since v2.0.0

Refinements

Since v2.0.0

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

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

Symbols

Signature

declare const ConfigTypeId: unique symbol
Since v2.0.0

Signature

type ConfigTypeId = typeof ConfigTypeId

Utils

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

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>;
}

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

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

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

Signature

declare const nested: {
(name: string): <A>(self: Config<A>) => Config<A>;
<A>(self: Config<A>, name: string): Config<A>;
}
Since v2.0.0

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

Signature

declare const option: <A>(self: Config<A>) => Config<Option.Option<A>>
Since v2.0.0

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

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>;
}
Since v2.0.0

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

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

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

Signature

declare const repeat: <A>(self: Config<A>) => Config<Array<A>>
Since v2.0.0

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

Signature

declare const validate: {
<A, B>(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>(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>;
}

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

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

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

Signature

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

Zipping

Since v2.0.0

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

Signature

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]>;
}
Since v2.0.0

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

Signature

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>;
}