Skip to content

Config

44 exports Added in v2.0.0 Source

Constructors

all

Added in v2.0.0 Source

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

array

Added in v2.0.0 Source

Constructs a config for an array of values.

Signature

declare const array: <A>(config: Config<A>, name?: string) => Config<Array<A>>;

boolean

Added in v2.0.0 Source

Constructs a config for a boolean value.

Signature

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

branded

Added in v3.16.0 Source

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

chunk

Added in v2.0.0 Source

Constructs a config for a sequence of values.

Signature

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

date

Added in v2.0.0 Source

Constructs a config for a date value.

Signature

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

duration

Added in v2.5.0 Source

Constructs a config for a duration value.

Signature

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

fail

Added in v2.0.0 Source

Constructs a config that fails with the specified message.

Signature

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

hashMap

Added in v2.0.0 Source

Constructs a config for a sequence of values.

Signature

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

hashSet

Added in v2.0.0 Source

Constructs a config for a sequence of values.

Signature

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

integer

Added in v2.0.0 Source

Constructs a config for a integer value.

Signature

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

literal

Added in v2.0.0 Source

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")

logLevel

Added in v2.0.0 Source

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

number

Added in v2.0.0 Source

Constructs a config for a float value.

Signature

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

port

Added in v3.16.0 Source

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

Signature

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

primitive

Added in v2.0.0 Source

Constructs a new primitive config.

Signature

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

redacted

Added in v2.0.0 Source

Constructs a config for a redacted value.

Signature

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

secret

Added in v2.0.0 Source

Constructs a config for a secret value.

Signature

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

string

Added in v2.0.0 Source

Constructs a config for a string value.

Signature

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

succeed

Added in v2.0.0 Source

Constructs a config which contains the specified value.

Signature

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

suspend

Added in v2.0.0 Source

Lazily constructs a config.

Signature

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

sync

Added in v2.0.0 Source

Constructs a config which contains the specified lazy value.

Signature

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

unwrap

Added in v2.0.0 Source

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)

url

Added in v3.11.0 Source

Constructs a config for an URL value.

Signature

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

Mapping

map

Added in v2.0.0 Source

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

Added in v2.0.0 Source

A Config describes the structure of some configuration data.

Signature

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

LiteralValue type

Added in v2.0.0 Source

Signature

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

Other

Config

Added in v2.0.0 Source

Refinements

isConfig

Added in v2.0.0 Source

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

ConfigTypeId

Added in v2.0.0 Source

Signature

declare const ConfigTypeId: unique symbol;

ConfigTypeId type

Added in v2.0.0 Source

Signature

type ConfigTypeId = typeof ConfigTypeId;

Utils

mapAttempt

Added in v2.0.0 Source

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

mapOrFail

Added in v2.0.0 Source

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

nested

Added in v2.0.0 Source

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

option

Added in v2.0.0 Source

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

orElse

Added in v2.0.0 Source

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

orElseIf

Added in v2.0.0 Source

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

repeat

Added in v2.0.0 Source

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

validate

Added in v2.0.0 Source

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

withDefault

Added in v2.0.0 Source

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

zip

Added in v2.0.0 Source

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

zipWith

Added in v2.0.0 Source

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