nestjs-aborter
Version:
Automatic request cancellation and timeout handling for NestJS applications
34 lines (33 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AborterReason = exports.AborterSignal = exports.aborterReasonFactory = exports.aborterSignalFactory = void 0;
const common_1 = require("@nestjs/common");
/**
* Factory function to extract AbortSignal from request
*/
const aborterSignalFactory = (_data, ctx) => {
const request = ctx.switchToHttp().getRequest();
return request.abortController?.signal;
};
exports.aborterSignalFactory = aborterSignalFactory;
/**
* Factory function to extract abort reason from request
*/
const aborterReasonFactory = (_data, ctx) => {
const request = ctx.switchToHttp().getRequest();
return request.abortReason;
};
exports.aborterReasonFactory = aborterReasonFactory;
/**
* Injects the AbortSignal from the current HTTP request.
*
* Use this to cancel operations when the client disconnects,
* a timeout is reached, or an error occurs.
*/
exports.AborterSignal = (0, common_1.createParamDecorator)(exports.aborterSignalFactory);
/**
* Injects the abort reason from the current HTTP request.
*
* Returns why the request was aborted (e.g., timeout, client disconnect, error).
*/
exports.AborterReason = (0, common_1.createParamDecorator)(exports.aborterReasonFactory);