magner
Version:
Universal admin panel magnetic to any backend
56 lines (55 loc) • 2.83 kB
TypeScript
import type { WretcherOptions } from 'wretch';
import type { DataToUrlHelper, ErrorParser, ProfileRequestFunc, UrlToDataHelper } from '../../types/configs/development';
import type { RequestFunc } from '../../types';
import type { CardRequestFunc } from '../../types/utils/api';
import type { TableRequestFunc } from '../../types/configs/pages/table';
import { ApiError } from '../../utils';
interface ApiControllerOptions {
baseUrl?: string;
fetchOptions?: WretcherOptions;
dataToUrl?: DataToUrlHelper;
urlToData?: UrlToDataHelper;
parseError?: ErrorParser<any>;
headers?: Record<string, string>;
interceptError?: (e: {
response?: Response;
text?: string;
name?: string;
}) => void;
}
type DataOrError<RESULT = any> = {
data: RESULT;
error?: never;
} | {
error: ApiError<any> | Error;
data?: never;
};
declare const createApi: (options: ApiControllerOptions) => {
instance: import("wretch").Wretcher;
get: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
post: <RESULT_1 = any>(path: string, body: any, config?: WretcherOptions) => Promise<DataOrError<RESULT_1>>;
put: <RESULT_1 = any>(path: string, body: any, config?: WretcherOptions) => Promise<DataOrError<RESULT_1>>;
patch: <RESULT_1 = any>(path: string, body: any, config?: WretcherOptions) => Promise<DataOrError<RESULT_1>>;
delete: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
head: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
opts: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
};
export declare const request: (options: ApiControllerOptions) => {
api: {
instance: import("wretch").Wretcher;
get: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
post: <RESULT_1 = any>(path: string, body: any, config?: WretcherOptions) => Promise<DataOrError<RESULT_1>>;
put: <RESULT_1 = any>(path: string, body: any, config?: WretcherOptions) => Promise<DataOrError<RESULT_1>>;
patch: <RESULT_1 = any>(path: string, body: any, config?: WretcherOptions) => Promise<DataOrError<RESULT_1>>;
delete: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
head: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
opts: <RESULT = any>(path: string, config?: WretcherOptions) => Promise<DataOrError<RESULT>>;
};
custom: RequestFunc;
card: CardRequestFunc;
table: TableRequestFunc;
profile: ProfileRequestFunc;
};
export type ApiType = ReturnType<typeof createApi>;
export type Request = ReturnType<typeof request>;
export {};