WIP: initial prototype

- Added options parameter in API methods
- Updated typings
This commit is contained in:
delvedor
2018-12-12 16:47:29 +01:00
parent 7c1b58d703
commit b91b1ad1de
4 changed files with 413 additions and 391 deletions

View File

@ -33,8 +33,13 @@ class Transport {
}
}
request (params, callback) {
request (params, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
callback = once(callback)
// TODO: return in the result the metadata
const meta = {
connection: null,
request: null,
@ -48,7 +53,7 @@ class Transport {
headers: null,
warnings: null
}
const maxRetries = params.maxRetries || this.maxRetries
const maxRetries = options.maxRetries || this.maxRetries
var request = { abort: noop }
const makeRequest = () => {
@ -96,11 +101,12 @@ class Transport {
// serializes the querystring
params.querystring = this.serializer.qserialize(params.querystring)
// handles request timeout
params.timeout = toMs(params.requestTimeout || this.requestTimeout)
params.timeout = toMs(options.requestTimeout || this.requestTimeout)
meta.request = params
this.emit('request', null, meta)
if (options.asStream === true) params.asStream = true
// perform the actual http request
return meta.connection.request(params, onResponse)
}
@ -139,7 +145,7 @@ class Transport {
result.warnings = headers['warning'].split(/(?!\B"[^"]*),(?![^"]*"\B)/)
}
if (params.asStream === true) {
if (options.asStream === true) {
result.body = response
meta.response = result
this.emit('response', null, meta)
@ -180,7 +186,7 @@ class Transport {
// we should ignore the statusCode if the user has configured the `ignore` field with
// the statusCode we just got or if the request method is HEAD and the statusCode is 404
const ignoreStatusCode = (Array.isArray(params.ignore) && params.ignore.indexOf(statusCode) > -1) ||
const ignoreStatusCode = (Array.isArray(options.ignore) && options.ignore.indexOf(statusCode) > -1) ||
(isHead === true && statusCode === 404)
if (ignoreStatusCode === false &&