import type { DefinedUseQueryResult, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InfiniteQueryObserverSuccessResult, InitialDataFunction, QueryObserverSuccessResult, QueryOptions, UseBaseQueryOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult, } from '@tanstack/react-query'; import type { CreateTRPCClientOptions, TRPCClient, TRPCRequestOptions, TRPCUntypedClient, } from '@trpc/client'; import type { AnyRouter, coerceAsyncIterableToArray, DistributiveOmit, } from '@trpc/server/unstable-core-do-not-import'; import type { JSX, ReactNode } from 'react'; import type { TRPCContextProps } from '../../internals/context'; import type { TRPCQueryKey } from '../../internals/getQueryKey'; export type OutputWithCursor = { cursor: TCursor | null; data: TData; }; export interface TRPCReactRequestOptions // For RQ, we use their internal AbortSignals instead of letting the user pass their own extends Omit { /** * Opt out of SSR for this query by passing `ssr: false` */ ssr?: boolean; /** * Opt out or into aborting request on unmount */ abortOnUnmount?: boolean; } export interface TRPCUseQueryBaseOptions { /** * tRPC-related options */ trpc?: TRPCReactRequestOptions; } export interface UseTRPCQueryOptions< TOutput, TData, TError, TQueryOptsData = TOutput, > extends DistributiveOmit< UseBaseQueryOptions, 'queryKey' >, TRPCUseQueryBaseOptions {} export interface UseTRPCSuspenseQueryOptions extends DistributiveOmit< UseSuspenseQueryOptions, 'queryKey' >, TRPCUseQueryBaseOptions {} export interface UseTRPCPrefetchQueryOptions extends DistributiveOmit< FetchQueryOptions, 'queryKey' >, TRPCUseQueryBaseOptions {} /** @internal **/ export interface DefinedUseTRPCQueryOptions< TOutput, TData, TError, TQueryOptsData = TOutput, > extends DistributiveOmit< UseTRPCQueryOptions, 'queryKey' > { initialData: InitialDataFunction | TQueryOptsData; } export interface TRPCQueryOptions extends DistributiveOmit, 'queryKey'>, TRPCUseQueryBaseOptions { queryKey: TRPCQueryKey; } export type ExtractCursorType = TInput extends { cursor?: any } ? TInput['cursor'] : unknown; export interface UseTRPCInfiniteQueryOptions extends DistributiveOmit< UseInfiniteQueryOptions< TOutput, TError, TOutput, any, ExtractCursorType >, 'queryKey' | 'initialPageParam' >, TRPCUseQueryBaseOptions { initialCursor?: ExtractCursorType; } export type UseTRPCPrefetchInfiniteQueryOptions = DistributiveOmit< FetchInfiniteQueryOptions< TOutput, TError, TOutput, any, ExtractCursorType >, 'queryKey' | 'initialPageParam' > & TRPCUseQueryBaseOptions & { initialCursor?: ExtractCursorType; }; export interface UseTRPCSuspenseInfiniteQueryOptions extends DistributiveOmit< UseSuspenseInfiniteQueryOptions< TOutput, TError, TOutput, any, ExtractCursorType >, 'queryKey' | 'initialPageParam' >, TRPCUseQueryBaseOptions { initialCursor?: ExtractCursorType; } export interface UseTRPCMutationOptions< TInput, TError, TOutput, TContext = unknown, > extends UseMutationOptions, TRPCUseQueryBaseOptions {} export interface UseTRPCSubscriptionOptions { /** * @deprecated * use a `skipToken` from `@tanstack/react-query` instead * this will be removed in v12 */ enabled?: boolean; /** * Called when the subscription is started */ onStarted?: () => void; /** * Called when new data is received */ onData?: (data: TOutput) => void; /** * Called when an **unrecoverable error** occurs and the subscription is closed */ onError?: (err: TError) => void; /** * Called when the subscription is completed on the server */ onComplete?: () => void; } export interface TRPCSubscriptionBaseResult { status: 'idle' | 'connecting' | 'pending' | 'error'; data: undefined | TOutput; error: null | TError; /** * Reset the subscription */ reset: () => void; } export interface TRPCSubscriptionIdleResult extends TRPCSubscriptionBaseResult { status: 'idle'; data: undefined; error: null; } export interface TRPCSubscriptionConnectingResult extends TRPCSubscriptionBaseResult { status: 'connecting'; data: undefined | TOutput; error: TError | null; } export interface TRPCSubscriptionPendingResult extends TRPCSubscriptionBaseResult { status: 'pending'; data: TOutput | undefined; error: null; } export interface TRPCSubscriptionErrorResult extends TRPCSubscriptionBaseResult { status: 'error'; data: TOutput | undefined; error: TError; } export type TRPCSubscriptionResult = | TRPCSubscriptionIdleResult | TRPCSubscriptionConnectingResult | TRPCSubscriptionErrorResult | TRPCSubscriptionPendingResult; export interface TRPCProviderProps extends Omit, 'client'> { children: ReactNode; client: TRPCClient | TRPCUntypedClient; } export type TRPCProvider = ( props: TRPCProviderProps, ) => JSX.Element; export type CreateClient = ( opts: CreateTRPCClientOptions, ) => TRPCUntypedClient; /** * @internal */ export type UseTRPCQueryResult = TRPCHookResult & UseQueryResult, TError>; /** * @internal */ export type DefinedUseTRPCQueryResult = DefinedUseQueryResult< TData, TError > & TRPCHookResult; /** * @internal */ export type UseTRPCQuerySuccessResult = QueryObserverSuccessResult & TRPCHookResult; /** * @internal */ export type UseTRPCSuspenseQueryResult = [ TData, UseSuspenseQueryResult & TRPCHookResult, ]; /** * @internal */ export type UseTRPCInfiniteQueryResult = TRPCHookResult & UseInfiniteQueryResult< InfiniteData> | null>, TError >; /** * @internal */ export type UseTRPCInfiniteQuerySuccessResult = InfiniteQueryObserverSuccessResult< InfiniteData> | null>, TError > & TRPCHookResult; /** * @internal */ export type UseTRPCSuspenseInfiniteQueryResult = [ InfiniteData> | null>, UseSuspenseInfiniteQueryResult< InfiniteData> | null>, TError > & TRPCHookResult, ]; /** * @internal */ export type UseTRPCMutationResult = TRPCHookResult & UseMutationResult; export interface TRPCHookResult { trpc: { path: string; }; }