Skip to content

refactor(middleware): use metadataTarget consistently in class decorator branches#161

Merged
VikramAditya33 merged 1 commit into
FOSSFORGE:mainfrom
mvanhorn:refactor/metadataTarget-consistent-79
May 18, 2026
Merged

refactor(middleware): use metadataTarget consistently in class decorator branches#161
VikramAditya33 merged 1 commit into
FOSSFORGE:mainfrom
mvanhorn:refactor/metadataTarget-consistent-79

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

Hoist the metadataTarget derivation in UsePipes, UseGuards, and UseFilters so the class-decorator branch uses the same target as the method-decorator branch.

Closes #79

Why

Each of the three decorators already derives metadataTarget for method/parameter application:

const metadataTarget = typeof target === 'function' ? target : (target as object).constructor;

but the class-decorator branch still calls Reflect.getMetadata / Reflect.defineMetadata with target directly. For a class decorator target is the constructor itself so the two are equivalent today, but mixing the keys means a future lookup using metadataTarget on a class-decorated handler would not find the metadata written via target. Hoisting the derivation keeps the metadata key consistent across both branches.

Changes

  • src/websocket/middleware/pipes/use-pipes.decorator.ts: class branch now reads/writes against metadataTarget.
  • src/websocket/middleware/guards/use-guards.decorator.ts: hoist metadataTarget to the top of the decorator body, use it in both branches.
  • src/websocket/middleware/filters/use-filters.decorator.ts: same hoist.

The method-decorator branches are unchanged (they already used metadataTarget); the only semantic move is in the class branch.

Verification

  • npm run build clean.
  • npx jest src/websocket/middleware/{pipes,guards,filters}/ - 50/50 passing.
  • npm run format:check clean on the three files.
  • npx eslint clean on the three files.

…tor branches

Closes FOSSFORGE#79.

`UsePipes`, `UseGuards`, and `UseFilters` already compute
`metadataTarget` for the method-decorator branch but the class-decorator
branch still calls `Reflect.getMetadata`/`defineMetadata` with `target`
directly. Hoist the `metadataTarget` computation to the top of the
decorator body and use it in both branches.

Functionally equivalent (class decorators receive the constructor as
`target`), but keeps the metadata-key target consistent across method
and class application sites - which matters when the same decorator
might one day be used to look up a key written by the other branch.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 21d637f5-da38-4694-81d2-d8dc37b4bedf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VikramAditya33 VikramAditya33 self-requested a review May 18, 2026 07:45
Copy link
Copy Markdown
Collaborator

@VikramAditya33 VikramAditya33 left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you

@VikramAditya33 VikramAditya33 merged commit fb800b1 into FOSSFORGE:main May 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use metadataTarget consistently in UsePipes decorator

2 participants