/// import { EventEmitter } from "events"; import * as Protobuf from "protobufjs"; import { Client } from "@grpc/grpc-js"; import { ProtoRequest } from "./ProtoRequest"; import type { UntypedProtoRequest } from "./untyped"; import type { ClientSettings, EndpointMatcher, ProtoSettings, RequestMiddleware, RequestOptions, StreamReader, StreamWriterSandbox } from "./interfaces"; export interface ProtoClient { on(event: "request", listener: (request: UntypedProtoRequest) => void): this; off(event: "request", listener: (request: UntypedProtoRequest) => void): this; emit(eventName: "request", request: UntypedProtoRequest): boolean; } /** * Shorthand wrapper utilities for gRPC client calls */ export declare class ProtoClient extends EventEmitter { /** * Client settings */ clientSettings: ClientSettings; /** * Protobuf parsing settings */ protoSettings: ProtoSettings; /** * Internal proto conversion options, for referencing */ protoConversionOptions: Protobuf.IConversionOptions; /** * List of currently active requests */ activeRequests: UntypedProtoRequest[]; /** * Middleware to run before each request */ middleware: RequestMiddleware[]; /** * Root protobuf object for referencing */ private root?; /** * Client endpoints list */ private clients; /** * Shorthand wrapper utilities for gRPC client calls * @param options Configuration options for the client */ constructor(options?: { clientSettings?: ClientSettings; protoSettings?: ProtoSettings; conversionOptions?: Protobuf.IConversionOptions; }); /** * Configures settings for client connection * @param clientSettings Settings for client connection */ configureClient(clientSettings: ClientSettings): void; /** * Configures options for reading/writing proto definitions * @param protoSettings Proto reading/writing settings */ configureProtos(protoSettings: ProtoSettings): void; /** * Configures conversion options when decoding proto responses * @param options Conversion options */ configureConversionOptions(options: Protobuf.IConversionOptions): void; /** * Fetches the endpoint matching client instance * throwing an error if not yet configured * @param request Active request looking for it's client endpoint */ getClient(request: UntypedProtoRequest): Client; /** * Fetches the current proto root object, throwing an error if not yet configured */ getRoot(): Protobuf.Root; /** * Adds function to the middleware stack * @param middleware Middleware to run before each request */ useMiddleware(middleware: RequestMiddleware): void; /** * Sends unary (request/response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup */ makeUnaryRequest(method: string): Promise>; /** * Sends unary (request/response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param data Data to be sent as part of the request */ makeUnaryRequest(method: string, data: RequestType): Promise>; /** * Sends unary (request/response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param data Data to be sent as part of the request. Defaults to empty object * @param abortController Abort controller for canceling the active request */ makeUnaryRequest(method: string, data: RequestType | null, abortController: AbortController): Promise>; /** * Sends unary (request/response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param data Data to be sent as part of the request. Defaults to empty object * @param requestOptions Options for this specific request */ makeUnaryRequest(method: string, data: RequestType | null, requestOptions: RequestOptions): Promise>; /** * Sends client stream (request stream, single response) request to the service endpoint. * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param writerSandbox Async supported callback for writing data to the open stream */ makeClientStreamRequest(method: string, writerSandbox: StreamWriterSandbox): Promise>; /** * Sends client stream (request stream, single response) request to the service endpoint. * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param writerSandbox Async supported callback for writing data to the open stream * @param abortController Abort controller for canceling the active request */ makeClientStreamRequest(method: string, writerSandbox: StreamWriterSandbox, abortController: AbortController): Promise>; /** * Sends client stream (request stream, single response) request to the service endpoint. * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param writerSandbox Async supported callback for writing data to the open stream * @param requestOptions Options for this specific request */ makeClientStreamRequest(method: string, writerSandbox: StreamWriterSandbox, requestOptions: RequestOptions): Promise>; /** * Sends a server stream (single request, streamed response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param streamReader Iteration function that will be called on every response chunk */ makeServerStreamRequest(method: string, streamReader: StreamReader): Promise>; /** * Sends a server stream (single request, streamed response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param data Data to be sent as part of the request * @param streamReader Iteration function that will be called on every response chunk */ makeServerStreamRequest(method: string, data: RequestType, streamReader: StreamReader): Promise>; /** * Sends a server stream (single request, streamed response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param data Data to be sent as part of the request * @param streamReader Iteration function that will be called on every response chunk * @param abortController Abort controller for canceling the active request */ makeServerStreamRequest(method: string, data: RequestType, streamReader: StreamReader, abortController: AbortController): Promise>; /** * Sends a server stream (single request, streamed response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param data Data to be sent as part of the request * @param streamReader Iteration function that will be called on every response chunk * @param requestOptions Options for this specific request */ makeServerStreamRequest(method: string, data: RequestType, streamReader: StreamReader, requestOptions: RequestOptions): Promise>; /** * Sends a bi-directional (stream request, stream response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param writerSandbox Async supported callback for writing data to the open stream * @param streamReader Iteration function that will be called on every response chunk */ makeBidiStreamRequest(method: string, writerSandbox: StreamWriterSandbox, streamReader: StreamReader): Promise>; /** * Sends a bi-directional (stream request, stream response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param writerSandbox Async supported callback for writing data to the open stream * @param streamReader Iteration function that will be called on every response chunk * @param abortController Abort controller for canceling the active request */ makeBidiStreamRequest(method: string, writerSandbox: StreamWriterSandbox, streamReader: StreamReader, abortController: AbortController): Promise>; /** * Sends a bi-directional (stream request, stream response) request to the service endpoint * @param method Fully qualified path of the method for the request that can be used by protobufjs.lookup * @param writerSandbox Async supported callback for writing data to the open stream * @param streamReader Iteration function that will be called on every response chunk * @param requestOptions Options for this specific request */ makeBidiStreamRequest(method: string, writerSandbox: StreamWriterSandbox, streamReader: StreamReader, requestOptions: RequestOptions): Promise>; /** * Aborts all requests that match the method defined * @param match Method to match */ abortRequests(match: string): void; /** * Aborts all requests whose method passes the regex test * @param match Regex run against the method namespace for matching */ abortRequests(match: RegExp): void; /** * Aborts all requests that pass the match function * @param match Endpoint matcher util */ abortRequests(match: EndpointMatcher): void; /** * Aborts all active requests and closes all gRPC connections */ close(): void; /** * Manages request within the active requests list * @param method Method name for the request * @param requestMethodType Method type */ private generateRequest; /** * Removes request from the active request list * @param request Request to be removed */ private removeActiveRequest; } //# sourceMappingURL=ProtoClient.d.ts.map