UNPKG

payload-rest-client

Version:

A typesafe rest api client for the payload cms.

19 lines (18 loc) 822 B
import { FetchMethod } from "./fetch"; import { ClientOptions } from "./types"; export type CEInput<P = Record<string, string>, Q = Record<string, any>, B = any> = { params?: P; query?: Q; body?: B; }; export type CustomEndpoint<Input extends CEInput, Output> = (input: Input) => Promise<Output>; export type CustomEndpoints = Record<string, CustomEndpoint<any, any>>; export type CustomEndpointFactory<Params> = { method: FetchMethod; path: (params: Params) => string; }; export type CustomEndpointFactories = Record<string, CustomEndpointFactory<any>>; export type CE_To_CEFactory<T> = { [P in keyof T]: T[P] extends CustomEndpoint<infer I, any> ? CustomEndpointFactory<I["params"]> : never; }; export declare const createCustomEndpoints: (options: ClientOptions) => CustomEndpoints | undefined;