fix(metadata): keep a subclass's decorators off its base class (GitHub #44)
CI / dco (pull_request) Successful in 4s
CI / build (pull_request) Successful in 29s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / runtimes (deno) (pull_request) Successful in 33s
CI / runtimes (edge) (pull_request) Successful in 19s

record in params.ts read the argument map with Reflect.getMetadata,
which walks the prototype chain, then pushed into the list it got back
and defined that same object on the subclass. On a subclass with no
metadata of its own, that object was the base class's, so a @query on
Child.list also showed up in getArgs(Base, 'list').

routeDecorator in metadata.ts had the same pattern with the routes
array, so a @Get on a subclass was also served by the base controller.
It is the same bug in the same shape, so it is fixed here too.

Both now write a copy onto the decorated class: a shallow copy of the
map and a new list for the method in params.ts, a new array in
metadata.ts. getMetadata returns the class's own metadata once it has
some, so later decorators on that class copy its own data, not the
base's. A subclass still starts from what it inherits, as before.

The other decorators in metadata.ts (@Provider, @Step, @Route,
@Module, @Transformer, @Html) define a fresh value per class or per
method and never mutate what they read, so they are unaffected.

Refs: GitHub #44
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-24 18:27:35 -05:00
1 parent 32bd4f6e4a
commit dae052f400
5 files changed
+51 -5

No files matched your search

+8
View File
@@ -293,6 +293,14 @@ npm treats versions as semver and semver forbids leading zeros.
against the disconnect, and the source's `return()` is called without being waited on, so one
that hangs or throws can no longer hold up or break the cleanup. Compressed streams included.
- **Decorating a subclass no longer changes its base class** (GitHub #44). The argument
decorators (`@query`, `@param`, `@needs`, …) and the route decorators (`@Get`, `@Ws`, …) read
their metadata with `Reflect.getMetadata`, which walks the prototype chain, and then pushed into
what came back. On a subclass that was the base class's own map or array, so a `@query` on
`Child.list` also appeared in `getArgs(Base, 'list')`, and a route declared on `Child` was served
by `Base` too. Each decorator now writes a copy onto the class it decorates. The subclass still
starts from what it inherits.
- **`listen()` rejects when the port is taken** (#138). A bind failure such as `EADDRINUSE` or
`EACCES` arrives as the server's `error` event, which `listen()` did not handle: the promise
never settled, and the error surfaced as an unhandled one. It now rejects with that error. The