import { AnyRouter } from '@trpc/server' ; import { TRPCLink } from './core' ; export function retryLink < TRouter extends AnyRouter = AnyRouter > ( opts ) { return ( ) => { return ( { op , next , prev } ) => { let attempts = 0 ; const fn = ( ) => { attempts ++ ; next ( op , ( result ) => { if ( result instanceof Error ) { attempts < opts . attempts ? fn ( ) : prev ( result ) ; } else { prev ( result ) ; } } ) ; } ; fn ( ) ; } ; } ; }