/**
* @since 1.0.0
*/
import type * as Chunk from "@effect/data/Chunk"
import type * as Either from "@effect/data/Either"
import type { LazyArg } from "@effect/data/Function"
import type * as HashMap from "@effect/data/HashMap"
import type * as HashSet from "@effect/data/HashSet"
import type * as Option from "@effect/data/Option"
import type { Pipeable } from "@effect/data/Pipeable"
import type { Predicate, Refinement } from "@effect/data/Predicate"
import type * as ConfigError from "@effect/io/ConfigError"
import type * as ConfigSecret from "@effect/io/ConfigSecret"
import * as internal from "@effect/io/internal/config"
import type * as LogLevel from "@effect/io/LogLevel"
/**
* @since 1.0.0
* @category symbols
*/
export const ConfigTypeId: unique symbol = internal.ConfigTypeId
/**
* @since 1.0.0
* @category symbols
*/
export type ConfigTypeId = typeof ConfigTypeId
/**
* A `Config` describes the structure of some configuration data.
*
* @since 1.0.0
* @category models
*/
export interface Config extends Config.Variance, Pipeable {}
/**
* @since 1.0.0
*/
export declare namespace Config {
/**
* @since 1.0.0
* @category models
*/
export interface Variance {
readonly [ConfigTypeId]: {
readonly _A: (_: never) => A
}
}
/**
* @since 1.0.0
* @category models
*/
export interface Primitive extends Config {
readonly description: string
parse(text: string): Either.Either
}
/**
* Wraps a nested structure, converting all primitives to a `Config`.
*
* `Config.Wrap<{ key: string }>` becomes `{ key: Config }`
*
* To create the resulting config, use the `unwrap` constructor.
*
* @since 1.0.0
* @category models
*/
export type Wrap =
| (A extends Record ? {
[K in keyof A]: Wrap
}
: never)
| Config
}
/**
* Constructs a config from a tuple / struct / arguments of configs.
*
* @since 1.0.0
* @category constructors
*/
export const all: > | Record>>(
arg: Arg
) => Config<
[Arg] extends [ReadonlyArray>] ? {
-readonly [K in keyof Arg]: [Arg[K]] extends [Config] ? A : never
}
: [Arg] extends [Iterable>] ? Array
: [Arg] extends [Record>] ? {
-readonly [K in keyof Arg]: [Arg[K]] extends [Config] ? A : never
}
: never
> = internal.all
/**
* Constructs a config for an array of values.
*
* @since 1.0.0
* @category constructors
*/
export const array: (config: Config, name?: string | undefined) => Config> = internal.array
/**
* Constructs a config for a boolean value.
*
* @since 1.0.0
* @category constructors
*/
export const boolean: (name?: string | undefined) => Config = internal.boolean
/**
* Constructs a config for a sequence of values.
*
* @since 1.0.0
* @category constructors
*/
export const chunk: (config: Config, name?: string | undefined) => Config> = internal.chunk
/**
* Constructs a config for a date value.
*
* @since 1.0.0
* @category constructors
*/
export const date: (name?: string | undefined) => Config = internal.date
/**
* Constructs a config that fails with the specified message.
*
* @since 1.0.0
* @category constructors
*/
export const fail: (message: string) => Config = internal.fail
/**
* Constructs a config for a float value.
*
* @since 1.0.0
* @category constructors
*/
export const number: (name?: string | undefined) => Config = internal.number
/**
* Constructs a config for a integer value.
*
* @since 1.0.0
* @category constructors
*/
export const integer: (name?: string | undefined) => Config = internal.integer
/**
* Constructs a config for a `LogLevel` value.
*
* @since 1.0.0
* @category constructors
*/
export const logLevel: (name?: string | undefined) => Config = internal.logLevel
/**
* 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.
*
* @param u - The value to check for being a `Config` value.
*
* @returns `true` if the specified value is a `Config` value, `false`
* otherwise.
*
* @since 1.0.0
* @category refinements
*/
export const isConfig: (u: unknown) => u is Config = internal.isConfig
/**
* Returns a config whose structure is the same as this one, but which produces
* a different value, constructed using the specified function.
*
* @since 1.0.0
* @category utils
*/
export const map: {
(f: (a: A) => B): (self: Config) => Config
(self: Config, f: (a: A) => B): Config
} = internal.map
/**
* 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.
*
* @since 1.0.0
* @category utils
*/
export const mapAttempt: {
(f: (a: A) => B): (self: Config) => Config
(self: Config, f: (a: A) => B): Config
} = internal.mapAttempt
/**
* 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.
*
* @since 1.0.0
* @category utils
*/
export const mapOrFail: {
(f: (a: A) => Either.Either): (self: Config) => Config
(self: Config, f: (a: A) => Either.Either): Config
} = internal.mapOrFail
/**
* Returns a config that has this configuration nested as a property of the
* specified name.
*
* @since 1.0.0
* @category utils
*/
export const nested: {
(name: string): (self: Config) => Config
(self: Config, name: string): Config
} = internal.nested
/**
* 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.
*
* @since 1.0.0
* @category utils
*/
export const orElse: {
(that: LazyArg>): (self: Config) => Config
(self: Config, that: LazyArg>): Config
} = internal.orElse
/**
* 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.
*
* @since 1.0.0
* @category utils
*/
export const orElseIf: {
(
options: {
readonly if: Predicate
readonly orElse: LazyArg>
}
): (self: Config) => Config
(
self: Config,
options: {
readonly if: Predicate
readonly orElse: LazyArg>
}
): Config
} = internal.orElseIf
/**
* Returns an optional version of this config, which will be `None` if the
* data is missing from configuration, and `Some` otherwise.
*
* @since 1.0.0
* @category utils
*/
export const option: (self: Config) => Config> = internal.option
/**
* Constructs a new primitive config.
*
* @since 1.0.0
* @category constructors
*/
export const primitive: (
description: string,
parse: (text: string) => Either.Either
) => Config = internal.primitive
/**
* Returns a config that describes a sequence of values, each of which has the
* structure of this config.
*
* @since 1.0.0
* @category utils
*/
export const repeat: (self: Config) => Config> = internal.repeat
/**
* Constructs a config for a secret value.
*
* @since 1.0.0
* @category constructors
*/
export const secret: (name?: string | undefined) => Config = internal.secret
/**
* Constructs a config for a sequence of values.
*
* @since 1.0.0
* @category constructors
*/
export const hashSet: (config: Config, name?: string | undefined) => Config> = internal.hashSet
/**
* Constructs a config for a string value.
*
* @since 1.0.0
* @category constructors
*/
export const string: (name?: string | undefined) => Config = internal.string
/**
* Constructs a config which contains the specified value.
*
* @since 1.0.0
* @category constructors
*/
export const succeed: (value: A) => Config = internal.succeed
/**
* Lazily constructs a config.
*
* @since 1.0.0
* @category constructors
*/
export const suspend: (config: LazyArg>) => Config = internal.suspend
/**
* Constructs a config which contains the specified lazy value.
*
* @since 1.0.0
* @category constructors
*/
export const sync: (value: LazyArg) => Config = internal.sync
/**
* Constructs a config for a sequence of values.
*
* @since 1.0.0
* @category constructors
*/
export const hashMap: (config: Config, name?: string | undefined) => Config> =
internal.hashMap
/**
* Constructs a config from some configuration wrapped with the `Wrap` utility type.
*
* For example:
*
* ```
* import { Config, unwrap } from "@effect/io/Config"
*
* interface Options { key: string }
*
* const makeConfig = (config: Config.Wrap): Config => unwrap(config)
* ```
*
* @since 1.0.0
* @category constructors
*/
export const unwrap: (wrapped: Config.Wrap) => Config = internal.unwrap
/**
* Returns a config that describes the same structure as this one, but which
* performs validation during loading.
*
* @since 1.0.0
* @category utils
*/
export const validate: {
(
options: {
readonly message: string
readonly validation: Refinement
}
): (self: Config) => Config
(options: {
readonly message: string
readonly validation: Predicate
}): (self: Config) => Config
(
self: Config,
options: {
readonly message: string
readonly validation: Refinement
}
): Config
(self: Config, options: {
readonly message: string
readonly validation: Predicate
}): Config
} = internal.validate
/**
* Returns a config that describes the same structure as this one, but has the
* specified default value in case the information cannot be found.
*
* @since 1.0.0
* @category utils
*/
export const withDefault: {
(def: A2): (self: Config) => Config
(self: Config, def: A2): Config
} = internal.withDefault
/**
* Adds a description to this configuration, which is intended for humans.
*
* @since 1.0.0
* @category utils
*/
export const withDescription: {
(description: string): (self: Config) => Config
(self: Config, description: string): Config
} = internal.withDescription
/**
* Returns a config that is the composition of this config and the specified
* config.
*
* @since 1.0.0
* @category utils
*/
export const zip: {
(that: Config): (self: Config) => Config
(self: Config, that: Config): Config
} = internal.zip
/**
* Returns a config that is the composes this config and the specified config
* using the provided function.
*
* @since 1.0.0
* @category utils
*/
export const zipWith: {
(that: Config, f: (a: A, b: B) => C): (self: Config) => Config
(self: Config, that: Config, f: (a: A, b: B) => C): Config
} = internal.zipWith