From 7c9424cf2433f8ac16a4031b270f1754cfcf2e52 Mon Sep 17 00:00:00 2001 From: Timur Amirov Date: Tue, 27 Mar 2018 22:20:29 +0200 Subject: [PATCH] curcuit-breaker-js: introduce @types/curcuit-breaker-js --- .../circuit-breaker-js-tests.ts | 12 ++++++ types/circuit-breaker-js/index.d.ts | 38 +++++++++++++++++++ types/circuit-breaker-js/tsconfig.json | 23 +++++++++++ types/circuit-breaker-js/tslint.json | 1 + 4 files changed, 74 insertions(+) create mode 100644 types/circuit-breaker-js/circuit-breaker-js-tests.ts create mode 100644 types/circuit-breaker-js/index.d.ts create mode 100644 types/circuit-breaker-js/tsconfig.json create mode 100644 types/circuit-breaker-js/tslint.json diff --git a/types/circuit-breaker-js/circuit-breaker-js-tests.ts b/types/circuit-breaker-js/circuit-breaker-js-tests.ts new file mode 100644 index 0000000000..1436e13e90 --- /dev/null +++ b/types/circuit-breaker-js/circuit-breaker-js-tests.ts @@ -0,0 +1,12 @@ +import CircuitBreaker = require('circuit-breaker-js'); + +const breaker = new CircuitBreaker(); +breaker.isOpen(); + +const options: CircuitBreaker.Options = {}; + +let status: number = CircuitBreaker.CLOSED; +status = CircuitBreaker.OPEN; + +breaker.forceOpen(); +breaker.forceClose(); diff --git a/types/circuit-breaker-js/index.d.ts b/types/circuit-breaker-js/index.d.ts new file mode 100644 index 0000000000..6fc58bd40d --- /dev/null +++ b/types/circuit-breaker-js/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for circuit-breaker-js 0.0 +// Project: http://yammer.github.io/circuit-breaker-js/ +// Definitions by: Timur Amirov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = CircuitBreaker; + +declare namespace CircuitBreaker { + interface Options { + windowDuration?: number; + numBuckets?: number; + timeoutDuration?: number; + errorThreshold?: number; + volumeThreshold?: number; + + onCircuitOpen?: (m: Metrics) => void; + onCircuitClose?: (m: Metrics) => void; + } + + interface Metrics { + totalCount: number; + errorCount: number; + errorPercentage: number; + } +} + +declare class CircuitBreaker { + static OPEN: 0; + static HALF_OPEN: 1; + static CLOSED: 2; + + constructor(options?: CircuitBreaker.Options); + run(command: () => void, fallback?: () => void): void; + forceClose(): void; + forceOpen(): void; + unforce(): void; + isOpen(): boolean; +} diff --git a/types/circuit-breaker-js/tsconfig.json b/types/circuit-breaker-js/tsconfig.json new file mode 100644 index 0000000000..67d9c57cc0 --- /dev/null +++ b/types/circuit-breaker-js/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", + "circuit-breaker-js-tests.ts" + ] +} diff --git a/types/circuit-breaker-js/tslint.json b/types/circuit-breaker-js/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/circuit-breaker-js/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }