import * as grpc from '@grpc/grpc-js'; import { ErrorContext, GenericErrorContext } from '../errorcontexts'; import { CouchbaseError } from '../errors'; import { StatusDetails } from './statusdetails'; /** * Why a failed couchbase2 request may be sent again. The names are the ones * a classic connection records in an error context's `retry_reasons`. * * @internal */ export type RetryReason = 'service_not_available' | 'key_value_locked'; /** * An SDK error class whose constructor takes a cause and a context. * * @internal */ export type ErrorClass = new (cause?: Error, context?: ErrorContext) => CouchbaseError; /** * What a failure says about itself, the part of its error context that does * not depend on the request's history. * * @internal */ export type GatewayErrorFields = Pick; /** * What the request knows about its own history, the rest of the error * context. * * @internal */ export type RequestErrorFields = Pick; /** * A failure resolved to plain values: the error to raise and whether to * retry first. It is built into an error only when the request gives up, so * that the context can carry the whole retry history. * * @internal */ export interface MappedError { /** * The class to raise, or undefined for a plain {@link CouchbaseError} * carrying the gateway's message, for a failure with no more specific * error. */ errorClass: ErrorClass | undefined; /** * The failure's own context fields. */ fields: GatewayErrorFields; /** * Set when the failure is worth retrying. */ retryReason: RetryReason | undefined; /** * A value from the gateway that has no mapping here, for the log. */ unrecognized?: string; } /** * The error classes for `NOT_FOUND`, by `ResourceInfo.resource_type`. * * @internal */ export declare const NOT_FOUND: Readonly>; /** * The error classes for `ALREADY_EXISTS`, by `ResourceInfo.resource_type`. * * @internal */ export declare const ALREADY_EXISTS: Readonly>; /** * The error classes for `FAILED_PRECONDITION`, by the first violation's * type. A type missing here has no SDK error of its own and is a plain * {@link CouchbaseError}. * * @internal */ export declare const PRECONDITION_FAILED: Readonly>; /** * The error classes for codes no detail refines. `DEADLINE_EXCEEDED` * depends on the operation and is decided in {@link mapStatus}; a code * missing from both is a plain {@link CouchbaseError}. * * @internal */ export declare const BY_CODE: Readonly>>; /** * Whether `err` is a failed call as grpc-js reports it. * * @internal */ export declare function isServiceError(err: unknown): err is grpc.ServiceError; /** * `err`, thrown by a call, as the SDK sees it. `readOnly` decides whether a * deadline leaves the outcome ambiguous. Anything that is not a failed call, * such as a request that could not be serialized, is mapped as `UNKNOWN`. * * @internal */ export declare function mapServiceError(err: unknown, readOnly: boolean): MappedError; /** * Maps a failure's `code` and `message`, refined by whatever `details` the * gateway sent. A missing detail falls back to the code alone. Every detail * the gateway sent goes into the context whatever the code, while the code * decides which of them choose the error class. * * @internal */ export declare function mapStatus(code: grpc.status, message: string, details: StatusDetails | undefined, readOnly: boolean): MappedError; /** * The error to raise for `mapped`, its context completed by `request`. The * gRPC error is never the cause: what it says is in the context. * * @internal */ export declare function errorFromMapped(mapped: MappedError, request: RequestErrorFields): CouchbaseError; /** * Runs `call`, raising `FeatureNotAvailableError` in place of an invalid * argument the server explains with `phrase`: a setting the server refuses * for what the cluster or the bucket is, rather than for its value. * * @internal */ export declare function unavailableWhen(phrase: string, call: () => Promise): Promise; /** * The name of a gRPC status code, such as `NOT_FOUND`. * * @internal */ export declare function statusName(code: number): string;