UNPKG

@risemaxi/api-client

Version:

Client Library for Rise

52 lines 6.49 kB
import { Static } from "@sinclair/typebox"; import { FetchQueryOptions, InfiniteData, MutationKey, QueryClient, QueryFunctionContext, QueryKey, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query"; import type { Fetcher, HttpMethod, MaybeOptionalArg, MaybeOptionalOptions } from "./client.types.js"; import { DeleteEndpoints, EndpointByMethod, GetEndpoints, PatchEndpoints, PostEndpoints, PutEndpoints } from "./contract.js"; export declare class RiseApiClient { #private; fetcher: Fetcher; constructor(fetcher: Fetcher); setBaseUrl(baseUrl: string): this; setEnableParsing(enable: boolean): this; get<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): Promise<Static<TEndpoint>["response"]>; post<Path extends keyof PostEndpoints, TEndpoint extends PostEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): Promise<Static<TEndpoint>["response"]>; patch<Path extends keyof PatchEndpoints, TEndpoint extends PatchEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): Promise<Static<TEndpoint>["response"]>; delete<Path extends keyof DeleteEndpoints, TEndpoint extends DeleteEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): Promise<Static<TEndpoint>["response"]>; put<Path extends keyof PutEndpoints, TEndpoint extends PutEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): Promise<Static<TEndpoint>["response"]>; } export declare function createRiseApiClient(fetcher: Fetcher): RiseApiClient; export declare class RiseApiHooks { #private; constructor(client: RiseApiClient); getCacheKey<Method extends HttpMethod, Endpoint extends EndpointByMethod[Method], Path extends keyof Endpoint, TEndpoint extends Endpoint[Path]>(method: Method, path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): readonly [string, ...unknown[]]; setCachedData<Method extends HttpMethod, Endpoint extends EndpointByMethod[Method], Path extends keyof Endpoint, TEndpoint extends Endpoint[Path]>(queryClient: QueryClient, method: Method, path: Path, ...options: MaybeOptionalOptions<Static<TEndpoint>["response"], Static<TEndpoint>["parameters"]>): void; useSetCachedData<Method extends HttpMethod, Endpoint extends EndpointByMethod[Method], Path extends keyof Endpoint, TEndpoint extends Endpoint[Path]>(method: Method, path: Path, ...options: MaybeOptionalOptions<Static<TEndpoint>["response"], Static<TEndpoint>["parameters"]>): void; getCachedData<Method extends HttpMethod, Endpoint extends EndpointByMethod[Method], Path extends keyof Endpoint, TEndpoint extends Endpoint[Path]>(queryClient: QueryClient, method: Method, path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): // @ts-expect-error cannot seem to index with response Static<TEndpoint>["response"] | undefined; useGetCachedData<Method extends HttpMethod, Endpoint extends EndpointByMethod[Method], Path extends keyof Endpoint, TEndpoint extends Endpoint[Path]>(method: Method, path: Path, ...params: MaybeOptionalArg<Static<TEndpoint>["parameters"]>): // @ts-expect-error cannot seem to index with parameters Static<TEndpoint>["response"] | undefined; prefetchData<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(queryClient: QueryClient, path: Path, ...rest: MaybeOptionalOptions<Static<TEndpoint>["parameters"], FetchQueryOptions>): void; usePrefetchData<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(path: Path, ...rest: MaybeOptionalOptions<Static<TEndpoint>["parameters"], FetchQueryOptions>): void; useGet<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path], TQueryFnData extends Static<TEndpoint>["response"], TError = unknown, TData = TQueryFnData>(path: Path, ...rest: MaybeOptionalOptions<Static<TEndpoint>["parameters"], Omit<UseQueryOptions<TQueryFnData, TError, TData>, "queryKey" | "queryFn">>): UseQueryResult<TData, TError> & { invalidate: () => Promise<void>; queryKey: QueryKey; }; useInfiniteGet<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path], TData extends Static<TEndpoint>["response"], TError = Error>(path: Path, configMapper: (context: QueryFunctionContext<QueryKey>) => Static<TEndpoint>["parameters"], options: Omit<UseInfiniteQueryOptions<TData, TError>, "queryKey" | "queryFn">): UseInfiniteQueryResult<InfiniteData<TData>, TError> & { invalidate: () => Promise<void>; queryKey: QueryKey; }; usePost<Path extends keyof PostEndpoints, TEndpoint extends PostEndpoints[Path], TVariables extends Static<TEndpoint>["parameters"], TData extends Static<TEndpoint>["response"], TError = unknown>(path: Path, options?: Omit<UseMutationOptions<TData, TError, TVariables>, "mutationKey" | "mutationFn">): UseMutationResult<TData, TError, TVariables> & { mutationKey: MutationKey; }; usePatch<Path extends keyof PatchEndpoints, TEndpoint extends PatchEndpoints[Path], TVariables extends Static<TEndpoint>["parameters"], TData extends Static<TEndpoint>["response"], TError = unknown>(path: Path, options?: Omit<UseMutationOptions<TData, TError, TVariables>, "mutationKey" | "mutationFn">): UseMutationResult<TData, TError, TVariables> & { mutationKey: MutationKey; }; useDelete<Path extends keyof DeleteEndpoints, TEndpoint extends DeleteEndpoints[Path], TVariables extends Static<TEndpoint>["parameters"], TData extends Static<TEndpoint>["response"], TError = unknown>(path: Path, options?: Omit<UseMutationOptions<TData, TError, TVariables>, "mutationKey" | "mutationFn">): UseMutationResult<TData, TError, TVariables> & { mutationKey: MutationKey; }; usePut<Path extends keyof PutEndpoints, TEndpoint extends PutEndpoints[Path], TVariables extends Static<TEndpoint>["parameters"], TData extends Static<TEndpoint>["response"], TError = unknown>(path: Path, options?: Omit<UseMutationOptions<TData, TError, TVariables>, "mutationKey" | "mutationFn">): UseMutationResult<TData, TError, TVariables> & { mutationKey: MutationKey; }; } export declare function createRiseApiHooks(client: RiseApiClient): RiseApiHooks; //# sourceMappingURL=client.d.ts.map