Comparing version 3.3.2 to 3.3.3
@@ -10,2 +10,4 @@ "use strict"; | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _humps = _interopRequireDefault(require("humps")); | ||
@@ -62,27 +64,36 @@ | ||
async function getPaginated(service, endpoint, options = {}) { | ||
const requestOptions = defaultRequest(service, endpoint, { | ||
headers: service.headers, | ||
qs: options, | ||
resolveWithFullResponse: true | ||
}); | ||
const response = await service.requester.get(requestOptions); | ||
const links = (0, _parseLinkHeader.default)(response.headers.link); | ||
const page = response.headers['x-page']; | ||
const underMaxPageLimit = options.maxPages ? page < options.maxPages : true; // If not looking for a singular page and still under the max pages limit AND their is a next page, paginate | ||
function getPaginated(_x, _x2) { | ||
return _getPaginated.apply(this, arguments); | ||
} | ||
if (!options.page && underMaxPageLimit && links.next) { | ||
const more = await getPaginated(service, links.next.url.replace(service.url, ''), options); | ||
return [...response.body, ...more]; | ||
} | ||
function _getPaginated() { | ||
_getPaginated = (0, _asyncToGenerator2.default)(function* (service, endpoint, options = {}) { | ||
const requestOptions = defaultRequest(service, endpoint, { | ||
headers: service.headers, | ||
qs: options, | ||
resolveWithFullResponse: true | ||
}); | ||
const response = yield service.requester.get(requestOptions); | ||
const links = (0, _parseLinkHeader.default)(response.headers.link); | ||
const page = response.headers['x-page']; | ||
const underMaxPageLimit = options.maxPages ? page < options.maxPages : true; // If not looking for a singular page and still under the max pages limit AND their is a next page, paginate | ||
return response.body; | ||
if (!options.page && underMaxPageLimit && links.next) { | ||
const more = yield getPaginated(service, links.next.url.replace(service.url, ''), options); | ||
return [...response.body, ...more]; | ||
} | ||
return response.body; | ||
}); | ||
return _getPaginated.apply(this, arguments); | ||
} | ||
class RequestHelper { | ||
static async get(service, endpoint, options = {}, { | ||
static get(service, endpoint, options = {}, { | ||
stream = false | ||
} = {}) { | ||
if (stream) return getStream(service, endpoint, options); | ||
return getPaginated(service, endpoint, options); | ||
return (0, _asyncToGenerator2.default)(function* () { | ||
if (stream) return getStream(service, endpoint, options); | ||
return getPaginated(service, endpoint, options); | ||
})(); | ||
} | ||
@@ -89,0 +100,0 @@ |
@@ -10,2 +10,4 @@ "use strict"; | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _errors = require("request-promise-core/errors"); | ||
@@ -19,11 +21,20 @@ | ||
const promisifiedFn = (0, _util.default)(fn); | ||
return async function (opts) { | ||
const response = await promisifiedFn(opts); | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = (0, _asyncToGenerator2.default)(function* (opts) { | ||
const response = yield promisifiedFn(opts); | ||
if (response.statusCode >= 400 && response.statusCode <= 599) { | ||
throw new _errors.StatusCodeError(response.statusCode, response.body, {}, null); | ||
} | ||
if (response.statusCode >= 400 && response.statusCode <= 599) { | ||
throw new _errors.StatusCodeError(response.statusCode, response.body, {}, null); | ||
} | ||
return opts.resolveWithFullResponse ? response : response.body; | ||
}; | ||
return opts.resolveWithFullResponse ? response : response.body; | ||
}); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}() | ||
); | ||
} | ||
@@ -30,0 +41,0 @@ |
{ | ||
"name": "gitlab", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"description": "Full NodeJS implementation of the GitLab API. Supports Promises, Async/Await.", | ||
@@ -35,2 +35,3 @@ "main": "dist/latest/index.js", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0-beta.46", | ||
"@babel/plugin-transform-async-to-generator": "^7.0.0-beta.46", | ||
"@babel/plugin-transform-runtime": "^7.0.0-beta.46", | ||
@@ -37,0 +38,0 @@ "@babel/preset-env": "^7.0.0-beta.46", |
@@ -5,3 +5,3 @@ [![dependencies Status](https://david-dm.org/jdalrymple/node-gitlab/status.svg)](https://david-dm.org/jdalrymple/node-gitlab)[![devDependencies Status](https://david-dm.org/jdalrymple/node-gitlab/dev-status.svg)](https://david-dm.org/jdalrymple/node-gitlab?type=dev)[![Code Climate](https://codeclimate.com/github/jdalrymple/node-gitlab/badges/gpa.svg)](https://codeclimate.com/github/jdalrymple/node-gitlab)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![NPM](https://nodei.co/npm/node-gitlab.png?downloads=true&stars=true)](https://nodei.co/npm/node-gitlab/) | ||
[![NPM](https://nodei.co/npm/node-gitlab.png?downloads=true&stars=true)](https://nodei.co/npm/gitlab/) | ||
@@ -389,2 +389,6 @@ # node-gitlab | ||
[3.3.3](https://github.com/jdalrymple/node-gitlab/tags/3.3.3) (2018-5-13) | ||
------------------ | ||
- Fixing #84 | ||
[3.3.2](https://github.com/jdalrymple/node-gitlab/tags/3.3.2) (2018-5-9) | ||
@@ -391,0 +395,0 @@ ------------------ |
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
372539
8847
728
13