File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed
Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @auralis/core " : minor
3+ ---
4+
5+ feat: add ` @Controller ` decorator
Original file line number Diff line number Diff line change 1+ import type { Constructor } from "../utilities/constructor.util.ts" ;
2+ import { ensureControllerRef } from "../utilities/registry.util.ts" ;
3+
4+ /**
5+ * Controller decorator for defining a controller class.
6+ *
7+ * This decorator does not apply response headers.
8+ *
9+ * @param path The base path for the controller that usually starts with a slash.
10+ *
11+ * @see `RestController` if you want to create a RESTful controller.
12+ */
13+ export function Controller ( path : string ) : ClassDecorator {
14+ return function ( target ) {
15+ const controller = target as unknown as Constructor ;
16+
17+ const controllerRef = ensureControllerRef ( controller ) ;
18+
19+ controllerRef . path = path ;
20+ controllerRef . responseHeaders ??= { } ;
21+
22+ if ( process . env . AURALIS_DEBUG ) {
23+ console . debug ( "[Controller]:" , {
24+ args : [ target ] ,
25+ controller,
26+ path,
27+ } ) ;
28+ }
29+ } ;
30+ }
Original file line number Diff line number Diff line change 11import type { Constructor } from "../utilities/constructor.util.ts" ;
22import { ensureControllerRef } from "../utilities/registry.util.ts" ;
33
4+ /**
5+ * REST controller decorator for defining a RESTful controller class.
6+ *
7+ * This decorator applies the `Content-Type: application/json; charset=utf-8` response header.
8+ *
9+ * @param path The base path for the controller that usually starts with a slash.
10+ *
11+ * @see `Controller` if you want to create a basic controller that does not apply response headers.
12+ */
413export function RestController ( path : string ) : ClassDecorator {
514 return function ( target ) {
615 const controller = target as unknown as Constructor ;
Original file line number Diff line number Diff line change 11export type { Auralis } from "./auralis.ts" ;
2+ export { Controller } from "./decorators/controller.decorator.ts" ;
23export { Delete } from "./decorators/delete.decorator.ts" ;
34export { Get } from "./decorators/get.decorator.ts" ;
45export { HttpMethod } from "./decorators/http-method.decorator.ts" ;
You can’t perform that action at this time.
0 commit comments