Package: effect
Module: Config
Scopes a config under a named prefix.
When to use
Use when you need to group related config keys under a common namespace.
Details
The prefix is prepended to every key the inner config reads. With
fromUnknown this means an extra object level; with fromEnv it means
a _-separated prefix on env var names.
Multiple nested calls compose: the outermost name becomes the
outermost path segment.
Example (Nesting a struct config under "database")
import { Config, ConfigProvider, Effect } from "effect"
const dbConfig = Config.all({
host: Config.string("host"),
port: Config.number("port")
}).pipe(Config.nested("database"))
const provider = ConfigProvider.fromUnknown({
database: { host: "localhost", port: "5432" }
})
// Effect.runSync(dbConfig.parse(provider))
// { host: "localhost", port: 5432 }
Example (Reading env vars with a nested prefix)
import { Config, ConfigProvider, Effect } from "effect"
const host = Config.string("host").pipe(Config.nested("database"))
const provider = ConfigProvider.fromEnv({
env: { database_host: "localhost" }
})
// Effect.runSync(host.parse(provider)) // "localhost"
See
all – combine multiple configs into a structschema – read structured config from a schemaSignature
declare const nested: { (name: string): <A>(self: Config<A>) => Config<A>; <A>(self: Config<A>, name: string): Config<A>; }
Since v2.0.0