-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
✅ accepted-PRs-welcomeFeature proposal is accepted and ready to work onFeature proposal is accepted and ready to work on👉 good first issueGood for newcomersGood for newcomers🙋♂️ help wantedExtra attention is neededExtra attention is needed
Description
Issue
Consuming application can't nest Router
in their own applyDecorators
calls to allow for more complex configurations. This is currently not supported due to the getCallerFilePath
function always expecting the router path to be a constant number (i.e. 2) levels down on the call stack.
i.e. in the example down below, it's assumed that authedRoute.decorator.ts
is the router instead of dog.route.ts
because it sits one step further down on the call stack which results in:
[Nest] 91798 - 12/06/2024, 4:25:52 PM WARN TRPC Generator encountered an error.
[Nest] 91798 - 12/06/2024, 4:25:52 PM WARN Error: Could not find router DogRouter class declaration.
Proposal
- Turn the
path
property onROUTER_METADATA_KEY
from a string of a single path to an array of the path hierarchy. - Update serializeRouterProcedures to work down the list of paths to find the first one with a classDeclaration and use that.
If this looks good, let me know and I'd be happy to kick up a PR!
Example Use Case
authedRoute.decorator.ts
import { AuthnMiddleware } from '@/common/middlewares/authn.middleware';
import { AuthzMiddleware } from '@/common/middlewares/authz.middleware';
import { ResponseTimeMiddleware } from '@/common/middlewares/responseTime.middleware';
import { applyDecorators } from '@nestjs/common';
import { UseMiddlewares, Router } from 'nestjs-trpc';
export const AuthedRoute = (options: { alias: string }) => {
return applyDecorators(
Router({ alias: options.alias }),
UseMiddlewares(ResponseTimeMiddleware, AuthnMiddleware, AuthzMiddleware),
);
};
dog.route.ts
@Injectable()
@AuthedRoute({ alias: 'dog' })
export class DogRouter {
@Query()
async find() {
return {};
}
}
Metadata
Metadata
Assignees
Labels
✅ accepted-PRs-welcomeFeature proposal is accepted and ready to work onFeature proposal is accepted and ready to work on👉 good first issueGood for newcomersGood for newcomers🙋♂️ help wantedExtra attention is neededExtra attention is needed