import type { FetcherInterceptor } from '@distributedlab/fetcher'; import { Fetcher } from '@distributedlab/fetcher'; import type { JsonApiResponse } from './response'; import type { Endpoint, JsonApiClientConfig, JsonApiClientRequestOpts, JsonApiDefaultMeta, URL } from './types'; /** * Represents JsonApiClient that performs requests to backend */ export declare class JsonApiClient { #private; constructor(config: JsonApiClientConfig, interceptors?: FetcherInterceptor[]); /** * Clones current JsonApiClient instance */ clone(): JsonApiClient; /** * Sets Fetcher instance to the client instance. */ get fetcher(): Fetcher; /** * Sets Fetcher instance to the client instance. */ useFetcher(fetcher: Fetcher): JsonApiClient; /** * Base URL will be prepended to `url` unless `url` is absolute. * It can be convenient to set `baseUrl` for an instance of fetcher to pass * relative URLs to methods of that instance. */ get baseUrl(): URL; /** * Assigns new base URL to the current instance. */ useBaseUrl(baseUrl: URL): JsonApiClient; /** * Creates new instance JsonApiClient instance with given base URL. */ withBaseUrl(baseUrl: URL): JsonApiClient; /** * Sets new interceptor to the current Fetcher instance. */ addInterceptor(interceptor: FetcherInterceptor): void; /** * Removes the existing interceptor from the Fetcher instance. */ removeInterceptor(interceptor: FetcherInterceptor): void; /** * Clears all existing interceptors from the Fetcher instance. */ clearInterceptors(): void; /** * Generates new request id in the UUID format. */ createRequestId(): string; /** * Interrupts the request by given `requestId`, if request is not found returns `false`. */ abort(requestId?: string): boolean; /** * Performs a http request */ request(opts: JsonApiClientRequestOpts): Promise>; /** * Makes a `GET` to a target `endpoint` with the provided `query` params. * Parses the response in JsonApi format. */ get(endpoint: Endpoint, opts?: Partial): Promise>; /** * Makes a `POST` to a target `endpoint` with the provided `data` as body. * Parses the response in JsonApi format. */ post(endpoint: Endpoint, opts?: Partial): Promise>; /** * Makes a `PATCH` to a target `endpoint` with the provided `data` as body. * Signing can be enabled with `needSign` argument. Parses the response in * JsonApi format. */ patch(endpoint: string, opts?: Partial): Promise>; /** * Makes a `PUT` to a target `endpoint` with the provided `data` as body. * Parses the response in JsonApi format. */ put(endpoint: string, opts?: Partial): Promise>; /** * Makes a `DELETE` to a target `endpoint` with the provided `data` as body. * Parses the response in JsonApi format. */ delete(endpoint: string, opts?: Partial): Promise>; }