Skip to content

Commit 2adcd23

Browse files
committed
Implemented the correct handling of big int numbers by the JS client
1 parent 566d637 commit 2adcd23

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "manticoresearch",
3-
"version": "3.2.0",
3+
"version": "3.1.0",
44
"description": "Javascript client for Manticore Search",
55
"license": "MIT",
66
"main": "src/index.js",
@@ -18,7 +18,8 @@
1818
"index"
1919
],
2020
"dependencies": {
21-
"superagent": "5.1.0"
21+
"superagent": "5.1.0",
22+
"json-bigint": "1.0.0"
2223
},
2324
"devDependencies": {
2425
"inherits": "^2.0.4",

src/ApiClient.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* @module ApiClient
27-
* @version 3.2.0
27+
* @version 3.0.0
2828
*/
2929

3030
/**
@@ -335,6 +335,8 @@
335335
});
336336
};
337337

338+
exports.JSONbig = require('json-bigint')({ storeAsString: true });
339+
338340
/**
339341
* Deserializes an HTTP response body into a value of the specified type.
340342
* @param {Object} response A SuperAgent response object.
@@ -348,14 +350,20 @@
348350
if (response == null || returnType == null || response.status == 204) {
349351
return null;
350352
}
351-
// Rely on SuperAgent for parsing response body.
353+
// Use json-bigint for parsing json responses otherwise rely on SuperAgent
352354
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
353-
var data = response.body;
355+
var data;
356+
if (returnType === Object || typeof returnType === 'object') {
357+
data = exports.JSONbig.parse(response.text);
358+
} else {
359+
data = response.body;
360+
}
354361
if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) {
355362
// SuperAgent does not always produce a body; use the unparsed response as a fallback
356363
data = response.text;
357364
}
358-
return exports.convertToType(data, returnType);
365+
const res = exports.convertToType(data, returnType);
366+
return res;
359367
};
360368

361369
/**
@@ -440,7 +448,8 @@
440448
}
441449

442450
if (contentType === 'application/x-www-form-urlencoded') {
443-
request.send(querystring.stringify(this.normalizeParams(formParams)));
451+
console.log('test request 2');
452+
request.send(querystring.stringify(this.normalizeParams(formParams)));
444453
} else if (contentType == 'multipart/form-data') {
445454
var _formParams = this.normalizeParams(formParams);
446455
for (var key in _formParams) {

0 commit comments

Comments
 (0)