@duongtrungnguyen/next-helper
Version:
Helper library for Next.js 15
62 lines • 2.2 kB
TypeScript
import type { QueryKey, QueryClient } from "./types";
/**
* Implementation of the QueryClient interface.
* Manages query data, fetching states, and cache invalidation.
*/
declare class QueryClientImpl implements QueryClient {
/**
* A set to keep track of currently fetching queries.
*/
private fetchingQueries;
/**
* Converts a query key to a string.
* @param queryKey - The key of the query.
* @returns The string representation of the query key.
*/
private getKeyString;
/**
* Retrieves the data for a given query key.
* @param queryKey - The key of the query.
* @returns The data associated with the query key, or undefined if not found.
*/
getQueryData<TData>(queryKey: QueryKey): TData | undefined;
/**
* Sets the data for a given query key.
* @param queryKey - The key of the query.
* @param data - The new data or a function that returns the new data based on the old data.
*/
setQueryData<TData>(queryKey: QueryKey, data: TData | ((oldData: TData | undefined) => TData)): void;
/**
* Invalidates all queries that match the given query key.
* @param queryKey - The key of the query.
*/
invalidateQueries(queryKey: QueryKey): Promise<void>;
/**
* Refetches all queries that match the given query key.
* @param queryKey - The key of the query.
*/
refetchQueries(queryKey: QueryKey): Promise<void>;
/**
* Removes all queries that match the given query key.
* @param queryKey - The key of the query.
*/
removeQueries(queryKey: QueryKey): void;
/**
* Clears all queries from the cache.
*/
clear(): void;
/**
* Returns the number of currently fetching queries.
* @returns The number of fetching queries.
*/
isFetching(): number;
/**
* Sets the fetching state for a given query key.
* @param queryKey - The key of the query.
* @param isFetching - Whether the query is currently fetching.
*/
setFetching(queryKey: QueryKey, isFetching: boolean): void;
}
export declare const queryClient: QueryClientImpl;
export {};
//# sourceMappingURL=query-client.d.ts.map