(name?: string): Config<URL>Creates a config for a URL value parsed from a string.
When to use
Use to read configuration values that must be valid URL strings.
Details
This is a shortcut for Config.schema(Schema.URL, name).
Gotchas
Fails if the string cannot be parsed by the URL constructor.
Example (Reading a URL)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const url = yield* Config.url("URL")
console.log(url)
})
const provider = ConfigProvider.fromEnv({
env: {
URL: "https://example.com"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output:
// URL {
// href: 'https://example.com/',
// origin: 'https://example.com',
// protocol: 'https:',
// username: '',
// password: '',
// host: 'example.com',
// hostname: 'example.com',
// port: '',
// pathname: '/',
// search: '',
// searchParams: URLSearchParams {},
// hash: ''
// }export function function url(name?: string): Config<URL>Creates a config for a URL value parsed from a string.
When to use
Use to read configuration values that must be valid URL strings.
Details
This is a shortcut for Config.schema(Schema.URL, name).
Gotchas
Fails if the string cannot be parsed by the URL constructor.
Example (Reading a URL)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const url = yield* Config.url("URL")
console.log(url)
})
const provider = ConfigProvider.fromEnv({
env: {
URL: "https://example.com"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output:
// URL {
// href: 'https://example.com/',
// origin: 'https://example.com',
// protocol: 'https:',
// username: '',
// password: '',
// host: 'example.com',
// hostname: 'example.com',
// port: '',
// pathname: '/',
// search: '',
// searchParams: URLSearchParams {},
// hash: ''
// }
url(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 URL: URLconst URL: {
Rebuild: URL;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<URL, readonly []>) => Schema.URL;
annotateKey: (annotations: Schema.Annotations.Key<URL>) => Schema.URL;
check: (checks_0: SchemaAST.Check<URL>, ...checks: Array<SchemaAST.Check<URL>>) => Schema.URL;
rebuild: (ast: SchemaAST.Declaration) => Schema.URL;
make: (input: globalThis.URL, options?: MakeOptions) => globalThis.URL;
makeOption: (input: globalThis.URL, options?: MakeOptions) => Option_.Option<globalThis.URL>;
makeEffect: (input: globalThis.URL, options?: MakeOptions) => Effect.Effect<globalThis.URL, 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
URL
.
Schema for JavaScript URL objects.
Details
Default JSON serializer:
- encodes
URL as a string
URL, name: string | undefinedname)
}