Skip to content

Commit ec4e28f

Browse files
author
William
authored
Merge pull request #8 from scality/improvement/ARSNN-2-convert-project-to-JS
Improvement/arsnn 2 convert project to js
2 parents e14a16f + 435c743 commit ec4e28f

File tree

16 files changed

+169
-432
lines changed

16 files changed

+169
-432
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
index.d.ts

.eslintrc.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es2021: true,
6+
},
7+
extends: 'airbnb-base',
8+
overrides: [
9+
],
10+
parserOptions: {
11+
ecmaVersion: 'latest',
12+
},
13+
rules: {
14+
},
15+
};

.eslintrc.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/tests.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ jobs:
3232
run: yarn install --frozen-lockfile
3333
- name: run lint
3434
run: yarn run eslint
35-
- name: run build
36-
run: yarn build
35+

index.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as http from 'http';
2+
import * as https from 'https';
3+
import { HttpAgent, HttpsAgent } from 'agentkeepalive';
4+
5+
import { HttpsOptions, HttpOptions } from 'agentkeepalive';
6+
7+
declare namespace http {
8+
export interface clientConfigurationDefault {
9+
/**
10+
* Maximum Socket Number: true if TCP session reuse must be enabled
11+
*/
12+
maxSockets?: boolean;
13+
}
14+
15+
export class Agent extends HttpAgent {
16+
constructor(opts?: HttpOptions, config?: clientConfigurationDefault);
17+
}
18+
}
19+
20+
declare namespace https {
21+
export interface clientConfigurationDefault {
22+
/**
23+
* Maximum Socket Number: true if TCP session reuse must be enabled
24+
*/
25+
maxSockets?: boolean;
26+
}
27+
28+
export class Agent extends HttpsAgent {
29+
constructor(opts?: HttpsOptions, config?: clientConfigurationDefault);
30+
}
31+
}
32+
33+
exports.http = http;
34+
exports.https = https;

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable global-require */
2+
3+
exports.http = {
4+
Agent: require('./lib/http-agent').default,
5+
};
6+
7+
exports.https = {
8+
Agent: require('./lib/https-agent').default,
9+
};
10+
11+
exports.AgentConfiguration = require('./lib/config/agentConfiguration').default;

index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as http from 'http';
2-
31
/**
42
* The maximum socket configuration defaults to 50.
53
*/
@@ -10,10 +8,10 @@ const maxSocketsNumber = Number(process.env.MAX_SOCKETS) || 50;
108
* The goal is to enforce a `maxSockets` property to properly
119
* handle load.
1210
*/
13-
const agentConfiguration: http.AgentOptions = {
14-
keepAlive: true,
15-
maxSockets: maxSocketsNumber,
16-
maxFreeSockets: maxSocketsNumber,
17-
}
11+
const agentConfiguration = {
12+
keepAlive: true,
13+
maxSockets: maxSocketsNumber,
14+
maxFreeSockets: maxSocketsNumber,
15+
};
1816

19-
export default agentConfiguration;
17+
exports.default = agentConfiguration;

lib/config/default.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/http-agent.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const HttpAgent = require('agentkeepalive');
2+
const agentConfiguration = require('./config/agentConfiguration');
3+
4+
/**
5+
* @class AgentHttp
6+
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
7+
* networking configuration across components.
8+
*/
9+
class AgentHttp extends HttpAgent {
10+
/**
11+
* Constructor for the AgentHttp class
12+
*
13+
* @param opts - Custom HTTP Agent options
14+
* @param config - user-defined default configuration to apply
15+
*/
16+
constructor(opts, config = {
17+
maxSockets: true,
18+
}) {
19+
// Enforce TCP session reuse configuration, unless explicitely specified.
20+
let defaultConfigurations = {};
21+
if (config.maxSockets) {
22+
defaultConfigurations = agentConfiguration;
23+
}
24+
super({ ...opts, ...defaultConfigurations });
25+
}
26+
}
27+
28+
exports.default = AgentHttp;

0 commit comments

Comments
 (0)