@fastify/circuit-breaker
Advanced tools
Comparing version 3.1.0 to 3.2.0
{ | ||
"name": "@fastify/circuit-breaker", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "A low overhead circuit breaker for your routes", | ||
@@ -34,3 +34,3 @@ "main": "index.js", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.24.1" | ||
"tsd": "^0.25.0" | ||
}, | ||
@@ -37,0 +37,0 @@ "dependencies": { |
@@ -7,2 +7,3 @@ import { | ||
} from "fastify"; | ||
import { Stream } from "node:stream"; | ||
@@ -34,2 +35,3 @@ declare module "fastify" { | ||
threshold?: number; | ||
/** | ||
@@ -46,2 +48,34 @@ * The maximum number of milliseconds you can wait before return a `TimeoutError`. | ||
resetTimeout?: number; | ||
/** | ||
* Gets called when the circuit is `open` due to timeouts. | ||
* It can modify the reply and return a `string` | `Buffer` | `Stream` | | ||
* `Error` payload. If an `Error` is thrown it will be routed to your error | ||
* handler. | ||
*/ | ||
onTimeout?: (request: FastifyRequest, reply: FastifyReply) => void | string | Buffer | Stream | Error | Promise<void | string | Buffer | Stream | Error>; | ||
/** | ||
* | ||
* @default 'Timeout' | ||
*/ | ||
timeoutErrorMessage?: string; | ||
/** | ||
* Gets called when the circuit is `open` due to errors. | ||
* It can modify the reply and return a `string` | `Buffer` | `Stream` | ||
* payload. If an `Error` is thrown it will be routed to your error handler. | ||
*/ | ||
onCircuitOpen?: (request: FastifyRequest, reply: FastifyReply) => void | string | Buffer | Stream | Promise<void | string | Buffer | Stream>; | ||
/** | ||
* @default 'Circuit open' | ||
*/ | ||
circuitOpenErrorMessage?: string; | ||
/** | ||
* The amount of cached requests. | ||
* @default 500 | ||
*/ | ||
cache?: number; | ||
}; | ||
@@ -48,0 +82,0 @@ export const fastifyCircuitBreaker: FastifyCircuitBreaker |
@@ -1,2 +0,3 @@ | ||
import fastify from "fastify"; | ||
import fastify, { FastifyReply, FastifyRequest } from "fastify"; | ||
import { expectType } from "tsd"; | ||
import FastifyCircuitBreaker, { FastifyCircuitBreakerOptions } from ".."; | ||
@@ -29,3 +30,57 @@ | ||
}, | ||
(req, reply) => {} | ||
(req, reply) => { } | ||
); | ||
app.register(FastifyCircuitBreaker, { timeoutErrorMessage: 'Timeon' }); | ||
app.register(FastifyCircuitBreaker, { | ||
onTimeout: async (req, reply) => { | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
const statusCode = await Promise.resolve(504) | ||
reply.statusCode = statusCode | ||
throw new Error('timed out') | ||
} | ||
}); | ||
app.register(FastifyCircuitBreaker, { | ||
onTimeout: (req, reply) => { | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
reply.statusCode = 504 | ||
return 'timed out' | ||
} | ||
}); | ||
app.register(FastifyCircuitBreaker, { | ||
onTimeout: async (req, reply) => { | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
reply.statusCode = 504 | ||
return 'timed out' | ||
} | ||
}); | ||
app.register(FastifyCircuitBreaker, { circuitOpenErrorMessage: 'circus open' }); | ||
app.register(FastifyCircuitBreaker, { | ||
onCircuitOpen: async (req, reply) => { | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
const statusCode = await Promise.resolve(504) | ||
reply.statusCode = statusCode | ||
throw new Error('circuit open') | ||
} | ||
}); | ||
app.register(FastifyCircuitBreaker, { | ||
onCircuitOpen: (req, reply) => { | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
reply.statusCode = 504 | ||
return 'circuit open' | ||
} | ||
}); | ||
app.register(FastifyCircuitBreaker, { | ||
onCircuitOpen: async (req, reply) => { | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
reply.statusCode = 504 | ||
return 'circuit open' | ||
} | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34818
939
1