@hazeljs/core 0.2.0-beta.73 → 0.2.0-beta.74
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 +29 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -215,6 +215,28 @@ export class UserController {
|
|
|
215
215
|
}
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
+
### Custom metadata and parameter decorators
|
|
219
|
+
|
|
220
|
+
Attach custom metadata for guards or other layers with **SetMetadata** / **getMetadata**, and build your own parameter decorators with **createParamDecorator**:
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { SetMetadata, getMetadata, createParamDecorator } from '@hazeljs/core';
|
|
224
|
+
|
|
225
|
+
// Custom metadata (e.g. for guards)
|
|
226
|
+
@SetMetadata('roles', ['admin'])
|
|
227
|
+
class AdminController {}
|
|
228
|
+
|
|
229
|
+
// Custom parameter decorator
|
|
230
|
+
const CurrentUser = createParamDecorator((_req, ctx) => ctx.user);
|
|
231
|
+
|
|
232
|
+
@Get('profile')
|
|
233
|
+
getProfile(@CurrentUser user: User) {
|
|
234
|
+
return user;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Use the custom param decorator **without** parentheses: `@CurrentUser`. See the [full API reference](https://hazeljs.com/docs/api-reference) for `ParamDecoratorContext` and `CUSTOM_METADATA_PREFIX`.
|
|
239
|
+
|
|
218
240
|
## Middleware
|
|
219
241
|
|
|
220
242
|
### Global Middleware
|
|
@@ -504,10 +526,13 @@ Startup and registration logs (controllers, routes, providers) are at `debug` le
|
|
|
504
526
|
- `@Controller(path)` - Define a controller
|
|
505
527
|
- `@Injectable(options?)` - Mark class as injectable
|
|
506
528
|
- `@Get(path?)`, `@Post(path?)`, `@Put(path?)`, `@Delete(path?)`, `@Patch(path?)` - HTTP methods
|
|
507
|
-
- `@Param(name)`, `@Query(name)`, `@Body()`, `@Headers(name)` - Parameter extraction
|
|
508
|
-
- `@
|
|
509
|
-
- `@
|
|
510
|
-
- `@
|
|
529
|
+
- `@Param(name)`, `@Query(name)`, `@Body()`, `@Headers(name)`, `@Req()`, `@Res()`, `@Ip()`, `@Host()` - Parameter extraction
|
|
530
|
+
- `@UseGuards(...guards)`, `@UseInterceptors(...interceptors)`, `@UsePipes(...pipes)` - Apply guards, interceptors, pipes
|
|
531
|
+
- `@Public()` / `@SkipAuth()` - Mark route as public
|
|
532
|
+
- `@Timeout(ms)`, `@Retry(options)`, `@Optional()`, `@Session()` - Per-route behavior
|
|
533
|
+
- `@ApiTags(...tags)`, `@ApiOperation(options)` - OpenAPI metadata
|
|
534
|
+
- **SetMetadata(key, value)** - Attach custom metadata to a class or method (read with `getMetadata(key, target, propertyKey?)`)
|
|
535
|
+
- **createParamDecorator(resolve)** - Build custom parameter decorators that inject values from `(req, context, container)`
|
|
511
536
|
|
|
512
537
|
### Classes
|
|
513
538
|
|
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.74",
|
|
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",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://hazeljs.com",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "f863c8fb663e52a87551bdb34a2df59ceed3d423"
|
|
67
67
|
}
|