feat: add @HttpMethod - #9
Conversation
🦋 Changeset detectedLatest commit: 9b7e64b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds a new exported HttpMethod type and decorator, refactors Get/Post/Put/Delete to delegate to HttpMethod, updates auralis.ts to import the HttpMethod type-only, and adds a changeset that bumps @auralis/core with the message "feat: add @HttpMethod". Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer (annotation)
participant Method as Controller Method
participant VerbDec as @Get/@Post/@Put/@Delete
participant HM as HttpMethod factory
participant Reg as Auralis Registry
Dev->>Method: add @VerbDec
Method->>VerbDec: apply decorator
VerbDec->>HM: delegate to HttpMethod("VERB")
HM->>Reg: ensure controller container & handlers map
HM->>Reg: ensure handler metadata exists
HM->>Reg: set handler.method = "VERB"
Note over HM,Reg: optional debug log if AURALIS_DEBUG
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (7)
.changeset/pretty-owls-fly.md (1)
2-2: Consider bumping @auralis/core as a minor, not patch.This introduces a new public decorator (
@HttpMethod) and expands the public API. By SemVer, adding functionality in a backward-compatible manner typically warrants a minor version bump.Apply this diff if you agree:
-"@auralis/core": patch +"@auralis/core": minorpackages/core/src/decorators/put.decorator.ts (1)
3-5: Fix the MDN reference URL.The correct MDN path is “Web/HTTP/Methods/PUT”, not “Web/HTTP/Reference/Methods/PUT”.
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/PUT + * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUTpackages/core/src/decorators/get.decorator.ts (1)
3-5: Fix the MDN reference URL.The correct MDN path is “Web/HTTP/Methods/GET”, not “Web/HTTP/Reference/Methods/GET”.
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/GET + * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GETpackages/core/src/decorators/post.decorator.ts (1)
3-5: Fix the MDN reference URL.The correct MDN path is “Web/HTTP/Methods/POST”, not “Web/HTTP/Reference/Methods/POST”.
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST + * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POSTpackages/core/src/decorators/delete.decorator.ts (2)
3-5: Use the canonical MDN URL for DELETESlight nit: the canonical MDN path is /Web/HTTP/Methods/DELETE.
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/DELETE + * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
1-1: Reduce ambiguity by aliasing the value importType and value share the same export name HttpMethod. Aliasing the value import clarifies intent at the call site.
-import { HttpMethod } from "./http-method.decorator.ts"; +import { HttpMethod as HttpMethodDecorator } from "./http-method.decorator.ts"; @@ -export const Delete: MethodDecorator = HttpMethod("DELETE"); +export const Delete: MethodDecorator = HttpMethodDecorator("DELETE");Also applies to: 6-6
packages/core/src/decorators/http-method.decorator.ts (1)
4-12: Include TRACE to complete the standard HTTP method unionTRACE is part of the standard set per MDN. Adding it helps completeness and type safety.
export type HttpMethod = | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" - | "PATCH"; + | "PATCH" + | "TRACE";
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
.changeset/pretty-owls-fly.md(1 hunks)packages/core/src/auralis.ts(1 hunks)packages/core/src/decorators/delete.decorator.ts(1 hunks)packages/core/src/decorators/get.decorator.ts(1 hunks)packages/core/src/decorators/http-method.decorator.ts(1 hunks)packages/core/src/decorators/post.decorator.ts(1 hunks)packages/core/src/decorators/put.decorator.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/core/src/decorators/put.decorator.ts (2)
packages/core/src/index.ts (1)
Put(7-7)packages/core/src/decorators/http-method.decorator.ts (2)
HttpMethod(4-12)HttpMethod(14-41)
packages/core/src/decorators/delete.decorator.ts (1)
packages/core/src/decorators/http-method.decorator.ts (2)
HttpMethod(4-12)HttpMethod(14-41)
packages/core/src/decorators/get.decorator.ts (1)
packages/core/src/decorators/http-method.decorator.ts (2)
HttpMethod(4-12)HttpMethod(14-41)
packages/core/src/decorators/post.decorator.ts (1)
packages/core/src/decorators/http-method.decorator.ts (2)
HttpMethod(4-12)HttpMethod(14-41)
🪛 GitHub Check: Lint: node-24, ubuntu-latest
packages/core/src/decorators/http-method.decorator.ts
[warning] 30-30:
Forbidden non-null assertion
[warning] 23-23:
Forbidden non-null assertion
🔇 Additional comments (5)
packages/core/src/auralis.ts (1)
6-6: Good switch to a type-only import.This keeps the runtime bundle clean while aligning with the shared HttpMethod type. No concerns.
packages/core/src/decorators/put.decorator.ts (1)
6-6: LGTM: Put delegates to the shared HttpMethod factory.Removes duplication and centralizes registration logic. Good change.
packages/core/src/decorators/get.decorator.ts (1)
6-6: LGTM: Get now reuses the shared HttpMethod decorator.Consistent with other HTTP verb decorators and reduces boilerplate.
packages/core/src/decorators/post.decorator.ts (1)
6-6: LGTM: Post now delegates to the shared HttpMethod decorator.Keeps behavior centralized and consistent with other verbs.
packages/core/src/decorators/delete.decorator.ts (1)
6-6: LGTM: Delegating to shared HttpMethod keeps decorators DRY and consistentThis simplifies maintenance and centralizes behavior. Looks good.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (2)
packages/core/src/decorators/http-method.decorator.ts (2)
14-33: Remove non-null assertions and make get-or-create explicit (fixes lint warnings)This removes the “Forbidden non-null assertion” warnings (Lines 25 and 32) and improves type-safety by explicitly typing the registry and performing get-or-create steps.
export function HttpMethod(method: HttpMethod): MethodDecorator { - return (target, propertyKey, descriptor) => { + type HandlerFn = (...args: unknown[]) => unknown; + interface HandlerRef { + method?: HttpMethod; + } + interface ControllerRef { + handlers: Map<HandlerFn, HandlerRef>; + } + return (target, propertyKey, descriptor) => { const controller = ( typeof target === "function" ? target : target.constructor ) as Constructor; - const fn = descriptor.value as (...args: unknown[]) => unknown; + const fn = descriptor.value as HandlerFn; - if (!Auralis[AURALIS_REGISTRY_SYMBOL].has(controller)) { - Auralis[AURALIS_REGISTRY_SYMBOL].set(controller, {}); - } - - const controllerRef = Auralis[AURALIS_REGISTRY_SYMBOL].get(controller)!; - controllerRef.handlers ??= new Map(); - - if (!controllerRef.handlers.has(fn)) { - controllerRef.handlers.set(fn, {}); - } - - const handlerRef = controllerRef.handlers.get(fn)!; - handlerRef.method = method; + const registry = Auralis[AURALIS_REGISTRY_SYMBOL] as Map< + Constructor, + Partial<ControllerRef> + >; + let controllerRef = registry.get(controller); + if (!controllerRef) { + controllerRef = {}; + registry.set(controller, controllerRef); + } + if (!controllerRef.handlers) { + controllerRef.handlers = new Map<HandlerFn, HandlerRef>(); + } + let handlerRef = controllerRef.handlers.get(fn); + if (!handlerRef) { + handlerRef = {}; + controllerRef.handlers.set(fn, handlerRef); + } + handlerRef.method = method;
35-41: Guard process for non-Node runtimes and improve debug readabilityReferencing process directly will throw in non-Node environments. Also prefer logging the controller’s name for readability.
- if (process.env.AURALIS_DEBUG) { - console.debug(`[${method}]:`, { - owningClass: controller, - propertyKey, - fn, - }); - } + if (typeof process !== "undefined" && process.env?.AURALIS_DEBUG) { + console.debug(`[${method}]:`, { + owningClass: (controller as any)?.name ?? controller, + propertyKey, + fn, + }); + }
🧹 Nitpick comments (2)
packages/core/src/decorators/http-method.decorator.ts (2)
4-12: Consider including TRACE or confirm intentional omissionCommon method sets also include TRACE. If it wasn’t intentionally excluded, add it for completeness.
export type HttpMethod = | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" - | "PATCH"; + | "PATCH" + | "TRACE";
14-14: Name overloading of type and value is fine; consider a brief JSDoc to clarifySharing the name HttpMethod for both the type and decorator is legal and idiomatic in TS, but can be momentarily confusing. A short JSDoc on the decorator clarifying its usage as @HttpMethod("GET") would help DX.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/core/src/decorators/http-method.decorator.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Shinigami92
PR: auralisjs/auralis#9
File: packages/core/src/decorators/get.decorator.ts:1-6
Timestamp: 2025-08-13T16:52:45.876Z
Learning: In the Auralis framework, Shinigami92 plans to merge Path and HttpMethod decorators into a single decorator to allow usage like Get('/:id') instead of Get Path('/:id'), improving developer experience and following common HTTP framework patterns.
📚 Learning: 2025-08-13T16:52:45.876Z
Learnt from: Shinigami92
PR: auralisjs/auralis#9
File: packages/core/src/decorators/get.decorator.ts:1-6
Timestamp: 2025-08-13T16:52:45.876Z
Learning: In the Auralis framework, Shinigami92 plans to merge Path and HttpMethod decorators into a single decorator to allow usage like Get('/:id') instead of Get Path('/:id'), improving developer experience and following common HTTP framework patterns.
Applied to files:
packages/core/src/decorators/http-method.decorator.ts
🧬 Code Graph Analysis (1)
packages/core/src/decorators/http-method.decorator.ts (2)
packages/core/src/utilities/constructor.util.ts (1)
Constructor(1-1)packages/core/src/auralis.ts (2)
Auralis(39-242)AURALIS_REGISTRY_SYMBOL(12-12)
🪛 GitHub Check: Lint: node-24, ubuntu-latest
packages/core/src/decorators/http-method.decorator.ts
[warning] 32-32:
Forbidden non-null assertion
[warning] 25-25:
Forbidden non-null assertion
🔇 Additional comments (1)
packages/core/src/decorators/http-method.decorator.ts (1)
16-19: Good: correctly handles static methods and narrows handler typeThe controller resolution now supports static methods, and the handler type is no longer the broad Function. Looks good.
Summary by CodeRabbit