record (src/params.ts) read the argument map with Reflect.getMetadata, which walks the prototype chain, then pushed into what it got back. On a subclass that was the base class's map, so a @query on Child.list also showed up in getArgs(Base, 'list').
Same bug, also fixed here: the route decorator in src/metadata.ts did the same with the routes array, so a @Get on a subclass was added to the base controller. The other decorators in metadata.ts (@Provider, @Step, @Route, @Module, @Transformer, @Html) define a fresh value and never mutate what they read, so they are unaffected.
Fix. Both now write a copy onto the decorated class: a shallow copy of the map plus a new list in params.ts, a new array in metadata.ts. This copies on every write, not only the first. getMetadata returns the class's own data once it has any, so the result is the same as a getOwnMetadata copy-on-first-write. It costs one array copy per decorator, at decoration time only.
Worth a look: a subclass that overrides a method keeps the base's argument specs for that method and adds its own. With the same index on both, getArgs returns two specs for that index. That was already the behaviour on the subclass before, and the issue asks for "clone the inherited map and list", so I kept it. Starting an overridden method from an empty list would be a separate decision.
Tests: test/params.test.ts and test/metadata.test.ts, "inheritance" blocks. The base-unchanged cases failed on develop (expected ['a','b'] to deeply equal ['a']) and pass with the fix.
Fixes GitHub #44.
`record` (src/params.ts) read the argument map with `Reflect.getMetadata`, which walks the prototype chain, then pushed into what it got back. On a subclass that was the base class's map, so a `@query` on `Child.list` also showed up in `getArgs(Base, 'list')`.
**Same bug, also fixed here:** the route decorator in src/metadata.ts did the same with the `routes` array, so a `@Get` on a subclass was added to the base controller. The other decorators in metadata.ts (`@Provider`, `@Step`, `@Route`, `@Module`, `@Transformer`, `@Html`) define a fresh value and never mutate what they read, so they are unaffected.
**Fix.** Both now write a copy onto the decorated class: a shallow copy of the map plus a new list in params.ts, a new array in metadata.ts. This copies on every write, not only the first. `getMetadata` returns the class's own data once it has any, so the result is the same as a `getOwnMetadata` copy-on-first-write. It costs one array copy per decorator, at decoration time only.
**Worth a look:** a subclass that overrides a method keeps the base's argument specs for that method and adds its own. With the same index on both, `getArgs` returns two specs for that index. That was already the behaviour on the subclass before, and the issue asks for "clone the inherited map and list", so I kept it. Starting an overridden method from an empty list would be a separate decision.
Tests: `test/params.test.ts` and `test/metadata.test.ts`, "inheritance" blocks. The base-unchanged cases failed on develop (`expected ['a','b'] to deeply equal ['a']`) and pass with the fix.
Ran: lint (0 errors), format:check, typecheck, `npm test` (1165 passed), complexity:check, test:deno (63 passed), test:bun (52 passed), test:edge (PASS).
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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fixes GitHub #44.
record(src/params.ts) read the argument map withReflect.getMetadata, which walks the prototype chain, then pushed into what it got back. On a subclass that was the base class's map, so a@queryonChild.listalso showed up ingetArgs(Base, 'list').Same bug, also fixed here: the route decorator in src/metadata.ts did the same with the
routesarray, so a@Geton a subclass was added to the base controller. The other decorators in metadata.ts (@Provider,@Step,@Route,@Module,@Transformer,@Html) define a fresh value and never mutate what they read, so they are unaffected.Fix. Both now write a copy onto the decorated class: a shallow copy of the map plus a new list in params.ts, a new array in metadata.ts. This copies on every write, not only the first.
getMetadatareturns the class's own data once it has any, so the result is the same as agetOwnMetadatacopy-on-first-write. It costs one array copy per decorator, at decoration time only.Worth a look: a subclass that overrides a method keeps the base's argument specs for that method and adds its own. With the same index on both,
getArgsreturns two specs for that index. That was already the behaviour on the subclass before, and the issue asks for "clone the inherited map and list", so I kept it. Starting an overridden method from an empty list would be a separate decision.Tests:
test/params.test.tsandtest/metadata.test.ts, "inheritance" blocks. The base-unchanged cases failed on develop (expected ['a','b'] to deeply equal ['a']) and pass with the fix.Ran: lint (0 errors), format:check, typecheck,
npm test(1165 passed), complexity:check, test:deno (63 passed), test:bun (52 passed), test:edge (PASS).b256bc8570todae052f400