(name?: string): Config<Date>Creates a config for a Date value parsed from a string.
When to use
Use to read date settings that must parse to valid Date values.
Details
Shortcut for Config.schema(Schema.DateValid, name).
Gotchas
Fails with a SchemaError if the string produces an invalid Date.
Example (Reading a date)
import { Config, ConfigProvider, Effect } from "effect"
const createdAt = Config.date("CREATED_AT")
const provider = ConfigProvider.fromUnknown({ CREATED_AT: "2024-01-15" })
// Effect.runSync(createdAt.parse(provider))
// Date("2024-01-15T00:00:00.000Z")export function function date(name?: string): Config<Date>Creates a config for a Date value parsed from a string.
When to use
Use to read date settings that must parse to valid Date values.
Details
Shortcut for Config.schema(Schema.DateValid, name).
Gotchas
Fails with a SchemaError if the string produces an invalid Date.
Example (Reading a date)
import { Config, ConfigProvider, Effect } from "effect"
const createdAt = Config.date("CREATED_AT")
const provider = ConfigProvider.fromUnknown({ CREATED_AT: "2024-01-15" })
// Effect.runSync(createdAt.parse(provider))
// Date("2024-01-15T00:00:00.000Z")
date(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 DateValid: DateValidconst DateValid: {
Rebuild: DateValid;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<Date, readonly []>) => Schema.DateValid;
annotateKey: (annotations: Schema.Annotations.Key<Date>) => Schema.DateValid;
check: (checks_0: SchemaAST.Check<Date>, ...checks: Array<SchemaAST.Check<Date>>) => Schema.DateValid;
rebuild: (ast: SchemaAST.Declaration) => Schema.DateValid;
make: (input: globalThis.Date, options?: MakeOptions) => globalThis.Date;
makeOption: (input: globalThis.Date, options?: MakeOptions) => Option_.Option<globalThis.Date>;
makeEffect: (input: globalThis.Date, options?: MakeOptions) => Effect.Effect<globalThis.Date, 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
DateValid
.
Schema for valid JavaScript Date objects.
Details
This schema accepts Date instances but rejects invalid dates (such as new
Date("invalid")).
DateValid, name: string | undefinedname)
}