diff --git a/types/opossum/index.d.ts b/types/opossum/index.d.ts new file mode 100644 index 0000000000..bcdc262d99 --- /dev/null +++ b/types/opossum/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for opossum 1.8 +// Project: https://github.com/bucharest-gold/opossum +// Definitions by: Quinn Langille +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/// +import * as stream from "stream"; + +export type Action = () => any; + +export class CircuitBreaker { + promisify(action: Action): Promise; + stats(): stream.Transform; +} + +export interface CircuitBreakerOptions { + timeout?: number; + maxFailures?: number; + resetTimeout?: number; + rollingCountTimeout?: number; + rollingCountBuckets?: number; + name?: string; + rollingPercentilesEnabled?: boolean; + capacity?: number; + errorThresholdPercentage?: number; + enabled?: boolean; + allowWarmUp?: boolean; +} + +export default function circuitBreaker( + action: Action, + options?: CircuitBreakerOptions +): CircuitBreaker; diff --git a/types/opossum/opossum-tests.ts b/types/opossum/opossum-tests.ts new file mode 100644 index 0000000000..22778147e5 --- /dev/null +++ b/types/opossum/opossum-tests.ts @@ -0,0 +1,24 @@ +import { Transform } from "stream"; +import circuitBreaker, { CircuitBreaker, CircuitBreakerOptions } from "opossum"; + +const _blank = () => {}; + +const testNoOptions: CircuitBreaker = circuitBreaker(_blank); + +const options: CircuitBreakerOptions = { + timeout: 1, + maxFailures: 1, + resetTimeout: 1, + rollingCountTimeout: 1, + rollingCountBuckets: 1, + name: "testing", + rollingPercentilesEnabled: true, + capacity: 1, + errorThresholdPercentage: 1, + enabled: true, + allowWarmUp: true +}; + +const testWithOptions: CircuitBreaker = circuitBreaker(_blank, options); +const shouldBeAPromise: Promise = testWithOptions.promisify(_blank); +const shouldBeATransformStream: Transform = testWithOptions.stats(); diff --git a/types/opossum/tsconfig.json b/types/opossum/tsconfig.json new file mode 100644 index 0000000000..7ddf39bf63 --- /dev/null +++ b/types/opossum/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "opossum-tests.ts" + ] +} diff --git a/types/opossum/tslint.json b/types/opossum/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/opossum/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }