import * as _$_trpc_client0 from "@trpc/client"; import { CreateTRPCClientOptions, HTTPBatchLinkOptions, HTTPLinkOptions, OperationContext, TRPCClientError, TRPCClientErrorLike, TRPCProcedureOptions, TRPCRequestOptions, TRPCResolverDef } from "@trpc/client"; import { AnyTRPCProcedure, AnyTRPCRootTypes, AnyTRPCRouter, DeepPartial, TRPCProcedureType, inferProcedureInput, inferTransformedProcedureOutput } from "@trpc/server"; import { MaybeRefOrGetter, Ref, ShallowRef, UnwrapRef } from "vue"; import { TRPCConnectionState } from "@trpc/client/unstable-internals"; import { Unsubscribable } from "@trpc/server/observable"; import { RouterRecord, inferAsyncIterableYield } from "@trpc/server/unstable-core-do-not-import"; import { AsyncData, AsyncDataOptions } from "nuxt/app"; import { FetchOptions } from "ofetch"; //#region src/client/nuxt-types.d.ts type PickFrom> = T extends Array ? T : T extends Record ? keyof T extends K[number] ? T : K[number] extends never ? T : Pick : T; type KeysOf = Array; type AsyncDataRefreshCause = 'initial' | 'refresh:hook' | 'refresh:manual' | 'watch'; interface AsyncDataExecuteOptions { /** * Force a refresh, even if there is already a pending request. Previous requests will * not be cancelled, but their result will not affect the data/pending state - and any * previously awaited promises will not resolve until this new request resolves. */ dedupe?: 'cancel' | 'defer'; cause?: AsyncDataRefreshCause; /** @internal */ cachedData?: any; } //#endregion //#region src/client/create-trpc-nuxt-client.d.ts interface TRPCSubscriptionObserver { onStarted: (opts: { context: OperationContext | undefined; }) => void; onData: (value: inferAsyncIterableYield) => void; onError: (err: TError) => void; onStopped: () => void; onComplete: () => void; onConnectionStateChange: (state: TRPCConnectionState) => void; } type SubscriptionResolver = (input: TDef['input'], opts?: Partial>> & TRPCProcedureOptions) => Unsubscribable; type SubscriptionStatus = 'idle' | 'connecting' | 'pending' | 'error'; interface UseSubscriptionOptions { enabled?: MaybeRefOrGetter; onStarted?: (opts: { context: OperationContext | undefined; }) => void; onData?: (data: TOutput) => void; onError?: (error: TError) => void; onComplete?: () => void; onConnectionStateChange?: (state: TRPCConnectionState) => void; onStopped?: () => void; trpc?: TRPCRequestOptions; } interface UseSubscriptionReturn { status: Ref; data: ShallowRef; error: ShallowRef; reset: () => void; } interface DecoratedSubscription { /** * @example * * const { status, data, error } = $trpc.chat.onMessage.useSubscription( * () => ({ roomId: props.roomId }), * { * onData: (message) => { * messages.value.push(message); * }, * } * ); */ useSubscription: (input: MaybeRefOrGetter, opts?: UseSubscriptionOptions, TRPCClientError>) => UseSubscriptionReturn, TRPCClientError>; subscribe: SubscriptionResolver; } type DecorateProcedure = TType extends 'query' ? DecoratedQuery : TType extends 'mutation' ? DecoratedMutation : TType extends 'subscription' ? DecoratedSubscription : never; type DecorateRouterRecord = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? DecorateRouterRecord : $Value extends AnyTRPCProcedure ? DecorateProcedure<$Value['_def']['type'], { input: inferProcedureInput<$Value>; output: inferTransformedProcedureOutput; transformer: TRoot['transformer']; errorShape: TRoot['errorShape']; }> : never : never }; type Resolver = (input: TDef['input'], opts?: TRPCProcedureOptions) => Promise; interface DecoratedQuery { /** * @example * * const { data } = await $trpc.todo.getTodos.useQuery() */ useQuery: = KeysOf, DefaultT = undefined>(input: MaybeRefOrGetter, opts?: Omit, 'watch'> & { /** * The custom unique key to use. * @see https://nuxt.com/docs/4.x/api/composables/use-async-data#params */ queryKey?: string; watch?: AsyncDataOptions['watch'] | false; trpc?: TRPCRequestOptions; }) => AsyncData | DefaultT, TRPCClientErrorLike>; query: Resolver; } interface DecoratedMutation { /** * @example * * const { mutate } = $trpc.todo.addTodo.useMutation() * mutate({ text: 'migrate to TRPC v11', completed: false }) */ useMutation: = KeysOf, DefaultT = undefined>(opts?: Omit, 'lazy' | 'watch' | 'server' | 'immediate'> & { /** * The custom unique key to use. * @see https://nuxt.com/docs/4.x/api/composables/use-async-data#params */ mutationKey?: string; trpc?: TRPCRequestOptions; }) => AsyncData | DefaultT, TRPCClientErrorLike> & { /** * The function to call to trigger the mutation. */ mutate: (input: TDef['input'], opts?: AsyncDataExecuteOptions) => Promise | DefaultT, TRPCClientErrorLike>['data']>>; }; mutate: Resolver; } declare function createTRPCNuxtClient(opts: CreateTRPCClientOptions): DecorateRouterRecord; //#endregion //#region src/client/get-query-key.d.ts type ProcedureOrRouter = DecoratedMutation | DecoratedQuery | DecorateRouterRecord; /** @internal */ type GetQueryProcedureInput = DeepPartial | undefined; type GetParams = TProcedureOrRouter extends DecoratedQuery ? [input?: GetQueryProcedureInput<$Def['input']>] : []; /** @internal */ /** * Method to extract the query key for a procedure * @param procedure - procedure * @param input - input to procedure * @see https://trpc-nuxt.pages.dev/guides/mutation-and-revalidation */ declare function getQueryKey(procedureOrRouter: TProcedureOrRouter, ..._params: GetParams): string; /** * Method to extract the mutation key for a procedure * @param procedure - procedure * @see https://trpc-nuxt.pages.dev/guides/mutation-and-revalidation */ declare function getMutationKey>(procedure: TProcedure): string; //#endregion //#region src/client/links.d.ts interface DefaultLinkOptionsParams { /** * Select headers to pass to `useRequestHeaders`. */ pickHeaders?: string[]; /** * ofetch fetch options. * @see https://github.com/unjs/ofetch */ fetchOptions?: FetchOptions; } type HTTPLinkOptions$1 = HTTPLinkOptions & DefaultLinkOptionsParams; /** * This is a convenience wrapper around the original httpLink * that replaces regular `fetch` with a `$fetch` from Nuxt. It * also sets the default headers based on `useRequestHeaders` values. * * During server-side rendering, calling $fetch to fetch your internal API routes * will directly call the relevant function (emulating the request), * saving an additional API call. * * @see https://nuxt.com/docs/api/utils/dollarfetch */ declare function httpLink(opts?: HTTPLinkOptions$1): _$_trpc_client0.TRPCLink; type HttpBatchLinkOptions = HTTPBatchLinkOptions & DefaultLinkOptionsParams; /** * This is a convenience wrapper around the original httpBatchLink * that replaces regular `fetch` with a `$fetch` from Nuxt. It * also sets the default headers based on `useRequestHeaders` values. * * During server-side rendering, calling $fetch to fetch your internal API routes * will directly call the relevant function (emulating the request), * saving an additional API call. * * @see https://nuxt.com/docs/api/utils/dollarfetch */ declare function httpBatchLink(opts?: HttpBatchLinkOptions): _$_trpc_client0.TRPCLink; //#endregion export { type UseSubscriptionOptions, type UseSubscriptionReturn, createTRPCNuxtClient, getMutationKey, getQueryKey, httpBatchLink, httpLink };