@hazeljs/core 0.2.0-beta.1
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/README.md +522 -0
- package/dist/__tests__/container.test.d.ts +2 -0
- package/dist/__tests__/container.test.d.ts.map +1 -0
- package/dist/__tests__/container.test.js +454 -0
- package/dist/__tests__/decorators.test.d.ts +2 -0
- package/dist/__tests__/decorators.test.d.ts.map +1 -0
- package/dist/__tests__/decorators.test.js +693 -0
- package/dist/__tests__/errors/http.error.test.d.ts +2 -0
- package/dist/__tests__/errors/http.error.test.d.ts.map +1 -0
- package/dist/__tests__/errors/http.error.test.js +117 -0
- package/dist/__tests__/filters/exception-filter.test.d.ts +2 -0
- package/dist/__tests__/filters/exception-filter.test.d.ts.map +1 -0
- package/dist/__tests__/filters/exception-filter.test.js +135 -0
- package/dist/__tests__/filters/http-exception.filter.test.d.ts +2 -0
- package/dist/__tests__/filters/http-exception.filter.test.d.ts.map +1 -0
- package/dist/__tests__/filters/http-exception.filter.test.js +119 -0
- package/dist/__tests__/hazel-app.test.d.ts +2 -0
- package/dist/__tests__/hazel-app.test.d.ts.map +1 -0
- package/dist/__tests__/hazel-app.test.js +682 -0
- package/dist/__tests__/hazel-module.test.d.ts +2 -0
- package/dist/__tests__/hazel-module.test.d.ts.map +1 -0
- package/dist/__tests__/hazel-module.test.js +408 -0
- package/dist/__tests__/hazel-response.test.d.ts +2 -0
- package/dist/__tests__/hazel-response.test.d.ts.map +1 -0
- package/dist/__tests__/hazel-response.test.js +138 -0
- package/dist/__tests__/health.test.d.ts +2 -0
- package/dist/__tests__/health.test.d.ts.map +1 -0
- package/dist/__tests__/health.test.js +147 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +239 -0
- package/dist/__tests__/interceptors/interceptor.test.d.ts +2 -0
- package/dist/__tests__/interceptors/interceptor.test.d.ts.map +1 -0
- package/dist/__tests__/interceptors/interceptor.test.js +166 -0
- package/dist/__tests__/logger.test.d.ts +2 -0
- package/dist/__tests__/logger.test.d.ts.map +1 -0
- package/dist/__tests__/logger.test.js +141 -0
- package/dist/__tests__/middleware/cors.test.d.ts +2 -0
- package/dist/__tests__/middleware/cors.test.d.ts.map +1 -0
- package/dist/__tests__/middleware/cors.test.js +129 -0
- package/dist/__tests__/middleware/csrf.test.d.ts +2 -0
- package/dist/__tests__/middleware/csrf.test.d.ts.map +1 -0
- package/dist/__tests__/middleware/csrf.test.js +247 -0
- package/dist/__tests__/middleware/global-middleware.test.d.ts +2 -0
- package/dist/__tests__/middleware/global-middleware.test.d.ts.map +1 -0
- package/dist/__tests__/middleware/global-middleware.test.js +259 -0
- package/dist/__tests__/middleware/rate-limit.test.d.ts +2 -0
- package/dist/__tests__/middleware/rate-limit.test.d.ts.map +1 -0
- package/dist/__tests__/middleware/rate-limit.test.js +264 -0
- package/dist/__tests__/middleware/security-headers.test.d.ts +2 -0
- package/dist/__tests__/middleware/security-headers.test.d.ts.map +1 -0
- package/dist/__tests__/middleware/security-headers.test.js +229 -0
- package/dist/__tests__/middleware/timeout.test.d.ts +2 -0
- package/dist/__tests__/middleware/timeout.test.d.ts.map +1 -0
- package/dist/__tests__/middleware/timeout.test.js +132 -0
- package/dist/__tests__/middleware.test.d.ts +2 -0
- package/dist/__tests__/middleware.test.d.ts.map +1 -0
- package/dist/__tests__/middleware.test.js +180 -0
- package/dist/__tests__/pipes/pipe.test.d.ts +2 -0
- package/dist/__tests__/pipes/pipe.test.d.ts.map +1 -0
- package/dist/__tests__/pipes/pipe.test.js +245 -0
- package/dist/__tests__/pipes/validation.pipe.test.d.ts +2 -0
- package/dist/__tests__/pipes/validation.pipe.test.d.ts.map +1 -0
- package/dist/__tests__/pipes/validation.pipe.test.js +297 -0
- package/dist/__tests__/request-parser.test.d.ts +2 -0
- package/dist/__tests__/request-parser.test.d.ts.map +1 -0
- package/dist/__tests__/request-parser.test.js +182 -0
- package/dist/__tests__/router.test.d.ts +2 -0
- package/dist/__tests__/router.test.d.ts.map +1 -0
- package/dist/__tests__/router.test.js +680 -0
- package/dist/__tests__/routing/route-matcher.test.d.ts +2 -0
- package/dist/__tests__/routing/route-matcher.test.d.ts.map +1 -0
- package/dist/__tests__/routing/route-matcher.test.js +219 -0
- package/dist/__tests__/routing/version.decorator.test.d.ts +2 -0
- package/dist/__tests__/routing/version.decorator.test.d.ts.map +1 -0
- package/dist/__tests__/routing/version.decorator.test.js +298 -0
- package/dist/__tests__/service.test.d.ts +2 -0
- package/dist/__tests__/service.test.d.ts.map +1 -0
- package/dist/__tests__/service.test.js +121 -0
- package/dist/__tests__/shutdown.test.d.ts +2 -0
- package/dist/__tests__/shutdown.test.d.ts.map +1 -0
- package/dist/__tests__/shutdown.test.js +250 -0
- package/dist/__tests__/testing/testing.module.test.d.ts +2 -0
- package/dist/__tests__/testing/testing.module.test.d.ts.map +1 -0
- package/dist/__tests__/testing/testing.module.test.js +370 -0
- package/dist/__tests__/upload/file-upload.test.d.ts +2 -0
- package/dist/__tests__/upload/file-upload.test.d.ts.map +1 -0
- package/dist/__tests__/upload/file-upload.test.js +498 -0
- package/dist/__tests__/utils/sanitize.test.d.ts +2 -0
- package/dist/__tests__/utils/sanitize.test.d.ts.map +1 -0
- package/dist/__tests__/utils/sanitize.test.js +291 -0
- package/dist/__tests__/validator.test.d.ts +2 -0
- package/dist/__tests__/validator.test.d.ts.map +1 -0
- package/dist/__tests__/validator.test.js +300 -0
- package/dist/container.d.ts +80 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +271 -0
- package/dist/decorators.d.ts +92 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +343 -0
- package/dist/errors/http.error.d.ts +31 -0
- package/dist/errors/http.error.d.ts.map +1 -0
- package/dist/errors/http.error.js +62 -0
- package/dist/filters/exception-filter.d.ts +39 -0
- package/dist/filters/exception-filter.d.ts.map +1 -0
- package/dist/filters/exception-filter.js +38 -0
- package/dist/filters/http-exception.filter.d.ts +9 -0
- package/dist/filters/http-exception.filter.d.ts.map +1 -0
- package/dist/filters/http-exception.filter.js +42 -0
- package/dist/hazel-app.d.ts +78 -0
- package/dist/hazel-app.d.ts.map +1 -0
- package/dist/hazel-app.js +453 -0
- package/dist/hazel-module.d.ts +20 -0
- package/dist/hazel-module.d.ts.map +1 -0
- package/dist/hazel-module.js +109 -0
- package/dist/hazel-response.d.ts +20 -0
- package/dist/hazel-response.d.ts.map +1 -0
- package/dist/hazel-response.js +68 -0
- package/dist/health.d.ts +73 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +174 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +140 -0
- package/dist/interceptors/interceptor.d.ts +22 -0
- package/dist/interceptors/interceptor.d.ts.map +1 -0
- package/dist/interceptors/interceptor.js +46 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +238 -0
- package/dist/middleware/cors.middleware.d.ts +44 -0
- package/dist/middleware/cors.middleware.d.ts.map +1 -0
- package/dist/middleware/cors.middleware.js +118 -0
- package/dist/middleware/csrf.middleware.d.ts +82 -0
- package/dist/middleware/csrf.middleware.d.ts.map +1 -0
- package/dist/middleware/csrf.middleware.js +183 -0
- package/dist/middleware/global-middleware.d.ts +111 -0
- package/dist/middleware/global-middleware.d.ts.map +1 -0
- package/dist/middleware/global-middleware.js +179 -0
- package/dist/middleware/rate-limit.middleware.d.ts +73 -0
- package/dist/middleware/rate-limit.middleware.d.ts.map +1 -0
- package/dist/middleware/rate-limit.middleware.js +124 -0
- package/dist/middleware/security-headers.middleware.d.ts +76 -0
- package/dist/middleware/security-headers.middleware.d.ts.map +1 -0
- package/dist/middleware/security-headers.middleware.js +123 -0
- package/dist/middleware/timeout.middleware.d.ts +25 -0
- package/dist/middleware/timeout.middleware.d.ts.map +1 -0
- package/dist/middleware/timeout.middleware.js +74 -0
- package/dist/middleware.d.ts +13 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +47 -0
- package/dist/pipes/pipe.d.ts +50 -0
- package/dist/pipes/pipe.d.ts.map +1 -0
- package/dist/pipes/pipe.js +96 -0
- package/dist/pipes/validation.pipe.d.ts +6 -0
- package/dist/pipes/validation.pipe.d.ts.map +1 -0
- package/dist/pipes/validation.pipe.js +61 -0
- package/dist/request-context.d.ts +17 -0
- package/dist/request-context.d.ts.map +1 -0
- package/dist/request-context.js +2 -0
- package/dist/request-parser.d.ts +7 -0
- package/dist/request-parser.d.ts.map +1 -0
- package/dist/request-parser.js +60 -0
- package/dist/router.d.ts +33 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +426 -0
- package/dist/routing/route-matcher.d.ts +39 -0
- package/dist/routing/route-matcher.d.ts.map +1 -0
- package/dist/routing/route-matcher.js +93 -0
- package/dist/routing/version.decorator.d.ts +36 -0
- package/dist/routing/version.decorator.d.ts.map +1 -0
- package/dist/routing/version.decorator.js +89 -0
- package/dist/service.d.ts +9 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +39 -0
- package/dist/shutdown.d.ts +32 -0
- package/dist/shutdown.d.ts.map +1 -0
- package/dist/shutdown.js +109 -0
- package/dist/testing/testing.module.d.ts +83 -0
- package/dist/testing/testing.module.d.ts.map +1 -0
- package/dist/testing/testing.module.js +164 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/upload/file-upload.d.ts +75 -0
- package/dist/upload/file-upload.d.ts.map +1 -0
- package/dist/upload/file-upload.js +261 -0
- package/dist/utils/sanitize.d.ts +45 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/sanitize.js +165 -0
- package/dist/validator.d.ts +7 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +119 -0
- package/package.json +65 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HazelApp = exports.Module = exports.HazelModule = void 0;
|
|
7
|
+
exports.Controller = Controller;
|
|
8
|
+
exports.Injectable = Injectable;
|
|
9
|
+
exports.Get = Get;
|
|
10
|
+
exports.Post = Post;
|
|
11
|
+
exports.Put = Put;
|
|
12
|
+
exports.Delete = Delete;
|
|
13
|
+
exports.Patch = Patch;
|
|
14
|
+
exports.Inject = Inject;
|
|
15
|
+
exports.Service = Service;
|
|
16
|
+
exports.Body = Body;
|
|
17
|
+
exports.Request = Request;
|
|
18
|
+
exports.Param = Param;
|
|
19
|
+
exports.Query = Query;
|
|
20
|
+
exports.UsePipes = UsePipes;
|
|
21
|
+
exports.UseInterceptors = UseInterceptors;
|
|
22
|
+
exports.UseGuards = UseGuards;
|
|
23
|
+
exports.AITask = AITask;
|
|
24
|
+
exports.Req = Req;
|
|
25
|
+
exports.Headers = Headers;
|
|
26
|
+
exports.HttpCode = HttpCode;
|
|
27
|
+
exports.Header = Header;
|
|
28
|
+
exports.Redirect = Redirect;
|
|
29
|
+
exports.Res = Res;
|
|
30
|
+
require("reflect-metadata");
|
|
31
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
32
|
+
const hazel_app_1 = require("./hazel-app");
|
|
33
|
+
Object.defineProperty(exports, "HazelApp", { enumerable: true, get: function () { return hazel_app_1.HazelApp; } });
|
|
34
|
+
const CONTROLLER_METADATA_KEY = 'hazel:controller';
|
|
35
|
+
const INJECTABLE_METADATA_KEY = 'hazel:injectable';
|
|
36
|
+
const ROUTE_METADATA_KEY = 'hazel:routes';
|
|
37
|
+
const SERVICE_METADATA_KEY = 'hazel:service';
|
|
38
|
+
const INJECT_METADATA_KEY = 'hazel:inject';
|
|
39
|
+
const PIPE_METADATA_KEY = 'hazel:pipe';
|
|
40
|
+
const INTERCEPTOR_METADATA_KEY = 'hazel:interceptor';
|
|
41
|
+
const CLASS_INTERCEPTOR_METADATA_KEY = 'hazel:class-interceptors';
|
|
42
|
+
const HTTP_CODE_METADATA_KEY = 'hazel:http-code';
|
|
43
|
+
const HEADER_METADATA_KEY = 'hazel:headers';
|
|
44
|
+
const REDIRECT_METADATA_KEY = 'hazel:redirect';
|
|
45
|
+
// Re-export from hazel-module for backward compatibility
|
|
46
|
+
var hazel_module_1 = require("./hazel-module");
|
|
47
|
+
Object.defineProperty(exports, "HazelModule", { enumerable: true, get: function () { return hazel_module_1.HazelModule; } });
|
|
48
|
+
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return hazel_module_1.Module; } });
|
|
49
|
+
function Controller(options) {
|
|
50
|
+
return (target) => {
|
|
51
|
+
const opts = typeof options === 'string' ? { path: options } : options;
|
|
52
|
+
logger_1.default.debug(`Registering controller: ${target.constructor?.name || target.name} at path: ${opts.path}`);
|
|
53
|
+
Reflect.defineMetadata(CONTROLLER_METADATA_KEY, opts, target);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function Injectable(options = {}) {
|
|
57
|
+
return (target) => {
|
|
58
|
+
logger_1.default.debug(`Registering injectable: ${target.constructor?.name || target.name}`);
|
|
59
|
+
Reflect.defineMetadata(INJECTABLE_METADATA_KEY, options, target);
|
|
60
|
+
// Store scope metadata for container
|
|
61
|
+
if (options.scope) {
|
|
62
|
+
Reflect.defineMetadata('hazel:scope', options.scope, target);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function Get(options) {
|
|
67
|
+
const opts = typeof options === 'string' ? { path: options } : options || {};
|
|
68
|
+
return createRouteDecorator('GET', opts);
|
|
69
|
+
}
|
|
70
|
+
function Post(options) {
|
|
71
|
+
const opts = typeof options === 'string' ? { path: options } : options || {};
|
|
72
|
+
return createRouteDecorator('POST', opts);
|
|
73
|
+
}
|
|
74
|
+
function Put(options) {
|
|
75
|
+
const opts = typeof options === 'string' ? { path: options } : options || {};
|
|
76
|
+
return createRouteDecorator('PUT', opts);
|
|
77
|
+
}
|
|
78
|
+
function Delete(options) {
|
|
79
|
+
const opts = typeof options === 'string' ? { path: options } : options || {};
|
|
80
|
+
return createRouteDecorator('DELETE', opts);
|
|
81
|
+
}
|
|
82
|
+
function Patch(options) {
|
|
83
|
+
const opts = typeof options === 'string' ? { path: options } : options || {};
|
|
84
|
+
return createRouteDecorator('PATCH', opts);
|
|
85
|
+
}
|
|
86
|
+
function Inject(token) {
|
|
87
|
+
return (target, propertyKey, parameterIndex) => {
|
|
88
|
+
logger_1.default.debug(`Registering injection for parameter ${parameterIndex} in ${target.constructor?.name}`);
|
|
89
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, target) || [];
|
|
90
|
+
injections[parameterIndex] = token;
|
|
91
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, target);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function Service(options = {}) {
|
|
95
|
+
return function (target) {
|
|
96
|
+
Reflect.defineMetadata(SERVICE_METADATA_KEY, options, target);
|
|
97
|
+
// Store scope metadata for container
|
|
98
|
+
if (options.scope) {
|
|
99
|
+
Reflect.defineMetadata('hazel:scope', options.scope, target);
|
|
100
|
+
}
|
|
101
|
+
// Get constructor parameters
|
|
102
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', target) || [];
|
|
103
|
+
const repositories = paramTypes
|
|
104
|
+
.map((paramType, index) => {
|
|
105
|
+
const model = Reflect.getMetadata('hazel:repository', paramType)?.model;
|
|
106
|
+
if (model) {
|
|
107
|
+
return { index, model };
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
})
|
|
111
|
+
.filter(Boolean);
|
|
112
|
+
if (repositories.length > 0) {
|
|
113
|
+
Reflect.defineMetadata('hazel:repositories', repositories, target);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function Body(dtoType) {
|
|
118
|
+
return (target, propertyKey, parameterIndex) => {
|
|
119
|
+
if (!propertyKey) {
|
|
120
|
+
throw new Error('Body decorator must be used on a method parameter');
|
|
121
|
+
}
|
|
122
|
+
logger_1.default.debug(`Registering body parameter ${parameterIndex} in ${target.constructor?.name}`);
|
|
123
|
+
// Get the constructor of the target
|
|
124
|
+
const constructor = target
|
|
125
|
+
.constructor;
|
|
126
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
127
|
+
// Store the injection metadata
|
|
128
|
+
injections[parameterIndex] = {
|
|
129
|
+
type: 'body',
|
|
130
|
+
dtoType,
|
|
131
|
+
token: dtoType,
|
|
132
|
+
};
|
|
133
|
+
logger_1.default.debug('Setting DTO type from Body decorator:', dtoType?.name);
|
|
134
|
+
logger_1.default.debug('Updated injections:', JSON.stringify(injections, null, 2));
|
|
135
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function Request() {
|
|
139
|
+
return (target, propertyKey, parameterIndex) => {
|
|
140
|
+
if (!propertyKey) {
|
|
141
|
+
throw new Error('Request decorator must be used on a method parameter');
|
|
142
|
+
}
|
|
143
|
+
const constructor = target
|
|
144
|
+
.constructor;
|
|
145
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
146
|
+
injections[parameterIndex] = { type: 'request' };
|
|
147
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function Param(paramName, pipe) {
|
|
151
|
+
return (target, propertyKey, parameterIndex) => {
|
|
152
|
+
if (!propertyKey) {
|
|
153
|
+
throw new Error('Param decorator must be used on a method parameter');
|
|
154
|
+
}
|
|
155
|
+
logger_1.default.debug(`Registering param ${paramName} at index ${parameterIndex} in ${target.constructor?.name} with pipe:`, pipe?.name);
|
|
156
|
+
// Get the constructor of the target
|
|
157
|
+
const constructor = target
|
|
158
|
+
.constructor;
|
|
159
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
160
|
+
injections[parameterIndex] = { type: 'param', name: paramName, pipe };
|
|
161
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
162
|
+
logger_1.default.debug('Updated injections:', JSON.stringify(injections, null, 2));
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function Query(paramName, pipe) {
|
|
166
|
+
return (target, propertyKey, parameterIndex) => {
|
|
167
|
+
if (!propertyKey) {
|
|
168
|
+
throw new Error('Query decorator must be used on a method parameter');
|
|
169
|
+
}
|
|
170
|
+
logger_1.default.debug(`Registering query param ${paramName || 'all'} at index ${parameterIndex} in ${target.constructor?.name} with pipe:`, pipe?.name);
|
|
171
|
+
// Get the constructor of the target
|
|
172
|
+
const constructor = target
|
|
173
|
+
.constructor;
|
|
174
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
175
|
+
injections[parameterIndex] = { type: 'query', name: paramName, pipe };
|
|
176
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
177
|
+
logger_1.default.debug('Updated injections:', JSON.stringify(injections, null, 2));
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function UsePipes(...pipes) {
|
|
181
|
+
const decorator = (target, propertyKey) => {
|
|
182
|
+
const pipeMetadata = pipes.map((pipe) => {
|
|
183
|
+
if (typeof pipe === 'function') {
|
|
184
|
+
return { type: pipe };
|
|
185
|
+
}
|
|
186
|
+
return pipe;
|
|
187
|
+
});
|
|
188
|
+
if (propertyKey) {
|
|
189
|
+
// Method decorator
|
|
190
|
+
const routes = Reflect.getMetadata(ROUTE_METADATA_KEY, target.constructor) || [];
|
|
191
|
+
const route = routes.find((r) => r.propertyKey === propertyKey);
|
|
192
|
+
if (route) {
|
|
193
|
+
route.pipes = pipeMetadata;
|
|
194
|
+
logger_1.default.debug('Setting pipes for route:', {
|
|
195
|
+
method: route.method,
|
|
196
|
+
path: route.path,
|
|
197
|
+
pipes: pipeMetadata.map((p) => p.type.name),
|
|
198
|
+
});
|
|
199
|
+
Reflect.defineMetadata(ROUTE_METADATA_KEY, routes, target.constructor);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Class decorator
|
|
204
|
+
const existingPipes = Reflect.getMetadata(PIPE_METADATA_KEY, target) || [];
|
|
205
|
+
Reflect.defineMetadata(PIPE_METADATA_KEY, [...existingPipes, ...pipeMetadata], target);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
return decorator;
|
|
209
|
+
}
|
|
210
|
+
function UseInterceptors(...interceptors) {
|
|
211
|
+
const decorator = (target, propertyKey, descriptor) => {
|
|
212
|
+
const interceptorMetadata = interceptors.map((interceptor) => {
|
|
213
|
+
if (typeof interceptor === 'function') {
|
|
214
|
+
return { type: interceptor };
|
|
215
|
+
}
|
|
216
|
+
return interceptor;
|
|
217
|
+
});
|
|
218
|
+
if (propertyKey && descriptor) {
|
|
219
|
+
// Method decorator
|
|
220
|
+
logger_1.default.debug(`Registering interceptors for method ${String(propertyKey)} in ${target.constructor?.name}`);
|
|
221
|
+
Reflect.defineMetadata(INTERCEPTOR_METADATA_KEY, interceptorMetadata, target, propertyKey);
|
|
222
|
+
return descriptor;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// Class decorator
|
|
226
|
+
logger_1.default.debug(`Registering interceptors for class ${target.name}`);
|
|
227
|
+
Reflect.defineMetadata(CLASS_INTERCEPTOR_METADATA_KEY, interceptorMetadata, target);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
return decorator;
|
|
231
|
+
}
|
|
232
|
+
function UseGuards(...guards) {
|
|
233
|
+
const decorator = (target, propertyKey, descriptor) => {
|
|
234
|
+
if (propertyKey && descriptor) {
|
|
235
|
+
// Method decorator
|
|
236
|
+
const existingGuards = Reflect.getMetadata('hazel:guards', target, propertyKey) || [];
|
|
237
|
+
Reflect.defineMetadata('hazel:guards', [...existingGuards, ...guards], target, propertyKey);
|
|
238
|
+
return descriptor;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// Class decorator
|
|
242
|
+
const existingGuards = Reflect.getMetadata('hazel:guards', target) || [];
|
|
243
|
+
Reflect.defineMetadata('hazel:guards', [...existingGuards, ...guards], target);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
return decorator;
|
|
247
|
+
}
|
|
248
|
+
function AITask(options) {
|
|
249
|
+
return (target, propertyKey, descriptor) => {
|
|
250
|
+
Reflect.defineMetadata('hazel:ai-task', options, target, propertyKey);
|
|
251
|
+
return descriptor;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function Req() {
|
|
255
|
+
return (target, propertyKey, parameterIndex) => {
|
|
256
|
+
if (!propertyKey) {
|
|
257
|
+
throw new Error('Req decorator must be used on a method parameter');
|
|
258
|
+
}
|
|
259
|
+
const constructor = target
|
|
260
|
+
.constructor;
|
|
261
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
262
|
+
injections[parameterIndex] = { type: 'request' };
|
|
263
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function Headers(headerName) {
|
|
267
|
+
return (target, propertyKey, parameterIndex) => {
|
|
268
|
+
if (!propertyKey) {
|
|
269
|
+
throw new Error('Headers decorator must be used on a method parameter');
|
|
270
|
+
}
|
|
271
|
+
const constructor = target
|
|
272
|
+
.constructor;
|
|
273
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
274
|
+
injections[parameterIndex] = { type: 'headers', name: headerName };
|
|
275
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function HttpCode(statusCode) {
|
|
279
|
+
return (target, propertyKey, descriptor) => {
|
|
280
|
+
Reflect.defineMetadata(HTTP_CODE_METADATA_KEY, statusCode, target, propertyKey);
|
|
281
|
+
return descriptor;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function Header(name, value) {
|
|
285
|
+
return (target, propertyKey, descriptor) => {
|
|
286
|
+
const existingHeaders = Reflect.getMetadata(HEADER_METADATA_KEY, target, propertyKey) || [];
|
|
287
|
+
existingHeaders.push({ name, value });
|
|
288
|
+
Reflect.defineMetadata(HEADER_METADATA_KEY, existingHeaders, target, propertyKey);
|
|
289
|
+
return descriptor;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function Redirect(url, statusCode = 302) {
|
|
293
|
+
return (target, propertyKey, descriptor) => {
|
|
294
|
+
Reflect.defineMetadata(REDIRECT_METADATA_KEY, { url, statusCode }, target, propertyKey);
|
|
295
|
+
return descriptor;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function Res() {
|
|
299
|
+
return (target, propertyKey, parameterIndex) => {
|
|
300
|
+
if (!propertyKey) {
|
|
301
|
+
throw new Error('Res decorator must be used on a method parameter');
|
|
302
|
+
}
|
|
303
|
+
logger_1.default.debug(`Registering response parameter ${parameterIndex} in ${target.constructor?.name}`);
|
|
304
|
+
// Get the constructor of the target
|
|
305
|
+
const constructor = target
|
|
306
|
+
.constructor;
|
|
307
|
+
const injections = Reflect.getMetadata(INJECT_METADATA_KEY, constructor, propertyKey) || [];
|
|
308
|
+
// Store the injection metadata
|
|
309
|
+
injections[parameterIndex] = {
|
|
310
|
+
type: 'response',
|
|
311
|
+
};
|
|
312
|
+
Reflect.defineMetadata(INJECT_METADATA_KEY, injections, constructor, propertyKey);
|
|
313
|
+
logger_1.default.debug('Updated injections:', JSON.stringify(injections, null, 2));
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function createRouteDecorator(method, options) {
|
|
317
|
+
return (target, propertyKey, descriptor) => {
|
|
318
|
+
logger_1.default.debug(`Registering ${method} route: ${String(propertyKey)}`);
|
|
319
|
+
const routes = Reflect.getMetadata(ROUTE_METADATA_KEY, target.constructor) ||
|
|
320
|
+
[];
|
|
321
|
+
const routeOptions = typeof options === 'string' ? { path: options } : options || {};
|
|
322
|
+
const pipes = Reflect.getMetadata(PIPE_METADATA_KEY, target, propertyKey) || [];
|
|
323
|
+
const interceptors = Reflect.getMetadata(INTERCEPTOR_METADATA_KEY, target, propertyKey) || [];
|
|
324
|
+
const classInterceptors = Reflect.getMetadata(CLASS_INTERCEPTOR_METADATA_KEY, target.constructor) || [];
|
|
325
|
+
logger_1.default.debug('Route metadata:', {
|
|
326
|
+
method,
|
|
327
|
+
path: routeOptions.path || '/',
|
|
328
|
+
propertyKey: String(propertyKey),
|
|
329
|
+
pipes: pipes.map((p) => p.type.name),
|
|
330
|
+
interceptors: interceptors.map((i) => i.type.name),
|
|
331
|
+
});
|
|
332
|
+
routes.push({
|
|
333
|
+
method,
|
|
334
|
+
path: routeOptions.path || '/',
|
|
335
|
+
propertyKey,
|
|
336
|
+
middlewares: routeOptions.middlewares || [],
|
|
337
|
+
pipes: [...pipes, ...(routeOptions.pipes || [])],
|
|
338
|
+
interceptors: [...classInterceptors, ...interceptors, ...(routeOptions.interceptors || [])],
|
|
339
|
+
});
|
|
340
|
+
Reflect.defineMetadata(ROUTE_METADATA_KEY, routes, target.constructor);
|
|
341
|
+
return descriptor;
|
|
342
|
+
};
|
|
343
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare class HttpError extends Error {
|
|
2
|
+
readonly statusCode: number;
|
|
3
|
+
readonly errors?: string[] | undefined;
|
|
4
|
+
constructor(statusCode: number, message: string, errors?: string[] | undefined);
|
|
5
|
+
}
|
|
6
|
+
export declare class BadRequestError extends HttpError {
|
|
7
|
+
constructor(message: string, errors?: string[]);
|
|
8
|
+
}
|
|
9
|
+
export declare class UnauthorizedError extends HttpError {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class ForbiddenError extends HttpError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class NotFoundError extends HttpError {
|
|
16
|
+
constructor(message?: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class ConflictError extends HttpError {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class InternalServerError extends HttpError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
export declare const HttpException: typeof HttpError;
|
|
25
|
+
export declare const BadRequestException: typeof BadRequestError;
|
|
26
|
+
export declare const UnauthorizedException: typeof UnauthorizedError;
|
|
27
|
+
export declare const ForbiddenException: typeof ForbiddenError;
|
|
28
|
+
export declare const NotFoundException: typeof NotFoundError;
|
|
29
|
+
export declare const ConflictException: typeof ConflictError;
|
|
30
|
+
export declare const InternalServerErrorException: typeof InternalServerError;
|
|
31
|
+
//# sourceMappingURL=http.error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.error.d.ts","sourceRoot":"","sources":["../../src/errors/http.error.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;aAEhB,UAAU,EAAE,MAAM;aAElB,MAAM,CAAC,EAAE,MAAM,EAAE;gBAFjB,UAAU,EAAE,MAAM,EAClC,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAA;CAKpC;AAED,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE;CAI/C;AAED,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,OAAO,GAAE,MAAuB;CAI7C;AAED,qBAAa,cAAe,SAAQ,SAAS;gBAC/B,OAAO,GAAE,MAAoB;CAI1C;AAED,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,GAAE,MAAoB;CAI1C;AAED,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,GAAE,MAAgC;CAItD;AAGD,eAAO,MAAM,aAAa,kBAAY,CAAC;AACvC,eAAO,MAAM,mBAAmB,wBAAkB,CAAC;AACnD,eAAO,MAAM,qBAAqB,0BAAoB,CAAC;AACvD,eAAO,MAAM,kBAAkB,uBAAiB,CAAC;AACjD,eAAO,MAAM,iBAAiB,sBAAgB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,sBAAgB,CAAC;AAC/C,eAAO,MAAM,4BAA4B,4BAAsB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalServerErrorException = exports.ConflictException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = exports.HttpException = exports.InternalServerError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpError = void 0;
|
|
4
|
+
class HttpError extends Error {
|
|
5
|
+
constructor(statusCode, message, errors) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
this.name = 'HttpError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpError = HttpError;
|
|
13
|
+
class BadRequestError extends HttpError {
|
|
14
|
+
constructor(message, errors) {
|
|
15
|
+
super(400, message, errors);
|
|
16
|
+
this.name = 'BadRequestError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.BadRequestError = BadRequestError;
|
|
20
|
+
class UnauthorizedError extends HttpError {
|
|
21
|
+
constructor(message = 'Unauthorized') {
|
|
22
|
+
super(401, message);
|
|
23
|
+
this.name = 'UnauthorizedError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
27
|
+
class ForbiddenError extends HttpError {
|
|
28
|
+
constructor(message = 'Forbidden') {
|
|
29
|
+
super(403, message);
|
|
30
|
+
this.name = 'ForbiddenError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ForbiddenError = ForbiddenError;
|
|
34
|
+
class NotFoundError extends HttpError {
|
|
35
|
+
constructor(message = 'Not Found') {
|
|
36
|
+
super(404, message);
|
|
37
|
+
this.name = 'NotFoundError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.NotFoundError = NotFoundError;
|
|
41
|
+
class ConflictError extends HttpError {
|
|
42
|
+
constructor(message) {
|
|
43
|
+
super(409, message);
|
|
44
|
+
this.name = 'ConflictError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ConflictError = ConflictError;
|
|
48
|
+
class InternalServerError extends HttpError {
|
|
49
|
+
constructor(message = 'Internal Server Error') {
|
|
50
|
+
super(500, message);
|
|
51
|
+
this.name = 'InternalServerError';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.InternalServerError = InternalServerError;
|
|
55
|
+
// Aliases using Exception naming convention (matches documentation)
|
|
56
|
+
exports.HttpException = HttpError;
|
|
57
|
+
exports.BadRequestException = BadRequestError;
|
|
58
|
+
exports.UnauthorizedException = UnauthorizedError;
|
|
59
|
+
exports.ForbiddenException = ForbiddenError;
|
|
60
|
+
exports.NotFoundException = NotFoundError;
|
|
61
|
+
exports.ConflictException = ConflictError;
|
|
62
|
+
exports.InternalServerErrorException = InternalServerError;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Request, Response } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Arguments host provides access to the underlying platform request/response
|
|
4
|
+
*/
|
|
5
|
+
export interface ArgumentsHost {
|
|
6
|
+
switchToHttp(): {
|
|
7
|
+
getRequest<T = Request>(): T;
|
|
8
|
+
getResponse<T = Response>(): T;
|
|
9
|
+
};
|
|
10
|
+
getType(): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Exception filter interface
|
|
14
|
+
*/
|
|
15
|
+
export interface ExceptionFilter<T = unknown> {
|
|
16
|
+
catch(exception: T, host: ArgumentsHost): void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Implementation of ArgumentsHost
|
|
20
|
+
*/
|
|
21
|
+
export declare class ArgumentsHostImpl implements ArgumentsHost {
|
|
22
|
+
private readonly request;
|
|
23
|
+
private readonly response;
|
|
24
|
+
constructor(request: Request, response: Response);
|
|
25
|
+
switchToHttp(): {
|
|
26
|
+
getRequest: <T = Request>() => T;
|
|
27
|
+
getResponse: <T = Response>() => T;
|
|
28
|
+
};
|
|
29
|
+
getType(): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decorator to mark a class as an exception filter
|
|
33
|
+
*/
|
|
34
|
+
export declare function Catch(...exceptions: Array<new (...args: never[]) => unknown>): ClassDecorator;
|
|
35
|
+
/**
|
|
36
|
+
* Get exception types that a filter handles
|
|
37
|
+
*/
|
|
38
|
+
export declare function getFilterExceptions(filter: object): Array<new (...args: unknown[]) => unknown>;
|
|
39
|
+
//# sourceMappingURL=exception-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-filter.d.ts","sourceRoot":"","sources":["../../src/filters/exception-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,IAAI;QACd,UAAU,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC,CAAC;QAC7B,WAAW,CAAC,CAAC,GAAG,QAAQ,KAAK,CAAC,CAAC;KAChC,CAAC;IACF,OAAO,IAAI,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChE;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IAEnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ;IAGrC,YAAY,IAAI;QAAE,UAAU,EAAE,CAAC,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC;QAAC,WAAW,EAAE,CAAC,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAA;KAAE;IAOxF,OAAO,IAAI,MAAM;CAGlB;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,GAAG,cAAc,CAI7F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAE9F"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgumentsHostImpl = void 0;
|
|
4
|
+
exports.Catch = Catch;
|
|
5
|
+
exports.getFilterExceptions = getFilterExceptions;
|
|
6
|
+
/**
|
|
7
|
+
* Implementation of ArgumentsHost
|
|
8
|
+
*/
|
|
9
|
+
class ArgumentsHostImpl {
|
|
10
|
+
constructor(request, response) {
|
|
11
|
+
this.request = request;
|
|
12
|
+
this.response = response;
|
|
13
|
+
}
|
|
14
|
+
switchToHttp() {
|
|
15
|
+
return {
|
|
16
|
+
getRequest: () => this.request,
|
|
17
|
+
getResponse: () => this.response,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getType() {
|
|
21
|
+
return 'http';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ArgumentsHostImpl = ArgumentsHostImpl;
|
|
25
|
+
/**
|
|
26
|
+
* Decorator to mark a class as an exception filter
|
|
27
|
+
*/
|
|
28
|
+
function Catch(...exceptions) {
|
|
29
|
+
return (target) => {
|
|
30
|
+
Reflect.defineMetadata('hazel:exception-filter', exceptions, target);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get exception types that a filter handles
|
|
35
|
+
*/
|
|
36
|
+
function getFilterExceptions(filter) {
|
|
37
|
+
return Reflect.getMetadata('hazel:exception-filter', filter.constructor) || [];
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExceptionFilter, ArgumentsHost } from './exception-filter';
|
|
2
|
+
import { HttpError } from '../errors/http.error';
|
|
3
|
+
/**
|
|
4
|
+
* Built-in HTTP exception filter
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpExceptionFilter implements ExceptionFilter<HttpError> {
|
|
7
|
+
catch(exception: HttpError, host: ArgumentsHost): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=http-exception.filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-exception.filter.d.ts","sourceRoot":"","sources":["../../src/filters/http-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAS,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD;;GAEG;AACH,qBACa,mBAAoB,YAAW,eAAe,CAAC,SAAS,CAAC;IACpE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;CAsBvD"}
|
|
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpExceptionFilter = void 0;
|
|
13
|
+
const exception_filter_1 = require("./exception-filter");
|
|
14
|
+
const http_error_1 = require("../errors/http.error");
|
|
15
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
16
|
+
/**
|
|
17
|
+
* Built-in HTTP exception filter
|
|
18
|
+
*/
|
|
19
|
+
let HttpExceptionFilter = class HttpExceptionFilter {
|
|
20
|
+
catch(exception, host) {
|
|
21
|
+
const ctx = host.switchToHttp();
|
|
22
|
+
const response = ctx.getResponse();
|
|
23
|
+
const request = ctx.getRequest();
|
|
24
|
+
const status = exception.statusCode || 500;
|
|
25
|
+
const message = exception.message || 'Internal server error';
|
|
26
|
+
logger_1.default.error(`[${request.method}] ${request.url} - ${message} (${status})`);
|
|
27
|
+
if (process.env.NODE_ENV === 'development' && exception.stack) {
|
|
28
|
+
logger_1.default.debug(exception.stack);
|
|
29
|
+
}
|
|
30
|
+
response.status(status).json({
|
|
31
|
+
statusCode: status,
|
|
32
|
+
message,
|
|
33
|
+
timestamp: new Date().toISOString(),
|
|
34
|
+
path: request.url,
|
|
35
|
+
...(exception.errors && { errors: exception.errors }),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.HttpExceptionFilter = HttpExceptionFilter;
|
|
40
|
+
exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([
|
|
41
|
+
(0, exception_filter_1.Catch)(http_error_1.HttpError)
|
|
42
|
+
], HttpExceptionFilter);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Type } from './types';
|
|
2
|
+
import { Container } from './container';
|
|
3
|
+
import { Router } from './router';
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { Request, Response } from './types';
|
|
6
|
+
import { ShutdownManager } from './shutdown';
|
|
7
|
+
import { HealthCheckManager } from './health';
|
|
8
|
+
import { TimeoutOptions } from './middleware/timeout.middleware';
|
|
9
|
+
import { CorsOptions } from './middleware/cors.middleware';
|
|
10
|
+
export declare class HazelApp {
|
|
11
|
+
private readonly moduleType;
|
|
12
|
+
private container;
|
|
13
|
+
private router;
|
|
14
|
+
private requestParser;
|
|
15
|
+
private server;
|
|
16
|
+
private module;
|
|
17
|
+
private shutdownManager;
|
|
18
|
+
private healthManager;
|
|
19
|
+
private requestTimeout;
|
|
20
|
+
private corsEnabled;
|
|
21
|
+
private corsOptions?;
|
|
22
|
+
private timeoutMiddleware?;
|
|
23
|
+
constructor(moduleType: Type<unknown>);
|
|
24
|
+
private initialize;
|
|
25
|
+
private collectControllers;
|
|
26
|
+
register<T>(component: Type<T>): HazelApp;
|
|
27
|
+
get(path: string, ...handlers: Array<(req: Request, res: Response) => void>): HazelApp;
|
|
28
|
+
post(path: string, ...handlers: Array<(req: Request, res: Response) => void>): HazelApp;
|
|
29
|
+
put(path: string, ...handlers: Array<(req: Request, res: Response) => void>): HazelApp;
|
|
30
|
+
delete(path: string, ...handlers: Array<(req: Request, res: Response) => void>): HazelApp;
|
|
31
|
+
listen(port: number): Promise<void>;
|
|
32
|
+
private handleRoute;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Register a custom shutdown handler
|
|
36
|
+
*/
|
|
37
|
+
registerShutdownHandler(handler: {
|
|
38
|
+
name: string;
|
|
39
|
+
handler: () => Promise<void>;
|
|
40
|
+
timeout?: number;
|
|
41
|
+
}): void;
|
|
42
|
+
/**
|
|
43
|
+
* Register a custom health check
|
|
44
|
+
*/
|
|
45
|
+
registerHealthCheck(check: {
|
|
46
|
+
name: string;
|
|
47
|
+
check: () => Promise<{
|
|
48
|
+
status: 'healthy' | 'unhealthy' | 'degraded';
|
|
49
|
+
message?: string;
|
|
50
|
+
details?: Record<string, unknown>;
|
|
51
|
+
}>;
|
|
52
|
+
critical?: boolean;
|
|
53
|
+
timeout?: number;
|
|
54
|
+
}): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set request timeout
|
|
57
|
+
*/
|
|
58
|
+
setRequestTimeout(timeout: number, options?: TimeoutOptions): void;
|
|
59
|
+
/**
|
|
60
|
+
* Enable CORS
|
|
61
|
+
*/
|
|
62
|
+
enableCors(options?: CorsOptions): void;
|
|
63
|
+
/**
|
|
64
|
+
* Disable CORS
|
|
65
|
+
*/
|
|
66
|
+
disableCors(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get health check manager
|
|
69
|
+
*/
|
|
70
|
+
getHealthManager(): HealthCheckManager;
|
|
71
|
+
/**
|
|
72
|
+
* Get shutdown manager
|
|
73
|
+
*/
|
|
74
|
+
getShutdownManager(): ShutdownManager;
|
|
75
|
+
getContainer(): Container;
|
|
76
|
+
getRouter(): Router;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=hazel-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazel-app.d.ts","sourceRoot":"","sources":["../src/hazel-app.ts"],"names":[],"mappings":"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"}
|