nestjs-aborter
Version:
Automatic request cancellation and timeout handling for NestJS applications
65 lines (64 loc) • 2.56 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var AborterModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AborterModule = void 0;
const common_1 = require("@nestjs/common");
const aborter_interceptor_1 = require("./interceptors/aborter.interceptor");
/**
* Global module for configuring the Aborter interceptor.
*
* Import this module in your root AppModule to enable
* automatic request cancellation and timeout handling.
*/
let AborterModule = AborterModule_1 = class AborterModule {
/**
* Configure the module with static options.
*
* @param options - Configuration options for the Aborter interceptor
* @returns Dynamic module configuration
*/
static forRoot(options = {}) {
return {
module: AborterModule_1,
providers: [
{
provide: aborter_interceptor_1.ABORT_CONTROLLER_OPTIONS,
useValue: options,
},
],
exports: [aborter_interceptor_1.ABORT_CONTROLLER_OPTIONS],
};
}
/**
* Configure the module asynchronously with a factory function.
* Useful for loading configuration from ConfigService or other providers.
*
* @param options - Async configuration options
* @returns Dynamic module configuration
*/
static forRootAsync(options) {
return {
module: AborterModule_1,
imports: options.imports || [],
providers: [
{
provide: aborter_interceptor_1.ABORT_CONTROLLER_OPTIONS,
useFactory: options.useFactory,
inject: options.inject || [],
},
],
exports: [aborter_interceptor_1.ABORT_CONTROLLER_OPTIONS],
};
}
};
exports.AborterModule = AborterModule;
exports.AborterModule = AborterModule = AborterModule_1 = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({})
], AborterModule);