Config.ts overview
Since v2.0.0
Exports Grouped by Category
constructors
all
Constructs a config from a tuple / struct / arguments of configs.
Signature
declare const all: <const Arg extends Iterable<Config<any>> | Record<string, Config<any>>>(
arg: Arg
) => Config<
[Arg] extends [ReadonlyArray<Config<any>>]
? { -readonly [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>>]
? { -readonly [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never }
: never
>
Since v2.0.0
array
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
boolean
Constructs a config for a boolean value.
Signature
declare const boolean: (name?: string) => Config<boolean>
Since v2.0.0
chunk
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
date
Constructs a config for a date value.
Signature
declare const date: (name?: string) => Config<Date>
Since v2.0.0
duration
Constructs a config for a duration value.
Signature
declare const duration: (name?: string) => Config<Duration.Duration>
Since v2.5.0
fail
Constructs a config that fails with the specified message.
Signature
declare const fail: (message: string) => Config<never>
Since v2.0.0
hashMap
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
hashSet
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
integer
Constructs a config for a integer value.
Signature
declare const integer: (name?: string) => Config<number>
Since v2.0.0
literal
Constructs a config for a literal value.
Example
import { Config } from "effect"
const config = Config.literal("http", "https")("PROTOCOL")
Signature
declare const literal: <Literals extends ReadonlyArray<LiteralValue>>(
...literals: Literals
) => (name?: string) => Config<Literals[number]>
Since v2.0.0
logLevel
Constructs a config for a LogLevel
value.
Signature
declare const logLevel: (name?: string) => Config<LogLevel.LogLevel>
Since v2.0.0
nonEmptyString
Constructs a config for a non-empty string value.
Signature
declare const nonEmptyString: (name?: string) => Config<string>
Since v3.7.0
number
Constructs a config for a float value.
Signature
declare const number: (name?: string) => Config<number>
Since v2.0.0
primitive
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
redacted
Constructs a config for a redacted value.
Signature
declare const redacted: {
(name?: string): Config<Redacted.Redacted>
<A>(config: Config<A>): Config<Redacted.Redacted<A>>
}
Since v2.0.0
secret
Constructs a config for a secret value.
Signature
declare const secret: (name?: string) => Config<Secret.Secret>
Since v2.0.0
string
Constructs a config for a string value.
Signature
declare const string: (name?: string) => Config<string>
Since v2.0.0
succeed
Constructs a config which contains the specified value.
Signature
declare const succeed: <A>(value: A) => Config<A>
Since v2.0.0
suspend
Lazily constructs a config.
Signature
declare const suspend: <A>(config: LazyArg<Config<A>>) => Config<A>
Since v2.0.0
sync
Constructs a config which contains the specified lazy value.
Signature
declare const sync: <A>(value: LazyArg<A>) => Config<A>
Since 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
declare const unwrap: <A>(wrapped: Config.Wrap<A>) => Config<A>
Since v2.0.0
url
Constructs a config for a URL value.
Signature
declare const url: (name?: string) => Config<URL>
Since v3.11.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
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>
}
Since 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> {}
Since v2.0.0
LiteralValue (type alias)
Signature
type LiteralValue = string | number | boolean | null | bigint
Since 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
declare const isConfig: (u: unknown) => u is Config<unknown>
Since v2.0.0
symbols
ConfigTypeId
Signature
declare const ConfigTypeId: unique symbol
Since v2.0.0
ConfigTypeId (type alias)
Signature
type ConfigTypeId = typeof ConfigTypeId
Since v2.0.0
utils
Config (namespace)
Since v2.0.0
Variance (interface)
Signature
export interface Variance<out A> {
readonly [ConfigTypeId]: {
readonly _A: Types.Covariant<A>
}
}
Since 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>
}
Since v2.0.0
Success (type alias)
Signature
type Success<T> = [T] extends [Config<infer _A>] ? _A : never
Since v2.5.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
type Wrap<A> = [NonNullable<A>] extends [infer T]
? [IsPlainObject<T>] extends [true]
? { readonly [K in keyof A]: Wrap<A[K]> } | Config<A>
: Config<A>
: Config<A>
Since 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
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>
}
Since 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
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>
}
Since v2.0.0
nested
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
option
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
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
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
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
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>
}
Since v2.0.0
repeat
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
validate
Returns a config that describes the same structure as this one, but which performs validation during loading.
Signature
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>
}
Since 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
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>
}
Since v2.0.0
withDescription
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>
}
Since v2.0.0
zipping
zip
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
zipWith
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>
}
Since v2.0.0