rqlite-js 2.5.4 → 2.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es6/http-request/content-types.js +1 -1
- package/es6/http-request/index.js +40 -6
- package/lib/api/backup/index.js +11 -10
- package/lib/api/backup/index.js.map +1 -1
- package/lib/api/client/index.js +10 -9
- package/lib/api/client/index.js.map +1 -1
- package/lib/api/data/index.js +9 -8
- package/lib/api/data/index.js.map +1 -1
- package/lib/api/results/data-result-error.js +2 -1
- package/lib/api/results/data-result-error.js.map +1 -1
- package/lib/api/results/data-result.js +42 -41
- package/lib/api/results/data-result.js.map +1 -1
- package/lib/api/results/data-results.js +20 -19
- package/lib/api/results/data-results.js.map +1 -1
- package/lib/api/results/index.js.map +1 -1
- package/lib/api/status/index.js +6 -5
- package/lib/api/status/index.js.map +1 -1
- package/lib/http-request/content-types.js +2 -2
- package/lib/http-request/content-types.js.map +1 -1
- package/lib/http-request/errors.js +2 -1
- package/lib/http-request/errors.js.map +1 -1
- package/lib/http-request/http-methods.js.map +1 -1
- package/lib/http-request/index.js +158 -123
- package/lib/http-request/index.js.map +1 -1
- package/lib/http-request/retryable.js +5 -4
- package/lib/http-request/retryable.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/package.json +17 -17
- package/CHANGELOG.md +0 -320
package/lib/api/status/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var _client = _interopRequireDefault(require("../client"));function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var _client = _interopRequireDefault(require("../client"));function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);enumerableOnly && (symbols = symbols.filter(function (sym) {return Object.getOwnPropertyDescriptor(object, sym).enumerable;})), keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = null != arguments[i] ? arguments[i] : {};i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {(0, _defineProperty2.default)(target, key, source[key]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));});}return target;} /**
|
|
6
|
+
* Status api client to perform RQLite status and diagnostics operations
|
|
7
|
+
* @module api/status
|
|
8
|
+
*/ /**
|
|
8
9
|
* @typedef {Object} HttpResponse
|
|
9
10
|
* @property {Object} Body The HTTP response body parsed by JSON.parse()
|
|
10
11
|
* @property {Number} statusCode The HTTP response code
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
/**
|
|
14
14
|
* @typedef {Object} StatusAllHostsResponse
|
|
15
15
|
* @property {HttpResponse} response An HTTP response
|
|
@@ -50,5 +50,6 @@ class StatusApiClient extends _client.default {
|
|
|
50
50
|
return { response, host: hosts[activeHostIndex] };
|
|
51
51
|
});return function (_x, _x2) {return _ref.apply(this, arguments);};}());
|
|
52
52
|
return Promise.all(promises);})();
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
|
+
}exports.default = StatusApiClient;
|
|
54
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_client","_interopRequireDefault","require","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","PATH_STATUS","exports","StatusApiClient","ApiClient","status","options","_superprop_getGet","get","_this","_asyncToGenerator2","call","useLeader","statusAllHosts","_this2","hosts","getHosts","promises","map","_ref","_host","activeHostIndex","response","host","_x","_x2","Promise","all"],"sources":["../../../es6/api/status/index.js"],"sourcesContent":["/**\n * Status api client to perform RQLite status and diagnostics operations\n * @module api/status\n */\nimport ApiClient from '../client'\n\n/**\n * @typedef {Object} HttpResponse\n * @property {Object} Body The HTTP response body parsed by JSON.parse()\n * @property {Number} statusCode The HTTP response code\n */\n\n/**\n * @typedef {Object} StatusAllHostsResponse\n * @property {HttpResponse} response An HTTP response\n * @property {String} host The host name\n */\n\n/**\n * The RQLite status api path\n */\nexport const PATH_STATUS = '/status'\n\n/**\n * Data api client to perform RQLite queries\n */\nexport default class StatusApiClient extends ApiClient {\n /**\n * Get the RQLite server status which defaults to the master host\n * @param {Object} [options={}] RQLite api options\n * @returns {HttpResponse} An HTTP response object\n */\n async status (options = {}) {\n return super.get(PATH_STATUS, { useLeader: true, ...options })\n }\n\n /**\n * Get the RQLite server status for all hosts as an array of object with\n * the host and their status\n * @param {Object} [options={}] RQLite api options\n * @param {Object} [options.raw] If true return the raw http response from\n * RQLite response\n * @returns {StatusAllHostsResponse[]} An array of http response for the provide hosts\n */\n async statusAllHosts (options = {}) {\n const hosts = this.getHosts()\n // Get the status for all of the hosts\n const promises = hosts.map(async (_host, activeHostIndex) => {\n const response = await this.status({ ...options, activeHostIndex })\n return { response, host: hosts[activeHostIndex] }\n })\n return Promise.all(promises)\n }\n}\n"],"mappings":";;;;AAIA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA,eAAiC,SAAAC,QAAAC,MAAA,EAAAC,cAAA,OAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,MAAAG,MAAA,CAAAC,qBAAA,OAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,EAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,UAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,MAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,UAAAH,IAAA,WAAAU,cAAAC,MAAA,YAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,SAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,OAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,OAAAC,gBAAA,CAAAC,OAAA,EAAAR,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,QAAAhB,MAAA,CAAAmB,yBAAA,GAAAnB,MAAA,CAAAoB,gBAAA,CAAAV,MAAA,EAAAV,MAAA,CAAAmB,yBAAA,CAAAL,MAAA,KAAAlB,OAAA,CAAAI,MAAA,CAAAc,MAAA,GAAAC,OAAA,WAAAC,GAAA,GAAAhB,MAAA,CAAAqB,cAAA,CAAAX,MAAA,EAAAM,GAAA,EAAAhB,MAAA,CAAAK,wBAAA,CAAAS,MAAA,EAAAE,GAAA,cAAAN,MAAA,GAJjC;AACA;AACA;AACA,GAHA,CAMA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMY,WAAW,GAAG,SAAS;;AAEpC;AACA;AACA,GAFAC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AAGe,MAAME,eAAe,SAASC,eAAS,CAAC;EACrD;AACF;AACA;AACA;AACA;EACQC,MAAMA,CAAEC,OAAO,GAAG,CAAC,CAAC,EAAE,KAAAC,iBAAA,GAAAA,CAAA,WAAAC,GAAA,CAAAC,KAAA,mBAAAC,kBAAA,CAAAb,OAAA;MAC1B,OAAOU,iBAAA,GAAAI,IAAA,CAAAF,KAAA,EAAUR,WAAW,EAAAb,aAAA,GAAIwB,SAAS,EAAE,IAAI,IAAKN,OAAO,CAAE,CAAC;EAChE;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACQO,cAAcA,CAAEP,OAAO,GAAG,CAAC,CAAC,EAAE,KAAAQ,MAAA,mBAAAJ,kBAAA,CAAAb,OAAA;MAClC,MAAMkB,KAAK,GAAGD,MAAI,CAACE,QAAQ,CAAC,CAAC;MAC7B;MACA,MAAMC,QAAQ,GAAGF,KAAK,CAACG,GAAG,gCAAAC,IAAA,OAAAT,kBAAA,CAAAb,OAAA,EAAC,WAAOuB,KAAK,EAAEC,eAAe,EAAK;UAC3D,MAAMC,QAAQ,SAASR,MAAI,CAACT,MAAM,CAAAjB,aAAA,CAAAA,aAAA,KAAMkB,OAAO,SAAEe,eAAe,GAAE,CAAC;UACnE,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAER,KAAK,CAACM,eAAe,CAAC,CAAC,CAAC;QACnD,CAAC,mBAAAG,EAAA,EAAAC,GAAA,UAAAN,IAAA,CAAAhC,KAAA,OAAAI,SAAA,QAAC;MACF,OAAOmC,OAAO,CAACC,GAAG,CAACV,QAAQ,CAAC;EAC9B;AACF,CAACf,OAAA,CAAAL,OAAA,GAAAM,eAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.
|
|
2
|
-
const CONTENT_TYPE_APPLICATION_JSON = 'application/json
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.CONTENT_TYPE_TEXT_PLAIN = exports.CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED = exports.CONTENT_TYPE_APPLICATION_OCTET_STREAM = exports.CONTENT_TYPE_APPLICATION_JSON = void 0;const CONTENT_TYPE_TEXT_PLAIN = 'text/plain';exports.CONTENT_TYPE_TEXT_PLAIN = CONTENT_TYPE_TEXT_PLAIN;
|
|
2
|
+
const CONTENT_TYPE_APPLICATION_JSON = 'application/json';exports.CONTENT_TYPE_APPLICATION_JSON = CONTENT_TYPE_APPLICATION_JSON;
|
|
3
3
|
const CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded';exports.CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED = CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED;
|
|
4
4
|
const CONTENT_TYPE_APPLICATION_OCTET_STREAM = 'application/octet-stream';exports.CONTENT_TYPE_APPLICATION_OCTET_STREAM = CONTENT_TYPE_APPLICATION_OCTET_STREAM;
|
|
5
5
|
//# sourceMappingURL=content-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"content-types.js","names":["CONTENT_TYPE_TEXT_PLAIN","exports","CONTENT_TYPE_APPLICATION_JSON","CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED","CONTENT_TYPE_APPLICATION_OCTET_STREAM"],"sources":["../../es6/http-request/content-types.js"],"sourcesContent":["export const CONTENT_TYPE_TEXT_PLAIN = 'text/plain'\nexport const CONTENT_TYPE_APPLICATION_JSON = 'application/json'\nexport const CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded'\nexport const CONTENT_TYPE_APPLICATION_OCTET_STREAM = 'application/octet-stream'\n"],"mappings":"qQAAO,MAAMA,uBAAuB,GAAG,YAAY,CAAAC,OAAA,CAAAD,uBAAA,GAAAA,uBAAA;AAC5C,MAAME,6BAA6B,GAAG,kBAAkB,CAAAD,OAAA,CAAAC,6BAAA,GAAAA,6BAAA;AACxD,MAAMC,8CAA8C,GAAG,mCAAmC,CAAAF,OAAA,CAAAE,8CAAA,GAAAA,8CAAA;AAC1F,MAAMC,qCAAqC,GAAG,0BAA0B,CAAAH,OAAA,CAAAG,qCAAA,GAAAA,qCAAA"}
|
|
@@ -12,5 +12,6 @@ class ERROR_HTTP_REQUEST_MAX_REDIRECTS extends Error {
|
|
|
12
12
|
super(...args);
|
|
13
13
|
this.name = this.constructor.name;
|
|
14
14
|
this.code = this.constructor.name;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
}exports.ERROR_HTTP_REQUEST_MAX_REDIRECTS = ERROR_HTTP_REQUEST_MAX_REDIRECTS;
|
|
16
17
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"errors.js","names":["ERROR_HTTP_REQUEST_MAX_REDIRECTS","Error","constructor","args","name","code","exports"],"sources":["../../es6/http-request/errors.js"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\n/**\n * Http request errors\n * @module http-request/errors\n */\n\n/**\n * Error when max rediret attempts have been reached\n */\nexport class ERROR_HTTP_REQUEST_MAX_REDIRECTS extends Error {\n constructor (...args) {\n super(...args)\n this.name = this.constructor.name\n this.code = this.constructor.name\n }\n}\n"],"mappings":"8HAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMA,gCAAgC,SAASC,KAAK,CAAC;EAC1DC,WAAWA,CAAE,GAAGC,IAAI,EAAE;IACpB,KAAK,CAAC,GAAGA,IAAI,CAAC;IACd,IAAI,CAACC,IAAI,GAAG,IAAI,CAACF,WAAW,CAACE,IAAI;IACjC,IAAI,CAACC,IAAI,GAAG,IAAI,CAACH,WAAW,CAACE,IAAI;EACnC;AACF,CAACE,OAAA,CAAAN,gCAAA,GAAAA,gCAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"http-methods.js","names":["HTTP_METHOD_DELETE","exports","HTTP_METHOD_GET","HTTP_METHOD_HEAD","HTTP_METHOD_OPTIONS","HTTP_METHOD_PATCH","HTTP_METHOD_POST","HTTP_METHOD_PUT"],"sources":["../../es6/http-request/http-methods.js"],"sourcesContent":["/**\n * Http methods\n * @module http-request/http-methods\n */\n\n/**\n * Http DELETE method\n */\nexport const HTTP_METHOD_DELETE = 'DELETE'\n\n/**\n * Http GET method\n */\nexport const HTTP_METHOD_GET = 'GET'\n\n/**\n * Http HEAD method\n */\nexport const HTTP_METHOD_HEAD = 'HEAD'\n\n/**\n * Http OPTIONS method\n */\nexport const HTTP_METHOD_OPTIONS = 'OPTIONS'\n\n/**\n * Http PATCH method\n */\nexport const HTTP_METHOD_PATCH = 'PATCH'\n\n/**\n * Http POST method\n */\nexport const HTTP_METHOD_POST = 'POST'\n\n/**\n * Http PUT method\n */\nexport const HTTP_METHOD_PUT = 'PUT'\n"],"mappings":"oRAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,QAAQ;;AAE1C;AACA;AACA,GAFAC,OAAA,CAAAD,kBAAA,GAAAA,kBAAA;AAGO,MAAME,eAAe,GAAG,KAAK;;AAEpC;AACA;AACA,GAFAD,OAAA,CAAAC,eAAA,GAAAA,eAAA;AAGO,MAAMC,gBAAgB,GAAG,MAAM;;AAEtC;AACA;AACA,GAFAF,OAAA,CAAAE,gBAAA,GAAAA,gBAAA;AAGO,MAAMC,mBAAmB,GAAG,SAAS;;AAE5C;AACA;AACA,GAFAH,OAAA,CAAAG,mBAAA,GAAAA,mBAAA;AAGO,MAAMC,iBAAiB,GAAG,OAAO;;AAExC;AACA;AACA,GAFAJ,OAAA,CAAAI,iBAAA,GAAAA,iBAAA;AAGO,MAAMC,gBAAgB,GAAG,MAAM;;AAEtC;AACA;AACA,GAFAL,OAAA,CAAAK,gBAAA,GAAAA,gBAAA;AAGO,MAAMC,eAAe,GAAG,KAAK,CAAAN,OAAA,CAAAM,eAAA,GAAAA,eAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.DEAULT_TIMEOUT = exports.DEAULT_RETRY_DELAY = void 0;exports.createDefaultHeaders = createDefaultHeaders;exports.default = void 0;exports.getWaitTimeExponential = getWaitTimeExponential;var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -14,10 +14,10 @@ var _contentTypes = require("./content-types");
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
var _errors = require("./errors");
|
|
17
|
-
var _retryable = require("./retryable");function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
var _retryable = require("./retryable");function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);enumerableOnly && (symbols = symbols.filter(function (sym) {return Object.getOwnPropertyDescriptor(object, sym).enumerable;})), keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = null != arguments[i] ? arguments[i] : {};i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {(0, _defineProperty2.default)(target, key, source[key]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));});}return target;} /**
|
|
18
|
+
* Plain HTTP client to be used when creating RQLite specific API HTTP clients
|
|
19
|
+
* @module http-request
|
|
20
|
+
*/
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -89,14 +89,14 @@ function cleanPath(path) {
|
|
|
89
89
|
* backoff algorithm.
|
|
90
90
|
* @param {Number} attempt The retry attempt
|
|
91
91
|
* @param {Number} base The base of the exponential backoff
|
|
92
|
-
* @param {Number}
|
|
92
|
+
* @param {Number} exponent The exponential power
|
|
93
93
|
* @returns {Number} The time to wait in milliseconds
|
|
94
94
|
*/
|
|
95
|
-
function getWaitTimeExponential(attempt = 0, base = 100,
|
|
95
|
+
function getWaitTimeExponential(attempt = 0, base = 100, exponent = 2) {
|
|
96
96
|
if (attempt === 0) {
|
|
97
97
|
return 0;
|
|
98
98
|
}
|
|
99
|
-
return Math.pow(
|
|
99
|
+
return Math.pow(exponent, attempt) * base;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
@@ -105,78 +105,83 @@ function getWaitTimeExponential(attempt = 0, base = 100, pow = 2) {
|
|
|
105
105
|
* server
|
|
106
106
|
*/
|
|
107
107
|
class HttpRequest {
|
|
108
|
-
/**
|
|
109
|
-
* The index of the host in this.hosts which will be tried
|
|
110
|
-
* first before attempting other hosts
|
|
111
|
-
* @type {Number}
|
|
112
|
-
*/
|
|
113
108
|
|
|
114
109
|
|
|
115
|
-
/**
|
|
116
|
-
* Whether or not the setNextActiveHostIndex() should
|
|
117
|
-
* perform a round robin strategy
|
|
118
|
-
*/
|
|
119
110
|
|
|
120
111
|
|
|
121
|
-
/**
|
|
122
|
-
* The regex pattern to check if a uri is absolute or relative,
|
|
123
|
-
* if it is absolute the host is not appended
|
|
124
|
-
*/
|
|
125
112
|
|
|
126
113
|
|
|
127
|
-
/**
|
|
128
|
-
* A list of hosts that are tried in round robin fashion
|
|
129
|
-
* when certain HTTP responses are received
|
|
130
|
-
* @type {String[]}
|
|
131
|
-
*/
|
|
132
114
|
|
|
133
115
|
|
|
134
|
-
/**
|
|
135
|
-
* @type {import('http').Agent} The http agent if it is set
|
|
136
|
-
*/
|
|
137
116
|
|
|
138
117
|
|
|
139
|
-
/**
|
|
140
|
-
* @type {import('https').Agent} The https agent if it is set
|
|
141
|
-
*/
|
|
142
118
|
|
|
143
119
|
|
|
144
|
-
/**
|
|
145
|
-
* The host list index of the leader node defaults
|
|
146
|
-
* to the first host
|
|
147
|
-
* @type {Number}
|
|
148
|
-
*/
|
|
149
120
|
|
|
150
121
|
|
|
151
|
-
/**
|
|
152
|
-
* Http error codes which are considered retryable
|
|
153
|
-
* @type {Set}
|
|
154
|
-
*/
|
|
155
122
|
|
|
156
123
|
|
|
157
|
-
/**
|
|
158
|
-
* Http status codes which are considered retryable
|
|
159
|
-
* @type {Set}
|
|
160
|
-
*/
|
|
161
124
|
|
|
162
125
|
|
|
163
|
-
/**
|
|
164
|
-
* Http methods which are considered retryable
|
|
165
|
-
* @type {Set}
|
|
166
|
-
*/
|
|
167
126
|
|
|
168
127
|
|
|
169
|
-
/**
|
|
170
|
-
* The exponential backoff base for retries
|
|
171
|
-
*/
|
|
172
128
|
|
|
173
129
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
180
185
|
|
|
181
186
|
|
|
182
187
|
/**
|
|
@@ -199,58 +204,63 @@ class HttpRequest {
|
|
|
199
204
|
* @param {Set|String[]} [options.retryableHttpMethods] The list of retryable http methods
|
|
200
205
|
* @param {Number} [options.exponentailBackoffBase] The value for exponentail backoff base
|
|
201
206
|
* for retry exponential backoff
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
207
|
+
* @param {Number} [options.exponentailBackoffExponent] Exponent to increase backoff each try
|
|
208
|
+
*/
|
|
209
|
+
constructor(hosts, options = {}) {/**
|
|
210
|
+
* The index of the host in this.hosts which will be tried
|
|
211
|
+
* first before attempting other hosts
|
|
212
|
+
* @type {Number}
|
|
213
|
+
*/(0, _defineProperty2.default)(this, "activeHostIndex", 0); /**
|
|
214
|
+
* Whether or not the setNextActiveHostIndex() should
|
|
215
|
+
* perform a round robin strategy
|
|
216
|
+
*/(0, _defineProperty2.default)(this, "activeHostRoundRobin", true); /**
|
|
217
|
+
* The regex pattern to check if a uri is absolute or relative,
|
|
218
|
+
* if it is absolute the host is not appended
|
|
219
|
+
*/(0, _defineProperty2.default)(this, "absoluteUriPattern", /^https?:\/\//); /**
|
|
220
|
+
* A list of hosts that are tried in round robin fashion
|
|
221
|
+
* when certain HTTP responses are received
|
|
222
|
+
* @type {String[]}
|
|
223
|
+
*/(0, _defineProperty2.default)(this, "hosts", []); /**
|
|
224
|
+
* @type {import('http').Agent} The http agent if it is set
|
|
225
|
+
*/(0, _defineProperty2.default)(this, "httpAgent", void 0); /**
|
|
226
|
+
* @type {import('https').Agent} The https agent if it is set
|
|
227
|
+
*/(0, _defineProperty2.default)(this, "httpsAgent", void 0); /**
|
|
228
|
+
* The host list index of the leader node defaults
|
|
229
|
+
* to the first host
|
|
230
|
+
* @type {Number}
|
|
231
|
+
*/(0, _defineProperty2.default)(this, "leaderHostIndex", 0); /**
|
|
232
|
+
* Http error codes which are considered retryable
|
|
233
|
+
* @type {Set}
|
|
234
|
+
*/(0, _defineProperty2.default)(this, "retryableErrorCodes", _retryable.RETRYABLE_ERROR_CODES); /**
|
|
235
|
+
* Http status codes which are considered retryable
|
|
236
|
+
* @type {Set}
|
|
237
|
+
*/(0, _defineProperty2.default)(this, "retryableStatusCodes", _retryable.RETRYABLE_STATUS_CODES); /**
|
|
238
|
+
* Http methods which are considered retryable
|
|
239
|
+
* @type {Set}
|
|
240
|
+
*/(0, _defineProperty2.default)(this, "retryableHttpMethods", _retryable.RETRYABLE_HTTP_METHODS); /**
|
|
241
|
+
* The exponential backoff base for retries
|
|
242
|
+
*/(0, _defineProperty2.default)(this, "exponentailBackoffBase", 100); /**
|
|
243
|
+
* The exponent to increase backoff each try
|
|
244
|
+
*/(0, _defineProperty2.default)(this, "exponentailBackoffExponent", 1.1); /**
|
|
245
|
+
* Authentication Map
|
|
246
|
+
* @type {Map}
|
|
247
|
+
* @property {String} username
|
|
248
|
+
* @property {String} password
|
|
249
|
+
*/(0, _defineProperty2.default)(this, "authentication", new Map());this.setHosts(hosts);if (this.getTotalHosts() === 0) {throw new Error('At least one host must be provided');}const _options$activeHostRo = options.activeHostRoundRobin,activeHostRoundRobin = _options$activeHostRo === void 0 ? true : _options$activeHostRo,httpAgent = options.httpAgent,httpsAgent = options.httpsAgent,retryableErrorCodes = options.retryableErrorCodes,retryableStatusCodes = options.retryableStatusCodes,retryableHttpMethods = options.retryableHttpMethods,exponentailBackoffExponent = options.exponentailBackoffExponent,exponentailBackoffBase = options.exponentailBackoffBase,authentication = options.authentication;if (typeof authentication === 'object') {const username = authentication.username,password = authentication.password;if (username) {this.authentication.set('username', username);}if (password) {this.authentication.set('password', password);}}if (typeof activeHostRoundRobin !== 'undefined') {this.setActiveHostRoundRobin(activeHostRoundRobin);}if (typeof httpAgent !== 'undefined') {this.setHttpAgent(httpAgent);}if (typeof httpsAgent !== 'undefined') {this.setHttpsAgent(httpsAgent);}if (retryableErrorCodes instanceof Set || Array.isArray(retryableErrorCodes)) {this.setRetryableErrorCodes(Array.isArray(retryableErrorCodes) ? Set(retryableErrorCodes) : retryableErrorCodes);}if (retryableStatusCodes instanceof Set || Array.isArray(retryableStatusCodes)) {this.setRetryableStatusCodes(
|
|
250
|
+
Array.isArray(retryableStatusCodes) ? Set(retryableStatusCodes) : retryableStatusCodes
|
|
251
|
+
);
|
|
245
252
|
}
|
|
246
253
|
if (retryableHttpMethods instanceof Set || Array.isArray(retryableHttpMethods)) {
|
|
247
254
|
this.setRetryableHttpMethods(
|
|
248
|
-
|
|
249
|
-
|
|
255
|
+
Array.isArray(retryableHttpMethods) ? Set(retryableHttpMethods) : retryableHttpMethods
|
|
256
|
+
);
|
|
250
257
|
}
|
|
251
258
|
if (Number.isFinite(exponentailBackoffBase)) {
|
|
252
259
|
this.setExponentailBackoffBase(exponentailBackoffBase);
|
|
253
260
|
}
|
|
261
|
+
if (Number.isFinite(exponentailBackoffExponent)) {
|
|
262
|
+
this.setExponentailBackoffExponent(exponentailBackoffExponent);
|
|
263
|
+
}
|
|
254
264
|
}
|
|
255
265
|
|
|
256
266
|
/**
|
|
@@ -285,6 +295,22 @@ class HttpRequest {
|
|
|
285
295
|
return this.exponentailBackoffBase;
|
|
286
296
|
}
|
|
287
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Set the exponentail backoff exponent
|
|
300
|
+
* @param {Number} exponentailBackoffExponent
|
|
301
|
+
*/
|
|
302
|
+
setExponentailBackoffExponent(exponentailBackoffExponent) {
|
|
303
|
+
this.exponentailBackoffExponent = exponentailBackoffExponent;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get the exponentail backoff exponent
|
|
308
|
+
* @return {Number} The exponentail backoff exponent
|
|
309
|
+
*/
|
|
310
|
+
getExponentailBackoffExponent() {
|
|
311
|
+
return this.exponentailBackoffExponent;
|
|
312
|
+
}
|
|
313
|
+
|
|
288
314
|
/**
|
|
289
315
|
* Set the retryable error codes
|
|
290
316
|
* @param {Set} retryableErrorCodes
|
|
@@ -552,10 +578,10 @@ class HttpRequest {
|
|
|
552
578
|
*/
|
|
553
579
|
requestIsRetryable(options = {}) {
|
|
554
580
|
const
|
|
555
|
-
|
|
581
|
+
statusCode =
|
|
556
582
|
|
|
557
583
|
|
|
558
|
-
|
|
584
|
+
options.statusCode,errorCode = options.errorCode,httpMethod = options.httpMethod;
|
|
559
585
|
// Honor strictly the http method
|
|
560
586
|
if (!this.getRetryableHttpMethods().has(httpMethod)) {
|
|
561
587
|
return false;
|
|
@@ -578,7 +604,7 @@ class HttpRequest {
|
|
|
578
604
|
*/
|
|
579
605
|
fetch(options = {}) {var _this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
580
606
|
const
|
|
581
|
-
|
|
607
|
+
body =
|
|
582
608
|
|
|
583
609
|
|
|
584
610
|
|
|
@@ -594,7 +620,8 @@ class HttpRequest {
|
|
|
594
620
|
|
|
595
621
|
|
|
596
622
|
|
|
597
|
-
|
|
623
|
+
|
|
624
|
+
options.body,_options$headers = options.headers,headers = _options$headers === void 0 ? {} : _options$headers,_options$httpMethod = options.httpMethod,httpMethod = _options$httpMethod === void 0 ? _httpMethods.HTTP_METHOD_GET : _options$httpMethod,query = options.query,_options$stream = options.stream,stream = _options$stream === void 0 ? false : _options$stream,_options$timeout = options.timeout,timeout = _options$timeout === void 0 ? DEAULT_TIMEOUT : _options$timeout,_options$useLeader = options.useLeader,useLeader = _options$useLeader === void 0 ? false : _options$useLeader,_options$retries = options.retries,retries = _options$retries === void 0 ? _this.getTotalHosts() * 3 : _options$retries,_options$maxRedirects = options.maxRedirects,maxRedirects = _options$maxRedirects === void 0 ? 10 : _options$maxRedirects,_options$attempt = options.attempt,attempt = _options$attempt === void 0 ? 0 : _options$attempt,_options$retryAttempt = options.retryAttempt,retryAttempt = _options$retryAttempt === void 0 ? 0 : _options$retryAttempt,_options$redirectAtte = options.redirectAttempt,redirectAttempt = _options$redirectAtte === void 0 ? 0 : _options$redirectAtte,attemptHostIndex = options.attemptHostIndex,_options$exponentailB = options.exponentailBackoffExponent,exponentailBackoffExponent = _options$exponentailB === void 0 ? _this.getExponentailBackoffExponent() : _options$exponentailB,_options$exponentailB2 = options.exponentailBackoffBase,exponentailBackoffBase = _options$exponentailB2 === void 0 ? _this.getExponentailBackoffBase() : _options$exponentailB2,_options$httpAgent = options.httpAgent,httpAgent = _options$httpAgent === void 0 ? _this.getHttpAgent() : _options$httpAgent,_options$httpsAgent = options.httpsAgent,httpsAgent = _options$httpsAgent === void 0 ? _this.getHttpsAgent() : _options$httpsAgent;
|
|
598
625
|
// Honor the supplied attemptHostIndex or get the active host
|
|
599
626
|
const activeHost = Number.isFinite(attemptHostIndex) ? _this.getHosts()[attemptHostIndex] :
|
|
600
627
|
_this.getActiveHost(useLeader);
|
|
@@ -608,8 +635,8 @@ class HttpRequest {
|
|
|
608
635
|
if (_this.authentication.size) {
|
|
609
636
|
auth = {
|
|
610
637
|
username: _this.authentication.get('username'),
|
|
611
|
-
password: _this.authentication.get('password')
|
|
612
|
-
|
|
638
|
+
password: _this.authentication.get('password')
|
|
639
|
+
};
|
|
613
640
|
}
|
|
614
641
|
const response = yield (0, _axios.default)({
|
|
615
642
|
url: uri,
|
|
@@ -625,15 +652,15 @@ class HttpRequest {
|
|
|
625
652
|
httpAgent,
|
|
626
653
|
paramsSerializer(params) {
|
|
627
654
|
return (0, _qs.stringify)(params, { arrayFormat: 'brackets' });
|
|
628
|
-
}
|
|
629
|
-
|
|
655
|
+
}
|
|
656
|
+
});
|
|
630
657
|
if (stream) {
|
|
631
658
|
return response.data;
|
|
632
659
|
}
|
|
633
660
|
return {
|
|
634
661
|
body: response.data,
|
|
635
|
-
status: response.status
|
|
636
|
-
|
|
662
|
+
status: response.status
|
|
663
|
+
};
|
|
637
664
|
} catch (e) {
|
|
638
665
|
const _e$response = e.response,response = _e$response === void 0 ? {} : _e$response,errorCode = e.code;
|
|
639
666
|
const responseStatus = response.status,_response$headers = response.headers,responseHeaders = _response$headers === void 0 ? {} : _response$headers;
|
|
@@ -641,8 +668,8 @@ class HttpRequest {
|
|
|
641
668
|
const retryable = _this.requestIsRetryable({
|
|
642
669
|
statusCode: responseStatus,
|
|
643
670
|
errorCode,
|
|
644
|
-
httpMethod
|
|
645
|
-
|
|
671
|
+
httpMethod
|
|
672
|
+
});
|
|
646
673
|
// Save the next active host index and pass it to retry manually
|
|
647
674
|
let nextAttemptHostIndex = Number.isFinite(attemptHostIndex) ? attemptHostIndex :
|
|
648
675
|
_this.getActiveHostIndex();
|
|
@@ -671,19 +698,26 @@ class HttpRequest {
|
|
|
671
698
|
uri: location,
|
|
672
699
|
attempt: attempt + 1,
|
|
673
700
|
redirectAttempt: redirectAttempt + 1,
|
|
674
|
-
attemptHostIndex: nextAttemptHostIndex })
|
|
675
|
-
|
|
701
|
+
attemptHostIndex: nextAttemptHostIndex })
|
|
702
|
+
);
|
|
676
703
|
}
|
|
677
704
|
if (retryable && retryAttempt < retries) {
|
|
678
|
-
const waitTime = getWaitTimeExponential(
|
|
679
|
-
|
|
680
|
-
|
|
705
|
+
const waitTime = getWaitTimeExponential(
|
|
706
|
+
retryAttempt,
|
|
707
|
+
exponentailBackoffBase,
|
|
708
|
+
exponentailBackoffExponent
|
|
709
|
+
);
|
|
710
|
+
yield new Promise((resolve) => {
|
|
711
|
+
setTimeout(() => {
|
|
712
|
+
resolve(undefined);
|
|
713
|
+
}, waitTime);
|
|
714
|
+
});
|
|
681
715
|
return _this.fetch(_objectSpread(_objectSpread({},
|
|
682
716
|
options), {}, {
|
|
683
717
|
attempt: attempt + 1,
|
|
684
718
|
retryAttempt: retryAttempt + 1,
|
|
685
|
-
attemptHostIndex: nextAttemptHostIndex })
|
|
686
|
-
|
|
719
|
+
attemptHostIndex: nextAttemptHostIndex })
|
|
720
|
+
);
|
|
687
721
|
}
|
|
688
722
|
throw e;
|
|
689
723
|
}})();
|
|
@@ -705,5 +739,6 @@ class HttpRequest {
|
|
|
705
739
|
*/
|
|
706
740
|
post(options = {}) {var _this3 = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
707
741
|
return _this3.fetch(_objectSpread(_objectSpread({}, options), {}, { httpMethod: _httpMethods.HTTP_METHOD_POST }));})();
|
|
708
|
-
}
|
|
742
|
+
}
|
|
743
|
+
}exports.default = HttpRequest;
|
|
709
744
|
//# sourceMappingURL=index.js.map
|