@octokit/types
Advanced tools
Comparing version 2.10.0 to 2.11.0
{ | ||
"name": "@octokit/types", | ||
"version": "2.10.0", | ||
"version": "2.11.0", | ||
"publishConfig": { | ||
@@ -17,3 +17,3 @@ "access": "public" | ||
"pretest": "npm run -s lint", | ||
"test": "npx tsc --noEmit --declaration src/index.ts", | ||
"test": "npx tsc --noEmit --declaration src/index.ts test.ts", | ||
"update-endpoints": "npm-run-all update-endpoints:*", | ||
@@ -20,0 +20,0 @@ "update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json", |
@@ -9,6 +9,21 @@ # types.ts | ||
<!-- toc --> | ||
- [Usage](#usage) | ||
- [Examples](#examples) | ||
- [Get parameter and response data types for a REST API endpoint](#get-parameter-and-response-data-types-for-a-rest-api-endpoint) | ||
- [Get response types from endpoint methods](#get-response-types-from-endpoint-methods) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
<!-- tocstop --> | ||
## Usage | ||
Get parameter and response data types for a REST API endpoint | ||
See all exported types at https://octokit.github.io/types.ts | ||
## Examples | ||
### Get parameter and response data types for a REST API endpoint | ||
```ts | ||
@@ -27,3 +42,3 @@ import { Endpoints } from "./src"; | ||
Get response types from endpoint methods | ||
### Get response types from endpoint methods | ||
@@ -46,4 +61,2 @@ ```ts | ||
See https://octokit.github.io/types.ts for all exported types | ||
## Contributing | ||
@@ -50,0 +63,0 @@ |
import { EndpointDefaults } from "./EndpointDefaults"; | ||
import { EndpointOptions } from "./EndpointOptions"; | ||
import { RequestOptions } from "./RequestOptions"; | ||
@@ -9,9 +8,13 @@ import { RequestParameters } from "./RequestParameters"; | ||
export interface EndpointInterface { | ||
export interface EndpointInterface<D extends object = object> { | ||
/** | ||
* Transforms a GitHub REST API endpoint into generic request options | ||
* | ||
* @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
* @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`. | ||
*/ | ||
(options: EndpointOptions): RequestOptions; | ||
<O extends RequestParameters = RequestParameters>( | ||
options: O & { method?: string } & ("url" extends keyof D | ||
? { url?: string } | ||
: { url: string }) | ||
): RequestOptions & Pick<D & O, keyof RequestOptions>; | ||
@@ -24,8 +27,12 @@ /** | ||
*/ | ||
<R extends Route>( | ||
route: keyof Endpoints | R, | ||
options?: R extends keyof Endpoints | ||
< | ||
R extends Route, | ||
P extends RequestParameters = R extends keyof Endpoints | ||
? Endpoints[R]["parameters"] & RequestParameters | ||
: RequestParameters | ||
): R extends keyof Endpoints ? Endpoints[R]["request"] : RequestOptions; | ||
>( | ||
route: keyof Endpoints | R, | ||
parameters?: P | ||
): (R extends keyof Endpoints ? Endpoints[R]["request"] : RequestOptions) & | ||
Pick<P, keyof RequestOptions>; | ||
@@ -35,8 +42,10 @@ /** | ||
*/ | ||
DEFAULTS: EndpointDefaults; | ||
DEFAULTS: D & EndpointDefaults; | ||
/** | ||
* Returns a new `endpoint` with updated route and parameters | ||
* Returns a new `endpoint` interface with new defaults | ||
*/ | ||
defaults: (newDefaults: RequestParameters) => EndpointInterface; | ||
defaults: <O extends RequestParameters = RequestParameters>( | ||
newDefaults: O | ||
) => EndpointInterface<D & O>; | ||
@@ -52,3 +61,15 @@ merge: { | ||
*/ | ||
(route: Route, parameters?: RequestParameters): EndpointDefaults; | ||
< | ||
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; | ||
@@ -61,3 +82,5 @@ /** | ||
*/ | ||
(options: RequestParameters): EndpointDefaults; | ||
<P extends RequestParameters = RequestParameters>( | ||
options: P | ||
): EndpointDefaults & D & P; | ||
@@ -69,3 +92,3 @@ /** | ||
*/ | ||
(): EndpointDefaults; | ||
(): D & EndpointDefaults; | ||
}; | ||
@@ -79,3 +102,5 @@ | ||
*/ | ||
parse: (options: EndpointDefaults) => RequestOptions; | ||
parse: <O extends EndpointDefaults = EndpointDefaults>( | ||
options: O | ||
) => RequestOptions & Pick<O, keyof RequestOptions>; | ||
} |
@@ -9,3 +9,3 @@ import { EndpointInterface } from "./EndpointInterface"; | ||
export interface RequestInterface { | ||
export interface RequestInterface<D extends object = object> { | ||
/** | ||
@@ -16,3 +16,7 @@ * Sends a request based on endpoint options | ||
*/ | ||
<T = any>(options: EndpointOptions): Promise<OctokitResponse<T>>; | ||
<T = any, O extends RequestParameters = RequestParameters>( | ||
options: O & { method?: string } & ("url" extends keyof D | ||
? { url?: string } | ||
: { url: string }) | ||
): Promise<OctokitResponse<T>>; | ||
@@ -35,5 +39,7 @@ /** | ||
/** | ||
* Returns a new `endpoint` with updated route and parameters | ||
* Returns a new `request` with updated route and parameters | ||
*/ | ||
defaults: (newDefaults: RequestParameters) => RequestInterface; | ||
defaults: <O extends RequestParameters = RequestParameters>( | ||
newDefaults: O | ||
) => RequestInterface<D & O>; | ||
@@ -43,3 +49,3 @@ /** | ||
*/ | ||
endpoint: EndpointInterface; | ||
endpoint: EndpointInterface<D>; | ||
} |
@@ -45,3 +45,3 @@ import { RequestRequestOptions } from "./RequestRequestOptions"; | ||
*/ | ||
[parameter: string]: any; | ||
[parameter: string]: unknown; | ||
}; |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "2.10.0"; | ||
export const VERSION = "2.11.0"; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1118056
41891
66