@@ -6,6 +6,7 @@ import type {
66 ResolvedReturnType ,
77} from './create-resource-query.svelte' ;
88import { fromStore , toStore } from 'svelte/store' ;
9+ import { debugLogQuery } from '$lib/debug' ;
910
1011export const createResourceMutation = < T extends Resource , K extends keyof T > (
1112 client : { current : T | undefined } ,
@@ -14,14 +15,19 @@ export const createResourceMutation = <T extends Resource, K extends keyof T>(
1415 type MutArgs = ArgumentsType < T [ K ] > ;
1516 type MutReturn = ResolvedReturnType < T [ K ] > ;
1617
18+ const name = $derived ( client . current ?. name ) ;
19+ const methodName = $derived ( String ( method ) ) ;
20+
21+ let index = 0 ;
22+
1723 const mutationOptions = $derived ( {
1824 mutationKey : [
1925 'viam-svelte-sdk' ,
2026 'partID' ,
2127 ( client . current as T & { partID : string } ) ?. partID ,
2228 'resource' ,
23- client . current ?. name ,
24- String ( method ) ,
29+ name ,
30+ methodName ,
2531 ] ,
2632 mutationFn : async ( request ) => {
2733 const clientFunc = client . current ?. [ method ] ;
@@ -32,7 +38,22 @@ export const createResourceMutation = <T extends Resource, K extends keyof T>(
3238 ) ;
3339 }
3440
35- return clientFunc . apply ( client . current , request ) as Promise < MutReturn > ;
41+ debugLogQuery ( index , 'REQ' , name , methodName , request ) ;
42+
43+ try {
44+ const result = ( await clientFunc . apply (
45+ client . current ,
46+ request
47+ ) ) as Promise < MutReturn > ;
48+
49+ debugLogQuery ( index ++ , 'RES' , name , methodName , result ) ;
50+
51+ return result ;
52+ } catch ( error ) {
53+ debugLogQuery ( index ++ , 'ERR' , name , methodName , error ) ;
54+
55+ throw error ;
56+ }
3657 } ,
3758 } satisfies MutationOptions < MutReturn , Error , MutArgs > ) ;
3859
0 commit comments