Skip to content

Commit c7e0ec8

Browse files
Refactor codegen (#68)
* bring back Status enum * refactor codgen * remove static code from codegen * more cleanup * Polish truapi codegen display naming * Fix typecheck and playground default for resource allocation example - Use value: undefined (not null) for unit variants of the mixed AllocatableResource enum in the rustdoc client example so the generated example file typechecks under tsc -p tsconfig.examples.json. - Drop the post-JSON collapse_tag_only_objects step in the playground codegen. It was over-eager: any { tag: "X" } object was rewritten to the bare string "X", which breaks mixed enums where the wire codec requires a tagged object. Unit-only enums already render as bare strings at the source. - Remove stray empty doc lines in calls.rs, local_storage.rs and permissions.rs, and reformat the rustdoc display-name test per nightly rustfmt. * Replace consecutive writeln! blocks with writedoc! The explorer registry and playground services writers had many multi-line writeln! formats for adjacent fixed-shape lines. Group those into single writedoc! blocks with named arguments. Generated output is byte-identical. * Collapse more multi-writeln blocks in ts.rs - Use writedoc! for the three-line generic codec function definition. - Use named-capture interpolation so single multi-line writeln! formats collapse to one line. - Fold the wire_version response decode branch into one writeln! with a conditional suffix. - Fold write_payload_field's two branches into a single writeln! by building the encoded argument up front. - Collapse the trailing close-brace + blank-line pair after each generated client class into one writeln!. * Make value optional for unit variants of mixed enums Generated types now emit `{ tag: "X"; value?: undefined }` for unit variants in mixed enums, so consumers can write `{ tag: "X" }` without the `value: undefined` placeholder. To keep the codec assignable to the public type: - Add S.TaggedUnion in scale.ts that wraps scale-ts's Enum and narrows unit-variant codecs (Codec<undefined>) to `value?: undefined`. - Refine indexedTaggedUnion's variant type the same way, so versioned wrappers with V<N>(_void) variants follow the same convention. Update the resource_allocation rustdoc example accordingly. * rename truapiCall -> System * flatten * merge apis * rename * rename path / get rid legcacy * Fix codegen drift and refresh explorer icon map - Normalize single-quoted TS string literals to double-quoted JSON in playground default-request extraction so examples like `message: '{"jsonrpc":...}'` round-trip through serde_json. - Apply nightly rustfmt to api/payment.rs, api/statement_store.rs, and v01/chain.rs. - Update explorer group icons for the renamed groups (account, chain) and add icons for entropy, json-rpc, permissions, resource-allocation, theme, transaction. * fix * fix rewiring * rm reordering * fix * remove explorer * fix clippy * fix clippy ref * remove hard-coded service fields * playground: fix Transaction → Signing method routing The `Transaction` trait was merged back into `Signing` but the playground bridge and auto-test still referenced `"transaction"` as a `TrUApiClient` key, causing a TS build failure. Route `create_transaction` and `create_transaction_with_legacy_account` through `signing` to match the generated client. --------- Co-authored-by: Filippo Vecchiato <filippo@parity.io>
1 parent a0ed249 commit c7e0ec8

180 files changed

Lines changed: 10074 additions & 15423 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/skills/regen-codegen/SKILL.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: regen-codegen
3-
description: Regenerate the @parity/truapi TypeScript client and playground/explorer metadata from the truapi crate's rustdoc JSON. Use whenever the Rust trait surface changes.
3+
description: Regenerate the @parity/truapi TypeScript client and playground metadata from the truapi crate's rustdoc JSON. Use whenever the Rust trait surface changes.
44
---
55

66
# Regenerate the TypeScript client
@@ -14,7 +14,7 @@ not change rustdoc output) or purely TS-side.
1414
```
1515

1616
Expected output: `Generated client at js/packages/truapi/src/generated/`,
17-
`Generated playground metadata ...`, `Generated explorer registry ...`.
17+
`Generated playground metadata ...`.
1818

1919
The script is `cargo +nightly rustdoc --output-format json`
2020
`truapi-codegen``prettier --write``npm run build` in
@@ -24,8 +24,7 @@ The script is `cargo +nightly rustdoc --output-format json` →
2424

2525
```bash
2626
git status js/packages/truapi/src/generated \
27-
js/packages/truapi/src/playground \
28-
js/packages/truapi/src/explorer
27+
js/packages/truapi/src/playground
2928
git diff js/packages/truapi/src/generated/
3029
```
3130

.claude/skills/truapi-definition-of-done/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ git submodule update --init --recursive
3030
cargo commands clean.
3131
- [ ] **Codegen** — only if Rust trait surface changed. Invoke the
3232
`regen-codegen` skill, then commit
33-
`js/packages/truapi/src/{generated,playground,explorer}/`.
33+
`js/packages/truapi/src/{generated,playground}/`.
3434
- [ ] **`@parity/truapi`** — invoke the `ts-client-checks` skill.
3535
`npm run build && npm test` clean.
3636
- [ ] **Playground snapshot** — only if codegen ran or

.github/workflows/ci.yml

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ jobs:
2424

2525
- uses: dtolnay/rust-toolchain@nightly
2626
with:
27-
components: rustfmt
27+
components: rustfmt, clippy
2828

2929
- uses: dtolnay/rust-toolchain@stable
30-
with:
31-
components: clippy
3230

3331
- uses: Swatinem/rust-cache@v2
3432

@@ -38,8 +36,8 @@ jobs:
3836
- name: cargo +nightly fmt --check
3937
run: cargo +nightly fmt --check
4038

41-
- name: cargo clippy
42-
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
39+
- name: cargo +nightly clippy
40+
run: cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings
4341

4442
- name: cargo test
4543
run: cargo test --workspace --all-features
@@ -70,13 +68,11 @@ jobs:
7068
run: |
7169
if ! git diff --quiet --exit-code -- \
7270
js/packages/truapi/src/generated \
73-
js/packages/truapi/src/playground \
74-
js/packages/truapi/src/explorer; then
71+
js/packages/truapi/src/playground; then
7572
echo "::error::Generated TypeScript is out of date. Run ./scripts/codegen.sh and commit the result."
7673
git --no-pager diff -- \
7774
js/packages/truapi/src/generated \
78-
js/packages/truapi/src/playground \
79-
js/packages/truapi/src/explorer
75+
js/packages/truapi/src/playground
8076
exit 1
8177
fi
8278
@@ -132,29 +128,6 @@ jobs:
132128
working-directory: playground
133129
run: yarn lint
134130

135-
explorer:
136-
name: Explorer (build + lint)
137-
runs-on: ubuntu-latest
138-
needs: ts-client
139-
steps:
140-
- uses: actions/checkout@v4
141-
142-
- uses: actions/setup-node@v4
143-
with:
144-
node-version: 22
145-
146-
- name: Build @parity/truapi
147-
run: npm ci --prefix js/packages/truapi && npm run build --prefix js/packages/truapi
148-
149-
- name: Install explorer deps
150-
run: npm ci --prefix explorer
151-
152-
- name: Build
153-
run: npm run build --prefix explorer
154-
155-
- name: Lint
156-
run: npm run lint --prefix explorer
157-
158131
e2e:
159132
name: E2E (playground inside dotli)
160133
# Temporarily disabled while the dotli playground smoke test is stabilized.

.github/workflows/deploy-docs.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: pages
10+
cancel-in-progress: false
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- uses: dtolnay/rust-toolchain@stable
24+
25+
- uses: Swatinem/rust-cache@v2
26+
27+
- name: Configure Pages
28+
uses: actions/configure-pages@v5
29+
30+
- name: Build Rust API docs
31+
run: cargo doc -p truapi --no-deps
32+
33+
- name: Redirect site root to crate docs
34+
run: |
35+
cat > target/doc/index.html <<'EOF'
36+
<!doctype html>
37+
<html lang="en">
38+
<head>
39+
<meta charset="utf-8">
40+
<meta http-equiv="refresh" content="0; url=./truapi/">
41+
<link rel="canonical" href="./truapi/">
42+
<title>TrUAPI Docs</title>
43+
</head>
44+
<body>
45+
<p>Redirecting to <a href="./truapi/">TrUAPI docs</a>…</p>
46+
</body>
47+
</html>
48+
EOF
49+
cp target/doc/index.html target/doc/404.html
50+
touch target/doc/.nojekyll
51+
52+
- name: Upload Pages artifact
53+
uses: actions/upload-pages-artifact@v3
54+
with:
55+
path: target/doc
56+
57+
deploy:
58+
needs: build
59+
runs-on: ubuntu-latest
60+
environment:
61+
name: github-pages
62+
url: ${{ steps.deployment.outputs.page_url }}
63+
steps:
64+
- name: Deploy to GitHub Pages
65+
id: deployment
66+
uses: actions/deploy-pages@v4

.github/workflows/deploy-explorer.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

CLAUDE.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ rust/crates/
1313
truapi-macros/ #[wire(id = N)] proc-macro
1414
js/packages/
1515
truapi/ @parity/truapi TS package; src/generated/ produced by truapi-codegen
16-
explorer/ Vite documentation explorer; deploys to GitHub Pages
17-
playground/ Next.js interactive explorer; deploys to truapi-playground.dot
16+
playground/ Next.js interactive playground; deploys to truapi-playground.dot
1817
hosts/dotli/ dotli submodule
1918
docs/ design docs, RFCs, feature proposals
2019
scripts/codegen.sh regenerate the TS client from the Rust crate
@@ -24,6 +23,8 @@ scripts/codegen.sh regenerate the TS client from the Rust crate
2423

2524
- Every `pub` Rust item (functions, methods, types, traits, modules, constants) carries a doc comment (`///` or `//!`).
2625
Keep it short and focused on intent or invariants, not on what the signature already says.
26+
- Do not add code comments or doc comments that narrate migrations, compatibility shims, or historical changes. Comments should describe only the current code.
27+
- Remove legacy compatibility code by default. Keep or add it only when explicitly requested.
2728
- In Rust format strings, prefer inlined variables: `"log value: {value:?}"` over `"log value: {:?}", value`.
2829

