mini-nest 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +556 -0
- package/dist/aop/aopWrapper.d.ts +17 -0
- package/dist/aop/aopWrapper.d.ts.map +1 -0
- package/dist/aop/aopWrapper.js +112 -0
- package/dist/aop/aopWrapper.js.map +1 -0
- package/dist/cache/cacheManager.d.ts +11 -0
- package/dist/cache/cacheManager.d.ts.map +1 -0
- package/dist/cache/cacheManager.js +42 -0
- package/dist/cache/cacheManager.js.map +1 -0
- package/dist/circuitBreaker/circuitBreakerManager.d.ts +21 -0
- package/dist/circuitBreaker/circuitBreakerManager.d.ts.map +1 -0
- package/dist/circuitBreaker/circuitBreakerManager.js +60 -0
- package/dist/circuitBreaker/circuitBreakerManager.js.map +1 -0
- package/dist/circuitBreaker/circuitOpenError.d.ts +4 -0
- package/dist/circuitBreaker/circuitOpenError.d.ts.map +1 -0
- package/dist/circuitBreaker/circuitOpenError.js +11 -0
- package/dist/circuitBreaker/circuitOpenError.js.map +1 -0
- package/dist/container.js +33 -0
- package/dist/controller.js +10 -0
- package/dist/core/app/App.d.ts +31 -0
- package/dist/core/app/App.d.ts.map +1 -0
- package/dist/core/app/App.js +149 -0
- package/dist/core/app/App.js.map +1 -0
- package/dist/core/container/container.d.ts +16 -0
- package/dist/core/container/container.d.ts.map +1 -0
- package/dist/core/container/container.js +61 -0
- package/dist/core/container/container.js.map +1 -0
- package/dist/core/pipeline/ExecutionContext.d.ts +22 -0
- package/dist/core/pipeline/ExecutionContext.d.ts.map +1 -0
- package/dist/core/pipeline/ExecutionContext.js +31 -0
- package/dist/core/pipeline/ExecutionContext.js.map +1 -0
- package/dist/core/pipeline/RequestPipeline.d.ts +9 -0
- package/dist/core/pipeline/RequestPipeline.d.ts.map +1 -0
- package/dist/core/pipeline/RequestPipeline.js +83 -0
- package/dist/core/pipeline/RequestPipeline.js.map +1 -0
- package/dist/createMethodDecorator.js +22 -0
- package/dist/createParamDecorator.js +46 -0
- package/dist/decorators/Injectable.d.ts +3 -0
- package/dist/decorators/Injectable.d.ts.map +1 -0
- package/dist/decorators/Injectable.js +10 -0
- package/dist/decorators/Injectable.js.map +1 -0
- package/dist/decorators/UseGuard.d.ts +6 -0
- package/dist/decorators/UseGuard.d.ts.map +1 -0
- package/dist/decorators/UseGuard.js +20 -0
- package/dist/decorators/UseGuard.js.map +1 -0
- package/dist/decorators/UseInterceptor.d.ts +5 -0
- package/dist/decorators/UseInterceptor.d.ts.map +1 -0
- package/dist/decorators/UseInterceptor.js +15 -0
- package/dist/decorators/UseInterceptor.js.map +1 -0
- package/dist/decorators/aop/Cache.d.ts +6 -0
- package/dist/decorators/aop/Cache.d.ts.map +1 -0
- package/dist/decorators/aop/Cache.js +13 -0
- package/dist/decorators/aop/Cache.js.map +1 -0
- package/dist/decorators/aop/CircuitBreaker.d.ts +6 -0
- package/dist/decorators/aop/CircuitBreaker.d.ts.map +1 -0
- package/dist/decorators/aop/CircuitBreaker.js +10 -0
- package/dist/decorators/aop/CircuitBreaker.js.map +1 -0
- package/dist/decorators/aop/Retry.d.ts +2 -0
- package/dist/decorators/aop/Retry.d.ts.map +1 -0
- package/dist/decorators/aop/Retry.js +10 -0
- package/dist/decorators/aop/Retry.js.map +1 -0
- package/dist/decorators/aop/Timeout.d.ts +2 -0
- package/dist/decorators/aop/Timeout.d.ts.map +1 -0
- package/dist/decorators/aop/Timeout.js +10 -0
- package/dist/decorators/aop/Timeout.js.map +1 -0
- package/dist/decorators/http/Controller.d.ts +3 -0
- package/dist/decorators/http/Controller.d.ts.map +1 -0
- package/dist/decorators/http/Controller.js +11 -0
- package/dist/decorators/http/Controller.js.map +1 -0
- package/dist/decorators/http/CreateMethodDecorator.d.ts +8 -0
- package/dist/decorators/http/CreateMethodDecorator.d.ts.map +1 -0
- package/dist/decorators/http/CreateMethodDecorator.js +20 -0
- package/dist/decorators/http/CreateMethodDecorator.js.map +1 -0
- package/dist/decorators/http/CreateParamDecorator.d.ts +13 -0
- package/dist/decorators/http/CreateParamDecorator.d.ts.map +1 -0
- package/dist/decorators/http/CreateParamDecorator.js +57 -0
- package/dist/decorators/http/CreateParamDecorator.js.map +1 -0
- package/dist/decorators/index.d.ts +11 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +37 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators.js +1 -0
- package/dist/examples/User.example.js +12 -0
- package/dist/examples/container.example.js +31 -0
- package/dist/examples/container.example.mjs +42 -0
- package/dist/examples/controllers/LogController.js +33 -0
- package/dist/examples/controllers/UserController.js +68 -0
- package/dist/examples/createTestApp.js +23 -0
- package/dist/examples/interceptors/LoggerInterceptor.js +12 -0
- package/dist/examples/log.example.js +6 -0
- package/dist/examples/services/LoggerService.js +19 -0
- package/dist/examples/services/UserService.js +40 -0
- package/dist/exceptions/HTTPExceptions.d.ts +36 -0
- package/dist/exceptions/HTTPExceptions.d.ts.map +1 -0
- package/dist/exceptions/HTTPExceptions.js +62 -0
- package/dist/exceptions/HTTPExceptions.js.map +1 -0
- package/dist/exceptions/baseHTTPException.d.ts +16 -0
- package/dist/exceptions/baseHTTPException.d.ts.map +1 -0
- package/dist/exceptions/baseHTTPException.js +25 -0
- package/dist/exceptions/baseHTTPException.js.map +1 -0
- package/dist/exceptions/defaultExceptionFilter.d.ts +10 -0
- package/dist/exceptions/defaultExceptionFilter.d.ts.map +1 -0
- package/dist/exceptions/defaultExceptionFilter.js +65 -0
- package/dist/exceptions/defaultExceptionFilter.js.map +1 -0
- package/dist/exceptions/exceptionFilter.d.ts +6 -0
- package/dist/exceptions/exceptionFilter.d.ts.map +1 -0
- package/dist/exceptions/exceptionFilter.js +3 -0
- package/dist/exceptions/exceptionFilter.js.map +1 -0
- package/dist/exceptions/exceptionHandler.d.ts +12 -0
- package/dist/exceptions/exceptionHandler.d.ts.map +1 -0
- package/dist/exceptions/exceptionHandler.js +50 -0
- package/dist/exceptions/exceptionHandler.js.map +1 -0
- package/dist/exceptions/index.d.ts +6 -0
- package/dist/exceptions/index.d.ts.map +1 -0
- package/dist/exceptions/index.js +22 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/guards/Guard.d.ts +5 -0
- package/dist/guards/Guard.d.ts.map +1 -0
- package/dist/guards/Guard.js +3 -0
- package/dist/guards/Guard.js.map +1 -0
- package/dist/guards/applyGuard.d.ts +5 -0
- package/dist/guards/applyGuard.d.ts.map +1 -0
- package/dist/guards/applyGuard.js +15 -0
- package/dist/guards/applyGuard.js.map +1 -0
- package/dist/http/HttpRequest.d.ts +52 -0
- package/dist/http/HttpRequest.d.ts.map +1 -0
- package/dist/http/HttpRequest.js +103 -0
- package/dist/http/HttpRequest.js.map +1 -0
- package/dist/http/HttpResponse.d.ts +20 -0
- package/dist/http/HttpResponse.d.ts.map +1 -0
- package/dist/http/HttpResponse.js +63 -0
- package/dist/http/HttpResponse.js.map +1 -0
- package/dist/http/adapters/expressAdapter.d.ts +17 -0
- package/dist/http/adapters/expressAdapter.d.ts.map +1 -0
- package/dist/http/adapters/expressAdapter.js +91 -0
- package/dist/http/adapters/expressAdapter.js.map +1 -0
- package/dist/http/adapters/fastifyAdapter.d.ts +17 -0
- package/dist/http/adapters/fastifyAdapter.d.ts.map +1 -0
- package/dist/http/adapters/fastifyAdapter.js +91 -0
- package/dist/http/adapters/fastifyAdapter.js.map +1 -0
- package/dist/http/adapters/httpAdapter.d.ts +14 -0
- package/dist/http/adapters/httpAdapter.d.ts.map +1 -0
- package/dist/http/adapters/httpAdapter.js +3 -0
- package/dist/http/adapters/httpAdapter.js.map +1 -0
- package/dist/http/client/httpClient.d.ts +51 -0
- package/dist/http/client/httpClient.d.ts.map +1 -0
- package/dist/http/client/httpClient.js +163 -0
- package/dist/http/client/httpClient.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/injectable.js +12 -0
- package/dist/interceptor.js +44 -0
- package/dist/interceptors/Interceptor.d.ts +4 -0
- package/dist/interceptors/Interceptor.d.ts.map +1 -0
- package/dist/interceptors/Interceptor.js +3 -0
- package/dist/interceptors/Interceptor.js.map +1 -0
- package/dist/interceptors/applyInterceptor.d.ts +5 -0
- package/dist/interceptors/applyInterceptor.d.ts.map +1 -0
- package/dist/interceptors/applyInterceptor.js +22 -0
- package/dist/interceptors/applyInterceptor.js.map +1 -0
- package/dist/lifecycle/lifecycle.d.ts +23 -0
- package/dist/lifecycle/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle/lifecycle.js +3 -0
- package/dist/lifecycle/lifecycle.js.map +1 -0
- package/dist/main.js +6 -0
- package/dist/metadata.js +83 -0
- package/dist/middleware/middleware.d.ts +14 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/middleware.js +41 -0
- package/dist/middleware/middleware.js.map +1 -0
- package/dist/middleware/type.d.ts +4 -0
- package/dist/middleware/type.d.ts.map +1 -0
- package/dist/middleware/type.js +3 -0
- package/dist/middleware/type.js.map +1 -0
- package/dist/paramRegistry.js +4 -0
- package/dist/request/createMethodDecorator.js +22 -0
- package/dist/request/createParamDecorator.js +46 -0
- package/dist/request/interceptor.js +44 -0
- package/dist/request/metadata.js +83 -0
- package/dist/request/paramRegistry.js +4 -0
- package/dist/request/resolveHandlerArgument.js +108 -0
- package/dist/request/routeMatch.js +24 -0
- package/dist/request/routeRegistry.js +107 -0
- package/dist/request/utils/normalizePath.js +16 -0
- package/dist/request/validation/rule.js +44 -0
- package/dist/request/validation/validationErrorException.js +8 -0
- package/dist/resolveHandlerArgument.js +33 -0
- package/dist/routeMatch.js +24 -0
- package/dist/routeRegistry.js +108 -0
- package/dist/routes.js +1 -0
- package/dist/routing/metadata.d.ts +19 -0
- package/dist/routing/metadata.d.ts.map +1 -0
- package/dist/routing/metadata.js +65 -0
- package/dist/routing/metadata.js.map +1 -0
- package/dist/routing/metadataKeys.d.ts +22 -0
- package/dist/routing/metadataKeys.d.ts.map +1 -0
- package/dist/routing/metadataKeys.js +19 -0
- package/dist/routing/metadataKeys.js.map +1 -0
- package/dist/routing/paramTypes.d.ts +18 -0
- package/dist/routing/paramTypes.d.ts.map +1 -0
- package/dist/routing/paramTypes.js +3 -0
- package/dist/routing/paramTypes.js.map +1 -0
- package/dist/routing/routeRegistry.d.ts +31 -0
- package/dist/routing/routeRegistry.d.ts.map +1 -0
- package/dist/routing/routeRegistry.js +99 -0
- package/dist/routing/routeRegistry.js.map +1 -0
- package/dist/simulateRequest.js +52 -0
- package/dist/utils/decoratorCheck.d.ts +3 -0
- package/dist/utils/decoratorCheck.d.ts.map +1 -0
- package/dist/utils/decoratorCheck.js +37 -0
- package/dist/utils/decoratorCheck.js.map +1 -0
- package/dist/utils/log.d.ts +7 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +20 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/metadataKey.d.ts +9 -0
- package/dist/utils/metadataKey.d.ts.map +1 -0
- package/dist/utils/metadataKey.js +28 -0
- package/dist/utils/metadataKey.js.map +1 -0
- package/dist/utils/normalizePath.js +16 -0
- package/dist/validation/resolveHandlerArgument.d.ts +10 -0
- package/dist/validation/resolveHandlerArgument.d.ts.map +1 -0
- package/dist/validation/resolveHandlerArgument.js +112 -0
- package/dist/validation/resolveHandlerArgument.js.map +1 -0
- package/dist/validation/rule.d.ts +35 -0
- package/dist/validation/rule.d.ts.map +1 -0
- package/dist/validation/rule.js +45 -0
- package/dist/validation/rule.js.map +1 -0
- package/dist/validation/validationErrorException.d.ts +6 -0
- package/dist/validation/validationErrorException.d.ts.map +1 -0
- package/dist/validation/validationErrorException.js +9 -0
- package/dist/validation/validationErrorException.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
// This file is an example of how the DI container works.
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
const container_1 = require("../container");
|
|
15
|
+
const injectable_1 = require("../injectable");
|
|
16
|
+
const LoggerService_1 = require("./services/LoggerService");
|
|
17
|
+
let UserService = class UserService {
|
|
18
|
+
constructor(logger) {
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
}
|
|
21
|
+
hello() {
|
|
22
|
+
this.logger.log('Hello from UserService');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
UserService = __decorate([
|
|
26
|
+
(0, injectable_1.Injectable)(),
|
|
27
|
+
__metadata("design:paramtypes", [LoggerService_1.LoggerService])
|
|
28
|
+
], UserService);
|
|
29
|
+
const c = container_1.container;
|
|
30
|
+
const service = c.resolve(UserService);
|
|
31
|
+
service.hello();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
import "reflect-metadata";
|
|
12
|
+
import { container } from "../container";
|
|
13
|
+
function Injectable() {
|
|
14
|
+
return function (target) {
|
|
15
|
+
const dependencies = Reflect.getMetadata('design:paramtypes', target);
|
|
16
|
+
console.log('Dependencies for', target.name, ':', dependencies);
|
|
17
|
+
container.register(target, dependencies); // 👈 让 container 知道这个类依赖谁
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let Logger = class Logger {
|
|
21
|
+
log(msg) {
|
|
22
|
+
console.log('[Logger]', msg);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
Logger = __decorate([
|
|
26
|
+
Injectable()
|
|
27
|
+
], Logger);
|
|
28
|
+
let UserService = class UserService {
|
|
29
|
+
constructor(logger) {
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
}
|
|
32
|
+
hello() {
|
|
33
|
+
this.logger.log('Hello from UserService');
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
UserService = __decorate([
|
|
37
|
+
Injectable(),
|
|
38
|
+
__metadata("design:paramtypes", [Logger])
|
|
39
|
+
], UserService);
|
|
40
|
+
const c = container;
|
|
41
|
+
const service = c.resolve(UserService);
|
|
42
|
+
service.hello();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LogController = void 0;
|
|
13
|
+
const controller_1 = require("../../controller");
|
|
14
|
+
const createMethodDecorator_1 = require("../../request/createMethodDecorator");
|
|
15
|
+
const interceptor_1 = require("../../request/interceptor");
|
|
16
|
+
const LoggerInterceptor_1 = require("../interceptors/LoggerInterceptor");
|
|
17
|
+
let LogController = class LogController {
|
|
18
|
+
test() {
|
|
19
|
+
console.log('[Handler] Executing');
|
|
20
|
+
return { ok: true };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.LogController = LogController;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, createMethodDecorator_1.Get)('/test'),
|
|
26
|
+
__metadata("design:type", Function),
|
|
27
|
+
__metadata("design:paramtypes", []),
|
|
28
|
+
__metadata("design:returntype", void 0)
|
|
29
|
+
], LogController.prototype, "test", null);
|
|
30
|
+
exports.LogController = LogController = __decorate([
|
|
31
|
+
(0, controller_1.Controller)('/log'),
|
|
32
|
+
(0, interceptor_1.UseInterceptor)(LoggerInterceptor_1.LoggerInterceptor)
|
|
33
|
+
], LogController);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserController = void 0;
|
|
16
|
+
const controller_1 = require("../../controller");
|
|
17
|
+
const createMethodDecorator_1 = require("../../request/createMethodDecorator");
|
|
18
|
+
const createParamDecorator_1 = require("../../request/createParamDecorator");
|
|
19
|
+
const UserService_1 = require("../services/UserService");
|
|
20
|
+
let UserController = class UserController {
|
|
21
|
+
constructor(userService) {
|
|
22
|
+
this.userService = userService;
|
|
23
|
+
}
|
|
24
|
+
getAll() {
|
|
25
|
+
return this.userService.getUsers();
|
|
26
|
+
}
|
|
27
|
+
getUser(id, v) {
|
|
28
|
+
if (v === 'true') {
|
|
29
|
+
return this.userService.getVerboseUser(id);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return this.userService.getUserById(id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
createUser(id, expand, name, token) {
|
|
36
|
+
console.log('Injected parameters:', { id, expand, name, token });
|
|
37
|
+
return this.userService.createUser(id, name, expand, token);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.UserController = UserController;
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, createMethodDecorator_1.Get)('/'),
|
|
43
|
+
__metadata("design:type", Function),
|
|
44
|
+
__metadata("design:paramtypes", []),
|
|
45
|
+
__metadata("design:returntype", void 0)
|
|
46
|
+
], UserController.prototype, "getAll", null);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, createMethodDecorator_1.Get)('/:id'),
|
|
49
|
+
__param(0, (0, createParamDecorator_1.Param)('id')),
|
|
50
|
+
__param(1, (0, createParamDecorator_1.Query)('verbose')),
|
|
51
|
+
__metadata("design:type", Function),
|
|
52
|
+
__metadata("design:paramtypes", [String, String]),
|
|
53
|
+
__metadata("design:returntype", void 0)
|
|
54
|
+
], UserController.prototype, "getUser", null);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, createMethodDecorator_1.Post)('/:id'),
|
|
57
|
+
__param(0, (0, createParamDecorator_1.Param)('id')),
|
|
58
|
+
__param(1, (0, createParamDecorator_1.Query)('expand')),
|
|
59
|
+
__param(2, (0, createParamDecorator_1.Body)('name')),
|
|
60
|
+
__param(3, (0, createParamDecorator_1.Header)('authorization')),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", [Number, String, String, String]),
|
|
63
|
+
__metadata("design:returntype", void 0)
|
|
64
|
+
], UserController.prototype, "createUser", null);
|
|
65
|
+
exports.UserController = UserController = __decorate([
|
|
66
|
+
(0, controller_1.Controller)('/users'),
|
|
67
|
+
__metadata("design:paramtypes", [UserService_1.UserService])
|
|
68
|
+
], UserController);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestApp = createTestApp;
|
|
4
|
+
const container_1 = require("../container");
|
|
5
|
+
const simulateRequest_1 = require("../simulateRequest");
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
async function createTestApp(controller, route, method, options) {
|
|
8
|
+
// auto register controller & its dependencies
|
|
9
|
+
if (!container_1.container.resolve(controller)) {
|
|
10
|
+
container_1.container.register(controller, undefined);
|
|
11
|
+
}
|
|
12
|
+
// optional manual service registration
|
|
13
|
+
options?.services?.forEach(serviceClass => {
|
|
14
|
+
if (!container_1.container.resolve(serviceClass)) {
|
|
15
|
+
container_1.container.register(serviceClass, new serviceClass());
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
// simulate request
|
|
19
|
+
return await (0, simulateRequest_1.simulateRequest)(route, method, {
|
|
20
|
+
body: options?.body,
|
|
21
|
+
headers: options?.headers,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerInterceptor = void 0;
|
|
4
|
+
class LoggerInterceptor {
|
|
5
|
+
async intercept(next) {
|
|
6
|
+
console.log('[Logger] Before handler');
|
|
7
|
+
const result = await next();
|
|
8
|
+
console.log('[Logger] After handler', result);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.LoggerInterceptor = LoggerInterceptor;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const simulateRequest_1 = require("../simulateRequest");
|
|
4
|
+
require("./controllers/LogController");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
(0, simulateRequest_1.simulateRequest)('/log/test', 'GET');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoggerService = void 0;
|
|
10
|
+
const injectable_1 = require("../../injectable");
|
|
11
|
+
let LoggerService = class LoggerService {
|
|
12
|
+
log(msg) {
|
|
13
|
+
console.log('[LoggerService]', msg);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.LoggerService = LoggerService;
|
|
17
|
+
exports.LoggerService = LoggerService = __decorate([
|
|
18
|
+
(0, injectable_1.Injectable)()
|
|
19
|
+
], LoggerService);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserService = void 0;
|
|
13
|
+
const injectable_1 = require("../../injectable");
|
|
14
|
+
const LoggerService_1 = require("./LoggerService");
|
|
15
|
+
let UserService = class UserService {
|
|
16
|
+
constructor(logger) {
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
}
|
|
19
|
+
getUsers() {
|
|
20
|
+
this.logger.log('Fetching users...');
|
|
21
|
+
return ['Alice', 'Bob', 'Charlie'];
|
|
22
|
+
}
|
|
23
|
+
getUserById(id) {
|
|
24
|
+
this.logger.log(`Fetching user with id: ${id}`);
|
|
25
|
+
return { id, name: 'Alice' };
|
|
26
|
+
}
|
|
27
|
+
getVerboseUser(id) {
|
|
28
|
+
this.logger.log(`Fetching verbose user with id: ${id}`);
|
|
29
|
+
return { id, name: 'Alice', age: 30, email: 'example@example.com' };
|
|
30
|
+
}
|
|
31
|
+
createUser(id, name, expand, token) {
|
|
32
|
+
this.logger.log(`Creating user with id: ${id}, name: ${name}, expand: ${expand}, token: ${token}`);
|
|
33
|
+
return { id, name, expand, token };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.UserService = UserService;
|
|
37
|
+
exports.UserService = UserService = __decorate([
|
|
38
|
+
(0, injectable_1.Injectable)(),
|
|
39
|
+
__metadata("design:paramtypes", [LoggerService_1.LoggerService])
|
|
40
|
+
], UserService);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseHTTPException, HttpExceptionResponse } from "./baseHTTPException";
|
|
2
|
+
export interface ValidationError {
|
|
3
|
+
field: string;
|
|
4
|
+
message: string;
|
|
5
|
+
value?: any;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationExceptionResponse extends HttpExceptionResponse {
|
|
8
|
+
errors: ValidationError[];
|
|
9
|
+
}
|
|
10
|
+
export declare class BadRequestException extends BaseHTTPException {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class UnauthorizedException extends BaseHTTPException {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class ForbiddenException extends BaseHTTPException {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class NotFoundException extends BaseHTTPException {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class InternalServerErrorException extends BaseHTTPException {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class NotImplementedException extends BaseHTTPException {
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class BadGatewayException extends BaseHTTPException {
|
|
29
|
+
constructor(message?: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class ValidationException extends BaseHTTPException {
|
|
32
|
+
readonly errors: ValidationError[];
|
|
33
|
+
constructor(errors: ValidationError[], message?: string);
|
|
34
|
+
getResponse(): ValidationExceptionResponse;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=HTTPExceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPExceptions.d.ts","sourceRoot":"","sources":["../../src/exceptions/HTTPExceptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB;IACtE,MAAM,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;gBAC1C,OAAO,GAAE,MAAsB;CAG9C;AAED,qBAAa,qBAAsB,SAAQ,iBAAiB;gBAC5C,OAAO,GAAE,MAAuB;CAG/C;AAED,qBAAa,kBAAmB,SAAQ,iBAAiB;gBACzC,OAAO,GAAE,MAAoB;CAG5C;AAED,qBAAa,iBAAkB,SAAQ,iBAAiB;gBACxC,OAAO,GAAE,MAAoB;CAG5C;AAED,qBAAa,4BAA6B,SAAQ,iBAAiB;gBACnD,OAAO,GAAE,MAAgC;CAGxD;AAED,qBAAa,uBAAwB,SAAQ,iBAAiB;gBAC9C,OAAO,GAAE,MAA0B;CAGlD;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;gBAC1C,OAAO,GAAE,MAAsB;CAG9C;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;aAElC,MAAM,EAAE,eAAe,EAAE;gBAAzB,MAAM,EAAE,eAAe,EAAE,EACzC,OAAO,GAAE,MAA4B;IAKhC,WAAW,IAAI,2BAA2B;CAQtD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = void 0;
|
|
4
|
+
const baseHTTPException_1 = require("./baseHTTPException");
|
|
5
|
+
class BadRequestException extends baseHTTPException_1.BaseHTTPException {
|
|
6
|
+
constructor(message = 'Bad Request') {
|
|
7
|
+
super(message, 400, 'Bad Request');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.BadRequestException = BadRequestException;
|
|
11
|
+
class UnauthorizedException extends baseHTTPException_1.BaseHTTPException {
|
|
12
|
+
constructor(message = 'Unauthorized') {
|
|
13
|
+
super(message, 401, 'Unauthorized');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.UnauthorizedException = UnauthorizedException;
|
|
17
|
+
class ForbiddenException extends baseHTTPException_1.BaseHTTPException {
|
|
18
|
+
constructor(message = 'Forbidden') {
|
|
19
|
+
super(message, 403, 'Forbidden');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ForbiddenException = ForbiddenException;
|
|
23
|
+
class NotFoundException extends baseHTTPException_1.BaseHTTPException {
|
|
24
|
+
constructor(message = 'Not Found') {
|
|
25
|
+
super(message, 404, 'Not Found');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.NotFoundException = NotFoundException;
|
|
29
|
+
class InternalServerErrorException extends baseHTTPException_1.BaseHTTPException {
|
|
30
|
+
constructor(message = 'Internal Server Error') {
|
|
31
|
+
super(message, 500, 'Internal Server Error');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.InternalServerErrorException = InternalServerErrorException;
|
|
35
|
+
class NotImplementedException extends baseHTTPException_1.BaseHTTPException {
|
|
36
|
+
constructor(message = 'Not Implemented') {
|
|
37
|
+
super(message, 501, 'Not Implemented');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.NotImplementedException = NotImplementedException;
|
|
41
|
+
class BadGatewayException extends baseHTTPException_1.BaseHTTPException {
|
|
42
|
+
constructor(message = 'Bad Gateway') {
|
|
43
|
+
super(message, 502, 'Bad Gateway');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.BadGatewayException = BadGatewayException;
|
|
47
|
+
class ValidationException extends baseHTTPException_1.BaseHTTPException {
|
|
48
|
+
constructor(errors, message = 'Validation failed') {
|
|
49
|
+
super(message, 422, 'Validation Error');
|
|
50
|
+
this.errors = errors;
|
|
51
|
+
}
|
|
52
|
+
getResponse() {
|
|
53
|
+
return {
|
|
54
|
+
statusCode: this.statusCode,
|
|
55
|
+
message: this.message,
|
|
56
|
+
error: this.error,
|
|
57
|
+
errors: this.errors,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ValidationException = ValidationException;
|
|
62
|
+
//# sourceMappingURL=HTTPExceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPExceptions.js","sourceRoot":"","sources":["../../src/exceptions/HTTPExceptions.ts"],"names":[],"mappings":";;;AAAA,2DAA+E;AAW/E,MAAa,mBAAoB,SAAQ,qCAAiB;IACtD,YAAY,UAAkB,aAAa;QACvC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;IACvC,CAAC;CACJ;AAJD,kDAIC;AAED,MAAa,qBAAsB,SAAQ,qCAAiB;IACxD,YAAY,UAAkB,cAAc;QACxC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;IACxC,CAAC;CACJ;AAJD,sDAIC;AAED,M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
+
statusCode: number;
|
|
3
|
+
message: string;
|
|
4
|
+
error: string;
|
|
5
|
+
timestamp?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class BaseHTTPException extends Error {
|
|
9
|
+
readonly message: string;
|
|
10
|
+
readonly statusCode: number;
|
|
11
|
+
readonly error?: string | undefined;
|
|
12
|
+
constructor(message: string, statusCode: number, error?: string | undefined);
|
|
13
|
+
getResponse(): HttpExceptionResponse;
|
|
14
|
+
getStatus(): number;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=baseHTTPException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseHTTPException.d.ts","sourceRoot":"","sources":["../../src/exceptions/baseHTTPException.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,iBAAkB,SAAQ,KAAK;aACZ,OAAO,EAAE,MAAM;aAAkB,UAAU,EAAE,MAAM;aAAkB,KAAK,CAAC,EAAE,MAAM;gBAAnF,OAAO,EAAE,MAAM,EAAkB,UAAU,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,MAAM,YAAA;IAM/G,WAAW,IAAI,qBAAqB;IAQpC,SAAS;CAGZ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseHTTPException = void 0;
|
|
4
|
+
class BaseHTTPException extends Error {
|
|
5
|
+
constructor(message, statusCode, error) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.message = message;
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.error = error;
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
Error.captureStackTrace(this, this.constructor);
|
|
12
|
+
}
|
|
13
|
+
getResponse() {
|
|
14
|
+
return {
|
|
15
|
+
statusCode: this.statusCode,
|
|
16
|
+
message: this.message,
|
|
17
|
+
error: this.error || this.name,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getStatus() {
|
|
21
|
+
return this.statusCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.BaseHTTPException = BaseHTTPException;
|
|
25
|
+
//# sourceMappingURL=baseHTTPException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseHTTPException.js","sourceRoot":"","sources":["../../src/exceptions/baseHTTPException.ts"],"names":[],"mappings":";;;AAQA,MAAa,iBAAkB,SAAQ,KAAK;IACxC,YAA4B,OAAe,EAAkB,UAAkB,EAAkB,KAAc;QAC3G,KAAK,CAAC,OAAO,CAAC,CAAC;QADS,YAAO,GAAP,OAAO,CAAQ;QAAkB,eAAU,GAAV,UAAU,CAAQ;QAAkB,UAAK,GAAL,KAAK,CAAS;QAE3G,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;IAED,WAAW;QACP,OAAO;YACH,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI;SACjC,CAAA;IACL,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AAlBD,8CAkBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext } from "../core/pipeline/ExecutionContext";
|
|
2
|
+
import { ExceptionFilter } from "./exceptionFilter";
|
|
3
|
+
export declare class DefaultExceptionFilter implements ExceptionFilter<any> {
|
|
4
|
+
catch(exception: unknown, context: ExecutionContext): void;
|
|
5
|
+
canHandle(_: unknown): boolean;
|
|
6
|
+
private handleHttpException;
|
|
7
|
+
private handleError;
|
|
8
|
+
private handleUnknown;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=defaultExceptionFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultExceptionFilter.d.ts","sourceRoot":"","sources":["../../src/exceptions/defaultExceptionFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAIrE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,sBAAuB,YAAW,eAAe,CAAC,GAAG,CAAC;IAC/D,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAa1D,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAK9B,OAAO,CAAC,mBAAmB;IAuB3B,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,aAAa;CAexB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultExceptionFilter = void 0;
|
|
4
|
+
const log_1 = require("../utils/log");
|
|
5
|
+
const baseHTTPException_1 = require("./baseHTTPException");
|
|
6
|
+
class DefaultExceptionFilter {
|
|
7
|
+
catch(exception, context) {
|
|
8
|
+
const response = context.getResponse();
|
|
9
|
+
if (exception instanceof baseHTTPException_1.BaseHTTPException) {
|
|
10
|
+
this.handleHttpException(exception, response, context);
|
|
11
|
+
}
|
|
12
|
+
else if (exception instanceof Error) {
|
|
13
|
+
this.handleError(exception, response, context);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.handleUnknown(exception, response, context);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//by design this filter can handle any exception
|
|
20
|
+
canHandle(_) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
handleHttpException(exception, response, context) {
|
|
24
|
+
const exceptionResponse = exception.getResponse();
|
|
25
|
+
const request = context.getRequest();
|
|
26
|
+
const errorResponse = {
|
|
27
|
+
...exceptionResponse,
|
|
28
|
+
timestamp: new Date().toISOString(),
|
|
29
|
+
path: request.path,
|
|
30
|
+
};
|
|
31
|
+
response.status(exceptionResponse.statusCode).json(errorResponse);
|
|
32
|
+
if (exception.statusCode >= 500) {
|
|
33
|
+
log_1.Log.error(`[HTTP Exception:] ${exceptionResponse.statusCode} ${exceptionResponse.message} on ${request.method} ${request.path}`, exception.stack);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
log_1.Log.warn(`[HTTP Exception:] ${exceptionResponse.statusCode} ${exceptionResponse.message} on ${request.method} ${request.path}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
handleError(error, response, context) {
|
|
40
|
+
const request = context.getRequest();
|
|
41
|
+
const errorResponse = {
|
|
42
|
+
statusCode: 500,
|
|
43
|
+
message: 'Internal Server Error',
|
|
44
|
+
error: 'InternalServerError',
|
|
45
|
+
timestamp: new Date().toISOString(),
|
|
46
|
+
path: request.path,
|
|
47
|
+
};
|
|
48
|
+
response.status(500).json(errorResponse);
|
|
49
|
+
log_1.Log.error(`[Unhandled Exception:] 500 ${error.message} on ${request.method} ${request.path}`, error.stack);
|
|
50
|
+
}
|
|
51
|
+
handleUnknown(cause, response, context) {
|
|
52
|
+
const request = context.getRequest();
|
|
53
|
+
const errorResponse = {
|
|
54
|
+
statusCode: 500,
|
|
55
|
+
message: 'Internal Server Error',
|
|
56
|
+
error: 'InternalServerError',
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
|
+
path: request.path,
|
|
59
|
+
};
|
|
60
|
+
response.status(500).json(errorResponse);
|
|
61
|
+
log_1.Log.error(`[Unhandled Critical Exception:] Unknown error on ${request.method} ${request.path}, it is more likely the framework's fault than yours.`, JSON.stringify(cause));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.DefaultExceptionFilter = DefaultExceptionFilter;
|
|
65
|
+
//# sourceMappingURL=defaultExceptionFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultExceptionFilter.js","sourceRoot":"","sources":["../../src/exceptions/defaultExceptionFilter.ts"],"names":[],"mappings":";;;AAEA,sCAAmC;AACnC,2DAAwD;AAGxD,MAAa,sBAAsB;IAC/B,KAAK,CAAC,SAAkB,EAAE,OAAyB;QAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,SAAS,YAAY,qCAAiB,EAAE,CAAC;YACzC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;aAAM,IAAI,SAAS,YAAY,KAAK,EAAE,CAAC;YACpC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;IAEL,CAAC;IAED,gDAAgD;IAChD,SAAS,CAAC,CAAU;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IAGO,mBAAmB,CAAC,SAA4B,EAAE,QAAsB,EAAE,OAAyB;QACvG,MAAM,iBAAiB,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAClD,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,aAAa,GAAG;YAClB,GAAG,iBAAiB;YACpB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,OAAO,CAAC,IAAI;SACrB,CAAA;QACD,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,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AS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,OAAO,CAAC,IAAI;SACrB,CAAC;QACF,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACzC,SAAG,CAAC,KAAK,CACL,oDAAoD,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,uDAAuD,EACzI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CACxB,CAAC;IACN,CAAC;CACJ;AAzED,wDAyEC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExecutionContext } from "../core/pipeline/ExecutionContext";
|
|
2
|
+
export interface ExceptionFilter<T = any> {
|
|
3
|
+
catch(exception: T, context: ExecutionContext): void | Promise<void>;
|
|
4
|
+
canHandle(exception: unknown): boolean;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=exceptionFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptionFilter.d.ts","sourceRoot":"","sources":["../../src/exceptions/exceptionFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG;IACpC,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC;CAC1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptionFilter.js","sourceRoot":"","sources":["../../src/exceptions/exceptionFilter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExecutionContext } from "../core/pipeline/ExecutionContext";
|
|
2
|
+
import { HttpResponse } from "../http/HttpResponse";
|
|
3
|
+
import { ExceptionFilter } from "./exceptionFilter";
|
|
4
|
+
export declare class ExceptionHandler {
|
|
5
|
+
private filters;
|
|
6
|
+
private defaultFilter;
|
|
7
|
+
registerFilter(filter: ExceptionFilter, order: number): void;
|
|
8
|
+
handleException(exception: unknown, context: ExecutionContext): Promise<HttpResponse>;
|
|
9
|
+
clearCache(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const exceptionHandler: ExceptionHandler;
|
|
12
|
+
//# sourceMappingURL=exceptionHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptionHandler.d.ts","sourceRoot":"","sources":["../../src/exceptions/exceptionHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD,qBAAa,gBAAgB;IACzB,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,aAAa,CAAgC;IAErD,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM;IAK/C,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;IA8B3F,UAAU;CAGb;AAGD,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exceptionHandler = exports.ExceptionHandler = void 0;
|
|
4
|
+
const log_1 = require("../utils/log");
|
|
5
|
+
const defaultExceptionFilter_1 = require("./defaultExceptionFilter");
|
|
6
|
+
//TODO: Improve Exception Handler to support async filters and filter chaining
|
|
7
|
+
class ExceptionHandler {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.filters = [];
|
|
10
|
+
this.defaultFilter = new defaultExceptionFilter_1.DefaultExceptionFilter();
|
|
11
|
+
}
|
|
12
|
+
registerFilter(filter, order) {
|
|
13
|
+
this.filters.push({ filter, order });
|
|
14
|
+
this.filters.sort((a, b) => a.order - b.order);
|
|
15
|
+
}
|
|
16
|
+
async handleException(exception, context) {
|
|
17
|
+
const response = context.getResponse();
|
|
18
|
+
for (const { filter } of this.filters) {
|
|
19
|
+
if (filter.canHandle && !filter.canHandle(exception)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
await filter.catch(exception, context);
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
catch (filterError) {
|
|
27
|
+
log_1.Log.error(`[Exception Filter Error:] Error in exception filter ${filter.constructor.name}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await this.defaultFilter.catch(exception, context);
|
|
32
|
+
}
|
|
33
|
+
catch (defaultExceptionFilterError) {
|
|
34
|
+
log_1.Log.error(`[Default Exception Filter Error:] Error in default exception filter`);
|
|
35
|
+
response.status(500).json({
|
|
36
|
+
statusCode: 500,
|
|
37
|
+
message: 'Critical Internal Server Error, unable to process exception',
|
|
38
|
+
error: 'InternalServerError',
|
|
39
|
+
timestamp: new Date().toISOString(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
clearCache() {
|
|
45
|
+
this.filters = [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ExceptionHandler = ExceptionHandler;
|
|
49
|
+
exports.exceptionHandler = new ExceptionHandler();
|
|
50
|
+
//# sourceMappingURL=exceptionHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptionHandler.js","sourceRoot":"","sources":["../../src/exceptions/exceptionHandler.ts"],"names":[],"mappings":";;;AAEA,sCAAmC;AACnC,qEAAkE;AAQlE,8EAA8E;AAC9E,MAAa,gBAAgB;IAA7B;QACY,YA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