@connectrpc/connect-query
Version:
TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers.
44 lines • 2.09 kB
TypeScript
import { type Message, type PartialMessage, type PlainMessage } from "@bufbuild/protobuf";
import type { MethodUnaryDescriptor } from "./method-unary-descriptor.js";
import type { DisableQuery } from "./utils.js";
/**
* TanStack Query requires query keys in order to decide when the query should automatically update.
*
* `QueryKey`s in TanStack Query are usually arbitrary, but Connect-Query uses the approach of creating a query key that begins with the least specific information: the service's `typeName`, followed by the method name, and ending with the most specific information to identify a particular request: the input message itself.
*
* For example, for a query key might look like this:
*
* @example
* [
* "connectrpc.eliza.v1.ElizaService",
* "Say",
* { sentence: "hello there" },
* ]
*/
export type ConnectQueryKey<I extends Message<I>> = [
serviceTypeName: string,
methodName: string,
input: PlainMessage<I>
];
/**
* TanStack Query requires query keys in order to decide when the query should automatically update.
*
* In Connect-Query, much of this is handled automatically by this function.
*
* @see ConnectQueryKey for information on the components of Connect-Query's keys.
*/
export declare function createConnectQueryKey<I extends Message<I>, O extends Message<O>>(methodDescriptor: Pick<MethodUnaryDescriptor<I, O>, "I" | "name" | "service">, input?: DisableQuery | PartialMessage<I> | undefined): ConnectQueryKey<I>;
/**
* Similar to @see ConnectQueryKey, but for infinite queries.
*/
export type ConnectInfiniteQueryKey<I extends Message<I>> = [
serviceTypeName: string,
methodName: string,
input: PlainMessage<I>,
"infinite"
];
/**
* Similar to @see createConnectQueryKey, but for infinite queries.
*/
export declare function createConnectInfiniteQueryKey<I extends Message<I>, O extends Message<O>>(methodDescriptor: Pick<MethodUnaryDescriptor<I, O>, "I" | "name" | "service">, input?: DisableQuery | PartialMessage<I> | undefined): ConnectInfiniteQueryKey<I>;
//# sourceMappingURL=connect-query-key.d.ts.map