import type * as grpc from '@grpc/grpc-js'; import { RetryReason } from './errormapping'; import type { RequestContext } from './requestcontext'; /** * A strategy's answer: wait `delayMs` and retry, or give up when it is * undefined. * * @internal */ export interface RetryAction { /** * The milliseconds to wait before retrying, or undefined to give up. */ delayMs: number | undefined; } /** * The answer that gives up. * * @internal */ export declare const DO_NOT_RETRY: RetryAction; /** * What a strategy may read about the request it is deciding for. * * @internal */ export interface RetryRequest { /** * The request's own identifier, as logged with each retry. */ readonly identifier: string; /** * Whether the request may be sent again whatever the reason. Only * read-only operations are idempotent, so this is the operation's * `readOnly`. */ readonly idempotent: boolean; /** * The retries made so far, not counting the one being decided. */ readonly retryAttempts: number; /** * Each reason retried for so far, once, in the order first seen. */ readonly retryReasons: readonly RetryReason[]; } /** * Decides whether, and after how long, a request is retried. Neither * couchbase2 reason always retries, so every retry is put to the strategy. It only proposes a delay: the request's deadline still caps it. * * @internal */ export interface RetryStrategy { /** * Whether, and after how long, `request` is retried for `reason`. */ retryAfter(request: RetryRequest, reason: RetryReason): RetryAction; } /** * Whether a request that is not idempotent may be retried for `reason`. * * @internal */ export declare function allowsNonIdempotentRetry(reason: RetryReason): boolean; /** * The wait in milliseconds before retry number `retryAttempts + 1`. There is * no attempt cap; the request's deadline is one. * * @internal */ export declare function controlledBackoff(retryAttempts: number): number; /** * Retries with controlled backoff whenever retrying cannot apply a write * twice. * * @internal */ export declare class BestEffortRetryStrategy implements RetryStrategy { /** * Retries after the controlled backoff when `request` is idempotent or * `reason` says the gateway did not apply it; gives up otherwise. */ retryAfter(request: RetryRequest, reason: RetryReason): RetryAction; } /** * Sends a unary call through `ctx` until it succeeds or the request gives * up. `call` makes one attempt, given the call options to pass to grpc-js; * `sleep` waits between attempts. * * @internal */ export declare function retryUnary(ctx: RequestContext, call: (options: grpc.CallOptions) => Promise, sleep?: (ms: number) => Promise): Promise; /** * Sends one unary call through `ctx`, retrying it as the context decides. * `send` makes one attempt, given the call options and the callback to pass * to the generated client. * * @internal */ export declare function unary(ctx: RequestContext, send: (options: grpc.CallOptions, callback: grpc.requestCallback) => void): Promise;