@@ -11,12 +11,15 @@ type CreateUpdateMiddleware = <T extends BuilderTypeTemplate>(
1111
1212export const createUpdateMiddleware : CreateUpdateMiddleware = ( tags ) =>
1313 async function updateMiddleware ( ctx , next , throwError , config ) {
14+ type TagObj = QueryUpdateTagObject < any , any , any , any > ;
15+ type TagCtx = QueryTagContext < any > ;
16+
1417 let undos : UpdateTagsUndoer [ ] | null = null ;
15- const invalidates : QueryUpdateTagObject [ ] = [ ] ;
16- const optCtx : QueryTagContext < unknown > = { client : ctx . client , vars : ctx . vars , data : undefined } ;
18+ const invalidates : TagObj [ ] = [ ] ;
19+ const optCtx : TagCtx = { client : ctx . client , vars : ctx . vars , data : undefined } ;
1720
1821 try {
19- const optUpdates = resolveTags < any , QueryUpdateTagObject > ( { tags, ...optCtx } ) . filter ( ( u ) => u . optimistic ) ;
22+ const optUpdates = resolveTags < any , TagObj > ( { tags, ...optCtx } ) . filter ( ( u ) => u . optimistic ) ;
2023 undos = updateTags ( {
2124 queryClient : ctx . client ,
2225 tags : optUpdates . filter ( ( x ) => x . updater ) ,
@@ -30,17 +33,17 @@ export const createUpdateMiddleware: CreateUpdateMiddleware = (tags) =>
3033
3134 const data = await next ( ctx ) ;
3235
33- const pesCtx : QueryTagContext < unknown > = { ...optCtx , data } ;
34- const pesUpdates = resolveTags < any , QueryUpdateTagObject > ( { tags, ...pesCtx } ) . filter ( ( u ) => ! u . optimistic ) ;
36+ const pesCtx : TagCtx = { ...optCtx , data } ;
37+ const pesUpdates = resolveTags < any , TagObj > ( { tags, ...pesCtx } ) . filter ( ( u ) => ! u . optimistic ) ;
3538 updateTags ( { queryClient : ctx . client , tags : pesUpdates . filter ( ( x ) => x . updater ) , ctx : pesCtx } ) ;
3639 invalidates . push ( ...pesUpdates ) ;
3740
3841 return data ;
3942 } catch ( error ) {
4043 if ( undos ?. length ) undoUpdateTags ( undos , ctx . client ) ;
4144
42- const pesCtx : QueryTagContext < unknown > = { ...optCtx , error } ;
43- const pesUpdates = resolveTags < any , QueryUpdateTagObject > ( { tags, ...pesCtx } ) . filter ( ( u ) => ! u . optimistic ) ;
45+ const pesCtx : TagCtx = { ...optCtx , error } ;
46+ const pesUpdates = resolveTags < any , TagObj > ( { tags, ...pesCtx } ) . filter ( ( u ) => ! u . optimistic ) ;
4447 invalidates . push ( ...pesUpdates ) ;
4548
4649 throw error ;
0 commit comments