1import * as Railway from "@/Railway";
2import * as Effect from "effect/Effect";
3import * as pathe from "pathe";
4import { Partition, Site } from "./suite-env.ts";
5import { Db } from "./postgres-shared.ts";
6
7export { Db, Site };
8
9/**
10 * Async (non-Effect) canvas Function. Postgres is declared on `env` as a
11 * string URI — Railway has no native bindings, so {@link Railway.InferEnv}
12 * maps every key to `string`. The handler in `async-postgres.ts` reads
13 * `env.DATABASE_URL` with plain `pg`.
14 *
15 * Props are an Effect so `Db` is yielded first and `connectionUri` is a
16 * resolved Output (not a nested Effect that `toEnvRecord` would drop).
17 */
18export const PostgresFn = Railway.Function(
19 "PostgresFn",
20 Effect.gen(function* () {
21 const db = yield* Db;
22 return {
23 project: Site,
24 environment: Partition,
25 main: pathe.resolve(import.meta.dirname, "async-postgres.ts"),
26 env: {
27 DATABASE_URL: db.connectionUri,
28 },
29 build: { install: ["pg"] },
30 };
31 }),
32);
33
34export type PostgresFnEnv = Railway.InferEnv<typeof PostgresFn>;