@dbs-portal/core-api
Version:
HTTP client and API utilities for DBS Portal
131 lines • 3.95 kB
TypeScript
/**
* MSW integration with TanStack Query
*/
import type { QueryClient, QueryClientConfig } from '@tanstack/react-query';
import type { RequestHandler } from 'msw';
import type { MockConfig } from '../types';
/**
* Query client configuration with MSW support
*/
export interface MockAwareQueryClientConfig extends QueryClientConfig {
/** MSW configuration */
mocking?: Partial<MockConfig>;
/** Custom mock handlers */
mockHandlers?: RequestHandler[];
/** Whether to auto-setup MSW */
autoSetupMocks?: boolean;
}
/**
* Create query client with MSW integration
*/
export declare function createMockAwareQueryClient(config?: MockAwareQueryClientConfig): Promise<QueryClient>;
/**
* Query client wrapper with MSW utilities
*/
export declare class MockAwareQueryClient {
private queryClient;
private mockConfig?;
constructor(queryClient: QueryClient, mockConfig?: Partial<MockConfig>);
/**
* Get the underlying query client
*/
getClient(): QueryClient;
/**
* Check if mocking is enabled
*/
isMocking(): boolean;
/**
* Invalidate queries (useful after adding/removing mock handlers)
*/
invalidateAll(): Promise<void>;
/**
* Clear all queries (useful when switching between mock/real APIs)
*/
clear(): void;
/**
* Reset queries to initial state
*/
resetQueries(): Promise<void>;
/**
* Refetch all queries (useful after mock data changes)
*/
refetchAll(): Promise<void>;
}
/**
* Testing utilities for MSW + React Query
*/
export declare const mockQueryUtils: {
/**
* Create a query client optimized for testing
*/
createTestQueryClient(mockHandlers?: RequestHandler[]): Promise<QueryClient>;
/**
* Create a query client for Storybook
*/
createStorybookQueryClient(mockHandlers?: RequestHandler[]): Promise<QueryClient>;
/**
* Wait for queries to settle (useful in tests)
*/
waitForQueries(queryClient: QueryClient, timeout?: number): Promise<void>;
/**
* Mock query data directly in cache
*/
setQueryData<T>(queryClient: QueryClient, queryKey: unknown[], data: T): void;
/**
* Get query data from cache
*/
getQueryData<T>(queryClient: QueryClient, queryKey: unknown[]): T | undefined;
};
/**
* Hook utilities for MSW + React Query integration
*/
export declare const mockHookUtils: {
/**
* Create mock-aware query options
*/
createMockQueryOptions<T>(queryKey: unknown[], mockData: T, options?: {
enabled?: boolean;
staleTime?: number;
gcTime?: number;
}): {
queryKey: unknown[];
queryFn: () => Promise<T>;
enabled: boolean;
staleTime: number;
gcTime: number;
};
/**
* Create mock-aware mutation options
*/
createMockMutationOptions<TData, TError, TVariables>(mockMutationFn: (variables: TVariables) => Promise<TData> | TData, options?: {
onSuccess?: (data: TData, variables: TVariables) => void;
onError?: (error: TError, variables: TVariables) => void;
}): {
mutationFn: (variables: TVariables) => Promise<TData>;
onSuccess: ((data: TData, variables: TVariables) => void) | undefined;
onError: ((error: TError, variables: TVariables) => void) | undefined;
retry: number;
};
};
/**
* Development utilities for MSW + React Query
*/
export declare const mockDevUtils: {
/**
* Log query cache state (useful for debugging)
*/
logQueryCache(queryClient: QueryClient): void;
/**
* Log mutation cache state
*/
logMutationCache(queryClient: QueryClient): void;
/**
* Check if MSW is properly set up for queries
*/
checkMswSetup(): {
isMswSetup: boolean;
isMockingEnabled: boolean;
mockConfig: Partial<MockConfig>;
};
};
//# sourceMappingURL=query-integration.d.ts.map