@bigmi/core
Version:
TypeScript library for Bitcoin apps.
30 lines (29 loc) • 1.4 kB
TypeScript
import type { RpcResponse } from '../types/rpc.js';
import type { MaybePromise } from '../types/utils.js';
export type RpcRequest = {
jsonrpc?: '2.0';
method: string;
params?: any;
id?: number;
};
export type HttpRequestReturnType<body extends RpcRequest | RpcRequest[] = RpcRequest> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse;
export type HttpRpcClientOptions = {
fetchOptions?: Omit<RequestInit, 'body'> | undefined;
onRequest?: ((request: Request, init: RequestInit) => MaybePromise<void | undefined | (RequestInit & {
url?: string | undefined;
})>) | undefined;
onResponse?: ((response: Response) => Promise<void> | void) | undefined;
timeout?: number | undefined;
};
export type HttpRequestParameters<body extends RpcRequest | RpcRequest[] = RpcRequest> = {
url?: string;
body?: body;
fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined;
onRequest?: ((request: Request) => Promise<void> | void) | undefined;
onResponse?: ((response: Response) => Promise<void> | void) | undefined;
timeout?: HttpRpcClientOptions['timeout'] | undefined;
};
export type HttpRpcClient = {
request<body extends RpcRequest | RpcRequest[]>(params: HttpRequestParameters<body>): Promise<HttpRequestReturnType<body>>;
};
export declare function getHttpRpcClient(url: string, options?: HttpRpcClientOptions): HttpRpcClient;