Compare commits

...

10 Commits

Author SHA1 Message Date
Vitaliy Filippov 32b843aaf3 Change git dependency URLs 2024-07-21 17:37:36 +03:00
William 66e97ab935
Merge pull request #9 from scality/improvement/ARSNN-2-fixup-declarations
Improvement/arsnn 2 fixup declarations
2022-12-14 17:14:27 +01:00
williamlardier 8425d23e04
ARSNN-2: bump project version 2022-12-14 17:12:36 +01:00
williamlardier 2e3d13c5b9
ARSNN-2: fixups for declarations 2022-12-14 17:12:18 +01:00
William ec4e28f050
Merge pull request #8 from scality/improvement/ARSNN-2-convert-project-to-JS
Improvement/arsnn 2 convert project to js
2022-12-14 14:58:52 +01:00
williamlardier 435c7436d0
ARSNN-2: bump project to 1.0.5 2022-12-14 14:12:33 +01:00
williamlardier aae50a9096
ARSNN-2: export declarations 2022-12-14 14:12:30 +01:00
williamlardier 1881146b28
ARSNN-2: cleanups for eslint and exports 2022-12-14 11:44:18 +01:00
williamlardier 6c600cd02f
ARSNN-2: convert files to JS and update environment 2022-12-14 11:33:12 +01:00
williamlardier 72108aed4f
ARSNN-2: remove TS files 2022-12-14 11:32:45 +01:00
16 changed files with 126 additions and 1651 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
index.d.ts

15
.eslintrc.cjs Normal file
View File

@ -0,0 +1,15 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: 'airbnb-base',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
},
};

View File

@ -1,23 +0,0 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": ["build/**/*.js", "build/**/*.d.ts"],
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}

View File

@ -32,5 +32,4 @@ jobs:
run: yarn install --frozen-lockfile run: yarn install --frozen-lockfile
- name: run lint - name: run lint
run: yarn run eslint run: yarn run eslint
- name: run build
run: yarn build

29
index.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
import HttpAgent, { HttpsAgent } from 'agentkeepalive';
import { HttpsOptions, HttpOptions } from 'agentkeepalive';
declare namespace http {
export interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}
export class Agent extends HttpAgent {
constructor(opts?: HttpOptions, config?: clientConfigurationDefault);
}
}
declare namespace https {
export interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}
export class Agent extends HttpsAgent {
constructor(opts?: HttpsOptions, config?: clientConfigurationDefault);
}
}

11
index.js Normal file
View File

@ -0,0 +1,11 @@
/* eslint-disable global-require */
exports.http = {
Agent: require('./lib/http-agent').default,
};
exports.https = {
Agent: require('./lib/https-agent').default,
};
exports.AgentConfiguration = require('./lib/config/agentConfiguration').default;

View File

@ -1,13 +0,0 @@
import agentConfiguration from "./lib/config/agentConfiguration";
import httpAgent from "./lib/http-agent";
import httpsAgent from "./lib/https-agent";
export const http = {
Agent: httpAgent,
};
export const https = {
Agent: httpsAgent,
};
export const AgentConfiguration = agentConfiguration;

View File

@ -1,5 +1,3 @@
import * as http from 'http';
/** /**
* The maximum socket configuration defaults to 50. * The maximum socket configuration defaults to 50.
*/ */
@ -10,10 +8,10 @@ const maxSocketsNumber = Number(process.env.MAX_SOCKETS) || 50;
* The goal is to enforce a `maxSockets` property to properly * The goal is to enforce a `maxSockets` property to properly
* handle load. * handle load.
*/ */
const agentConfiguration: http.AgentOptions = { const agentConfiguration = {
keepAlive: true, keepAlive: true,
maxSockets: maxSocketsNumber, maxSockets: maxSocketsNumber,
maxFreeSockets: maxSocketsNumber, maxFreeSockets: maxSocketsNumber,
} };
export default agentConfiguration; exports.default = agentConfiguration;

View File

@ -1,6 +0,0 @@
export default interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}

28
lib/http-agent.js Normal file
View File

@ -0,0 +1,28 @@
const HttpAgent = require('agentkeepalive');
const agentConfiguration = require('./config/agentConfiguration');
/**
* @class AgentHttp
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
* networking configuration across components.
*/
class AgentHttp extends HttpAgent {
/**
* Constructor for the AgentHttp class
*
* @param opts - Custom HTTP Agent options
* @param config - user-defined default configuration to apply
*/
constructor(opts, config = {
maxSockets: true,
}) {
// Enforce TCP session reuse configuration, unless explicitely specified.
let defaultConfigurations = {};
if (config.maxSockets) {
defaultConfigurations = agentConfiguration;
}
super({ ...opts, ...defaultConfigurations });
}
}
exports.default = AgentHttp;

View File

