UNPKG

1.72 kBTypeScriptView Raw
1import type { EndpointInterface } from "./EndpointInterface.js";
2import type { OctokitResponse } from "./OctokitResponse.js";
3import type { RequestParameters } from "./RequestParameters.js";
4import type { Route } from "./Route.js";
5import type { Endpoints } from "./generated/Endpoints.js";
6export interface RequestInterface<D extends object = object> {
7 /**
8 * Sends a request based on endpoint options
9 *
10 * @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
11 */
12 <T = any, O extends RequestParameters = RequestParameters>(options: O & {
13 method?: string;
14 } & ("url" extends keyof D ? {
15 url?: string;
16 } : {
17 url: string;
18 })): Promise<OctokitResponse<T>>;
19 /**
20 * Sends a request based on endpoint options
21 *
22 * @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
23 * @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
24 */
25 <R extends Route>(route: keyof Endpoints | R, options?: R extends keyof Endpoints ? Endpoints[R]["parameters"] & RequestParameters : RequestParameters): R extends keyof Endpoints ? Promise<Endpoints[R]["response"]> : Promise<OctokitResponse<any>>;
26 /**
27 * Returns a new `request` with updated route and parameters
28 */
29 defaults: <O extends RequestParameters = RequestParameters>(newDefaults: O) => RequestInterface<D & O>;
30 /**
31 * Octokit endpoint API, see {@link https://github.com/octokit/endpoint.js|@octokit/endpoint}
32 */
33 endpoint: EndpointInterface<D>;
34}