Skip to content

[pull] main from jsr-io:main#93

Merged
pull[bot] merged 1 commit into
code:mainfrom
jsr-io:main
Jun 7, 2026
Merged

[pull] main from jsr-io:main#93
pull[bot] merged 1 commit into
code:mainfrom
jsr-io:main

Conversation

@pull

@pull pull Bot commented Jun 7, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

…1431)

## Step 3 — Hyperdrive Postgres connectivity spike

Part of the API service split
([`docs/design/api-service-split.md`](https://github.com/jsr-io/jsr/blob/main/docs/design/api-service-split.md),
RFC #1414). Follows #1417 (`jsr_types` extraction) and #1429 (workers-rs
scaffold).

This PR proves the **wasm database story end-to-end**: the `api.jsr.io`
Worker opens a Postgres connection through the Cloudflare **Hyperdrive**
binding and runs a trivial `SELECT 1`. No real endpoints move yet — that
starts in step 4.

### What's here
- **`src/db.rs`** — `connect()` opens the connection via
`env.hyperdrive("HYPERDRIVE").connect()`, which returns a
`worker::Socket` (TCP to the Hyperdrive endpoint; Hyperdrive terminates
TLS to the DB origin, so we use `NoTls` — no rustls in wasm). The socket
is handed to `tokio_postgres::Config::connect_raw`, and the connection
future is driven on the Worker event loop with
`wasm_bindgen_futures::spawn_local`. `ping()` runs `SELECT 1`.
- **`Cargo.toml`** — `tokio-postgres` with **`default-features =
false`** so its native runtime (tokio `net`/`time`, `socket2`) is
excluded from the wasm build; only the wire-protocol codec we drive over
our own socket remains. `getrandom` `wasm_js` feature enabled (the SCRAM
client nonce needs an RNG, and getrandom has no default backend on
`wasm32-unknown-unknown`).
- **`src/lib.rs`** — new `GET /api/db_health` route runs the ping and
returns the echoed value; every other path still returns `501`.
- **`wrangler.toml`** — local-dev Hyperdrive binding with
`localConnectionString` pointing at the `docker-compose` Postgres, so
the DB path runs under `wrangler dev` without a Cloudflare account.

### Verification
`api-worker` CI (fmt `--check`, `clippy --target wasm32-unknown-unknown
-- -D warnings`, `cargo build --target wasm32-unknown-unknown
--release`) — all green locally on the repo-pinned toolchain (1.89.0).
The key result: **`tokio-postgres` compiles to
`wasm32-unknown-unknown`** with the feature set above.

### Deliberately deferred
The production Hyperdrive **Terraform** (`cloudflare_hyperdrive_config`
+ the Cloud SQL public-access / authorized-networks wiring it needs)
lands with the **deploy/infra PR**, where a deployed Worker actually
consumes the binding — rather than creating an orphaned Hyperdrive
config now. Flagging since the RFC sequence listed terraform under step
3; happy to fold it in here instead if preferred.
@pull pull Bot locked and limited conversation to collaborators Jun 7, 2026
@pull pull Bot added the ⤵️ pull label Jun 7, 2026
@pull pull Bot merged commit 92953f5 into code:main Jun 7, 2026
5 of 6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant