better ts adapters

This commit is contained in:
Aiden McClelland
2025-11-07 16:43:14 -07:00
parent 7667b1adaf
commit eb64c1f422
4 changed files with 348 additions and 27 deletions

View File

@@ -1,5 +1,7 @@
use clap::Parser;
use rpc_toolkit::{from_fn_async, Context, Empty, HandlerTS, ParentHandler, Server};
use rpc_toolkit::{
from_fn, from_fn_async, Context, Empty, HandlerExt, HandlerTS, ParentHandler, Server,
};
use serde::{Deserialize, Serialize};
use yajrc::RpcError;
@@ -14,10 +16,19 @@ struct Thing1Params {
thing: String,
}
#[derive(Debug, Deserialize, Serialize, Parser)]
struct NoTSParams {
foo: String,
}
async fn thing1_handler(_ctx: TestContext, params: Thing1Params) -> Result<String, RpcError> {
Ok(format!("Thing1 is {}", params.thing))
}
fn no_ts_handler(_ctx: TestContext, params: NoTSParams) -> Result<String, RpcError> {
Ok(format!("foo:{}", params.foo))
}
#[derive(Debug, Deserialize, Serialize, Parser)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
struct GroupParams {
@@ -38,7 +49,8 @@ async fn test_basic_server() {
from_fn_async(|_ctx: TestContext, params: GroupParams| async move {
Ok::<_, RpcError>(format!("verbose: {}", params.verbose))
}),
),
)
.subcommand("no-ts", from_fn(no_ts_handler).no_ts()),
);
println!("{}", root_handler.type_info().unwrap_or_default());