Skip to content

Commit 5087a2a

Browse files
committed
version 2.9.0
1 parent 297a432 commit 5087a2a

File tree

6 files changed

+152
-113
lines changed

6 files changed

+152
-113
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const yildiz = new YildizClient({
1515
proto: "http",
1616
host: "localhost",
1717
port: 3058,
18-
token: "bla-bla-bla-bla" //optional
18+
token: "bla-bla-bla-bla", //optional
19+
disableKeepAlive: false, //optional - disable keep alive pool
20+
enableTimings: false //optional - adds time object to response of yildiz.raw()
21+
timeoutMs: 7500 //optional - timeout in milliseconds for the request
1922
});
2023

2124
(async () => {

lib/HttpClient.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ class HttpClient {
1616
proto,
1717
host,
1818
port,
19-
token
19+
token,
20+
disableKeepAlive,
21+
enableTimings,
22+
timeoutMs
2023
} = config;
2124

2225
prefix = prefix || DEFAULT_PREFIX;
2326

24-
this._agent = new http.Agent({
25-
keepAlive: true,
26-
keepAliveMsecs: 3000,
27-
maxSockets: 200,
28-
maxFreeSockets: 150
29-
});
27+
this._agent = undefined;
28+
if(disableKeepAlive !== true){
29+
this._agent = new http.Agent({
30+
keepAlive: true,
31+
keepAliveMsecs: 3000,
32+
maxSockets: 200,
33+
maxFreeSockets: 150
34+
});
35+
}
3036

31-
this.timeoutMs = 7500;
37+
this.timeoutMs = timeoutMs || 7500;
3238

33-
this._req = getInstance(prefix, token, proto, host, port, this._agent);
39+
this._req = getInstance(prefix, token, proto, host, port, this._agent, enableTimings);
3440
debug(`${proto}://${host}:${port} via prefix = ${prefix}.`);
3541
}
3642

lib/promRequest.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Promise = require("bluebird");
44
const request = require("request");
55
const debug = require("debug")("yildiz:http:pr");
66

7-
const reqProm = (prefix, token, proto, host, port, path = "/", options = {}, agent = undefined, expectedStatusCode = null) => {
7+
const reqProm = (prefix, token, proto, host, port, path = "/", options = {}, agent = undefined, timings = false, expectedStatusCode = null) => {
88

99
options.url = `${proto}://${host}:${port}${path}`;
1010

@@ -28,7 +28,13 @@ const reqProm = (prefix, token, proto, host, port, path = "/", options = {}, age
2828
}
2929

3030
//keep-alive
31-
options.agent = agent;
31+
if(agent){
32+
options.agent = agent;
33+
}
34+
35+
if(timings){
36+
options.time = true;
37+
}
3238

3339
return new Promise((resolve, reject) => {
3440
request(options, (error, response, body) => {
@@ -46,6 +52,20 @@ const reqProm = (prefix, token, proto, host, port, path = "/", options = {}, age
4652
//empty
4753
}
4854

55+
const responseData = {
56+
time: null
57+
};
58+
59+
if(timings){
60+
responseData.time = {
61+
elapsedTime: response.elapsedTime,
62+
responseStartTime: response.responseStartTime,
63+
timingStart: response.timingStart,
64+
timings: response.timings,
65+
timingPhases: response.timingPhases
66+
};
67+
}
68+
4969
if(expectedStatusCode && response.statusCode !== expectedStatusCode){
5070

5171
let errorMessage = "No error message present in body";
@@ -58,19 +78,19 @@ const reqProm = (prefix, token, proto, host, port, path = "/", options = {}, age
5878
return reject(new Error(`Response status code: ${response.statusCode} does match expected status code: ${expectedStatusCode}. ${errorMessage}.`));
5979
}
6080

61-
resolve({
81+
resolve(Object.assign(responseData, {
6282
status: response.statusCode,
6383
headers: response.headers,
6484
body: parsedBody
65-
});
85+
}));
6686
});
6787
});
6888
};
6989

7090
module.exports = {
71-
getInstance: (prefix, token, proto = "http", host = "localhost", port = 3058, agent = undefined) => {
91+
getInstance: (prefix, token, proto = "http", host = "localhost", port = 3058, agent = undefined, timings = false) => {
7292
return (path, options, expectedStatusCode) => {
73-
return reqProm(prefix, token, proto, host, port, path, options, agent, expectedStatusCode);
93+
return reqProm(prefix, token, proto, host, port, path, options, agent, timings, expectedStatusCode);
7494
};
7595
}
7696
};

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yildiz-js",
3-
"version": "2.8.0",
3+
"version": "2.9.0",
44
"description": "Client for yildiz graph database",
55
"main": "index.js",
66
"scripts": {
@@ -26,11 +26,11 @@
2626
"dependencies": {
2727
"bluebird": "^3.5.1",
2828
"debug": "^3.1.0",
29-
"request": "^2.83.0"
29+
"request": "^2.85.0"
3030
},
3131
"devDependencies": {
3232
"body-parser": "^1.18.2",
33-
"express": "^4.16.2",
34-
"mocha": "^4.0.1"
33+
"express": "^4.16.3",
34+
"mocha": "^5.0.4"
3535
}
3636
}

test/int/Client.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ describe("Client INT", () => {
1414
const client = new HttpClient({
1515
proto: "http",
1616
host: "localhost",
17-
port
17+
port,
18+
disableKeepAlive: false,
19+
enableTimings: true
1820
});
1921

2022
before(done => {

0 commit comments

Comments
 (0)