[036-ts-types-from-rust]: Generate TypeScript types from Rust via ts-rs#46
[036-ts-types-from-rust]: Generate TypeScript types from Rust via ts-rs#46archae0pteryx merged 3 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR wires ts-rs-based TypeScript generation: it adds Cargo env/config and an optional ts-rs feature, annotates domain types for conditional export, introduces a domain ChangesTypeScript Generation from Rust
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Cargo as Cargo / Rust test
participant Domain as crates/domain (ts-rs)
participant FS as src/types/generated (filesystem)
participant CI as CI / Taskfile
Dev->>Cargo: run `cargo test -p adhd-ranch-domain --features export-ts`
Cargo->>Domain: enable `export-ts` feature, execute ts-rs export tests
Domain->>FS: write generated `.ts` files to `src/types/generated` (TS_RS_EXPORT_DIR)
Dev->>CI: push branch
CI->>CI: run `task gen-types:check`
CI->>FS: verify `git diff --exit-code -- src/types/generated` and no untracked files
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
Adds an optional `export-ts` feature on `crates/domain` that derives
`ts_rs::TS` for every shared domain type. `cargo test -p adhd-ranch-domain
--features export-ts` writes `.ts` files into `src/types/generated/`,
driven by `TS_RS_EXPORT_DIR` and `TS_RS_LARGE_INT=number` configured
in `.cargo/config.toml`.
The hand-written `src/types/{focus,timer,proposal,settings,monitor}.ts`
now re-export from `generated/`. `src/types/timer.ts` retains the
`PRESET_OPTIONS` runtime constant alongside the type re-exports.
`MonitorInfo` moved from `src-tauri/src/ui_bridge/` into
`crates/domain/src/monitor.rs` so it can be annotated with the rest.
Taskfile gains `gen-types` and `gen-types:check`; the latter is wired
into `task check` to fail when committed `src/types/generated/*.ts`
drifts from Rust.
ts-rs is pinned to `12` rather than the `10` the issue mentioned —
v10/11 lack `TS_RS_LARGE_INT`, so `u64`/`i64` would have leaked into
TS as `bigint` and broken existing call sites that pass `number`.
Closes #38.
99966af to
0bf85f7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src-tauri/src/ui_bridge/mod.rs (1)
256-264:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winPopulate all required
MonitorInfofields inget_monitors.At Line 261, the
adhd_ranch_domain::MonitorInfoliteral only setsidxandlabel, but the domain struct includes additional fields (primary,position,size). This is a correctness blocker (compile failure or incomplete payload).Proposed fix
pub fn get_monitors(app: AppHandle<Wry>) -> Vec<MonitorInfo> { app.try_state::<crate::app::MonitorsState>() .map(|s| { s.0.iter() .enumerate() .map(|(i, m)| MonitorInfo { idx: i, label: m.label.clone(), + primary: m.primary, + position: m.position, + size: m.size, }) .collect() }) .unwrap_or_default() }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src-tauri/src/ui_bridge/mod.rs` around lines 256 - 264, The MonitorInfo literal returned by get_monitors only sets idx and label; update the map closure inside get_monitors (the code using app.try_state::<crate::app::MonitorsState>() and iterating s.0) to populate the remaining fields on adhd_ranch_domain::MonitorInfo—set primary from m.primary, position from m.position (or construct the expected position type from m.x/m.y if needed), and size from m.size (or m.width/m.height) so all required fields (primary, position, size) are filled and types are converted/cloned as required.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Taskfile.yaml`:
- Around line 35-40: The drift check currently runs "git diff --exit-code --
src/types/generated" which ignores untracked files and lets newly generated .ts
files slip through; update the gen-types:check task to also detect untracked
files under src/types/generated (e.g., by running git ls-files --others
--exclude-standard -- src/types/generated and failing if it returns any paths,
or by using git status --porcelain and failing on lines starting with "?") so
the task fails when new generated files are present; change the command sequence
in the gen-types:check task to include this additional check after the gen-types
step.
---
Outside diff comments:
In `@src-tauri/src/ui_bridge/mod.rs`:
- Around line 256-264: The MonitorInfo literal returned by get_monitors only
sets idx and label; update the map closure inside get_monitors (the code using
app.try_state::<crate::app::MonitorsState>() and iterating s.0) to populate the
remaining fields on adhd_ranch_domain::MonitorInfo—set primary from m.primary,
position from m.position (or construct the expected position type from m.x/m.y
if needed), and size from m.size (or m.width/m.height) so all required fields
(primary, position, size) are filled and types are converted/cloned as required.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3f6289f6-4ea1-4aba-9149-4d4a07b6773d
⛔ Files ignored due to path filters (17)
Cargo.lockis excluded by!**/*.locksrc/types/generated/Alerts.tsis excluded by!**/generated/**src/types/generated/Caps.tsis excluded by!**/generated/**src/types/generated/DisplayConfig.tsis excluded by!**/generated/**src/types/generated/Focus.tsis excluded by!**/generated/**src/types/generated/FocusId.tsis excluded by!**/generated/**src/types/generated/FocusTimer.tsis excluded by!**/generated/**src/types/generated/MonitorInfo.tsis excluded by!**/generated/**src/types/generated/NewFocus.tsis excluded by!**/generated/**src/types/generated/Proposal.tsis excluded by!**/generated/**src/types/generated/ProposalId.tsis excluded by!**/generated/**src/types/generated/ProposalKind.tsis excluded by!**/generated/**src/types/generated/Settings.tsis excluded by!**/generated/**src/types/generated/Task.tsis excluded by!**/generated/**src/types/generated/TimerPreset.tsis excluded by!**/generated/**src/types/generated/TimerStatus.tsis excluded by!**/generated/**src/types/generated/Widget.tsis excluded by!**/generated/**
📒 Files selected for processing (29)
.cargo/config.tomlTaskfile.yamlbiome.jsoncrates/domain/Cargo.tomlcrates/domain/src/focus.rscrates/domain/src/lib.rscrates/domain/src/monitor.rscrates/domain/src/proposal.rscrates/domain/src/settings.rscrates/domain/src/timer.rsissues/README.mdissues/done/036-ts-types-from-rust.mdsrc-tauri/src/ui_bridge/mod.rssrc/api/fixtureFocusReader.test.tssrc/api/tauriFocusReader.tssrc/components/App.test.tsxsrc/components/EditProposalModal.test.tsxsrc/components/FocusCard.test.tsxsrc/components/FocusList.test.tsxsrc/components/PendingTray.test.tsxsrc/components/PigDetail.test.tsxsrc/hooks/useAppState.test.tsxsrc/hooks/useFocuses.test.tsxsrc/lib/capState.test.tssrc/types/focus.tssrc/types/monitor.tssrc/types/proposal.tssrc/types/settings.tssrc/types/timer.ts
CodeRabbit on PR #46: `git diff --exit-code` ignores untracked files, so a newly annotated Rust type that produces a brand-new `.ts` could slip through CI. Add an explicit `git ls-files --others` check.
Closes #38. Implements
issues/036-ts-types-from-rust.md.Summary
export-tsfeature oncrates/domainthat derivests_rs::TSforFocus,Task,FocusId,FocusTimer,TimerPreset,TimerStatus,Proposal,ProposalKind,NewFocus,ProposalId,Settings,Caps,Widget,Alerts,DisplayConfig, andMonitorInfo.cargo test -p adhd-ranch-domain --features export-tswrites.tsfiles intosrc/types/generated/(env in.cargo/config.toml:TS_RS_EXPORT_DIR,TS_RS_LARGE_INT=number).MonitorInfomoved fromsrc-tauri/src/ui_bridge/tocrates/domain/src/monitor.rsso it can ride the same export path.src/types/{focus,timer,proposal,settings,monitor}.tsnow re-export fromgenerated/.timer.tskeeps thePRESET_OPTIONSruntime constant.Taskfile.yamlgainsgen-typesandgen-types:check. The latter is wired intotask checkand fails when committedsrc/types/generated/*.tsdrifts from Rust.Notes
12not10. v10/11 lackTS_RS_LARGE_INT, sou64/i64would have leaked asbigintand broken existing call sites.Focusnow requirescreated_at. Test fixtures acrosssrc/**/*.test.{ts,tsx}andsrc/api/tauriFocusReader.tswere updated to populate the field.src/types/generated/is committed (gitignoring it would defeat the diff-check).biome.jsonignores the directory for formatting.Test plan
task check(lint + typecheck + tests + ts-rs drift check) green locally.cargo test -p adhd-ranch-domain --features export-tsregenerates the same files (no diff).npm run typecheckclean.Acceptance criteria
ts-rsadded as optional dep tocrates/domain.#[ts]behindexport-tsfeature.cargo test -p adhd-ranch-domain --features export-tsgenerates correct.tsfiles.src/types/focus.ts,proposal.ts,timer.tsreplaced by generated equivalents.src/types/settings.tsandsrc/types/monitor.ts(added in 032) also generated.task gen-types:check).task checkgreen.Summary by CodeRabbit
Refactor
Chores
Tests / CI