(name?: string): Config<string>Creates a config for a non-empty string value. Fails if the value is an empty string.
When to use
Use to read a string config value that must contain at least one character.
Details
Shortcut for Config.schema(Schema.NonEmptyString, name).
export function function nonEmptyString(
name?: string
): Config<string>
Creates a config for a non-empty string value. Fails if the value is an
empty string.
When to use
Use to read a string config value that must contain at least one character.
Details
Shortcut for Config.schema(Schema.NonEmptyString, name).
nonEmptyString(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 NonEmptyString: NonEmptyStringconst NonEmptyString: {
Rebuild: NonEmptyString;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.NonEmptyString;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.NonEmptyString;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.NonEmptyString;
rebuild: (ast: SchemaAST.String) => Schema.NonEmptyString;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, 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
NonEmptyString
.
Schema for non-empty strings. Validates that a string has at least one
character.
NonEmptyString, name: string | undefinedname)
}