(name?: string): Config<Duration>Creates a config for a Duration value parsed from a human-readable
string.
When to use
Use to read time duration settings such as timeouts, intervals, or TTLs.
Details
Shortcut for Config.schema(Schema.DurationFromString, name).
Accepts any string that Duration.fromInput can parse (e.g.
"10 seconds", "500 millis", "Infinity", "-Infinity").
Example (Reading a duration)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const duration = yield* Config.duration("DURATION")
console.log(duration)
})
const provider = ConfigProvider.fromEnv({
env: {
DURATION: "10 seconds"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output: Duration { _tag: "millis", value: 10000 }export function function duration(
name?: string
): Config<Duration>
Creates a config for a Duration value parsed from a human-readable
string.
When to use
Use to read time duration settings such as timeouts, intervals, or TTLs.
Details
Shortcut for Config.schema(Schema.DurationFromString, name).
Accepts any string that Duration.fromInput can parse (e.g.
"10 seconds", "500 millis", "Infinity", "-Infinity").
Example (Reading a duration)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const duration = yield* Config.duration("DURATION")
console.log(duration)
})
const provider = ConfigProvider.fromEnv({
env: {
DURATION: "10 seconds"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output: Duration { _tag: "millis", value: 10000 }
duration(name: string | undefinedname?: string) {
return function schema<T>(
codec: Schema.ConstraintCodec<T, unknown>,
path?: string | ConfigProvider.Path
): Config<T>
Creates a Config<T> from a Schema.Codec.
When to use
Use when you need to read structured or schema-validated configuration.
Details
The optional path sets the local path segment(s) for the config lookup.
It is appended to the logical path prefix accumulated from outer
nested
calls. Pass a single string for a flat key or an array for
nested paths.
Convenience constructors such as string, number, and boolean delegate
to this API.
The codec is used to decode the raw StringTree produced by the provider
into T. Schema validation errors are wrapped in ConfigError.
Example (Reading a structured config)
import { Config, ConfigProvider, Effect, Schema } from "effect"
const DbConfig = Config.schema(
Schema.Struct({
host: Schema.String,
port: Schema.Int
}),
"db"
)
const provider = ConfigProvider.fromUnknown({
db: { host: "localhost", port: 5432 }
})
// Effect.runSync(DbConfig.parse(provider))
// { host: "localhost", port: 5432 }
schema(import SchemaSchema.const DurationFromString: DurationFromStringconst DurationFromString: {
Rebuild: DurationFromString;
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Duration, readonly []>) => Schema.DurationFromString;
annotateKey: (annotations: Schema.Annotations.Key<Duration>) => Schema.DurationFromString;
check: (checks_0: SchemaAST.Check<Duration>, ...checks: Array<SchemaAST.Check<Duration>>) => Schema.DurationFromString;
rebuild: (ast: SchemaAST.Declaration) => Schema.DurationFromString;
make: (input: Duration_.Duration, options?: MakeOptions) => Duration_.Duration;
makeOption: (input: Duration_.Duration, options?: MakeOptions) => Option_.Option<Duration_.Duration>;
makeEffect: (input: Duration_.Duration, options?: MakeOptions) => Effect.Effect<Duration_.Duration, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
DurationFromString
.
Schema that parses a string into a Duration.
Details
Decoding:
- A
string is decoded as a Duration, accepting any format that
Duration.fromInput can parse.
Encoding:
- A
Duration is encoded as a parseable string.
DurationFromString, name: string | undefinedname)
}