feat: generate typed frontend API contracts
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
use std::fmt::Write as _;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use trx_core::radio::freq::{Band, Freq};
|
||||
use trx_core::rig::state::{SpectrumData, VchanRdsEntry};
|
||||
use trx_core::rig::{
|
||||
RigAccessMethod, RigCapabilities, RigInfo, RigRxStatus, RigStatus, RigTxStatus, RigVfo,
|
||||
RigVfoEntry,
|
||||
};
|
||||
use trx_core::{DecoderConfig, RdsData, RigFilterState, RigMode, RigSnapshot, WfmDenoiseLevel};
|
||||
use trx_frontend_http::server::api::rig::{RigListItem, RigListResponse};
|
||||
use trx_protocol::{DecoderActivation, DecoderDescriptor};
|
||||
use ts_rs::{Config, TS};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut output = String::from(
|
||||
"// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>\n\
|
||||
//\n\
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later\n\n\
|
||||
// Generated by `cargo run -p trx-frontend-http --example generate_typescript`.\n\
|
||||
// Do not edit manually.\n\n",
|
||||
);
|
||||
let config = Config::default();
|
||||
|
||||
macro_rules! export {
|
||||
($type:ty) => {
|
||||
writeln!(output, "export {}\n", <$type as TS>::decl(&config))?;
|
||||
};
|
||||
}
|
||||
|
||||
export!(Band);
|
||||
export!(Freq);
|
||||
export!(RigMode);
|
||||
export!(RigAccessMethod);
|
||||
export!(RigCapabilities);
|
||||
export!(RigInfo);
|
||||
export!(RigVfoEntry);
|
||||
export!(RigVfo);
|
||||
export!(RigTxStatus);
|
||||
export!(RigRxStatus);
|
||||
export!(RigStatus);
|
||||
export!(DecoderConfig);
|
||||
export!(WfmDenoiseLevel);
|
||||
export!(RigFilterState);
|
||||
export!(RdsData);
|
||||
export!(SpectrumData);
|
||||
export!(VchanRdsEntry);
|
||||
export!(RigSnapshot);
|
||||
export!(RigListItem);
|
||||
export!(RigListResponse);
|
||||
export!(DecoderActivation);
|
||||
export!(DecoderDescriptor);
|
||||
|
||||
let output_path =
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("frontend/src/api/generated.ts");
|
||||
fs::create_dir_all(output_path.parent().expect("generated file has a parent"))?;
|
||||
fs::write(output_path, output)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user