/** * @jorvel/runtime — a small TanStack-Query-style data layer. * * A `QueryClient` holds a keyed cache; `useQuery` reads it with * stale-while-revalidate semantics (return cached data instantly, refetch in the * background when stale); `useMutation` runs writes and can invalidate queries. * * Deliberately tiny — no infinite queries, no suspense mode — but real: dedupes * in-flight fetches, tracks fetching/stale state, supports optimistic * `setQueryData`, and cross-component cache sharing via `useSyncExternalStore`. * MF-singleton-safe: the default client is pinned to `globalThis`. */ import React from 'react'; export type QueryKey = readonly unknown[]; export type QueryStatus = 'pending' | 'success' | 'error'; interface QueryEntry { data?: T; error?: unknown; status: QueryStatus; updatedAt: number; /** In-flight fetch promise (for dedupe). */ promise?: Promise; listeners: Set<() => void>; /** True while a (re)fetch is running, independent of whether data exists. */ fetching: boolean; /** Bumped on every change so `useSyncExternalStore` sees a new snapshot. */ version: number; } export interface QueryClientOptions { /** Default staleness window (ms). Cached data older than this refetches on use. Default 0. */ staleTime?: number; /** Testable clock. */ now?: () => number; } export declare class QueryClient { private cache; private readonly staleTime; private readonly now; constructor(opts?: QueryClientOptions); private entry; private emit; subscribe(key: QueryKey, cb: () => void): () => void; getEntry(key: QueryKey): Readonly>; isStale(key: QueryKey, staleTime?: number): boolean; /** Imperatively seed/replace a query's data (optimistic updates, SSR hydration). */ setQueryData(key: QueryKey, updater: T | ((prev: T | undefined) => T)): void; /** * Fetch (or dedupe onto an in-flight fetch). Resolves with the data; updates * the cache + notifies subscribers. `force` bypasses the in-flight dedupe only * when nothing is running. */ fetchQuery(key: QueryKey, queryFn: () => Promise): Promise; /** Invalidate matching queries. String/array = exact-prefix; fn = predicate. */ invalidate(matcher: QueryKey | ((key: unknown[]) => boolean)): void; clear(): void; } export declare function getDefaultQueryClient(): QueryClient; export declare function QueryClientProvider({ client, children, }: { client?: QueryClient; children: React.ReactNode; }): import("react/jsx-runtime").JSX.Element; export declare function useQueryClient(): QueryClient; export interface UseQueryOptions { queryKey: QueryKey; queryFn: () => Promise; /** Staleness window (ms). Cached data older than this refetches on mount/use. */ staleTime?: number; /** Skip fetching until true. Default true. */ enabled?: boolean; } export interface UseQueryResult { data: T | undefined; error: unknown; status: QueryStatus; /** True on the first load with no cached data. */ isLoading: boolean; /** True whenever a fetch is in flight (incl. background revalidation). */ isFetching: boolean; isStale: boolean; refetch: () => Promise; } export declare function useQuery(options: UseQueryOptions): UseQueryResult; export interface UseMutationOptions { mutationFn: (input: Input) => Promise; onSuccess?: (data: Output, input: Input) => void | Promise; onError?: (error: unknown, input: Input) => void; } export type MutationStatus = 'idle' | 'pending' | 'success' | 'error'; export interface UseMutationResult { mutate: (input: Input) => void; mutateAsync: (input: Input) => Promise; data: Output | undefined; error: unknown; status: MutationStatus; isPending: boolean; reset: () => void; } export declare function useMutation(options: UseMutationOptions): UseMutationResult; export {}; //# sourceMappingURL=query.d.ts.map