@ -1,33 +0,0 @@
import HttpAgent, { HttpOptions } from 'agentkeepalive';
import clientConfigurationDefault from './config/default';
import agentConfiguration from './config/agentConfiguration';
/**
* @class AgentHttp
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
* networking configuration across components.
*/
export default class AgentHttp extends HttpAgent {
/**
* Constructor for the AgentHttp class
*
* @param opts - Custom HTTP Agent options
* @param config - user-defined default configuration to apply
*/
constructor(
opts?: HttpOptions,
config: clientConfigurationDefault = {
maxSockets: true,
},
) {
// Enforce TCP session reuse configuration, unless explicitely specified.
let defaultConfigurations: HttpOptions = {};
if (config.maxSockets) {
defaultConfigurations = agentConfiguration;
}
super({
...opts,
...defaultConfigurations,
});
}
}

28
lib/https-agent.js Normal file
View File

@ -0,0 +1,28 @@
const { HttpsAgent } = require('agentkeepalive');
const agentConfiguration = require('./config/agentConfiguration');
/**
* @class AgentHttps
* Abstracts the native HttpsAgent class from agentkeepalive to enforce common
* networking configuration across components.
*/
class AgentHttps extends HttpsAgent {
/**
* Constructor for the AgentHttps class
*
* @param opts - Custom HTTPs Agent options
* @param config - user-defined default configuration to apply
*/
constructor(opts, config = {
maxSockets: true,
}) {
// Enforce TCP session reuse configuration, unless explicitely specified.
let defaultConfigurations = {};
if (config.maxSockets) {
defaultConfigurations = agentConfiguration;
}
super({ ...opts, ...defaultConfigurations });
}
}
exports.default = AgentHttps;

View File

@ -1,33 +0,0 @@
import { HttpsAgent, HttpsOptions } from 'agentkeepalive';
import clientConfigurationDefault from './config/default';
import agentConfiguration from './config/agentConfiguration';
/**
* @class AgentHttps
* Abstracts the native HttpsAgent class from agentkeepalive to enforce common
* networking configuration across components.
*/
export default class AgentHttps extends HttpsAgent {
/**
* Constructor for the AgentHttps class
*
* @param opts - Custom HTTPs Agent options
* @param config - user-defined default configuration to apply
*/
constructor(
opts?: HttpsOptions,
config: clientConfigurationDefault = {
maxSockets: true,
},
) {
// Enforce TCP session reuse configuration, unless explicitely specified.
let defaultConfigurations: HttpsOptions = {};
if (config.maxSockets) {
defaultConfigurations = agentConfiguration;
}
super({
...opts,
...defaultConfigurations,
});
}
}

View File

@ -1,37 +1,30 @@
{ {
"name": "httpagent", "name": "httpagent",
"version": "1.0.4", "version": "1.0.6",
"engines": { "engines": {
"node": ">=16" "node": ">=16"
}, },
"description": "A utility library for networking", "description": "A utility library for networking",
"main": "build/index.js", "main": "index.js",
"repository": "git@github.com:scality/httpagent.git", "repository": "git@github.com:scality/httpagent.git",
"author": "Scality Inc.", "author": "Scality Inc.",
"license": "Apache-2.0", "license": "Apache-2.0",
"scripts": { "scripts": {
"build": "tsc --declaration; tsc --build tsconfig.json",
"format": "prettier --write \"**/*.{ts,tsx,css,html}\" ", "format": "prettier --write \"**/*.{ts,tsx,css,html}\" ",
"prepare": "yarn build || true",
"eslint": "eslint ./ --ext .js,.ts,.tsx", "eslint": "eslint ./ --ext .js,.ts,.tsx",
"eslint-fix": "eslint ./ --ext .js,.ts,.tsx --fix", "eslint-fix": "eslint ./ --ext .js,.ts,.tsx --fix",
"eslint-init": "eslint --init", "eslint-init": "eslint --init"
"lint": "eslint ./ --ext .js,.ts,.tsx --format visualstudio --no-color --max-warnings 10 --report-unused-disable-directives"
}, },
"dependencies": { "dependencies": {
"@types/node": "^18.11.9",
"agentkeepalive": "^4.2.1" "agentkeepalive": "^4.2.1"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.44.0", "eslint": "^7.32.0 || ^8.2.0",
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-config-scality": "git+https://github.com/scality/Guidelines#8.2.0", "eslint-config-scality": "git+https://git.yourcmc.ru/vitalif/zenko-eslint-config-scality.git",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.0", "prettier": "^2.8.0"
"typescript": "^4.9.3"
} }
} }

View File

@ -1,22 +0,0 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"rootDir": "./",
"resolveJsonModule": true,
"allowJs": true,
"checkJs": false,
"outDir": "build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"declaration": true,
"noImplicitAny": false,
"noEmitOnError": false,
"sourceMap": true,
"declarationMap": true
},
"include": ["index.ts", "lib/**/*"],
"exclude": ["node_modules/*"],
"compileOnSave": true
}

1497
yarn.lock

File diff suppressed because it is too large Load Diff