Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodenext compatibility #187

Merged
merged 3 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ module.exports = fp(underPressure, {
fastify: '4.x',
name: '@fastify/under-pressure'
})
module.exports.default = underPressure
module.exports.underPressure = underPressure
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

module.exports.TYPE_EVENT_LOOP_DELAY = TYPE_EVENT_LOOP_DELAY
module.exports.TYPE_EVENT_LOOP_UTILIZATION = TYPE_EVENT_LOOP_UTILIZATION
Expand Down
36 changes: 19 additions & 17 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import {
FastifyInstance,
FastifyPluginCallback,
FastifyPluginAsync,
FastifyReply,
FastifyRequest
} from "fastify";

export const TYPE_EVENT_LOOP_DELAY = 'eventLoopDelay'
export const TYPE_HEAP_USED_BYTES = 'heapUsedBytes'
export const TYPE_RSS_BYTES = 'rssBytes'
export const TYPE_HEALTH_CHECK = 'healthCheck'
export const TYPE_EVENT_LOOP_UTILIZATION = 'eventLoopUtilization'
declare module "fastify" {
interface FastifyInstance {
memoryUsage(): { heapUsed: number; rssBytes: number; eventLoopDelay: number; eventLoopUtilized: number };
}
}

type UnderPressure = FastifyPluginAsync<underPressure.UnderPressureOptions>;

declare namespace underPressure {
interface UnderPressureOptions {
export const TYPE_EVENT_LOOP_DELAY = 'eventLoopDelay'
export const TYPE_HEAP_USED_BYTES = 'heapUsedBytes'
export const TYPE_RSS_BYTES = 'rssBytes'
export const TYPE_HEALTH_CHECK = 'healthCheck'
export const TYPE_EVENT_LOOP_UTILIZATION = 'eventLoopUtilization'

export interface UnderPressureOptions {
maxEventLoopDelay?: number;
maxEventLoopUtilization?: number;
maxHeapUsedBytes?: number;
Expand All @@ -26,16 +34,10 @@ declare namespace underPressure {
exposeStatusRoute?: boolean | string | { routeOpts: object; routeSchemaOpts?: object; routeResponseSchemaOpts?: object; url?: string };
customError?: Error;
}
}

declare module "fastify" {
interface FastifyInstance {
memoryUsage(): { heapUsed: number; rssBytes: number; eventLoopDelay: number; eventLoopUtilized: number };
}
export const underPressure: UnderPressure
export { underPressure as default }
}

declare let underPressure: FastifyPluginCallback<
underPressure.UnderPressureOptions
>;

export default underPressure;
declare function underPressure(...params: Parameters<UnderPressure>): ReturnType<UnderPressure>
export = underPressure