mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
new types for package "overload-protection" (#42886)
* types for overload-protection * prettier formatting * added parameter type for logging function Co-authored-by: Daniel Hirth <daniel.hirth@wolterskluwer.com>
This commit is contained in:
51
types/overload-protection/index.d.ts
vendored
Normal file
51
types/overload-protection/index.d.ts
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// Type definitions for overload-protection 1.2
|
||||
// Project: https://github.com/davidmarkclements/overload-protection
|
||||
// Definitions by: Daniel Hirth <https://github.com/dornfeder>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace protect {
|
||||
type KoaFrameworkSelection = 'koa';
|
||||
type HttpFrameworkSelection = 'express' | 'http' | 'restify';
|
||||
|
||||
interface ProtectionConfig {
|
||||
production?: boolean;
|
||||
clientRetrySecs?: number;
|
||||
sampleInterval?: number;
|
||||
maxEventLoopDelay?: number;
|
||||
maxHeapUsedBytes?: number;
|
||||
maxRssBytes?: number;
|
||||
errorPropagationMode?: boolean;
|
||||
logging?: boolean | string | ((msg: string) => void);
|
||||
logStatsOnReq?: false;
|
||||
}
|
||||
|
||||
interface ProtectionInstance {
|
||||
overload: boolean;
|
||||
eventLoopOverload: boolean;
|
||||
heapUsedOverload: boolean;
|
||||
rssOverload: boolean;
|
||||
eventLoopDelay: number;
|
||||
maxEventLoopDelay: number;
|
||||
maxHeapUsedBytes: number;
|
||||
maxRssBytes: number;
|
||||
}
|
||||
|
||||
interface KoaProtectionInstance extends ProtectionInstance {
|
||||
(ctx: object, next: () => any): any;
|
||||
}
|
||||
|
||||
interface HttpProtectionInstance extends ProtectionInstance {
|
||||
(req: object, res: object, next: () => any): any;
|
||||
}
|
||||
}
|
||||
|
||||
declare function protect(
|
||||
framework: protect.KoaFrameworkSelection,
|
||||
config?: protect.ProtectionConfig,
|
||||
): protect.KoaProtectionInstance;
|
||||
declare function protect(
|
||||
framework: protect.HttpFrameworkSelection,
|
||||
config?: protect.ProtectionConfig,
|
||||
): protect.HttpProtectionInstance;
|
||||
|
||||
export = protect;
|
||||
40
types/overload-protection/overload-protection-tests.ts
Normal file
40
types/overload-protection/overload-protection-tests.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import op = require('overload-protection');
|
||||
|
||||
const config1: op.ProtectionConfig = {
|
||||
production: true,
|
||||
clientRetrySecs: 2,
|
||||
sampleInterval: 1,
|
||||
maxEventLoopDelay: 40,
|
||||
maxHeapUsedBytes: 25,
|
||||
maxRssBytes: 321,
|
||||
errorPropagationMode: true,
|
||||
logging: console.log,
|
||||
logStatsOnReq: false,
|
||||
};
|
||||
|
||||
const config2: op.ProtectionConfig = {
|
||||
logging: false,
|
||||
};
|
||||
|
||||
const config3: op.ProtectionConfig = {
|
||||
logging: 'warn',
|
||||
};
|
||||
|
||||
const instance = op('koa');
|
||||
|
||||
console.log(instance);
|
||||
console.log(instance({ foo: 'bar' }, () => 'Hello'));
|
||||
console.log(instance.overload);
|
||||
console.log(instance.eventLoopOverload);
|
||||
console.log(instance.heapUsedOverload);
|
||||
console.log(instance.rssOverload);
|
||||
console.log(instance.eventLoopDelay);
|
||||
console.log(instance.maxEventLoopDelay);
|
||||
console.log(instance.maxHeapUsedBytes);
|
||||
console.log(instance.maxRssBytes);
|
||||
|
||||
const instance2 = op('express', config1);
|
||||
console.log(instance2({ foo: 'bar' }, { hello: 'world' }, () => 'World'));
|
||||
|
||||
op('http', config2);
|
||||
op('restify', config3);
|
||||
24
types/overload-protection/tsconfig.json
Normal file
24
types/overload-protection/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"overload-protection-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/overload-protection/tslint.json
Normal file
1
types/overload-protection/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user