UNPKG

@connectrpc/connect-query

Version:

TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers.

31 lines 1.77 kB
import type { Message, PartialMessage } from "@bufbuild/protobuf"; import type { CallOptions, ConnectError, Transport } from "@connectrpc/connect"; import type { QueryFunction, UseQueryOptions, UseSuspenseQueryOptions } from "@tanstack/react-query"; import type { ConnectQueryKey } from "./connect-query-key.js"; import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js"; import { type DisableQuery } from "./utils.js"; export interface ConnectQueryOptions { /** The transport to be used for the fetching. */ transport: Transport; /** Any additional call options to provide the transport on call. */ callOptions?: Omit<CallOptions, "signal"> | undefined; } /** * Options for useQuery */ export type CreateQueryOptions<I extends Message<I>, O extends Message<O>, SelectOutData = 0> = ConnectQueryOptions & Omit<UseQueryOptions<O, ConnectError, SelectOutData, ConnectQueryKey<I>>, "queryFn" | "queryKey">; /** * Options for useQuery */ export type CreateSuspenseQueryOptions<I extends Message<I>, O extends Message<O>, SelectOutData = 0> = ConnectQueryOptions & Omit<UseSuspenseQueryOptions<O, ConnectError, SelectOutData, ConnectQueryKey<I>>, "queryFn" | "queryKey">; /** * Creates all options required to make a query. Useful in combination with `useQueries` from tanstack/react-query. */ export declare function createUseQueryOptions<I extends Message<I>, O extends Message<O>>(methodSig: MethodUnaryDescriptor<I, O>, input: DisableQuery | PartialMessage<I> | undefined, { transport, callOptions, }: ConnectQueryOptions & { transport: Transport; }): { queryKey: ConnectQueryKey<I>; queryFn: QueryFunction<O, ConnectQueryKey<I>>; enabled: boolean | undefined; }; //# sourceMappingURL=create-use-query-options.d.ts.map