@@ -378,6 +378,8 @@ fn runtime(
378378 . iter ( )
379379 . chain ( & cfg. mutations )
380380 . any ( |cmd| command_uses_typed_error ( cmd, exporter. types , cfg) ) ;
381+ let has_query_key_args =
382+ cfg. tanstack . is_some ( ) && cfg. queries . iter ( ) . any ( |cmd| !cmd. args ( ) . is_empty ( ) ) ;
381383
382384 if let Some ( _framework) = & cfg. tanstack {
383385 let has_queries = !cfg. queries . is_empty ( ) ;
@@ -450,11 +452,10 @@ fn runtime(
450452 let key_body = if has_no_args {
451453 format ! ( "() => [{key_prefix}]{as_const}" )
452454 } else {
453- let first_arg = & arguments[ 0 ] . 0 ;
454455 let args_obj = format ! ( "{{ {} }}" , call_args) ;
455456
456457 format ! (
457- "({optional_fn_arguments}) => {first_arg} !== undefined ? [{key_prefix}, {args_obj} ]{as_const} : [{key_prefix}]{as_const} " ,
458+ "({optional_fn_arguments}) => filterKey( [{key_prefix}]{as_const}, {args_obj}) " ,
458459 )
459460 } ;
460461
@@ -694,7 +695,7 @@ fn runtime(
694695 }
695696
696697 // Runtime
697- if has_typed_error || has_unwrap_typed_error || enabled_events {
698+ if has_typed_error || has_unwrap_typed_error || has_query_key_args || enabled_events {
698699 out. push_str ( "\n /* Tauri Specta runtime */\n " ) ;
699700
700701 if has_typed_error {
@@ -717,6 +718,15 @@ fn runtime(
717718 }
718719 out. push ( '\n' ) ;
719720 }
721+ if has_query_key_args {
722+ out. push ( '\n' ) ;
723+ if jsdoc {
724+ out. push_str ( FILTER_KEY_IMPL_JS ) ;
725+ } else {
726+ out. push_str ( FILTER_KEY_IMPL_TS ) ;
727+ }
728+ out. push ( '\n' ) ;
729+ }
720730 if enabled_events {
721731 out. push ( '\n' ) ;
722732 out. push_str ( make_event_impl) ;
@@ -954,6 +964,7 @@ const RESERVED_NDT_NAMES: &[&str] = &[
954964 "__TAURI_INVOKE" ,
955965 "__TANSTACK_QUERY_OPTIONS" ,
956966 "__TANSTACK_MUTATION_OPTIONS" ,
967+ "filterKey" ,
957968 "typedError" ,
958969 "unwrapTypedError" ,
959970 "makeEvent" ,
@@ -1006,6 +1017,23 @@ async function unwrapTypedError(result) {
10061017 return v.data;
10071018}"# ;
10081019
1020+ const FILTER_KEY_IMPL_TS : & str = r#"function filterKey<const P extends readonly unknown[], A extends Record<string, unknown>>(prefix: P, args: A): readonly [...P] | readonly [...P, Partial<A>] {
1021+ const filtered = Object.fromEntries(Object.entries(args).filter(([, v]) => v !== undefined));
1022+ return Object.keys(filtered).length > 0 ? [...prefix, filtered] as const as any : [...prefix] as const;
1023+ }"# ;
1024+
1025+ const FILTER_KEY_IMPL_JS : & str = r#"/**
1026+ * @template {readonly unknown[]} P
1027+ * @template {Record<string, unknown>} A
1028+ * @param {P} prefix
1029+ * @param {A} args
1030+ * @returns {readonly [...P] | readonly [...P, Partial<A>]}
1031+ */
1032+ function filterKey(prefix, args) {
1033+ const filtered = Object.fromEntries(Object.entries(args).filter(([, v]) => v !== undefined));
1034+ return Object.keys(filtered).length > 0 ? [...prefix, filtered] : [...prefix];
1035+ }"# ;
1036+
10091037const MAKE_EVENT_IMPL_TS : & str = r#"type EventEmit<T> = [T] extends [null] ? () => Promise<void> : (payload: T) => Promise<void>;
10101038
10111039function makeEvent<T>(name: string) {
0 commit comments