@trpc/react-query
Advanced tools
Comparing version 10.32.0 to 10.32.1-alpha-actions-2-2023-08-09-10-23-47.45
@@ -1,10 +0,8 @@ | ||
import { InfiniteData } from '@tanstack/react-query'; | ||
import { TRPCClientErrorLike } from '@trpc/client'; | ||
import { AnyMutationProcedure, AnyProcedure, AnyQueryProcedure, AnyRouter, AnySubscriptionProcedure, inferProcedureInput, ProcedureRouterRecord, ProtectedIntersection } from '@trpc/server'; | ||
import { inferTransformedProcedureOutput, inferTransformedSubscriptionOutput } from '@trpc/server/shared'; | ||
import { QueryKey, QueryType } from './internals/getArrayQueryKey'; | ||
import { TRPCUseQueries } from './internals/useQueries'; | ||
import { CreateReactUtilsProxy } from './shared'; | ||
import { CreateReactQueryHooks } from './shared/hooks/createRootHooks'; | ||
import { CreateClient, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, TRPCProvider, UseDehydratedState, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions } from './shared/hooks/types'; | ||
import { CreateReactQueryHooks } from './shared/hooks/createHooksInternal'; | ||
import { CreateClient, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, TRPCProvider, UseDehydratedState, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult } from './shared/hooks/types'; | ||
import { CreateTRPCReactOptions } from './shared/types'; | ||
@@ -21,11 +19,15 @@ /** | ||
*/ | ||
export type DecorateProcedure<TProcedure extends AnyProcedure, _TFlags, TPath extends string> = TProcedure extends AnyQueryProcedure ? { | ||
export type DecorateProcedure<TProcedure extends AnyProcedure, _TFlags, TPath extends string> = TProcedure extends AnyQueryProcedure ? (inferProcedureInput<TProcedure> extends { | ||
cursor?: any; | ||
} | void ? { | ||
/** | ||
* Method to extract the query key for a procedure | ||
* @param type - defaults to `any` | ||
* @see https://trpc.io/docs/client/react/getQueryKey | ||
* @deprecated - import `getQueryKey` from `@trpc/react-query` instead | ||
* @see https://trpc.io/docs/client/react/suspense#useinfinitesuspensequery | ||
*/ | ||
getQueryKey: (input: inferProcedureInput<TProcedure>, type?: QueryType) => QueryKey; | ||
useInfiniteQuery: (input: Omit<inferProcedureInput<TProcedure>, 'cursor'>, opts: UseTRPCInfiniteQueryOptions<TPath, inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>>) => UseTRPCInfiniteQueryResult<inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>, inferProcedureInput<TProcedure>>; | ||
/** | ||
* @see https://trpc.io/docs/client/react/suspense | ||
*/ | ||
useSuspenseInfiniteQuery: (input: Omit<inferProcedureInput<TProcedure>, 'cursor'>, opts: UseTRPCSuspenseInfiniteQueryOptions<TPath, inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>>) => UseTRPCSuspenseInfiniteQueryResult<inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>, inferProcedureInput<TProcedure>>; | ||
} : object) & { | ||
/** | ||
* @see https://trpc.io/docs/client/react/useQuery | ||
@@ -37,22 +39,5 @@ */ | ||
*/ | ||
useSuspenseQuery: <TQueryFnData extends inferTransformedProcedureOutput<TProcedure> = inferTransformedProcedureOutput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure>, opts?: Omit<UseTRPCQueryOptions<TPath, inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientErrorLike<TProcedure>>, 'enabled' | 'suspense'>) => [ | ||
TData, | ||
UseTRPCQuerySuccessResult<TData, TRPCClientErrorLike<TProcedure>> | ||
]; | ||
} & (inferProcedureInput<TProcedure> extends { | ||
cursor?: any; | ||
} | void ? { | ||
useSuspenseQuery: <TQueryFnData extends inferTransformedProcedureOutput<TProcedure> = inferTransformedProcedureOutput<TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure>, opts?: UseTRPCSuspenseQueryOptions<TPath, inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientErrorLike<TProcedure>>) => UseTRPCSuspenseQueryResult<TData, TRPCClientErrorLike<TProcedure>>; | ||
} : TProcedure extends AnyMutationProcedure ? { | ||
/** | ||
* @see https://trpc.io/docs/client/react/suspense#useinfinitesuspensequery | ||
*/ | ||
useInfiniteQuery: (input: Omit<inferProcedureInput<TProcedure>, 'cursor'>, opts?: UseTRPCInfiniteQueryOptions<TPath, inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>>) => UseTRPCInfiniteQueryResult<inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>>; | ||
/** | ||
* @see https://trpc.io/docs/client/react/suspense | ||
*/ | ||
useSuspenseInfiniteQuery: (input: Omit<inferProcedureInput<TProcedure>, 'cursor'>, opts?: Omit<UseTRPCInfiniteQueryOptions<TPath, inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>>, 'enabled' | 'suspense'>) => [ | ||
InfiniteData<inferTransformedProcedureOutput<TProcedure>>, | ||
UseTRPCInfiniteQuerySuccessResult<inferTransformedProcedureOutput<TProcedure>, TRPCClientErrorLike<TProcedure>> | ||
]; | ||
} : object) : TProcedure extends AnyMutationProcedure ? { | ||
/** | ||
* @see https://trpc.io/docs/client/react/useMutation | ||
@@ -71,8 +56,3 @@ */ | ||
export type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord, TFlags, TPath extends string = ''> = { | ||
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? { | ||
/** | ||
* @deprecated - import `getQueryKey` from `@trpc/react-query` instead | ||
*/ | ||
getQueryKey: () => QueryKey; | ||
} & DecoratedProcedureRecord<TProcedures[TKey]['_def']['record'], TFlags, `${TPath}${TKey & string}.`> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey], TFlags, `${TPath}${TKey & string}`> : never; | ||
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record'], TFlags, `${TPath}${TKey & string}.`> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey], TFlags, `${TPath}${TKey & string}`> : never; | ||
}; | ||
@@ -79,0 +59,0 @@ /** |
export * from '@trpc/client'; | ||
export { getQueryKey } from './internals/getQueryKey'; | ||
export { createTRPCReact, type CreateTRPCReact } from './createTRPCReact'; | ||
export { createReactQueryHooks } from './interop'; | ||
export type { inferReactQueryProcedureOptions } from './utils/inferReactQueryProcedure'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,7 +6,7 @@ 'use strict'; | ||
var client = require('@trpc/client'); | ||
var createHooksInternal = require('./createHooksInternal-466f5861.js'); | ||
var utilsProxy = require('./utilsProxy-d2fa3c0d.js'); | ||
var shared = require('@trpc/server/shared'); | ||
var React = require('react'); | ||
var createHooksInternal = require('./createHooksInternal-80631a60.js'); | ||
require('@tanstack/react-query'); | ||
require('./getArrayQueryKey-4bdb5cc2.js'); | ||
@@ -22,3 +22,3 @@ /** | ||
return React.useMemo(()=>{ | ||
return createHooksInternal.createReactQueryUtilsProxy(context); | ||
return utilsProxy.createReactQueryUtilsProxy(context); | ||
}, [ | ||
@@ -36,3 +36,3 @@ context | ||
function createTRPCReact(opts) { | ||
const hooks = createHooksInternal.createHooksInternal(opts); | ||
const hooks = createHooksInternal.createRootHooks(opts); | ||
const proxy = createHooksInternalProxy(hooks); | ||
@@ -42,16 +42,3 @@ return proxy; | ||
// interop: | ||
/** | ||
* @deprecated use `createTRPCReact` instead | ||
*/ function createReactQueryHooks(opts) { | ||
const trpc = createHooksInternal.createHooksInternal(opts); | ||
const proxy = createHooksInternalProxy(trpc); | ||
return { | ||
...trpc, | ||
proxy | ||
}; | ||
} | ||
exports.getQueryKey = createHooksInternal.getQueryKey; | ||
exports.createReactQueryHooks = createReactQueryHooks; | ||
exports.getQueryKey = utilsProxy.getQueryKey; | ||
exports.createTRPCReact = createTRPCReact; | ||
@@ -58,0 +45,0 @@ Object.keys(client).forEach(function (k) { |
/// <reference types="react" /> | ||
import { CancelOptions, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, QueryClient, RefetchOptions, RefetchQueryFilters, ResetOptions, ResetQueryFilters, SetDataOptions, Updater } from '@tanstack/react-query'; | ||
import { CreateTRPCProxyClient, TRPCClient, TRPCClientError, TRPCRequestOptions } from '@trpc/client'; | ||
import type { AnyRouter } from '@trpc/server'; | ||
import { inferHandlerInput, inferProcedureInput } from '@trpc/server'; | ||
import { inferTransformedProcedureOutput } from '@trpc/server/shared'; | ||
export interface TRPCFetchQueryOptions<TInput, TError, TOutput> extends FetchQueryOptions<TInput, TError, TOutput>, TRPCRequestOptions { | ||
} | ||
export interface TRPCFetchInfiniteQueryOptions<TInput, TError, TOutput> extends FetchInfiniteQueryOptions<TInput, TError, TOutput>, TRPCRequestOptions { | ||
} | ||
import { CancelOptions, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, QueryClient, QueryFilters, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query'; | ||
import { CreateTRPCProxyClient, TRPCClientError, TRPCRequestOptions, TRPCUntypedClient } from '@trpc/client'; | ||
import type { AnyRouter, DistributiveOmit } from '@trpc/server'; | ||
import { ExtractCursorType } from '../shared'; | ||
import { TRPCQueryKey } from './getQueryKey'; | ||
export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'> & TRPCRequestOptions; | ||
export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, TRPCQueryKey, ExtractCursorType<TInput>>, 'queryKey' | 'defaultPageParam'> & TRPCRequestOptions & { | ||
initialCursor?: ExtractCursorType<TInput>; | ||
}; | ||
/** @internal */ | ||
export type SSRState = false | 'prepass' | 'mounting' | 'mounted'; | ||
export type SSRState = 'mounted' | 'mounting' | 'prepass' | false; | ||
export interface ProxyTRPCContextProps<TRouter extends AnyRouter, TSSRContext> { | ||
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
client: TRPCClient<TRouter>; | ||
client: TRPCUntypedClient<TRouter>; | ||
/** | ||
@@ -53,76 +53,60 @@ * The SSR context when server-side rendering | ||
export declare const contextProps: (keyof ProxyTRPCContextProps<any, any>)[]; | ||
/** @internal */ | ||
type TRPCContextResetQueries<TRouter extends AnyRouter> = | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientresetqueries | ||
* @internal | ||
*/ | ||
(<TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>>(pathAndInput?: [TPath, TInput?] | TPath, filters?: ResetQueryFilters, options?: ResetOptions) => Promise<void>) & | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientresetqueries | ||
*/ | ||
((filters?: ResetQueryFilters, options?: ResetOptions) => Promise<void>); | ||
/** | ||
* @deprecated | ||
* @internal | ||
**/ | ||
export interface TRPCContextState<TRouter extends AnyRouter, TSSRContext = undefined> extends Required<TRPCContextProps<TRouter, TSSRContext>> { | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery | ||
*/ | ||
fetchQuery: <TPath extends keyof TRouter['_def']['queries'] & string, TProcedure extends TRouter['_def']['queries'][TPath], TOutput extends inferTransformedProcedureOutput<TProcedure>, TInput extends inferProcedureInput<TProcedure>>(pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>], opts?: TRPCFetchQueryOptions<TInput, TRPCClientError<TProcedure>, TOutput>) => Promise<TOutput>; | ||
fetchQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<unknown>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchinfinitequery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery | ||
*/ | ||
fetchInfiniteQuery: <TPath extends keyof TRouter['_def']['queries'] & string, TProcedure extends TRouter['_def']['queries'][TPath], TOutput extends inferTransformedProcedureOutput<TProcedure>, TInput extends inferProcedureInput<TProcedure>>(pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>], opts?: TRPCFetchInfiniteQueryOptions<TInput, TRPCClientError<TProcedure>, TOutput>) => Promise<InfiniteData<TOutput>>; | ||
fetchInfiniteQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchInfiniteQueryOptions<unknown, unknown, TRPCClientError<TRouter>>) => Promise<InfiniteData<unknown, unknown>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
prefetchQuery: <TPath extends keyof TRouter['_def']['queries'] & string, TProcedure extends TRouter['_def']['queries'][TPath], TOutput extends inferTransformedProcedureOutput<TProcedure>, TInput extends inferProcedureInput<TProcedure>>(pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>], opts?: TRPCFetchQueryOptions<TInput, TRPCClientError<TProcedure>, TOutput>) => Promise<void>; | ||
prefetchQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchinfinitequery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery | ||
*/ | ||
prefetchInfiniteQuery: <TPath extends keyof TRouter['_def']['queries'] & string, TProcedure extends TRouter['_def']['queries'][TPath], TOutput extends inferTransformedProcedureOutput<TProcedure>, TInput extends inferProcedureInput<TProcedure>>(pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>], opts?: TRPCFetchInfiniteQueryOptions<TInput, TRPCClientError<TProcedure>, TOutput>) => Promise<void>; | ||
prefetchInfiniteQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchInfiniteQueryOptions<unknown, unknown, TRPCClientError<TRouter>>) => Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientensurequerydata | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientensurequerydata | ||
*/ | ||
ensureQueryData: <TPath extends keyof TRouter['_def']['queries'] & string, TProcedure extends TRouter['_def']['queries'][TPath], TOutput extends inferTransformedProcedureOutput<TProcedure>, TInput extends inferProcedureInput<TProcedure>>(pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>], opts?: TRPCFetchQueryOptions<TInput, TRPCClientError<TProcedure>, TOutput>) => Promise<TOutput>; | ||
ensureQueryData: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<unknown>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/query-invalidation | ||
* @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation | ||
*/ | ||
invalidateQueries: <TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>>(pathAndInput?: [TPath, TInput?] | TPath, filters?: InvalidateQueryFilters, options?: InvalidateOptions) => Promise<void>; | ||
invalidateQueries: (queryKey: TRPCQueryKey, filters?: InvalidateQueryFilters, options?: InvalidateOptions) => Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientresetqueries | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientresetqueries | ||
*/ | ||
resetQueries: TRPCContextResetQueries<TRouter>; | ||
resetQueries: (queryKey: TRPCQueryKey, filters?: QueryFilters, options?: ResetOptions) => Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientrefetchqueries | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientrefetchqueries | ||
*/ | ||
refetchQueries<TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>>(pathAndInput: [TPath, TInput?], filters?: RefetchQueryFilters, options?: RefetchOptions): Promise<void>; | ||
refetchQueries: (queryKey: TRPCQueryKey, filters?: RefetchQueryFilters, options?: RefetchOptions) => Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientrefetchqueries | ||
* @link https://tanstack.com/query/v5/docs/react/guides/query-cancellation | ||
*/ | ||
refetchQueries(filters?: RefetchQueryFilters, options?: RefetchOptions): Promise<void>; | ||
cancelQuery: (queryKey: TRPCQueryKey, options?: CancelOptions) => Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/query-cancellation | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientsetquerydata | ||
*/ | ||
cancelQuery: <TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>>(pathAndInput: [TPath, TInput?], options?: CancelOptions) => Promise<void>; | ||
setQueryData: (queryKey: TRPCQueryKey, updater: Updater<unknown, unknown>, options?: SetDataOptions) => void; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientsetquerydata | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
setQueryData: <TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>, TOutput extends inferTransformedProcedureOutput<TRouter['_def']['queries'][TPath]>>(pathAndInput: [TPath, TInput?], updater: Updater<TOutput | undefined, TOutput | undefined>, options?: SetDataOptions) => void; | ||
getQueryData: (queryKey: TRPCQueryKey) => unknown; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientgetquerydata | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientsetquerydata | ||
*/ | ||
getQueryData: <TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>, TOutput extends inferTransformedProcedureOutput<TRouter['_def']['queries'][TPath]>>(pathAndInput: [TPath, TInput?]) => TOutput | undefined; | ||
setInfiniteQueryData: (queryKey: TRPCQueryKey, updater: Updater<InfiniteData<unknown> | undefined, InfiniteData<unknown> | undefined>, options?: SetDataOptions) => void; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientsetquerydata | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
setInfiniteQueryData: <TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>, TOutput extends inferTransformedProcedureOutput<TRouter['_def']['queries'][TPath]>>(pathAndInput: [TPath, TInput?], updater: Updater<InfiniteData<TOutput> | undefined, InfiniteData<TOutput> | undefined>, options?: SetDataOptions) => void; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
getInfiniteQueryData: <TPath extends keyof TRouter['_def']['queries'] & string, TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>, TOutput extends inferTransformedProcedureOutput<TRouter['_def']['queries'][TPath]>>(pathAndInput: [TPath, TInput?]) => InfiniteData<TOutput> | undefined; | ||
getInfiniteQueryData: (queryKey: TRPCQueryKey) => InfiniteData<unknown> | undefined; | ||
} | ||
export declare const TRPCContext: import("react").Context<any>; | ||
export {}; | ||
//# sourceMappingURL=context.d.ts.map |
@@ -1,2 +0,3 @@ | ||
export declare function getClientArgs<TPathAndInput extends unknown[], TOptions>(pathAndInput: TPathAndInput, opts: TOptions): readonly [unknown, unknown, any]; | ||
import { TRPCQueryKey } from './getQueryKey'; | ||
export declare function getClientArgs<TOptions>(queryKey: TRPCQueryKey, opts: TOptions, pageParam?: any): readonly [string, unknown, any]; | ||
//# sourceMappingURL=getClientArgs.d.ts.map |
import { AnyMutationProcedure, AnyQueryProcedure, AnyRouter, DeepPartial, inferProcedureInput } from '@trpc/server'; | ||
import { QueryType } from '../internals/getArrayQueryKey'; | ||
import { DecoratedProcedureRecord, DecorateProcedure } from '../shared'; | ||
export type QueryType = 'any' | 'infinite' | 'query'; | ||
export type TRPCQueryKey = [ | ||
string[], | ||
{ | ||
input?: unknown; | ||
type?: Exclude<QueryType, 'any'>; | ||
}? | ||
]; | ||
/** | ||
* We treat `undefined` as an input the same as omitting an `input` | ||
* https://github.com/trpc/trpc/issues/2290 | ||
*/ | ||
export declare function getQueryKeyInternal(path: string, input: unknown): [string] | [string, unknown]; | ||
* To allow easy interactions with groups of related queries, such as | ||
* invalidating all queries of a router, we use an array as the path when | ||
* storing in tanstack query. | ||
**/ | ||
export declare function getQueryKeyInternal(path: string[], input: unknown, type: QueryType): TRPCQueryKey; | ||
type GetInfiniteQueryInput<TProcedureInput, TInputWithoutCursor = Omit<TProcedureInput, 'cursor'>> = keyof TInputWithoutCursor extends never ? undefined : DeepPartial<TInputWithoutCursor> | undefined; | ||
@@ -15,3 +23,3 @@ /** @internal */ | ||
type GetQueryParams<TProcedureOrRouter extends AnyQueryProcedure, TProcedureInput = inferProcedureInput<TProcedureOrRouter>> = TProcedureInput extends undefined ? [] : [input?: GetQueryProcedureInput<TProcedureInput>, type?: QueryType]; | ||
type GetParams<TProcedureOrRouter extends AnyQueryProcedure | AnyMutationProcedure | AnyRouter, TPath extends string, TFlags> = TProcedureOrRouter extends AnyQueryProcedure ? [ | ||
type GetParams<TProcedureOrRouter extends AnyMutationProcedure | AnyQueryProcedure | AnyRouter, TPath extends string, TFlags> = TProcedureOrRouter extends AnyQueryProcedure ? [ | ||
procedureOrRouter: DecorateProcedure<TProcedureOrRouter, TFlags, TPath>, | ||
@@ -22,3 +30,3 @@ ..._params: GetQueryParams<TProcedureOrRouter> | ||
]; | ||
type GetQueryKeyParams<TProcedureOrRouter extends AnyQueryProcedure | AnyMutationProcedure | AnyRouter, TPath extends string, TFlags> = GetParams<TProcedureOrRouter, TPath, TFlags>; | ||
type GetQueryKeyParams<TProcedureOrRouter extends AnyMutationProcedure | AnyQueryProcedure | AnyRouter, TPath extends string, TFlags> = GetParams<TProcedureOrRouter, TPath, TFlags>; | ||
/** | ||
@@ -31,4 +39,11 @@ * Method to extract the query key for a procedure | ||
*/ | ||
export declare function getQueryKey<TProcedureOrRouter extends AnyQueryProcedure | AnyMutationProcedure | AnyRouter, TPath extends string, TFlags>(..._params: GetQueryKeyParams<TProcedureOrRouter, TPath, TFlags>): import("../internals/getArrayQueryKey").QueryKey; | ||
export declare function getQueryKey<TProcedureOrRouter extends AnyMutationProcedure | AnyQueryProcedure | AnyRouter, TPath extends string, TFlags>(..._params: GetQueryKeyParams<TProcedureOrRouter, TPath, TFlags>): TRPCQueryKey; | ||
export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [ | ||
string[], | ||
{ | ||
input?: GetQueryProcedureInput<TInput>; | ||
type: TType; | ||
}? | ||
]; | ||
export {}; | ||
//# sourceMappingURL=getQueryKey.d.ts.map |
import { QueryKey, UseQueryOptions } from '@tanstack/react-query'; | ||
import { AnyRouter } from '@trpc/server'; | ||
import { AnyRouter, DistributiveOmit } from '@trpc/server'; | ||
import { UseQueriesProcedureRecord, UseTRPCQueryOptions, UseTRPCQueryResult } from '../shared'; | ||
@@ -7,7 +7,7 @@ /** | ||
*/ | ||
export type UseQueryOptionsForUseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>; | ||
export type UseQueryOptionsForUseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = DistributiveOmit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>; | ||
/** | ||
* @internal | ||
*/ | ||
export type TrpcQueryOptionsForUseQueries<TPath, TInput, TOutput, TData, TError> = Omit<UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>, 'context'>; | ||
export type TrpcQueryOptionsForUseQueries<TPath, TInput, TOutput, TData, TError> = DistributiveOmit<UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>, 'queryKey'>; | ||
/** | ||
@@ -27,4 +27,4 @@ * @internal | ||
*/ | ||
export type TRPCUseQueries<TRouter extends AnyRouter> = <TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[]>(queriesCallback: (t: UseQueriesProcedureRecord<TRouter>) => readonly [...QueriesOptions<TQueryOptions>], context?: UseQueryOptions['context']) => QueriesResults<TQueryOptions>; | ||
export type TRPCUseQueries<TRouter extends AnyRouter> = <TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[]>(queriesCallback: (t: UseQueriesProcedureRecord<TRouter>) => readonly [...QueriesOptions<TQueryOptions>]) => QueriesResults<TQueryOptions>; | ||
export {}; | ||
//# sourceMappingURL=useQueries.d.ts.map |
export { createServerSideHelpers } from './ssgProxy'; | ||
export type { | ||
/** | ||
* @deprecated this exported is planned to be removed in the next major version | ||
*/ | ||
CreateServerSideHelpersOptions as CreateSSGHelpersOptions, } from './types'; | ||
export type { DecoratedProcedureSSGRecord } from './ssgProxy'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,7 +5,7 @@ 'use strict'; | ||
var shared = require('@trpc/server/shared'); | ||
var reactQuery = require('@tanstack/react-query'); | ||
var client = require('@trpc/client'); | ||
var server = require('@trpc/server'); | ||
var getArrayQueryKey = require('../getArrayQueryKey-4bdb5cc2.js'); | ||
var shared = require('@trpc/server/shared'); | ||
var utilsProxy = require('../utilsProxy-d2fa3c0d.js'); | ||
require('react'); | ||
@@ -16,4 +16,4 @@ var queryClient = require('../queryClient-358a9a75.js'); | ||
* Create functions you can use for server-side rendering / static generation | ||
* @deprecated use `createServerSideHelpers` instead | ||
*/ function createSSGHelpers(opts) { | ||
* @see https://trpc.io/docs/client/nextjs/server-side-helpers | ||
*/ function createServerSideHelpers(opts) { | ||
const queryClient$1 = queryClient.getQueryClient(opts); | ||
@@ -37,3 +37,3 @@ const resolvedOpts = (()=>{ | ||
const { client: client$1 } = opts; | ||
const untypedClient = client.getUntypedClient(client$1); | ||
const untypedClient = client$1 instanceof client.TRPCUntypedClient ? client$1 : client.getUntypedClient(client$1); | ||
return { | ||
@@ -44,38 +44,2 @@ query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input), | ||
})(); | ||
const prefetchQuery = async (...pathAndInput)=>{ | ||
return queryClient$1.prefetchQuery({ | ||
queryKey: getArrayQueryKey.getArrayQueryKey(pathAndInput, 'query'), | ||
queryFn: ()=>resolvedOpts.query({ | ||
path: pathAndInput[0], | ||
input: pathAndInput[1] | ||
}) | ||
}); | ||
}; | ||
const prefetchInfiniteQuery = async (...pathAndInput)=>{ | ||
return queryClient$1.prefetchInfiniteQuery({ | ||
queryKey: getArrayQueryKey.getArrayQueryKey(pathAndInput, 'infinite'), | ||
queryFn: ()=>resolvedOpts.query({ | ||
path: pathAndInput[0], | ||
input: pathAndInput[1] | ||
}) | ||
}); | ||
}; | ||
const fetchQuery = async (...pathAndInput)=>{ | ||
return queryClient$1.fetchQuery({ | ||
queryKey: getArrayQueryKey.getArrayQueryKey(pathAndInput, 'query'), | ||
queryFn: ()=>resolvedOpts.query({ | ||
path: pathAndInput[0], | ||
input: pathAndInput[1] | ||
}) | ||
}); | ||
}; | ||
const fetchInfiniteQuery = async (...pathAndInput)=>{ | ||
return queryClient$1.fetchInfiniteQuery({ | ||
queryKey: getArrayQueryKey.getArrayQueryKey(pathAndInput, 'infinite'), | ||
queryFn: ()=>resolvedOpts.query({ | ||
path: pathAndInput[0], | ||
input: pathAndInput[1] | ||
}) | ||
}); | ||
}; | ||
function _dehydrate(opts = { | ||
@@ -91,36 +55,55 @@ shouldDehydrateQuery () { | ||
} | ||
return { | ||
prefetchQuery, | ||
prefetchInfiniteQuery, | ||
fetchQuery, | ||
fetchInfiniteQuery, | ||
dehydrate: _dehydrate, | ||
queryClient: queryClient$1 | ||
}; | ||
} | ||
/** | ||
* Create functions you can use for server-side rendering / static generation | ||
* @see https://trpc.io/docs/client/nextjs/server-side-helpers | ||
*/ function createServerSideHelpers(opts) { | ||
const helpers = createSSGHelpers(opts); | ||
return shared.createFlatProxy((key)=>{ | ||
if (key === 'queryClient') { | ||
return helpers.queryClient; | ||
} | ||
if (key === 'dehydrate') { | ||
return helpers.dehydrate; | ||
} | ||
if (key === 'queryClient') return queryClient$1; | ||
if (key === 'dehydrate') return _dehydrate; | ||
return shared.createRecursiveProxy((opts)=>{ | ||
const args = opts.args; | ||
const pathCopy = [ | ||
const input = args[0]; | ||
const arrayPath = [ | ||
key, | ||
...opts.path | ||
]; | ||
const utilName = pathCopy.pop(); | ||
const fullPath = pathCopy.join('.'); | ||
const helperKey = `${utilName}Query`; | ||
// ^? | ||
const fn = helpers[helperKey]; | ||
return fn(fullPath, ...args); | ||
const utilName = arrayPath.pop(); | ||
const queryFn = ()=>resolvedOpts.query({ | ||
path: arrayPath.join('.'), | ||
input | ||
}); | ||
const queryKey = utilsProxy.getQueryKeyInternal(arrayPath, input, utilsProxy.getQueryType(utilName)); | ||
const helperMap = { | ||
fetch: ()=>{ | ||
const args1 = args[1]; | ||
return queryClient$1.fetchQuery({ | ||
...args1, | ||
queryKey, | ||
queryFn | ||
}); | ||
}, | ||
fetchInfinite: ()=>{ | ||
const args1 = args[1]; | ||
return queryClient$1.fetchInfiniteQuery({ | ||
...args1, | ||
queryKey, | ||
queryFn, | ||
defaultPageParam: args1?.initialCursor ?? null | ||
}); | ||
}, | ||
prefetch: ()=>{ | ||
const args1 = args[1]; | ||
return queryClient$1.prefetchQuery({ | ||
...args1, | ||
queryKey, | ||
queryFn | ||
}); | ||
}, | ||
prefetchInfinite: ()=>{ | ||
const args1 = args[1]; | ||
return queryClient$1.prefetchInfiniteQuery({ | ||
...args1, | ||
queryKey, | ||
queryFn, | ||
defaultPageParam: args1?.initialCursor ?? null | ||
}); | ||
} | ||
}; | ||
return helperMap[utilName](); | ||
}); | ||
@@ -127,0 +110,0 @@ }); |
import { DehydratedState, DehydrateOptions, InfiniteData, QueryClient } from '@tanstack/react-query'; | ||
import { AnyProcedure, AnyQueryProcedure, AnyRouter, Filter, inferHandlerInput, ProtectedIntersection } from '@trpc/server'; | ||
import { inferRouterProxyClient, TRPCClientError, TRPCUntypedClient } from '@trpc/client'; | ||
import { AnyProcedure, AnyQueryProcedure, AnyRouter, ClientDataTransformerOptions, Filter, inferProcedureInput, inferRouterContext, ProtectedIntersection } from '@trpc/server'; | ||
import { inferTransformedProcedureOutput } from '@trpc/server/shared'; | ||
import { CreateServerSideHelpersOptions } from './types'; | ||
import { CreateTRPCReactQueryClientConfig, ExtractCursorType, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from '../shared'; | ||
interface CreateSSGHelpersInternal<TRouter extends AnyRouter> { | ||
router: TRouter; | ||
ctx: inferRouterContext<TRouter>; | ||
transformer?: ClientDataTransformerOptions; | ||
} | ||
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> { | ||
client: inferRouterProxyClient<TRouter> | TRPCUntypedClient<TRouter>; | ||
} | ||
type CreateServerSideHelpersOptions<TRouter extends AnyRouter> = CreateTRPCReactQueryClientConfig & (CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>); | ||
type DecorateProcedure<TProcedure extends AnyProcedure> = { | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
fetch(...args: inferHandlerInput<TProcedure>): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
fetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
fetchInfinite(...args: inferHandlerInput<TProcedure>): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>>>; | ||
fetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
prefetch(...args: inferHandlerInput<TProcedure>): Promise<void>; | ||
prefetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
prefetchInfinite(...args: inferHandlerInput<TProcedure>): Promise<void>; | ||
prefetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<void>; | ||
}; | ||
@@ -26,4 +36,4 @@ /** | ||
*/ | ||
export type DecoratedProcedureSSGRecord<TRouter extends AnyRouter> = { | ||
[TKey in keyof Filter<TRouter['_def']['record'], AnyRouter | AnyQueryProcedure>]: TRouter['_def']['record'][TKey] extends AnyRouter ? DecoratedProcedureSSGRecord<TRouter['_def']['record'][TKey]> : DecorateProcedure<TRouter['_def']['record'][TKey]>; | ||
type DecoratedProcedureSSGRecord<TRouter extends AnyRouter> = { | ||
[TKey in keyof Filter<TRouter['_def']['record'], AnyQueryProcedure | AnyRouter>]: TRouter['_def']['record'][TKey] extends AnyRouter ? DecoratedProcedureSSGRecord<TRouter['_def']['record'][TKey]> : DecorateProcedure<TRouter['_def']['record'][TKey]>; | ||
}; | ||
@@ -30,0 +40,0 @@ /** |
import { TRPCClientErrorLike } from '@trpc/client'; | ||
import type { AnyRouter } from '@trpc/server'; | ||
import { Observable } from '@trpc/server/observable'; | ||
import { TRPCContextState } from '../../internals/context'; | ||
import { TRPCUseQueries } from '../../internals/useQueries'; | ||
import { CreateTRPCReactOptions } from '../types'; | ||
import { CreateClient, TRPCProvider, UseDehydratedState, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCSubscriptionOptions } from './types'; | ||
import { CreateClient, TRPCProvider, UseDehydratedState, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult } from './types'; | ||
/** | ||
@@ -15,15 +14,38 @@ * @internal | ||
useContext: () => TRPCContextState<TRouter, TSSRContext>; | ||
useQuery: (pathAndInput: [path: string, ...args: unknown[]], opts?: UseTRPCQueryOptions<unknown, unknown, unknown, unknown, TRPCClientErrorLike<TRouter>, unknown> | undefined) => UseTRPCQueryResult<unknown, TRPCClientErrorLike<TRouter>>; | ||
useQuery: (path: string[], input: unknown, opts?: UseTRPCQueryOptions<unknown, unknown, unknown, unknown, TRPCClientErrorLike<TRouter>, unknown> | undefined) => UseTRPCQueryResult<unknown, TRPCClientErrorLike<TRouter>>; | ||
useSuspenseQuery: (path: string[], input: unknown, opts?: UseTRPCSuspenseQueryOptions<unknown, unknown, unknown, unknown, TRPCClientErrorLike<TRouter>> | undefined) => UseTRPCSuspenseQueryResult<unknown, TRPCClientErrorLike<TRouter>>; | ||
useQueries: TRPCUseQueries<TRouter>; | ||
useMutation: (path: string | [string], opts?: UseTRPCMutationOptions<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown> | undefined) => UseTRPCMutationResult<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>; | ||
useSubscription: (pathAndInput: [ | ||
path: string, | ||
...args: unknown[] | ||
], opts: UseTRPCSubscriptionOptions<Observable<unknown, unknown>, TRPCClientErrorLike<TRouter>>) => void; | ||
useMutation: (path: string[], opts?: UseTRPCMutationOptions<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown> | undefined) => UseTRPCMutationResult<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>; | ||
useSubscription: (path: string[], input: unknown, opts: UseTRPCSubscriptionOptions<unknown, TRPCClientErrorLike<TRouter>>) => void; | ||
useDehydratedState: UseDehydratedState<TRouter>; | ||
useInfiniteQuery: (pathAndInput: [ | ||
path: string, | ||
input: Record<any, unknown> | ||
], opts?: UseTRPCInfiniteQueryOptions<unknown, unknown, unknown, TRPCClientErrorLike<TRouter>> | undefined) => UseTRPCInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>>; | ||
useInfiniteQuery: (path: string[], input: unknown, opts: UseTRPCInfiniteQueryOptions<unknown, unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>; | ||
useSuspenseInfiniteQuery: (path: string[], input: unknown, opts: UseTRPCSuspenseInfiniteQueryOptions<unknown, unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCSuspenseInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>; | ||
}; | ||
/** | ||
* Hack to infer the type of `createReactQueryHooks` | ||
* @link https://stackoverflow.com/a/59072991 | ||
*/ | ||
declare class GnClass<TRouter extends AnyRouter, TSSRContext = unknown> { | ||
fn(): { | ||
Provider: TRPCProvider<TRouter, TSSRContext>; | ||
createClient: CreateClient<TRouter>; | ||
useContext: () => TRPCContextState<TRouter, TSSRContext>; | ||
useQuery: (path: string[], input: unknown, opts?: UseTRPCQueryOptions<unknown, unknown, unknown, unknown, TRPCClientErrorLike<TRouter>, unknown> | undefined) => UseTRPCQueryResult<unknown, TRPCClientErrorLike<TRouter>>; | ||
useSuspenseQuery: (path: string[], input: unknown, opts?: UseTRPCSuspenseQueryOptions<unknown, unknown, unknown, unknown, TRPCClientErrorLike<TRouter>> | undefined) => UseTRPCSuspenseQueryResult<unknown, TRPCClientErrorLike<TRouter>>; | ||
useQueries: TRPCUseQueries<TRouter>; | ||
useMutation: (path: string[], opts?: UseTRPCMutationOptions<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown> | undefined) => UseTRPCMutationResult<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>; | ||
useSubscription: (path: string[], input: unknown, opts: UseTRPCSubscriptionOptions<unknown, TRPCClientErrorLike<TRouter>>) => void; | ||
useDehydratedState: UseDehydratedState<TRouter>; | ||
useInfiniteQuery: (path: string[], input: unknown, opts: UseTRPCInfiniteQueryOptions<unknown, unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>; | ||
useSuspenseInfiniteQuery: (path: string[], input: unknown, opts: UseTRPCSuspenseInfiniteQueryOptions<unknown, unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCSuspenseInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>; | ||
}; | ||
} | ||
type returnTypeInferer<TType> = TType extends (a: Record<string, string>) => infer U ? U : never; | ||
type fooType<TRouter extends AnyRouter, TSSRContext = unknown> = GnClass<TRouter, TSSRContext>['fn']; | ||
/** | ||
* Infer the type of a `createReactQueryHooks` function | ||
* @internal | ||
*/ | ||
export type CreateReactQueryHooks<TRouter extends AnyRouter, TSSRContext = unknown> = returnTypeInferer<fooType<TRouter, TSSRContext>>; | ||
export {}; | ||
//# sourceMappingURL=createHooksInternal.d.ts.map |
export { createRootHooks } from './createHooksInternal'; | ||
/** | ||
* @deprecated | ||
* DELETE ME | ||
*/ | ||
export * from './deprecated/createHooksInternal'; | ||
//# sourceMappingURL=createRootHooks.d.ts.map |
@@ -1,6 +0,7 @@ | ||
import { DefinedUseQueryResult, DehydratedState, InfiniteQueryObserverSuccessResult, InitialDataFunction, QueryObserverSuccessResult, QueryOptions, UseBaseQueryOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryResult } from '@tanstack/react-query'; | ||
import { CreateTRPCClientOptions, TRPCClient, TRPCRequestOptions } from '@trpc/client'; | ||
import { AnyRouter } from '@trpc/server'; | ||
import { DefinedUseQueryResult, DehydratedState, InfiniteData, InfiniteQueryObserverSuccessResult, InitialDataFunction, QueryObserverSuccessResult, QueryOptions, UseBaseQueryOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query'; | ||
import { CreateTRPCClientOptions, TRPCRequestOptions, TRPCUntypedClient } from '@trpc/client'; | ||
import { AnyRouter, DistributiveOmit } from '@trpc/server'; | ||
import { ReactNode } from 'react'; | ||
import { TRPCContextProps } from '../../internals/context'; | ||
import { TRPCQueryKey } from '../../internals/getQueryKey'; | ||
import { TRPCHookResult } from '../../internals/useHookResult'; | ||
@@ -27,22 +28,31 @@ export type OutputWithCursor<TData, TCursor = any> = { | ||
} | ||
export interface UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData = TOutput> extends UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, [ | ||
export interface UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, [ | ||
TPath, | ||
TInput | ||
]>, TRPCUseQueryBaseOptions { | ||
]>, 'queryKey'>, TRPCUseQueryBaseOptions { | ||
} | ||
export interface UseTRPCSuspenseQueryOptions<TPath, TInput, TOutput, TData, TError> extends DistributiveOmit<UseSuspenseQueryOptions<TOutput, TError, TData, [TPath, TInput]>, 'queryKey'>, TRPCUseQueryBaseOptions { | ||
} | ||
/** @internal **/ | ||
export interface DefinedUseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData = TOutput> extends UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData> { | ||
initialData: TQueryOptsData | InitialDataFunction<TQueryOptsData>; | ||
export interface DefinedUseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData>, 'queryKey'> { | ||
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData; | ||
} | ||
export interface TRPCQueryOptions<TPath, TInput, TData, TError> extends QueryOptions<TData, TError, TData, [TPath, TInput]>, TRPCUseQueryBaseOptions { | ||
export interface TRPCQueryOptions<TPath, TInput, TData, TError> extends DistributiveOmit<QueryOptions<TData, TError, TData, [TPath, TInput]>, 'queryKey'>, TRPCUseQueryBaseOptions { | ||
queryKey: TRPCQueryKey; | ||
} | ||
export type ExtractCursorType<TInput> = TInput extends { | ||
cursor: any; | ||
cursor?: any; | ||
} ? TInput['cursor'] : unknown; | ||
export interface UseTRPCInfiniteQueryOptions<TPath, TInput, TOutput, TError> extends UseInfiniteQueryOptions<TOutput, TError, TOutput, TOutput, [ | ||
export interface UseTRPCInfiniteQueryOptions<TPath, TInput, TOutput, TError> extends DistributiveOmit<UseInfiniteQueryOptions<TOutput, TError, TOutput, TOutput, [ | ||
TPath, | ||
Omit<TInput, 'cursor'> | ||
]>, TRPCUseQueryBaseOptions { | ||
], ExtractCursorType<TInput>>, 'queryKey' | 'defaultPageParam'>, TRPCUseQueryBaseOptions { | ||
initialCursor?: ExtractCursorType<TInput>; | ||
} | ||
export interface UseTRPCSuspenseInfiniteQueryOptions<TPath, TInput, TOutput, TError> extends DistributiveOmit<UseSuspenseInfiniteQueryOptions<TOutput, TError, TOutput, TOutput, [ | ||
TPath, | ||
Omit<TInput, 'cursor'> | ||
], ExtractCursorType<TInput>>, 'queryKey' | 'defaultPageParam'>, TRPCUseQueryBaseOptions { | ||
initialCursor?: ExtractCursorType<TInput>; | ||
} | ||
export interface UseTRPCMutationOptions<TInput, TError, TOutput, TContext = unknown> extends UseMutationOptions<TOutput, TError, TInput, TContext>, TRPCUseQueryBaseOptions { | ||
@@ -60,8 +70,8 @@ } | ||
export type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (props: TRPCProviderProps<TRouter, TSSRContext>) => JSX.Element; | ||
export type UseDehydratedState<TRouter extends AnyRouter> = (client: TRPCClient<TRouter>, trpcState: DehydratedState | undefined) => DehydratedState | undefined; | ||
export type CreateClient<TRouter extends AnyRouter> = (opts: CreateTRPCClientOptions<TRouter>) => TRPCClient<TRouter>; | ||
export type UseDehydratedState<TRouter extends AnyRouter> = (client: TRPCUntypedClient<TRouter>, trpcState: DehydratedState | undefined) => DehydratedState | undefined; | ||
export type CreateClient<TRouter extends AnyRouter> = (opts: CreateTRPCClientOptions<TRouter>) => TRPCUntypedClient<TRouter>; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCQueryResult<TData, TError> = UseQueryResult<TData, TError> & TRPCHookResult; | ||
export type UseTRPCQueryResult<TData, TError> = TRPCHookResult & UseQueryResult<TData, TError>; | ||
/** | ||
@@ -78,11 +88,25 @@ * @internal | ||
*/ | ||
export type UseTRPCInfiniteQueryResult<TData, TError> = UseInfiniteQueryResult<TData, TError> & TRPCHookResult; | ||
export type UseTRPCSuspenseQueryResult<TData, TError> = [ | ||
TData, | ||
UseSuspenseQueryResult<TData, TError> & TRPCHookResult | ||
]; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCInfiniteQuerySuccessResult<TData, TError> = InfiniteQueryObserverSuccessResult<TData, TError> & TRPCHookResult; | ||
export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult & UseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError>; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> = UseMutationResult<TData, TError, TVariables, TContext> & TRPCHookResult; | ||
export type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> = InfiniteQueryObserverSuccessResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [ | ||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, | ||
UseSuspenseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult | ||
]; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> = TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -5,8 +5,8 @@ 'use strict'; | ||
var createHooksInternal = require('../createHooksInternal-466f5861.js'); | ||
var createHooksInternal = require('../createHooksInternal-80631a60.js'); | ||
var utilsProxy = require('../utilsProxy-d2fa3c0d.js'); | ||
var queryClient = require('../queryClient-358a9a75.js'); | ||
require('@trpc/server/shared'); | ||
require('../getArrayQueryKey-4bdb5cc2.js'); | ||
require('@tanstack/react-query'); | ||
require('@trpc/client'); | ||
require('@tanstack/react-query'); | ||
require('react'); | ||
@@ -16,10 +16,10 @@ | ||
exports.TRPCContext = createHooksInternal.TRPCContext; | ||
exports.contextProps = createHooksInternal.contextProps; | ||
exports.createHooksInternal = createHooksInternal.createHooksInternal; | ||
exports.createReactProxyDecoration = createHooksInternal.createReactProxyDecoration; | ||
exports.createReactQueryUtilsProxy = createHooksInternal.createReactQueryUtilsProxy; | ||
exports.createRootHooks = createHooksInternal.createRootHooks; | ||
exports.createUseQueriesProxy = createHooksInternal.createUseQueriesProxy; | ||
exports.getClientArgs = createHooksInternal.getClientArgs; | ||
exports.TRPCContext = utilsProxy.TRPCContext; | ||
exports.contextProps = utilsProxy.contextProps; | ||
exports.createReactQueryUtilsProxy = utilsProxy.createReactQueryUtilsProxy; | ||
exports.getQueryType = utilsProxy.getQueryType; | ||
exports.getQueryClient = queryClient.getQueryClient; |
import { AnyRouter } from '@trpc/server'; | ||
import { CreateReactQueryHooks } from '../hooks/createRootHooks'; | ||
import { CreateReactQueryHooks } from '../hooks/createHooksInternal'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Create proxy for decorating procedures |
@@ -1,2 +0,2 @@ | ||
import { TRPCClient, TRPCClientError } from '@trpc/client'; | ||
import { TRPCClientError, TRPCUntypedClient } from '@trpc/client'; | ||
import { AnyProcedure, AnyQueryProcedure, AnyRouter, Filter, inferProcedureInput } from '@trpc/server'; | ||
@@ -10,3 +10,3 @@ import { inferTransformedProcedureOutput } from '@trpc/server/shared'; | ||
export type UseQueriesProcedureRecord<TRouter extends AnyRouter, TPath extends string = ''> = { | ||
[TKey in keyof Filter<TRouter['_def']['record'], AnyRouter | AnyQueryProcedure>]: TRouter['_def']['record'][TKey] extends AnyRouter ? UseQueriesProcedureRecord<TRouter['_def']['record'][TKey], `${TPath}${TKey & string}.`> : GetQueryOptions<TRouter['_def']['record'][TKey], `${TPath}${TKey & string}`>; | ||
[TKey in keyof Filter<TRouter['_def']['record'], AnyQueryProcedure | AnyRouter>]: TRouter['_def']['record'][TKey] extends AnyRouter ? UseQueriesProcedureRecord<TRouter['_def']['record'][TKey], `${TPath}${TKey & string}.`> : GetQueryOptions<TRouter['_def']['record'][TKey], `${TPath}${TKey & string}`>; | ||
}; | ||
@@ -17,4 +17,4 @@ /** | ||
*/ | ||
export declare function createUseQueriesProxy<TRouter extends AnyRouter>(client: TRPCClient<TRouter>): UseQueriesProcedureRecord<TRouter, "">; | ||
export declare function createUseQueriesProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): UseQueriesProcedureRecord<TRouter, "">; | ||
export {}; | ||
//# sourceMappingURL=useQueriesProxy.d.ts.map |
import { CancelOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, Query, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query'; | ||
import { TRPCClientError } from '@trpc/client'; | ||
import { AnyQueryProcedure, AnyRouter, DeepPartial, Filter, inferProcedureInput, ProtectedIntersection } from '@trpc/server'; | ||
import { AnyQueryProcedure, AnyRouter, DeepPartial, Filter, inferProcedureInput, MaybePromise, ProtectedIntersection } from '@trpc/server'; | ||
import { inferTransformedProcedureOutput } from '@trpc/server/shared'; | ||
import { DecoratedProxyTRPCContextProps, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from '../../internals/context'; | ||
import { QueryKeyKnown } from '../../internals/getArrayQueryKey'; | ||
import { QueryKeyKnown, QueryType, TRPCQueryKey } from '../../internals/getQueryKey'; | ||
import { ExtractCursorType } from '../hooks/types'; | ||
type DecorateProcedure<TProcedure extends AnyQueryProcedure> = { | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery | ||
*/ | ||
fetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TProcedure>, inferTransformedProcedureOutput<TProcedure>>): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
fetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchinfinitequery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery | ||
*/ | ||
fetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TProcedure>, inferTransformedProcedureOutput<TProcedure>>): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>>>; | ||
fetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchquery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery | ||
*/ | ||
prefetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TProcedure>, inferTransformedProcedureOutput<TProcedure>>): Promise<void>; | ||
prefetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchinfinitequery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery | ||
*/ | ||
prefetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TProcedure>, inferTransformedProcedureOutput<TProcedure>>): Promise<void>; | ||
prefetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientensurequerydata | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientensurequerydata | ||
*/ | ||
ensureData(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TProcedure>, inferTransformedProcedureOutput<TProcedure>>): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
ensureData(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TProcedure>, TRPCClientError<TProcedure>>): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientinvalidatequeries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries | ||
*/ | ||
@@ -37,15 +38,15 @@ invalidate(input?: DeepPartial<inferProcedureInput<TProcedure>>, filters?: Omit<InvalidateQueryFilters, 'predicate'> & { | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientrefetchqueries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries | ||
*/ | ||
refetch(input?: inferProcedureInput<TProcedure>, filters?: RefetchQueryFilters, options?: RefetchOptions): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientcancelqueries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries | ||
*/ | ||
cancel(input?: inferProcedureInput<TProcedure>, options?: CancelOptions): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientresetqueries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries | ||
*/ | ||
reset(input?: inferProcedureInput<TProcedure>, options?: ResetOptions): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientsetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata | ||
*/ | ||
@@ -58,13 +59,13 @@ setData( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientsetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata | ||
*/ | ||
setInfiniteData(input: inferProcedureInput<TProcedure>, updater: Updater<InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined, InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined>, options?: SetDataOptions): void; | ||
setInfiniteData(input: inferProcedureInput<TProcedure>, updater: Updater<InfiniteData<inferTransformedProcedureOutput<TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined, InfiniteData<inferTransformedProcedureOutput<TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined>, options?: SetDataOptions): void; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientgetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
getData(input?: inferProcedureInput<TProcedure>): inferTransformedProcedureOutput<TProcedure> | undefined; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientgetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined; | ||
getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined; | ||
}; | ||
@@ -79,3 +80,3 @@ /** | ||
* @link https://trpc.io/docs/v10/useContext#query-invalidation | ||
* @link https://tanstack.com/query/v4/docs/react/guides/query-invalidation | ||
* @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation | ||
*/ | ||
@@ -87,11 +88,17 @@ invalidate(input?: undefined, filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise<void>; | ||
*/ | ||
export type DecoratedProcedureUtilsRecord<TRouter extends AnyRouter> = { | ||
[TKey in keyof Filter<TRouter['_def']['record'], AnyRouter | AnyQueryProcedure>]: TRouter['_def']['record'][TKey] extends AnyRouter ? DecoratedProcedureUtilsRecord<TRouter['_def']['record'][TKey]> & DecorateRouter : DecorateProcedure<TRouter['_def']['record'][TKey]>; | ||
} & DecorateRouter; | ||
export type DecoratedProcedureUtilsRecord<TRouter extends AnyRouter> = DecorateRouter & { | ||
[TKey in keyof Filter<TRouter['_def']['record'], AnyQueryProcedure | AnyRouter>]: TRouter['_def']['record'][TKey] extends AnyRouter ? DecoratedProcedureUtilsRecord<TRouter['_def']['record'][TKey]> & DecorateRouter : DecorateProcedure<TRouter['_def']['record'][TKey]>; | ||
}; | ||
type AnyDecoratedProcedure = DecorateProcedure<any>; | ||
export type CreateReactUtilsProxy<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<DecoratedProxyTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter>>; | ||
export declare const getQueryType: (utilName: keyof AnyDecoratedProcedure) => QueryType; | ||
/** | ||
* @internal | ||
*/ | ||
export declare function createReactQueryUtilsProxy<TRouter extends AnyRouter, TSSRContext>(context: TRPCContextState<AnyRouter, unknown>): ProtectedIntersection<DecoratedProxyTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter>>; | ||
export declare function createReactQueryUtilsProxy<TRouter extends AnyRouter, TSSRContext>(context: TRPCContextState<AnyRouter, unknown>, overrides?: Partial<Record<keyof AnyDecoratedProcedure, (opts: { | ||
queryKey: TRPCQueryKey; | ||
path: string[]; | ||
input: unknown; | ||
}) => MaybePromise<void>>>): ProtectedIntersection<DecoratedProxyTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter>>; | ||
export {}; | ||
//# sourceMappingURL=utilsProxy.d.ts.map |
@@ -26,10 +26,3 @@ /// <reference types="react" /> | ||
* Override behaviors of the built-in hooks | ||
* @deprecated use `overrides` instead | ||
*/ | ||
unstable_overrides?: { | ||
useMutation?: Partial<UseMutationOverride>; | ||
}; | ||
/** | ||
* Override behaviors of the built-in hooks | ||
*/ | ||
overrides?: { | ||
@@ -48,8 +41,3 @@ useMutation?: Partial<UseMutationOverride>; | ||
context?: React.Context<any>; | ||
/** | ||
* Override the default React Query context | ||
* @default undefined | ||
*/ | ||
reactQueryContext?: React.Context<QueryClient | undefined>; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@trpc/react-query", | ||
"version": "10.32.0", | ||
"version": "10.32.1-alpha-actions-2-2023-08-09-10-23-47.45+696472da3", | ||
"description": "The tRPC React library", | ||
@@ -39,7 +39,2 @@ "author": "KATT", | ||
"default": "./dist/shared/index.js" | ||
}, | ||
"./ssg": { | ||
"import": "./dist/ssg/index.mjs", | ||
"require": "./dist/ssg/index.js", | ||
"default": "./dist/ssg/index.js" | ||
} | ||
@@ -54,3 +49,2 @@ }, | ||
"shared", | ||
"ssg", | ||
"!**/*.test.*" | ||
@@ -68,5 +62,5 @@ ], | ||
"peerDependencies": { | ||
"@tanstack/react-query": "^4.18.0", | ||
"@trpc/client": "10.32.0", | ||
"@trpc/server": "10.32.0", | ||
"@tanstack/react-query": "^5.0.0-beta.9", | ||
"@trpc/client": "10.32.1-alpha-actions-2-2023-08-09-10-23-47.45+696472da3", | ||
"@trpc/server": "10.32.1-alpha-actions-2-2023-08-09-10-23-47.45+696472da3", | ||
"react": ">=16.8.0", | ||
@@ -76,5 +70,5 @@ "react-dom": ">=16.8.0" | ||
"devDependencies": { | ||
"@tanstack/react-query": "^4.18.0", | ||
"@trpc/client": "10.32.0", | ||
"@trpc/server": "10.32.0", | ||
"@tanstack/react-query": "^5.0.0-beta.9", | ||
"@trpc/client": "10.32.1-alpha-actions-2-2023-08-09-10-23-47.45+696472da3", | ||
"@trpc/server": "10.32.1-alpha-actions-2-2023-08-09-10-23-47.45+696472da3", | ||
"@types/express": "^4.17.17", | ||
@@ -85,3 +79,3 @@ "@types/node": "^18.16.16", | ||
"express": "^4.17.1", | ||
"next": "^13.4.3", | ||
"next": "^13.4.13", | ||
"react": "^18.2.0", | ||
@@ -99,3 +93,3 @@ "react-dom": "^18.2.0", | ||
], | ||
"gitHead": "f8cf27c773b97dedb5eb95ca548cee7acb55c92a" | ||
"gitHead": "696472da3e2725eb043bce42883365e07fd25bec" | ||
} |
@@ -5,3 +5,2 @@ export * from '@trpc/client'; | ||
export { createTRPCReact, type CreateTRPCReact } from './createTRPCReact'; | ||
export { createReactQueryHooks } from './interop'; | ||
export type { inferReactQueryProcedureOptions } from './utils/inferReactQueryProcedure'; |
@@ -1,7 +0,12 @@ | ||
export function getClientArgs<TPathAndInput extends unknown[], TOptions>( | ||
pathAndInput: TPathAndInput, | ||
import { TRPCQueryKey } from './getQueryKey'; | ||
export function getClientArgs<TOptions>( | ||
queryKey: TRPCQueryKey, | ||
opts: TOptions, | ||
pageParam?: any, | ||
) { | ||
const [path, input] = pathAndInput; | ||
return [path, input, (opts as any)?.trpc] as const; | ||
const path = queryKey[0]; | ||
const input = queryKey[1]?.input; | ||
if (pageParam) (input as any).cursor = pageParam; | ||
return [path.join('.'), input, (opts as any)?.trpc] as const; | ||
} |
@@ -8,15 +8,39 @@ import { | ||
} from '@trpc/server'; | ||
import { getArrayQueryKey, QueryType } from '../internals/getArrayQueryKey'; | ||
import { DecoratedProcedureRecord, DecorateProcedure } from '../shared'; | ||
export type QueryType = 'any' | 'infinite' | 'query'; | ||
export type TRPCQueryKey = [ | ||
string[], | ||
{ input?: unknown; type?: Exclude<QueryType, 'any'> }?, | ||
]; | ||
/** | ||
* We treat `undefined` as an input the same as omitting an `input` | ||
* https://github.com/trpc/trpc/issues/2290 | ||
*/ | ||
* To allow easy interactions with groups of related queries, such as | ||
* invalidating all queries of a router, we use an array as the path when | ||
* storing in tanstack query. | ||
**/ | ||
export function getQueryKeyInternal( | ||
path: string, | ||
path: string[], | ||
input: unknown, | ||
): [string] | [string, unknown] { | ||
if (path.length) return input === undefined ? [path] : [path, input]; | ||
return [] as unknown as [string]; | ||
type: QueryType, | ||
): TRPCQueryKey { | ||
// Construct a query key that is easy to destructure and flexible for | ||
// partial selecting etc. | ||
// https://github.com/trpc/trpc/issues/3128 | ||
// some parts of the path may be dot-separated, split them up | ||
const splitPath = path.flatMap((part) => part.split('.')); | ||
if (!input && (!type || type === 'any')) | ||
// for `utils.invalidate()` to match all queries (including vanilla react-query) | ||
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]` | ||
return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey); | ||
return [ | ||
splitPath, | ||
{ | ||
...(typeof input !== 'undefined' && { input: input }), | ||
...(type && type !== 'any' && { type: type }), | ||
}, | ||
]; | ||
} | ||
@@ -47,4 +71,4 @@ | ||
TProcedureOrRouter extends | ||
| AnyMutationProcedure | ||
| AnyQueryProcedure | ||
| AnyMutationProcedure | ||
| AnyRouter, | ||
@@ -70,4 +94,4 @@ TPath extends string, | ||
TProcedureOrRouter extends | ||
| AnyMutationProcedure | ||
| AnyQueryProcedure | ||
| AnyMutationProcedure | ||
| AnyRouter, | ||
@@ -87,4 +111,4 @@ TPath extends string, | ||
TProcedureOrRouter extends | ||
| AnyMutationProcedure | ||
| AnyQueryProcedure | ||
| AnyMutationProcedure | ||
| AnyRouter, | ||
@@ -97,8 +121,10 @@ TPath extends string, | ||
const path = procedureOrRouter._def().path as string[]; | ||
const dotPath = path.join('.'); | ||
const queryKey = getArrayQueryKey( | ||
getQueryKeyInternal(dotPath, input), | ||
type ?? 'any', | ||
); | ||
const queryKey = getQueryKeyInternal(path, input, type ?? 'any'); | ||
return queryKey; | ||
} | ||
// TODO: look over if we can't use a single type | ||
export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [ | ||
string[], | ||
{ input?: GetQueryProcedureInput<TInput>; type: TType }?, | ||
]; |
import { QueryKey, UseQueryOptions } from '@tanstack/react-query'; | ||
import { AnyRouter } from '@trpc/server'; | ||
import { AnyRouter, DistributiveOmit } from '@trpc/server'; | ||
import { | ||
@@ -17,3 +17,6 @@ UseQueriesProcedureRecord, | ||
TQueryKey extends QueryKey = QueryKey, | ||
> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>; | ||
> = DistributiveOmit< | ||
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | ||
'queryKey' | ||
>; | ||
@@ -29,3 +32,6 @@ /** | ||
TError, | ||
> = Omit<UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>, 'context'>; | ||
> = DistributiveOmit< | ||
UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>, | ||
'queryKey' | ||
>; | ||
@@ -85,3 +91,2 @@ /** | ||
) => readonly [...QueriesOptions<TQueryOptions>], | ||
context?: UseQueryOptions['context'], | ||
) => QueriesResults<TQueryOptions>; |
export { createServerSideHelpers } from './ssgProxy'; | ||
export type { | ||
/** | ||
* @deprecated this exported is planned to be removed in the next major version | ||
*/ | ||
CreateServerSideHelpersOptions as CreateSSGHelpersOptions, | ||
} from './types'; | ||
export type { DecoratedProcedureSSGRecord } from './ssgProxy'; |
import { | ||
dehydrate, | ||
DehydratedState, | ||
@@ -8,7 +9,17 @@ DehydrateOptions, | ||
import { | ||
getUntypedClient, | ||
inferRouterProxyClient, | ||
TRPCClientError, | ||
TRPCUntypedClient, | ||
} from '@trpc/client'; | ||
import { | ||
AnyProcedure, | ||
AnyQueryProcedure, | ||
AnyRouter, | ||
callProcedure, | ||
ClientDataTransformerOptions, | ||
Filter, | ||
inferHandlerInput, | ||
inferProcedureInput, | ||
inferRouterContext, | ||
Maybe, | ||
ProtectedIntersection, | ||
@@ -21,29 +32,77 @@ } from '@trpc/server'; | ||
} from '@trpc/server/shared'; | ||
import { createSSGHelpers } from '../ssg/ssg'; | ||
import { CreateServerSideHelpersOptions } from './types'; | ||
import { getQueryKeyInternal } from '../internals/getQueryKey'; | ||
import { | ||
CreateTRPCReactQueryClientConfig, | ||
ExtractCursorType, | ||
getQueryClient, | ||
getQueryType, | ||
TRPCFetchInfiniteQueryOptions, | ||
TRPCFetchQueryOptions, | ||
} from '../shared'; | ||
interface CreateSSGHelpersInternal<TRouter extends AnyRouter> { | ||
router: TRouter; | ||
ctx: inferRouterContext<TRouter>; | ||
transformer?: ClientDataTransformerOptions; | ||
} | ||
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> { | ||
client: inferRouterProxyClient<TRouter> | TRPCUntypedClient<TRouter>; | ||
} | ||
type CreateServerSideHelpersOptions<TRouter extends AnyRouter> = | ||
CreateTRPCReactQueryClientConfig & | ||
(CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>); | ||
type DecorateProcedure<TProcedure extends AnyProcedure> = { | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
fetch( | ||
...args: inferHandlerInput<TProcedure> | ||
input: inferProcedureInput<TProcedure>, | ||
opts?: TRPCFetchQueryOptions< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
fetchInfinite( | ||
...args: inferHandlerInput<TProcedure> | ||
): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>>>; | ||
input: inferProcedureInput<TProcedure>, | ||
opts?: TRPCFetchInfiniteQueryOptions< | ||
inferProcedureInput<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
): Promise< | ||
InfiniteData< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null | ||
> | ||
>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
prefetch(...args: inferHandlerInput<TProcedure>): Promise<void>; | ||
prefetch( | ||
input: inferProcedureInput<TProcedure>, | ||
opts?: TRPCFetchQueryOptions< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/guides/prefetching | ||
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching | ||
*/ | ||
prefetchInfinite(...args: inferHandlerInput<TProcedure>): Promise<void>; | ||
prefetchInfinite( | ||
input: inferProcedureInput<TProcedure>, | ||
opts?: TRPCFetchInfiniteQueryOptions< | ||
inferProcedureInput<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
): Promise<void>; | ||
}; | ||
@@ -54,6 +113,6 @@ | ||
*/ | ||
export type DecoratedProcedureSSGRecord<TRouter extends AnyRouter> = { | ||
type DecoratedProcedureSSGRecord<TRouter extends AnyRouter> = { | ||
[TKey in keyof Filter< | ||
TRouter['_def']['record'], | ||
AnyRouter | AnyQueryProcedure | ||
AnyQueryProcedure | AnyRouter | ||
>]: TRouter['_def']['record'][TKey] extends AnyRouter | ||
@@ -74,5 +133,53 @@ ? DecoratedProcedureSSGRecord<TRouter['_def']['record'][TKey]> | ||
) { | ||
const helpers = createSSGHelpers(opts); | ||
const queryClient = getQueryClient(opts); | ||
type CreateServerSideHelpers = ProtectedIntersection< | ||
const resolvedOpts: { | ||
serialize: (obj: unknown) => any; | ||
query: (queryOpts: { path: string; input: unknown }) => Promise<unknown>; | ||
} = (() => { | ||
if ('router' in opts) { | ||
const { transformer, ctx, router } = opts; | ||
return { | ||
serialize: transformer | ||
? ('input' in transformer ? transformer.input : transformer).serialize | ||
: (obj) => obj, | ||
query: (queryOpts) => { | ||
return callProcedure({ | ||
procedures: router._def.procedures, | ||
path: queryOpts.path, | ||
rawInput: queryOpts.input, | ||
ctx, | ||
type: 'query', | ||
}); | ||
}, | ||
}; | ||
} | ||
const { client } = opts; | ||
const untypedClient = | ||
client instanceof TRPCUntypedClient | ||
? client | ||
: getUntypedClient(client as any); | ||
return { | ||
query: (queryOpts) => | ||
untypedClient.query(queryOpts.path, queryOpts.input), | ||
serialize: (obj) => untypedClient.runtime.transformer.serialize(obj), | ||
}; | ||
})(); | ||
function _dehydrate( | ||
opts: DehydrateOptions = { | ||
shouldDehydrateQuery() { | ||
// makes sure to serialize errors | ||
return true; | ||
}, | ||
}, | ||
): DehydratedState { | ||
const before = dehydrate(queryClient, opts); | ||
const after = resolvedOpts.serialize(before); | ||
return after; | ||
} | ||
type CreateSSGHelpers = ProtectedIntersection< | ||
{ | ||
@@ -85,26 +192,57 @@ queryClient: QueryClient; | ||
return createFlatProxy<CreateServerSideHelpers>((key) => { | ||
if (key === 'queryClient') { | ||
return helpers.queryClient; | ||
} | ||
return createFlatProxy<CreateSSGHelpers>((key) => { | ||
if (key === 'queryClient') return queryClient; | ||
if (key === 'dehydrate') return _dehydrate; | ||
if (key === 'dehydrate') { | ||
return helpers.dehydrate; | ||
} | ||
return createRecursiveProxy((opts) => { | ||
const args = opts.args; | ||
const input = args[0]; | ||
const arrayPath = [key, ...opts.path]; | ||
const utilName = arrayPath.pop() as keyof AnyDecoratedProcedure; | ||
const pathCopy = [key, ...opts.path]; | ||
const queryFn = () => | ||
resolvedOpts.query({ path: arrayPath.join('.'), input }); | ||
const utilName = pathCopy.pop() as keyof AnyDecoratedProcedure; | ||
const queryKey = getQueryKeyInternal( | ||
arrayPath, | ||
input, | ||
getQueryType(utilName), | ||
); | ||
const fullPath = pathCopy.join('.'); | ||
const helperMap: Record<keyof AnyDecoratedProcedure, () => unknown> = { | ||
fetch: () => { | ||
const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>; | ||
return queryClient.fetchQuery({ ...args1, queryKey, queryFn }); | ||
}, | ||
fetchInfinite: () => { | ||
const args1 = args[1] as Maybe< | ||
TRPCFetchInfiniteQueryOptions<any, any, any> | ||
>; | ||
return queryClient.fetchInfiniteQuery({ | ||
...args1, | ||
queryKey, | ||
queryFn, | ||
defaultPageParam: args1?.initialCursor ?? null, | ||
}); | ||
}, | ||
prefetch: () => { | ||
const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>; | ||
return queryClient.prefetchQuery({ ...args1, queryKey, queryFn }); | ||
}, | ||
prefetchInfinite: () => { | ||
const args1 = args[1] as Maybe< | ||
TRPCFetchInfiniteQueryOptions<any, any, any> | ||
>; | ||
return queryClient.prefetchInfiniteQuery({ | ||
...args1, | ||
queryKey, | ||
queryFn, | ||
defaultPageParam: args1?.initialCursor ?? null, | ||
}); | ||
}, | ||
}; | ||
const helperKey = `${utilName}Query` as const; | ||
// ^? | ||
const fn: (...args: any) => any = helpers[helperKey]; | ||
return fn(fullPath, ...args); | ||
return helperMap[utilName](); | ||
}); | ||
}); | ||
} |
import { | ||
DefinedUseQueryResult, | ||
DehydratedState, | ||
InfiniteData, | ||
InfiniteQueryObserverSuccessResult, | ||
@@ -14,11 +15,16 @@ InitialDataFunction, | ||
UseQueryResult, | ||
UseSuspenseInfiniteQueryOptions, | ||
UseSuspenseInfiniteQueryResult, | ||
UseSuspenseQueryOptions, | ||
UseSuspenseQueryResult, | ||
} from '@tanstack/react-query'; | ||
import { | ||
CreateTRPCClientOptions, | ||
TRPCClient, | ||
TRPCRequestOptions, | ||
TRPCUntypedClient, | ||
} from '@trpc/client'; | ||
import { AnyRouter } from '@trpc/server'; | ||
import { AnyRouter, DistributiveOmit } from '@trpc/server'; | ||
import { ReactNode } from 'react'; | ||
import { TRPCContextProps } from '../../internals/context'; | ||
import { TRPCQueryKey } from '../../internals/getQueryKey'; | ||
import { TRPCHookResult } from '../../internals/useHookResult'; | ||
@@ -58,11 +64,26 @@ | ||
TQueryOptsData = TOutput, | ||
> extends UseBaseQueryOptions< | ||
TOutput, | ||
TError, | ||
TData, | ||
TQueryOptsData, | ||
[TPath, TInput] | ||
> extends DistributiveOmit< | ||
UseBaseQueryOptions< | ||
TOutput, | ||
TError, | ||
TData, | ||
TQueryOptsData, | ||
[TPath, TInput] | ||
>, | ||
'queryKey' | ||
>, | ||
TRPCUseQueryBaseOptions {} | ||
export interface UseTRPCSuspenseQueryOptions< | ||
TPath, | ||
TInput, | ||
TOutput, | ||
TData, | ||
TError, | ||
> extends DistributiveOmit< | ||
UseSuspenseQueryOptions<TOutput, TError, TData, [TPath, TInput]>, | ||
'queryKey' | ||
>, | ||
TRPCUseQueryBaseOptions {} | ||
/** @internal **/ | ||
@@ -76,18 +97,19 @@ export interface DefinedUseTRPCQueryOptions< | ||
TQueryOptsData = TOutput, | ||
> extends UseTRPCQueryOptions< | ||
TPath, | ||
TInput, | ||
TOutput, | ||
TData, | ||
TError, | ||
TQueryOptsData | ||
> extends DistributiveOmit< | ||
UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError, TQueryOptsData>, | ||
'queryKey' | ||
> { | ||
initialData: TQueryOptsData | InitialDataFunction<TQueryOptsData>; | ||
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData; | ||
} | ||
export interface TRPCQueryOptions<TPath, TInput, TData, TError> | ||
extends QueryOptions<TData, TError, TData, [TPath, TInput]>, | ||
TRPCUseQueryBaseOptions {} | ||
extends DistributiveOmit< | ||
QueryOptions<TData, TError, TData, [TPath, TInput]>, | ||
'queryKey' | ||
>, | ||
TRPCUseQueryBaseOptions { | ||
queryKey: TRPCQueryKey; | ||
} | ||
export type ExtractCursorType<TInput> = TInput extends { cursor: any } | ||
export type ExtractCursorType<TInput> = TInput extends { cursor?: any } | ||
? TInput['cursor'] | ||
@@ -97,8 +119,12 @@ : unknown; | ||
export interface UseTRPCInfiniteQueryOptions<TPath, TInput, TOutput, TError> | ||
extends UseInfiniteQueryOptions< | ||
TOutput, | ||
TError, | ||
TOutput, | ||
TOutput, | ||
[TPath, Omit<TInput, 'cursor'>] | ||
extends DistributiveOmit< | ||
UseInfiniteQueryOptions< | ||
TOutput, | ||
TError, | ||
TOutput, | ||
TOutput, | ||
[TPath, Omit<TInput, 'cursor'>], | ||
ExtractCursorType<TInput> | ||
>, | ||
'queryKey' | 'defaultPageParam' | ||
>, | ||
@@ -109,2 +135,22 @@ TRPCUseQueryBaseOptions { | ||
export interface UseTRPCSuspenseInfiniteQueryOptions< | ||
TPath, | ||
TInput, | ||
TOutput, | ||
TError, | ||
> extends DistributiveOmit< | ||
UseSuspenseInfiniteQueryOptions< | ||
TOutput, | ||
TError, | ||
TOutput, | ||
TOutput, | ||
[TPath, Omit<TInput, 'cursor'>], | ||
ExtractCursorType<TInput> | ||
>, | ||
'queryKey' | 'defaultPageParam' | ||
>, | ||
TRPCUseQueryBaseOptions { | ||
initialCursor?: ExtractCursorType<TInput>; | ||
} | ||
export interface UseTRPCMutationOptions< | ||
@@ -134,3 +180,3 @@ TInput, | ||
export type UseDehydratedState<TRouter extends AnyRouter> = ( | ||
client: TRPCClient<TRouter>, | ||
client: TRPCUntypedClient<TRouter>, | ||
trpcState: DehydratedState | undefined, | ||
@@ -141,3 +187,3 @@ ) => DehydratedState | undefined; | ||
opts: CreateTRPCClientOptions<TRouter>, | ||
) => TRPCClient<TRouter>; | ||
) => TRPCUntypedClient<TRouter>; | ||
@@ -147,4 +193,4 @@ /** | ||
*/ | ||
export type UseTRPCQueryResult<TData, TError> = UseQueryResult<TData, TError> & | ||
TRPCHookResult; | ||
export type UseTRPCQueryResult<TData, TError> = TRPCHookResult & | ||
UseQueryResult<TData, TError>; | ||
@@ -169,7 +215,6 @@ /** | ||
*/ | ||
export type UseTRPCInfiniteQueryResult<TData, TError> = UseInfiniteQueryResult< | ||
export type UseTRPCSuspenseQueryResult<TData, TError> = [ | ||
TData, | ||
TError | ||
> & | ||
TRPCHookResult; | ||
UseSuspenseQueryResult<TData, TError> & TRPCHookResult, | ||
]; | ||
@@ -179,4 +224,7 @@ /** | ||
*/ | ||
export type UseTRPCInfiniteQuerySuccessResult<TData, TError> = | ||
InfiniteQueryObserverSuccessResult<TData, TError> & TRPCHookResult; | ||
export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult & | ||
UseInfiniteQueryResult< | ||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, | ||
TError | ||
>; | ||
@@ -186,3 +234,25 @@ /** | ||
*/ | ||
export type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> = | ||
InfiniteQueryObserverSuccessResult< | ||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, | ||
TError | ||
> & | ||
TRPCHookResult; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [ | ||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, | ||
UseSuspenseInfiniteQueryResult< | ||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, | ||
TError | ||
> & | ||
TRPCHookResult, | ||
]; | ||
/** | ||
* @internal | ||
*/ | ||
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> = | ||
UseMutationResult<TData, TError, TVariables, TContext> & TRPCHookResult; | ||
TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>; |
import { AnyRouter } from '@trpc/server'; | ||
import { createRecursiveProxy } from '@trpc/server/shared'; | ||
import { getArrayQueryKey } from '../../internals/getArrayQueryKey'; | ||
import { getQueryKeyInternal } from '../../internals/getQueryKey'; | ||
import { CreateReactQueryHooks } from '../hooks/createRootHooks'; | ||
import { CreateReactQueryHooks } from '../hooks/createHooksInternal'; | ||
@@ -15,7 +13,5 @@ /** | ||
>(name: string, hooks: CreateReactQueryHooks<TRouter, TSSRContext>) { | ||
return createRecursiveProxy((opts) => { | ||
const args = opts.args; | ||
return createRecursiveProxy(({ path, args }) => { | ||
const pathCopy = [name, ...path]; | ||
const pathCopy = [name, ...opts.path]; | ||
// The last arg is for instance `.useMutation` or `.useQuery()` | ||
@@ -25,16 +21,6 @@ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
// The `path` ends up being something like `post.byId` | ||
const path = pathCopy.join('.'); | ||
if (lastArg === 'useMutation') { | ||
return (hooks as any)[lastArg](path, ...args); | ||
return (hooks as any)[lastArg](pathCopy, ...args); | ||
} | ||
const [input, ...rest] = args; | ||
const queryKey = getQueryKeyInternal(path, input); | ||
// Expose queryKey helper | ||
if (lastArg === 'getQueryKey') { | ||
return getArrayQueryKey(queryKey, (rest[0] as any) ?? 'any'); | ||
} | ||
if (lastArg === '_def') { | ||
@@ -46,15 +32,7 @@ return { | ||
if (lastArg.startsWith('useSuspense')) { | ||
const opts = rest[0] || {}; | ||
const fn = | ||
lastArg === 'useSuspenseQuery' ? 'useQuery' : 'useInfiniteQuery'; | ||
const result = (hooks as any)[fn](queryKey, { | ||
...opts, | ||
suspense: true, | ||
enabled: true, | ||
}); | ||
return [result.data, result]; | ||
} | ||
return (hooks as any)[lastArg](queryKey, ...rest); | ||
const [input, ...rest] = args; | ||
const opts = rest[0] || {}; | ||
return (hooks as any)[lastArg](pathCopy, input, opts); | ||
}); | ||
} |
import { QueryOptions } from '@tanstack/react-query'; | ||
import { TRPCClient, TRPCClientError } from '@trpc/client'; | ||
import { TRPCClientError, TRPCUntypedClient } from '@trpc/client'; | ||
import { | ||
@@ -45,3 +45,3 @@ AnyProcedure, | ||
TRouter['_def']['record'], | ||
AnyRouter | AnyQueryProcedure | ||
AnyQueryProcedure | AnyRouter | ||
>]: TRouter['_def']['record'][TKey] extends AnyRouter | ||
@@ -63,14 +63,13 @@ ? UseQueriesProcedureRecord< | ||
export function createUseQueriesProxy<TRouter extends AnyRouter>( | ||
client: TRPCClient<TRouter>, | ||
client: TRPCUntypedClient<TRouter>, | ||
) { | ||
return createRecursiveProxy((opts) => { | ||
const path = opts.path.join('.'); | ||
const arrayPath = opts.path; | ||
const dotPath = arrayPath.join('.'); | ||
const [input, ...rest] = opts.args; | ||
const queryKey = getQueryKeyInternal(path, input); | ||
const options: QueryOptions = { | ||
queryKey, | ||
queryKey: getQueryKeyInternal(arrayPath, input, 'query'), | ||
queryFn: () => { | ||
return client.query(path, input); | ||
return client.query(dotPath, input); | ||
}, | ||
@@ -77,0 +76,0 @@ ...(rest[0] as any), |
@@ -20,2 +20,3 @@ import { | ||
inferProcedureInput, | ||
MaybePromise, | ||
ProtectedIntersection, | ||
@@ -35,8 +36,13 @@ } from '@trpc/server'; | ||
} from '../../internals/context'; | ||
import { QueryKeyKnown } from '../../internals/getArrayQueryKey'; | ||
import { getQueryKeyInternal } from '../../internals/getQueryKey'; | ||
import { | ||
getQueryKeyInternal, | ||
QueryKeyKnown, | ||
QueryType, | ||
TRPCQueryKey, | ||
} from '../../internals/getQueryKey'; | ||
import { ExtractCursorType } from '../hooks/types'; | ||
type DecorateProcedure<TProcedure extends AnyQueryProcedure> = { | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery | ||
*/ | ||
@@ -46,5 +52,4 @@ fetch( | ||
opts?: TRPCFetchQueryOptions< | ||
inferProcedureInput<TProcedure>, | ||
TRPCClientError<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure> | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
@@ -54,3 +59,3 @@ ): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchinfinitequery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery | ||
*/ | ||
@@ -61,9 +66,14 @@ fetchInfinite( | ||
inferProcedureInput<TProcedure>, | ||
TRPCClientError<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure> | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>>>; | ||
): Promise< | ||
InfiniteData< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null | ||
> | ||
>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchquery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery | ||
*/ | ||
@@ -73,5 +83,4 @@ prefetch( | ||
opts?: TRPCFetchQueryOptions< | ||
inferProcedureInput<TProcedure>, | ||
TRPCClientError<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure> | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
@@ -81,3 +90,3 @@ ): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchinfinitequery | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery | ||
*/ | ||
@@ -88,4 +97,4 @@ prefetchInfinite( | ||
inferProcedureInput<TProcedure>, | ||
TRPCClientError<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure> | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
@@ -95,3 +104,3 @@ ): Promise<void>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/react/reference/QueryClient#queryclientensurequerydata | ||
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientensurequerydata | ||
*/ | ||
@@ -101,5 +110,4 @@ ensureData( | ||
opts?: TRPCFetchQueryOptions< | ||
inferProcedureInput<TProcedure>, | ||
TRPCClientError<TProcedure>, | ||
inferTransformedProcedureOutput<TProcedure> | ||
inferTransformedProcedureOutput<TProcedure>, | ||
TRPCClientError<TProcedure> | ||
>, | ||
@@ -109,3 +117,3 @@ ): Promise<inferTransformedProcedureOutput<TProcedure>>; | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientinvalidatequeries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries | ||
*/ | ||
@@ -133,3 +141,3 @@ invalidate( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientrefetchqueries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries | ||
*/ | ||
@@ -143,3 +151,3 @@ refetch( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientcancelqueries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries | ||
*/ | ||
@@ -152,3 +160,3 @@ cancel( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientresetqueries | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries | ||
*/ | ||
@@ -161,3 +169,3 @@ reset( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientsetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata | ||
*/ | ||
@@ -177,3 +185,3 @@ setData( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientsetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata | ||
*/ | ||
@@ -183,4 +191,12 @@ setInfiniteData( | ||
updater: Updater< | ||
InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined, | ||
InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined | ||
| InfiniteData< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null | ||
> | ||
| undefined, | ||
| InfiniteData< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null | ||
> | ||
| undefined | ||
>, | ||
@@ -191,3 +207,3 @@ options?: SetDataOptions, | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientgetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
@@ -199,7 +215,12 @@ getData( | ||
/** | ||
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientgetquerydata | ||
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata | ||
*/ | ||
getInfiniteData( | ||
input?: inferProcedureInput<TProcedure>, | ||
): InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined; | ||
): | ||
| InfiniteData< | ||
inferTransformedProcedureOutput<TProcedure>, | ||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null | ||
> | ||
| undefined; | ||
}; | ||
@@ -215,3 +236,3 @@ | ||
* @link https://trpc.io/docs/v10/useContext#query-invalidation | ||
* @link https://tanstack.com/query/v4/docs/react/guides/query-invalidation | ||
* @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation | ||
*/ | ||
@@ -228,12 +249,13 @@ invalidate( | ||
*/ | ||
export type DecoratedProcedureUtilsRecord<TRouter extends AnyRouter> = { | ||
[TKey in keyof Filter< | ||
TRouter['_def']['record'], | ||
AnyRouter | AnyQueryProcedure | ||
>]: TRouter['_def']['record'][TKey] extends AnyRouter | ||
? DecoratedProcedureUtilsRecord<TRouter['_def']['record'][TKey]> & | ||
DecorateRouter | ||
: // utils only apply to queries | ||
DecorateProcedure<TRouter['_def']['record'][TKey]>; | ||
} & DecorateRouter; // Add functions that should be available at utils root | ||
export type DecoratedProcedureUtilsRecord<TRouter extends AnyRouter> = | ||
DecorateRouter & { | ||
[TKey in keyof Filter< | ||
TRouter['_def']['record'], | ||
AnyQueryProcedure | AnyRouter | ||
>]: TRouter['_def']['record'][TKey] extends AnyRouter | ||
? DecoratedProcedureUtilsRecord<TRouter['_def']['record'][TKey]> & | ||
DecorateRouter | ||
: // utils only apply to queries | ||
DecorateProcedure<TRouter['_def']['record'][TKey]>; | ||
}; // Add functions that should be available at utils root | ||
@@ -250,2 +272,27 @@ type AnyDecoratedProcedure = DecorateProcedure<any>; | ||
export const getQueryType = ( | ||
utilName: keyof AnyDecoratedProcedure, | ||
): QueryType => { | ||
switch (utilName) { | ||
case 'fetch': | ||
case 'ensureData': | ||
case 'prefetch': | ||
case 'getData': | ||
case 'setData': | ||
return 'query'; | ||
case 'fetchInfinite': | ||
case 'prefetchInfinite': | ||
case 'getInfiniteData': | ||
case 'setInfiniteData': | ||
return 'infinite'; | ||
case 'cancel': | ||
case 'invalidate': | ||
case 'refetch': | ||
case 'reset': | ||
return 'any'; | ||
} | ||
}; | ||
/** | ||
@@ -257,3 +304,15 @@ * @internal | ||
TSSRContext, | ||
>(context: TRPCContextState<AnyRouter, unknown>) { | ||
>( | ||
context: TRPCContextState<AnyRouter, unknown>, | ||
overrides?: Partial< | ||
Record< | ||
keyof AnyDecoratedProcedure, | ||
(opts: { | ||
queryKey: TRPCQueryKey; | ||
path: string[]; | ||
input: unknown; | ||
}) => MaybePromise<void> | ||
> | ||
>, | ||
) { | ||
type CreateReactUtilsProxyReturnType = CreateReactUtilsProxy< | ||
@@ -273,47 +332,29 @@ TRouter, | ||
return createRecursiveProxy(({ path, args }) => { | ||
const pathCopy = [key, ...path]; | ||
const utilName = pathCopy.pop() as keyof AnyDecoratedProcedure; | ||
return createRecursiveProxy((opts) => { | ||
const path = [key, ...opts.path]; | ||
const utilName = path.pop() as keyof AnyDecoratedProcedure; | ||
const args = [...opts.args] as Parameters< | ||
AnyDecoratedProcedure[typeof utilName] | ||
>; | ||
const input = args.shift(); // args can now be spread when input removed | ||
const queryType = getQueryType(utilName); | ||
const queryKey = getQueryKeyInternal(path, input, queryType); | ||
const fullPath = pathCopy.join('.'); | ||
const getOpts = (name: typeof utilName) => { | ||
if (['setData', 'setInfiniteData'].includes(name)) { | ||
const [input, updater, ...rest] = args as Parameters< | ||
AnyDecoratedProcedure[typeof utilName] | ||
>; | ||
const queryKey = getQueryKeyInternal(fullPath, input); | ||
return { | ||
queryKey, | ||
updater, | ||
rest, | ||
}; | ||
} | ||
const [input, ...rest] = args as Parameters< | ||
AnyDecoratedProcedure[typeof utilName] | ||
>; | ||
const queryKey = getQueryKeyInternal(fullPath, input); | ||
return { | ||
queryKey, | ||
rest, | ||
}; | ||
}; | ||
const { queryKey, rest, updater } = getOpts(utilName); | ||
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = { | ||
fetch: () => context.fetchQuery(queryKey, ...rest), | ||
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, ...rest), | ||
prefetch: () => context.prefetchQuery(queryKey, ...rest), | ||
fetch: () => context.fetchQuery(queryKey, ...args), | ||
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]), | ||
prefetch: () => context.prefetchQuery(queryKey, ...args), | ||
prefetchInfinite: () => | ||
context.prefetchInfiniteQuery(queryKey, ...rest), | ||
ensureData: () => context.ensureQueryData(queryKey, ...rest), | ||
invalidate: () => context.invalidateQueries(queryKey, ...rest), | ||
reset: () => context.resetQueries(queryKey, ...rest), | ||
refetch: () => context.refetchQueries(queryKey, ...rest), | ||
cancel: () => context.cancelQuery(queryKey, ...rest), | ||
setData: () => context.setQueryData(queryKey, updater, ...rest), | ||
setInfiniteData: () => | ||
context.setInfiniteQueryData(queryKey, updater, ...rest), | ||
context.prefetchInfiniteQuery(queryKey, args[0]), | ||
ensureData: () => context.ensureQueryData(queryKey, ...args), | ||
invalidate: () => context.invalidateQueries(queryKey, ...args), | ||
reset: () => context.resetQueries(queryKey, ...args), | ||
refetch: () => context.refetchQueries(queryKey, ...args), | ||
cancel: () => context.cancelQuery(queryKey, ...args), | ||
setData: () => { | ||
context.setQueryData(queryKey, args[0], args[1]); | ||
}, | ||
setInfiniteData: () => { | ||
context.setInfiniteQueryData(queryKey, args[0], args[1]); | ||
}, | ||
getData: () => context.getQueryData(queryKey), | ||
@@ -323,2 +364,13 @@ getInfiniteData: () => context.getInfiniteQueryData(queryKey), | ||
if (overrides?.[utilName]) { | ||
const override = overrides?.[utilName]?.({ | ||
queryKey: queryKey as unknown as TRPCQueryKey, | ||
path, | ||
input, | ||
}); | ||
if (override instanceof Promise) { | ||
return override.then(() => contextMap[utilName]()); | ||
} | ||
} | ||
return contextMap[utilName](); | ||
@@ -325,0 +377,0 @@ }); |
@@ -27,10 +27,3 @@ import { QueryClient } from '@tanstack/react-query'; | ||
* Override behaviors of the built-in hooks | ||
* @deprecated use `overrides` instead | ||
*/ | ||
unstable_overrides?: { | ||
useMutation?: Partial<UseMutationOverride>; | ||
}; | ||
/** | ||
* Override behaviors of the built-in hooks | ||
*/ | ||
overrides?: { | ||
@@ -51,7 +44,2 @@ useMutation?: Partial<UseMutationOverride>; | ||
context?: React.Context<any>; | ||
/** | ||
* Override the default React Query context | ||
* @default undefined | ||
*/ | ||
reactQueryContext?: React.Context<QueryClient | undefined>; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
234840
94
5117
1
2