Skip to content

feat: add @HttpMethod - #9

Merged
Shinigami92 merged 4 commits into
mainfrom
feat-add-http-method-decorator
Aug 13, 2025
Merged

feat: add @HttpMethod#9
Shinigami92 merged 4 commits into
mainfrom
feat-add-http-method-decorator

Conversation

@Shinigami92

@Shinigami92 Shinigami92 commented Aug 13, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added a shared HttpMethod decorator and expanded HTTP-verb type (includes HEAD, CONNECT, OPTIONS, PATCH plus GET/POST/PUT/DELETE).
  • Refactor
    • Consolidated Get/Post/Put/Delete decorators to delegate to the shared HttpMethod for consistent behavior and maintenance.
  • Chores
    • Minor version bump for core and added a changeset entry documenting the HttpMethod addition.

@Shinigami92 Shinigami92 self-assigned this Aug 13, 2025
@Shinigami92 Shinigami92 added the c: feature Request for new feature label Aug 13, 2025
@changeset-bot

changeset-bot Bot commented Aug 13, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9b7e64b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@auralis/core Minor

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

@coderabbitai

coderabbitai Bot commented Aug 13, 2025

Copy link
Copy Markdown

Walkthrough

Adds 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

Cohort / File(s) Summary
New HttpMethod decorator & type
packages/core/src/decorators/http-method.decorator.ts
Adds exported HttpMethod type (HTTP verb union) and exported HttpMethod(method) decorator factory that ensures controller handler metadata exists in the Auralis registry and sets the handler's HTTP method; emits debug logging when AURALIS_DEBUG is truthy.
Refactor HTTP-verb decorators
packages/core/src/decorators/get.decorator.ts, packages/core/src/decorators/post.decorator.ts, packages/core/src/decorators/put.decorator.ts, packages/core/src/decorators/delete.decorator.ts
Replaces per-decorator registry-manipulating implementations with one-line delegations to HttpMethod("VERB"); removes local registry mutations and per-decorator debug logic; adds brief JSDoc/MDN references.
Core type import update
packages/core/src/auralis.ts
Removes local HttpMethod union alias and imports the HttpMethod type-only from the new decorator module; no runtime changes.
Changeset metadata
.changeset/pretty-owls-fly.md
Adds changeset declaring a minor bump for @auralis/core with message: "feat: add @HttpMethod".

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Poem

A rabbit taps keys soft and light,
I stitch verbs to handlers, snug and right.
GET, POST, PUT, DELETE in a row—
One factory binds them, tidy and slow.
🥕🐰

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-add-http-method-decorator

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

github-actions Bot commented Aug 13, 2025

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 6.51% (🎯 90%)
⬆️ +0.71%
29 / 445
🔴 Statements 6.51% (🎯 90%)
⬆️ +0.71%
29 / 445
🔴 Functions 19.23% (🎯 90%)
⬇️ -0.77%
5 / 26
🔴 Branches 26.31% (🎯 85%)
⬇️ -1.46%
5 / 19
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/auralis.ts 8.93%
🟰 ±0%
100%
🟰 ±0%
40%
🟰 ±0%
8.93%
🟰 ±0%
66-137, 142-241, 244-267
packages/core/src/decorators/delete.decorator.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
1-6
packages/core/src/decorators/get.decorator.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
1-6
packages/core/src/decorators/http-method.decorator.ts 0% 0% 0% 0% 1-43
packages/core/src/decorators/post.decorator.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
1-6
packages/core/src/decorators/put.decorator.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
1-6
Unchanged Files
examples/cat-rest-api/src/main.ts 0% 0% 0% 0% 1-10
examples/cat-rest-api/src/cats/cat.controller.ts 0% 0% 0% 0% 1-64
examples/cat-rest-api/src/cats/cat.dto.ts 0% 100% 100% 0% 3-13
packages/core/src/index.ts 0% 100% 100% 0% 2-13
packages/core/src/decorators/path-variable.decorator.ts 0% 0% 0% 0% 1-39
packages/core/src/decorators/path.decorator.ts 0% 0% 0% 0% 1-38
packages/core/src/decorators/request-body.decorator.ts 0% 0% 0% 0% 1-42
packages/core/src/decorators/rest-controller.decorator.ts 0% 0% 0% 0% 1-27
packages/core/src/errors/auralis-response.error.ts 26.31% 0% 0% 26.31% 7-9, 12-22
packages/core/src/errors/internal-server-response.error.ts 57.14% 100% 0% 57.14% 5-7
packages/core/src/errors/not-found-response.error.ts 57.14% 100% 0% 57.14% 5-7
packages/core/src/factories/auralis.factory.ts 0% 0% 0% 0% 1-12
packages/core/src/utilities/constructor.util.ts 100% 100% 100% 100%
packages/core/src/utilities/param-names.util.ts 0% 0% 0% 0% 1-11
Generated in workflow #19 for commit 9b7e64b by the Vitest Coverage Report Action

@Shinigami92

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 13, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread .changeset/pretty-owls-fly.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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": minor
packages/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/PUT
packages/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/GET
packages/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/POST
packages/core/src/decorators/delete.decorator.ts (2)

3-5: Use the canonical MDN URL for DELETE

Slight 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 import

Type 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 union

TRACE 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

📥 Commits

Reviewing files that changed from the base of the PR and between 36e0749 and 5c8db0b.

📒 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 consistent

This simplifies maintenance and centralizes behavior. Looks good.

Comment thread packages/core/src/decorators/get.decorator.ts
Comment thread packages/core/src/decorators/http-method.decorator.ts
Comment thread packages/core/src/decorators/http-method.decorator.ts Outdated
Comment thread packages/core/src/decorators/http-method.decorator.ts Outdated
Comment thread packages/core/src/decorators/http-method.decorator.ts
Comment thread packages/core/src/decorators/http-method.decorator.ts
@Shinigami92
Shinigami92 added this pull request to the merge queue Aug 13, 2025
Merged via the queue into main with commit fd4a071 Aug 13, 2025
7 of 8 checks passed
@Shinigami92
Shinigami92 deleted the feat-add-http-method-decorator branch August 13, 2025 16:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 readability

Referencing 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 omission

Common 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 clarify

Sharing 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8626681 and 9b7e64b.

📒 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 type

The controller resolution now supports static methods, and the handler type is no longer the broad Function. Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant