Minor koa decorator fixes.

This commit is contained in:
2026-04-14 12:31:38 +01:00
parent bee509b4b6
commit 8bb18bce05
2 changed files with 13 additions and 10 deletions
+7 -8
View File
@@ -221,13 +221,13 @@
}
},
"node_modules/@types/node": {
"version": "25.5.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.2.tgz",
"integrity": "sha512-tO4ZIRKNC+MDWV4qKVZe3Ql/woTnmHDr5JD8UI5hn2pwBrHEwOEMZK7WlNb5RKB6EoJ02gwmQS9OrjuFnZYdpg==",
"version": "25.6.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.0.tgz",
"integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.18.0"
"undici-types": "~7.19.0"
}
},
"node_modules/@types/qs": {
@@ -520,7 +520,6 @@
"resolved": "https://registry.npmjs.org/koa/-/koa-3.2.0.tgz",
"integrity": "sha512-TrM4/tnNY7uJ1aW55sIIa+dqBvc4V14WRIAlGcWat9wV5pRS9Wr5Zk2ZTjQP1jtfIHDoHiSbPuV08P0fUZo2pg==",
"license": "MIT",
"peer": true,
"dependencies": {
"accepts": "^1.3.8",
"content-disposition": "~1.0.1",
@@ -693,9 +692,9 @@
}
},
"node_modules/undici-types": {
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
"integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==",
"version": "7.19.2",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz",
"integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==",
"dev": true,
"license": "MIT"
},
+6 -2
View File
@@ -17,6 +17,7 @@ export function get(path: string) {
if (!context.metadata[routeSymbol]) {
context.metadata[routeSymbol] = [] as Route[];
}
// @ts-ignore
context.metadata[routeSymbol].push({method: 'get', path, fn: originalMethod});
}
return originalMethod;
@@ -27,8 +28,9 @@ export function post(path: string) {
return function getDecorator (originalMethod: any, context: ClassMethodDecoratorContext) {
if (context.metadata) {
if (!context.metadata[routeSymbol]) {
context.metadata[routeSymbol] = [] as Route;
context.metadata[routeSymbol] = [] as Route[];
}
// @ts-ignore
context.metadata[routeSymbol].push({method: 'post', path, fn: originalMethod});
}
return originalMethod;
@@ -41,6 +43,7 @@ export function middleware(fn: any, path: string = '') {
if (!context.metadata[routeSymbol]) {
context.metadata[routeSymbol] = [];
}
// @ts-ignore
context.metadata[routeSymbol].unshift({method: 'use', path, fn});
}
return constructor;
@@ -54,7 +57,8 @@ export function router(prefix: string) {
constructor(...args: any[]) {
super(...args);
this.router = new Router({prefix});
for (const route of context.metadata?.[routeSymbol] || [] satisfies Route[]) switch (route.method) {
for (const route of (context.metadata?.[routeSymbol] || []) as Route[]) switch (route.method) {
case "get": this.router.get(route.path, route.fn); break;
case "post": this.router.post(route.path, route.fn); break;
case 'use': this.router.use(route.fn); break;