diff --git a/src/index.ts b/src/index.ts index 368726766..06b0546c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,8 +9,16 @@ import { endpointsToMethods } from "./endpoints-to-methods"; export function restEndpointMethods(octokit: Octokit): Api { const api = endpointsToMethods(octokit, ENDPOINTS); return { - ...api, rest: api, }; } restEndpointMethods.VERSION = VERSION; + +export function legacyRestEndpointMethods(octokit: Octokit): Api["rest"] & Api { + const api = endpointsToMethods(octokit, ENDPOINTS); + return { + ...api, + rest: api, + }; +} +legacyRestEndpointMethods.VERSION = VERSION; diff --git a/src/types.ts b/src/types.ts index 4a511e6a5..a2a596ec9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,9 +2,7 @@ import { Route, RequestParameters } from "@octokit/types"; import { RestEndpointMethods } from "./generated/method-types"; -export type Api = RestEndpointMethods & { - rest: RestEndpointMethods; -}; +export type Api = { rest: RestEndpointMethods }; export type EndpointDecorations = { mapToData?: string; diff --git a/test/rest-endpoint-methods.test.ts b/test/rest-endpoint-methods.test.ts index 476c6dc8e..bd8d2da0f 100644 --- a/test/rest-endpoint-methods.test.ts +++ b/test/rest-endpoint-methods.test.ts @@ -1,7 +1,7 @@ import fetchMock from "fetch-mock"; import { Octokit } from "@octokit/core"; -import { restEndpointMethods } from "../src"; +import { restEndpointMethods, legacyRestEndpointMethods } from "../src"; describe("REST API endpoint methods", () => { it("README example", async () => { @@ -179,11 +179,11 @@ describe("REST API endpoint methods", () => { return octokit.rest.apps.listInstallations(); }); - // besides setting `octokit.rest.*`, the plugin is also setting the same methods - // directly on `octokit.*` for legacy reasons. We will deprecate the `octokit.*` - // methods in future, but for now we just make sure they are set + // besides setting `octokit.rest.*`, the plugin exports legacyRestEndpointMethods + // which is also setting the same methods directly on `octokit.*` for legacy reasons. + // We will deprecate the `octokit.*` methods in future, but for now we just make sure they are set - it("octokit.repos.createForAuthenticatedUser()", async () => { + it("legacyRestEndpointMethods", async () => { const mock = fetchMock.sandbox().post( "path:/user/repos", { id: 1 }, @@ -194,7 +194,7 @@ describe("REST API endpoint methods", () => { } ); - const MyOctokit = Octokit.plugin(restEndpointMethods); + const MyOctokit = Octokit.plugin(legacyRestEndpointMethods); const octokit = new MyOctokit({ auth: "secret123", request: { @@ -203,10 +203,14 @@ describe("REST API endpoint methods", () => { }); // See https://developer.github.com/v3/repos/#create - const { data } = await octokit.repos.createForAuthenticatedUser({ + const response1 = await octokit.repos.createForAuthenticatedUser({ + name: "my-new-repo", + }); + const response2 = await octokit.rest.repos.createForAuthenticatedUser({ name: "my-new-repo", }); - expect(data.id).toStrictEqual(1); + expect(response1.data.id).toStrictEqual(1); + expect(response2.data.id).toStrictEqual(1); }); });