@fuse-autotech/nest-timeout

中文文档
2.1.0发布于 2023/12/10MITCommonJS零依赖近 30 天下载 9082

This package enables to use a custom timeout alongside with the global timeout interceptor.

原始使用文档
文档目录6 节
  1. Description
  2. Installation
  3. Usage
  4. Interceptor
  5. @Timeout() Decorator
  6. License

Fuse Logo Nest Logo

Timeout Interceptor for NestJS

Description

NestJS Timeout Interceptor repository. It enables setting up a global timeout for a NestJS application, which can be overridden by a Timeout Decorator for controller classes and methods specific timeouts. This gives the user more flexibility with a small amount of additional code. Method timeouts are preferred over class timeouts, which are preferred over global timeouts. Enjoy!

Installation

$ npm install @fuse-autotech/nest-timeout

Usage

Interceptor

Options:

  • defaultTimeout - Number of milliseconds after which the interceptor throws a RequestTimeoutException if no other timeout is defined for the endpoint
  • isEnabled - Determine if the interceptor is enabled. Defaults to true. Useful for debugging to avoid timeouts

import { Module } from "@nestjs/common";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { TimeoutInterceptor } from "@fuse-autotech/nest-timeout";

@Module({
    imports: [],
    controllers: [],
    providers: [{
        provide: APP_INTERCEPTOR,
        useValue: new TimeoutInterceptor({ defaultTimeout: 10000 })
    }]
})
export class AppModule {}

@Timeout() Decorator

Can be used both on Controllers and Controller Methods:


import { Controller, Get, Param, Post } from '@nestjs/common';
import { Timeout } from '@fuse-autotech/nest-timeout';

@Controller('cats')
@Timeout(10000) // Applied for all methods unless decorated
export class CatsController {
    @Get()
    findAll(): string {
        return 'This action returns all cats';
    }
        
    @Get(':id') 
    @Timeout(30000) // Overrides controller timeout
    findOne(@Param('id') id: string ): string {
            return `This action returns a #${id} cat`;
        }

    @Post()
    @Timeout(0) // Disables timeout for the method
    create(): string {
        return 'This action adds a new cat';
    }
}

License

Nest timeout is MIT licensed.

版本与发布记录

@fuse-autotech/nest-timeout 共发布 6 个版本,首次发布于 2023/02/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2023/12/102 年前
2.0.02023/11/242 年前
1.1.02023/11/242 年前
1.0.12023/06/113 年前
1.0.02023/02/223 年前
0.0.0-development2023/02/143 年前

关于 @fuse-autotech/nest-timeout 的常见问题

@fuse-autotech/nest-timeout 是什么?

This package enables to use a custom timeout alongside with the global timeout interceptor.

如何安装 @fuse-autotech/nest-timeout?

在项目目录运行 npm install @fuse-autotech/nest-timeout,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@nestjs/common(^8.0.0 || ^9.0.0 || ^10.0.0)、@nestjs/core(^8.0.0 || ^9.0.0 || ^10.0.0)、reflect-metadata(^0.1.12)、rxjs(^7.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fuse-autotech/nest-timeout 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fuse-autotech__nest-timeout 是否存在。

@fuse-autotech/nest-timeout 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@fuse-autotech/nest-timeout 可以商用吗?

@fuse-autotech/nest-timeout 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fuse-autotech/nest-timeout 的下载量有多少?

根据 npm 官方下载统计,@fuse-autotech/nest-timeout 在 2026/10/16 – 2026/11/14 这 30 天内被下载 9,082 次,日均约 303 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fuse-autotech/nest-timeout 还在维护吗?

最新版本 2.1.0 发布于 2023/12/10(2 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。