Skip to content

wip: add function to export method signatures #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions yerpc-derive/src/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use quote::quote;
pub(crate) fn generate_typescript_generator(info: &RpcInfo) -> TokenStream {
let mut gen_types = vec![];
let mut gen_methods = vec![];
let mut raw_gen_methods = vec![];
for method in &info.methods {
let (is_positional, gen_args) = match &method.input {
Inputs::Positional(ref inputs) => {
Expand Down Expand Up @@ -54,6 +55,11 @@ pub(crate) fn generate_typescript_generator(info: &RpcInfo) -> TokenStream {
let method = Method::new(#ts_name, #rpc_name, args, #gen_output, #is_notification, #is_positional, #docs);
out.push_str(&method.to_string(root_namespace));
));
raw_gen_methods.push(quote!(
let args = vec![#(#gen_args),*];
let method = Method::new(#ts_name, #rpc_name, args, #gen_output, #is_notification, #is_positional, #docs);
out.push(method);
));
}

let outdir_path = info
Expand Down Expand Up @@ -104,5 +110,15 @@ pub(crate) fn generate_typescript_generator(info: &RpcInfo) -> TokenStream {
let ts_module = #ts_base.replace("#methods", &out);
fs::write(&outdir.join("client.ts"), &ts_module).expect("Failed to write TS bindings");
}

// #[cfg(test)]
/** exposes the methods so you can generate other stuff from it */
pub fn raw_ts_binding_methods()-> Vec<::yerpc::typescript::Method> {
use ::yerpc::typescript::type_def::TypeDef;
use ::yerpc::typescript::Method;
let mut out:Vec<Method> = vec![];
#(#raw_gen_methods)*
out
}
}
}