@connectrpc/connect-query
Version:
TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers.
41 lines • 2.76 kB
TypeScript
import type { Message, PartialMessage } from "@bufbuild/protobuf";
import type { CallOptions, ConnectError, Transport } from "@connectrpc/connect";
import type { GetNextPageParamFunction, InfiniteData, QueryFunction, UseInfiniteQueryOptions, UseSuspenseInfiniteQueryOptions } from "@tanstack/react-query";
import { type ConnectInfiniteQueryKey } from "./connect-query-key.js";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import { type DisableQuery } from "./utils.js";
/**
* Options specific to connect-query
*/
export interface ConnectInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>> {
/** Defines which part of the input should be considered the page param */
pageParamKey: ParamKey;
/** Transport can be overridden here.*/
transport: Transport;
/** Additional call options */
callOptions?: Omit<CallOptions, "signal"> | undefined;
/** Determines the next page. */
getNextPageParam: GetNextPageParamFunction<PartialMessage<I>[ParamKey], O>;
}
/**
* Options for useInfiniteQuery
*/
export type CreateInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>> = ConnectInfiniteQueryOptions<I, O, ParamKey> & Omit<UseInfiniteQueryOptions<O, ConnectError, InfiniteData<O>, O, ConnectInfiniteQueryKey<I>, PartialMessage<I>[ParamKey]>, "getNextPageParam" | "initialPageParam" | "queryFn" | "queryKey">;
/**
* Options for useSuspenseInfiniteQuery
*/
export type CreateSuspenseInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>> = ConnectInfiniteQueryOptions<I, O, ParamKey> & Omit<UseSuspenseInfiniteQueryOptions<O, ConnectError, InfiniteData<O>, O, ConnectInfiniteQueryKey<I>, PartialMessage<I>[ParamKey]>, "getNextPageParam" | "initialPageParam" | "queryFn" | "queryKey">;
/**
* Query the method provided. Maps to useInfiniteQuery on tanstack/react-query
*
* @param methodSig
* @returns
*/
export declare function createUseInfiniteQueryOptions<I extends Message<I>, O extends Message<O>, ParamKey extends keyof PartialMessage<I>>(methodSig: MethodUnaryDescriptor<I, O>, input: DisableQuery | (PartialMessage<I> & Required<Pick<PartialMessage<I>, ParamKey>>), { transport, getNextPageParam, pageParamKey, callOptions, }: ConnectInfiniteQueryOptions<I, O, ParamKey>): {
getNextPageParam: ConnectInfiniteQueryOptions<I, O, ParamKey>["getNextPageParam"];
queryKey: ConnectInfiniteQueryKey<I>;
queryFn: QueryFunction<O, ConnectInfiniteQueryKey<I>, PartialMessage<I>[ParamKey]>;
initialPageParam: PartialMessage<I>[ParamKey];
enabled: boolean;
};
//# sourceMappingURL=create-use-infinite-query-options.d.ts.map