rqlite-js 2.5.2 → 2.5.5
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/.eslintrc +1 -1
- package/.travis.yml +2 -2
- package/es6/api/client/index.js +9 -3
- package/es6/api/data/index.js +35 -7
- package/es6/api/results/data-result-error.js +6 -0
- package/es6/api/results/data-result.js +6 -5
- package/es6/api/results/data-results.js +8 -6
- package/es6/api/status/index.js +1 -1
- package/es6/http-request/content-types.js +1 -1
- package/es6/http-request/index.js +41 -33
- package/lib/api/backup/index.js +1 -1
- package/lib/api/backup/index.js.map +1 -1
- package/lib/api/client/index.js +18 -12
- package/lib/api/client/index.js.map +1 -1
- package/lib/api/data/index.js +43 -15
- package/lib/api/data/index.js.map +1 -1
- package/lib/api/results/data-result-error.js +6 -0
- package/lib/api/results/data-result-error.js.map +1 -1
- package/lib/api/results/data-result.js +7 -6
- package/lib/api/results/data-result.js.map +1 -1
- package/lib/api/results/data-results.js +13 -11
- 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 +2 -2
- 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.map +1 -1
- package/lib/http-request/http-methods.js.map +1 -1
- package/lib/http-request/index.js +62 -54
- package/lib/http-request/index.js.map +1 -1
- package/lib/http-request/retryable.js +1 -1
- package/lib/http-request/retryable.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +18 -18
- package/CHANGELOG.md +0 -306
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
class DataResult {
|
|
11
11
|
/**
|
|
12
12
|
* The time the results query took to complete
|
|
13
|
+
* @type {Number}
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
|
|
@@ -42,19 +43,19 @@ class DataResult {
|
|
|
42
43
|
* @param {Array} result An API response individual result
|
|
43
44
|
* @param {Array} [valuesIndex] The index to get the values from the result
|
|
44
45
|
*/
|
|
45
|
-
constructor(result, valuesIndex) {(0, _defineProperty2.default)(this, "time", 0);(0, _defineProperty2.default)(this, "lastInsertId", void 0);(0, _defineProperty2.default)(this, "rowsAffected",
|
|
46
|
+
constructor(result, valuesIndex) {(0, _defineProperty2.default)(this, "time", 0.0);(0, _defineProperty2.default)(this, "lastInsertId", void 0);(0, _defineProperty2.default)(this, "rowsAffected", 0);(0, _defineProperty2.default)(this, "results", []);(0, _defineProperty2.default)(this, "data", {});
|
|
46
47
|
if (typeof result !== 'object') {
|
|
47
48
|
throw new Error('The result argument is required to be an object');
|
|
48
49
|
}
|
|
49
50
|
if (typeof valuesIndex !== 'undefined' && !Number.isFinite(valuesIndex)) {
|
|
50
51
|
throw new Error('The valuesIndex argument is required to be a finite number when provided');
|
|
51
52
|
}
|
|
52
|
-
this.time = result.time;
|
|
53
|
-
this.rowsAffected = result.rows_affected;
|
|
53
|
+
this.time = parseFloat(result.time || 0.0);
|
|
54
|
+
this.rowsAffected = parseInt(result.rows_affected || 0, 10);
|
|
54
55
|
this.lastInsertId = result.last_insert_id;
|
|
55
56
|
// Map the values array to an object where columns are the properties
|
|
56
|
-
if (Number.isFinite(valuesIndex)) {
|
|
57
|
-
columns = result.columns;
|
|
57
|
+
if (Number.isFinite(valuesIndex)) {
|
|
58
|
+
const columns = result.columns;
|
|
58
59
|
const resultValues = result.values[valuesIndex];
|
|
59
60
|
if (resultValues) {
|
|
60
61
|
this.data = resultValues.reduce((acc, val, i) => {
|
|
@@ -76,7 +77,7 @@ class DataResult {
|
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Get the time the result took
|
|
79
|
-
* @returns {Number}
|
|
80
|
+
* @returns {Number} The time the query took
|
|
80
81
|
*/
|
|
81
82
|
getTime() {
|
|
82
83
|
return this.time;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"data-result.js","names":["DataResult","constructor","result","valuesIndex","Error","Number","isFinite","time","parseFloat","rowsAffected","parseInt","rows_affected","lastInsertId","last_insert_id","columns","resultValues","values","data","reduce","acc","val","i","col","get","property","getTime","getLastInsertId","getRowsAffected","toObject","JSON","parse","stringify","toArray","Object","toColumnsArray","keys","toString"],"sources":["../../../es6/api/results/data-result.js"],"sourcesContent":["/**\n * Class for handling single RQLite data api result\n * @module api/results/data-result\n */\n\n/**\n * A class that represents one data result from an RQLite query or execute\n * API call\n */\nexport default class DataResult {\n /**\n * The time the results query took to complete\n * @type {Number}\n */\n time = 0.0\n\n /**\n * The last insert id\n * @type {Number}\n */\n lastInsertId\n\n /**\n * The rows affected\n * @type {Number}\n */\n rowsAffected = 0\n\n /**\n * An array of DataResult and/or DataResultError instances\n * @type {Array<DataResult|DataResultError>}\n */\n results = []\n\n /**\n * An object after the columns and values are mapped from\n * an RQLite response\n */\n data = {}\n\n /**\n * The data result constructor\n * @param {Array} result An API response individual result\n * @param {Array} [valuesIndex] The index to get the values from the result\n */\n constructor (result, valuesIndex) {\n if (typeof result !== 'object') {\n throw new Error('The result argument is required to be an object')\n }\n if (typeof valuesIndex !== 'undefined' && !Number.isFinite(valuesIndex)) {\n throw new Error('The valuesIndex argument is required to be a finite number when provided')\n }\n this.time = parseFloat(result.time || 0.0)\n this.rowsAffected = parseInt(result.rows_affected || 0, 10)\n this.lastInsertId = result.last_insert_id\n // Map the values array to an object where columns are the properties\n if (Number.isFinite(valuesIndex)) {\n const { columns } = result\n const resultValues = result.values[valuesIndex]\n if (resultValues) {\n this.data = resultValues.reduce((acc, val, i) => {\n const col = columns[i]\n acc[col] = val\n return acc\n }, {})\n }\n }\n }\n\n /**\n * Return the value a property or undefined if it does not exist\n * @returns {*} The value of the property or undefined\n */\n get (property) {\n return this.data[property]\n }\n\n /**\n * Get the time the result took\n * @returns {Number} The time the query took\n */\n getTime () {\n return this.time\n }\n\n /**\n * Get the last insert id\n * @returns {Number|undefined}\n */\n getLastInsertId () {\n return this.lastInsertId\n }\n\n /**\n * Get the row affected\n * @returns {Number|undefined}\n */\n getRowsAffected () {\n return this.rowsAffected\n }\n\n /**\n * Get the result data as plain object\n * @returns {Object} The data as an object\n */\n toObject () {\n // Clone deep\n return JSON.parse(JSON.stringify(this.data))\n }\n\n /**\n * Map the data values to an array\n * @returns {Array}\n */\n toArray () {\n return Object.values(this.data)\n }\n\n /**\n * Map the data properites to an array\n * @returns {String[]}\n */\n toColumnsArray () {\n return Object.keys(this.data)\n }\n\n /**\n * Convert the result data to a JSON string\n * @returns {String} The JSON string for the data object\n */\n toString () {\n return JSON.stringify(this.data)\n }\n}\n"],"mappings":"0RAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACe,MAAMA,UAAN,CAAiB;EAC9B;AACF;AACA;AACA;;;EAGE;AACF;AACA;AACA;;;EAGE;AACF;AACA;AACA;;;EAGE;AACF;AACA;AACA;;;EAGE;AACF;AACA;AACA;;;EAGE;AACF;AACA;AACA;AACA;EACEC,WAAW,CAAEC,MAAF,EAAUC,WAAV,EAAuB,6CA/B3B,GA+B2B,kHAnBnB,CAmBmB,iDAbxB,EAawB,8CAP3B,EAO2B;IAChC,IAAI,OAAOD,MAAP,KAAkB,QAAtB,EAAgC;MAC9B,MAAM,IAAIE,KAAJ,CAAU,iDAAV,CAAN;IACD;IACD,IAAI,OAAOD,WAAP,KAAuB,WAAvB,IAAsC,CAACE,MAAM,CAACC,QAAP,CAAgBH,WAAhB,CAA3C,EAAyE;MACvE,MAAM,IAAIC,KAAJ,CAAU,0EAAV,CAAN;IACD;IACD,KAAKG,IAAL,GAAYC,UAAU,CAACN,MAAM,CAACK,IAAP,IAAe,GAAhB,CAAtB;IACA,KAAKE,YAAL,GAAoBC,QAAQ,CAACR,MAAM,CAACS,aAAP,IAAwB,CAAzB,EAA4B,EAA5B,CAA5B;IACA,KAAKC,YAAL,GAAoBV,MAAM,CAACW,cAA3B;IACA;IACA,IAAIR,MAAM,CAACC,QAAP,CAAgBH,WAAhB,CAAJ,EAAkC;MAChC,MAAQW,OAAR,GAAoBZ,MAApB,CAAQY,OAAR;MACA,MAAMC,YAAY,GAAGb,MAAM,CAACc,MAAP,CAAcb,WAAd,CAArB;MACA,IAAIY,YAAJ,EAAkB;QAChB,KAAKE,IAAL,GAAYF,YAAY,CAACG,MAAb,CAAoB,CAACC,GAAD,EAAMC,GAAN,EAAWC,CAAX,KAAiB;UAC/C,MAAMC,GAAG,GAAGR,OAAO,CAACO,CAAD,CAAnB;UACAF,GAAG,CAACG,GAAD,CAAH,GAAWF,GAAX;UACA,OAAOD,GAAP;QACD,CAJW,EAIT,EAJS,CAAZ;MAKD;IACF;EACF;;EAED;AACF;AACA;AACA;EACEI,GAAG,CAAEC,QAAF,EAAY;IACb,OAAO,KAAKP,IAAL,CAAUO,QAAV,CAAP;EACD;;EAED;AACF;AACA;AACA;EACEC,OAAO,GAAI;IACT,OAAO,KAAKlB,IAAZ;EACD;;EAED;AACF;AACA;AACA;EACEmB,eAAe,GAAI;IACjB,OAAO,KAAKd,YAAZ;EACD;;EAED;AACF;AACA;AACA;EACEe,eAAe,GAAI;IACjB,OAAO,KAAKlB,YAAZ;EACD;;EAED;AACF;AACA;AACA;EACEmB,QAAQ,GAAI;IACV;IACA,OAAOC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,SAAL,CAAe,KAAKd,IAApB,CAAX,CAAP;EACD;;EAED;AACF;AACA;AACA;EACEe,OAAO,GAAI;IACT,OAAOC,MAAM,CAACjB,MAAP,CAAc,KAAKC,IAAnB,CAAP;EACD;;EAED;AACF;AACA;AACA;EACEiB,cAAc,GAAI;IAChB,OAAOD,MAAM,CAACE,IAAP,CAAY,KAAKlB,IAAjB,CAAP;EACD;;EAED;AACF;AACA;AACA;EACEmB,QAAQ,GAAI;IACV,OAAOP,IAAI,CAACE,SAAL,CAAe,KAAKd,IAApB,CAAP;EACD,CA3H6B,C"}
|
|
@@ -12,6 +12,7 @@ var _dataResultError = _interopRequireDefault(require("./data-result-error")); /
|
|
|
12
12
|
/**
|
|
13
13
|
* The time the results took to return from the
|
|
14
14
|
* RQLite api
|
|
15
|
+
* @type {Number}
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
18
|
|
|
@@ -23,10 +24,11 @@ var _dataResultError = _interopRequireDefault(require("./data-result-error")); /
|
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* The data result list constructor
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {Number} time The time the API response took to complete
|
|
27
|
+
* @param {Object} data The data object sent from a RQLite API response
|
|
28
|
+
* @param {Number} data.time The time the API response took to complete
|
|
29
|
+
* @param {Object[{error:String,values:Object}]} data.results The results array
|
|
28
30
|
*/
|
|
29
|
-
constructor(data) {(0, _defineProperty2.default)(this, "time", 0);(0, _defineProperty2.default)(this, "results", []);
|
|
31
|
+
constructor(data) {(0, _defineProperty2.default)(this, "time", 0.0);(0, _defineProperty2.default)(this, "results", []);
|
|
30
32
|
this.setApiData(data);
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -41,14 +43,14 @@ var _dataResultError = _interopRequireDefault(require("./data-result-error")); /
|
|
|
41
43
|
if (!data.results) {
|
|
42
44
|
throw new Error('The data object is required to have a results property');
|
|
43
45
|
}
|
|
44
|
-
this.time = data.time || 0;
|
|
45
|
-
data.results,results = _data$results === void 0 ? [] : _data$results;
|
|
46
|
+
this.time = parseFloat(data.time || 0.0);
|
|
47
|
+
const _data$results = data.results,results = _data$results === void 0 ? [] : _data$results;
|
|
46
48
|
this.results = results.reduce((acc, result) => {
|
|
47
49
|
// If there is an error property this is an error
|
|
48
50
|
if (typeof result === 'object' && result.error) {
|
|
49
51
|
return acc.concat(new _dataResultError.default(result.error));
|
|
50
|
-
}
|
|
51
|
-
vals = result.values;
|
|
52
|
+
}
|
|
53
|
+
const vals = result.values;
|
|
52
54
|
// We don't have values so this is a single result row
|
|
53
55
|
if (!vals) {
|
|
54
56
|
return acc.concat(new _dataResult.default(result));
|
|
@@ -72,12 +74,12 @@ var _dataResultError = _interopRequireDefault(require("./data-result-error")); /
|
|
|
72
74
|
* @returns {DataResultError|undefined}
|
|
73
75
|
*/
|
|
74
76
|
getFirstError() {
|
|
75
|
-
return this.results.find(v => v instanceof _dataResultError.default);
|
|
77
|
+
return this.results.find((v) => v instanceof _dataResultError.default);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
81
|
* Get the time the results took
|
|
80
|
-
* @
|
|
82
|
+
* @returns {Number} The time the query took
|
|
81
83
|
*/
|
|
82
84
|
getTime() {
|
|
83
85
|
return this.time;
|
|
@@ -104,7 +106,7 @@ var _dataResultError = _interopRequireDefault(require("./data-result-error")); /
|
|
|
104
106
|
* @returns {Object[]} The data as an array or objects
|
|
105
107
|
*/
|
|
106
108
|
toArray() {
|
|
107
|
-
return this.results.map(result => result.toObject());
|
|
109
|
+
return this.results.map((result) => result.toObject());
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
/**
|
|
@@ -113,7 +115,7 @@ var _dataResultError = _interopRequireDefault(require("./data-result-error")); /
|
|
|
113
115
|
* @returns {String} A JSON string
|
|
114
116
|
*/
|
|
115
117
|
toString() {
|
|
116
|
-
const list = this.results.map(result => result.
|
|
118
|
+
const list = this.results.map((result) => result.toObject());
|
|
117
119
|
return JSON.stringify(list);
|
|
118
120
|
}}exports.default = DataResults;module.exports = exports.default;
|
|
119
121
|
//# sourceMappingURL=data-results.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"data-results.js","names":["DataResults","constructor","data","setApiData","Error","results","time","parseFloat","reduce","acc","result","error","concat","DataResultError","vals","values","DataResult","dataResults","map","_v","valuesIndex","hasError","getFirstError","find","v","getTime","get","index","getResults","toArray","toObject","toString","list","JSON","stringify"],"sources":["../../../es6/api/results/data-results.js"],"sourcesContent":["/**\n * Class for handling many RQLite data api results\n * @module api/results/data-results\n */\nimport DataResult from './data-result'\nimport DataResultError from './data-result-error'\n\n/**\n * A class to manage a list of results from an RQLite query or execute API response\n */\nexport default class DataResults {\n /**\n * The time the results took to return from the\n * RQLite api\n * @type {Number}\n */\n time = 0.0\n\n /**\n * The results which is an empty arry to start\n * @type {DataResult[]}\n */\n results = []\n\n /**\n * The data result list constructor\n * @param {Object} data The data object sent from a RQLite API response\n * @param {Number} data.time The time the API response took to complete\n * @param {Object[{error:String,values:Object}]} data.results The results array\n */\n constructor (data) {\n this.setApiData(data)\n }\n\n /**\n * Set the api as results\n * @param {Object} data Api data\n */\n setApiData (data) {\n if (typeof data !== 'object') {\n throw new Error('The data argument is required to be an object')\n }\n if (!data.results) {\n throw new Error('The data object is required to have a results property')\n }\n this.time = parseFloat(data.time || 0.0)\n const { results = [] } = data\n this.results = results.reduce((acc, result) => {\n // If there is an error property this is an error\n if (typeof result === 'object' && result.error) {\n return acc.concat(new DataResultError(result.error))\n }\n const { values: vals } = result\n // We don't have values so this is a single result row\n if (!vals) {\n return acc.concat(new DataResult(result))\n }\n // Map the values to DataResult instances\n const dataResults = vals.map((_v, valuesIndex) => new DataResult(result, valuesIndex))\n return acc.concat(dataResults)\n }, [])\n }\n\n /**\n * Returns true if an instance of DataResultError exists in the results\n * @returns {Boolean} True if a DataResultError instance exists\n */\n hasError () {\n return !!this.getFirstError()\n }\n\n /**\n * Get the first error that occured\n * @returns {DataResultError|undefined}\n */\n getFirstError () {\n return this.results.find((v) => v instanceof DataResultError)\n }\n\n /**\n * Get the time the results took\n * @returns {Number} The time the query took\n */\n getTime () {\n return this.time\n }\n\n /**\n * Return one result at a specific index or undefined it it does not exist\n * @returns {DataResult|DataResultError|undefined}\n */\n get (index) {\n return this.results[index]\n }\n\n /**\n * Return the results array\n * @returns {Array<DataResult|DataResultError>}\n */\n getResults () {\n return this.results\n }\n\n /**\n * Get the result data list as array of plain objects\n * @returns {Object[]} The data as an array or objects\n */\n toArray () {\n return this.results.map((result) => result.toObject())\n }\n\n /**\n * Convert the result data list to a JSON string that is an\n * array of objects\n * @returns {String} A JSON string\n */\n toString () {\n const list = this.results.map((result) => result.toObject())\n return JSON.stringify(list)\n }\n}\n"],"mappings":";;;;AAIA;AACA,8E,CALA;AACA;AACA;AACA,G,CAIA;AACA;AACA,GACe,MAAMA,WAAN,CAAkB;EAC/B;AACF;AACA;AACA;AACA;;;EAGE;AACF;AACA;AACA;;;EAGE;AACF;AACA;AACA;AACA;AACA;EACEC,WAAW,CAAEC,IAAF,EAAQ,6CAdZ,GAcY,iDART,EAQS;IACjB,KAAKC,UAAL,CAAgBD,IAAhB;EACD;;EAED;AACF;AACA;AACA;EACEC,UAAU,CAAED,IAAF,EAAQ;IAChB,IAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;MAC5B,MAAM,IAAIE,KAAJ,CAAU,+CAAV,CAAN;IACD;IACD,IAAI,CAACF,IAAI,CAACG,OAAV,EAAmB;MACjB,MAAM,IAAID,KAAJ,CAAU,wDAAV,CAAN;IACD;IACD,KAAKE,IAAL,GAAYC,UAAU,CAACL,IAAI,CAACI,IAAL,IAAa,GAAd,CAAtB;IACA,sBAAyBJ,IAAzB,CAAQG,OAAR,CAAQA,OAAR,8BAAkB,EAAlB;IACA,KAAKA,OAAL,GAAeA,OAAO,CAACG,MAAR,CAAe,CAACC,GAAD,EAAMC,MAAN,KAAiB;MAC7C;MACA,IAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,CAACC,KAAzC,EAAgD;QAC9C,OAAOF,GAAG,CAACG,MAAJ,CAAW,IAAIC,wBAAJ,CAAoBH,MAAM,CAACC,KAA3B,CAAX,CAAP;MACD;MACD,MAAgBG,IAAhB,GAAyBJ,MAAzB,CAAQK,MAAR;MACA;MACA,IAAI,CAACD,IAAL,EAAW;QACT,OAAOL,GAAG,CAACG,MAAJ,CAAW,IAAII,mBAAJ,CAAeN,MAAf,CAAX,CAAP;MACD;MACD;MACA,MAAMO,WAAW,GAAGH,IAAI,CAACI,GAAL,CAAS,CAACC,EAAD,EAAKC,WAAL,KAAqB,IAAIJ,mBAAJ,CAAeN,MAAf,EAAuBU,WAAvB,CAA9B,CAApB;MACA,OAAOX,GAAG,CAACG,MAAJ,CAAWK,WAAX,CAAP;IACD,CAbc,EAaZ,EAbY,CAAf;EAcD;;EAED;AACF;AACA;AACA;EACEI,QAAQ,GAAI;IACV,OAAO,CAAC,CAAC,KAAKC,aAAL,EAAT;EACD;;EAED;AACF;AACA;AACA;EACEA,aAAa,GAAI;IACf,OAAO,KAAKjB,OAAL,CAAakB,IAAb,CAAkB,CAACC,CAAD,KAAOA,CAAC,YAAYX,wBAAtC,CAAP;EACD;;EAED;AACF;AACA;AACA;EACEY,OAAO,GAAI;IACT,OAAO,KAAKnB,IAAZ;EACD;;EAED;AACF;AACA;AACA;EACEoB,GAAG,CAAEC,KAAF,EAAS;IACV,OAAO,KAAKtB,OAAL,CAAasB,KAAb,CAAP;EACD;;EAED;AACF;AACA;AACA;EACEC,UAAU,GAAI;IACZ,OAAO,KAAKvB,OAAZ;EACD;;EAED;AACF;AACA;AACA;EACEwB,OAAO,GAAI;IACT,OAAO,KAAKxB,OAAL,CAAaa,GAAb,CAAiB,CAACR,MAAD,KAAYA,MAAM,CAACoB,QAAP,EAA7B,CAAP;EACD;;EAED;AACF;AACA;AACA;AACA;EACEC,QAAQ,GAAI;IACV,MAAMC,IAAI,GAAG,KAAK3B,OAAL,CAAaa,GAAb,CAAiB,CAACR,MAAD,KAAYA,MAAM,CAACoB,QAAP,EAA7B,CAAb;IACA,OAAOG,IAAI,CAACC,SAAL,CAAeF,IAAf,CAAP;EACD,CA7G8B,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../es6/api/results/index.js"],"sourcesContent":["/**\n * Features for handle RQLite data api responses for success and errors\n * @module api/results\n */\nexport { default as DataResult } from './data-result'\nexport { default as DataResultError } from './data-result-error'\nexport { default as DataResults } from './data-results'\n"],"mappings":";;;;AAIA;AACA;AACA"}
|
package/lib/api/status/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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);
|
|
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
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {Object} HttpResponse
|
|
@@ -38,7 +38,7 @@ class StatusApiClient extends _client.default {
|
|
|
38
38
|
* Get the RQLite server status for all hosts as an array of object with
|
|
39
39
|
* the host and their status
|
|
40
40
|
* @param {Object} [options={}] RQLite api options
|
|
41
|
-
* @param {Object} [options.raw] If true return the raw http
|
|
41
|
+
* @param {Object} [options.raw] If true return the raw http response from
|
|
42
42
|
* RQLite response
|
|
43
43
|
* @returns {StatusAllHostsResponse[]} An array of http response for the provide hosts
|
|
44
44
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["PATH_STATUS","StatusApiClient","ApiClient","status","options","useLeader","statusAllHosts","hosts","getHosts","promises","map","_host","activeHostIndex","response","host","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,2D;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMA,WAAW,GAAG,SAApB;;AAEP;AACA;AACA,G;AACe,MAAMC,eAAN,SAA8BC,eAA9B,CAAwC;EACrD;AACF;AACA;AACA;AACA;EACQC,MAAM,CAAEC,OAAO,GAAG,EAAZ,EAAgB;MAC1B,OAAO,gCAAUJ,WAAV,kBAAyBK,SAAS,EAAE,IAApC,IAA6CD,OAA7C,EAAP,CAD0B;EAE3B;;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACQE,cAAc,CAAEF,OAAO,GAAG,EAAZ,EAAgB;MAClC,MAAMG,KAAK,GAAG,MAAI,CAACC,QAAL,EAAd;MACA;MACA,MAAMC,QAAQ,GAAGF,KAAK,CAACG,GAAN,uEAAU,WAAOC,KAAP,EAAcC,eAAd,EAAkC;UAC3D,MAAMC,QAAQ,SAAS,MAAI,CAACV,MAAL,iCAAiBC,OAAjB,SAA0BQ,eAA1B,IAAvB;UACA,OAAO,EAAEC,QAAF,EAAYC,IAAI,EAAEP,KAAK,CAACK,eAAD,CAAvB,EAAP;QACD,CAHgB,sEAAjB;MAIA,OAAOG,OAAO,CAACC,GAAR,CAAYP,QAAZ,CAAP,CAPkC;EAQnC,CA1BoD,C"}
|
|
@@ -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","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,YAAhC,C;AACA,MAAMC,6BAA6B,GAAG,kBAAtC,C;AACA,MAAMC,8CAA8C,GAAG,mCAAvD,C;AACA,MAAMC,qCAAqC,GAAG,0BAA9C,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"errors.js","names":["ERROR_HTTP_REQUEST_MAX_REDIRECTS","Error","constructor","args","name","code"],"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,gCAAN,SAA+CC,KAA/C,CAAqD;EAC1DC,WAAW,CAAE,GAAGC,IAAL,EAAW;IACpB,MAAM,GAAGA,IAAT;IACA,KAAKC,IAAL,GAAY,KAAKF,WAAL,CAAiBE,IAA7B;IACA,KAAKC,IAAL,GAAY,KAAKH,WAAL,CAAiBE,IAA7B;EACD,CALyD,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"http-methods.js","names":["HTTP_METHOD_DELETE","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,QAA3B;;AAEP;AACA;AACA,G;AACO,MAAMC,eAAe,GAAG,KAAxB;;AAEP;AACA;AACA,G;AACO,MAAMC,gBAAgB,GAAG,MAAzB;;AAEP;AACA;AACA,G;AACO,MAAMC,mBAAmB,GAAG,SAA5B;;AAEP;AACA;AACA,G;AACO,MAAMC,iBAAiB,GAAG,OAA1B;;AAEP;AACA;AACA,G;AACO,MAAMC,gBAAgB,GAAG,MAAzB;;AAEP;AACA;AACA,G;AACO,MAAMC,eAAe,GAAG,KAAxB,C"}
|
|
@@ -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,12 +14,47 @@ 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);
|
|
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
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* RQliteJS HTTP Request options
|
|
25
|
+
* @typedef HttpRequestOptions
|
|
26
|
+
* @type {Object}
|
|
27
|
+
* @property {Object} [auth] A object for user authentication
|
|
28
|
+
* @property {String} [auth.username] The username for authentication
|
|
29
|
+
* @property {String} [auth.password] The username for authentication
|
|
30
|
+
* @property {Object} [body] The body of the HTTP request
|
|
31
|
+
* @property {Object} [headers={}] HTTP headers to send with the request
|
|
32
|
+
* @property {String} [httpMethod=HTTP_METHOD_GET] The HTTP method for the request
|
|
33
|
+
* i.e. GET or POST
|
|
34
|
+
* @property {Object} [query] An object with the query to send with the HTTP request
|
|
35
|
+
* @property {Boolean} [stream=false] When true the returned value is a request object with
|
|
36
|
+
* stream support instead of a request-promise result
|
|
37
|
+
* @property {Number} [timeout=DEAULT_TIMEOUT] Optional timeout to override default
|
|
38
|
+
* @property {String} uri The uri for the request which can be a relative path to use
|
|
39
|
+
* the currently active host or a full i.e. http://localhost:4001/db/query which is used
|
|
40
|
+
* literally
|
|
41
|
+
* @property {Boolean} [useLeader=false] When true the request will use the master host, the
|
|
42
|
+
* first host in this.hosts, this is ideal for write operations to skip the redirect
|
|
43
|
+
* @property {Number} [retries] The number of retries, defaults to the number of
|
|
44
|
+
* hosts times 3
|
|
45
|
+
* @property {Number} [maxRedirects=10] The maximum number of HTTP redirects to follow before
|
|
46
|
+
* throwing an error
|
|
47
|
+
* @property {Number} [attempt=0] The current attempt count when retrying or redirecting
|
|
48
|
+
* @property {Number} [retryAttempt=0] The current attempt based on retry logic
|
|
49
|
+
* @property {Number} [redirectAttempt=0] The current attempt based on redirect logic
|
|
50
|
+
* @property {Number} [attemptHostIndex] When in a retry state the host index of the last
|
|
51
|
+
* attempt which is used to get the next host index
|
|
52
|
+
* @property {import('http').Agent} [httpAgent] An option http agent, useful for
|
|
53
|
+
* keepalive pools using plain HTTP
|
|
54
|
+
* @property {import('https').Agent} [httpsAgent] An option http agent, useful
|
|
55
|
+
* for keepalive pools using SSL
|
|
56
|
+
*/
|
|
57
|
+
|
|
23
58
|
/**
|
|
24
59
|
* The default timeout value
|
|
25
60
|
*/
|
|
@@ -35,8 +70,8 @@ const DEAULT_RETRY_DELAY = 30000;
|
|
|
35
70
|
* @param {Object} [headers={}] HTTP headers to send with the request
|
|
36
71
|
* @returns {Object} The headers with defaults applied
|
|
37
72
|
*/exports.DEAULT_RETRY_DELAY = DEAULT_RETRY_DELAY;
|
|
38
|
-
function createDefaultHeaders(headers = {}) {
|
|
39
|
-
headers.Accept,Accept = _headers$Accept === void 0 ? _contentTypes.CONTENT_TYPE_APPLICATION_JSON : _headers$Accept;
|
|
73
|
+
function createDefaultHeaders(headers = {}) {
|
|
74
|
+
const _headers$Accept = headers.Accept,Accept = _headers$Accept === void 0 ? _contentTypes.CONTENT_TYPE_APPLICATION_JSON : _headers$Accept;
|
|
40
75
|
return _objectSpread(_objectSpread({}, headers), {}, { Accept });
|
|
41
76
|
}
|
|
42
77
|
|
|
@@ -169,8 +204,8 @@ class HttpRequest {
|
|
|
169
204
|
this.setHosts(hosts);
|
|
170
205
|
if (this.getTotalHosts() === 0) {
|
|
171
206
|
throw new Error('At least one host must be provided');
|
|
172
|
-
}
|
|
173
|
-
|
|
207
|
+
}
|
|
208
|
+
const _options$activeHostRo =
|
|
174
209
|
|
|
175
210
|
|
|
176
211
|
|
|
@@ -180,8 +215,8 @@ class HttpRequest {
|
|
|
180
215
|
|
|
181
216
|
|
|
182
217
|
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,exponentailBackoffBase = options.exponentailBackoffBase,authentication = options.authentication;
|
|
183
|
-
if (typeof authentication === 'object') {
|
|
184
|
-
username = authentication.username,password = authentication.password;
|
|
218
|
+
if (typeof authentication === 'object') {
|
|
219
|
+
const username = authentication.username,password = authentication.password;
|
|
185
220
|
if (username) {
|
|
186
221
|
this.authentication.set('username', username);
|
|
187
222
|
}
|
|
@@ -224,8 +259,8 @@ class HttpRequest {
|
|
|
224
259
|
* @param {String} [authentication.username] The host authentication username
|
|
225
260
|
* @param {String} [authentication.password] The host authentication password
|
|
226
261
|
*/
|
|
227
|
-
setAuthentication(authentication = {}) {
|
|
228
|
-
username = authentication.username,password = authentication.password;
|
|
262
|
+
setAuthentication(authentication = {}) {
|
|
263
|
+
const username = authentication.username,password = authentication.password;
|
|
229
264
|
if (username) {
|
|
230
265
|
this.authentication.set('username', username);
|
|
231
266
|
}
|
|
@@ -363,10 +398,10 @@ class HttpRequest {
|
|
|
363
398
|
*/
|
|
364
399
|
findHostIndex(host) {
|
|
365
400
|
const parsedHostToFind = (0, _url.parse)(host);
|
|
366
|
-
return this.getHosts().findIndex(v => {
|
|
401
|
+
return this.getHosts().findIndex((v) => {
|
|
367
402
|
const parsedHost = (0, _url.parse)(v);
|
|
368
403
|
// Find a host where all the parsed fields match the requested host
|
|
369
|
-
return ['hostname', 'protocol', 'port', 'path'].every(field => parsedHostToFind[field] === parsedHost[field]);
|
|
404
|
+
return ['hostname', 'protocol', 'port', 'path'].every((field) => parsedHostToFind[field] === parsedHost[field]);
|
|
370
405
|
});
|
|
371
406
|
}
|
|
372
407
|
|
|
@@ -515,8 +550,8 @@ class HttpRequest {
|
|
|
515
550
|
* @param {String} options.httpMethod The http method
|
|
516
551
|
* @returns {Boolean} True if the request is retry able
|
|
517
552
|
*/
|
|
518
|
-
requestIsRetryable(options = {}) {
|
|
519
|
-
|
|
553
|
+
requestIsRetryable(options = {}) {
|
|
554
|
+
const
|
|
520
555
|
statusCode =
|
|
521
556
|
|
|
522
557
|
|
|
@@ -536,42 +571,13 @@ class HttpRequest {
|
|
|
536
571
|
|
|
537
572
|
/**
|
|
538
573
|
* Perform an HTTP request using the provided options
|
|
539
|
-
* @param {
|
|
540
|
-
* @param {Object} [options.auth] A object for user authentication
|
|
541
|
-
* @param {String} [options.auth.username] The username for authentication
|
|
542
|
-
* @param {String} [options.auth.password] The username for authentication
|
|
543
|
-
* @param {Object} [options.body] The body of the HTTP request
|
|
544
|
-
* @param {Object} [options.headers={}] HTTP headers to send with the request
|
|
545
|
-
* @param {String} [options.httpMethod=HTTP_METHOD_GET] The HTTP method for the request
|
|
546
|
-
* i.e. GET or POST
|
|
547
|
-
* @param {Object} [options.query] An object with the query to send with the HTTP request
|
|
548
|
-
* @param {Boolean} [options.stream=false] When true the returned value is a request object with
|
|
549
|
-
* stream support instead of a request-promise result
|
|
550
|
-
* @param {Number} [options.timeout=DEAULT_TIMEOUT] Optional timeout to override default
|
|
551
|
-
* @param {String} options.uri The uri for the request which can be a relative path to use
|
|
552
|
-
* the currently active host or a full i.e. http://localhost:4001/db/query which is used
|
|
553
|
-
* literally
|
|
554
|
-
* @param {Boolean} [options.useLeader=false] When true the request will use the master host, the
|
|
555
|
-
* first host in this.hosts, this is ideal for write operations to skip the redirect
|
|
556
|
-
* @param {Number} [options.retries] The number of retries, defaults to the number of
|
|
557
|
-
* hosts times 3
|
|
558
|
-
* @param {Number} [options.maxRedirects=10] The maximum number of HTTP redirects to follow before
|
|
559
|
-
* throwing an error
|
|
560
|
-
* @param {Number} [options.attempt=0] The current attempt count when retrying or redirecting
|
|
561
|
-
* @param {Number} [options.retryAttempt=0] The current attempt based on retry logic
|
|
562
|
-
* @param {Number} [options.redirectAttempt=0] The current attempt based on redirect logic
|
|
563
|
-
* @param {Number} [options.attemptHostIndex] When in a retry state the host index of the last
|
|
564
|
-
* attempt which is used to get the next host index
|
|
565
|
-
* @param {import('http').Agent} [options.httpAgent] An option http agent, useful for
|
|
566
|
-
* keepalive pools using plain HTTP
|
|
567
|
-
* @param {import('https').Agent} [options.httpsAgent] An option http agent, useful
|
|
568
|
-
* for keepalive pools using SSL
|
|
574
|
+
* @param {HttpRequestOptions} [options={}] Options for the HTTP client
|
|
569
575
|
* @returns {Promise<{status: Number, body: Object|String}>} An object with a status and body
|
|
570
576
|
* property when stream is false and a stream when the stream option is true
|
|
571
577
|
* @throws {ERROR_HTTP_REQUEST_MAX_REDIRECTS} When the maximum number of redirect has been reached
|
|
572
578
|
*/
|
|
573
|
-
fetch(options = {}) {var _this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
574
|
-
|
|
579
|
+
fetch(options = {}) {var _this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
580
|
+
const
|
|
575
581
|
body =
|
|
576
582
|
|
|
577
583
|
|
|
@@ -591,8 +597,8 @@ class HttpRequest {
|
|
|
591
597
|
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.exponentailBackoffBase,exponentailBackoffBase = _options$exponentailB === void 0 ? _this.getExponentailBackoffBase() : _options$exponentailB,_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;
|
|
592
598
|
// Honor the supplied attemptHostIndex or get the active host
|
|
593
599
|
const activeHost = Number.isFinite(attemptHostIndex) ? _this.getHosts()[attemptHostIndex] :
|
|
594
|
-
_this.getActiveHost(useLeader);
|
|
595
|
-
uri = options.uri;
|
|
600
|
+
_this.getActiveHost(useLeader);
|
|
601
|
+
let uri = options.uri;
|
|
596
602
|
if (!uri) {
|
|
597
603
|
throw new Error('The uri option is required');
|
|
598
604
|
}
|
|
@@ -628,9 +634,9 @@ class HttpRequest {
|
|
|
628
634
|
body: response.data,
|
|
629
635
|
status: response.status };
|
|
630
636
|
|
|
631
|
-
} catch (e) {
|
|
632
|
-
e.response,response = _e$response === void 0 ? {} : _e$response,errorCode = e.code;
|
|
633
|
-
responseStatus = response.status,_response$headers = response.headers,responseHeaders = _response$headers === void 0 ? {} : _response$headers;
|
|
637
|
+
} catch (e) {
|
|
638
|
+
const _e$response = e.response,response = _e$response === void 0 ? {} : _e$response,errorCode = e.code;
|
|
639
|
+
const responseStatus = response.status,_response$headers = response.headers,responseHeaders = _response$headers === void 0 ? {} : _response$headers;
|
|
634
640
|
// Check if the error was a redirect
|
|
635
641
|
const retryable = _this.requestIsRetryable({
|
|
636
642
|
statusCode: responseStatus,
|
|
@@ -670,7 +676,9 @@ class HttpRequest {
|
|
|
670
676
|
}
|
|
671
677
|
if (retryable && retryAttempt < retries) {
|
|
672
678
|
const waitTime = getWaitTimeExponential(retryAttempt, exponentailBackoffBase);
|
|
673
|
-
const delayPromise = new Promise(resolve =>
|
|
679
|
+
const delayPromise = new Promise((resolve) => {
|
|
680
|
+
setTimeout(resolve, waitTime);
|
|
681
|
+
});
|
|
674
682
|
yield delayPromise;
|
|
675
683
|
return _this.fetch(_objectSpread(_objectSpread({},
|
|
676
684
|
options), {}, {
|
|
@@ -685,7 +693,7 @@ class HttpRequest {
|
|
|
685
693
|
|
|
686
694
|
/**
|
|
687
695
|
* Perform an HTTP GET request
|
|
688
|
-
* @param {
|
|
696
|
+
* @param {HttpRequestOptions} [options={}] The options
|
|
689
697
|
* @see this.fetch() for options
|
|
690
698
|
*/
|
|
691
699
|
get(options = {}) {var _this2 = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
@@ -694,7 +702,7 @@ class HttpRequest {
|
|
|
694
702
|
|
|
695
703
|
/**
|
|
696
704
|
* Perform an HTTP POST request
|
|
697
|
-
* @param {
|
|
705
|
+
* @param {HttpRequestOptions} [options={}] The options
|
|
698
706
|
* @see this.fetch() for options
|
|
699
707
|
*/
|
|
700
708
|
post(options = {}) {var _this3 = this;return (0, _asyncToGenerator2.default)(function* () {
|