UNPKG

@dbs-portal/core-api

Version:

HTTP client and API utilities for DBS Portal

141 lines 3.88 kB
/** * Query utilities and helpers */ import type { QueryClient } from '@tanstack/react-query'; import type { ApiError } from '../types'; /** * Error handling utilities */ export declare const queryErrorUtils: { /** * Check if error is a network error */ isNetworkError: (error: unknown) => boolean; /** * Check if error is an API error with status */ isApiError: (error: unknown) => error is ApiError; /** * Check if error is a client error (4xx) */ isClientError: (error: unknown) => boolean; /** * Check if error is a server error (5xx) */ isServerError: (error: unknown) => boolean; /** * Check if error is unauthorized (401) */ isUnauthorized: (error: unknown) => boolean; /** * Check if error is forbidden (403) */ isForbidden: (error: unknown) => boolean; /** * Check if error is not found (404) */ isNotFound: (error: unknown) => boolean; /** * Get error message from various error types */ getErrorMessage: (error: unknown) => string; }; /** * Cache management utilities */ export declare const cacheUtils: { /** * Invalidate all queries matching a pattern */ invalidateByPattern: (queryClient: QueryClient, pattern: readonly unknown[]) => Promise<void>; /** * Remove all queries matching a pattern */ removeByPattern: (queryClient: QueryClient, pattern: readonly unknown[]) => void; /** * Prefetch multiple queries */ prefetchMultiple: (queryClient: QueryClient, queries: Array<{ queryKey: readonly unknown[]; queryFn: () => Promise<any>; staleTime?: number; }>) => Promise<PromiseSettledResult<void>[]>; /** * Get cache statistics */ getCacheStats: (queryClient: QueryClient) => { totalQueries: number; activeQueries: number; staleQueries: number; errorQueries: number; loadingQueries: number; successQueries: number; }; /** * Clear all cache data */ clearAll: (queryClient: QueryClient) => void; /** * Reset all queries to initial state */ resetAll: (queryClient: QueryClient) => Promise<void>; }; /** * Query key utilities */ export declare const keyUtils: { /** * Create a hierarchical query key */ createHierarchical: (...segments: (string | number | object)[]) => readonly unknown[]; /** * Match query keys by pattern */ matchesPattern: (queryKey: readonly unknown[], pattern: readonly unknown[]) => boolean; /** * Extract parameters from query key */ extractParams: <T = Record<string, any>>(queryKey: readonly unknown[], paramIndex: number) => T | null; }; /** * Retry utilities */ export declare const retryUtils: { /** * Exponential backoff with jitter */ exponentialBackoff: (attemptIndex: number, baseDelay?: number) => number; /** * Linear backoff */ linearBackoff: (attemptIndex: number, baseDelay?: number) => number; /** * Fixed delay */ fixedDelay: (delay?: number) => number; /** * Should retry based on error type */ shouldRetry: (failureCount: number, error: unknown, maxRetries?: number) => boolean; }; /** * Performance utilities */ export declare const performanceUtils: { /** * Measure query performance */ measureQuery: <T>(queryFn: () => Promise<T>, queryKey: readonly unknown[]) => Promise<{ data: T; duration: number; }>; /** * Create a debounced query function */ debounce: <T extends (...args: any[]) => any>(fn: T, delay: number) => T; /** * Create a throttled query function */ throttle: <T extends (...args: any[]) => any>(fn: T, delay: number) => T; }; //# sourceMappingURL=utils.d.ts.map