@octokit/plugin-paginate-rest
Advanced tools
Comparing version 2.13.4 to 2.13.5
@@ -5,4 +5,57 @@ 'use strict'; | ||
const VERSION = "2.13.4"; | ||
const VERSION = "2.13.5"; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
/** | ||
@@ -25,2 +78,9 @@ * Some “list” response that can be paginated have a different response structure | ||
function normalizePaginatedListResponse(response) { | ||
// endpoints can respond with 204 if repository is empty | ||
if (!response.data) { | ||
return _objectSpread2(_objectSpread2({}, response), {}, { | ||
data: [] | ||
}); | ||
} | ||
const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data); | ||
@@ -64,15 +124,28 @@ if (!responseNeedsNormalization) return response; // keep the additional properties intact as there is currently no other way | ||
}; | ||
const response = await requestMethod({ | ||
method, | ||
url, | ||
headers | ||
}); | ||
const normalizedResponse = normalizePaginatedListResponse(response); // `response.headers.link` format: | ||
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"' | ||
// sets `url` to undefined if "next" URL is not present or `link` header is not set | ||
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1]; | ||
return { | ||
value: normalizedResponse | ||
}; | ||
try { | ||
const response = await requestMethod({ | ||
method, | ||
url, | ||
headers | ||
}); | ||
const normalizedResponse = normalizePaginatedListResponse(response); // `response.headers.link` format: | ||
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"' | ||
// sets `url` to undefined if "next" URL is not present or `link` header is not set | ||
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1]; | ||
return { | ||
value: normalizedResponse | ||
}; | ||
} catch (error) { | ||
if (error.status !== 409) throw error; | ||
url = ""; | ||
return { | ||
value: { | ||
status: 200, | ||
headers: {}, | ||
data: [] | ||
} | ||
}; | ||
} | ||
} | ||
@@ -79,0 +152,0 @@ |
@@ -15,9 +15,23 @@ import { normalizePaginatedListResponse } from "./normalize-paginated-list-response"; | ||
return { done: true }; | ||
const response = await requestMethod({ method, url, headers }); | ||
const normalizedResponse = normalizePaginatedListResponse(response); | ||
// `response.headers.link` format: | ||
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"' | ||
// sets `url` to undefined if "next" URL is not present or `link` header is not set | ||
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1]; | ||
return { value: normalizedResponse }; | ||
try { | ||
const response = await requestMethod({ method, url, headers }); | ||
const normalizedResponse = normalizePaginatedListResponse(response); | ||
// `response.headers.link` format: | ||
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"' | ||
// sets `url` to undefined if "next" URL is not present or `link` header is not set | ||
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1]; | ||
return { value: normalizedResponse }; | ||
} | ||
catch (error) { | ||
if (error.status !== 409) | ||
throw error; | ||
url = ""; | ||
return { | ||
value: { | ||
status: 200, | ||
headers: {}, | ||
data: [], | ||
}, | ||
}; | ||
} | ||
}, | ||
@@ -24,0 +38,0 @@ }), |
@@ -18,2 +18,9 @@ /** | ||
export function normalizePaginatedListResponse(response) { | ||
// endpoints can respond with 204 if repository is empty | ||
if (!response.data) { | ||
return { | ||
...response, | ||
data: [], | ||
}; | ||
} | ||
const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data); | ||
@@ -20,0 +27,0 @@ if (!responseNeedsNormalization) |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "2.13.4"; | ||
export const VERSION = "2.13.5"; |
@@ -11,4 +11,11 @@ import { Octokit } from "@octokit/core"; | ||
done?: undefined; | ||
} | { | ||
value: { | ||
status: number; | ||
headers: {}; | ||
data: never[]; | ||
}; | ||
done?: undefined; | ||
}>; | ||
}; | ||
}; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "2.13.4"; | ||
export declare const VERSION = "2.13.5"; |
@@ -1,2 +0,2 @@ | ||
const VERSION = "2.13.4"; | ||
const VERSION = "2.13.5"; | ||
@@ -20,2 +20,9 @@ /** | ||
function normalizePaginatedListResponse(response) { | ||
// endpoints can respond with 204 if repository is empty | ||
if (!response.data) { | ||
return { | ||
...response, | ||
data: [], | ||
}; | ||
} | ||
const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data); | ||
@@ -58,9 +65,23 @@ if (!responseNeedsNormalization) | ||
return { done: true }; | ||
const response = await requestMethod({ method, url, headers }); | ||
const normalizedResponse = normalizePaginatedListResponse(response); | ||
// `response.headers.link` format: | ||
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"' | ||
// sets `url` to undefined if "next" URL is not present or `link` header is not set | ||
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1]; | ||
return { value: normalizedResponse }; | ||
try { | ||
const response = await requestMethod({ method, url, headers }); | ||
const normalizedResponse = normalizePaginatedListResponse(response); | ||
// `response.headers.link` format: | ||
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"' | ||
// sets `url` to undefined if "next" URL is not present or `link` header is not set | ||
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1]; | ||
return { value: normalizedResponse }; | ||
} | ||
catch (error) { | ||
if (error.status !== 409) | ||
throw error; | ||
url = ""; | ||
return { | ||
value: { | ||
status: 200, | ||
headers: {}, | ||
data: [], | ||
}, | ||
}; | ||
} | ||
}, | ||
@@ -67,0 +88,0 @@ }), |
{ | ||
"name": "@octokit/plugin-paginate-rest", | ||
"description": "Octokit plugin to paginate REST API endpoint responses", | ||
"version": "2.13.4", | ||
"version": "2.13.5", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
188957
2588