Skip to content

feat(decorators): update @routup/decorators for routup v5#764

Merged
tada5hi merged 2 commits intomasterfrom
745-decorators
Apr 8, 2026
Merged

feat(decorators): update @routup/decorators for routup v5#764
tada5hi merged 2 commits intomasterfrom
745-decorators

Conversation

@tada5hi
Copy link
Copy Markdown
Contributor

@tada5hi tada5hi commented Apr 8, 2026

closes #745

Summary by CodeRabbit

  • New Features

    • Added @DContext() decorator; controller methods may return values directly (framework handles responses)
  • Refactor

    • Shifted handlers to event-based signatures and simplified method parameter patterns
  • Documentation

    • README updated with expanded "Parameter Decorators" table and new usage/installation examples
  • Tests

    • Tests switched to Fetch-style execution instead of Node/supertest
  • Chores

    • Package alignment updated for v5 and lint-staged added for source linting

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d5de69ed-b42b-44a5-8005-1876977dc289

📥 Commits

Reviewing files that changed from the base of the PR and between 18760a4 and 7e8aef3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json

📝 Walkthrough

Walkthrough

Updated @routup/decorators for routup v5: handlers switched from (req, res, next) to single IRoutupEvent, parameter extraction moved to event-based async APIs, new DContext decorator added, core handler wiring switched to defineCoreHandler, README/tests updated to use router.fetch and returned responses.

Changes

Cohort / File(s) Summary
Docs & Package
packages/decorators/README.md, packages/decorators/package.json, package.json
README updated for v5 event semantics and Parameter Decorators table; install/example uses serve(router); bumped routup peer/dev dependency to ^5.0.0-beta.3; removed supertest deps; added lint-staged config.
Core types
packages/decorators/src/type.ts, packages/decorators/src/parameter/constants.ts, packages/decorators/src/parameter/type.ts
Replaced Request/Response/Next types with IRoutupEvent; HandlerContext → { event: IRoutupEvent }; HandlerInterface.run accepts event; added ParameterType.CONTEXT; removed DecoratorParameterBuildFn.
Argument & extractor logic
packages/decorators/src/method/arguments.ts, packages/decorators/src/parameter/module.ts
buildDecoratorMethodArguments made async, returns Promise<any[]>, awaits extractors and sources values from context.event (params, headers, headers.get, readRequestBody, etc.); added DContext() decorator factory.
Mounting & handlers
packages/decorators/src/mount.ts, packages/decorators/src/utils/handler.ts
Switched mountController(s) to accept IRouter; replaced coreHandler with defineCoreHandler; registered handlers now receive single event and call buildDecoratorMethodArguments({ event }, ...); class handler factory updated to call middle(event) / middle.run(event).
Test fixtures
packages/decorators/test/data/...
test/data/combined.ts, .../cookie.ts, .../get.ts, .../header.ts, .../middleware.ts, .../post.ts, .../query.ts
Controllers and middleware signatures changed to accept IRoutupEvent or use @DContext()/@DPath/@DPaths only; removed @DRequest/@DResponse/@DNext usage; replaced send(res, ...) with returned values and event-based extraction.
Unit tests
packages/decorators/test/unit/...
body.spec.ts, combined.spec.ts, cookie.spec.ts, header.spec.ts, middleware.spec.ts, query.spec.ts
Removed supertest/createNodeDispatcher; tests use router.fetch(Request) via new createTestRequest; updated assertions to Fetch API style; extractors switched to use context.event and readRequestBody (body extractor async).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Client
  participant Router as Router (IRouter)
  participant Core as defineCoreHandler
  participant Args as buildDecoratorMethodArguments
  participant Controller as Controller Method

  Client->>Router: fetch(Request)
  Router->>Core: matched handler(event)
  Core->>Args: buildDecoratorMethodArguments({ event }, parameters)
  Args-->>Core: Promise<arguments>
  Core->>Controller: controllerMethod(...arguments)
  Controller-->>Core: return value
  Core-->>Router: resolve response
  Router-->>Client: Response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 Hopped from req/res to one bright event,

I nibble params where headers are sent,
No more next-calls — I return a treat,
Tests fetch my routes, responses neat,
A rabbit's cheer for v5's new beat.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: updating the @routup/decorators package to support routup v5.
Linked Issues check ✅ Passed All code changes from issue #745 are implemented: peer dependencies updated [package.json], handler signatures converted from (req, res, next) to (event) [mount.ts, handler.ts, type.ts, test files], internal send() calls replaced with return values [test data files], useRequest* calls replaced with event.* properties [arguments.ts, test files], tests updated to use router.fetch instead of supertest [test unit files].
Out of Scope Changes check ✅ Passed All changes are directly related to the routup v5 migration objectives. No unrelated modifications detected beyond the scope of updating handler semantics, parameter decorators, and test infrastructure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 745-decorators

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
packages/decorators/test/unit/header.spec.ts (1)

