diff --git a/README.md b/README.md index d02fe2b..4ced70c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![CI](https://github.com/fastify/fastify-circuit-breaker/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-circuit-breaker/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/circuit-breaker.svg?style=flat)](https://www.npmjs.com/package/@fastify/circuit-breaker) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) +[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) A low overhead [circuit breaker](https://martinfowler.com/bliki/CircuitBreaker.html) for your routes. diff --git a/package.json b/package.json index ea4a63a..8688f0b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "types": "types/index.d.ts", "type": "commonjs", "scripts": { - "lint": "standard", + "lint": "eslint", + "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:unit": "c8 -100 node --test", "test:typescript": "tsd" @@ -30,7 +31,7 @@ "@types/node": "^22.0.0", "c8": "^10.1.2", "fastify": "^5.0.0", - "standard": "^17.1.0", + "neostandard": "^0.11.9", "tsd": "^0.31.1" }, "dependencies": { diff --git a/types/index.d.ts b/types/index.d.ts index 3d1e693..bd15b3d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,10 +3,10 @@ import { FastifyRequest, FastifyReply, HookHandlerDoneFunction, -} from "fastify"; -import { Stream } from "node:stream"; +} from 'fastify' +import { Stream } from 'node:stream' -declare module "fastify" { +declare module 'fastify' { interface FastifyInstance { circuitBreaker( options?: fastifyCircuitBreaker.FastifyCircuitBreakerOptions @@ -14,7 +14,7 @@ declare module "fastify" { } } -type FastifyCircuitBreaker = FastifyPluginCallback; +type FastifyCircuitBreaker = FastifyPluginCallback declare namespace fastifyCircuitBreaker { export interface FastifyCircuitBreakerBeforeHandler { @@ -75,10 +75,10 @@ declare namespace fastifyCircuitBreaker { * @default 500 */ cache?: number; - }; + } export const fastifyCircuitBreaker: FastifyCircuitBreaker export { fastifyCircuitBreaker as default } } -declare function fastifyCircuitBreaker(...params: Parameters): ReturnType +declare function fastifyCircuitBreaker (...params: Parameters): ReturnType export = fastifyCircuitBreaker diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 92e0329..a4bc18b 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,36 +1,36 @@ -import fastify, { FastifyReply, FastifyRequest } from "fastify"; -import { expectType } from "tsd"; -import FastifyCircuitBreaker, { FastifyCircuitBreakerOptions } from ".."; +import fastify, { FastifyReply, FastifyRequest } from 'fastify' +import { expectType } from 'tsd' +import FastifyCircuitBreaker, { FastifyCircuitBreakerOptions } from '..' -const app = fastify(); +const app = fastify() -app.register(FastifyCircuitBreaker); -app.register(FastifyCircuitBreaker, {}); -app.register(FastifyCircuitBreaker, { timeout: 5000 }); -app.register(FastifyCircuitBreaker, { threshold: 5 }); -app.register(FastifyCircuitBreaker, { resetTimeout: 10000 }); +app.register(FastifyCircuitBreaker) +app.register(FastifyCircuitBreaker, {}) +app.register(FastifyCircuitBreaker, { timeout: 5000 }) +app.register(FastifyCircuitBreaker, { threshold: 5 }) +app.register(FastifyCircuitBreaker, { resetTimeout: 10000 }) app.register(FastifyCircuitBreaker, { timeout: 5000, threshold: 5, resetTimeout: 10000, -}); +}) const fastifyCircuitBreakerOptions: FastifyCircuitBreakerOptions = { timeout: 5000, threshold: 5, resetTimeout: 10000, -}; -app.register(FastifyCircuitBreaker, fastifyCircuitBreakerOptions); +} +app.register(FastifyCircuitBreaker, fastifyCircuitBreakerOptions) app.get( - "/", + '/', { preHandler: app.circuitBreaker(), }, (req, reply) => { } -); +) -app.register(FastifyCircuitBreaker, { timeoutErrorMessage: 'Timeon' }); +app.register(FastifyCircuitBreaker, { timeoutErrorMessage: 'Timeon' }) app.register(FastifyCircuitBreaker, { onTimeout: async (req, reply) => { expectType(req) @@ -39,7 +39,7 @@ app.register(FastifyCircuitBreaker, { reply.statusCode = statusCode throw new Error('timed out') } -}); +}) app.register(FastifyCircuitBreaker, { onTimeout: (req, reply) => { expectType(req) @@ -47,7 +47,7 @@ app.register(FastifyCircuitBreaker, { reply.statusCode = 504 return 'timed out' } -}); +}) app.register(FastifyCircuitBreaker, { onTimeout: async (req, reply) => { expectType(req) @@ -55,9 +55,9 @@ app.register(FastifyCircuitBreaker, { reply.statusCode = 504 return 'timed out' } -}); +}) -app.register(FastifyCircuitBreaker, { circuitOpenErrorMessage: 'circus open' }); +app.register(FastifyCircuitBreaker, { circuitOpenErrorMessage: 'circus open' }) app.register(FastifyCircuitBreaker, { onCircuitOpen: async (req, reply) => { expectType(req) @@ -66,7 +66,7 @@ app.register(FastifyCircuitBreaker, { reply.statusCode = statusCode throw new Error('circuit open') } -}); +}) app.register(FastifyCircuitBreaker, { onCircuitOpen: (req, reply) => { expectType(req) @@ -74,7 +74,7 @@ app.register(FastifyCircuitBreaker, { reply.statusCode = 504 return 'circuit open' } -}); +}) app.register(FastifyCircuitBreaker, { onCircuitOpen: async (req, reply) => { expectType(req) @@ -82,4 +82,4 @@ app.register(FastifyCircuitBreaker, { reply.statusCode = 504 return 'circuit open' } -}); +})