| 1 | import type * as Effect from "effect/Effect"; |
| 2 | |
| 3 | /** |
| 4 | * Typed `env` for an async (non-Effect) {@link Function}. Railway |
| 5 | * bindings are environment variables, so every entry is a `string` — |
| 6 | * the same object the handler receives as its second argument |
| 7 | * (`process.env` keys declared on `env`). |
| 8 | * |
| 9 | * Analogous to `Cloudflare.InferEnv`, which maps env entries onto native |
| 10 | * Worker bindings. Railway has only env vars, so the mapping is 1:1 to |
| 11 | * `string`. |
| 12 | * |
| 13 | * @example |
| 14 | * ```typescript |
| 15 | * export const Ping = Railway.Function("Ping", { |
| 16 | * project: Site, |
| 17 | * main: "./src/ping.ts", |
| 18 | * env: { DATABASE_URL: db.connectionUri }, |
| 19 | * }); |
| 20 | * export type PingEnv = Railway.InferEnv<typeof Ping>; |
| 21 | * ``` |
| 22 | */ |
| 23 | export type InferEnv<F> = |
| 24 | F extends Effect.Effect<infer A, infer _E, infer _R> |
| 25 | ? InferEnv<A> |
| 26 | : F extends { readonly Props: { readonly env?: infer E } } |
| 27 | ? InferEnvRecord<Exclude<E, undefined>> |
| 28 | : InferEnvRecord<F>; |
| 29 | |
| 30 | type InferEnvRecord<E> = { |
| 31 | readonly [K in keyof E]: string; |
| 32 | }; |