6-9: Consider centralizing createTestRequest() in a shared test util.

This helper is repeated across multiple spec files; extracting it once will reduce duplication and keep request construction behavior consistent.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/decorators/test/unit/header.spec.ts` around lines 6 - 9, Extract the
createTestRequest function into a single shared test utility module and export
it (preserving the same signature: createTestRequest(url: string, options?:
RequestInit): Request and the same fullUrl logic), then replace the duplicated
local helpers in all spec files (including header.spec.ts) with imports from
that shared util; ensure the shared module imports/exports any required
DOM/Request types so existing tests compile and update test imports to reference
the new exported function name.
packages/decorators/src/type.ts (1)

32-35: Model async extractors explicitly in the public type.

buildDecoratorMethodArguments() now awaits extractor results, but ParameterExtractFn still advertises a plain any return. Tightening this to an awaitable return keeps the public parameter contract aligned with the new async extractor path.

♻️ Suggested typing update
 export type ParameterExtractFn = (
     context: HandlerContext,
     key?: string,
-) => any;
+) => Promise<unknown> | unknown;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/decorators/src/type.ts` around lines 32 - 35, ParameterExtractFn
currently returns plain any but extractors can be async
(buildDecoratorMethodArguments awaits them); change ParameterExtractFn's return
type to an awaitable type such as Promise<any> or PromiseLike<any> (or use a
MaybePromise<T> alias) so the public parameter contract reflects async
extractors; update the type declaration for ParameterExtractFn accordingly and
ensure any usages of ParameterExtractFn (e.g., in buildDecoratorMethodArguments)
remain compatible.
packages/decorators/test/data/get.ts (1)

1-1: Unused import: IRoutupEvent

The IRoutupEvent type is imported but never used in this file. Consider removing it.

