import * as React from "react"; import { TRPCClient, TRPCClientErrorLike, TRPCRequestOptions, TRPCUntypedClient } from "@trpc/client"; import { AnyTRPCProcedure, AnyTRPCRootTypes, AnyTRPCRouter, TRPCProcedureType, TRPCRouterRecord, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput } from "@trpc/server"; import { DataTag, DefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, InfiniteData, QueryClient, QueryFilters, SkipToken, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UnusedSkipTokenInfiniteOptions, UnusedSkipTokenOptions, UseMutationOptions } from "@tanstack/react-query"; import { DistributiveOmit, MaybePromise, coerceAsyncIterableToArray, inferAsyncIterableYield } from "@trpc/server/unstable-core-do-not-import"; import { TRPCConnectionState } from "@trpc/client/unstable-internals"; import { Unsubscribable } from "@trpc/server/observable"; //#region src/internals/types.d.ts /** * Turn a set of optional properties into required * @internal */ type WithRequired = TObj & { [P in TKey]-?: TObj[P]; }; /** * @internal */ type ResolverDef = { input: any; output: any; transformer: boolean; errorShape: any; featureFlags: FeatureFlags; }; /** * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374 */ type CursorInput = { cursor?: any; }; type OptionalCursorInput = CursorInput | void; /** * @internal */ type ExtractCursorType = TInput extends CursorInput ? TInput['cursor'] : unknown; /** * @internal */ type TRPCInfiniteData = InfiniteData> | null>; /** * @public */ interface TRPCReactRequestOptions 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; } /** * @public */ interface TRPCQueryBaseOptions { /** * tRPC-related options */ trpc?: TRPCReactRequestOptions; } /** * @public */ interface TRPCQueryOptionsResult { trpc: { path: string; }; } /** * @public */ type QueryType = 'any' | 'infinite' | 'query'; /** * @public */ type TRPCQueryKeyWithoutPrefix = [path: string[], opts?: { input?: unknown; type?: Exclude; }]; /** * @public */ type TRPCQueryKeyWithPrefix = [prefix: string[], ...TRPCQueryKeyWithoutPrefix]; type TRPCQueryKey = TPrefixEnabled extends true ? TRPCQueryKeyWithPrefix : TRPCQueryKeyWithoutPrefix; type AnyTRPCQueryKey = TRPCQueryKeyWithoutPrefix | TRPCQueryKeyWithPrefix; /** * @public */ type TRPCMutationKeyWithPrefix = [prefix: string[], ...TRPCMutationKeyWithoutPrefix]; /** * @public */ type TRPCMutationKeyWithoutPrefix = [path: string[]]; type AnyTRPCMutationKey = TRPCMutationKeyWithoutPrefix | TRPCMutationKeyWithPrefix; /** * @public */ type TRPCMutationKey = TPrefixEnabled extends true ? TRPCMutationKeyWithPrefix : TRPCMutationKeyWithoutPrefix; /** * Feature flags for configuring tRPC behavior * @public */ type FeatureFlags = { keyPrefix: boolean; }; /** * @internal */ type ofFeatureFlags = T; /** * @internal */ type KeyPrefixOptions = TFeatureFlags['keyPrefix'] extends true ? { keyPrefix: string; } : { /** * In order to use a query key prefix, you have to initialize the context with the `keyPrefix` */ keyPrefix?: never; }; /** * Default feature flags with query key prefix disabled * @public */ type DefaultFeatureFlags = ofFeatureFlags<{ keyPrefix: false; }>; //#endregion //#region src/internals/infiniteQueryOptions.d.ts type ReservedOptions$2 = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash' | 'initialPageParam'; interface UndefinedTRPCInfiniteQueryOptionsIn extends DistributiveOmit, TRPCQueryKey, NonNullable> | null>, ReservedOptions$2>, TRPCQueryBaseOptions { initialCursor?: NonNullable> | null; } interface UndefinedTRPCInfiniteQueryOptionsOut extends DistributiveOmit, TRPCQueryKey, NonNullable> | null>, 'initialPageParam'>, TRPCQueryOptionsResult { queryKey: DataTag, TRPCInfiniteData, TError>; initialPageParam: NonNullable> | null; } interface DefinedTRPCInfiniteQueryOptionsIn extends DistributiveOmit, TRPCQueryKey, NonNullable> | null>, ReservedOptions$2>, TRPCQueryBaseOptions { initialCursor?: NonNullable> | null; } interface DefinedTRPCInfiniteQueryOptionsOut extends DistributiveOmit, TRPCQueryKey, NonNullable> | null>, 'initialPageParam'>, TRPCQueryOptionsResult { queryKey: DataTag, TRPCInfiniteData, TError>; initialPageParam: NonNullable> | null; } interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn extends DistributiveOmit, TRPCQueryKey, NonNullable> | null>, ReservedOptions$2>, TRPCQueryBaseOptions { initialCursor?: NonNullable> | null; } interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut extends DistributiveOmit, TRPCQueryKey, NonNullable> | null>, 'initialPageParam'>, TRPCQueryOptionsResult { queryKey: DataTag, TRPCInfiniteData, TError>; initialPageParam: NonNullable> | null; } interface TRPCInfiniteQueryOptions { (input: TDef['input'] | SkipToken, opts: DefinedTRPCInfiniteQueryOptionsIn, TDef['featureFlags']>): DefinedTRPCInfiniteQueryOptionsOut, TDef['featureFlags']>; (input: TDef['input'], opts: UnusedSkipTokenTRPCInfiniteQueryOptionsIn, TDef['featureFlags']>): UnusedSkipTokenTRPCInfiniteQueryOptionsOut, TDef['featureFlags']>; (input: TDef['input'] | SkipToken, opts: UndefinedTRPCInfiniteQueryOptionsIn, TDef['featureFlags']>): UndefinedTRPCInfiniteQueryOptionsOut, TDef['featureFlags']>; } //#endregion //#region src/internals/mutationOptions.d.ts type ReservedOptions$1 = 'mutationKey' | 'mutationFn'; type TRPCMutationOptionsIn = DistributiveOmit, ReservedOptions$1> & TRPCQueryBaseOptions & KeyPrefixOptions; interface TRPCMutationOptionsOut extends UseMutationOptions, TRPCQueryOptionsResult { mutationKey: TRPCMutationKey; } interface TRPCMutationOptions { (opts?: TRPCMutationOptionsIn, TDef['output'], TContext, TFeatureFlags>): TRPCMutationOptionsOut, TDef['output'], TContext, TFeatureFlags>; } /** * @internal */ interface MutationOptionsOverride { onSuccess: (opts: { /** * Calls the original function that was defined in the query's `onSuccess` option */ originalFn: () => MaybePromise; queryClient: QueryClient; /** * Meta data passed in from the `useMutation()` hook */ meta: Record; }) => MaybePromise; } //#endregion //#region src/internals/queryOptions.d.ts type ReservedOptions = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'; interface UndefinedTRPCQueryOptionsIn extends DistributiveOmit, TError, coerceAsyncIterableToArray, TRPCQueryKey>, ReservedOptions>, TRPCQueryBaseOptions {} interface UndefinedTRPCQueryOptionsOut extends UndefinedInitialDataOptions, TError, coerceAsyncIterableToArray, TRPCQueryKey>, TRPCQueryOptionsResult { queryKey: DataTag, coerceAsyncIterableToArray, TError>; } interface DefinedTRPCQueryOptionsIn extends DistributiveOmit>, TError, coerceAsyncIterableToArray, TRPCQueryKey>, ReservedOptions>, TRPCQueryBaseOptions {} interface DefinedTRPCQueryOptionsOut extends DefinedInitialDataOptions, TError, coerceAsyncIterableToArray, TRPCQueryKey>, TRPCQueryOptionsResult { queryKey: DataTag, coerceAsyncIterableToArray, TError>; } interface UnusedSkipTokenTRPCQueryOptionsIn extends DistributiveOmit, TError, coerceAsyncIterableToArray, TRPCQueryKey>, ReservedOptions>, TRPCQueryBaseOptions {} interface UnusedSkipTokenTRPCQueryOptionsOut extends UnusedSkipTokenOptions, TError, coerceAsyncIterableToArray, TRPCQueryKey>, TRPCQueryOptionsResult { queryKey: DataTag, coerceAsyncIterableToArray, TError>; } interface TRPCQueryOptions { (input: TDef['input'] | SkipToken, opts: DefinedTRPCQueryOptionsIn, TFeatureFlags>): DefinedTRPCQueryOptionsOut, TFeatureFlags>; (input: TDef['input'], opts?: UnusedSkipTokenTRPCQueryOptionsIn, TFeatureFlags>): UnusedSkipTokenTRPCQueryOptionsOut, TFeatureFlags>; (input: TDef['input'] | SkipToken, opts?: UndefinedTRPCQueryOptionsIn, TFeatureFlags>): UndefinedTRPCQueryOptionsOut, TFeatureFlags>; } //#endregion //#region src/internals/subscriptionOptions.d.ts interface BaseTRPCSubscriptionOptionsIn { enabled?: boolean; onStarted?: () => void; onData?: (data: inferAsyncIterableYield) => void; onError?: (err: TError) => void; onConnectionStateChange?: (state: TRPCConnectionState) => void; } interface UnusedSkipTokenTRPCSubscriptionOptionsIn { onStarted?: () => void; onData?: (data: inferAsyncIterableYield) => void; onError?: (err: TError) => void; onConnectionStateChange?: (state: TRPCConnectionState) => void; } interface TRPCSubscriptionOptionsOut extends UnusedSkipTokenTRPCSubscriptionOptionsIn, TRPCQueryOptionsResult { enabled: boolean; queryKey: TRPCQueryKey; subscribe: (innerOpts: UnusedSkipTokenTRPCSubscriptionOptionsIn) => Unsubscribable; } interface TRPCSubscriptionOptions { (input: TDef['input'], opts?: UnusedSkipTokenTRPCSubscriptionOptionsIn, TRPCClientErrorLike>): TRPCSubscriptionOptionsOut, TRPCClientErrorLike, TFeatureFlags>; (input: TDef['input'] | SkipToken, opts?: BaseTRPCSubscriptionOptionsIn, TRPCClientErrorLike>): TRPCSubscriptionOptionsOut, TRPCClientErrorLike, TFeatureFlags>; } type TRPCSubscriptionStatus = 'idle' | 'connecting' | 'pending' | 'error'; interface TRPCSubscriptionBaseResult { status: TRPCSubscriptionStatus; data: undefined | TOutput; error: null | TError; /** * Reset the subscription */ reset: () => void; } interface TRPCSubscriptionIdleResult extends TRPCSubscriptionBaseResult { status: 'idle'; data: undefined; error: null; } interface TRPCSubscriptionConnectingResult extends TRPCSubscriptionBaseResult { status: 'connecting'; data: undefined | TOutput; error: TError | null; } interface TRPCSubscriptionPendingResult extends TRPCSubscriptionBaseResult { status: 'pending'; data: TOutput | undefined; error: null; } interface TRPCSubscriptionErrorResult extends TRPCSubscriptionBaseResult { status: 'error'; data: TOutput | undefined; error: TError; } type TRPCSubscriptionResult = TRPCSubscriptionIdleResult | TRPCSubscriptionConnectingResult | TRPCSubscriptionErrorResult | TRPCSubscriptionPendingResult; export declare function useSubscription(opts: TRPCSubscriptionOptionsOut): TRPCSubscriptionResult; //#endregion //#region src/internals/createOptionsProxy.d.ts interface DecorateRouterKeyable { /** * Calculate the TanStack Query Key for any path, could be used to invalidate every procedure beneath this path * * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey */ pathKey: () => TRPCQueryKey; /** * Calculate a TanStack Query Filter for any path, could be used to manipulate every procedure beneath this path * * @see https://tanstack.com/query/latest/docs/framework/react/guides/filters * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter */ pathFilter: (filters?: QueryFilters>) => WithRequired>, 'queryKey'>; } interface TypeHelper { /** * @internal prefer using inferInput and inferOutput to access types */ '~types': { input: TDef['input']; output: TDef['output']; errorShape: TDef['errorShape']; }; } type inferInput | DecorateQueryProcedure | DecorateMutationProcedure> = TProcedure['~types']['input']; type inferOutput | DecorateQueryProcedure | DecorateMutationProcedure> = TProcedure['~types']['output']; interface DecorateInfiniteQueryProcedure extends TypeHelper { /** * Create a set of type-safe infinite query options that can be passed to `useInfiniteQuery`, `prefetchInfiniteQuery` etc. * * @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions * @see https://trpc.io/docs/client/tanstack-react-query/usage#infiniteQueryOptions */ infiniteQueryOptions: TRPCInfiniteQueryOptions; /** * Calculate the TanStack Query Key for a Infinite Query Procedure * * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey */ infiniteQueryKey: (input?: Partial) => DataTag, TRPCInfiniteData, TRPCClientErrorLike<{ transformer: TDef['transformer']; errorShape: TDef['errorShape']; }>>; /** * Calculate a TanStack Query Filter for a Infinite Query Procedure * * @see https://tanstack.com/query/latest/docs/framework/react/guides/filters * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter */ infiniteQueryFilter: (input?: Partial, filters?: QueryFilters, TRPCInfiniteData, TRPCClientErrorLike<{ transformer: TDef['transformer']; errorShape: TDef['errorShape']; }>>>) => WithRequired, TRPCInfiniteData, TRPCClientErrorLike<{ transformer: TDef['transformer']; errorShape: TDef['errorShape']; }>>>, 'queryKey'>; } interface DecorateQueryProcedure extends TypeHelper, DecorateRouterKeyable { /** * Create a set of type-safe query options that can be passed to `useQuery`, `prefetchQuery` etc. * * @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryOptions */ queryOptions: TRPCQueryOptions; /** * Calculate the TanStack Query Key for a Query Procedure * * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey */ queryKey: (input?: Partial) => DataTag, TDef['output'], TRPCClientErrorLike<{ transformer: TDef['transformer']; errorShape: TDef['errorShape']; }>>; /** * Calculate a TanStack Query Filter for a Query Procedure * * @see https://tanstack.com/query/latest/docs/framework/react/guides/filters * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter */ queryFilter: (input?: Partial, filters?: QueryFilters, TDef['output'], TRPCClientErrorLike<{ transformer: TDef['transformer']; errorShape: TDef['errorShape']; }>>>) => WithRequired, TDef['output'], TRPCClientErrorLike<{ transformer: TDef['transformer']; errorShape: TDef['errorShape']; }>>>, 'queryKey'>; } interface DecorateMutationProcedure extends TypeHelper { /** * Create a set of type-safe mutation options that can be passed to `useMutation` * * @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationOptions */ mutationOptions: TRPCMutationOptions; /** * Calculate the TanStack Mutation Key for a Mutation Procedure * * @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationKey */ mutationKey: () => TRPCMutationKey; } interface DecorateSubscriptionProcedure extends TypeHelper { /** * Create a set of type-safe subscription options that can be passed to `useSubscription` * * @see https://trpc.io/docs/client/tanstack-react-query/usage#subscriptionOptions */ subscriptionOptions: TRPCSubscriptionOptions; } type DecorateProcedure = TType extends 'query' ? DecorateQueryProcedure & (TDef['input'] extends OptionalCursorInput ? DecorateInfiniteQueryProcedure : Record) : TType extends 'mutation' ? DecorateMutationProcedure : TType extends 'subscription' ? DecorateSubscriptionProcedure : never; /** * @internal */ type DecoratedRouterRecord = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends TRPCRouterRecord ? DecoratedRouterRecord & DecorateRouterKeyable : $Value extends AnyTRPCProcedure ? DecorateProcedure<$Value['_def']['type'], { input: inferProcedureInput<$Value>; output: inferTransformedProcedureOutput; transformer: TRoot['transformer']; errorShape: TRoot['errorShape']; featureFlags: TFeatureFlags; }> : never : never; }; type TRPCOptionsProxy = DecoratedRouterRecord & DecorateRouterKeyable; type TRPCOptionsProxyOptionsBase = { queryClient: QueryClient | (() => QueryClient); overrides?: { mutations?: MutationOptionsOverride; }; } & KeyPrefixOptions; interface TRPCOptionsProxyOptionsInternal { router: TRouter; ctx: inferRouterContext | (() => MaybePromise>); } interface TRPCOptionsProxyOptionsExternal { client: TRPCUntypedClient | TRPCClient; } type TRPCOptionsProxyOptions = TRPCOptionsProxyOptionsBase & (TRPCOptionsProxyOptionsInternal | TRPCOptionsProxyOptionsExternal); /** * Create a typed proxy from your router types. Can also be used on the server. * * @see https://trpc.io/docs/client/tanstack-react-query/setup#3b-setup-without-react-context * @see https://trpc.io/docs/client/tanstack-react-query/server-components#5-create-a-trpc-caller-for-server-components */ export declare function createTRPCOptionsProxy(opts: TRPCOptionsProxyOptions): TRPCOptionsProxy; //#endregion //#region src/internals/Context.d.ts type TRPCProviderType = React.FC<{ children: React.ReactNode; queryClient: QueryClient; trpcClient: TRPCClient; } & KeyPrefixOptions>; interface CreateTRPCContextResult { TRPCProvider: TRPCProviderType; useTRPC: () => TRPCOptionsProxy; useTRPCClient: () => TRPCClient; } /** * Create a set of type-safe provider-consumers * * @see https://trpc.io/docs/client/tanstack-react-query/setup#3a-setup-the-trpc-context-provider */ export declare function createTRPCContext(): CreateTRPCContextResult; //#endregion export type { AnyTRPCMutationKey, AnyTRPCQueryKey, DecorateMutationProcedure, DecorateProcedure, DecorateQueryProcedure, DecorateRouterKeyable, DecorateSubscriptionProcedure, DefaultFeatureFlags, ExtractCursorType, FeatureFlags, KeyPrefixOptions, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCInfiniteQueryOptions, TRPCMutationKey, TRPCMutationKeyWithPrefix, TRPCMutationKeyWithoutPrefix, TRPCMutationOptions, TRPCOptionsProxy, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryKeyWithPrefix, TRPCQueryKeyWithoutPrefix, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCReactRequestOptions, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionOptions, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCSubscriptionStatus, WithRequired, inferInput, inferOutput, ofFeatureFlags }; //# sourceMappingURL=index.d.mts.map