-
Notifications
You must be signed in to change notification settings - Fork 5
Export Rust core types to TypeScript with ts-rs and update CI #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ndency installation
Reviewer's GuideAdds TypeScript type generation for Tauri backend structs/enums using ts-rs, updates CI to build on additional targets (musl & Windows GNU) with cross support, switches the Microsoft auth client ID, and tweaks a few serialization details for TS/serde interoperability. Class diagram for auth and account TypeScript-backed modelsclassDiagram
class Account {
}
<<enumeration>> Account
Account : Offline(OfflineAccount)
Account : Microsoft(MicrosoftAccount)
class OfflineAccount {
String username
String uuid
}
class MicrosoftAccount {
String username
String uuid
String access_token
String refresh_token
u64 expires_at
}
class DeviceCodeResponse {
String user_code
String device_code
String verification_uri
u64 expires_in
u64 interval
Option~String~ message
}
class TokenResponse {
String access_token
Option~String~ refresh_token
Option~u64~ expires_in
String token_type
Option~String~ scope
}
class MinecraftAuthResponse {
String username
String access_token
String token_type
u64 expires_in
}
class MinecraftProfile {
String id
String name
}
Account *-- OfflineAccount
Account *-- MicrosoftAccount
Class diagram for download and Java management models exported to TypeScriptclassDiagram
class DownloadTask {
String url
PathBuf path
u64 total_size
bool resumable
u32 segments
}
class DownloadMetadata {
String url
String file_name
u64 total_size
u64 downloaded
u32 segments
bool resumable
}
class DownloadSegment {
u64 start
u64 end
u64 downloaded
u32 index
}
class JavaDownloadProgress {
String file_name
u64 downloaded_bytes
u64 total_bytes
f32 progress
bool done
}
class PendingJavaDownload {
u32 major_version
String image_type
String jvm_impl
String os
String arch
}
class DownloadQueue {
Vec~PendingJavaDownload~ pending_downloads
}
class ProgressEvent {
String file
u64 downloaded
u64 total
f32 progress
bool done
}
class JavaInstallation {
String path
String version
String vendor
String image_type
}
class ImageType {
}
<<enumeration>> ImageType
ImageType : Jre
ImageType : Jdk
class JavaReleaseInfo {
u32 major_version
String image_type
String jvm_impl
String os
String arch
String version
String release_name
String download_url
String checksum
u64 size
bool lts
}
class JavaCatalog {
Vec~JavaReleaseInfo~ releases
Vec~u32~ available_major_versions
Vec~String~ available_image_types
Vec~String~ available_jvm_impls
}
class JavaDownloadInfo {
String version
String release_name
String download_url
String checksum
u64 size
}
DownloadQueue *-- PendingJavaDownload
JavaCatalog *-- JavaReleaseInfo
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@SourceryAI title |
Workspace change through: c46d6c52 changesets found Planned changes to release
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 2 issues, and left some high level feedback:
- The
ts_rsusage is very repetitive, especially the longexport_topaths; consider centralizing the base output directory (e.g., via a macro, helper attribute, or build script) so new types and path changes are less error‑prone. - Several fields containing arbitrary JSON are exported as
Record<string, unknown>(e.g.,natives,features,classifiers,Argumentsfields); if the frontend relies on particular keys or shapes, it may be worth tightening these TypeScript types to catch UI-side misuse earlier.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `ts_rs` usage is very repetitive, especially the long `export_to` paths; consider centralizing the base output directory (e.g., via a macro, helper attribute, or build script) so new types and path changes are less error‑prone.
- Several fields containing arbitrary JSON are exported as `Record<string, unknown>` (e.g., `natives`, `features`, `classifiers`, `Arguments` fields); if the frontend relies on particular keys or shapes, it may be worth tightening these TypeScript types to catch UI-side misuse earlier.
## Individual Comments
### Comment 1
<location> `src-tauri/src/core/game_version.rs:6-13` </location>
<code_context>
/// Represents a Fabric loader version from the Meta API.
-#[derive(Debug, Deserialize, Serialize, Clone)]
+#[derive(Debug, Deserialize, Serialize, Clone, TS)]
+#[ts(
+ export,
</code_context>
<issue_to_address>
**issue (bug_risk):** Serde-renamed fields (e.g. `majorVersion`) will be mismatched in generated TS without `ts` renames or `serde-compat`.
For types like `JavaVersion`, `serde(rename = "majorVersion")` changes the JSON field, but `ts-rs` will still emit `major_version` unless configured otherwise. This makes the generated TS types disagree with the actual API. Please either:
1) Enable `ts-rs`’s `serde-compat` feature so serde renames are mirrored automatically, or
2) Add `#[ts(rename = "majorVersion")]` (and similar `ts` renames wherever `serde(rename = ...)` is used).
Otherwise the frontend will receive `majorVersion` while the TS types expect `major_version`.
</issue_to_address>
### Comment 2
<location> `src-tauri/src/main.rs:1753-1760` </location>
<code_context>
/// Version metadata for display in the UI
-#[derive(serde::Serialize)]
+#[derive(serde::Serialize, TS)]
+#[ts(
+ export,
+ export_to = "../../packages/ui/src/types/generated/VersionMetadata.ts"
+)]
struct VersionMetadata {
id: String,
#[serde(rename = "javaVersion")]
</code_context>
<issue_to_address>
**issue (bug_risk):** Generated TS for `VersionMetadata`/`InstalledVersion` fields won’t respect serde `rename`, causing type/JSON divergence.
In `VersionMetadata` and `InstalledVersion`, fields using `#[serde(rename = ...)]` (e.g. `javaVersion`, `type`) will still be emitted by `ts-rs` as `java_version`/`r#type` unless configured. That means the generated TS types won’t match the actual JSON shape the frontend receives.
Please either enable `ts-rs`’s `serde-compat` feature globally, or add explicit `#[ts(rename = "...")]` on the renamed fields so the TS definitions align with the serialized JSON.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds TypeScript type generation from Rust backend types using the ts-rs library. The changes enable automatic generation of TypeScript definitions for all data structures used in communication between the Rust backend and the frontend UI, ensuring type safety across the Rust-TypeScript boundary.
Changes:
- Added ts-rs 11.1.0 dependency to Cargo.toml
- Annotated 40+ core Rust structs and enums with
#[derive(TS)]and export metadata - Configured TypeScript output paths to
packages/ui/src/types/generated/ - Added proper type overrides for complex types (PathBuf → string, serde_json::Value → Record<string, unknown>)
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src-tauri/Cargo.toml | Added ts-rs dependency for TypeScript type generation |
| src-tauri/src/main.rs | Added TS import and annotations for UI-facing types (VersionMetadata, InstalledVersion, GithubRelease, PastebinResponse, MigrationResult, FileInfo) |
| src-tauri/src/core/auth.rs | Annotated authentication types with TS exports including tagged Account enum; includes unrelated CLIENT_ID change |
| src-tauri/src/core/config.rs | Exported configuration types (LauncherConfig, AssistantConfig, FeatureFlags) |
| src-tauri/src/core/downloader.rs | Exported download-related types with progress tracking structures |
| src-tauri/src/core/fabric.rs | Exported Fabric loader types including loader versions, libraries, and main class enum |
| src-tauri/src/core/forge.rs | Exported Forge types with proper PathBuf→string type override |
| src-tauri/src/core/game_version.rs | Exported comprehensive game version types with Record<string, unknown> overrides for serde_json::Value fields |
| src-tauri/src/core/instance.rs | Exported instance/profile configuration types |
| src-tauri/src/core/java.rs | Exported Java installation and catalog types with ImageType enum |
| src-tauri/src/core/manifest.rs | Exported Mojang version manifest types |
| src-tauri/src/core/assistant.rs | Exported AI assistant message and model types |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewed-by: Claude-Sonnet-4.5
- Split monolithic java.rs (1089 lines) into focused modules - detection: Java installation discovery - validation: Version validation and requirements checking - priority: Installation selection priority logic - provider: Java download provider trait - providers: Provider implementations (Adoptium) - persistence: Cache and catalog management - Add java_path_override field to Instance struct for per-instance Java configuration - Export JavaInstallation at core module level This refactoring improves maintainability and prepares for multi-vendor Java provider support. Reviewed-by: Claude Sonnet 4.5
- Centralize strip_unc_prefix into java/mod.rs to eliminate duplication across detection.rs and validation.rs - Remove unused JAVA_CHECK_TIMEOUT constant from validation.rs - Implement actual timeout mechanism in run_which_command_with_timeout() using try_wait() loop - Parallelize Adoptium API requests for better catalog fetch performance Fixes: - Multiple strip_unc_prefix implementations consolidated - Timeout constant now properly enforced in which/where command execution - Catalog fetching now uses concurrent tokio::spawn tasks instead of sequential await Reviewed-by: Claude Sonnet 4.5
- Add #[allow(dead_code)] attributes to utility functions - Improve 64-bit detection with case-insensitive check - Support aarch64 architecture in bitness detection - Add TODO for future vendor expansion Reviewed-by: Claude Sonnet 4.5
Replace potentially panicking unwrap() call with expect() that includes a descriptive error message to aid debugging if the edge case occurs. Reviewed-by: Claude Sonnet 4.5
…r handling - Extract version compatibility check into shared validation function - Remove duplicated version checking code across multiple modules - Simplify Java detection timeout logic in detection.rs - Expand vendor detection to support more JDK distributions (Dragonwell, Kona, Semeru, BiSheng, etc.) - Refactor start_game to use priority-based Java resolution - Improve error handling in Adoptium provider task collection Reviewed-by: Claude Sonnet 4.5
- Added support for detecting Java installations from SDKMAN! in `find_sdkman_java`. - Improved `run_which_command_with_timeout` to handle command timeouts gracefully. - Introduced a unified `JavaError` enum for consistent error handling across Java operations. - Updated functions to return `Result` types instead of `Option` for better error reporting. - Enhanced `load_cached_catalog` and `save_catalog_cache` to use `JavaError`. - Refactored `fetch_java_catalog`, `fetch_java_release`, and `fetch_available_versions` to return `JavaError`. - Improved validation functions to return detailed errors when checking Java installations. - Added tests for version parsing and compatibility checks. - Updated `resolve_java_for_launch` to handle instance-specific and global Java paths.
…eanup - Add CACHE_VERSION constant for cache format compatibility tracking - Add MAX_CACHE_SIZE_BYTES limit (10 MB) to prevent unbounded cache growth - Add cache_version field to JavaCatalog struct with default value - Implement cache version validation in load_cached_catalog() - Implement cache size enforcement in save_catalog_cache() - Add cleanup_expired_caches() for background cache cleanup - Add enforce_cache_size_limit() to validate cache file sizes - Add is_cache_version_compatible() helper function - Automatically clean up expired caches on load and clear operations - Validate cache version before using cached data Fixes: - Cache expiration without automatic cleanup (now cleaned on load) - Missing cache version control (now validates format compatibility) - Unbounded cache size growth (now limited to 10 MB) Reviewed-by: Claude 3.5 Sonnet
- Extract JavaError to dedicated error.rs module - Add serde defaults for JavaInstallation optional fields - Replace unwrap() with proper error propagation - Add detailed logging for Java resolution priority chain - Improve error mapping in validation (NotFound vs VerificationFailed) Reviewed-by: Claude Sonnet 4.5
- Export JavaError from java module - Fix type mismatches in Adoptium provider methods - Add type annotations for reqwest json() calls - Remove non-existent cache_version field from JavaCatalog - Fix resolve_java_for_launch call signature (remove extra window param) - Add error conversion to String for Tauri commands - Fix import for save_catalog_cache in adoptium.rs Reviewed-by: Claude Sonnet 4.5
Integrate Java runtime refactoring changes: - Modular Java detection and management system - Adoptium Java provider with automatic download - Instance-level Java path overrides - Priority-based Java resolution - Enhanced error handling with JavaError type - Cache management with versioning This merge combines the ts-rs TypeScript bindings work from PR HydroRoll-Team#77 with the comprehensive Java runtime improvements from PR HydroRoll-Team#82.
Summary by Sourcery
Export backend data structures to TypeScript for the new React-based UI and update CI to build additional targets.
New Features:
Enhancements:
Build:
CI: