UNPKG

apiful

Version:
62 lines (39 loc) 2.49 kB
import type { O as OpenAPIClient } from './shared/apiful.fCh43EkG.js'; export { F as FetchResponseData, a as FetchResponseError, b as FilterMethods, M as MethodOption, c as OpenAPIFetchOptions, P as ParamsOption, R as RequestBodyOption } from './shared/apiful.fCh43EkG.js'; import type { FetchOptions, MappedResponseType, ResponseType, $Fetch } from 'ofetch'; import type { OpenAPISchemaRepository } from 'apiful/schema'; import 'openapi-typescript-helpers'; type Fn<T = any> = (...args: any[]) => T; type HandlerExtension = Fn; type MethodsExtension = Record<string, unknown>; type ApiExtension = HandlerExtension | MethodsExtension; type HandlerExtensionBuilder = (client: ApiClient) => HandlerExtension; type MethodsExtensionBuilder = (client: ApiClient) => MethodsExtension; interface ApiClient<BaseURL extends string = string> extends Function { _handler: Fn; _extensions: Record<PropertyKey, unknown>; defaultOptions: FetchOptions; with: <Extension extends ApiExtension>(createExtension: (client: ApiClient<BaseURL>) => Extension) => this & Extension; } declare function createClient<const BaseURL extends string = '/'>(defaultOptions?: Omit<FetchOptions, 'baseURL'> & { baseURL?: BaseURL; }): ApiClient<BaseURL>; type ApiMethodHandler<Data = unknown> = <T = any, R extends ResponseType = 'json'>(data?: Data, opts?: Omit<FetchOptions<R>, 'baseURL' | 'method'>) => Promise<MappedResponseType<R, T>>; type ApiRouter = { (...args: (string | number)[]): ApiRouter; [key: string]: ApiRouter; } & { get: ApiMethodHandler<FetchOptions['query']>; post: ApiMethodHandler<FetchOptions['body']>; put: ApiMethodHandler<FetchOptions['body']>; delete: ApiMethodHandler<FetchOptions['body']>; patch: ApiMethodHandler<FetchOptions['body']>; }; declare function apiRouterBuilder(): (client: ApiClient) => ApiRouter; interface OFetchClient extends $Fetch { } declare function ofetchBuilder(): (client: ApiClient) => OFetchClient; type ExtractPaths<K> = K extends keyof OpenAPISchemaRepository ? OpenAPISchemaRepository[K] : Record<string, never>; declare function OpenAPIBuilder<const Schema extends string, Paths = ExtractPaths<Schema>>(): (client: ApiClient) => OpenAPIClient<Paths>; export { OpenAPIBuilder, apiRouterBuilder, createClient, ofetchBuilder }; export type { ApiClient, ApiExtension, ApiRouter, HandlerExtension, HandlerExtensionBuilder, MethodsExtension, MethodsExtensionBuilder, OFetchClient, OpenAPIClient };