| 1 | import * as ConfigProvider from "effect/ConfigProvider"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | |
| 4 | import { reifyBoundConfigProvider } from "../../Runtime.ts"; |
| 5 | import cloudflare_workers from "./cloudflare_workers.ts"; |
| 6 | |
| 7 | /** |
| 8 | * A `ConfigProvider` backed by the running Worker's environment. |
| 9 | * |
| 10 | * Values that were auto-bound by the deploy-time `Config` interceptor |
| 11 | * arrive in the env as `{"_tag":"Redacted","value":...}` markers; they are |
| 12 | * reified back to their raw source value before `Config` schemas decode |
| 13 | * them, matching the provider the Worker bridge installs by default. |
| 14 | */ |
| 15 | export const WorkerConfigProvider = () => |
| 16 | cloudflare_workers.pipe( |
| 17 | Effect.map(({ env }) => |
| 18 | reifyBoundConfigProvider( |
| 19 | ConfigProvider.fromUnknown(env), |
| 20 | env as Record<string, unknown>, |
| 21 | ), |
| 22 | ), |
| 23 | ); |