2930
## First-time setup
@@ -48,7 +49,7 @@ When the Rust trait surface changes, rerun:
4849
```
4950

5051
That will repopulate `js/packages/truapi/src/generated/`. Commit the regenerated files alongside the Rust changes.
51-
It also regenerates playground metadata in `js/packages/truapi/src/playground/` and explorer metadata in `js/packages/truapi/src/explorer/`.
52+
It also regenerates playground metadata in `js/packages/truapi/src/playground/codegen/`.
5253
After regenerating, rebuild the client and refresh the playground's link copy:
5354

5455
```bash
@@ -65,7 +66,7 @@ After regenerating, rebuild the client and refresh the playground's link copy:
6566
```bash
6667
cargo build --workspace
6768
cargo +nightly fmt --check
68-
cargo clippy --workspace --all-targets -- -D warnings
69+
cargo clippy --workspace --all-targets --all-features -- -D warnings
6970
cargo test --workspace
7071
```
7172

@@ -95,16 +96,7 @@ submodule init + `bun install` and the per-pane `cd` discipline).
9596
Alternatively, with a deployed Polkadot Desktop Host installed, navigate to
9697
`https://dot.li/localhost:3000` from within it.
9798

98-
### Explorer
99-
100-
```bash
101-
cd explorer
102-
npm run dev # Vite dev server
103-
npm run build # static GitHub Pages build to dist/
104-
npm run lint # TypeScript checks
105-
```
106-
10799
## Deployment
108100

