UNPKG

@tonightpass/react

Version:
41 lines (36 loc) 2.25 kB
import { SWRConfiguration, SWRResponse } from 'swr'; import { Client, PathsFor, Endpoints, TonightPassAPIError, APIRequestOptions, Query, WebSocketPaths, WebSocketEndpoints } from 'tonightpass'; import { SWRInfiniteConfiguration, SWRInfiniteResponse } from 'swr/infinite'; declare const client: Client; type AnyEndpoint = Endpoints extends infer T ? T : never; type ForceAccept$1<T> = T extends never ? any : T; type ResponseType<Path extends PathsFor<"GET">> = ForceAccept$1<Extract<AnyEndpoint, { path: Path; method: "GET"; }>["res"]>; type ErrorType<Path extends PathsFor<"GET">> = TonightPassAPIError<ResponseType<Path>>; interface UseAPIConfig<Path extends PathsFor<"GET">> extends SWRConfiguration<ResponseType<Path>, ErrorType<Path>> { requestOptions?: APIRequestOptions; } declare function useAPI<Path extends PathsFor<"GET">>(path: Path | null | undefined, query?: Query<Path>, config?: UseAPIConfig<Path>): SWRResponse<ResponseType<Path>, ErrorType<Path>>; interface UseAPIInfiniteConfig<Path extends PathsFor<"GET">> extends SWRInfiniteConfiguration<ResponseType<Path>, ErrorType<Path>> { requestOptions?: APIRequestOptions; } declare function useAPIInfinite<Path extends PathsFor<"GET">>(getKey: (pageIndex: number, previousPageData: ResponseType<Path> | null) => [Path, Query<Path> | undefined] | null, config?: UseAPIInfiniteConfig<Path>): SWRInfiniteResponse<ResponseType<Path>, ErrorType<Path>>; type AnyWebSocketEndpoint = WebSocketEndpoints extends infer T ? T : never; type ForceAccept<T> = T extends never ? unknown : T; type WebSocketOptionsType<Path extends WebSocketPaths> = ForceAccept<Extract<AnyWebSocketEndpoint, { path: Path; }>["options"]>; interface UseWebSocketOptions { maxReconnectAttempts?: number; reconnectInterval?: number; } declare function useWebSocket<Path extends WebSocketPaths>(path: Path | null | undefined, options?: WebSocketOptionsType<Path>, config?: UseWebSocketOptions): { data: any; error: any; isConnected: boolean; isDisconnected: boolean; message: any; }; export { type ErrorType, type ResponseType, type UseAPIConfig, type UseAPIInfiniteConfig, type UseWebSocketOptions, type WebSocketOptionsType, client, useAPI, useAPIInfinite, useWebSocket };