/** * Server function → TanStack Query integration. * * Provides type-safe `useQuery` and `useSuspenseQuery` that accept * server functions directly, with full TArgs + TData inference. * * @example * import { useQuery, useSuspenseQuery } from "@evjs/client"; * * // Server function — args & data fully typed * const { data: users } = useQuery(getUsers); // data: User[] * const { data: user } = useQuery(getUser, userId); // data: User * const { data } = useSuspenseQuery(getUsers); // data: User[] * * // Standard TanStack options — pass-through * const { data } = useQuery({ queryKey: [...], queryFn: ... }); * * // Cache invalidation — use getFnQueryKey(): * queryClient.invalidateQueries({ queryKey: getFnQueryKey(getUsers) }); * * // For other hooks (useInfiniteQuery, prefetch, loaders), use getFnQueryOptions(): * useInfiniteQuery({ ...getFnQueryOptions(getPosts), getNextPageParam: ... }); * context.queryClient.ensureQueryData(getFnQueryOptions(getUsers)); */ import type { UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; type NoMutationVariables = void; type ServerMutationVariables = TArgs extends [] ? NoMutationVariables : TArgs extends [infer Arg] ? Arg : TArgs; type AsyncServerFunction = (...args: TArgs) => Promise; /** * Extracts the stable query key for a given server function and its arguments. * * At runtime, server functions are augmented by the evjs compiler to carry internal metadata * (like unique function IDs and query key generators). However, in plain TypeScript, importing * a raw function from a `.server.ts` file only gives you its standard `() => Promise` type signature. * * This helper bridges the type gap, providing a completely type-safe way to extract the * underlying TanStack Query key from the server function stub without triggering static TS errors. */ export declare function getFnQueryKey(fn: AsyncServerFunction, ...args: TArgs): unknown[]; /** * Extracts the { queryKey, queryFn } object for TanStack Query options. * * At runtime, server functions are augmented by the evjs compiler to carry internal metadata * (like unique function IDs and query key generators). However, in plain TypeScript, importing * a raw function from a `.server.ts` file only gives you its standard `() => Promise` type signature. * * This helper bridges the type gap, providing a completely type-safe way to extract the * underlying TanStack Query Options from the server function stub without triggering static TS errors. */ export declare function getFnQueryOptions(fn: AsyncServerFunction, ...args: TArgs): { queryKey: unknown[]; queryFn: (ctx?: { signal?: AbortSignal; }) => Promise; }; /** * Type-safe `useQuery` that accepts server functions directly. * * @example * const { data } = useQuery(getUsers); // data: User[] * const { data } = useQuery(getUser, userId); // data: User * const { data } = useQuery({ queryKey, queryFn }); // standard TanStack */ export declare function useQuery(fn: (...args: TArgs) => Promise, ...args: TArgs): UseQueryResult; export declare function useQuery(options: UseQueryOptions): UseQueryResult; /** * Type-safe `useSuspenseQuery` that accepts server functions directly. * Data is guaranteed to be defined (no loading state). */ export declare function useSuspenseQuery(fn: (...args: TArgs) => Promise, ...args: TArgs): UseSuspenseQueryResult; export declare function useSuspenseQuery(options: UseSuspenseQueryOptions): UseSuspenseQueryResult; /** * Type-safe `useMutation` that accepts server functions directly. * * @example * const { mutateAsync } = useMutation(createUser); * await mutateAsync({ name: "Alice", email: "alice@example.com" }); * * // With additional TanStack options: * const { mutateAsync } = useMutation(createUser, { * onSuccess: () => queryClient.invalidateQueries({ queryKey: getFnQueryKey(getUsers) }), * }); * * // Standard TanStack pass-through: * const { mutateAsync } = useMutation({ mutationFn: createUser }); */ export declare function useMutation(fn: (...args: TArgs) => Promise, options?: Omit>, "mutationFn">): UseMutationResult>; export declare function useMutation(options: UseMutationOptions): UseMutationResult; export {}; //# sourceMappingURL=query.d.ts.map