109-
Pushes to `main` trigger `.github/workflows/deploy.yml`, which builds `playground/` and publishes the static export to `truapi-playground.dot` via `bulletin-deploy`.
110-
Pushes to `main` also trigger `.github/workflows/deploy-explorer.yml`, which builds `explorer/` and publishes it to GitHub Pages.
101+
Pushes to `main` trigger `.github/workflows/deploy-playground.yml`, which builds `playground/` and publishes the static export to `truapi-playground.dot` via `bulletin-deploy`.
102+
Pushes to `main` also trigger `.github/workflows/deploy-docs.yml`, which publishes the Rust API docs to GitHub Pages.

CONTRIBUTING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Canonical design documentation lives in `docs/design/`. To propose updates or ad
4444
### Prerequisites
4545

4646
- Rust toolchain (stable + nightly for `cargo fmt`)
47-
- Node.js and npm (for the TypeScript client and explorer)
47+
- Node.js and npm (for the TypeScript client)
4848
- Yarn 1.x (for the playground)
4949

5050
### Repository layout
@@ -56,8 +56,7 @@ rust/crates/
5656
truapi-macros/ #[wire(id = N)] proc-macro
5757
js/packages/
5858
truapi/ @parity/truapi TypeScript package (src/generated/ is auto-generated)
59-
explorer/ Vite documentation explorer (GitHub Pages)
60-
playground/ Next.js interactive explorer
59+
playground/ Next.js interactive playground
6160
hosts/dotli/ dotli host (git submodule)
6261
scripts/codegen.sh regenerate the TS client from the Rust crate
6362
```
@@ -109,7 +108,7 @@ TrUAPI protocol. When you modify traits or types there:
109108
# Rust
110109
cargo build --workspace
111110
cargo +nightly fmt --check
112-
cargo clippy --workspace --all-targets -- -D warnings
111+
cargo clippy --workspace --all-targets --all-features -- -D warnings
113112
cargo test --workspace
114113

115114
# TypeScript client

Cargo.lock

Lines changed: 26 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[workspace]
22
resolver = "2"
33
members = ["rust/crates/*"]
4+
5+
[workspace.package]
6+
edition = "2024"

0 commit comments

Comments
 (0)