| 1 | import * as Railway from "@/Railway"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as pathe from "pathe"; |
| 4 | import { Partition, Site } from "./suite-env.ts"; |
| 5 | import { Db } from "./postgres-shared.ts"; |
| 6 | |
| 7 | export { 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 | */ |
| 18 | export 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 | |
| 34 | export type PostgresFnEnv = Railway.InferEnv<typeof PostgresFn>; |