(
get: (path: Path) => Effect.Effect<Node | undefined, SourceError>
): ConfigProviderCreates a ConfigProvider from a raw lookup function.
When to use
Use when implementing a provider backed by a custom store, such as a database, remote API, or in-memory map.
Details
The get callback receives a Path and must return
Effect<Node | undefined, SourceError>. Return undefined when the path
does not exist; fail with SourceError only for actual I/O errors.
Example (Creating a simple in-memory provider)
import { ConfigProvider, Effect } from "effect"
const data: Record<string, string> = {
host: "localhost",
port: "5432"
}
const provider = ConfigProvider.make((path) => {
const key = path.join(".")
const value = data[key]
return Effect.succeed(
value !== undefined ? ConfigProvider.makeValue(value) : undefined
)
})export function function make(
get: (
path: Path
) => Effect.Effect<
Node | undefined,
SourceError
>
): ConfigProvider
Creates a ConfigProvider from a raw lookup function.
When to use
Use when implementing a provider backed by a custom store, such as a
database, remote API, or in-memory map.
Details
The get callback receives a Path and must return
Effect<Node | undefined, SourceError>. Return undefined when the path
does not exist; fail with SourceError only for actual I/O errors.
Example (Creating a simple in-memory provider)
import { ConfigProvider, Effect } from "effect"
const data: Record<string, string> = {
host: "localhost",
port: "5432"
}
const provider = ConfigProvider.make((path) => {
const key = path.join(".")
const value = data[key]
return Effect.succeed(
value !== undefined ? ConfigProvider.makeValue(value) : undefined
)
})
make(get: (
path: Path
) => Effect.Effect<Node | undefined, SourceError>
get: (path: Path(parameter) path: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<string | number>>): Array<string | number>; (...items: Array<string | number | ConcatArray<string | number>>): Array<string | number> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<string | number>;
indexOf: (searchElement: string | number, fromIndex?: number) => number;
lastIndexOf: (searchElement: string | number, fromIndex?: number) => number;
every: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) =>…;
some: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => void, thisArg?: any) => void;
map: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): Array<S>; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, th…;
reduce: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
reduceRight: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
find: { (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, t…;
findIndex: (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, string | number]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<string | number>;
includes: (searchElement: string | number, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: string | number, index: number, array: Array<string | number>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => string | number | undefined;
findLast: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknow…;
findLastIndex: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
toReversed: () => Array<string | number>;
toSorted: (compareFn?: ((a: string | number, b: string | number) => number) | undefined) => Array<string | number>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<string | number>): Array<string | number>; (start: number, deleteCount?: number): Array<string | number> };
with: (index: number, value: string | number) => Array<string | number>;
}
path: type Path = readonly (string | number)[]An ordered sequence of string or numeric segments that addresses a node in
the configuration tree. String segments name object keys; numeric segments
index into arrays.
When to use
Use to address raw configuration nodes when implementing or transforming a
ConfigProvider.
Example (A typical config path)
import type { ConfigProvider } from "effect"
const path: ConfigProvider.Path = ["database", "replicas", 0, "host"]
Path) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<type Node =
| {
readonly _tag: "Value"
readonly value: string
}
| {
readonly _tag: "Record"
readonly keys: ReadonlySet<string>
readonly value: string | undefined
}
| {
readonly _tag: "Array"
readonly length: number
readonly value: string | undefined
}
A discriminated union describing the shape of a configuration value at a
given path.
When to use
Use when implementing a custom ConfigProvider by returning raw
nodes from the get callback passed to
make
, or when inspecting raw
provider output before schema parsing.
Details
Value is a terminal string leaf. Record is an object-like container
whose immediate child keys are known and may carry an optional co-located
value. Array is an indexed container with a known length and may also
carry an optional co-located value.
Node | undefined, class SourceErrorclass SourceError {
name: string;
message: string;
stack: string;
cause: unknown;
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; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
}
Typed error indicating that a configuration source could not be read.
When to use
Use when you need to report that a custom provider's underlying store is
unreachable or produced an I/O error while reading configuration data.
Gotchas
Do not use SourceError for "key not found". That case is represented by
returning undefined from load.
Example (Failing with a SourceError)
import { ConfigProvider, Effect } from "effect"
const provider = ConfigProvider.make((_path) =>
Effect.fail(
new ConfigProvider.SourceError({ message: "connection refused" })
)
)
SourceError>): ConfigProvider {
return function makeSource(
get: (
path: Path
) => Effect.Effect<
Node | undefined,
SourceError
>,
transform: (path: Path) => Path
): ConfigProvider
makeSource(get: (
path: Path
) => Effect.Effect<Node | undefined, SourceError>
get, const identityPath: (path: Path) => PathidentityPath)
}