Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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 }
7 changes: 4 additions & 3 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading