Workstream E: generate bindings.ts via reusable specta_builder + export test
- 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:
parent
57ff364f54
commit
731966246f
@ -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
2992
src/lib/api/bindings.ts
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user