mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 10:21:55 +00:00
better TS
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#![recursion_limit = "512"]
|
||||
|
||||
use clap::Parser;
|
||||
use rpc_toolkit::ts::HandlerTSBindings;
|
||||
use rpc_toolkit::{
|
||||
from_fn, from_fn_async, Context, Empty, HandlerExt, HandlerTS, ParentHandler, Server,
|
||||
from_fn, from_fn_async, impl_ts_struct, Context, Empty, HandlerExt, ParentHandler, Server,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yajrc::RpcError;
|
||||
@@ -11,10 +14,12 @@ struct TestContext;
|
||||
impl Context for TestContext {}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Parser)]
|
||||
#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
|
||||
#[cfg_attr(feature = "ts", derive(visit_rs::VisitFields))]
|
||||
struct Thing1Params {
|
||||
thing: String,
|
||||
}
|
||||
#[cfg(feature = "ts")]
|
||||
impl_ts_struct!(Thing1Params);
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Parser)]
|
||||
struct NoTSParams {
|
||||
@@ -30,11 +35,13 @@ fn no_ts_handler(_ctx: TestContext, params: NoTSParams) -> Result<String, RpcErr
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Parser)]
|
||||
#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
|
||||
#[cfg_attr(feature = "ts", derive(visit_rs::VisitFields))]
|
||||
struct GroupParams {
|
||||
#[arg(short, long)]
|
||||
verbose: bool,
|
||||
}
|
||||
#[cfg(feature = "ts")]
|
||||
impl_ts_struct!(GroupParams);
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_basic_server() {
|
||||
@@ -53,7 +60,17 @@ async fn test_basic_server() {
|
||||
.subcommand("no-ts", from_fn(no_ts_handler).no_ts()),
|
||||
);
|
||||
|
||||
println!("{}", root_handler.type_info().unwrap_or_default());
|
||||
println!(
|
||||
"{:?}",
|
||||
root_handler.get_ts().map(|t| {
|
||||
use rpc_toolkit::ts::TSVisitor;
|
||||
use visit_rs::Visit;
|
||||
|
||||
let mut ts = TSVisitor::new();
|
||||
t.visit(&mut ts);
|
||||
ts
|
||||
})
|
||||
);
|
||||
|
||||
let server = Server::new(|| async { Ok(TestContext) }, root_handler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user