import { pipe } from "effect/Function"; import * as Array from "effect/Array"; import * as ConfigProvider from "effect/ConfigProvider"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; declare const process: { env: Record }; /** * A `ConfigProvider` that reads configuration directly from `process.env` by * exact path lookup. * * The Convex runtime exposes `process.env` for direct key access but does not * make it enumerable, so the built-in `ConfigProvider.fromEnv` (which builds a * trie over the environment to resolve and enumerate config paths) cannot be * used. This provider resolves each requested path to a single environment * variable, joining the path segments with `"_"` to match the key convention * `fromEnv` uses. As with the built-in providers, an empty string is treated as * a missing value, so `Config.withDefault` and `Config.option` recover from * it. */ export const make = (): ConfigProvider.ConfigProvider => ConfigProvider.make((path) => { const value = process.env[pipe(path, Array.map(String), Array.join("_"))]; return Effect.succeed( value === undefined || value === "" ? undefined : ConfigProvider.makeValue(value), ); }); /** * Installs the Convex-aware `ConfigProvider` as the ambient provider. */ export const layer: Layer.Layer = Layer.succeed( ConfigProvider.ConfigProvider, make(), );