1 | import type { EndpointDefaults } from "./EndpointDefaults.js";
|
2 | import type { RequestOptions } from "./RequestOptions.js";
|
3 | import type { RequestParameters } from "./RequestParameters.js";
|
4 | import type { Route } from "./Route.js";
|
5 | import type { Endpoints } from "./generated/Endpoints.js";
|
6 | export interface EndpointInterface<D extends object = object> {
|
7 | /**
|
8 | * Transforms a GitHub REST API endpoint into generic request options
|
9 | *
|
10 | * @param {object} endpoint Must set `url` unless it's set defaults. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
11 | */
|
12 | <O extends RequestParameters = RequestParameters>(options: O & {
|
13 | method?: string;
|
14 | } & ("url" extends keyof D ? {
|
15 | url?: string;
|
16 | } : {
|
17 | url: string;
|
18 | })): RequestOptions & Pick<D & O, keyof RequestOptions>;
|
19 | /**
|
20 | * Transforms a GitHub REST API endpoint into generic request 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, P extends RequestParameters = R extends keyof Endpoints ? Endpoints[R]["parameters"] & RequestParameters : RequestParameters>(route: keyof Endpoints | R, parameters?: P): (R extends keyof Endpoints ? Endpoints[R]["request"] : RequestOptions) & Pick<P, keyof RequestOptions>;
|
26 | /**
|
27 | * Object with current default route and parameters
|
28 | */
|
29 | DEFAULTS: D & EndpointDefaults;
|
30 | /**
|
31 | * Returns a new `endpoint` interface with new defaults
|
32 | */
|
33 | defaults: <O extends RequestParameters = RequestParameters>(newDefaults: O) => EndpointInterface<D & O>;
|
34 | merge: {
|
35 | /**
|
36 | * Merges current endpoint defaults with passed route and parameters,
|
37 | * without transforming them into request options.
|
38 | *
|
39 | * @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
|
40 | * @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
41 | *
|
42 | */
|
43 | <R extends Route, P extends RequestParameters = R extends keyof Endpoints ? Endpoints[R]["parameters"] & RequestParameters : RequestParameters>(route: keyof Endpoints | R, parameters?: P): D & (R extends keyof Endpoints ? Endpoints[R]["request"] & Endpoints[R]["parameters"] : EndpointDefaults) & P;
|
44 | /**
|
45 | * Merges current endpoint defaults with passed route and parameters,
|
46 | * without transforming them into request options.
|
47 | *
|
48 | * @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
49 | */
|
50 | <P extends RequestParameters = RequestParameters>(options: P): EndpointDefaults & D & P;
|
51 | /**
|
52 | * Returns current default options.
|
53 | *
|
54 | * @deprecated use endpoint.DEFAULTS instead
|
55 | */
|
56 | (): D & EndpointDefaults;
|
57 | };
|
58 | /**
|
59 | * Stateless method to turn endpoint options into request options.
|
60 | * Calling `endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))`.
|
61 | *
|
62 | * @param {object} options `method`, `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
63 | */
|
64 | parse: <O extends EndpointDefaults = EndpointDefaults>(options: O) => RequestOptions & Pick<O, keyof RequestOptions>;
|
65 | }
|