UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

187 lines • 7.53 kB
/** @packageDocumentation * @module RpcInterface */ import { BeEvent } from "@itwin/core-bentley"; import { IModelRpcProps } from "../../IModel"; import { RpcInterface } from "../../RpcInterface"; import { RpcConfiguration } from "./RpcConfiguration"; import { RpcRequestEvent, RpcRequestStatus, RpcResponseCacheControl } from "./RpcConstants"; import { RpcNotFoundResponse } from "./RpcControl"; import { RpcSerializedValue } from "./RpcMarshaling"; import { RpcOperation } from "./RpcOperation"; import { RpcProtocol, RpcProtocolVersion } from "./RpcProtocol"; /** @internal */ export declare const aggregateLoad: { lastRequest: number; lastResponse: number; }; /** @internal */ export declare class ResponseLike implements Response { private _data; get body(): null; arrayBuffer(): Promise<ArrayBuffer>; blob(): Promise<Blob>; formData(): Promise<FormData>; json(): Promise<any>; text(): Promise<string>; get bodyUsed(): boolean; get headers(): Headers; get ok(): boolean; get redirected(): boolean; get status(): number; get statusText(): string; get trailer(): Promise<Headers>; get type(): "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; get url(): string; clone(): this; constructor(data: any); } /** Supplies an IModelRpcProps for an RPC request. * @internal */ export type RpcRequestTokenSupplier_T = (request: RpcRequest) => IModelRpcProps | undefined; /** Supplies the initial retry interval for an RPC request. * @internal */ export type RpcRequestInitialRetryIntervalSupplier_T = (configuration: RpcConfiguration) => number; /** Notification callback for an RPC request. * @internal */ export type RpcRequestCallback_T = (request: RpcRequest) => void; /** Determines if caching is permitted for a RPC response. * @internal */ export type RpcResponseCachingCallback_T = (request: RpcRequest) => RpcResponseCacheControl; /** Runtime information related to the operation load of one or more RPC interfaces. * @internal */ export interface RpcOperationsProfile { readonly lastRequest: number; readonly lastResponse: number; } /** Handles RPC request events. * @internal */ export type RpcRequestEventHandler = (type: RpcRequestEvent, request: RpcRequest) => void; /** Resolves "not found" responses for RPC requests. * @internal */ export type RpcRequestNotFoundHandler = (request: RpcRequest, response: RpcNotFoundResponse, resubmit: () => void, reject: (reason?: any) => void) => void; /** A RPC operation request. * @internal */ export declare abstract class RpcRequest<TResponse = any> { private static _activeRequests; private _resolve; protected _resolveRaw: (value?: Response | PromiseLike<Response> | undefined) => void; private _reject; private _rejectRaw; private _created; private _lastSubmitted; private _lastUpdated; /** @internal */ _status: RpcRequestStatus; /** @internal */ _extendedStatus: string; private _connecting; private _active; private _hasRawListener; private _raw; private _sending?; private _attempts; private _retryAfter; private _transientFaults; protected _response: Response | undefined; protected _rawPromise: Promise<Response | undefined>; responseProtocolVersion: RpcProtocolVersion; /** All RPC requests that are currently in flight. */ static get activeRequests(): ReadonlyMap<string, RpcRequest>; /** Events raised by RpcRequest. See [[RpcRequestEvent]] */ static readonly events: BeEvent<RpcRequestEventHandler>; /** Resolvers for "not found" requests. See [[RpcRequestNotFoundHandler]] */ static readonly notFoundHandlers: BeEvent<RpcRequestNotFoundHandler>; /** The aggregate operations profile of all active RPC interfaces. */ static get aggregateLoad(): RpcOperationsProfile; /** * The request for the current RPC operation. * @note The return value of this function is only reliable if program control was received from a RPC interface class member function that directly returns the result of calling RpcInterface.forward. */ static current(context: RpcInterface): RpcRequest; /** The unique identifier of this request. */ readonly id: string; /** The operation for this request. */ readonly operation: RpcOperation; /** The parameters for this request. */ parameters: any[]; /** The RPC client instance for this request. */ readonly client: RpcInterface; /** Convenience access to the protocol of this request. */ readonly protocol: RpcProtocol; /** The implementation response for this request. */ readonly response: Promise<TResponse | undefined>; /** The status of this request. */ get status(): RpcRequestStatus; /** Extended status information for this request (if available). */ get extendedStatus(): string; /** The last submission for this request. */ get lastSubmitted(): number; /** The last status update received for this request. */ get lastUpdated(): number; /** The target interval (in milliseconds) between submission attempts for this request. */ retryInterval: number; /** Whether a connection is active for this request. */ get connecting(): boolean; /** Whether this request is pending. */ get pending(): boolean; /** The elapsed time for this request. */ get elapsed(): number; /** A protocol-specific path identifier for this request. */ path: string; /** A protocol-specific method identifier for this request. */ method: string; /** An attempt-specific value for when to next retry this request. */ get retryAfter(): number | null; /** Finds the first parameter of a given structural type if present. */ findParameterOfType<T>(requiredProperties: { [index: string]: string; }): T | undefined; /** Finds the first IModelRpcProps parameter if present. */ findTokenPropsParameter(): IModelRpcProps | undefined; /** The raw implementation response for this request. */ get rawResponse(): Promise<Response | undefined>; /** Constructs an RPC request. */ constructor(client: RpcInterface, operation: string, parameters: any[]); /** Override to send the request. */ protected abstract send(): Promise<number>; /** Override to load response value. */ protected abstract load(): Promise<RpcSerializedValue>; /** Override to set request header values. */ protected abstract setHeader(name: string, value: string): void; /** Sets the last updated time for the request. */ protected setLastUpdatedTime(): void; protected computeRetryAfter(attempts: number): number; protected recordTransientFault(): void; protected resetTransientFaultCount(): void; protected supportsStatusCategory(): boolean; cancel(): void; submit(): Promise<void>; protected handleUnknownResponse(code: number): void; private handleResponse; private transformResponseStatus; private handleResolved; private handleRejected; private handleNoContent; private handleNotFound; private resolve; private resolveRaw; protected reject(reason: any): void; /** @internal */ [Symbol.dispose](): void; private setPending; private handleTransientError; protected setHeaders(): Promise<void>; private setStatus; } /** @internal */ export declare const initializeRpcRequest: () => void; //# sourceMappingURL=RpcRequest.d.ts.map