blob: a700b0398b355dd22a88f379f34508bc69bfd929 [file] [log] [blame]
{"version":3,"file":"index.js","sources":["../dist-src/version.js","../dist-src/normalize-paginated-list-response.js","../dist-src/iterator.js","../dist-src/paginate.js","../dist-src/index.js"],"sourcesContent":["export const VERSION = \"1.1.2\";\n","/**\n * Some “list” response that can be paginated have a different response structure\n *\n * They have a `total_count` key in the response (search also has `incomplete_results`,\n * /installation/repositories also has `repository_selection`), as well as a key with\n * the list of the items which name varies from endpoint to endpoint:\n *\n * - https://developer.github.com/v3/search/#example (key `items`)\n * - https://developer.github.com/v3/checks/runs/#response-3 (key: `check_runs`)\n * - https://developer.github.com/v3/checks/suites/#response-1 (key: `check_suites`)\n * - https://developer.github.com/v3/apps/installations/#list-repositories (key: `repositories`)\n * - https://developer.github.com/v3/apps/installations/#list-installations-for-a-user (key `installations`)\n *\n * Octokit normalizes these responses so that paginated results are always returned following\n * the same structure. One challenge is that if the list response has only one page, no Link\n * header is provided, so this header alone is not sufficient to check wether a response is\n * paginated or not. For the exceptions with the namespace, a fallback check for the route\n * paths has to be added in order to normalize the response. We cannot check for the total_count\n * property because it also exists in the response of Get the combined status for a specific ref.\n */\nconst REGEX = [\n /^\\/search\\//,\n /^\\/repos\\/[^/]+\\/[^/]+\\/commits\\/[^/]+\\/(check-runs|check-suites)([^/]|$)/,\n /^\\/installation\\/repositories([^/]|$)/,\n /^\\/user\\/installations([^/]|$)/,\n /^\\/repos\\/[^/]+\\/[^/]+\\/actions\\/secrets([^/]|$)/,\n /^\\/repos\\/[^/]+\\/[^/]+\\/actions\\/workflows(\\/[^/]+\\/runs)?([^/]|$)/,\n /^\\/repos\\/[^/]+\\/[^/]+\\/actions\\/runs(\\/[^/]+\\/(artifacts|jobs))?([^/]|$)/\n];\nexport function normalizePaginatedListResponse(octokit, url, response) {\n const path = url.replace(octokit.request.endpoint.DEFAULTS.baseUrl, \"\");\n const responseNeedsNormalization = REGEX.find(regex => regex.test(path));\n if (!responseNeedsNormalization)\n return;\n // keep the additional properties intact as there is currently no other way\n // to retrieve the same information.\n const incompleteResults = response.data.incomplete_results;\n const repositorySelection = response.data.repository_selection;\n const totalCount = response.data.total_count;\n delete response.data.incomplete_results;\n delete response.data.repository_selection;\n delete response.data.total_count;\n const namespaceKey = Object.keys(response.data)[0];\n const data = response.data[namespaceKey];\n response.data = data;\n if (typeof incompleteResults !== \"undefined\") {\n response.data.incomplete_results = incompleteResults;\n }\n if (typeof repositorySelection !== \"undefined\") {\n response.data.repository_selection = repositorySelection;\n }\n response.data.total_count = totalCount;\n Object.defineProperty(response.data, namespaceKey, {\n get() {\n octokit.log.warn(`[@octokit/paginate-rest] \"response.data.${namespaceKey}\" is deprecated for \"GET ${path}\". Get the results directly from \"response.data\"`);\n return Array.from(data);\n }\n });\n}\n","import { normalizePaginatedListResponse } from \"./normalize-paginated-list-response\";\nexport function iterator(octokit, route, parameters) {\n const options = octokit.request.endpoint(route, parameters);\n const method = options.method;\n const headers = options.headers;\n let url = options.url;\n return {\n [Symbol.asyncIterator]: () => ({\n next() {\n if (!url) {\n return Promise.resolve({ done: true });\n }\n return octokit\n .request({ method, url, headers })\n .then((response) => {\n normalizePaginatedListResponse(octokit, url, response);\n // `response.headers.link` format:\n // '<https://api.github.com/users/aseemk/followers?page=2>; rel=\"next\", <https://api.github.com/users/aseemk/followers?page=2>; rel=\"last\"'\n // sets `url` to undefined if \"next\" URL is not present or `link` header is not set\n url = ((response.headers.link || \"\").match(/<([^>]+)>;\\s*rel=\"next\"/) || [])[1];\n return { value: response };\n });\n }\n })\n };\n}\n","import { iterator } from \"./iterator\";\nexport function paginate(octokit, route, parameters, mapFn) {\n if (typeof parameters === \"function\") {\n mapFn = parameters;\n parameters = undefined;\n }\n return gather(octokit, [], iterator(octokit, route, parameters)[Symbol.asyncIterator](), mapFn);\n}\nfunction gather(octokit, results, iterator, mapFn) {\n return iterator.next().then(result => {\n if (result.done) {\n return results;\n }\n let earlyExit = false;\n function done() {\n earlyExit = true;\n }\n results = results.concat(mapFn ? mapFn(result.value, done) : result.value.data);\n if (earlyExit) {\n return results;\n }\n return gather(octokit, results, iterator, mapFn);\n });\n}\n","import { VERSION } from \"./version\";\nimport { paginate } from \"./paginate\";\nimport { iterator } from \"./iterator\";\n/**\n * @param octokit Octokit instance\n * @param options Options passed to Octokit constructor\n */\nexport function paginateRest(octokit) {\n return {\n paginate: Object.assign(paginate.bind(null, octokit), {\n iterator: iterator.bind(null, octokit)\n })\n };\n}\npaginateRest.VERSION = VERSION;\n"],"names":[],"mappings":"AAAO,MAAM,OAAO,GAAG,mBAAmB,CAAC;;ACA3C;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,KAAK,GAAG;IACV,aAAa;IACb,2EAA2E;IAC3E,uCAAuC;IACvC,gCAAgC;IAChC,kDAAkD;IAClD,oEAAoE;IACpE,2EAA2E;CAC9E,CAAC;AACF,AAAO,SAAS,8BAA8B,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE;IACnE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACxE,MAAM,0BAA0B,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC,0BAA0B;QAC3B,OAAO;;;IAGX,MAAM,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC;IAC3D,MAAM,mBAAmB,GAAG,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC;IAC/D,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC;IAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC;IACxC,OAAO,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC;IAC1C,OAAO,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC;IAC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