@hazeljs/core 0.2.0-beta.1 → 0.2.0-beta.8
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 +21 -0
- package/dist/__tests__/container.test.js +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +30 -0
- package/package.json +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 HazelJS Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -219,7 +219,7 @@ describe('Container', () => {
|
|
|
219
219
|
Reflect.defineMetadata('design:paramtypes', [ServiceA], ServiceB);
|
|
220
220
|
container.registerProvider({ token: ServiceA, useClass: ServiceA });
|
|
221
221
|
container.registerProvider({ token: ServiceB, useClass: ServiceB });
|
|
222
|
-
expect(() => container.resolve(ServiceA)).toThrow(/
|
|
222
|
+
expect(() => container.resolve(ServiceA)).toThrow(/already being resolved/);
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
225
|
describe('clearRequestScope', () => {
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,OAAO,kBAAkB,CAAC;AAY1B,UAAU,UAAU;IAClB,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;AAEpF,qBAAa,MAAM;IAKL,OAAO,CAAC,SAAS;IAJ7B,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,cAAc,CAAuD;IAC7E,OAAO,CAAC,iBAAiB,CAAoB;gBAEzB,SAAS,EAAE,SAAS;IAUxC,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI;YA4DrC,UAAU;YAsBV,iBAAiB;IAe/B,OAAO,CAAC,kBAAkB;IAqQ1B,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,aAAa;IAOf,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA0C7F,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI;IAIjD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI;IAIlD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI;IAIjD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI;IAIpD,OAAO,CAAC,QAAQ;IAKV,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAkChE"}
|
package/dist/router.js
CHANGED
|
@@ -133,6 +133,29 @@ class Router {
|
|
|
133
133
|
method: req.method || 'GET',
|
|
134
134
|
url: req.url || '/',
|
|
135
135
|
};
|
|
136
|
+
// Execute guards (class-level + method-level)
|
|
137
|
+
const classGuards = Reflect.getMetadata('hazel:guards', controllerClass) || [];
|
|
138
|
+
const methodGuards = Reflect.getMetadata('hazel:guards', controllerClass.prototype, methodName) || [];
|
|
139
|
+
const allGuards = [...classGuards, ...methodGuards];
|
|
140
|
+
if (allGuards.length > 0) {
|
|
141
|
+
const executionContext = {
|
|
142
|
+
switchToHttp: () => ({
|
|
143
|
+
getRequest: () => req,
|
|
144
|
+
getResponse: () => res,
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
for (const guardType of allGuards) {
|
|
148
|
+
const guard = this.container.resolve(guardType);
|
|
149
|
+
const result = await guard.canActivate(executionContext);
|
|
150
|
+
if (!result) {
|
|
151
|
+
throw new http_error_1.UnauthorizedError('Unauthorized');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Propagate user set by guard to context
|
|
155
|
+
if (req.user) {
|
|
156
|
+
context.user = req.user;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
136
159
|
// Set DTO type from the first parameter that has a DTO type
|
|
137
160
|
for (const injection of injections) {
|
|
138
161
|
if (injection?.dtoType) {
|
|
@@ -210,6 +233,13 @@ class Router {
|
|
|
210
233
|
}
|
|
211
234
|
}
|
|
212
235
|
}
|
|
236
|
+
// Auto-inject RequestContext for undecorated parameters
|
|
237
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', controllerClass.prototype, methodName) || [];
|
|
238
|
+
for (let i = 0; i < paramTypes.length; i++) {
|
|
239
|
+
if (args[i] === undefined && !injections[i]) {
|
|
240
|
+
args[i] = context;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
213
243
|
// Apply ValidationPipe to the body if a DTO type is present
|
|
214
244
|
if (context.body && context.dtoType) {
|
|
215
245
|
logger_1.default.debug('Applying ValidationPipe with DTO type:', context.dtoType.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/core",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.8",
|
|
4
4
|
"description": "Core HazelJS framework - Dependency injection, routing, decorators, and base functionality",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"reflect-metadata": "^0.2.2",
|
|
24
24
|
"winston": "^3.17.0"
|
|
25
25
|
},
|
|
26
|
-
"peerDependencies": {},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/jest": "^29.5.14",
|
|
29
28
|
"@types/node": "^20.17.50",
|
|
@@ -61,5 +60,6 @@
|
|
|
61
60
|
"bugs": {
|
|
62
61
|
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
63
62
|
},
|
|
64
|
-
"homepage": "https://hazeljs.com"
|
|
63
|
+
"homepage": "https://hazeljs.com",
|
|
64
|
+
"gitHead": "b5cc0bf7d43739cad25220a611490b1d175acd62"
|
|
65
65
|
}
|