{"version":3,"file":"rpc-service-requestable.cjs","sourceRoot":"","sources":["../../src/rpc-service/rpc-service-requestable.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type {\n  Json,\n  JsonRpcParams,\n  JsonRpcRequest,\n  JsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { AddToCockatielEventData, FetchOptions } from './shared';\n\n/**\n * The interface for a service class responsible for making a request to a\n * target, whether that is a single RPC endpoint or an RPC endpoint in an RPC\n * service chain.\n */\nexport type RpcServiceRequestable = {\n  /**\n   * Listens for when the RPC service retries the request.\n   *\n   * @param listener - The callback to be called when the retry occurs.\n   * @returns What {@link ServicePolicy.onRetry} returns.\n   * @see {@link createServicePolicy}\n   */\n  onRetry(\n    listener: AddToCockatielEventData<\n      Parameters<ServicePolicy['onRetry']>[0],\n      { endpointUrl: string }\n    >,\n  ): ReturnType<ServicePolicy['onRetry']>;\n\n  /**\n   * Listens for when the RPC service retries the request too many times in a\n   * row.\n   *\n   * @param listener - The callback to be called when the circuit is broken.\n   * @returns What {@link ServicePolicy.onBreak} returns.\n   * @see {@link createServicePolicy}\n   */\n  onBreak(\n    listener: AddToCockatielEventData<\n      Parameters<ServicePolicy['onBreak']>[0],\n      { endpointUrl: string }\n    >,\n  ): ReturnType<ServicePolicy['onBreak']>;\n\n  /**\n   * Listens for when the policy underlying this RPC service detects a slow\n   * request.\n   *\n   * @param listener - The callback to be called when the request is slow.\n   * @returns What {@link ServicePolicy.onDegraded} returns.\n   * @see {@link createServicePolicy}\n   */\n  onDegraded(\n    listener: AddToCockatielEventData<\n      Parameters<ServicePolicy['onDegraded']>[0],\n      { endpointUrl: string }\n    >,\n  ): ReturnType<ServicePolicy['onDegraded']>;\n\n  /**\n   * Makes a request to the target.\n   */\n  request<Params extends JsonRpcParams, Result extends Json>(\n    jsonRpcRequest: JsonRpcRequest<Params>,\n    fetchOptions?: FetchOptions,\n  ): Promise<JsonRpcResponse<Result | null>>;\n};\n"]}