Skip to content

Commit

Permalink
feat: paginate map function can read response.data[namespaceKey] fo…
Browse files Browse the repository at this point in the history
…r name spaced endpoints
  • Loading branch information
gr2m committed Jan 26, 2020
1 parent 1c3e4e4 commit e7cc38d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/normalize-paginated-list-response.ts
Expand Up @@ -56,8 +56,8 @@ export function normalizePaginatedListResponse(
delete response.data.total_count;

const namespaceKey = Object.keys(response.data)[0];

response.data = response.data[namespaceKey];
const data = response.data[namespaceKey];
response.data = data;

if (typeof incompleteResults !== "undefined") {
response.data.incomplete_results = incompleteResults;
Expand All @@ -68,4 +68,13 @@ export function normalizePaginatedListResponse(
}

response.data.total_count = totalCount;

Object.defineProperty(response.data, namespaceKey, {
get() {
octokit.log.warn(
`[@octokit/paginate-rest] "response.data.${namespaceKey}" is deprecated for "GET ${path}". Get the results directly from "response.data"`
);
return Array.from(data);
}
});
}

0 comments on commit e7cc38d

Please sign in to comment.