diff --git a/.cargo/config.toml b/.cargo/config.toml index ddff4407..1d15640e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,10 @@ [build] rustflags = ["-C", "target-cpu=native"] + +# ts-rs writes the TypeScript bindings here (relative = resolved against the +# repo root, not the invocation directory). The subdirectory keeps room for +# bindings in other languages later. An explicitly set TS_RS_EXPORT_DIR (as +# devtools export-ts-types does) still wins: cargo only applies this default +# when the variable is unset. +[env] +TS_RS_EXPORT_DIR = { value = "bindings/ts", relative = true } diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index a92068f9..6409ada6 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -24,9 +24,10 @@ jobs: - name: Run tests run: cargo test --verbose - # cargo test regenerates bindings/ (ts-rs), so a diff here means the - # committed TypeScript bindings are stale — commit the regenerated files - - name: Check TypeScript bindings are up to date + # cargo test regenerates bindings/ts/ (ts-rs), so a diff here means the + # committed bindings are stale — commit the regenerated files. The check + # covers all of bindings/ so future languages get it for free. + - name: Check bindings are up to date run: git diff --exit-code bindings/ - name: Build diff --git a/AGENTS.md b/AGENTS.md index 55764523..98031812 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -193,16 +193,16 @@ Useful when you want to see if a patch actually works on production-shaped data ### Rust version The project does not pin its Rust version. Contributors should use a recent stable Rust toolchain with `rustfmt` and `clippy` components installed. -## TypeScript Bindings (`bindings/`) +## TypeScript Bindings (`bindings/ts/`) Committed, generated TypeScript definitions for the v4 REST types consumed by the btcmap.org frontend (see the README section "TypeScript bindings" for the full picture). Rules when working here: -- Never edit `bindings/*.ts` by hand — they are ts-rs output, regenerated by +- Never edit `bindings/ts/*.ts` by hand — they are ts-rs output, regenerated by every `cargo test` run. CI fails if the committed files don't match the code. - When you change a struct that derives `ts_rs::TS`, run `cargo test` and - commit the updated `bindings/` files in the same commit. + commit the updated `bindings/ts/` files in the same commit. - New exported structs follow the conventions: `#[ts(type = "number")]` on i64/u64 fields, `#[ts(type = "string")]` on RFC 3339 timestamp fields, `#[ts(optional)]` on `Option` fields with `skip_serializing_if`, and diff --git a/README.md b/README.md index 2f84918f..9316734c 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ The `devtools` script provides helper commands for development: | `gen-main-schema` | Generate `schema.sql` from migrations | | `export-ts-types [dir]` | Export the TypeScript bindings to a directory | -### TypeScript bindings (`bindings/`) +### TypeScript bindings (`bindings/ts/`) -`bindings/` contains TypeScript definitions for the v4 REST types that +`bindings/ts/` contains TypeScript definitions for the v4 REST types that [btcmap.org](https://github.com/teambtcmap/btcmap.org) consumes. They are **generated, not hand-written**: structs annotated with `#[derive(ts_rs::TS)]` are exported by [ts-rs](https://github.com/Aleph-Alpha/ts-rs) every time @@ -115,7 +115,7 @@ never goes stale silently — CI fails if a commit leaves it out of date. How the pieces fit: - **Changing an exported struct?** Run `cargo test` (or - `devtools export-ts-types`), and commit the updated `bindings/` files along + `devtools export-ts-types`), and commit the updated `bindings/ts/` files along with your change. The diff doubles as a readable record of the API change. - **Adding a new response type for the frontend?** Add `#[derive(ts_rs::TS)]` + `#[ts(export)]` to the struct. Conventions: @@ -124,6 +124,8 @@ How the pieces fit: modules get `#[ts(rename = "...")]` so every binding file is unique. Export is opt-in per struct — types not meant for third-party use simply don't get the derive. +- **Other languages:** the `ts/` subdirectory leaves room for bindings in + other languages (Kotlin, Swift, ...) to live alongside it under `bindings/`. - **Consuming the types?** The frontend fetches this directory from GitHub (`pnpm types:api` in btcmap.org) — no Rust toolchain or checkout of this repo required. Any other client can do the same. diff --git a/bindings/ActivityItem.ts b/bindings/ts/ActivityItem.ts similarity index 100% rename from bindings/ActivityItem.ts rename to bindings/ts/ActivityItem.ts diff --git a/bindings/Area.ts b/bindings/ts/Area.ts similarity index 100% rename from bindings/Area.ts rename to bindings/ts/Area.ts diff --git a/bindings/AreaSearchResult.ts b/bindings/ts/AreaSearchResult.ts similarity index 100% rename from bindings/AreaSearchResult.ts rename to bindings/ts/AreaSearchResult.ts diff --git a/bindings/AuthNostrResponse.ts b/bindings/ts/AuthNostrResponse.ts similarity index 100% rename from bindings/AuthNostrResponse.ts rename to bindings/ts/AuthNostrResponse.ts diff --git a/bindings/ChangePasswordArgs.ts b/bindings/ts/ChangePasswordArgs.ts similarity index 100% rename from bindings/ChangePasswordArgs.ts rename to bindings/ts/ChangePasswordArgs.ts diff --git a/bindings/ChartEntry.ts b/bindings/ts/ChartEntry.ts similarity index 100% rename from bindings/ChartEntry.ts rename to bindings/ts/ChartEntry.ts diff --git a/bindings/Community.ts b/bindings/ts/Community.ts similarity index 100% rename from bindings/Community.ts rename to bindings/ts/Community.ts diff --git a/bindings/Country.ts b/bindings/ts/Country.ts similarity index 100% rename from bindings/Country.ts rename to bindings/ts/Country.ts diff --git a/bindings/CreateTokenArgs.ts b/bindings/ts/CreateTokenArgs.ts similarity index 100% rename from bindings/CreateTokenArgs.ts rename to bindings/ts/CreateTokenArgs.ts diff --git a/bindings/CreateTokenResponse.ts b/bindings/ts/CreateTokenResponse.ts similarity index 100% rename from bindings/CreateTokenResponse.ts rename to bindings/ts/CreateTokenResponse.ts diff --git a/bindings/CreateUserArgs.ts b/bindings/ts/CreateUserArgs.ts similarity index 100% rename from bindings/CreateUserArgs.ts rename to bindings/ts/CreateUserArgs.ts diff --git a/bindings/CreateUserResponse.ts b/bindings/ts/CreateUserResponse.ts similarity index 100% rename from bindings/CreateUserResponse.ts rename to bindings/ts/CreateUserResponse.ts diff --git a/bindings/Dashboard.ts b/bindings/ts/Dashboard.ts similarity index 100% rename from bindings/Dashboard.ts rename to bindings/ts/Dashboard.ts diff --git a/bindings/Invoice.ts b/bindings/ts/Invoice.ts similarity index 100% rename from bindings/Invoice.ts rename to bindings/ts/Invoice.ts diff --git a/bindings/MeResponse.ts b/bindings/ts/MeResponse.ts similarity index 100% rename from bindings/MeResponse.ts rename to bindings/ts/MeResponse.ts diff --git a/bindings/NostrIdentityResponse.ts b/bindings/ts/NostrIdentityResponse.ts similarity index 100% rename from bindings/NostrIdentityResponse.ts rename to bindings/ts/NostrIdentityResponse.ts diff --git a/bindings/PaginationInfo.ts b/bindings/ts/PaginationInfo.ts similarity index 100% rename from bindings/PaginationInfo.ts rename to bindings/ts/PaginationInfo.ts diff --git a/bindings/Place.ts b/bindings/ts/Place.ts similarity index 100% rename from bindings/Place.ts rename to bindings/ts/Place.ts diff --git a/bindings/PlaceActivity.ts b/bindings/ts/PlaceActivity.ts similarity index 100% rename from bindings/PlaceActivity.ts rename to bindings/ts/PlaceActivity.ts diff --git a/bindings/PlaceArea.ts b/bindings/ts/PlaceArea.ts similarity index 100% rename from bindings/PlaceArea.ts rename to bindings/ts/PlaceArea.ts diff --git a/bindings/PlaceBoostQuote.ts b/bindings/ts/PlaceBoostQuote.ts similarity index 100% rename from bindings/PlaceBoostQuote.ts rename to bindings/ts/PlaceBoostQuote.ts diff --git a/bindings/PlaceComment.ts b/bindings/ts/PlaceComment.ts similarity index 100% rename from bindings/PlaceComment.ts rename to bindings/ts/PlaceComment.ts diff --git a/bindings/PlaceCommentListItem.ts b/bindings/ts/PlaceCommentListItem.ts similarity index 100% rename from bindings/PlaceCommentListItem.ts rename to bindings/ts/PlaceCommentListItem.ts diff --git a/bindings/PlaceCommentQuote.ts b/bindings/ts/PlaceCommentQuote.ts similarity index 100% rename from bindings/PlaceCommentQuote.ts rename to bindings/ts/PlaceCommentQuote.ts diff --git a/bindings/PlaceIssue.ts b/bindings/ts/PlaceIssue.ts similarity index 100% rename from bindings/PlaceIssue.ts rename to bindings/ts/PlaceIssue.ts diff --git a/bindings/PlaceIssueSummary.ts b/bindings/ts/PlaceIssueSummary.ts similarity index 100% rename from bindings/PlaceIssueSummary.ts rename to bindings/ts/PlaceIssueSummary.ts diff --git a/bindings/PlaceIssuesRes.ts b/bindings/ts/PlaceIssuesRes.ts similarity index 100% rename from bindings/PlaceIssuesRes.ts rename to bindings/ts/PlaceIssuesRes.ts diff --git a/bindings/PostPlaceBoostArgs.ts b/bindings/ts/PostPlaceBoostArgs.ts similarity index 100% rename from bindings/PostPlaceBoostArgs.ts rename to bindings/ts/PostPlaceBoostArgs.ts diff --git a/bindings/PostPlaceBoostResponse.ts b/bindings/ts/PostPlaceBoostResponse.ts similarity index 100% rename from bindings/PostPlaceBoostResponse.ts rename to bindings/ts/PostPlaceBoostResponse.ts diff --git a/bindings/PostPlaceCommentArgs.ts b/bindings/ts/PostPlaceCommentArgs.ts similarity index 100% rename from bindings/PostPlaceCommentArgs.ts rename to bindings/ts/PostPlaceCommentArgs.ts diff --git a/bindings/PostPlaceCommentResponse.ts b/bindings/ts/PostPlaceCommentResponse.ts similarity index 100% rename from bindings/PostPlaceCommentResponse.ts rename to bindings/ts/PostPlaceCommentResponse.ts diff --git a/bindings/SavedArea.ts b/bindings/ts/SavedArea.ts similarity index 100% rename from bindings/SavedArea.ts rename to bindings/ts/SavedArea.ts diff --git a/bindings/SavedPlace.ts b/bindings/ts/SavedPlace.ts similarity index 100% rename from bindings/SavedPlace.ts rename to bindings/ts/SavedPlace.ts diff --git a/bindings/SearchResponse.ts b/bindings/ts/SearchResponse.ts similarity index 100% rename from bindings/SearchResponse.ts rename to bindings/ts/SearchResponse.ts diff --git a/bindings/SearchResult.ts b/bindings/ts/SearchResult.ts similarity index 100% rename from bindings/SearchResult.ts rename to bindings/ts/SearchResult.ts diff --git a/bindings/SearchedArea.ts b/bindings/ts/SearchedArea.ts similarity index 100% rename from bindings/SearchedArea.ts rename to bindings/ts/SearchedArea.ts diff --git a/bindings/SearchedPlace.ts b/bindings/ts/SearchedPlace.ts similarity index 100% rename from bindings/SearchedPlace.ts rename to bindings/ts/SearchedPlace.ts diff --git a/bindings/TopEditor.ts b/bindings/ts/TopEditor.ts similarity index 100% rename from bindings/TopEditor.ts rename to bindings/ts/TopEditor.ts diff --git a/bindings/UpdateUsernameArgs.ts b/bindings/ts/UpdateUsernameArgs.ts similarity index 100% rename from bindings/UpdateUsernameArgs.ts rename to bindings/ts/UpdateUsernameArgs.ts