@octokit/plugin-rest-endpoint-methods
Advanced tools
Comparing version 7.2.2 to 7.2.3
@@ -1,28 +0,50 @@ | ||
function endpointsToMethods(octokit, endpointsMap) { | ||
const newMethods = {}; | ||
for (const [scope, endpoints] of Object.entries(endpointsMap)) { | ||
for (const [methodName, endpoint] of Object.entries(endpoints)) { | ||
const [route, defaults, decorations] = endpoint; | ||
const [method, url] = route.split(/ /); | ||
const endpointDefaults = Object.assign( | ||
{ method, url }, | ||
defaults | ||
import ENDPOINTS from "./generated/endpoints"; | ||
const endpointMethodsMap = /* @__PURE__ */ new Map(); | ||
for (const [scope, endpoints] of Object.entries(ENDPOINTS)) { | ||
for (const [methodName, endpoint] of Object.entries(endpoints)) { | ||
const [route, defaults, decorations] = endpoint; | ||
const [method, url] = route.split(/ /); | ||
const endpointDefaults = Object.assign( | ||
{ | ||
method, | ||
url | ||
}, | ||
defaults | ||
); | ||
if (!endpointMethodsMap.has(scope)) { | ||
endpointMethodsMap.set(scope, /* @__PURE__ */ new Map()); | ||
} | ||
endpointMethodsMap.get(scope).set(methodName, { | ||
scope, | ||
methodName, | ||
endpointDefaults, | ||
decorations | ||
}); | ||
} | ||
} | ||
const handler = { | ||
get({ octokit, scope, cache }, methodName) { | ||
if (cache[methodName]) { | ||
return cache[methodName]; | ||
} | ||
const { decorations, endpointDefaults } = endpointMethodsMap.get(scope).get(methodName); | ||
if (decorations) { | ||
cache[methodName] = decorate( | ||
octokit, | ||
scope, | ||
methodName, | ||
endpointDefaults, | ||
decorations | ||
); | ||
if (!newMethods[scope]) { | ||
newMethods[scope] = {}; | ||
} | ||
const scopeMethods = newMethods[scope]; | ||
if (decorations) { | ||
scopeMethods[methodName] = decorate( | ||
octokit, | ||
scope, | ||
methodName, | ||
endpointDefaults, | ||
decorations | ||
); | ||
continue; | ||
} | ||
scopeMethods[methodName] = octokit.request.defaults(endpointDefaults); | ||
} else { | ||
cache[methodName] = octokit.request.defaults(endpointDefaults); | ||
} | ||
return cache[methodName]; | ||
} | ||
}; | ||
function endpointsToMethods(octokit) { | ||
const newMethods = {}; | ||
for (const scope of endpointMethodsMap.keys()) { | ||
newMethods[scope] = new Proxy({ octokit, scope, cache: {} }, handler); | ||
} | ||
return newMethods; | ||
@@ -29,0 +51,0 @@ } |
@@ -1,6 +0,5 @@ | ||
import ENDPOINTS from "./generated/endpoints"; | ||
import { VERSION } from "./version"; | ||
import { endpointsToMethods } from "./endpoints-to-methods"; | ||
function restEndpointMethods(octokit) { | ||
const api = endpointsToMethods(octokit, ENDPOINTS); | ||
const api = endpointsToMethods(octokit); | ||
return { | ||
@@ -12,3 +11,3 @@ rest: api | ||
function legacyRestEndpointMethods(octokit) { | ||
const api = endpointsToMethods(octokit, ENDPOINTS); | ||
const api = endpointsToMethods(octokit); | ||
return { | ||
@@ -15,0 +14,0 @@ ...api, |
@@ -1,4 +0,4 @@ | ||
const VERSION = "7.2.2"; | ||
const VERSION = "7.2.3"; | ||
export { | ||
VERSION | ||
}; |
import type { Octokit } from "@octokit/core"; | ||
import type { EndpointsDefaultsAndDecorations } from "./types"; | ||
import type { RestEndpointMethods } from "./generated/method-types"; | ||
export declare function endpointsToMethods(octokit: Octokit, endpointsMap: EndpointsDefaultsAndDecorations): RestEndpointMethods; | ||
export declare function endpointsToMethods(octokit: Octokit): RestEndpointMethods; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "7.2.2"; | ||
export declare const VERSION = "7.2.3"; |
{ | ||
"name": "@octokit/plugin-rest-endpoint-methods", | ||
"version": "7.2.2", | ||
"version": "7.2.3", | ||
"description": "Octokit plugin adding one method for all of api.github.com REST API endpoints", | ||
@@ -5,0 +5,0 @@ "repository": "github:octokit/plugin-rest-endpoint-methods.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
1501125
21322