@octokit-next/endpoint
Advanced tools
Comparing version 1.14.0 to 1.15.0
@@ -1,17 +0,54 @@ | ||
import { expectType } from "tsd"; | ||
import { expectType, expectNotType } from "tsd"; | ||
import "@octokit-next/types-rest-api-ghes-3.2"; | ||
import { endpoint } from "./index.js"; | ||
declare module "@octokit-next/types" { | ||
namespace Octokit { | ||
interface Endpoints { | ||
/** | ||
* @see https://docs.github.com/rest/reference/apps#delete-an-installation-for-the-authenticated-app | ||
*/ | ||
"GET /endpoint-test/{id}": { | ||
parameters: { | ||
id: string; | ||
}; | ||
request: { | ||
method: "GET"; | ||
// the resulting `.url` property will replace the `{}` placeholders, so the type must be a generic string | ||
url: string; | ||
}; | ||
response: {}; | ||
}; | ||
} | ||
interface ApiVersions { | ||
"endpoint-test": { | ||
Endpoints: Octokit.Endpoints & { | ||
"POST /endpoint-test/{id}/version-test": { | ||
parameters: { | ||
id: string; | ||
test: string; | ||
}; | ||
request: { | ||
method: "POST"; | ||
url: string; | ||
data: { | ||
test: string; | ||
}; | ||
}; | ||
response: {}; | ||
}; | ||
}; | ||
}; | ||
} | ||
} | ||
} | ||
export function readmeExample() { | ||
const requestOptions = endpoint("GET /orgs/{org}/repos", { | ||
headers: { | ||
authorization: "token 0000000000000000000000000000000000000001", | ||
}, | ||
org: "octokit", | ||
type: "private", | ||
const requestOptions = endpoint("GET /endpoint-test/{id}", { | ||
id: "id", | ||
}); | ||
expectType<"GET">(requestOptions.method); | ||
expectType<"/orgs/{org}/repos">(requestOptions.url); | ||
expectType<string>(requestOptions.url); | ||
expectNotType<"/endpoint-test/{id}">(requestOptions.url); | ||
expectType<string>(requestOptions.headers["accept"]); | ||
@@ -26,15 +63,12 @@ expectType<string>(requestOptions.headers["user-agent"]); | ||
export function ghesExample() { | ||
const requestOptions = endpoint("PATCH /admin/organizations/{org}", { | ||
const requestOptions = endpoint("POST /endpoint-test/{id}/version-test", { | ||
request: { | ||
version: "ghes-3.2", | ||
version: "endpoint-test", | ||
}, | ||
headers: { | ||
authorization: "token 0000000000000000000000000000000000000001", | ||
}, | ||
org: "octokit", | ||
login: "new-octokit", | ||
id: "id", | ||
test: "test", | ||
}); | ||
expectType<"PATCH">(requestOptions.method); | ||
expectType<"/admin/organizations/{org}">(requestOptions.url); | ||
expectType<"POST">(requestOptions.method); | ||
expectType<string>(requestOptions.url); | ||
expectType<string>(requestOptions.headers["accept"]); | ||
@@ -45,4 +79,112 @@ expectType<string>(requestOptions.headers["user-agent"]); | ||
expectType<{ | ||
login: string; | ||
test: string; | ||
}>(requestOptions.data); | ||
} | ||
export function objectExample() { | ||
// @ts-expect-error - TODO: endpoint(options) is an alternative API to endpoint(route, parameters) | ||
const requestOptions = endpoint({ | ||
method: "GET", | ||
url: "/endpoint-test/{id}", | ||
id: "id", | ||
}); | ||
expectType<"GET">(requestOptions.method); | ||
expectType<string>(requestOptions.url); | ||
expectNotType<"/endpoint-test/{id}">(requestOptions.url); | ||
expectType<string>(requestOptions.headers["accept"]); | ||
expectType<string>(requestOptions.headers["user-agent"]); | ||
expectType<string | undefined>(requestOptions.headers["authorization"]); | ||
// @ts-expect-error - `.data` is not set for a GET operation | ||
requestOptions.data; | ||
} | ||
export function apiWithDefaults() { | ||
const myEndpoint = endpoint.withDefaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
headers: { | ||
"user-agent": "myApp/1.2.3", | ||
authorization: `token 0000000000000000000000000000000000000001`, | ||
}, | ||
}); | ||
const options = myEndpoint(`GET /endpoint-test/{id}`, { | ||
id: "id", | ||
}); | ||
expectType<"GET">(options.method); | ||
expectType<string>(options.url); | ||
const myEndpointWithToken2 = myEndpoint.withDefaults({ | ||
headers: { | ||
authorization: `token 0000000000000000000000000000000000000002`, | ||
}, | ||
}); | ||
const options2 = myEndpointWithToken2(`GET /endpoint-test/{id}`, { | ||
id: "id", | ||
}); | ||
expectType<"GET">(options2.method); | ||
expectType<string>(options2.url); | ||
} | ||
export function apiDEFAULTS() { | ||
expectType<"https://api.github.com">(endpoint.DEFAULTS.baseUrl); | ||
const myEndpoint = endpoint.withDefaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
}); | ||
myEndpoint.DEFAULTS; | ||
expectType<"https://github-enterprise.acme-inc.com/api/v3">( | ||
// @ts-expect-error - TODO: fix this | ||
myEndpoint.DEFAULTS.baseUrl | ||
); | ||
} | ||
export function apiMerge() { | ||
const myProjectEndpoint = endpoint.withDefaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
headers: { | ||
"user-agent": "myApp/1.2.3", | ||
}, | ||
org: "my-project", | ||
}); | ||
// @ts-expect-error - TODO: add types for endpoint.merge(). Compare https://github.com/octokit/types.ts/blob/7e5dd312188253e962fa209b16963f78113ba8c3/src/EndpointInterface.ts#L49-L88 | ||
const options = myProjectEndpoint.merge("GET /orgs/{org}/repos", { | ||
headers: { | ||
authorization: `token 0000000000000000000000000000000000000001`, | ||
}, | ||
org: "my-secret-project", | ||
type: "private", | ||
}); | ||
// expectType<{ | ||
// baseUrl: "https://github-enterprise.acme-inc.com/api/v3"; | ||
// method: "GET"; | ||
// url: "/orgs/{org}/repos"; | ||
// headers: { | ||
// accept: "application/vnd.github.v3+json"; | ||
// authorization: `token 0000000000000000000000000000000000000001`; | ||
// "user-agent": "myApp/1.2.3"; | ||
// }; | ||
// org: "my-secret-project"; | ||
// type: "private"; | ||
// }>(options); | ||
} | ||
export function apiParse() { | ||
// @ts-expect-error - TODO: add types for endpoint.parse(). Compare https://github.com/octokit/types.ts/blob/7e5dd312188253e962fa209b16963f78113ba8c3/src/EndpointInterface.ts#L90-L98 | ||
const requestOptions = endpoint.parse({ | ||
method: "GET", | ||
url: "/endpoint-test/{id}", | ||
id: "id", | ||
}); | ||
// expectType<"GET">(requestOptions.method); | ||
// expectType<string>(requestOptions.url); | ||
// expectNotType<"/endpoint-test/{id}">(requestOptions.url); | ||
} |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "1.14.0"; | ||
export const VERSION = "1.15.0"; |
{ | ||
"name": "@octokit-next/endpoint", | ||
"version": "1.14.0", | ||
"version": "1.15.0", | ||
"publishConfig": { | ||
@@ -30,3 +30,3 @@ "access": "public" | ||
"dependencies": { | ||
"@octokit-next/types": "1.14.0", | ||
"@octokit-next/types": "1.15.0", | ||
"is-plain-obj": "^4.0.0", | ||
@@ -33,0 +33,0 @@ "type-fest": "^2.3.4", |
@@ -17,3 +17,3 @@ # endpoint.js | ||
- [`endpoint(route, options)` or `endpoint(options)`](#endpointroute-options-or-endpointoptions) | ||
- [`endpoint.defaults()`](#endpointdefaults) | ||
- [`endpoint.withDefaults()`](#endpointdefaults) | ||
- [`endpoint.DEFAULTS`](#endpointdefaults) | ||
@@ -217,3 +217,3 @@ - [`endpoint.merge(route, options)` or `endpoint.merge(options)`](#endpointmergeroute-options-or-endpointmergeoptions) | ||
<td> | ||
Name of previews, such as <code>mercy</code>, <code>symmetra</code>, or <code>scarlet-witch</code>. See <a href="https://docs.github.com/rest/overview/api-previews">API Previews</a>. If <code>options.mediaType.previews</code> was set as default, the new previews will be merged into the default ones. Setting <code>options.mediaType.previews</code> will amend the <code>headers.accept</code> value. <code>options.mediaType.previews</code> will be merged with an existing array set using <code>.defaults()</code>. | ||
Name of previews, such as <code>mercy</code>, <code>symmetra</code>, or <code>scarlet-witch</code>. See <a href="https://docs.github.com/rest/overview/api-previews">API Previews</a>. If <code>options.mediaType.previews</code> was set as default, the new previews will be merged into the default ones. Setting <code>options.mediaType.previews</code> will amend the <code>headers.accept</code> value. <code>options.mediaType.previews</code> will be merged with an existing array set using <code>.withDefaults()</code>. | ||
</td> | ||
@@ -299,3 +299,3 @@ </tr> | ||
### `endpoint.defaults()` | ||
### `endpoint.withDefaults()` | ||
@@ -305,3 +305,3 @@ Override or set default options. Example: | ||
```js | ||
const myEndpoint = endpoint.defaults({ | ||
const myEndpoint = endpoint.withDefaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
@@ -329,6 +329,6 @@ headers: { | ||
You can call `.defaults()` again on the returned method, the defaults will cascade. | ||
You can call `.withDefaults()` again on the returned method, the defaults will cascade. | ||
```js | ||
const myEndpointWithToken2 = myEndpoint.defaults({ | ||
const myEndpointWithToken2 = myEndpoint.withDefaults({ | ||
headers: { | ||
@@ -339,3 +339,3 @@ authorization: `token 0000000000000000000000000000000000000002`, | ||
const options2 = myEndpoint(`GET /orgs/{org}/repos`, { | ||
const options2 = myEndpointWithToken2(`GET /orgs/{org}/repos`, { | ||
org: "my-project", | ||
@@ -361,3 +361,3 @@ per_page: 100, | ||
endpoint.DEFAULTS.baseUrl; // https://api.github.com | ||
const myEndpoint = endpoint.defaults({ | ||
const myEndpoint = endpoint.withDefaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
@@ -373,3 +373,3 @@ }); | ||
```js | ||
const myProjectEndpoint = endpoint.defaults({ | ||
const myProjectEndpoint = endpoint.withDefaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
@@ -422,3 +422,3 @@ headers: { | ||
endpoint(""); | ||
// Set cursor in the route argument and press `Ctrl + Enter` to get a type ahead for all 700+ REST API endpoints | ||
// Set cursor in the route argument and press `Ctrl + Space` to get a type ahead for all 700+ REST API endpoints | ||
@@ -443,3 +443,3 @@ const requestOptions = endpoint("GET /orgs/{org}/repos", { org: "octokit" }); | ||
}); | ||
// Set cursor in the route argument and press `Ctrl + Enter` to get a type ahead for all GHES 3.0 REST API endpoints | ||
// Set cursor in the route argument and press `Ctrl + Space` to get a type ahead for all GHES 3.0 REST API endpoints | ||
@@ -459,3 +459,3 @@ const requestOptions = endpoint("GET /admin/users/{username}", { | ||
The version can be set using `endpoint.defaults()` as well. You can override the version in each `endpoint()` call. | ||
The version can be set using `endpoint.withDefaults()` as well. You can override the version in each `endpoint()` call. | ||
@@ -467,3 +467,3 @@ ```js | ||
const ghes30endpoint = endpoint.defaults({ | ||
const ghes30endpoint = endpoint.withDefaults({ | ||
request: { | ||
@@ -475,3 +475,3 @@ version: "ghes-3.0", | ||
endpoint(""); | ||
// Set cursor in the route argument and press `Ctrl + Enter` to get a type ahead for all GHES 3.0 REST API endpoints | ||
// Set cursor in the route argument and press `Ctrl + Space` to get a type ahead for all GHES 3.0 REST API endpoints | ||
``` | ||
@@ -486,3 +486,3 @@ | ||
const ghes30endpoint = endpoint.defaults({ | ||
const ghes30endpoint = endpoint.withDefaults({ | ||
request: { | ||
@@ -494,3 +494,3 @@ version: "ghes-3.0", | ||
endpoint(""); | ||
// Set cursor in the route argument and press `Ctrl + Enter` to get a type ahead for all REST API endpoints | ||
// Set cursor in the route argument and press `Ctrl + Space` to get a type ahead for all REST API endpoints | ||
// that exist in both github.com and GitHub Enterprise Server 3.0 | ||
@@ -497,0 +497,0 @@ ``` |
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
55640
1248
+ Added@octokit-next/types@1.15.0(transitive)
- Removed@octokit-next/types@1.14.0(transitive)
Updated@octokit-next/types@1.15.0