import type { MethodInfoServerStreaming, MethodInfoUnary, PartialMessage, ServiceType } from "@bufbuild/protobuf"; import { ConnectError } from "./connect-error.js"; import type { Transport } from "./transport.js"; import type { CallOptions } from "./call-options.js"; /** * CallbackClient is a simple client that supports unary and server * streaming methods. Methods take callback functions, which will be * called when a response message arrives, or an error occurs. * * Client methods return a function that cancels the call. This is a * convenient alternative to creating a AbortController and passing * its AbortSignal as an option to the method. * * If a call is cancelled by an AbortController or by the returned * cancel-function, ConnectErrors with the code Canceled are * silently discarded. * * CallbackClient is most convenient for use in React effects, where * a function returned by the effect is called when the effect is * torn down. */ export type CallbackClient = { [P in keyof T["methods"]]: T["methods"][P] extends MethodInfoUnary ? (request: PartialMessage, callback: (error: ConnectError | undefined, response: O) => void, options?: CallOptions) => CancelFn : T["methods"][P] extends MethodInfoServerStreaming ? (request: PartialMessage, messageCallback: (response: O) => void, closeCallback: (error: ConnectError | undefined) => void, options?: CallOptions) => CancelFn : never; }; type CancelFn = () => void; /** * Create a CallbackClient for the given service, invoking RPCs through the * given transport. */ export declare function createCallbackClient(service: T, transport: Transport): CallbackClient; export {};