///
import * as Protobuf from "protobufjs";
import { EventEmitter } from "events";
import { CallOptions, Metadata, ServiceError, StatusObject } from "@grpc/grpc-js";
import type { ProtoClient } from "./ProtoClient";
import { RequestMethodType } from "./constants";
import type { RequestOptions, RequestRetryOptions, StreamReader, StreamWriterSandbox } from "./interfaces";
/**
* Custom event typings
*/
export interface ProtoRequest {
on(event: "response", listener: (request: ProtoRequest) => void): this;
on(event: "retry", listener: (request: ProtoRequest) => void): this;
on(event: "aborted", listener: (request: ProtoRequest) => void): this;
on(event: "end", listener: (request: ProtoRequest) => void): this;
off(event: "response", listener: (request: ProtoRequest) => void): this;
off(event: "retry", listener: (request: ProtoRequest) => void): this;
off(event: "aborted", listener: (request: ProtoRequest) => void): this;
off(event: "end", listener: (request: ProtoRequest) => void): this;
emit(eventName: "response", request: ProtoRequest): boolean;
emit(eventName: "retry", request: ProtoRequest): boolean;
emit(eventName: "aborted", request: ProtoRequest): boolean;
emit(eventName: "end", request: ProtoRequest): boolean;
}
/**
* Individual gRPC request
*/
export declare class ProtoRequest extends EventEmitter {
/**
* Fully qualified path of the method for the request that can be used by protobufjs.lookup
*/
readonly method: string;
/**
* Generated request path
*/
readonly requestPath: string;
/**
* Request proto message type
*/
readonly requestType: Protobuf.Type;
/**
* Response proto message type
*/
readonly responseType: Protobuf.Type;
/**
* Request method type
*/
readonly requestMethodType: RequestMethodType;
/**
* Time in milliseconds before cancelling the request
*/
timeout: number;
/**
* Configured retry options for this request
*/
retryOptions: RequestRetryOptions;
/**
* AbortController tied to the request
*/
abortController: AbortController;
/**
* Metadata instance for the request
*/
metadata: Metadata;
/**
* Request specific options
*/
callOptions: CallOptions;
/**
* Data response from the service, only valid for unary and client stream requests
*/
result?: ResponseType;
/**
* Metadata returned from the service
*/
responseMetadata?: Metadata;
/**
* Metadata returned from the service
*/
responseStatus?: StatusObject;
/**
* Number of retries made for this request
*/
retries: number;
/**
* References any error that may have occured during the request
*/
error?: Error;
/**
* When retries are enabled, all errors will be stored here
*/
readonly responseErrors: Error[];
/**
* Internal reference to the parent client instance
*/
private readonly client;
/**
* Internal reference to determine if request has start yet or not
*/
private hasRequestBegun;
/**
* Reference to the called stream from within the method
*/
private stream;
/**
* Internal class for managing individual requests
*/
constructor(client: ProtoClient, method: string, requestMethodType: RequestMethodType, requestOptions: AbortController | RequestOptions | undefined);
/**
* Indicates if the request is active (started, but not finished)
*
* Note*: For middleware, this will be false until all middleware
* completes and the request begins
*/
get isActive(): boolean;
/**
* Indicates if data can still be sent to the write stream
*/
get isWritable(): boolean;
/**
* Indicates if the data is still coming from the read stream
*/
get isReadable(): boolean;
/**
* Proxy to the trailing metadata returned at the end of the response
*/
get trailingMetadata(): Metadata | undefined;
/**
* Sends unary (request/response) request to the service endpoint
* @param data Data to be sent as part of the request. Defaults to empty object
*/
makeUnaryRequest(data?: RequestType | null): Promise;
/**
* Sends client stream (request stream, single response) request to the service endpoint
* @param writerSandbox Async supported callback for writing data to the open stream
*/
makeClientStreamRequest(writerSandbox: StreamWriterSandbox): Promise;
/**
* Sends a server stream (single request, streamed response) request to the service endpoint
* @param data Data to be sent as part of the request
* @param streamReader Iteration function that will get called on every response chunk
*/
makeServerStreamRequest(data: RequestType | StreamReader, streamReader?: StreamReader): Promise;
/**
* Sends a bi-directional (stream request, stream response) request to the service endpoint
* @param writerSandbox Async supported callback for writing data to the open stream
* @param streamReader Iteration function that will get called on every response chunk
*/
makeBidiStreamRequest(writerSandbox: StreamWriterSandbox, streamReader: StreamReader): Promise;
/**
* Aborts the request if it is still active
*/
abort(): void;
/**
* Serializing method for outgoing messages
* @param object Request object passed from the caller
*/
private serializeRequest;
/**
* Deserializing method for incoming messages
* @param buffer Buffer object repsonse from the connection
*/
private deserializeResponse;
/**
* Determins if this request can be retried on error
* @param code Status code of the current error
*/
private canRetry;
/**
* Wraps active request calls with retry and timeout handlers
* @param requestRunner Request wrapper for running through retries
*/
retryWrapper(requestRunner: (
/**
* Starts the timer for timeouts, and triggers the reached callback
* once timer threshold has been met
*/
timeout: (timeoutReached: () => void) => void,
/**
* Callback for when the service response has completed
*/
completed: (error?: Error | ServiceError | null) => void) => void): Promise;
}
//# sourceMappingURL=ProtoRequest.d.ts.map