/** * Runs generated unary SDK requests. * * Use {@link Request} to await a response, inspect call diagnostics, or cancel * a call. Use {@link RetryOptions} to control its timeout and retry policy. * * @packageDocumentation */ import { type CallOptions, type ClientUnaryCall, type ServiceError as GrpcServiceError, Metadata } from '@grpc/grpc-js'; import { Status as GrpcStatus, Code as StatusCode } from '../api/google/rpc/index.js'; import { SDKInterface } from '../sdk.js'; import { type MessageDescriptor } from './protos/core.js'; import { custom, customJson } from './util/logging.js'; /** * Controls the timeout and retry policy for one logical request. * * All values are milliseconds except {@link RetryOptions.RetryCount}. A gRPC * `deadline` in the same call-options object limits the complete request. The * SDK uses a 15-minute deadline when you omit it. * * @example * ```ts * import { Metadata } from '@grpc/grpc-js'; * import { * BucketService, * GetBucketRequest, * } from '@nebius/js-sdk/api/nebius/storage/v1/index'; * * async function getBucket(client: BucketService) { * const call = client.get( * GetBucketRequest.create({ id: 'bucket-id' }), * new Metadata(), * { * deadline: new Date(Date.now() + 30_000), * RequestTimeout: 20_000, * PerRetryTimeout: 5_000, * RetryCount: 2, * }, * ); * return call.result; * } * ``` */ export interface RetryOptions { /** * Limits one authenticated request window. * * The default is 60,000 milliseconds. */ RequestTimeout?: number; /** * Limits each gRPC attempt. * * The default is 20,000 milliseconds. The overall deadline and * {@link RetryOptions.RequestTimeout} can shorten an attempt. */ PerRetryTimeout?: number; /** * Sets the number of retries after the first attempt. * * The default is 3. Set this value to `0` to make only one attempt. */ RetryCount?: number; } /** * Contains the gRPC status codes that cause an automatic retry by default. * * The runtime can also retry selected transport failures, HTTP 52x failures, * and service errors that explicitly request a call retry. */ export declare const DefaultRetriableCodes: StatusCode[]; /** * Checks whether an SDK request error is safe to retry. * * This is shared by the request retry loop and long-running operation polling. */ export declare function isRetriableError(err: unknown): boolean; /** * Describes a generated unary method to the request runtime. * * Generated service clients normally create this value. Application code does * not need to construct it. */ export interface RequestSpec { /** Contains the gRPC method path, such as `/package.Service/Get`. */ path: string; /** Serializes the request message for gRPC. */ requestSerialize: (value: TReq) => Buffer; /** * Controls the `x-resetmask` header. * * Update methods send the header by default. Set this value to `false` to * disable that behavior for an update method. */ sendResetMask?: boolean; /** Returns schema data used to build a reset mask. */ requestDescriptor?: () => MessageDescriptor | undefined; } /** Defines the shape of a generated unary gRPC call function. */ export type CallCreator = (request: TReq, metadata: Metadata | undefined, options: Partial | undefined, callback: (error: GrpcServiceError | null, response: TRes) => void) => ClientUnaryCall; /** * Runs one unary SDK request and exposes its result and diagnostics. * * Generated service methods return this object. You can await the object * directly because it implements `PromiseLike`, or you can await * {@link Request.result}. Keep the object when you also need metadata, status, * request IDs, or cancellation. * * The runtime adds authorization metadata when a provider exists. It adds one * idempotency key to mutating methods and reuses that key for every retry. For * update methods, it can also create an `x-resetmask` header from the request. * * @example * ```ts * import { * BucketService, * GetBucketRequest, * } from '@nebius/js-sdk/api/nebius/storage/v1/index'; * * async function inspectRequest(client: BucketService) { * const call = client.get(GetBucketRequest.create({ id: 'bucket-id' })); * try { * const resource = await call; * const status = await call.status; * console.log(resource, status.code); * } catch (error) { * console.error('request failed', error); * } * } * ``` * * @typeParam TReq The generated request message type. * @typeParam TRes The generated response type. */ export declare class Request implements PromiseLike { /** Formats the current request state for Node.js inspection. */ [custom]: () => string; private sdk; private addr; private deserializer; private request; private requestMetadata; private requestOptions?; /** Contains the fully qualified runtime type name. */ readonly $type: 'nebius.sdk.Request'; /** Resolves with the response, or rejects with the final request error. */ readonly result: Promise; /** Resolves with the response headers when gRPC reports them. */ readonly initialMetadata: Promise; /** Resolves with the response trailers when gRPC reports them. */ readonly trailingMetadata: Promise; /** Resolves with the final Google RPC status for success or failure. */ readonly status: Promise; /** * Resolves with `x-request-id` when the server returns that header. * * Do not await this promise as a completion signal. It stays pending when * the server does not return the header. */ readonly requestId: Promise; /** * Resolves with `x-trace-id` when the server returns that header. * * Do not await this promise as a completion signal. It stays pending when * the server does not return the header. */ readonly traceId: Promise; private _resolveInitialMd; private _resolveTrailingMd; private _resolveStatus; private _resolveReqId; private _resolveTraceId; private logger; private _maybeReqId; private _maybeTraceId; private _maybeStatus; private _canceled; private _calls; private readonly serviceName; private readonly methodName; private readonly path; private readonly serializer; private readonly sendResetMask; /** * Creates and starts a request. * * Generated service clients call this constructor. Construction starts * authorization and the gRPC call without waiting for the result. */ constructor(sdk: SDKInterface, spec: RequestSpec, addr: string, deserializer: (value: Buffer) => TRes, request: TReq, requestMetadata: Metadata | undefined, requestOptions?: (Partial & RetryOptions) | undefined); /** * Registers handlers for the request result. * * This method makes awaiting the request equivalent to awaiting * {@link Request.result}. */ then(onfulfilled?: ((value: TRes) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike) | undefined | null): Promise; /** Returns a JSON-safe value for logs. */ [customJson](): Record; private _safeResolveIdsFromMd; private _isRetriableError; /** * Cancels active gRPC calls and prevents later retries. * * Cancellation is safe to call more than once. The result rejects with a * cancellation error after the active call reports cancellation. * * @example * ```ts * import { * BucketService, * GetBucketRequest, * } from '@nebius/js-sdk/api/nebius/storage/v1/index'; * * async function getWithLocalTimeout(client: BucketService) { * const call = client.get(GetBucketRequest.create({ id: 'bucket-id' })); * const timer = setTimeout(() => call.cancel('local timeout'), 5_000); * try { * return await call.result; * } finally { * clearTimeout(timer); * } * } * ``` */ cancel(reason?: string): void; } //# sourceMappingURL=request.d.ts.map