🧹 Proposed fix
-import type { IRoutupEvent } from 'routup';
 import {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/decorators/test/data/get.ts` at line 1, The import IRoutupEvent in
get.ts is unused and should be removed; edit the top-level import line that
mentions IRoutupEvent and delete that identifier so the file no longer imports
IRoutupEvent (keep any other imports intact) to eliminate the unused-type lint
error.
packages/decorators/test/data/combined.ts (1)

5-5: Unused import: DContext

DContext is imported but not used in any of the controller methods. Consider removing it unless it's needed for future additions.

🧹 Proposed fix
 import type { HandlerInterface } from '../../src';
 import {
-    DContext,
     DController,
     DDelete,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/decorators/test/data/combined.ts` at line 5, Remove the unused
import DContext from the file to eliminate dead code: locate the import list
that includes DContext (the symbol "DContext" in the combined.ts import block)
and delete that specific import entry; ensure no references to DContext exist
elsewhere in the file and run tests/lint to confirm the unused-import warning is
resolved.
packages/decorators/README.md (1)

159-179: Consider clarifying the async nature of body extraction.

The body extractor is marked async and uses readRequestBody, while cookie and query extractors are synchronous and use useRequestCookie/useRequestQuery. This is likely intentional since body parsing requires reading a stream, but a brief comment in the docs could help users understand why only body is async.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/decorators/README.md` around lines 159 - 179, The README shows three
extractors—body (async), cookie, and query—where body uses readRequestBody and
is async while cookie/query use useRequestCookie/useRequestCookies and
useRequestQuery synchronously; add a short clarifying comment in the docs next
to the body extractor explaining that readRequestBody consumes a request stream
and therefore is asynchronous (hence body is marked async), whereas cookie and
query access parsed data synchronously via useRequestCookie/useRequestCookies
and useRequestQuery so they do not need async behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/decorators/package.json`:
- Around line 54-60: Bump this package's semver major: update the package.json
"version" field from 3.4.3 to the next major (e.g., 4.0.0) to signal the
breaking v5-compatible API change for `@routup/decorators`, or if you intend CI to
auto-release, add a clear note in package.json or the PR describing that
automated release tooling will perform the major bump; ensure you update any
CHANGELOG/release notes referencing the `@routup/decorators` breaking changes
accordingly.

---

Nitpick comments:
In `@packages/decorators/README.md`:
- Around line 159-179: The README shows three extractors—body (async), cookie,
and query—where body uses readRequestBody and is async while cookie/query use
useRequestCookie/useRequestCookies and useRequestQuery synchronously; add a
short clarifying comment in the docs next to the body extractor explaining that
readRequestBody consumes a request stream and therefore is asynchronous (hence
body is marked async), whereas cookie and query access parsed data synchronously
via useRequestCookie/useRequestCookies and useRequestQuery so they do not need
async behavior.

In `@packages/decorators/src/type.ts`:
- Around line 32-35: ParameterExtractFn currently returns plain any but
extractors can be async (buildDecoratorMethodArguments awaits them); change
ParameterExtractFn's return type to an awaitable type such as Promise<any> or
PromiseLike<any> (or use a MaybePromise<T> alias) so the public parameter
contract reflects async extractors; update the type declaration for
ParameterExtractFn accordingly and ensure any usages of ParameterExtractFn
(e.g., in buildDecoratorMethodArguments) remain compatible.

In `@packages/decorators/test/data/combined.ts`:
- Line 5: Remove the unused import DContext from the file to eliminate dead
code: locate the import list that includes DContext (the symbol "DContext" in
the combined.ts import block) and delete that specific import entry; ensure no
references to DContext exist elsewhere in the file and run tests/lint to confirm
the unused-import warning is resolved.

In `@packages/decorators/test/data/get.ts`:
- Line 1: The import IRoutupEvent in get.ts is unused and should be removed;
edit the top-level import line that mentions IRoutupEvent and delete that
identifier so the file no longer imports IRoutupEvent (keep any other imports
intact) to eliminate the unused-type lint error.

In `@packages/decorators/test/unit/header.spec.ts`:
- Around line 6-9: Extract the createTestRequest function into a single shared
test utility module and export it (preserving the same signature:
createTestRequest(url: string, options?: RequestInit): Request and the same
fullUrl logic), then replace the duplicated local helpers in all spec files
(including header.spec.ts) with imports from that shared util; ensure the shared
module imports/exports any required DOM/Request types so existing tests compile
and update test imports to reference the new exported function name.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d7c2ee5-1c6f-464c-82b7-d02b4c8d4154

📥 Commits

Reviewing files that changed from the base of the PR and between 7a150d5 and 18760a4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (22)
  • packages/decorators/README.md
  • packages/decorators/package.json
  • packages/decorators/src/method/arguments.ts
  • packages/decorators/src/mount.ts
  • packages/decorators/src/parameter/constants.ts
  • packages/decorators/src/parameter/module.ts
  • packages/decorators/src/parameter/type.ts
  • packages/decorators/src/type.ts
  • packages/decorators/src/utils/handler.ts
  • packages/decorators/test/data/combined.ts
  • packages/decorators/test/data/cookie.ts
  • packages/decorators/test/data/get.ts
  • packages/decorators/test/data/header.ts
  • packages/decorators/test/data/middleware.ts
  • packages/decorators/test/data/post.ts
  • packages/decorators/test/data/query.ts
  • packages/decorators/test/unit/body.spec.ts
  • packages/decorators/test/unit/combined.spec.ts
  • packages/decorators/test/unit/cookie.spec.ts
  • packages/decorators/test/unit/header.spec.ts
  • packages/decorators/test/unit/middleware.spec.ts
  • packages/decorators/test/unit/query.spec.ts
💤 Files with no reviewable changes (1)
  • packages/decorators/src/parameter/type.ts

Comment on lines +54 to +60
"routup": "^5.0.0-beta.3"
},
"devDependencies": {
"@routup/body": "^2.4.3",
"@routup/cookie": "^2.4.3",
"@routup/query": "^2.4.3",
"@types/supertest": "^7.2.0",
"routup": "^4.0.1",
"supertest": "^7.1.4"
"routup": "^5.0.0-beta.3"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Major-version release step appears incomplete.

This PR introduces a v5 compatibility/breaking API migration, but @routup/decorators is still 3.4.3. Please bump to the next major (or document that automated release tooling will do it), otherwise consumers won’t get proper semver signaling.

Suggested semver bump
-    "version": "3.4.3",
+    "version": "4.0.0",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/decorators/package.json` around lines 54 - 60, Bump this package's
semver major: update the package.json "version" field from 3.4.3 to the next
major (e.g., 4.0.0) to signal the breaking v5-compatible API change for
`@routup/decorators`, or if you intend CI to auto-release, add a clear note in
package.json or the PR describing that automated release tooling will perform
the major bump; ensure you update any CHANGELOG/release notes referencing the
`@routup/decorators` breaking changes accordingly.

@tada5hi tada5hi merged commit f72386f into master Apr 8, 2026
1 of 2 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 8, 2026
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.

feat: update @routup/decorators for routup v5

1 participant