Workstream E: generate bindings.ts via reusable specta_builder + export test
Some checks failed
🏗️ Build and Test JellyTau / Run Tests (push) Failing after 3m41s
🏗️ Build and Test JellyTau / Build Android APK (push) Has been skipped
Traceability Validation / Check Requirement Traces (push) Failing after 48s

- Extract specta_builder() so run() and a #[test] share one command list.
- Add export_typescript_bindings test that writes src/lib/api/bindings.ts.
- Configure the TS exporter bigint behavior to Number (matches existing frontend).
- Commit the generated bindings.ts (typed commands.* wrappers + all DTO types).
This commit is contained in:
Duncan Tourolle 2026-06-20 18:25:54 +02:00
parent 57ff364f54
commit 731966246f
2 changed files with 3023 additions and 10 deletions

View File

@ -347,14 +347,10 @@ fn create_player_backend(
} }
} }
#[cfg_attr(mobile, tauri::mobile_entry_point)] /// Construct the tauri-specta command builder. Shared by `run()` and the
pub fn run() { /// bindings-export test so the TypeScript bindings always match the handler.
// Initialize logger fn specta_builder() -> Builder<tauri::Wry> {
env_logger::Builder::from_default_env() Builder::<tauri::Wry>::new()
.filter_level(log::LevelFilter::Info)
.init();
let builder = Builder::<tauri::Wry>::new()
.commands(tauri_specta::collect_commands![ .commands(tauri_specta::collect_commands![
// Player commands // Player commands
player_play_item, player_play_item,
@ -580,12 +576,22 @@ pub fn run() {
convert_ticks_to_seconds, convert_ticks_to_seconds,
calc_progress, calc_progress,
convert_percent_to_volume, convert_percent_to_volume,
]); ])
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
// Initialize logger
env_logger::Builder::from_default_env()
.filter_level(log::LevelFilter::Info)
.init();
let builder = specta_builder();
// Export TypeScript bindings (types + typed invoke wrappers) in dev builds. // Export TypeScript bindings (types + typed invoke wrappers) in dev builds.
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
builder builder
.export(specta_typescript::Typescript::default(), "../src/lib/api/bindings.ts") .export(specta_typescript::Typescript::default().bigint(specta_typescript::BigIntExportBehavior::Number), "../src/lib/api/bindings.ts")
.expect("Failed to export typescript bindings"); .expect("Failed to export typescript bindings");
tauri::Builder::default() tauri::Builder::default()
@ -835,3 +841,18 @@ pub fn run() {
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }
#[cfg(test)]
mod specta_bindings {
/// Generates `src/lib/api/bindings.ts`. Run with `cargo test export_typescript_bindings`.
#[test]
fn export_typescript_bindings() {
super::specta_builder()
.export(
specta_typescript::Typescript::default().bigint(specta_typescript::BigIntExportBehavior::Number),
"../src/lib/api/bindings.ts",
)
.expect("failed to export typescript bindings");
}
}

2992
src/lib/api/bindings.ts Normal file

File diff suppressed because it is too large Load Diff